[rspec-users] Verifying that a block calls a method

Scott Taylor mailing_lists at railsnewbie.com
Wed Apr 18 12:23:20 EDT 2007


>>
>> Well it seems to be good advise.  Unfortunately, it doesn't help me
>> with the Kernel#trap problem, though, which is what the email was
>> originally about.
>>
>
> If you want a concise answer, ask a short and concise question ;-)  
> Try this:
>
> class Mooky
>   def add_sigint_handler(trapper=Kernel)
>     trapper.trap("INT") { raise Interrupt }
>   end
> end
>
> describe Mooky do
>   it 'should install an INT trap that raises an Interrupted' do
>     mooky = Mooky.new
>     trapper = mock('Kernel')
>     trapper.should_receive(:trap).with("INT").and_yield
>     lambda do
>       mooky.add_sigint_handler(trapper)
>     end.should raise_error(Interrupt)
>   end
> end
>
> Any other suggestions?

Ah - I hadn't noticed the "and_yield" method - I was trying to just  
pass the proc to the "with" method.

That really clears things up.  Thanks, Aslak.

Scott


>
> Aslak
>
>> Scott
>>
>>
>>
>>>
>>> David
>>> _______________________________________________
>>> rspec-users mailing list
>>> rspec-users at rubyforge.org
>>> http://rubyforge.org/mailman/listinfo/rspec-users
>>
>> _______________________________________________
>> rspec-users mailing list
>> rspec-users at rubyforge.org
>> http://rubyforge.org/mailman/listinfo/rspec-users
>>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users



More information about the rspec-users mailing list