mirror of
https://github.com/thoughtbot/factory_bot_rails.git
synced 2022-11-09 11:49:18 -05:00
Merge branch 'add_fixture_replacement' of https://github.com/msgehard/factory_girl_rails
This commit is contained in:
commit
987a488e95
4 changed files with 51 additions and 5 deletions
|
@ -1,7 +1,7 @@
|
|||
PATH
|
||||
remote: .
|
||||
specs:
|
||||
factory_girl_rails (1.1.0)
|
||||
factory_girl_rails (1.2.0)
|
||||
factory_girl (~> 2.1.0)
|
||||
railties (>= 3.0.0)
|
||||
|
||||
|
|
31
features/fixture_replacement_config.feature
Normal file
31
features/fixture_replacement_config.feature
Normal file
|
@ -0,0 +1,31 @@
|
|||
@disable-bundler
|
||||
Feature:
|
||||
In order to not have to manually configure factory girl as the testing fixture replacement
|
||||
by using the --fixture-replacement=factory_girl option
|
||||
as a Rails3 and Factory Girl user
|
||||
I would like the Factory Girl Rails gem to configure Factory Girl
|
||||
as the fixture replacement.
|
||||
|
||||
Background:
|
||||
Given I successfully run `bundle exec rails new testapp`
|
||||
And I cd to "testapp"
|
||||
And I add "factory_girl_rails" from this project as a dependency
|
||||
|
||||
Scenario: Using Factory Girl and Factory Girl Rails with Test Unit generates
|
||||
a factory file and does not generate a fixture file
|
||||
And I successfully run `bundle install`
|
||||
And I successfully run `bundle exec rails generate model User name:string`
|
||||
Then the following files should exist:
|
||||
| test/factories/users.rb |
|
||||
And the following files should not exist:
|
||||
| test/fixtures/users.yml |
|
||||
|
||||
|
||||
Scenario: Using Factory Girl and Factory Girl Rails with RSpec should generate a factory file
|
||||
And I add "rspec-rails" as a dependency
|
||||
And I successfully run `bundle install`
|
||||
And I successfully run `bundle exec rails generate model User name:string`
|
||||
Then the following files should exist:
|
||||
| spec/factories/users.rb |
|
||||
And the following files should not exist:
|
||||
| spec/fixtures/users.yml |
|
|
@ -1,3 +1,7 @@
|
|||
When /^I add "([^"]+)" from this project as a dependency$/ do |gem_name|
|
||||
append_to_file('Gemfile', %{gem "#{gem_name}", :path => "#{PROJECT_ROOT}"})
|
||||
append_to_file('Gemfile', %{gem "#{gem_name}", :path => "#{PROJECT_ROOT}"\n})
|
||||
end
|
||||
|
||||
When /^I add "([^"]+)" as a dependency$/ do |gem_name|
|
||||
append_to_file('Gemfile', %{gem "#{gem_name}"\n})
|
||||
end
|
||||
|
|
|
@ -3,11 +3,22 @@ require 'rails'
|
|||
|
||||
module FactoryGirl
|
||||
class Railtie < Rails::Railtie
|
||||
|
||||
initializer "factory_girl.set_fixture_replacement" do
|
||||
generators = config.respond_to?(:app_generators) ? config.app_generators : config.generators
|
||||
|
||||
if generators.options[:rails][:test_framework] == :rspec
|
||||
generators.fixture_replacement :factory_girl, :dir => 'spec/factories'
|
||||
else
|
||||
generators.test_framework :test_unit, :fixture => false, :fixture_replacement => :factory_girl
|
||||
end
|
||||
end
|
||||
|
||||
config.after_initialize do
|
||||
FactoryGirl.definition_file_paths = [
|
||||
File.join(Rails.root, 'factories'),
|
||||
File.join(Rails.root, 'test', 'factories'),
|
||||
File.join(Rails.root, 'spec', 'factories')
|
||||
File.join(Rails.root, 'factories'),
|
||||
File.join(Rails.root, 'test', 'factories'),
|
||||
File.join(Rails.root, 'spec', 'factories')
|
||||
]
|
||||
FactoryGirl.find_definitions
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue