I added test/helpers/test_helper.rb file (which wasn't there by default) with this content and the method is_logged_in?:
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
# use minitest report
require 'minitest/reporters'
Minitest::Reporters.use!
class ActiveSupport::TestCase
fixtures :all
# Add more helper methods to be used by all tests here...
def is_logged_in?
!session[:user_id].nil?
end
end
, but when I use it in integration test - test/integrations/user_signup_test.rb:
require 'test_helper'
class UsersSignupTest < ActionDispatch::IntegrationTest
test "valid signup" do
....
assert is_logged_in?
....
end
end
and run rake test, it says :
UsersSignupTest#test_valid_signup: NoMethodError: undefined method is_logged_in?' for #<UsersSignupTest:0x000000060becc0> test/integration/users_signup_test.rb:30:in block in <class:UsersSignupTest>'
Aucun commentaire:
Enregistrer un commentaire