开发者

rspec test using regular database not test database

I am using Rspec,开发者_JAVA技巧 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.


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


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜