RSpec :: ExampleGroups的未定义方法define_enum_for

时间:2015-12-10 15:39:27

标签: ruby-on-rails-4 shoulda

将4.1从4.1升级到4.2.0后,我得到undefined define_enum_for method error

有没有解决这个问题?

Rails:4.2.0

Ruby:ruby 2.1.5p273(2014-11-13修订版48405)[i686-linux]

  1) Recording 
     Failure/Error:
       should define_enum_for(:state).
         with({
           initial: 'initial',
           running: 'running',
           stopped: 'stopped'
         })

     NoMethodError:
       undefined method `define_enum_for' for #<RSpec::ExampleGroups::Recording:0x99a0ea8>

shoulda-matchers#define_enum_for

2 个答案:

答案 0 :(得分:0)

为shoulda-matcher指定test_framework :rspec#配置解决了这个问题。

shoulda-matchers#configuration

Shoulda::Matchers.configure do |config|
  config.integrate do |with|
    with.test_framework :rspec

    with.library :active_record
    with.library :active_model
    with.library :action_controller
  end
end

答案 1 :(得分:0)

需要配置

  1. spec_helper.rb / rails_helper.rb配置块
  2. 类型:元数据

spec_helper.rb / rails_helper.rb

我需要spec_helper.rb中的Shoulda :: Matchers配置(该应用程序尚未迁移到rails_helper.rb-但如果可用,rails_helper.rb是我会放置的位置):

# spec/spec_helper.rb
Shoulda::Matchers.configure do |config|
  config.integrate do |with|
    with.test_framework :rspec
    with.library :rails # same as :active_record + :active_model + :active_controller
  end
end

元数据

但是,它还需要type:元数据才能起作用:

This==============\/
describe User, type: :model do
  it { should define_enum_for(:status) }
end