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.

chell
  • 7,646
  • 16
  • 74
  • 140

3 Answers3

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??

chrispanda
  • 3,204
  • 1
  • 21
  • 23
  • 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. – chell Jul 07 '11 at 02:36
  • Do you know how I can wipe out my development db after each test? – chell Jul 07 '11 at 02:36
  • @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 Ryder Nov 14 '11 at 21:33
  • 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). – Marnen Laibow-Koser Nov 14 '11 at 22:08
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'?

Community
  • 1
  • 1
benmac
  • 103
  • 7
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

konyak
  • 10,818
  • 4
  • 59
  • 65