I am using the acts_as_state_machine plugin to control state of an object in my app, however when testing this I need to be able to stub out the guard conditions so that state will change when I fire off an event without depending on other models. Guard conditions simply return true or false so I have an instance method: def encoded? <check state of other objects> return true or false end However I cannot find a way to stub out this method properly. Ideally I wish to do something that I expect I could do with Test::Unit mocks and just replace the encoded? instance method for all objects that might use it to just return true. Any ideas? David
On 3/27/07, David Smalley <david.smalley.lists at googlemail.com> wrote:> I am using the acts_as_state_machine plugin to control state of an > object in my app, however when testing this I need to be able to stub > out the guard conditions so that state will change when I fire off an > event without depending on other models. > > Guard conditions simply return true or false so I have an instance > method: > > def encoded? > <check state of other objects> > return true or false > end > > However I cannot find a way to stub out this method properly. Ideally > I wish to do something that I expect I could do with Test::Unit mocksWhat''s Test::Unit mocks?> and just replace the encoded? instance method for all objects that > might use it to just return true. > > Any ideas? >You can submit a feature request - ideally with a failing spec to illustrate what you want.> David > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
On 27 Mar 2007, at 11:19, aslak hellesoy wrote:> > What''s Test::Unit mocks?Ah sorry, by which I mean the /test/mocks/<env>/mocked_code.rb setup in a default Rails skeleton - it lets you drop a replacement for a method that appears higher up in the search path and allows you to completely over-ride a method.> >> and just replace the encoded? instance method for all objects that >> might use it to just return true. >> >> Any ideas? >> > > You can submit a feature request - ideally with a failing spec to > illustrate what you want.After a bit of digging around it looks like David (Chelimsky) has already submitted such a feature request https://rubyforge.org/tracker/index.php? func=detail&aid=6791&group_id=797&atid=3152 - looks a lot like what I want. Consider it similar to the syntax offered by mocha e.g. Order.any_instance.stubs(:shipped_on).returns(nil) I think it would be a very helpful addition to Rspec stub/mock framework - I''d be interested in helping to implement it but I fear I don''t know enough about how mocking works. I''ll dig into mocha and rspec code but if any of the Rspec developers want to take the lead that would be great! Cheers, David -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070327/9cb16f49/attachment-0001.html
On 3/27/07, David Smalley <david.smalley.lists at googlemail.com> wrote:> > > On 27 Mar 2007, at 11:19, aslak hellesoy wrote: > > > > > > What''s Test::Unit mocks? > > Ah sorry, by which I mean the > /test/mocks/<env>/mocked_code.rb setup in a default > Rails skeleton - it lets you drop a replacement for a method that appears > higher up in the search path and allows you to completely over-ride a > method. >I see. Strictly speaking these are not mocks, but stubs. http://www.martinfowler.com/articles/mocksArentStubs.html Aslak> > > > > > and just replace the encoded? instance method for all objects that > > might use it to just return true. > > > > > Any ideas? > > > > > > > > You can submit a feature request - ideally with a failing spec to > > illustrate what you want. > After a bit of digging around it looks like David (Chelimsky) has already > submitted such a feature request > > https://rubyforge.org/tracker/index.php?func=detail&aid=6791&group_id=797&atid=3152 > - looks a lot like what I want. > > Consider it similar to the syntax offered by mocha > > e.g. > Order.any_instance.stubs(:shipped_on).returns(nil) > > I think it would be a very helpful addition to Rspec stub/mock framework - > I''d be interested in helping to implement it but I fear I don''t know enough > about how mocking works. I''ll dig into mocha and rspec code but if any of > the Rspec developers want to take the lead that would be great! > > Cheers, > > David > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >