Repository navigation
Coming from RSpec
Cyril Kato edited this page Nov 1, 2026
·
1 revision
RSpec clone keeps the words of RSpec and some of its matchers, and leaves the rest out on purpose. What to write instead:
| RSpec | RSpec clone |
|---|---|
rspec spec/, rspec spec/x_spec.rb:12, --seed, --format
|
ruby spec/x_spec.rb, or a Rake TestTask; no command, no filter, no random order |
let!, subject!, memoized let
|
let and subject are plain methods; memoize by hand with an instance variable |
before(:each) |
before |
before(:all), after, around
|
nothing: a context isolates what a test leaves behind |
describe with no module |
described_class is undefined, not nil
|
expect(x).to eq y (==) |
eq compares with eql? and requires the class of the expected value: 1 is not 1.0
|
expect(x).to match "str" |
match takes a Regexp only |
raise_error, raise_error(/msg/)
|
raise_exception(Class), raise_exception(Class, "msg"), raise_exception(Class, /msg/)
|
not_to raise_error with no class |
not_to raise_exception StandardError |
be_truthy, be_falsey, be_falsy
|
be_true, be_false, be_nil, or satisfy
|
be_a, be_an, be_kind_of, be_instance_of
|
be_a_kind_of, be_an_instance_of
|
include, start_with, end_with, respond_to, cover, all, contain_exactly, have_attributes
|
satisfy { |value| … }, or a predicate of the value (be_empty, have_key) |
expect { … }.to change { x.y } |
change(x, :y): the object and the method |
change { }.from(a).to(b) where the value is already b
|
to requires a change; from … to compares with eql?
|
and, or, .and, .or
|
two expectations, or satisfy
|
rspec-its |
its is built in: its(:name, *arguments) { is_expected.to … }
|
pending inside an example, skip, xit
|
pending "why", with or without a block, instead of it
|
custom matcher DSL, RSpec::Matchers.define
|
any object with match? and to_s, given a word by a let
|
shared_examples, it_behaves_like
|
a specification of Fix, through matchi-fix |
mocks, stubs, allow, receive
|
nothing: the clone has no test doubles |
| a failure continues with the next example | the run stops at the first expectation that is not met |
context runs in the same process |
context runs in a child process |
The report differs too: one line per expectation, LOCATION: OUTCOME: SUMMARY, no dots, no summary count, no colour; see Reading the report.