I have a specification for an object that is at several levels of modules. Something like that:
describe Foo::Bar::Baz::Quux::Widget do it "should == another Widget for the same Doohickey" do doohickey = stub Foo::Bar::Baz::Quux::Widget.new(doohickey).should == Foo::Bar::Baz::Quux::Widget.new(doohickey) end it "should != another Widget for a different Doohickey" do one_doohickey = stub another_doohickey = stub Foo::Bar::Baz::Quux::Widget.new(one_doohickey).should == Foo::Bar::Baz::Quux::Widget.new(another_doohickey) end end
This is a lot of repetition, and it makes it look like I'm using an object from a different namespace. I would like to set the specification context for Foo::Bar::Baz::Quux . The following works are surprisingly good:
module Foo::Bar::Baz::Quux describe Widget do it "should == another Widget for the same Doohickey" do doohickey = stub Widget.new(doohickey).should == Widget.new(doohickey) end it "should != another Widget for a different Doohickey" do one_doohickey = stub another_doohickey = stub Widget.new(one_doohickey).should == Widget.new(another_doohickey) end end end
There is only one problem. Since I'm in Rails, I'm depending on ActiveSupport dependency management to automatically load the Foo::Bar::Baz::Quux module. This used to happen when I mentioned Foo::Bar::Baz::Quux::Widget . Now I define the module myself, so the real module definition in foo/bar/baz/quux.rb never loads.
How to change the constant search context for my specification without defining the module itself?
Peeja source share