user502052
user502052

Reputation: 15259

Trouble on using the RSpec 'its' feature

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?

Upvotes: 0

Views: 219

Answers (1)

cbron
cbron

Reputation: 4044

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)) }

Upvotes: 1

Related Questions