i've started writing tests for my controllers. For once of them, i need to be logged in, in order to check whether the page is rendered etc.
Since i'm using Devise that has a current_user helper over a User model, how can i form my :
开发者_如何学Pythondescribe "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 the undefined "authenticate!" method (devise specific) error ?
There's a good writeup on this topic on the Devise wiki. Basically you need to add the Devise test helpers, then call sign_in
to get a valid current user when your spec expects one.
精彩评论