[mocha-developer] Problem with RSpec and Mocha/Stubba

James Mead jamesmead44 at gmail.com
Wed Sep 13 08:23:46 EDT 2006

On 13/09/06, Luke Redpath <contact at lukeredpath.co.uk> wrote:
> I've recently upgraded to the latest versions of Mocha and RSpec (0.3.2and
> 0.6.3 respectively) and I'm no longer able to use Mocha/Stubba with RSpec.
> Its actually only Stubba I'm interested in as I use RSpec's built-in mocking
> library.
> I require stubba in my spec file but whenever I try and run my spec it
> fails with the error:
> Unintialized constant Test
> Digging around the Mocha source, it seems that it is trying to add
> extensions to Test::Unit which I haven't required as I don't need it.
> This isn't a Rails project, just a standalone Ruby lib that I'm working
> on.
> I've tried the obvious solution of requiring test/unit but that has its
> own issues (i.e. it puts test::unit output at the bottom of my spec
> output) and it still doesn't work, I get a new error:
> Undefined method 'stub' for nil:NilClass
> Here's the line where I'm trying to stub a method on an existing instance
> of an object:
> @connection.stubs(:logged_in?).returns(true)
> I've x-posted this to the Mocha dev list and RSpec dev list as I'm not
> sure where the issue lies.

Hi Luke,

Chris Roos & I have just taken a look at your problem. It seems that
Stubba::SetupAndTeardown#setup_stubs and #teardown_stubs are not getting
called. You are right about the missing require 'test/unit' in

I don't think this area of Mocha has changed much recently, but I could be
wrong. If you only need stubs and no mocks, you could get away with this
nasty hack...

# add this line to your context's setup
$stubba = Stubba::Central.new

Getting the auto-verify to work and sorting this out properly needs a bit
more thought.

Hope that helps.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/mocha-developer/attachments/20060913/b1f5dd58/attachment.html 

More information about the mocha-developer mailing list