I prefer to use rspec than test::unit for developing my apps. However I''ve found its mocking library to be pretty inflexible compared to Mocha. This isn''t really a surprise since rspec isn''t intended as a mocking framework, whereas Mocha is. So I''d like to play to both of their strengths and use rspec as my testing/specification framework and Mocha do to mocks. I installed the plugins for each, and whenever I try to mock a method with Mocha I get a nil object error at plugins/mocha/lib/stubba/setup_and_teardown.rb at line 18. I''ve looked through all the files referenced in the trace and haven''t been able to figure anything out. Not sure if anyone else has tried to use rspec and mocha together yet. I''d like some help from people with experience in either in getting these going. Pat --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Hi Pat, Thanks for the positive feedback on Mocha. You might like to know that the RSpec developers agree with you and are looking to ditch their internal mocking framework and integrate properly with Mocha. We aren''t using Mocha with RSpec, but I know some people are (e.g. http://www.lukeredpath.co.uk/). My colleague Chris Roos (http://blog.seagul.co.uk/) has just looked into the error you are seeing and it looks like the problem stems from a call to Test::Unit::TestCase#add_assertion from within Mocha::AutoVerify#teardown_mocks. Apparently the RSpec descendant of Test::Unit::TestCase raises an exception when you call #add_assertion (not sure why). A possible quick fix would be to add a rescue in the Mocha code... def teardown_mocks mocks.each { |mock| mock.verify { add_assertion rescue nil } } reset_mocks end This will mean that verified expectations will not be included in the assertion count, but I don''t think there are any other ramifications on the Mocha side. You might however want to check if it breaks anything on the RSpec side. -- James. http://blog.floehopper.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
I asked the question on the rspec mailing list on your behalf and got a response here - http://rubyforge.org/pipermail/rspec-devel/2006-September/000672.html -- James. http://blog.floehopper.org -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/mocha-developer/attachments/20060912/e3a8f17d/attachment.html
On 9/12/06, James Mead <jamesmead44-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> A possible quick fix would be to add a rescue in the Mocha code... > > def teardown_mocks > mocks.each { |mock| mock.verify { add_assertion rescue nil } } > reset_mocks > end > > -- > James. > http://blog.floehopper.orgHi James, Thanks for looking into this for me. With your fix, I managed to run specs fine. The one problem I''ve run into has to do with transactions. I''m getting the "WARNING: There is already a transaction in progress"..."WARNING: There is no transaction in progress" messages. That''s occurring because the transactions look like BEGIN BEGIN ROLLBACK ROLLBACK If I remove the mocha plugin then it doesn''t happen. I looked through all the mocha code and there was nothing that mentioned a transaction. I turned off transactional_fixtures in test_helper, figuring mocha might somehow use that, but it didn''t change anything. rspec ought to be handling all the transactions since it''s my testing framework. Any idea why the inclusion of mocha would try to start a new transaction? Again, thanks for your help. Pat --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On 14/09/06, Pat Maddox <pergesu at gmail.com> wrote:> > Thanks for looking into this for me. With your fix, I managed to run > specs fine. The one problem I''ve run into has to do with > transactions. I''m getting the "WARNING: There is already a > transaction in progress"..."WARNING: There is no transaction in > progress" messages. That''s occurring because the transactions look > like > BEGIN > BEGIN > ROLLBACK > ROLLBACK > > If I remove the mocha plugin then it doesn''t happen. I looked through > all the mocha code and there was nothing that mentioned a transaction. > I turned off transactional_fixtures in test_helper, figuring mocha > might somehow use that, but it didn''t change anything. > > rspec ought to be handling all the transactions since it''s my testing > framework. Any idea why the inclusion of mocha would try to start a > new transaction? > > Again, thanks for your help. > > PatHmm. Mocha definitely doesn''t do anything with the database, let alone transactions. I imagine it must be something to do with Rails'' TestCase and transactional fixtures. I''m not in a position to investigate this properly at the moment, but I''ll try and have a look later today. BTW - it might be better to move this thread over onto the Mocha list < mocha-developer at rubyforge.org> -- James. http://blog.floehopper.org -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/mocha-developer/attachments/20060914/8b26b90d/attachment.html