Problem using `rake test`

I am wondering how to set up testing in my rails applications. When I run rake test , the first thing that is strange is launching a bunch of CREATE TABLE against my dev. database (buzz .. don't like it ..). So I run rake test RAILS_ENV=test and even try bundle exec rake test RAILS_ENV=test . Now CREATE TABLE works against my test database, but all this error crashes:

 ** 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 used the base 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 am using Rails 3.0.7 and the basic configuration.

Any ideas?

EDIT

I get crazy, make many attempts, and it doesn't seem to work. When I launch a new application with several things, rake test works fine, but when I try to do this on my current one, it starts always against my dev. db and do not work at all. I tried to edit the test files, return them back, try to uninstall / install test db in different ways, try a different version of the rake, compare a lot of things on the one hand with my current application, and on the other a completely new one ... Nothing was found .. Help !

EDIT 2

It sounds weak, but is it normal that rake does the same as rake test ?

EDIT 3

There is disagreement, while I continue to work on what is wrong, I understand that every time I run rake test , it works in the dev environment, and not in the test one (viewing logs). It does this on my OSX computer and on our FreeBSD server for all Rails 3.0.7 applications. Are you sure rake test should work by default test environment?

EDIT 4

Please, help!

EDIT 5 - SUMMARY

When running rake test on my computer or on our server in Rails 3.0.7 with various applications, it performs the following actions:

  • perform a CREATE TABLE and INSERT INTO migration from dev. db
  • do not clean dev. db
  • development.log is not written to test.log
  • also a problem with the unknowm comman 't' error with one specific application.

EDIT 6 - db config

Nothing has changed so far: https://gist.github.com/1006199

EDIT 7

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

With RAILS_ENV="test" for the rake, everything is going well. It is recorded in test logs.

ruby -I test test/unit/category_test.rb the same erros as with rake , but do not write to dev. or test logs.

+4
source share
2 answers

a bunch of unorderd answers:

  • CREATE TABLE statements usually mean that your test_db is created from scratch (by default, db: migrate is run before the test task). are you sure they were called on dev_db? also check your /database.yml configuration to see if there is any typo there (for example: using the same table for test and dev environments)

  • it looks like there is an error in some migration files (the error 't' remembers blocks during migration).

  • "rake test" is the default task, so it starts when you just run "rake" with no arguments.

EDIT:

according to what i see when editing starting from 5 and up, it looks like you have a problem with the environment files. so try checking twice: * config / environment / test.rb * config / application.rb * config / environment.rb

if with RAILS_ENV = "test", everything is going well , then I'm pretty sure that you have changed some default behavior in your application (configs, env variables, any specific gem?)

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

+3
source

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

 $> bundle exec rake test 

instead of using 'rake test'

+1
source

All Articles