我有一个使用 Selenium 运行的集成测试。在我之前,我用 solr 构建了一些对象和索引。我可以在 subnsspot solr 测试日志中看到事件。然后在我的测试中,我执行搜索并得到一个错误,因为我的太阳黑子 solr 服务器没有运行。那是因为它使用 RAILS_ENV = test 运行。
这是我之前的每一个:
before :each do
Sunspot.remove_all!(Residential)
Sunspot.commit
@prop1 = FactoryGirl.create(:residential, { subdivision: "Steiner Ranch", street_name: "propone" })
@prop1.index!
@prop2 = FactoryGirl.create(:residential, { subdivision: "Jester Estates", street_name: "proptwo" })
@prop2.index!
@prop3 = FactoryGirl.create(:residential, { subdivision: "Cypress Ranch", street_name: "propthree" })
@prop3.index!
end
这是我的测试:
it "single word", :js => true do
visit '/'
fill_in 'subdivision', :with => 'cypress'
page.should_not have_content('propone')
page.should_not have_content('proptwo')
page.should have_content('propthree')
end
知道为什么搜索在开发环境而不是测试环境中运行吗?我有 ENV["RAILS_ENV"] ||= 'test' 作为我的 spec_helper 中的第一行。
最佳答案
我有同样的问题。事实证明,我运行的 Rails 应用程序实际上在配置文件中指定了 ENV["RAILS_ENV"] = 'development' (Apache 配置文件,因为我们使用的是乘客)。
如果您是这种情况,那么您可以更换
ENV["RAILS_ENV"] ||= 'test'
和
ENV["RAILS_ENV"] = 'test'
在您的 spec_helper 中。
我是这样做的
关于ruby-on-rails - Rspec 测试在错误的环境中运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12762267/