[rspec-users] problem with rspec_on_rails and @controller.should_receive(:render) in trunk

David Chelimsky dchelimsky at gmail.com
Thu Apr 19 10:57:02 EDT 2007


On 4/19/07, David Chelimsky <dchelimsky at gmail.com> wrote:
> On 4/19/07, Marcus Ahnve <marcus at ahnve.com> wrote:
> > On 4/18/07, David Chelimsky <dchelimsky at gmail.com> wrote:
> > > [...]
> > > FYI - Chris says the error is:
> > >
> > > <UsersController:0x323fe94> expected :render with ({:layout=>false})
> > > but received it with (no args)
> >
> > I am seeing this as well.
> >
> > I am running a spec like:
> >
> >    it "should use application layout" do
> >      @controller.should_receive(:render).with(:layout => "/layouts/application")
> >      get 'index'
> >    end
> >
> > If I change the spec to fail on purpose by for example changing the
> > expected layout name, I get the correct behaviour. The 'no args' thing
> > appears when the spec passes.
>
> OK - I'm getting somewhere with this. What happens is that render is
> actually called twice. So if you do this:
>
> it "should use application layout" do
>   controller.should_receive(:render).with(:layout => "/layouts/application")
>   controller.should_receive(:render).with(:no_args)
>   get 'index'
> end
>
> ... then the spec will pass.
>
> The problem is really one of feedback, IMO. The mock should tell you
> "hey, you said I should expect a single call w/ these args, but I got
> another one with these other args". Right now it's not telling you
> that your expectation was met AND there was a problem - just that
> there was a problem.
>
> Thoughts?

Afterthought - the original post in this thread said that this problem
appeared recently. I'm not 100% certain, but I think this is due to a
recent change to how Spec::Rails deals with #rescue_action. It used to
just catch everything. Now it lets you define the rescue_action in
your controller specs and ensures that mock errors are not caught
regardless of what you define. So rspec was actually hiding this
problem from you in the past, but is now shining a light on it (as it
should have all along). Make sense?

>
> >
> > /Marcus
> > _______________________________________________
> > rspec-users mailing list
> > rspec-users at rubyforge.org
> > http://rubyforge.org/mailman/listinfo/rspec-users
> >
>


More information about the rspec-users mailing list