2

I am getting undefined define_enum_for method error after upgrading rails to 4.2.0 from 4.1.

Is there any fix for this?

Rails : 4.2.0

Ruby : ruby 2.1.5p273 (2014-11-13 revision 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

Raghvendra Parashar
  • 3,883
  • 1
  • 23
  • 36

2 Answers2

0

specifying the test_framework :rspec for shoulda-matchers#configuration solved this problem.

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
Raghvendra Parashar
  • 3,883
  • 1
  • 23
  • 36
0

Configuration Required

  1. spec_helper.rb/rails_helper.rb configure block
  2. type: metadata

spec_helper.rb/rails_helper.rb

I required the Shoulda::Matchers configuration in the spec_helper.rb (the application had not been migrated to rails_helper.rb - but rails_helper.rb is the place I would have put it if available):

# 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

Metadata

But, it also required the type: metadata before it worked:

This==============\/
describe User, type: :model do
  it { should define_enum_for(:status) }
end
notapatch
  • 6,569
  • 6
  • 41
  • 45