开发者

Problem using `rake test`

I wonder how to setup testing in my rails apps. When I run rake test, first thing odd, it launch a bunch of CREATE TABLE against my dev. database (hum.. do not like this..). So I launch rake test RAILS_ENV=test and I even try bundle exec rake test RAILS_ENV=test. Now, the CREATE TABLE is against my test database but all fails with this error :

** Execute test:units
test/unit/category_test.rb:5:in `test': unknown command 't' (ArgumentError)
    from test/unit/category_test.rb:5:in `<class:CategoryTest>'

I have used basic generator in Rails 3 and do not change anything. So I have this in caterogy_test.rb :

require 'test_helper'

class CategoryTest < ActiveSupport::TestCase
   # Replace this with your real tests.

   test "the truth" do
       assert true
   end
end

I use Rails 3.0.7 and basic config.

Any ideas ?

EDIT

I am becoming crazy, made a lot of tries, neither seems to work. When I start a new application with a few things, rake test works fine but when I try this on my current one, it launch always against my dev. db and do not work at all. I have tried to edit the test files, to revert them back, try to remove/setup test db with different ways, try different rake version, compare a lot of things on one side my current application and on the other a brand new one... Found nothing.. Help !

EDIT 2

Sounds lame, but is it normal that rake does the same thing than rake test ?

EDIT 3

Sounds odds, while I continue to work on what's wrong, I realize that every-time I run rake test, it does stuff on the dev environment and not the test one (watching the logs). It does this on my computer OSX and on our server FreeBSD for all the Rails 3.0.7 apps. Are you sure rake test is supposed to work on the test envi开发者_运维问答ronment by default ?

EDIT 4

Please help!

EDIT 5 - SUMMARY

When running rake test in my computer or on our server in Rails 3.0.7 with different apps it does the following :

  • run CREATE TABLE and INSERT INTO migration against the dev. db.
  • do not empty the dev. db.
  • development.log gets written not the test.log
  • also an issue with the error unknowm comman 't' with one specific app.

EDIT 6 - db config

Nothing change from the default yet : https://gist.github.com/1006199

EDIT 7

rake db:test:prepare --trace -> nothing break (but keep printing (first_time) https://gist.github.com/1007340

With RAILS_ENV="test" for rake, everything goes fine. It write on the test logs.

ruby -I test test/unit/category_test.rb same erros than with rake, but no write on the dev. or test logs.


a bunch of unorderd answers:

  • the "CREATE TABLE" statements usually means that your test_db is created from scratch (by default, before test task, a db:migrate is launched). are you sure they're called on dev_db? also check your config/database.yml to see if there's some typo (eg: using same table for test and dev environments)

  • it looks like there's an error in some of your migration files (that 't' error remember blocks in migrations).

  • "rake test" is the default task, that's why it's run when you just launch "rake" without arguments.

EDIT:

according on what I see on edits, from 5 and above, it looks like you have some issue with environment files. so try to double-check: * config/environments/test.rb * config/application.rb * config/environment.rb

if with RAILS_ENV="test", everything goes fine, then I'm almost sure you have changed some default behaviour in your app (configs, env variables, any particular gem?)

also, in your test/test_helper.rb, add RAILS_ENV='test' at the beginning of file, this should force test environment.


I had that same error message, except to me it said: in `test': unknown command 'i' (ArgumentError). The 'fix' or 'workaround' was to simply use:

$> bundle exec rake test

instead of using 'rake test'

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜