[MacRuby-devel] [MacRuby] #674: Shoulda fails because of oddity with block_given?

MacRuby ruby-noreply at macosforge.org
Mon May 3 14:50:42 PDT 2010


#674: Shoulda fails because of oddity with block_given?
---------------------------------+------------------------------------------
 Reporter:  marick@…             |       Owner:  lsansonetti@…        
     Type:  defect               |      Status:  new                  
 Priority:  minor                |   Milestone:                       
Component:  MacRuby              |    Keywords:                       
---------------------------------+------------------------------------------
 The attached file shows that shoulda (on 0.5 and a recent version of 0.7)
 behaves incorrectly. The important part is this:

 {{{
   should "test something" do
     puts "I should be printed"
   end
 }}}


 The correct output shows that a test has been run:
 {{{
    1274 $ ruby shoulda-problem.rb
    ...
    I should be printed
 }}}

 With Macruby, you get this:
 {{{
 1275 $ macruby shoulda-problem.rb
   * DEFERRED: Samples should test something.
 }}}

 The problem is in this code:

 {{{
     def should(name, options = {}, &blk)
       if Shoulda.current_context
         block_given? ? Shoulda.current_context.should(name, options, &blk)
 : Shoulda.current_context.should_eventually(name)
       else
         context_name = self.name.gsub(/Test/, "")
         context = Shoulda::Context.new(context_name, self) do
 ==>          block_given? ? should(name, options, &blk) :
 should_eventually(name)
         end
         context.build
       end
     end
 }}}

 In Ruby 1.8.6 (and 1.9, I suppose, because Shoulda is said to work on
 1.9), the block_given? inside a block given to an initializer is supposed
 to evaluate to true. (!!!) In Macruby, it evaluates to False.

 This problem is easy to patch (and I'd be inclined to think the Shoulda
 people should, given that the code is tricksy). Still, it is a deviation
 from reference Ruby behavior.

-- 
Ticket URL: <http://www.macruby.org/trac/ticket/674>
MacRuby <http://macruby.org/>



More information about the MacRuby-devel mailing list