Doing last exercise of chapter 10, wild NoMethodError has appeared in listing 10.62 test
test/integration/users_index_test.rb
require 'test_helper'
class UsersIndexTest < ActionDispatch::IntegrationTest
def setup
@admin = users(:michael)
@non_admin = users(:archer)
end
test "index as admin including pagination and delete links" do
log_in_as(@admin)
get users_path
assert_template 'users/index'
assert_select 'div.pagination'
first_page_of_users = User.paginate(page: 1)
first_page_of_users.each do |user|
assert_select 'a[href=?]', user_path(user), text: user.name
unless user == @admin
assert_select 'a[href=?]', user_path(user), text: 'delete'
end
end
assert_difference 'User.count', -1 do
delete user_path(@non_admin)
end
end
test "index as non-admin" do
log_in_as(@non_admin)
get users_path
assert_select 'a', text: 'delete', count: 0
end
end
test error
ERROR["test_index_as_admin_including_pagination_and_delete_links", UsersIndexTest, 0.8833864140324295]
test_index_as_admin_including_pagination_and_delete_links#UsersIndexTest (0.88s)
NoMethodError: NoMethodError: undefined method `email' for nil:NilClass
test/test_helper.rb:31:in `log_in_as'
test/integration/users_index_test.rb:11:in `block in <class:UsersIndexTest>'
Any ideas what could be missed here? Many thanks!
Aucun commentaire:
Enregistrer un commentaire