How can I mix a module into an rspec context (aka describe
), such that the module's constants are available to the spec?
module Foo
FOO = 1
end
describe 'constants in rspec' do
include Foo
p const_get(:FOO) # => 1
p FOO # uninitialized constant FOO (NameError)
end
That const_get
can retrieve the constant when the name of the constant cannot is interesting. What's causing rspec's curious behavior?
I am using MRI 1.9.1 and rspec 2.8.0. The symptoms are the same with MRI 1.8.7.
You can use RSpec's
shared_context
: