0
我正在使用Ruby on Rails 3.0.9,RSpec-rails 2和FactoryGirl。我试图在关联模型上使用RSpec its
功能(在下面的示例中它是:account
),但我遇到了一些问题。使用RSpec'其'功能的问题
在我的规格文件我有:
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
功能?
你可以使用'let'过,但有一个主题:'{主题}用户' – iain
@Iain - “你可以用let,但是有一个主题...” - 你可以用let来做一个完整的例子吗? – user502052
@ user502052 Lain只是想用'let'作为原始提问者所做的:'let(:user){...}'然后做一个'subject {user}'。 – cbron