I'm working through the tutorial at Railstutorial.org and am in the middle of Chapter 8 where I'm trying to utilize a test_helper.rb
file which is located in
/test/test_helper.rb.
I have several tests running, one of which is calling a method I've defined in the test_helper.rb
file.
Full test_helper.rb
code:
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require "minitest/reporters"
Minitest::Reporters.use!
class ActiveSupport::TestCase
fixtures :all
# Returns true if a test user is logged in
def is_logged_in?
!session[:user_id].nil?
end
end
My actual test file is located in:
/test/integration/users_signup_test.rb
With partial code:
require 'test_helper'
class UsersSignupTest < ActionDispatch::IntegrationTest
test "valid signup information" do
get signup_path
assert_difference 'User.count', 1 do
post_via_redirect users_path, user: { name: "Example User",
email: "user@example.com",
password: "password",
password_confirmation: "password" }
end
assert_template 'users/show'
#relevant call to method
assert is_logged_in?
end
end
If I include the method in the actual test file itself everything works fine, but if I try to run a full suite of tests (rake test
) I get the following error message indicating it can't use my helper method is_logged_in?
NoMethodError: undefined method `is_logged_in?' for #<UsersSignupTest:0x000000075cd530>
I'm new to Rails, but is there a reason it can't find the method in my test_helper.rb
file?
I should note that everything technically works fine in Prod, and no actual failures occur in the test, just an error.
Aucun commentaire:
Enregistrer un commentaire