Giter VIP home page Giter VIP logo

rspec-basics's Introduction

RSpec Basics

Intro

Welcome to using RSpec! Here's a short intro to getting up to speed. If you're here after using m-spec, it was designed to help you quickly get to grips with RSpec. RSpec is an industry-standard tool for teams using Ruby, it's fully featured, well-documented, and helps you keep your test code DRY.

The trade-off for keeping code DRY is abstraction, and it can be tough for beginners to grapple with a lot of abstraction. So this repository is aimed for you to play with and learn by doing. Write specs, run the specs, read the comments in the files, explore and have fun! :)

Quick Setup

  • mkdir [dirname] to create a new project directory
  • cd into the directory
  • bundle init to add a Gemfile
  • bundle add rspec to add rspec
  • rspec --init to initialise the framework

Inquiry Projects

1. What is the purpose of initial files that were created?

How can you run your tests with common options like colour and formatted output?

create   .rspec
create   spec/spec_helper.rb

2. Write a simple spec

In a new project directory, initialise RSpec and use it to write a simple spec. If you need inspiration, write your own spec for Animal#roar.

3. Use RSpec mocks in a spec

Practice using RSpec's double() method. Write down your observations. Run irb and play around with the methods. Or use pry to pause your code path during a test run and explore.

4. Investigate

Resources

Usage Notes

  1. RSpec adds the lib directory to the load path if it's available, so you can use the require method relative from it - eg: simple usage spec
  2. RSpec has it's own spec runner, so running rspec by itself runs all the specs it finds.
  3. NB: RSpec will automatically try to find any spec in your spec directory named *_spec.rb - pay attention to your file names.
  4. To run an individual file, pass the filepath rspec spec/tests_should_run_independently_spec.rb
  5. To run an individual test, pass the filepath and linenumber rspec spec/tests_should_run_independently_spec.rb:17

rspec-basics's People

Contributors

dearshrewdwit avatar

Forkers

anastasisgi

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.