On 13/09/06, <b class="gmail_sendername">Luke Redpath</b> <<a href="mailto:contact@lukeredpath.co.uk">contact@lukeredpath.co.uk</a>> wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><div style=""><div>I've recently upgraded to the latest versions of Mocha and RSpec (0.3.2 and 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.
</div><div><br></div><div>I require stubba in my spec file but whenever I try and run my spec it fails with the error:</div><div><br></div><div>Unintialized constant Test</div><div><br></div><div>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.
</div><div><br></div><div>This isn't a Rails project, just a standalone Ruby lib that I'm working on.</div><div><br></div><div>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:
</div><div><br></div><div>Undefined method 'stub' for nil:NilClass</div><div><br></div><div>Here's the line where I'm trying to stub a method on an existing instance of an object:</div><div><br></div><div>@connection.stubs
(:logged_in?).returns(true)</div><div><br></div><div>I've x-posted this to the Mocha dev list and RSpec dev list as I'm not sure where the issue lies.<br></div></div></div></blockquote></div><br>Hi Luke,<br><br>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 SmartTestCase.
<br><br>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...<br><br># add this line to your context's setup<br>$stubba = Stubba::
Central.new<br><br>Getting the auto-verify to work and sorting this out properly needs a bit more thought.<br><br>Hope that helps.<br><br>-- <br>James.<br><a href="http://blog.floehopper.org">http://blog.floehopper.org</a>