Test Test
Test Test

Reputation: 2889

FactoryGirl and Rails 3.2 error

I have this in factories.rb:

FactoryGirl.create :user do |user|
  user.name "test"
  user.age "40"
end

and this in my test file:

require 'spec_helper'

describe "FirstTests" do
    it "creates a user" do
     user=Factory(:user)
    end
end

Like always nothing works. Could somebody explain me why I am getting this?

/usr/local/rvm/gems/ruby-1.9.3-p194/gems/factory_girl-4.1.0/lib/factory_girl/registry.rb:24:in `find': Factory not registered: user (ArgumentError)

Everything is there. why I am getting this error?

Upvotes: 1

Views: 157

Answers (1)

Unixmonkey
Unixmonkey

Reputation: 18784

You are using create instead of define

FactoryGirl.define do
  factory :user do
    name "test"
    age "40"
  end
end

and Factory(:user) instead of FactoryGirl.create(:user), or more simply create(:user)

https://github.com/thoughtbot/factory_girl/wiki/Usage

Upvotes: 5

Related Questions