How do I write an integration test helper that is used amongst several integration tests? I've tried the following with the following errors. I'm considering making a base class and extending that, but I don't understand how 'test_helper' is working! I can't put the helper methods in test_helper because they use special integration helpers like post_with_redirect
.
LS
$ ls test/integration
integration_helper_test.rb post_integration_test.rb user_flows_test.rb
Code, integration_helper_test.rb
class IntegrationHelperTest < ActionDispatch::IntegrationTest
def login(user)
...
Code, post_integration_test.rb
require 'test_helper'
require 'integration_helper_test'
# require 'integration/integration_helper_test'
class PostIntegrationTest < ActionDispatch::IntegrationTest
# include IntegrationHelperTest
Error
$ rake
rake aborted!
cannot load such file -- integration_helper_test
C:/Users/Chloe/workspace/SeenIt/test/integration/post_integration_test.rb:2:in `<top (required)>'
Tasks: TOP => test:run => test:integration
Code, post_integration_test.rb
require 'test_helper'
# require 'integration_helper_test'
require 'integration/integration_helper_test'
class PostIntegrationTest < ActionDispatch::IntegrationTest
Error
1) Error:
PostIntegrationTest#test_should_create_post:
NoMethodError: undefined method `login' for #<PostIntegrationTest:0x3da81d0>
test/integration/post_integration_test.rb:20:in `block in <class:PostIntegrationTest>'
Code, post_integration_test.rb
require 'test_helper'
# require 'integration_helper_test'
#require 'integration/integration_helper_test'
class PostIntegrationTest < ActionDispatch::IntegrationTest
include IntegrationHelperTest
Error
$ rake
rake aborted!
wrong argument type Class (expected Module)
C:/Users/Chloe/workspace/SeenIt/test/integration/post_integration_test.rb:6:in `include'
C:/Users/Chloe/workspace/SeenIt/test/integration/post_integration_test.rb:6:in `<class:PostIntegrationTest>'
C:/Users/Chloe/workspace/SeenIt/test/integration/post_integration_test.rb:5:in `<top (required)>'
Tasks: TOP => test:run => test:integration
test_helper.rb
ENV["RAILS_ENV"] ||= "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
class ActiveSupport::TestCase
ActiveRecord::Migration.check_pending!