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