Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added spec demonstrating mock return value for an edge case.

When a method has been stubbed previously to return a certain value (say, in a before(:each)), and then mocked w/o a return value (say, in a spec, to ensure a method was called), the stubbed value should still be returned.
  • Loading branch information...
commit b8135d5d8d04930f09d606a96c2d84be910a12f2 1 parent 361f315
@myronmarston myronmarston authored dchelimsky committed
Showing with 8 additions and 1 deletion.
  1. +8 −1 spec/rspec/mocks/mock_spec.rb
View
9 spec/rspec/mocks/mock_spec.rb
@@ -88,7 +88,14 @@ module Mocks
@mock.rspec_verify
end
- it "returns nil if no return value set" do
+ it "returns the previously stubbed value if no return value is set" do
+ @mock.stub!(:something).with("a","b","c").and_return(:stubbed_value)
+ @mock.should_receive(:something).with("a","b","c")
+ @mock.something("a","b","c").should == :stubbed_value
+ @mock.rspec_verify
+ end
+
+ it "returns nil if no return value is set and there is no previously stubbed value" do
@mock.should_receive(:something).with("a","b","c")
@mock.something("a","b","c").should be_nil
@mock.rspec_verify
Please sign in to comment.
Something went wrong with that request. Please try again.