9

Errors running test:units! #<RuntimeError: Command failed with status (1): [ruby -I"lib:test" -I"/Users/jake/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.2/lib" "/Users/jake/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.2/lib/rake/rake_test_loader.rb" "test/unit/**/*_test.rb" ]>

这是否意味着我的单元测试文件有问题,或者我的模型有问题?或者两者都可以?

下面的完整跟踪。

[app:]$ rake test --trace
** Invoke test (first_time)
** Execute test
** Invoke test:run (first_time)
** Execute test:run
** 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
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:abort_if_pending_migrations
** Execute db:test:prepare
** Invoke db:test:load (first_time)
** Invoke db:test:purge (first_time)
** Invoke environment 
** Invoke db:load_config 
** Execute db:test:purge
** Execute db:test:load
** Invoke db:test:load_schema (first_time)
** Invoke db:test:purge 
** Execute db:test:load_schema
** Invoke db:schema:load (first_time)
** Invoke environment 
** Invoke db:load_config 
** Execute db:schema:load
** Execute test:prepare
** Execute test:units
Run options: 

# Running tests:

..F

Finished tests in 0.411867s, 7.2839 tests/s, 7.2839 assertions/s.

  1) Failure:
test_should_save_user_with_valid_email_and_password(UserTest) [/Users/jake/Sites/app/test/unit/user_test.rb:9]:
Didn't save a valid record

3 tests, 3 assertions, 1 failures, 0 errors, 0 skips
** Invoke test:functionals (first_time)
** Invoke test:prepare 
** Execute test:functionals
Run options: 

# Running tests:



Finished tests in 0.004578s, 0.0000 tests/s, 0.0000 assertions/s.

0 tests, 0 assertions, 0 failures, 0 errors, 0 skips
** Invoke test:integration (first_time)
** Invoke test:prepare 
** Execute test:integration
Errors running test:units! #<RuntimeError: Command failed with status (1): [ruby -I"lib:test" -I"/Users/jake/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.2/lib" "/Users/jake/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.2/lib/rake/rake_test_loader.rb" "test/unit/**/*_test.rb" ]>

编辑

此错误仅在 rake 返回错误时出现。如果没有错误,这个运行测试的错误也不会出现......好奇和好奇......


这是您的一项测试未通过时的标准响应。我用一个模型创建了一个空项目,并添加了以下单元测试:

require 'test_helper'

class BlobTest < ActiveSupport::TestCase
  test "test errors" do
    assert false
  end
end

然后我运行它:

dhcp168:unittest pmorse$ rake test
Run options: 

# Running tests:

F

Finished tests in 0.030618s, 32.6605 tests/s, 32.6605 assertions/s.

  1) Failure:
test_test_errors(BlobTest) [/Users/pmorse/Projects/unittest/test/unit/blob_test.rb:8]:
Failed assertion, no message given.

1 tests, 1 assertions, 1 failures, 0 errors, 0 skips
Run options: 

# Running tests:

.......

Finished tests in 0.123589s, 56.6393 tests/s, 80.9133 assertions/s.

7 tests, 10 assertions, 0 failures, 0 errors, 0 skips
Errors running test:units! #<RuntimeError: Command failed with status (1): [ruby -I"lib:test" -I"/Users/pmorse/.rvm/gems/ruby-1.9.3-p194@rails/gems/rake-10.0.3/lib" "/Users/pmorse/.rvm/gems/ruby-1.9.3-p194@rails/gems/rake-10.0.3/lib/rake/rake_test_loader.rb" "test/unit/**/*_test.rb" ]>

我怀疑这是因为 Test::Unit 向 Rake 返回了一个错误代码,而 Rake 正在返回这个输出,这使得它看起来像是有问题。(我想出了点问题:你的测试没有通过。)

4

2 回答 2

12

这是您的一项测试未通过时的标准响应。我用一个模型创建了一个空项目,并添加了以下单元测试:

require 'test_helper'

class BlobTest < ActiveSupport::TestCase
  test "test errors" do
    assert false
  end
end

然后我运行它:

dhcp168:unittest pmorse$ rake test
Run options: 

# Running tests:

F

Finished tests in 0.030618s, 32.6605 tests/s, 32.6605 assertions/s.

  1) Failure:
test_test_errors(BlobTest) [/Users/pmorse/Projects/unittest/test/unit/blob_test.rb:8]:
Failed assertion, no message given.

1 tests, 1 assertions, 1 failures, 0 errors, 0 skips
Run options: 

# Running tests:

.......

Finished tests in 0.123589s, 56.6393 tests/s, 80.9133 assertions/s.

7 tests, 10 assertions, 0 failures, 0 errors, 0 skips
Errors running test:units! #<RuntimeError: Command failed with status (1): [ruby -I"lib:test" -I"/Users/pmorse/.rvm/gems/ruby-1.9.3-p194@rails/gems/rake-10.0.3/lib" "/Users/pmorse/.rvm/gems/ruby-1.9.3-p194@rails/gems/rake-10.0.3/lib/rake/rake_test_loader.rb" "test/unit/**/*_test.rb" ]>

我怀疑这是因为 Test::Unit 向 Rake 返回了一个错误代码,而 Rake 正在返回这个输出,这使得它看起来像是有问题。(我想出了点问题:你的测试没有通过。)

于 2012-12-31T14:30:24.670 回答
0

我也遇到了这个问题。

4小时后调查。我发现我定义了一个假设数据库中必须有记录的范围。像

scope :has_no_rep, where('country_id != ?', Country.global.id)`

def self.global
  Country.where(:code => GLOBAL_CODE).first
end

然后在初始化测试环境期间“加载”这个范围。将引发一个错误,这将导致问题..

所以我对这个问题的建议是。为您的开发环境设置一个新的空数据库(实际上。越类似测试的环境越好)。并尝试rails s。这可以帮助您定位错误。而不是模棱两可的“命令失败,状态为 X”

于 2013-07-05T06:14:07.933 回答