[rspec-users] modules and stub

Sarah Allen
Sun, 24 May 2009 23:15:43 -0000

If there is a method defined on a module, how do I stub it?

Imagine I have a module like this:

Module Foo
   Module Bar

    def self.do_something(path)
  ...
    end


   end
end


Somewhere in the code, there is this call:
               Foo::Bar::do_something(path)

In my test I want the above call to do nothing, so I tried this:
    before(:each) do
      Foo::Bar.stub!(:do_something).and_return
    end

but I confirm that do_something is getting called by adding a puts in
it. Do I not have the module/stub syntax correct?  How can I isolate
this further?

I tried looking at the doc ( http://rspec.rubyforge.org/rspec/1.2.6/ )
but I couldn''t really make sense of it.

Thanks,