[rspec-users] HowTo Specify A Method is Called Within A Controller's Action

David Chelimsky dchelimsky at gmail.com
Sat May 16 10:29:36 EDT 2009


On Sat, May 16, 2009 at 1:08 AM, Lee Longmore <lee_longmore at yahoo.co.uk> wrote:
>
> I am new to RSpec and would appreciate some pointers on how to specify the
> following for my Rails application...
>
> I have a controller called ContextsController and, within this, the usual
> 'create' method. The first line of this method should be:
>
> @member = logged_in_member
>
> where logged_in_member is a method that, for simplicity's sake, is a private
> method of the ContextsController and retrieves a Member model object based
> on the user_id in the session. I haven't written this method yet so would
> like to stub it out for now.
>
> What might an Example look like to spec this expected behaviour?
>
> In particular, I can't work out how to specify that logged_in_member is
> called.

member = stub_model(Member)
controller.should_receive(:logged_in_member).and_return(member)
get :action

HTH,
David

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


More information about the rspec-users mailing list