Rspec Rails - Mock will be current_user to check controller

I started writing tests for my controllers. For one of them, I need to log in to check if the page is displayed, etc.

Since I use Devise, which has a current_user helper on the user model, how can I form my own:

describe "when it GETS 'town'" do it "should render the template and be successful" do get :index response.should render_template(:index) response.should be_success end end 

so that I don't get undefined authentication! "method (develop specific) error?

+4
source share
1 answer

There's a good post on this topic on the Devify wiki . Basically you need to add Devise test helpers and then call sign_in to get the actual current user when your spec expects it.

+14
source

Source: https://habr.com/ru/post/1341488/


All Articles