vendredi 23 juin 2017

Failing test from Hartl's book [Chapter 8]

I'm on chapter 8 of Hartl's book Ruby on Rails and I'm getting a failed test that I can really figure out.

The error:

sample_app/test/integration/users_login_test.rb:43]:
Expected true to be nil or false

This is the test itself from integration/user_login_test.rb:

  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 line being pointed out:

assert_not is_logged_in?

The above method comes from a test helper test/test_helper.rb:

class ActiveSupport::TestCase
  fixtures :all

  # Returns true if a test user is logged in.
  def is_logged_in?
    !session[:user_id].nil?
  end
end

And here are my fixtures:

michael:
  name: Michael Example
  email: michael@example.com
  password_digest: <%= User.digest('password') %>

Any advice would be greatly appreciated. I can't figure out what i'm doing wrong.

Aucun commentaire:

Enregistrer un commentaire