thoughtbot/factory_girl — Issue #270: Traits don't work when using with construction methods in Rails
Author: Shamaoke
Created: 2012-01-17 10:09:57+00:00
State: open

Hi.

I work with Cucumber and RSpec in Rails. When I try to add a trait in any of the construction methods (`create`, `build`, etc.) the method just ignore that action and trait isn't applied.

Here's an example:

**Factory**

# spec/factories/friends.rb

FactoryGirl.define do
factory :friend do
trait :default do
name 'Rachel'
surname 'Green'
end
end
end

**Step Definitions**

# features/step_definitions/friends_steps.rb

Given /^a friend exists$/ do
FactoryGirl.create(:friend, :default)
#=> #, not 'Rachel' 'Green'
end

**Model Spec**

# spec/models/friend_spec.rb

require 'spec_helper'

describe Friend do
before { FactoryGirl.create(:friend, :default) }
#=> also #
end

Why can't I apply traits? Thanks.

Factory Girl 2.4.0;

Factory Girl Rails 1.5.0;

Cucumber 1.1.4;

Cucumber-rails 1.2.1;

RSpec 2.8.0;

RSpec-rails 2.8.1;

Ruby on Rails 3.1.3.