[rspec-users] Can module spec "behave like" controller spec?

David Chelimsky dchelimsky at gmail.com
Fri Aug 31 04:50:26 EDT 2007


On 8/31/07, Shaker <flyeminent at hotmail.com> wrote:
>
> Hello everyone:
>     Right now I am writing spec on modules, which are provided by my
> colleagues. Some of the modules actually contain action methods. I tried
> very hard to spec those action methods in modules. But it seems that  the
> rspec does not allow module spec to 'get' action like controller does. After
> I saw the documentation, I then used :behaviour_type=>:controller. However,
> it failed again. It reported an error for me. For illustration, I'd like a
> simple example.
> module MyModule
>     def copy #an action method
>         render :partial=>"/index", :layout=>false
>     end
> end
>
> describe MyModule, :behaviour_type=>:controller do
>     it "should render partial index" do
>         get 'copy' #test code not provided yet, just want to get the action
>     end
> end
> The error reported was: undefined method 'new' for MyModule:Module. Do you
> guys have any idea of the error? And how should I test the action methods in
> modules?

The ControllerBehaviour is trying to instantiate MyModule. What you'd
need to do is something like this:

class ControllerThatUsesMyModule
  include MyModule
end

describe ControllerThatUsesMyModule, :behaviour_type=>:controller do
   it "should render partial index" do
       get 'copy' #test code not provided yet, just want to get the action
   end
end

I haven't tried it, but it seems like it should work. Give it a whirl
and report back please.

Cheers,
David

> Cheers!
>
>
> --
> View this message in context: http://www.nabble.com/Can-module-spec-%22behave-like%22-controller-spec--tf4358891.html#a12422548
> Sent from the rspec-users mailing list archive at Nabble.com.
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list