Hi, I''ve been reading with interest the threads trying to integrate Mocha and Stubba with RSpec. So far, I''ve made the two changes in spec_helper.rb suggested, but discovered another one that neither of the archives mentions: If you use traditional mocking: object = mock or the stub shortcut : object = stub(:method => :result), you run into namespace conflicts with RSpec which has top level names that do that as well. The actual error message is 1) - Stubs should work with Stubba undefined method `stub_space'' for #<Spec::Runner::Specification:0xb76bd4d4> 2) - Mocks should work with Mocha ArgumentError in ''Mocks should work with Mocha'' wrong number of arguments (0 for 1) I could not get alias to work (but didn''t try alias_method yet,) so I just commented out the stub and mock calls in rspec-0.6.4/lib/spec/runner/execution_context.rb Is there a better way to do this? Ed -- Ed Howland http://greenprogrammer.blogspot.com
On 25/10/06, Ed Howland <ed.howland at gmail.com> wrote:> > I''ve been reading with interest the threads trying to integrate Mocha > and Stubba with RSpec. So far, I''ve made the two changes in > spec_helper.rb suggested, but discovered another one that neither of > the archives mentions: > > If you use traditional mocking: object = mock or the stub shortcut > : object = stub(:method => :result), you run into namespace conflicts > with RSpec which has top level names that do that as well. The actual > error message is > > 1) - Stubs should work with Stubba > undefined method `stub_space'' for > #<Spec::Runner::Specification:0xb76bd4d4> > > 2) - Mocks should work with Mocha > ArgumentError in ''Mocks should work with Mocha'' > wrong number of arguments (0 for 1) > > I could not get alias to work (but didn''t try alias_method yet,) so I > just commented out the stub and mock calls in > rspec-0.6.4/lib/spec/runner/execution_context.rb > > Is there a better way to do this? >Hi Ed, Unfortunately I haven''t had much time to work on Mocha recently. The work I have done most recently has been to make Mocha useable in the absence of Test::Unit. This should help with integrating with the more recent incarnations of RSpec. Take a look at the standalone_acceptance_test.rb file in HEAD (revision 70) for some ideas on how to hook into Mocha from a non Test::Unit testing framework. This is still a bit of a work in progress, but you might be able to get somewhere with it. -- James. http://blog.floehopper.org -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/mocha-developer/attachments/20061025/2f888b1e/attachment-0001.html
On 10/25/06, James Mead <jamesmead44 at gmail.com> wrote:> Hi Ed, > > Unfortunately I haven''t had much time to work on Mocha recently. The work I > have done most recently has been to make Mocha useable in the absence of > Test::Unit. This should help with integrating with the more recent > incarnations of RSpec. Take a look at the standalone_acceptance_test.rb file > in HEAD (revision 70) for some ideas on how to hook into Mocha from a non > Test::Unit testing framework. This is still a bit of a work in progress, but > you might be able to get somewhere with it. > > --Thanks, James I just gave a talk on Mocha and Stubba last night at the St. Louis Ruby Group. All my code examples were in RSpec, except for the last one which used stub(), which I generated in a normal Test::Unit::TestCase. I''ll check out the HEAD revision and see how to do it. David C. on the RSpec team said in a comment on Jay Fields'' blog that they were going to make RSpec pluggable for other mock frameworks, like yours and FlexMock. BTW, did you see how FlexMock is copying you now? Or at least jMock. Ed> James. > http://blog.floehopper.org > _______________________________________________ > mocha-developer mailing list > mocha-developer at rubyforge.org > http://rubyforge.org/mailman/listinfo/mocha-developer > >-- Ed Howland http://greenprogrammer.blogspot.com
On 10/25/06, Ed Howland <ed.howland at gmail.com> wrote:> On 10/25/06, James Mead <jamesmead44 at gmail.com> wrote: > > Hi Ed, > > > > Unfortunately I haven''t had much time to work on Mocha recently. The work I > > have done most recently has been to make Mocha useable in the absence of > > Test::Unit. This should help with integrating with the more recent > > incarnations of RSpec. Take a look at the standalone_acceptance_test.rb file > > in HEAD (revision 70) for some ideas on how to hook into Mocha from a non > > Test::Unit testing framework. This is still a bit of a work in progress, but > > you might be able to get somewhere with it. > > > > -- > Thanks, James > > I just gave a talk on Mocha and Stubba last night at the St. Louis > Ruby Group. All my code examples were in RSpec, except for the last > one which used stub(), which I generated in a normal > Test::Unit::TestCase. > > I''ll check out the HEAD revision and see how to do it. > > David C. on the RSpec team said in a comment on Jay Fields'' blog that > they were going to make RSpec pluggable for other mock frameworks, > like yours and FlexMock.Yes, it''s true, but this is going to be a little further down - a few weeks or a month. Right now we''re busy stabilizing some things including our own mock framework. I''m not exactly sure how the integration will work, but I imagine that there will be a hook into the runner that lets a framework say "use me", at which point each spec will call the framework at the beginning and the end. So as a user of rspec and mocha, you would do something like this: require ''mocha/rspec_plugin'' As a writer of a framework like mocha, you''d say something like this: RSPEC.use_me :mock, Mocha::RspecPlugin.new #need to tell rspec to turn off its own mocking, hence :mock module Mocha class RspecPlugin def spec_started(spec) #define methods here on the submitted spec like mock() and stub() (class << spec; self; end).class_eval { include Mocha::MockMethods } end def spec_ended(spec) #verify and clean up any mocks/stubs created since the spec started end end end This saves the user from having to things like this: mock = Mocha::Mock.new() and mock.verify Also helps to avoid collisions on the stuff both frameworks add to Object. Maybe a simpler way would be to just have a flag that lets you turn of rspec mocks in any given context: require ''mocha'' context "blah" do rspec_mocks :off ... That would require no integration points, but would not notify mocha when to verify (so users would have to do so explicitly) James - does any of this sound sound? I''m completely open to whatever makes integration and use simple w/o requiring complex dependencies between the frameworks. Cheers, David> BTW, did you see how FlexMock is copying you > now? Or at least jMock. > > > Ed > > James. > > http://blog.floehopper.org > > _______________________________________________ > > mocha-developer mailing list > > mocha-developer at rubyforge.org > > http://rubyforge.org/mailman/listinfo/mocha-developer > > > > > > > -- > Ed Howland > http://greenprogrammer.blogspot.com > _______________________________________________ > mocha-developer mailing list > mocha-developer at rubyforge.org > http://rubyforge.org/mailman/listinfo/mocha-developer >
On 25/10/06, Ed Howland <ed.howland at gmail.com> wrote:> > I just gave a talk on Mocha and Stubba last night at the St. Louis > Ruby Group. All my code examples were in RSpec, except for the last > one which used stub(), which I generated in a normal > Test::Unit::TestCase.Cool. I hope it went well :-) I''ll check out the HEAD revision and see how to do it. Great - let me know how you get on. David C. on the RSpec team said in a comment on Jay Fields'' blog that> they were going to make RSpec pluggable for other mock frameworks, > like yours and FlexMock. BTW, did you see how FlexMock is copying you > now? Or at least jMock. >Yes, I saw the changes to FlexMock. It was good of Jim to credit Mocha in his docs. His syntax is similar to some pre-Mocha stuff my colleague Ben Griffiths did. Of course I prefer the Mocha syntax ;-) David has explained the status with RSpec in another post on this thread. Happy mocking. -- James. http://blog.floehopper.org -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/mocha-developer/attachments/20061026/e3e8357d/attachment-0001.html
On 26/10/06, David Chelimsky <dchelimsky at gmail.com> wrote:> > Yes, it''s true, but this is going to be a little further down - a few > weeks or a month. Right now we''re busy stabilizing some things > including our own mock framework.Is there anything that the new RSpec mocking framework does that Mocha doesn''t do apart from the should-style stuff? I only ask, because it seems a shame to re-invent the wheel. I''m not exactly sure how the integration will work, Me either. As I don''t use RSpec, I don''t have a big incentive to work on integrating Mocha into RSpec. As we discussed previously, I have now made Mocha independent of Test::Unit which should make integration with any testing framework much easier. Take a look at standalone_acceptance_test.rb in HEAD to see how it can work. -- James. http://blog.floehopper.org -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/mocha-developer/attachments/20061026/e72969d4/attachment.html