Skip to content
This repository has been archived by the owner on Oct 27, 2021. It is now read-only.

Commit

Permalink
stubs calculate return value by executing block passed to #and_return
Browse files Browse the repository at this point in the history
(hint from Aisha Fenton).

[#642 state:resolved milestone:Maintenance]
  • Loading branch information
dchelimsky committed Jan 3, 2009
1 parent 904bc56 commit a99dbe9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion History.txt
Expand Up @@ -24,7 +24,7 @@
* html formatter (and subsequently the textmate formatter) header fills in completely when running a single example
* config.include now accepts an array of types (config.include(Helpers, :type => [:view, :controller]))

* 8 bug fixes
* 9 bug fixes

* fixed bug where {:a => 1, :b => 2}.should include(:a, :b) failed (Yossef Mendelssohn)
* only try to load Test::Unit if Test::Unit is defined (not just Test)
Expand All @@ -34,6 +34,7 @@
* Check whether test/unit has really been loaded before calling a method it defines (Brian Donovan). Closes #503.
* Fix spec_path for shared groups (Zach Dennis). Closes #615.
* stubbed message expectation not verified if it has been called *before* the expectation (Matthias Hennemeyer). Closes #637.
* stubs calculate return value by executing block passed to #and_return (hint from Aisha Fenton). Closes #642.

=== Version 1.1.11 / 2008-10-24

Expand Down
2 changes: 1 addition & 1 deletion lib/spec/mocks/proxy.rb
Expand Up @@ -91,7 +91,7 @@ def message_received(sym, *args, &block)
if expectation = find_almost_matching_expectation(sym, *args)
expectation.advise(args, block) unless expectation.expected_messages_received?
end
stub.invoke([], block)
stub.invoke(args, block)
elsif expectation
expectation.invoke(args, block)
elsif expectation = find_almost_matching_expectation(sym, *args)
Expand Down
6 changes: 6 additions & 0 deletions spec/spec/mocks/stub_spec.rb
Expand Up @@ -137,6 +137,12 @@ def existing_instance_method
@stub.foo("bar")
@stub.foo("baz")
end

it "calculates return value by executing block passed to #and_return" do
@mock.stub!(:something).with("a","b","c").and_return { |a,b,c| c+b+a }
@mock.something("a","b","c").should == "cba"
@mock.rspec_verify
end
end

describe "A method stub with args" do
Expand Down

0 comments on commit a99dbe9

Please sign in to comment.