将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>
答案 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)
我需要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