【发布时间】:2014-01-13 16:59:31
【问题描述】:
如何编写用于多个集成测试的集成测试助手?我已经尝试了以下错误。我正在考虑创建一个基类并对其进行扩展,但我不明白“test_helper”是如何工作的!我不能将辅助方法放在 test_helper 中,因为它们使用特殊的集成辅助方法,例如 post_with_redirect。
LS
$ ls test/integration
integration_helper_test.rb post_integration_test.rb user_flows_test.rb
代码,integration_helper_test.rb
class IntegrationHelperTest < ActionDispatch::IntegrationTest
def login(user)
...
代码,post_integration_test.rb
require 'test_helper'
require 'integration_helper_test'
# require 'integration/integration_helper_test'
class PostIntegrationTest < ActionDispatch::IntegrationTest
# include IntegrationHelperTest
错误
$ 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
代码,post_integration_test.rb
require 'test_helper'
# require 'integration_helper_test'
require 'integration/integration_helper_test'
class PostIntegrationTest < ActionDispatch::IntegrationTest
错误
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>'
代码,post_integration_test.rb
require 'test_helper'
# require 'integration_helper_test'
#require 'integration/integration_helper_test'
class PostIntegrationTest < ActionDispatch::IntegrationTest
include IntegrationHelperTest
错误
$ 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!
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-4 integration-testing