ruby-on-rails - Rspec 测试在错误的环境中运行?

标签 ruby-on-rails selenium solr rspec sunspot

我有一个使用 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 中。

我是这样做的
  • 我们的生产机器上没有 RSpec 和
  • 我们不在生产中运行测试。
  • 关于ruby-on-rails - Rspec 测试在错误的环境中运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12762267/

    相关文章:

    java - Solr复制字段复制到另一个字段

    solr - Solr 中的条件 FilterQuery

    ruby-on-rails - 删除 Rails 应用并将其重新部署到 heroku

    python - 检查元素是否存在,如果不存在则执行 ..

    java - org.openqa.selenium.NoSuchElementException 无法定位元素 :method":"link text" ,"selector":"http://

    java - selenium webdriver 的意外行为

    ruby-on-rails-3 - 太阳黑子 : boost scalar fields

    ruby-on-rails - 使用引擎时如何找到模型中的资源路径?

    ruby-on-rails - postgresql中的数据库连接超时错误

    ruby-on-rails - ruby 任务调度程序