Reputation: 4056
I'm new to testing rails applications as I usually just do manual testing... but I'm trying to do it the right way this time.
Why is this basic test failing?
test "once you go to to app you are asked to sign in" do
get "/"
assert_redirected_to "/users/sign_in"
assert_select "title", "Home Sign-In"
end
The first assertion is successful but not the second. The title seems correct when I view source.
<title>Home Sign-In</title>
Upvotes: 0
Views: 103
Reputation: 1775
@Pavel is right. A simple way to check the response after get request is @response.body. So in your case
test "once you go to to app you are asked to sign in" do
get "/"
assert_redirected_to "/users/sign_in"
byebug #print @response.body here. At this point @response.body will
# be "You are being redirected to /users/sign_in".
assert_select "title", "Home Sign-In"
end
So you can modify it as Pavel has suggested
test "sign in page title is correct" do
get "/users/sign_in"
assert_select "title", "Home Sign-In"
end
Upvotes: 0
Reputation: 371
If you have redirect call in your controller method it is not acturally rendered. That's why you can't use assert_select
.
You may try to divide your test case into two:
test "once you go to to app you are asked to sign in" do
get "/"
assert_redirected_to "/users/sign_in"
end
test "sign in page title is correct" do
get "/users/sign_in"
assert_select "title", "Home Sign-In"
end
Upvotes: 2