[rspec-users] Specifying that code is called in a block

Ashley Moran work at ashleymoran.me.uk
Thu Mar 1 05:35:13 EST 2007


On 1 Mar 2007, at 07:44, Matthijs Langenberg wrote:

> I'm actually interested in the other way around: when do you know the
> solution should be receiving a block in a method when writing a
> specification? Can anyone give me an example of that?


Best I can think of is this:

class MyClass
   def moo(quack_block)
     quack(&quack_block)
   end

   private
     def quack
       puts yield
     end
end

context "description of context" do
   setup do
     @mock = mock("mock")
     @my_object = MyClass.new
   end

   specify "descriptive specification" do
     @mock.should_receive(:woof)
     @my_object.moo(lambda { @mock.woof; "miaow" })
   end
end

Not sure in the real world it would be practical, or even if this is  
a good thing to do, but it seems to work

Ashley


More information about the rspec-users mailing list