Do Rspec tests work in the wrong environment?

I have an integral test that runs using selenium. In mine, in front of each I build several objects and an index with solr. I can see activity in my subnsspot solr test log. And then in my test, I search and get an error message because my sunspot solr server is not working. This is because it works with RAILS_ENV = test.

Here are mine 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 done in a development environment and not in a test environment? I have an ENV ["RAILS_ENV"] || = 'test' as the first line in my spec_helper.

+4
source share
1 answer

I had the same problem. It turned out that the Rails application I was working on actually indicated ENV ["RAILS_ENV"] = 'development' in the configuration file (Apache configuration file, since we are using the passenger).

If so, you can replace

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

with

 ENV["RAILS_ENV"] = 'test' 

in your spec_helper.

I have done it since

  • We do not have RSpec on our production machines and
  • We do not run tests during production.
+8
source

Source: https://habr.com/ru/post/1438183/


All Articles