In RSpec 1.3 the following would pass:
describe Person do
describe "#greeting" do
context "using #stub with correct parameters" do
before(:each) do
subject.stub(:greeting).with("Nicholas")
end
specify { lambda{ subject.greeting("Nicholas") }.should_not
raise_error(NoMethodError) }
end
context "using #stub with incorrect parameters" do
before(:each) do
subject.stub(:greeting).with("incorrect parameter")
end
specify { lambda{ subject.greeting("Nicholas") }.should
raise_error(NoMethodError) }
end
end
end
From the example above you can see that calling a stuff with a different parameter would raise a NoMethodError. A bit confusing.
Fortunately in RSpec 2 it fixed. The following error is raised:
1) Person#greeting using #stub with incorrect parameters
Failure/Error: specify { lambda{ subject.greeting("Nicholas") }.should raise_error(NoMethodError) }
expected NoMethodError, got ##<RSpec::Mocks::MockExpectationError: #<Person:0x0000010216fb68#> received :greeting with unexpected arguments
expected: ("incorrect parameter")
got: ("Nicholas")>
Related links: