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. 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. Cheers, Luke Redpath contact at lukeredpath.co.uk -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/mocha-developer/attachments/20060913/79b9a3f8/attachment-0001.html
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 SmartTestCase. 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. -- James. http://blog.floehopper.org -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/mocha-developer/attachments/20060913/b1f5dd58/attachment.html
On 13/09/06, James Mead <jamesmead44 at gmail.com> wrote: # 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. >Of course, I forgot to mention that this hack is more evil than nasty, because without the stubba teardown being triggered your stubbed method won''t get put back together again. So anything other than instance method stubs will be left in place and will most likely trip you up in subsequent tests. -- James. http://blog.floehopper.org -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/mocha-developer/attachments/20060913/d30e932f/attachment.html
Reasonably Related Threads
- Mocha, Stubba and RSpec
- Fwd: [ mocha-Bugs-5892 ] Using a setup method in test_case_class destroys subsequent test cases
- expectations on stubs (stubba) or mock methods on existing classes?
- Patch: make rdoc of lib/mocha/object.rb instead of lib/stubba/object.rb
- Mocha + Selenium-on-rails loading problem ?