Ken Egervari
2011-May-31 18:09 UTC
[rspec-users] How do you test a module that extends ActiveSupport::Concern?
I have a module that extends ActiveSupport::Concern. Here is the `included` block: included do after_save :save_tags has_many :taggings, :as => :taggable has_many :tags, :through => :taggings end How can I stub out these calls? I have tried a few ways, but Ruby complains that these methods don''t exist when I try and test the module in isolation. Thanks! Ken -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110531/f4d09f72/attachment.html>
Matt Wynne
2011-May-31 18:58 UTC
[rspec-users] How do you test a module that extends ActiveSupport::Concern?
Hi Ken, On 31 May 2011, at 19:09, Ken Egervari wrote:> I have a module that extends ActiveSupport::Concern. Here is the `included` block: > > included do > after_save :save_tags > > has_many :taggings, :as => :taggable > has_many :tags, :through => :taggings > end > > How can I stub out these calls? I have tried a few ways, but Ruby complains that these methods don''t exist when I try and test the module in isolation.I''ve never used concerns, but my guess is that they carry shared responsibility that''s mixed into a few other classes. If you want to test them in isolation (as opposed to just testing the behaviour of the actual classes you''ve mixed them in to) then I would create a simple dummy object in your test, mix the concern into that, and then test the behaviour of that object. Make sense?> > Thanks! > > Ken > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-userscheers, Matt matt at mattwynne.net 07974 430184