Why is an integration test failing with "Test Error failing to assert “login_path”

70 views Asked by At

I am following MHartl tutorial and I have an integration test that fails yet the two other assertions based on the same page are passing.

The code I have is

 test "login with valid information followed by logout" do
    get login_path
    post login_path, params: { session: { email:    @user.email,
                                          password: 'password' } }
    assert is_logged_in?
    assert_redirected_to @user
    follow_redirect!
    assert_template 'users/show'
    assert_select "a[href=?]", login_path, count: 0
    assert_select "a[href=?]", logout_path
    assert_select "a[href=?]", user_path(@user)
    delete logout_path
    assert_not is_logged_in?
    assert_redirected_to root_url
    follow_redirect!
    assert_select "a[href=?]", login_path
    assert_select "a[href=?]", logout_path,      count: 0
    assert_select "a[href=?]", user_path(@user), count: 0
  end

The one assertion not working is

assert_select "a[href=?]", login_path

which raises the error

Expected at least 1 element matching "a[href="/login"]", found 0

However, the last two assertions are passing as expected.

assert_select "a[href=?]", logout_path,      count: 0
assert_select "a[href=?]", user_path(@user), count: 0

So if all three assertions test whether the logout redirects to the homepage, why are the two passing while the test for login_path is failing?

0

There are 0 answers