为什么集成测试失败并显示“测试错误未能断言“ login_path”

时间:2019-06-04 12:03:40

标签: ruby ruby-on-rails-5 railstutorial.org

我正在遵循MHartl教程,并且我进行了一次集成测试,但该测试失败了,但基于同一页面的另外两个断言却通过了。

我的代码是

 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

一个断言不起作用

assert_select "a[href=?]", login_path

这会引发错误

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

但是,最后两个声明正在按预期方式通过。

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

因此,如果所有三个断言都测试注销是否重定向到主页,为什么在 login_path 的测试失败时,两个通过?

0 个答案:

没有答案
相关问题