[rspec-users] question about throw_symbol

Paul Mylchreest
Tue, 18 Aug 2009 17:19:32 -0000

Given
   rspec 1.2.8
   ruby 1.8.6 (2008-08-11 patchlevel 287) [universal-darwin9.0]

And the following spec:

   def over_limit?(a)
     catch(:over_limit) do
       a.each do |x|
         throw(:over_limit) if x > 10
       end
     end
   end

   describe "when over limit" do
     it "should throw symbol :over_limit" do
       lambda{
         over_limit?([0, 5, 11])
       }.should throw_symbol(:over_limit)
     end
   end

One would expect this to pass, however this is the result:

   when over limit
   - should throw symbol :over_limit (FAILED - 1)

   1)
   ''when over limit should throw symbol :over_limit'' FAILED
   expected :over_limit but nothing was thrown
   ./spec/rspec_tests/rutabaga_spec.rb:125:

When the catch is removed, it works.

Can anyone reproduce this behavior?

thanks

Paul Mylchreest
paul.mylchreest at mac.com