使用 RSpec“其”时出现问题特征
我正在使用 Ruby on Rails 3.0.9、RSpec-rails 2 和 FactoryGirl。我正在尝试在关联模型上使用 RSpec its
功能(在以下示例中为 :account
),但遇到了一些麻烦。
在我的规范文件中,我有:
describe User do
describe "Associations" do
let(:user) { Factory(:user, :account => Factory.build(:users_account)) }
it { should respond_to(:account) } # This work correctly
its(:account) { should_not be_nil } # This does NOT work correctly (read below for more information)
end
end
如果运行上述代码,我会收到以下错误:
Failure/Error: its(:account) { should_not be_nil }
expected: not nil
got: nil
如何使上述代码正常工作,以便正确使用 RSpec its
功能?
I am using Ruby on Rails 3.0.9, RSpec-rails 2 and FactoryGirl. I am trying to use the RSpec its
feature on a association model (in the following example it is :account
) but I have some trouble.
In my spec file I have:
describe User do
describe "Associations" do
let(:user) { Factory(:user, :account => Factory.build(:users_account)) }
it { should respond_to(:account) } # This work correctly
its(:account) { should_not be_nil } # This does NOT work correctly (read below for more information)
end
end
If I run the above code I get the following error:
Failure/Error: its(:account) { should_not be_nil }
expected: not nil
got: nil
How can I make the above code to work so to correctly use the RSpec its
feature?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
(:users_account) 之后缺少一个“)”。
除此之外我不确定,但你可以尝试使用 subject 而不是 let ,
You're missing a ')' after (:users_account).
Beyond that I'm not sure, but you could try to use subject instead of let as in,