我對RSpec仍然很熟悉,並且在爲我的多租戶應用設置測試時遇到了一些問題。多租戶和rspec
的應用程序工作在:
client1.example.com
client2.example.com
等....
在我的RSpec的我做了以下內容:
let(:tenant) { FactoryGirl.create(:tenant, subdomain: "client1") }
let(:root_path) { "http://client1.example.dev:3000" }
before {
tenant.save
visit root_path
}
describe "header" do
it "should have the right title" do
page.should have_selector('title', :text => tenant.name)
end
end
我在做一些在這裏感覺不對的東西,但不知道什麼是最好的方法是。
我很難編碼root_path。像
visit '/'
這樣的操作不起作用,因爲測試不知道什麼是正確的子域。這個可以嗎?我不知道爲什麼,但我必須在每次測試前做tenant.save,以便測試實際能夠根據子域找到租戶。如果我刪除tenant.save,我得到一個
Couldn't find Tenant with subdomain = client1
錯誤。我以爲FactoryGirl.create實際上保存到數據庫?
感謝您的幫助!
太棒了 - 謝謝! – cman77