Rails 4测试根本没有运行

时间:2014-03-19 15:21:32

标签: ruby-on-rails ruby unit-testing testing ruby-on-rails-4

我刚刚将项目更新为Rails 4。 我经历了Rails 4 Upgrade Guide。 除了测试,一切都很好。 我使用的是Ruby 2.0.0-p451和Rails 4.0.4 这些是我的宝石:

Using rake (10.1.1)
Using i18n (0.6.9)
Using minitest (4.7.5)
Using multi_json (1.9.0)
Using atomic (1.1.16)
Using thread_safe (0.3.0)
Using tzinfo (0.3.39)
Using activesupport (4.0.4)
Using builder (3.1.4)
Using erubis (2.7.0)
Using rack (1.5.2)
Using rack-test (0.6.2)
Using actionpack (4.0.4)
Using mime-types (1.25.1)
Using polyglot (0.3.4)
Using treetop (1.4.15)
Using mail (2.5.4)
Using actionmailer (4.0.4)
Using activemodel (4.0.4)
Using activerecord-deprecated_finders (1.0.3)
Using arel (4.0.2)
Using activerecord (4.0.4)
Using bcrypt (3.1.7)
Using thor (0.18.1)
Using railties (4.0.4)
Using bootstrap-datepicker-rails (1.3.0.1)
Using bundler (1.5.3)
Using coffee-script-source (1.7.0)
Using execjs (2.0.2)
Using coffee-script (2.2.0)
Using coffee-rails (4.0.1)
Using daemons (1.1.9)
Using docile (1.1.3)
Using dynamic_form (1.1.4)
Using eventmachine (1.0.3)
Using fancybox-rails (0.2.1)
Using hike (1.2.3)
Using jquery-rails (3.1.0)
Using jquery-ui-rails (4.2.0)
Using json (1.8.1)
Using mysql2 (0.3.15)
Using tilt (1.4.1)
Using sprockets (2.11.0)
Using sprockets-rails (2.0.1)
Using rails (4.0.4)
Using rails-i18n (4.0.1)
Using rails-perftest (0.0.3)
Using ruby-prof (0.14.2)
Using sass (3.2.16)
Using sass-rails (4.0.2)
Using select2-rails (3.5.4)
Using simplecov-html (0.8.0)
Using simplecov (0.8.2)
Using thin (1.6.2)
Using turbolinks (2.2.1)
Using uglifier (2.5.0)

这是我的test_helper.rb:

ENV["RAILS_ENV"] ||= "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'

class ActiveSupport::TestCase
  ActiveRecord::Migration.check_pending!

  # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
  #
  # Note: You'll currently still have to declare fixtures explicitly in integration tests
  # -- they do not yet inherit this setting
  fixtures :all

  # Add more helper methods to be used by all tests here...
end

这是我得到的错误代码:

C:\ruby-2.0.0-p451\bin\ruby.exe -e $stdout.sync=true;$stderr.sync=true;

load($0=ARGV.shift) C:\IssueManager\bin\rake test --trace
Testing started at 15:50 ...
** Invoke test (first_time)
** Execute test
** Invoke test:run (first_time)
** Invoke test:units (first_time)
** Invoke test:prepare (first_time)
** Invoke db:test:prepare (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** 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
** Invoke db:test:load 
** Invoke db:abort_if_pending_migrations (first_time)
** Invoke environment 
** Execute db:abort_if_pending_migrations
** Execute test:prepare
** Execute test:units
rake aborted!
undefined method `maintain_test_schema!' for #<ActiveRecord::Migration:0x2a4df70>
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/activerecord-4.0.4/lib/active_record/migration.rb:628:in `block in method_missing'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/activerecord-4.0.4/lib/active_record/migration.rb:601:in `block in say_with_time'
C:/ruby-2.0.0-p451/lib/ruby/2.0.0/benchmark.rb:281:in `measure'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/activerecord-4.0.4/lib/active_record/migration.rb:601:in `say_with_time'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/activerecord-4.0.4/lib/active_record/migration.rb:621:in `method_missing'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/activerecord-4.0.4/lib/active_record/migration.rb:387:in `method_missing'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/railties-4.0.4/lib/rails/test_help.rb:18:in `<top (required)>'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:229:in `require'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:229:in `block in require'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:214:in `load_dependency'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:229:in `require'
C:/IssueManager/test/test_helper.rb:4:in `<top (required)>'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:229:in `require'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:229:in `block in require'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:214:in `load_dependency'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:229:in `require'
C:/IssueManager/test/helpers/application_helper_test.rb:1:in `<top (required)>'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:229:in `require'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:229:in `block in require'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:214:in `load_dependency'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:229:in `require'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/railties-4.0.4/lib/rails/test_unit/sub_test_task.rb:73:in `block (3 levels) in define'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/railties-4.0.4/lib/rails/test_unit/sub_test_task.rb:73:in `each'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/railties-4.0.4/lib/rails/test_unit/sub_test_task.rb:73:in `block (2 levels) in define'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/railties-4.0.4/lib/rails/test_unit/sub_test_task.rb:72:in `each'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/railties-4.0.4/lib/rails/test_unit/sub_test_task.rb:72:in `block in define'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:236:in `call'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:236:in `block in execute'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:231:in `each'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:231:in `execute'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:175:in `block in invoke_with_call_chain'
C:/ruby-2.0.0-p451/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:168:in `invoke_with_call_chain'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:197:in `block in invoke_prerequisites'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:195:in `each'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:195:in `invoke_prerequisites'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:174:in `block in invoke_with_call_chain'
C:/ruby-2.0.0-p451/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:168:in `invoke_with_call_chain'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:161:in `invoke'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/railties-4.0.4/lib/rails/test_unit/testing.rake:61:in `block in <top (required)>'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:236:in `call'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:236:in `block in execute'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:231:in `each'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:231:in `execute'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:175:in `block in invoke_with_call_chain'
C:/ruby-2.0.0-p451/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:168:in `invoke_with_call_chain'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:161:in `invoke'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:149:in `invoke_task'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:106:in `block (2 levels) in top_level'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:106:in `each'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:106:in `block in top_level'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:115:in `run_with_threads'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:100:in `top_level'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:78:in `block in run'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:165:in `standard_exception_handling'
C:/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:75:in `run'
C:/IssueManager/bin/rake:4:in `<top (required)>'
-e:1:in `load'
-e:1:in `<main>'
Tasks: TOP => test:run => test:units
Run options: --seed 19194

# Running tests:



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

0 tests, 0 assertions, 0 failures, 0 errors, 0 skips

Process finished with exit code 0

我不知道为什么会这样。如果您需要有关我的项目/系统的更多信息,请随时询问。


编辑:

没有迁移文件callinge&#39; maintain_test_schema!&#39;,它在test_help.rb中调用:

# Make double-sure the RAILS_ENV is not set to production,
# so fixtures aren't loaded into that environment
abort("Abort testing: Your Rails environment is running in production mode!") if Rails.env.production?

require 'active_support/testing/autorun'
require 'active_support/test_case'
require 'action_controller/test_case'
require 'action_dispatch/testing/integration'
require 'rails/generators/test_case'

# Config Rails backtrace in tests.
require 'rails/backtrace_cleaner'
if ENV["BACKTRACE"].nil?
  Minitest.backtrace_filter = Rails.backtrace_cleaner
end

if defined?(ActiveRecord::Base)
  ActiveRecord::Migration.maintain_test_schema!

  class ActiveSupport::TestCase
    include ActiveRecord::TestFixtures
    self.fixture_path = "#{Rails.root}/test/fixtures/"
  end

  ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path

  def create_fixtures(*fixture_set_names, &block)
    FixtureSet.create_fixtures(ActiveSupport::TestCase.fixture_path, fixture_set_names, {}, &block)
  end
end

我刚刚用一个模型创建了一个新项目,甚至在那里我收到了这个错误:

C:\ruby-2.0.0-p451\bin\ruby.exe -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) C:\rails4test\bin\rake test
Testing started at 16:46 ...
Run options: --seed 46775


# Running tests:rake aborted!


undefined method `maintain_test_schema!' for #<ActiveRecord::Migration:0x291a290>

C:/rails4test/test/test_helper.rb:3:in `<top (required)>'
C:/rails4test/test/models/test_test.rb:1:in `<top (required)>'
-e:1:in `load'
-e:1:in `<main>'
Tasks: TOP => test:run => test:units
(See full trace by running task with --trace)


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

0 tests, 0 assertions, 0 failures, 0 errors, 0 skips

Process finished with exit code 1

2 个答案:

答案 0 :(得分:5)

ActiveRecord::Migration.maintain_test_schema!是Rails 4.1.x的一部分

这在4.0.x中不可用

答案 1 :(得分:1)

我遇到了同样的问题,我也使用了Ruby 2.0.0-p451和Rails 4.0.4。

我通过评论这一行来解决它ActiveRecord :: Migration.maintain_test_schema!在spec_helper.rb。