def setup
@user = users(:little)
end
test "login with valid information" do
get login_path
post login_path, params: { session: { email: @user.email,
password: 'password' } }
assert_redirected_to @user
follow_redirect!
assert_template 'users/show'
assert_select "a[href=?]", login_path, count: 0
assert_select "a[href=?]", logout_path, count: 1
assert_select "a[href=?]", user_path(@user), count: 1
end
def setup
@user = User.first
end
test "login with valid information" do
get login_path
post login_path, params: { session: { email: @user.email,
password: '111111' } }
assert_redirected_to @user
follow_redirect!
assert_template 'users/show'
assert_select "a[href=?]", login_path, count: 0
assert_select "a[href=?]", logout_path, count: 1
assert_select "a[href=?]", user_path(@user), count: 1
end
第一个是书上给的,第二个是我改了之后的,第二个测试无法通过,说是希望重定向,结果得到的是成功,但是把正确的密码'111111'改成'password' 测试竟然神奇的可以通过,书上说约定固件的密码为'password',应该和这没关系吧?为啥啊?
Failure: UsersLoginTest#test_login_with_valid_information [/home/yirolhao/ruby/project/rails/my-first-app/test/integration/users_login_test.rb:35]: Expected response to be a <3XX: redirect>, but was a <200: OK>