[rspec-users] passing a block to a stub method
jko170 at gmail.com
Mon Sep 13 22:38:02 EDT 2010
On Sep 13, 6:32 pm, nicolas <nicolas.br... at gmail.com> wrote:
> It seems that rspec doesn't support passing a block to a stub method.
> This code fails:
> def call_build_with_block(o)
> o.build do
> puts "hello"
> describe "call_build_with_block" do
> it "should call build with block" do
> o = double("object")
> o.should_receive(:build) do |&b|
> b.should_not be_nil
> block_given?.should == true
> rspec-users mailing list
> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
What you can use is the "and_yield" method:
o.should_receive(:build).and_yield do |eval_context|
Hope that helps.
More information about the rspec-users