简体   繁体   中英

assert_template error in my test. What kind of test is assert_template anyway?

Here is my test, similar to the mailer test from the Hartl tutorial:

  test "valid signup information with account activation" do
    get new_user_path
    assert_difference 'User.count', 1 do
      post users_path, user: { username:  "Jwan622",
                               first_name: "Jeffrey",
                               last_name: "Wan",
                               email: "Jwan622@yahoo.com",
                               password:              "password",
                               password_confirmation: "password",
                               city: "New York City",
                               state: "New York",
                               country: "United States"
                              }
    end
    assert_equal 1, ActionMailer::Base.deliveries.size
    user = assigns(:user)
    assert_not user.activated?
    log_in_as(user)
    assert_not is_logged_in?
    # Invalid activation token
    get edit_account_activation_path("invalid token")
    assert_not is_logged_in?
    # Valid token, wrong email
    get edit_account_activation_path(user.activation_token, email: 'wrong')
    assert_not is_logged_in?
    # Valid activation token
    get edit_account_activation_path(user.activation_token, email: user.email)
    assert user.reload.activated?
    follow_redirect!
    assert_template 'root_path'
    assert is_logged_in?
end

Here is my error message:

1) Failure:
UserSignupTest#test_valid_signup_information_with_account_activation [/Users/Jwan/Dropbox/Turing/projects/FlyAwayFromHere/test/integration/user_signup_test.rb:94]:
expecting <"root_path"> but rendering with <["layouts/_praise_bar", "layouts/_city_change", "planners/new", "layouts/_nav_bar", "layouts/_footer_bar", "layouts/application"]>

Questions:
1) What kind of test is assert_template? Is it minitest? capybara?
2) What kind of method is get? Is it a rack method that works in rails?
3) What does "assigns" do?
4) What am I doing wrong with this assert_template?

Change it to assert_template :new to make it work; this is testing that the new.html.erb was rendered.

See http://guides.rubyonrails.org/testing.html#testing-templates-and-layouts for more about assert_template and testing views in general.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM