module Bar
def self.baz_wrapper(&block)
Foo.baz(&block)
end
end
it "passes the given block to Foo" do
my_block = lambda {}
expect(Foo).to receive(:baz).with(&my_block)
Bar.baz_wrapper(&my_block)
endit "passes the given block to Foo" do
my_block = lambda {}
expect(Foo).to receive(:baz) do |&block|
expect(block).to eq(my_block)
end
Bar.baz_wrapper(&my_block)
end(Foo).to receive(:baz).with(&my_block)` work?
--
You received this message because you are subscribed to the Google Groups "rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rspec+un...@googlegroups.com.
To post to this group, send email to rs...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/3bfa0a8a-4f55-4e24-8527-3f2f4eb693ea%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
As Jon pointed out, the rspec-mocks API allows you to use blocks to specify implementation logic and/or return values so I don’t think that making it also match on the block will work well. The solution you came up with looks OK to me. You could shorten it further with a helper method:
module ReceiveWithBlock
def receive_with_block(method_name, &expected_block)
receive(method_name) { |&block| expect(block).to eq expected_block }
end
end
RSpec.configure do |config|
config.include ReceiveWithBlock
end
Which you could then use with:
expect(Foo).to receive_with_block(:baz, &my_block)
Given the rarity of this need and that there are solutions, I would lean against adding anything additional to the RSpec API for it.
Myron
To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/EB121FFFE7C64891924A7F6D1148B377%40jonrowe.co.uk.
To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/CADUxQmtp2MM4_OAJfS6zVt4mBjSxaN%3DKGXJcrUXOUSpFL8%2BG0w%40mail.gmail.com.