Skip to content

Commit

Permalink
Prep for FactoryGirl 4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaclayton committed Aug 2, 2012
1 parent 8d2f517 commit e9d9e30
Show file tree
Hide file tree
Showing 27 changed files with 50 additions and 1,443 deletions.
78 changes: 35 additions & 43 deletions GETTING_STARTED.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ Update Your Gemfile
If you're using Rails, you'll need to change the required version of `factory_girl_rails`:

```ruby
gem "factory_girl_rails", "~> 3.0"
gem "factory_girl_rails", "~> 4.0"
```

If you're *not* using Rails, you'll just have to change the required version of `factory_girl`:

```ruby
gem "factory_girl", "~> 3.0"
gem "factory_girl", "~> 4.0"
```

JRuby users: FactoryGirl works with JRuby starting with 1.6.7.2 (latest stable, as per July 2012).
Expand Down Expand Up @@ -875,14 +875,41 @@ FactoryGirl.define do
end
```

When using `initialize_with`, attributes accessed from the `initialize_with`
block are assigned a second time to the instance. Duplicate assignment can be
disabled by configuring FactoryGirl as such:
When using `initialize_with`, attributes accessed from within the `initialize_with`
block are assigned *only* in the constructor; this equates to roughly the
following code:

FactoryGirl.duplicate_attribute_assignment_from_initialize_with = false
```ruby
FactoryGirl.define do
factory :user do
initialize_with { new(name) }

name { 'value' }
end
end

FactoryGirl.build(:user)
# runs
User.new('value')
```

This prevents duplicate assignment; in versions of FactoryGirl before 4.0, it
would run this:

This would allow for attributes declared as ignored to not be ignored, since
it won't assign them for a second time.
```ruby
FactoryGirl.define do
factory :user do
initialize_with { new(name) }

name { 'value' }
end
end

FactoryGirl.build(:user)
# runs
user = User.new('value')
user.name = 'value'
```

Custom Strategies
-----------------
Expand Down Expand Up @@ -1042,38 +1069,3 @@ config.after(:suite) do
puts @factory_girl_results
end
```

Cucumber Integration
--------------------

factory\_girl ships with step definitions that make calling factories from Cucumber easier. To use them, add the following to features/support/env.rb:

```ruby
require "factory_girl/step_definitions"
```

Note: These step definitions are _deprecated_. Read why here:
http://robots.thoughtbot.com/post/25650434584/writing-better-cucumber-scenarios-or-why-were

Alternate Syntaxes
------------------

Users' tastes for syntax vary dramatically, but most users are looking for a
common feature set. Because of this factory\_girl supports "syntax layers" which
provide alternate interfaces. See Factory::Syntax for information about the
various layers available. For example, the Machinist-style syntax is popular:

```ruby
require "factory_girl/syntax/blueprint"
require "factory_girl/syntax/make"
require "factory_girl/syntax/sham"

Sham.email {|n| "#{n}@example.com" }

User.blueprint do
name { "Billy Bob" }
email { Sham.email }
end

User.make(name: "Johnny")
```
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,6 @@ factory_girl was written by Joe Ferris with contributions from several authors,
* Josh Clayton
* Thomas Walpole

The syntax layers are derived from software written by the following authors:

* Pete Yandell
* Rick Bradley
* Yossef Mendelssohn

![thoughtbot](http://thoughtbot.com/images/tm/logo.png)

factory_girl is maintained and funded by [thoughtbot, inc](http://thoughtbot.com/community)
Expand Down
241 changes: 0 additions & 241 deletions features/factory_girl_steps.feature

This file was deleted.

Loading

0 comments on commit e9d9e30

Please sign in to comment.