[rspec-users] accessing constants from another module within examples
David Chelimsky
dchelimsky at gmail.com
Wed Jun 16 10:22:15 EDT 2010
On Jun 16, 2010, at 9:11 AM, Jarmo Pertman wrote:
> Hello.
>
> I wanted to include module into ExampleGroup to write less code within
> examples, but was unable to do so. This seems to be strange, because
> in regular Class it works and all methods within that module are also
> accessible. See the example:
>
> module MyModule
> MyConstant = 1
>
> def my_method
> 2
> end
> end
>
> describe "including modules" do
> include MyModule
>
> it "works" do
> my_method.should == 2
> MyModule::MyConstant.should == 1
> end
>
> it "doesn't work" do
> MyConstant.should == 1
> end
> end
>
> Running this simple spec will produce one failure with this message:
> 1)
> NameError in 'including modules doesn't work'
> uninitialized constant MyConstant
>
> Is this an expected behaviour? Is there some other way to access
> constants from another module without specifying module name within
> examples?
Seems like a bug. Please submit it to http://github.com/rspec/rspec-core/issues for rspec-2, http://rspec.lighthouseapp.com to make sure it gets backported to rspec-1.
Thx,
David
More information about the rspec-users
mailing list