未定义的方法`check_pending!' for ActiveRecord :: Migration(Rails教程)

det*_*kai 3 ruby ruby-on-rails rails-activerecord

我的sample_app\spec\requests\user_pages_spec.rb文件:

 require 'spec_helper'

describe "User pages" do

  subject { page }

  describe "signup page" do
    before { visit signup_path }

    it { should have_content('Sign up') }
    it { should have_title(full_title('Sign up')) }
  end
end
Run Code Online (Sandbox Code Playgroud)

经过测试我得到:

No DRb server is running. Running in local process instead ...
    -- check_pending!()
    C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/migration.rb:465:in `block in method_missing': undefined method `check_pending!' for #<ActiveRecord::Migration:0x4adcf18> (NoMethodError)
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/migration.rb:438:in `block in say_with_time'
Run Code Online (Sandbox Code Playgroud)

Mos*_*yat 5

check_pending!()它是Rails 4中ActiveRecord :: Migration的一种方法,在读取Error时,发现你当前的Rails版本是3.2,所以这个方法不起作用,如果你使用Spork和RSpec你会发现Spork改变了你的spec/spec_helper.rb文件并添加了几行包括这一行:

 ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
Run Code Online (Sandbox Code Playgroud)

如果你想继续测试而不检查是否有任何迁移仍在运行,你所要做的就是评论这一行,你的测试将有效,如果你不使用Spork,仍然建议你打开规范/ spec_helper.rb并查看代码.