3

I am using Rspec, webrat, selenium rc for tests.

I am trying to do integration test with selenium and rspec.

I just looked in my development database and learned that my integration tests are using my development database and not my test database.

How an I configure rails and rspec and selenium to use my test database.

All my other tests seem to be using my test database.

3 Answers 3

16

Do you have a line like

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

in your spec_helper.rb? does it force the use of the test db if you add/replace it with

ENV["RAILS_ENV"] = 'test'

And could this be the root of your problem from yesterday - re email validation??

Sign up to request clarification or add additional context in comments.

4 Comments

Hey Chrispanda I changed my code to match yours above. This did not change the writing to the development database but I think that is how selenium works if I am running it from my system. It can't write to the test database as the tests are going through firefox. But I fixed the uniqueness problem by wiping out my database. This was the problem, I thought it was writing to my test db so I would do rake db:test:prepare and not rake db:reset. Ughhhh. Thank you.
Do you know how I can wipe out my development db after each test?
@MarnenLaibow-Koser - it's possible that a rails app uses an external data source populated by another app and the rails app is only an interface to that data. It's not always appropriate to use a test databse.
David: If it is appropriate to use a database in the first place, then it is always appropriate to have a test database. If the Rails app is only using an external data source, then it probably doesn't need a DB in the first place (and so different testing strategies will apply).
0

I faced the same issue (rspec tests running against development rather than test environment) while porting and Rails 2 app to Rails 3. Changing the line

ENV["Rails.env"] ||= 'test'

to

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

in spec_helper.rb fixed my issue.

I realize that RAILS_ENV has been deprecated in favor of Rails.env and suspect that something bad has been dragged over in the port forcing me to make this change.

There is also a good discussion of RAILS_ENV and Rails.env here which may provide some more insight:

Correct Ruby on Rails 3 replacement for ENV["RAILS_ENV"] ||= 'production'?

Comments

0

According to rspec-rails gem docs, put rspec-rails gem in the development and test groups of the Gemfile. This is because the test rake task loads development environment first before switching to test environment.

group :development, :test do
  gem 'rspec-rails'
end

References: https://github.com/rails/rails/issues/7175 , https://github.com/rails/rails/issues/8591 -- rspec loads development environment

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.