Skip to content

Instantly share code, notes, and snippets.

@probablykabari
Created March 15, 2010 17:29
Show Gist options
  • Save probablykabari/333081 to your computer and use it in GitHub Desktop.
Save probablykabari/333081 to your computer and use it in GitHub Desktop.
rspec2
# line 16
it "should tell you when it receives the right message with the wrong args if you stub the method (fix bug 15719)" do
# NOTE - for whatever reason, if you use a the block style of pending here,
# rcov gets unhappy. Don't know why yet.
m = mock("foo")
m.stub!(:bar)
m.should_receive(:bar).with("message")
lambda {
m.bar("different message")
}.should raise_error(Rspec::Mocks::MockExpectationError, %Q{Mock 'foo' expected :bar with ("message") but received it with ("different message")})
m.bar("message") # allows the spec to pass
end
#line 411
it "should temporarily replace a method stub on a mock" do
@mock.stub!(:msg).and_return(:stub_value)
@mock.should_receive(:msg).with(:arg).and_return(:mock_value)
@mock.msg(:arg).should equal(:mock_value)
@mock.msg.should equal(:stub_value)
@mock.msg.should equal(:stub_value)
@mock.rspec_verify
end
# line 138
it "should limit " do
@stub.stub!(:foo).with("bar")
@stub.should_receive(:foo).with("baz")
@stub.foo("bar")
@stub.foo("baz")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment