[rspec-users] Best way to spec nested modules?...

Stuart Hungerford stuart.hungerford at anu.edu.au
Sun Jan 25 21:56:19 EST 2009


Hi,

I've got a set of classes in nested Ruby modules which I'm using rspec  
to specify:

module Foo

     module Baz

        class C1 ... end

        class C2 ... end
     end
end

To specify C2 behaviour I need to create a bunch of C1 instances:

describe Foo::Baz::C2 do

     before(:each) do
         @c1a = Foo::Baz::C1.new(...)
         @c1b = Foo::Baz::C1.new(...)
         @c1c = Foo::Baz::C1.new(...)

         @c2 = Foo::Baz::C2.new(@c1a, @c1b, @c1c)
     end

     describe "some behaviour" do
         # ...
     end
end

After a while the many Foo::Baz:: module prefixes become pretty  
tedious and
not particularly DRY.

Can someone suggest a better way to manage using nested modules in  
rspec?

Thanks,

Stu

--
Stuart Hungerford
ANU Supercomputer Facility





More information about the rspec-users mailing list