FactoryGirl error

Please note am fairly new, so if this is a silly question my apologies.

I was moving programming along making some changes to one of my models using TDD. I started to get this message out of rspec:

Failure/Error: expect(factory).to be_valid, factory.errors.full_messages.join(‘,’)

I am assuming that this is due to a model change that my factory has become invalid. However, I can not seem to get to a valid state.

Here is my model:

class Item < ActiveRecord::Base
  belongs_to :user
  validates :name, presence: true
  validates :sku, presence: true
end

Here is my factory:

FactoryGirl.define do
  factory :item do
    name "factory_name"
    description "factory_description"
    user nil
    sku "factory_sku"
  end
end

What I wold like to know is:
Am I on the right track?
How do I go about troubleshooting this?

Thanks in advance!!
Rod.

I found that I comment out the line:

validates :sku, presence: true

or make the line a uniqueness validation

validates :sku, uniqueness: true

It works, although I am not sure why.

rod.

Can you please post your spec and also the full backtrace (the full text you see when the spec fails)?

@benorenstein His problem was related to the factory_spec.rb generated on using suspenders. And I think the backtrace told only about the

Failure/Error: expect(factory).to be_valid, factory.errors.full_messages.join(',')

at line number 9 of factory_spec.rb.

I’m afraid I still don’t have enough info to diagnose what’s wrong here.

There was no backtrace to speak of. I now think I understand what has happened. Follow this and see if I am on the right track…

I started with a GREEN rspec run.
I wrote a test to validate a new field on my model. Rspec is RED.
I created the migration and ran the rakes. Rspec is now GREEN.
I wrote a validation to test the presence of the new field. Rspec is RED.
I added the validate in the model.

At this point I was expecting a GREEN rspec run. However, it was red with the error above. I think it was telling me that factory that was initially created is not not valid because I never updated it with the new required field. Being new, I did not think it all the way through.