我可以在集成测试中使用多个虚拟应用吗?我想在另一个应用程序的某些测试中在一个应用程序中运行一些集成测试。
原因是我有一个可以在常规Rails应用程序和引擎中运行的gem,所以我想测试这两种情况。
关于如何实现这一目标的任何想法?
答案 0 :(得分:0)
应该可以直接实现。这是标准# Configure Rails Environment
ENV["RAILS_ENV"] = "test"
require File.expand_path("../../test/dummy/config/environment.rb", __FILE__)
ActiveRecord::Migrator.migrations_paths = [File.expand_path("../../test/dummy/db/migrate", __FILE__)]
require "rails/test_help"
Rails.backtrace_cleaner.remove_silencers!
# Load support files
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
# Load fixtures from the engine
if ActiveSupport::TestCase.method_defined?(:fixture_path=)
ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
end
:
test_helper
所以只需创建两个require "rails/test_help"
Rails.backtrace_cleaner.remove_silencers!
# Load support files
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
# Load fixtures from the engine
if ActiveSupport::TestCase.method_defined?(:fixture_path=)
ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
end
文件:
<强> test_helper_common.rb 强>
ENV["RAILS_ENV"] = "test"
require File.expand_path("../../test/dummy1/config/environment.rb", __FILE__)
ActiveRecord::Migrator.migrations_paths = [File.expand_path("../../test/dummy1/db/migrate", __FILE__)]
require __dir__ + 'common'
<强> test_helper_1.rb 强>
ENV["RAILS_ENV"] = "test"
require File.expand_path("../../test/dummy2/config/environment.rb", __FILE__)
ActiveRecord::Migrator.migrations_paths = [File.expand_path("../../test/dummy2/db/migrate", __FILE__)]
require __dir__ + '/common'
<强> test_helper_2.rb 强>
require 'test_helper_1'
然后在测试中只需require 'test_helper_2'
或MyMachine
。