我是Minitest和Apartment的新成员,难以正确配置环境来运行测试用例。我想使用Capybara & Selen进行验收测试。当我运行我的测试时,我收到以下错误消息:如何测试Apartment,Minitest,水豚和硒
Apartment::TenantNotFound: Apartment::TenantNotFound: One of the following schema(s) is invalid: "test-tenant" "public"
因此看起来租户没有正确创建。 Apartment gem提供了如何与Rspec一起使用的说明,但我不知道如何在Minitest中进行类似的设置。租户如何定义Minitest可以看到他们?
我test_helpers.rb:
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require "minitest/reporters"
require "minitest/rails/capybara"
Minitest::Reporters.use!
class ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
fixtures :all
end
class ActionController::TestCase
include Devise::TestHelpers
end
class ActionDispatch::IntegrationTest
end
而且测试用例:
require "test_helper"
class LoginTest < Capybara::Rails::TestCase
def setup
Apartment::Tenant.drop("test-tenant") rescue nil
Apartment::Tenant.create("test-tenant") rescue nil
Apartment::Tenant.switch!("test-tenant")
# Since we are using Apartment gem, we need to tell Capybara to connect our testing tenant URL + port number
Capybara.server_port = 5000
Capybara.always_include_port = true
Capybara.app_host = "http://test-tenant.lvh.me"
end
feature "Login" do
scenario "with correct credentials", js: true do
visit '/accounts/sign_in'
fill_in("account[email]", with: "#{accounts(:tenant_user).email}")
fill_in("account[password]", with: "password")
click_button("Sign in")
page.must_have_content("Signed in successfully.")
visit '/'
page.must_have_content("Welcome")
end
end
end
这种方法是否足够好,可以加速使用minitest进行轨道测试?我在与minitest测试公寓的过程中度过了一段可怕的时光,因为每次调用测试方法时都必须创建租户。 – artificis
我的观点是,按照你的方法,租户只在一个测试周期内创建一次?还是在每个测试用例之前创建? – artificis
租户只创建一次。然后,它将运行所有迁移以为租户创建表。 – talakoski