【问题标题】:undefined method define_enum_for for RSpec::ExampleGroupsRSpec::ExampleGroups 的未定义方法 define_enum_for
【发布时间】:2015-12-10 15:39:26
【问题描述】:

在将 rails 从 4.1 升级到 4.2.0 后,我收到了 undefined define_enum_for method error

有什么解决办法吗?

导轨: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

【问题讨论】:

    标签: ruby-on-rails-4 shoulda


    【解决方案1】:

    为 shoulda-matchers#configuration 指定 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
    

    【讨论】:

      【解决方案2】:

      需要配置

      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
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-01-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多