You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
This is the RSpec mono repo, it contains the core gems we think of as "rspec", they are:
rspec-core provides the structure for writing executable examples of how yourcode should behave, and anrspec command with tools to constrain whichexamples get run and tailor the output.
rspec-expectations lets you express expected outcomes on an object in an example.
rspec-mocks is a test-double framework for rspec with support for method stubs,fakes, and message expectations on generated test-doubles and real objectsalike.
rspec-support provides shared helper functionality for the other three gems, ingeneral you don't install this on its own.
Install
gem install rspec # for rspec-core, rspec-expectations and rspec-mocksgem install rspec-core # for rspec-core onlygem install rspec-expectations # for rspec-expectations onlygem install rspec-mocks # for rspec-mocks only
Want to run against themain branch? You'll need to include the dependentRSpec repos as well. Add the following to yourGemfile:
If you install the rspec-core gem, it installs therspec executable,which you'll use to run rspec. Therspec command comes with many usefuloptions.
Runrspec --help to see the complete list.
Getting started:
RSpec uses the words "describe" and "it" so we can express concepts like a conversation:
"Describe a calculator.""It adds together numbers."
e.g.
# in spec/calculator_spec.rbRSpec.describeCalculatordodescribe'#add'doit'returns the sum of its arguments'doexpect(Calculator.new.add(1,2)).toeq(3)endendend
Run this with the rspec command, and watch it fail:
Address the failure by defining a skeleton of theCalculator class:
# in lib/calculator.rbclassCalculatordefadd(a,b)endend
Be sure to require the implementation file in the spec:
# in spec/calculator_spec.rb# - RSpec adds ./lib to the $LOAD_PATHrequire"calculator"
Now run the spec again, and watch the expectation fail:
$ rspec spec/calculator_spec.rbFFailures: 1) Calculator#add returns the sum of its arguments Failure/Error: expect(Calculator.new.add(1, 2)).to eq(3) expected: 3 got: nil (compared using ==) # ./spec/calculator_spec.rb:6:in `block (3 levels) in <top (required)>'Finished in 0.00131 seconds (files took 0.10968 seconds to load)1 example, 1 failureFailed examples:rspec ./spec/calculator_spec.rb:5 # Calculator#add returns the sum of its arguments
Implement the simplest solution, by changing the definition ofCalculator#add to:
defadd(a,b)a +bend
Now run the spec again, and watch it pass:
$ rspec spec/calculator_spec.rb.Finished in 0.000315 seconds1 example, 0 failures
Use thedocumentation formatter to see the resulting spec:
$ rspec spec/calculator_spec.rb --format docCalculator #add returns the sum of its argumentsFinished in 0.000379 seconds1 example, 0 failures
Contributing
Once you've set up the environment, you'll need to cd into the workingdirectory of whichever repo you want to work in. From there you can run thespecs and cucumber features, and make patches.
NOTE: You do not need to use rspec-dev to work on a specific RSpec repo. Youcan treat each RSpec repo as an independent project.