[rspec-users] how to stub the :current_user and any methods associated with it

Shane Mingins smingins at elctech.com
Sun Apr 13 16:50:25 EDT 2008


Looking at yr earlier post ...

controller.stub!(:entries).and_return(@entry)

Not sure why you are stubbing entries on the controller ... entries is  
called on the current user ...

I tend to do this ...

@current_user = mock_model(User, :id => 1, :entries => [@entry])

HTH
Shane

On 13/04/2008, at 7:24 AM, newbie wrote:

> Hey Jarkko,
>
> Thanks for the feedback. I tried your suggestion and it doesn't seem
> to work.
>
> To quickly recap I'm just testing in my controller that this works
>
> def index
> @entries = current_user.entries
> end
>
> describe "on the main page" do
> it "should show all the current entries for the user" do
>    get :index
>    assigns[:entries].should == @entries
> end
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users




More information about the rspec-users mailing list