Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
多租户和rspec_Rspec_Factory Bot_Multi Tenant - Fatal编程技术网

多租户和rspec

多租户和rspec,rspec,factory-bot,multi-tenant,Rspec,Factory Bot,Multi Tenant,我仍然很熟悉w/RSpec,在为我的多租户应用程序设置测试时遇到了一些问题 该应用程序在以下位置工作: client1.example.com client2.example.com 等等 在我的RSpec中,我做了以下工作: let(:tenant) { FactoryGirl.create(:tenant, subdomain: "client1") } let(:root_path) { "http://client1.example.dev:3000" } before { ten

我仍然很熟悉w/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
我在这里做了一些感觉不对的事情,但不确定最好的方法是什么

  • 我正在硬编码根路径。像
    visit'/'
    这样的操作不起作用,因为测试不知道正确的子域是什么。这样行吗

  • 我不知道为什么,但我必须在每次测试之前执行tenant.save,以便测试能够根据子域找到租户。如果我删除tenant.save,我会得到一个
    找不到subdomain=client1的租户的错误。我以为FactoryGirl.create真的保存到数据库了


  • 谢谢你的帮助

    1:似乎这是必要的,我认为没有办法只指定子域

    2:是,
    create
    保存到数据库中(而
    build
    不保存)。然而,RSpec的
    let
    是惰性的——它只在第一次调用时进行计算

    这意味着如果没有
    tenant.save
    ,则在
    page.should\u selector('title',:text=>tenant.name)
    发生之前不会创建租户-在
    visit
    调用之后,为时已晚

    幸运的是,RSpec还提供了
    let
    是一个急切版本的
    let
    ,因此如果您使用它,您将不需要
    租户。请在
    之前的
    块中保存