[rspec-users] modules and stub

Sarah Allen lists at ruby-forum.com
Sun May 24 19:15:43 EDT 2009


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,
Sarah
-- 
Posted via http://www.ruby-forum.com/.


More information about the rspec-users mailing list