From d5a435dab071f156c43f8d770fdf8b9a49658104 Mon Sep 17 00:00:00 2001 From: Trevor John Date: Sat, 28 Jun 2014 13:32:06 -0400 Subject: [PATCH] allow dir to be optional param for generator [Fixes #131] --- features/fixture_replacement_config.feature | 15 +++++++++++++++ .../generators/rspec_generator.rb | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/features/fixture_replacement_config.feature b/features/fixture_replacement_config.feature index 671a643..b50ec12 100644 --- a/features/fixture_replacement_config.feature +++ b/features/fixture_replacement_config.feature @@ -83,3 +83,18 @@ Feature: Then the following files should not exist: | test/factories/users.rb | | spec/factories/users.rb | + + Scenario: Use a suffix with the Factory Girl generator + When I add "rspec-rails" as a dependency + When I configure the factories as: + """ + config.generators do |g| + g.factory_girl suffix: 'suffix' + end + """ + And I run `bundle install` with a clean environment + And I run `bundle exec rails generate model User name:string` with a clean environment + Then the following files should exist: + | spec/factories/users_suffix.rb | + Then the following files should not exist: + | spec/factories/users.rb | diff --git a/lib/factory_girl_rails/generators/rspec_generator.rb b/lib/factory_girl_rails/generators/rspec_generator.rb index 0248337..dd3fc29 100644 --- a/lib/factory_girl_rails/generators/rspec_generator.rb +++ b/lib/factory_girl_rails/generators/rspec_generator.rb @@ -16,7 +16,7 @@ module FactoryGirlRails end def factory_girl_directory - @generators.options.fetch(:factory_girl, { dir: 'spec/factories' })[:dir] + @generators.options.fetch(:factory_girl, {}).fetch(:dir, 'spec/factories') end end end