问题
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.
回答1:
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??
回答2:
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'?
回答3:
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
来源:https://stackoverflow.com/questions/6595682/rspec-test-using-regular-database-not-test-database