[英]Rspec + shoulda test fails on accept_nested_attributes_for despite relationship
I'm writing a model test for my Applications model, which accepts_nested_attributes_for(:user)
. 我正在为我的Applications模型编写模型测试,该模型接受
accepts_nested_attributes_for(:user)
。 Here's the test that's failing: 这是失败的测试:
describe UserApplication, "associations" do
it { should belong_to(:user) }
it { should accept_nested_attributes_for(:user) }
end
And here's the model: 这是模型:
class UserApplication < ActiveRecord::Base
#attr_accessible all the fields
belongs_to :user
accepts_nested_attributes_for :user
end
I'm using rspec with shoulda-matchers 2.8, and from my research this should all work fine. 我正在将rspec与shoulda-matchers 2.8一起使用,并且从我的研究中来看,这一切都可以正常工作。 No spring or any other weirdness, either.
也没有春天或任何其他怪异。 Here's the error I'm seeing:
这是我看到的错误:
1) UserApplication association
Failure/Error: it { should accept_nested_attributes_for(:user) }
NoMethodError:
undefined method `accept_nested_attributes_for' for #<RSpec::Core::ExampleGroup::Nested_2:0x007fec5c641a40>
# ./spec/models/user_application_spec.rb:25:in `block (2 levels) in <top (required)>'
I'm not sure what could be causing this. 我不确定是什么原因造成的。 Could this be some weird gem conflict shenanigans or am I missing something obvious?
这可能是一些怪异的宝石冲突恶作剧,还是我缺少明显的东西?
Okay, so I have to give credit to @PeterAlfvin for giving me the tools to see what was wrong. 好的,所以我必须感谢@PeterAlfvin给我的工具,以查看发生了什么问题。 My gemfile specified
gem 'shoulda-matchers'
but that was only loading up version 1.0, which didn't have support for accepts_nested_attributes_for
. 我的gemfile指定了gem'shoulda
gem 'shoulda-matchers'
matchers gem 'shoulda-matchers'
但它仅加载1.0版,该版本不支持accepts_nested_attributes_for
。 His suggestion, via https://stackoverflow.com/a/2954632/1008891 pointed me in the right direction. 他通过https://stackoverflow.com/a/2954632/1008891提出的建议为我指明了正确的方向。 Specifying 2.8.0 fixed the problem without immediately breaking anything.
指定2.8.0可解决问题,而无需立即中断任何操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.