Permalink
Browse files

Simplify some examples.

- #105.
  • Loading branch information...
1 parent 42b3ef7 commit 0b4eab2752c6361442029b55c2daa88f1abab1be @dchelimsky dchelimsky committed Feb 5, 2012
Showing with 14 additions and 24 deletions.
  1. +0 −3 lib/rspec/mocks/message_expectation.rb
  2. +14 −21 spec/rspec/mocks/mock_spec.rb
@@ -457,9 +457,6 @@ def invoke_consecutive_return_block(*args, &block)
end
def invoke_return_block(*args, &block)
- # Ruby 1.9 - when we set @return_block to return values
- # regardless of arguments, any arguments will result in
- # a "wrong number of arguments" error
@return_block.arity == 0 ? @return_block.call(&block) : @return_block.call(*args, &block)
end
@@ -174,33 +174,26 @@ def @mock.method_with_default_argument(arg={}); end
}.to raise_error(RSpec::Mocks::MockExpectationError, /Double \"test double\" received :something but passed block failed with: expected false to be true/)
end
- it "passes block to expectation block", :ruby => '> 1.8.6' do
- a = nil
+ it "passes proc to expectation block without an argument", :ruby => '> 1.8.6' do
# We eval this because Ruby 1.8.6's syntax parser barfs on { |&block| ... }
# and prevents the entire spec suite from running.
- eval("@mock.should_receive(:something) { |&block| a = block }")
- b = lambda { }
- @mock.something(&b)
- a.should eq b
- @mock.rspec_verify
+ eval("@mock.should_receive(:foo) {|&block| block.call.should eq(:bar)}")
+ @mock.foo { :bar }
end
- it "passes block to stub block with an argument", :ruby => '> 1.8.6' do
- a = nil
- eval("@mock.stub(:something){|something_else, &block| a = block}")
- b = lambda { }
- @mock.something(nil, &b)
- a.should eq b
- @mock.rspec_verify
+ it "passes proc to expectation block with an argument", :ruby => '> 1.8.6' do
+ eval("@mock.should_receive(:foo) {|arg, &block| block.call.should eq(:bar)}")
+ @mock.foo(:arg) { :bar }
end
- it "passes block to stub block without an argurment", :ruby => '>1.8.6' do
- a = nil
- eval("@mock.stub(:something){|&block| a = block}")
- b = lambda { }
- @mock.something(&b)
- a.should eq b
- @mock.rspec_verify
+ it "passes proc to stub block without an argurment", :ruby => '>1.8.6' do
+ eval("@mock.stub(:foo) {|&block| block.call.should eq(:bar)}")
+ @mock.foo { :bar }
+ end
+
+ it "passes proc to stub block with an argument", :ruby => '> 1.8.6' do
+ eval("@mock.stub(:foo) {|arg, &block| block.call.should eq(:bar)}")
+ @mock.foo(:arg) { :bar }
end
it "fails right away when method defined as never is received" do

0 comments on commit 0b4eab2

Please sign in to comment.