Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 4 未定义的方法为RSpec::ExampleGroups定义枚举_Ruby On Rails 4_Shoulda - Fatal编程技术网

Ruby on rails 4 未定义的方法为RSpec::ExampleGroups定义枚举

Ruby on rails 4 未定义的方法为RSpec::ExampleGroups定义枚举,ruby-on-rails-4,shoulda,Ruby On Rails 4,Shoulda,在将rails从4.1升级到4.2.0之后,我得到了方法错误的未定义的define_enum_ 这有什么解决办法吗 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',

在将rails从4.1升级到4.2.0之后,我得到了方法错误的
未定义的define_enum_

这有什么解决办法吗

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>
1)记录
失败/错误:
应为(:状态)定义_enum_。
与({
首字母:'首字母',
跑步:“跑步”,
停止:“停止”
})
命名错误:
未定义的方法“define_enum_for”#

为shoulda matchers指定
测试框架:rspec
,配置解决了这个问题

所需配置
  • spec_helper.rb/rails_helper.rb配置块
  • 类型:元数据
  • spec_helper.rb/rails_helper.rb 我需要spec_helper.rb中的Shoulda::Matchers配置(应用程序尚未迁移到
    rails_helper.rb
    ——但是
    rails_helper.rb
    是我可以放置它的地方(如果可用的话):

    元数据 但是,它还需要
    类型:
    元数据才能工作:

    This==============\/
    describe User, type: :model do
      it { should define_enum_for(:status) }
    end
    
    # 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
    
    This==============\/
    describe User, type: :model do
      it { should define_enum_for(:status) }
    end