我是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