1
2
obj.should ...
expect(obj).to ...
1
2
obj.should_not ...
expect(obj).not_to ...
1
2
obj.should =~ //
expect(obj).to match(//)
1
2
[1, 2, 3].should =~ [3, 2, 1]
expect([1, 2, 3]).to match_array([3, 2, 1])
1
2
obj.should > 3
expect(obj).to be > 3
1
2
lambda { ... }.should raise_error
expect { ... }.to raise_error

RSpec 2.14.0 or later

1
2
obj.stub(:foo)
allow(obj).to receive(:foo)
1
2
SomeClass.any_instance.should_receive(:foo)
expect_any_instance_of(SomeClass).to receive(:foo)
1
2
SomeClass.any_instance.stub(:foo)
allow_any_instance_of(SomeClass).to receive(:foo)

RSpec 2.99.0.beta1 or later

1
2
it { should eq(something) }
it { is_expected.to eq(something) }

RSpec 3.0.0.beta1 or later

1
2
obj.stub_chain(:foo, :bar).and_return(something)
allow(obj).to receive_message_chain(:foo, :bar).and_return(something)

Comments