Hi --

On Fri, 30 Jan 2009, Simon Chiang wrote:

> As an additional note to this, assigning constants in a describe under
> 1.8 causes namespace pollution.
>
>  require 'rubygems'
>  require 'minitest/spec'
>
>  module X
>    module Y
>    end
>  end
>
>  describe "Namespace Pollution" do
>    Y = X::Y
>  end
>
>  puts Y  # => 'X::Y' on 1.8, error on 1.9

It's not specific to minitest; it's a change in how constants are
resolved. I'm not sure of the exact formulation but what's happening
is that in a class_eval'd code block (which I think is what describe
does), 1.8 is looking for a constant scoped to the outer level, while
1.9 is looking for one that is scope to the class that's being
class_evaled.

You can see this also with a block for a new class:

module A
   module B
   end
end

Class.new do
   include A
   p B == A::B   # true in 1.9, error in 1.8 (unknown constant B)
end


David

-- 
David A. Black / Ruby Power and Light, LLC
Ruby/Rails consulting & training: http://www.rubypal.com
Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2)

http://www.wishsight.com => Independent, social wishlist management!