RSpec Ruby testing
Light · Postcard
102 × 152 mm · PDF
Dark · Postcard
102 × 152 mm · PDF
Ink saver · Postcard
102 × 152 mm · PDF
Light · A4 landscape
297 × 210 mm · PDF
Dark · A4 landscape
297 × 210 mm · PDF
Ink saver · A4 landscape
297 × 210 mm · PDF
Light · A3 landscape
420 × 297 mm · PDF
Dark · A3 landscape
420 × 297 mm · PDF
Ink saver · A3 landscape
420 × 297 mm · PDF
Start here
rspecrspec <file>
rspec <file>:<line>
rspec -e "<text>"
rspec --only-failures
rspec --fail-fast
rspec --format doc
rspec --initConcepts
Run
rspecrspec <file> <dir>
rspec <file>:<line>
rspec <file>[1:2]
rspec --dry-runrspec --versionFilter
rspec -e "<text>"
rspec -E "<regex>"
rspec --tag <tag>
rspec --tag ~<tag>
rspec --tag <key>:<value>
rspec --only-failures
rspec --next-failure
Output
rspec --format doc
rspec -f prspec -f failures
rspec -f json -o <file>
rspec --profilerspec --profile <n>
rspec -bFailures and order
rspec --fail-fast
rspec --fail-fast=<n>
rspec --seed <n>
rspec --order random
rspec --order defined
rspec --bisectWriting specs
RSpec.describe <Class> do
describe "#<method>" do
context "when <state>" do
it "<behaviour>" do
let(:<name>) { <value> }
subject { <expr> }
before { <setup> }
after { <cleanup> }
before(:all) { <setup> }
around { |ex| <x>; ex.run }
it "<x>", :<tag> do
shared_examples "<name>" do
it_behaves_like "<name>"
shared_context "<name>" do
skip "<reason>"
described_classExpectations
expect(<x>).to eq(<y>)
expect(<x>).not_to eq(<y>)
expect(<x>).to be_truthy
expect(<x>).to be_nil
expect(<x>).to be_a(<Class>)
expect(<x>).to include(<y>)
expect(<x>).to match(<regex>)
expect(<x>).to
be_within(<d>).of(<n>)
expect(<a>).to match_array(<b>)
expect { <code> }.to raise_error(<Error>)
expect { <code> }.to change { <x>
}.by(<n>)
expect(<x>).to be_<predicate>
Mocks
double("<name>", <m>: <v>)
instance_double(<Class>)
allow(<obj>).to
receive(:<m>).and_return(<v>)
expect(<obj>).to
receive(:<m>).with(<args>)
expect(<obj>).to have_received(:<m>)
Config
.rspecRSpec.configure do |c|
c.order = :random
c.default_formatter = "doc"
Recipes
rspec spec/models/user_spec.rb:42rspec --next-failurerspec -b -e "validates email"
rspec --order random # note the printed seedrspec --seed 4711 --bisect# run the minimal command bisect prints
# spec/spec_helper.rbRSpec.configure do |c| c.filter_run_when_matching :focus c.order = :randomend# then: fit "works" do ... end
bundle exec rspec \ --format progress \ --format json --out tmp/rspec.json \ --fail-fast=5



