阅读MiniTest失败的消息

时间:2014-12-10 07:31:22

标签: ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-4 minitest

我的测试失败了,我似乎无法正确阅读它。你会怎么读这个:

FAIL["test_password_resets", PasswordResetsTest, 0.310017]
   test_password_resets#PasswordResetsTest (0.31s)
          expecting <"password_resets/new"> but rendering with <[]>
          test/integration/password_resets_test.rb:15:in `block in <class:PasswordResetsTest>'

    1/1: [===================================] 100% Time: 00:00:00, Time: 00:00:00

  Finished in 0.31430s
  1 tests, 1 assertions, 1 failures, 0 errors, 0 skips

我将在哪里修复错误?它真的不会给我更多的测试表上的行号。但这并没有真正帮助我找到最终的解决方案。

以下是测试:

    test "password resets" do
    get new_password_reset_path
    assert_template 'password_resets/new'
    # invalid email
    post password_resets_path, password_reset: { email: "" }
    assert_not flash.empty?
    assert_template 'password_resets/new'
    # valid email
    post password_resets_path, password_reset: { email: @user.email }
    assert_not_equal @user.reset_digest, @user.reload.reset_digest
    assert_equal 1, ActionMailer::Base.deliveries.size
    assert_not flash.empty?
    assert_redirected_to root_url
    # password reset form
    user = assigns(:user)
    # wrong email
    get edit_password_reset_path(user.reset_token, email: "")
    assert_redirected_to root_url
    # inactive user
    user.toggle!(:activated)
    get edit_password_reset_path(user.reset_token, email: user.email)
    assert_redirected_to root_url
    user.toggle!(:activated)
    # right email, wrong token
    get edit_password_reset_path('wrong token', email: user.email)
    assert_redirected_to root_url
    # right email, right token
    get edit_password_reset_path(user.reset_token, email: user.email)
    assert_template 'password_resets/edit'
    assert_select "input[name=email][type=hidden][value=?]", user.email
    # invalid password & confirmation
    patch password_reset_path(user.reset_token),
          email: user.email,
          user: { password:              "foobaz",
                  password_confirmation: "barquux" }
    assert_select 'div#error_explanation'
    # blank password & confirmation
    patch password_reset_path(user.reset_token),
          email: user.email,
          user: { password:              "  ",
                  password_confirmation: "  " }
    assert_not flash.empty?
    assert_template 'password_resets/edit'
    # valid password & confirmation
    patch password_reset_path(user.reset_token),
          email: user.email,
          user: { password:              "foobaz",
                  password_confirmation: "foobaz" }
    assert is_logged_in?
    assert_not flash.empty?
    assert_redirected_to user
  end

第15行是“assert_template'password_resets / new'”第一个,技术上是第3行。

提前谢谢。

1 个答案:

答案 0 :(得分:1)

不要声明模板已呈现,而是尝试声明响应符合您的预期,然后然后断言模板是正确的。

assert_response :success
assert_template 'password_resets/new'

我怀疑请求被重定向,而不会呈现模板。