Skip to content
This repository

Modules included in example groups aren't visible in Ruby 1.9.3 #506

Closed
garybernhardt opened this Issue November 18, 2011 · 4 comments

2 participants

Gary Bernhardt Justin Ko
Gary Bernhardt

In Ruby 1.9.3, when including a module in an example group, constants defined in the module aren't in scope:

module X
  module Y
    def self.a_method
      5
    end
  end
end

describe X::Y do
  include X

  it "can access Y" do
    Y.a_method.should == 5
  end
end

This fails with "NameError: uninitialized constant Y".

This worked fine in 1.9.2, so it seemed like a Ruby change caused the regression. It happens both with rspec-core 2.6.0 and 2.7.1.

Justin Ko

Looks like a Ruby bug:

module X
  module Y
    def self.a
      puts 'a'
    end
  end
end

class Foo

end

a = Class.new(Foo) do
  include X

  def self.b
    Y.a
  end
end

puts a.b # => uninitialized constant Y (NameError)

Looks like 1.9.3 has a bug with "block evaluation" (Class.new, module_eval, etc.)

Justin Ko

I just tried it with 1.9.3-head, still no fix :(

@garybernhardt - I'll let you upsert this bug to ruby core.

Gary Bernhardt garybernhardt closed this November 23, 2011
Gary Bernhardt

Apparently this was never supposed to work in the first place; the fact that it worked on 1.9.2 was a bug. Shame. :/ http://redmine.ruby-lang.org/issues/5657

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.