Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 308
kidbrax Avatar asked Oct 06 '12 17:10

kidbrax


1 Answers

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.
like image 52
webdevguy Avatar answered Oct 08 '22 13:10

webdevguy