简体   繁体   中英

Rspec tests running in wrong environment?

I have an integraton test that is run using selenium. In my before each i build a few objects and index with solr. I can see the activity in my subnsspot solr test log. And then in my test I perform a search and get an error because my sunspot solr server isn't running. That's because it's running with RAILS_ENV = test.

Here's my before each:

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

And here is my test:

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

Any idea why the search is running in development environment and not test environment? I have ENV["RAILS_ENV"] ||= 'test' as the first line in my spec_helper.

I had this same issue. It turns out the Rails app I had running actually specified ENV["RAILS_ENV"] = 'development' in a configuration file (an Apache config file since we are using passenger).

If this is the case for you, then you can replace

ENV["RAILS_ENV"] ||= 'test' 

with

ENV["RAILS_ENV"] = 'test'

in your spec_helper.

I did that since

  1. we don't have RSpec on our production machines and
  2. we don't run tests in production.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM