Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/52.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
Ruby on rails Rspec-Elasticsearch自动回调在(:all)之前运行,但不在(:each)之前运行_Ruby On Rails_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Rspec - Fatal编程技术网 elasticsearch,rspec,Ruby On Rails,elasticsearch,Rspec" /> elasticsearch,rspec,Ruby On Rails,elasticsearch,Rspec" />

Ruby on rails Rspec-Elasticsearch自动回调在(:all)之前运行,但不在(:each)之前运行

Ruby on rails Rspec-Elasticsearch自动回调在(:all)之前运行,但不在(:each)之前运行,ruby-on-rails,elasticsearch,rspec,Ruby On Rails,elasticsearch,Rspec,当我在rspec中的before(:all)中创建记录时,也会创建索引,但它在before(:each)中不起作用。为什么会这样 例如: 我使用elasticsearch模型gem触发自动回调 如果我这样做 describe "#update_company_indexes" do before(:all) do Company.__elasticsearch__.create_index! force: true FactoryGirl.create(:company)

当我在rspec中的before(:all)中创建记录时,也会创建索引,但它在before(:each)中不起作用。为什么会这样

例如:

我使用elasticsearch模型gem触发自动回调

如果我这样做

describe "#update_company_indexes" do
  before(:all) do
    Company.__elasticsearch__.create_index! force: true
    FactoryGirl.create(:company)
  end
end
只要执行了FactoryGirl.create(:company),就会创建公司索引


但是相同的代码以前不起作用(:each)。

您能提供一些代码吗?嗨,伊利亚,对问题进行了更改。您能提供一些代码吗?嗨,伊利亚,对问题进行了更改