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:
d开发者_如何学Goescribe 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?
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,
subject { Factory.build(:user, :account => Factory.build(:users_account)) }
精彩评论