[rspec-users] should_receive with a block
zach.lists at gmail.com
Tue Jul 7 08:17:25 EDT 2009
That won't work because of how Ruby handles the equality of lambdas/
From my experience there are 2 approaches.
1) Test both the "call" and the block together. So instead of mocking
Util, mock SfProperty.
2) Store the lambda somewhere (like a Class variable). Test the lambda
separately, and test the "call" separately, but treat the lambda as a
black box. (though I'm sure you could do something funky with
redefining the Class variable within the test, and asserting that the
redefinition got passed in the "call" method).
Testing passed lambdas/procs can be tricky because you're testing the
behavior of something that _defines behavior_ and passes it to
On Jul 7, 2009, at 7:27 AM, doug livesey wrote:
> Hi -- can I specify the block that should be called with a method?
> Sort of like this:
> it "should bulk update the properties_params in groups of 50" do
> block = lambda do |params|
> SfProperty.put( :bulk_update, :sf_properties => params )
> Util.should_receive( :do_to_in_groups_of ).with( @properties_params,
> 50, &block )
> Or am I dreaming?
> rspec-users mailing list
> rspec-users at rubyforge.org
More information about the rspec-users