[rspec-users] [rspec-rails] how to test module behavior once and then confirm that controllers implement it?

Nick nick at deadorange.com
Sat Jan 15 00:29:58 EST 2011

Hey Lille.

> Specifically, what is the recommended structure for the test of the
> module filter;
How about creating a shared example group, and referencing that?

> next, how can I confirm that the controller classes
> that have included the module and are properly calling its methods as
> filters.
You can check if a class included a module like this:
    Foo.should include Bar

When an object calls a method that was mixed in, the method's called as 
though it truly is a part of the class. So you can just do:

Module Bar
  def baz; end

Class Foo
  include Bar

  def something

f = Foo.new
f.should_receive(:baz).and_return nil

In the rest of your specs, it's just a matter of stubbing out the call to 

> Cracking this could save me from duplicating the testing of the full
> behavior of the filters in several instances, in several
> ActionController classes.
I hope that helps!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110114/de2b0904/attachment.html>

More information about the rspec-users mailing list