开发者

Rake test failing in test environment only

开发者 https://www.devze.com 2023-03-07 02:23 出处:网络
I am running \"rake test\" over my Rails 3.0.7 (Ruby 1.8.7) project via the command line. My rails app is a fairly basic out-the-box app, as I am still learning. E.g. my Gemfile is:

I am running "rake test" over my Rails 3.0.7 (Ruby 1.8.7) project via the command line.

My rails app is a fairly basic out-the-box app, as I am still learning. E.g. my Gemfile is:

source 'http开发者_运维问答://rubygems.org'
gem 'rails', '3.0.7'
gem 'sqlite3'

When I do this without specifying the environment, it works. I presume this is hitting development, as when I try and point at the development environment, it still works ! Also when I run "rake test:units" or "rake test:functionals" these work without error too.

However, when I run against the test environment, the unit tests fail to run ? I have tried this both from Rubymine IDE and command line with the same results.

The trace outputs look as follows - firstly plain "rake test" :

C:\Users\Ben\dev\railstest>rake test --trace
(in C:/Users/Ben/dev/railstest)
** Invoke test (first_time)
** Execute test
** Invoke test:units (first_time)
** Invoke test:prepare (first_time)
** Invoke db:test:prepare (first_time)
** Invoke db:abort_if_pending_migrations (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:abort_if_pending_migrations
** Execute db:test:prepare
** Invoke db:test:load (first_time)
** Invoke db:test:purge (first_time)
** Invoke environment
** Execute db:test:purge
** Execute db:test:load
** Invoke db:schema:load (first_time)
** Invoke environment
** Execute db:schema:load
** Execute test:prepare
** Execute test:units
Loaded suite C:/dev/lang/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader Started
.......................
Finished in 2.821289 seconds.

23 tests, 24 assertions, 0 failures, 0 errors
** Invoke test:functionals (first_time)
** Invoke test:prepare
** Execute test:functionals
Loaded suite C:/dev/lang/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader Started
.............
Finished in 3.34668 seconds.

13 tests, 25 assertions, 0 failures, 0 errors
** Invoke test:integration (first_time)
** Invoke test:prepare
** Execute test:integration

And now the failing run against the test environment

C:\Users\Ben\dev\railstest>rake environment RAILS_ENV=test test --trace
(in C:/Users/Ben/dev/railstest)
** Invoke environment (first_time)
** Execute environment
** Invoke test (first_time)
** Execute test
** Invoke test:units (first_time)
** Invoke test:prepare (first_time)
** Invoke db:test:prepare (first_time)
** Invoke db:abort_if_pending_migrations (first_time)
** Invoke environment
** Execute db:abort_if_pending_migrations
** Execute db:test:prepare
** Invoke db:test:load (first_time)
** Invoke db:test:purge (first_time)
** Invoke environment
** Execute db:test:purge
** Invoke test:functionals (first_time)
** Invoke test:prepare
** Execute test:functionals
Loaded suite C:/dev/lang/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader Started
.............
Finished in 3.328125 seconds.

13 tests, 25 assertions, 0 failures, 0 errors
** Invoke test:integration (first_time)
** Invoke test:prepare
** Execute test:integration
Errors running test:units!

There is no more text in the error message, and no further indication what the errors actually are. I have re-run db:schema:load on both sqlite3 environments and db:seed to populate a few database tables too, although the test data is loaded via fixtures normally.

I figure the problem here is trying to run unit tests against the test environment, but I can't understand why ?


When you run rake test all unit, functional, and integration tests are run in the test environment. From what you've shown, the tests are working exactly as expected. You don't need to explicitly tell rake to use the test environment - that is assumed.

0

精彩评论

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

关注公众号