factory_girl_rails 4.4.1 → 4.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  Feature:
2
- 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
2
+ In order to not have to manually configure Factory Girl as the Rails testing fixture replacement by using the --fixture-replacement=factory_girl option
3
3
  I would like the Factory Girl Rails gem to configure Factory Girl as the fixture replacement.
4
4
 
5
5
  Background:
@@ -54,29 +54,22 @@ Feature:
54
54
  But the following files should exist:
55
55
  | custom/dir/users.rb |
56
56
 
57
- Scenario: Using Factory Girl and Factory Girl Rails with MiniTest should generate a factory file
58
- When I add "minitest" as a dependency
59
- And I configure the testing framework to use MiniTest
60
- And I run `bundle install` with a clean environment
61
- Then the output should contain "minitest"
57
+ Scenario: Using Factory Girl Rails with MiniTest should generate a factory file
58
+ When I run `bundle install` with a clean environment
62
59
  And I run `bundle exec rails generate model User name:string` with a clean environment
63
60
  Then the following files should exist:
64
61
  | test/factories/users.rb |
65
62
  But the following files should not exist:
66
63
  | spec/fixtures/users.yml |
67
64
 
68
- Scenario: Using Factory Girl and Factory Girl Rails with MiniTest and a custom directory should generate a factory file
65
+ Scenario: Using Factory Girl Rails with MiniTest and a custom directory should generate a factory file
69
66
  When I configure the factories directory as "custom/dir"
70
- And I add "minitest" as a dependency
71
- And I configure the testing framework to use MiniTest
72
67
  And I run `bundle install` with a clean environment
73
- Then the output should contain "minitest"
74
68
  And I run `bundle exec rails generate model User name:string` with a clean environment
75
69
  Then the following files should exist:
76
70
  | custom/dir/users.rb |
77
71
  But the following files should not exist:
78
72
  | spec/fixtures/users.yml |
79
- And the file "test/models/user_test.rb" should contain "MiniTest::Rails::ActiveSupport::TestCase"
80
73
 
81
74
  Scenario: Disable Factory Girl generator
82
75
  When I configure the factories as:
@@ -90,3 +83,18 @@ Feature:
90
83
  Then the following files should not exist:
91
84
  | test/factories/users.rb |
92
85
  | spec/factories/users.rb |
86
+
87
+ Scenario: Use a suffix with the Factory Girl generator
88
+ When I add "rspec-rails" as a dependency
89
+ When I configure the factories as:
90
+ """
91
+ config.generators do |g|
92
+ g.factory_girl suffix: 'suffix'
93
+ end
94
+ """
95
+ And I run `bundle install` with a clean environment
96
+ And I run `bundle exec rails generate model User name:string` with a clean environment
97
+ Then the following files should exist:
98
+ | spec/factories/users_suffix.rb |
99
+ Then the following files should not exist:
100
+ | spec/factories/users.rb |
@@ -1,6 +1,6 @@
1
1
  Feature:
2
2
  In order to easily generate factory files instead of fixture files when generating models
3
- As a user of Rails3 and factory_girl
3
+ As a user of Rails and Factory Girl
4
4
  I would like to use factory_girl_rails generators.
5
5
 
6
6
  Background:
@@ -8,21 +8,21 @@ Feature:
8
8
  And I cd to "testapp"
9
9
  And I add "factory_girl_rails" from this project as a dependency
10
10
 
11
- Scenario: The factory_girl_rails generators create a factory file for each model that I generate
11
+ Scenario: The factory_girl_rails generators create a factory file for each model if there is not a factories.rb file
12
12
  When I run `bundle install` with a clean environment
13
- And I run `bundle exec rails generate model User name:string --fixture-replacement=factory_girl` with a clean environment
14
- And I run `bundle exec rails generate model Namespaced::User name:string --fixture-replacement=factory_girl` with a clean environment
13
+ And I run `bundle exec rails generate model User name:string` with a clean environment
14
+ And I run `bundle exec rails generate model Namespaced::User name:string` with a clean environment
15
15
  Then the output should contain "test/factories/users.rb"
16
16
  And the output should contain "test/factories/namespaced_users.rb"
17
17
  And the file "test/factories/users.rb" should contain "factory :user do"
18
18
  And the file "test/factories/namespaced_users.rb" should contain "factory :namespaced_user, :class => 'Namespaced::User' do"
19
19
 
20
- Scenario: The factory_girl_rails generators create a factory file with a custom name for each model that I generate
20
+ Scenario: The factory_girl_rails generators does not create a factory file for each model if there is a factories.rb file in the test directory
21
21
  When I run `bundle install` with a clean environment
22
- And I set the FactoryGirl :suffix option to "factory"
23
- And I run `bundle exec rails generate model User name:string --fixture-replacement=factory_girl` with a clean environment
24
- And I run `bundle exec rails generate model Namespaced::User name:string --fixture-replacement=factory_girl` with a clean environment
25
- Then the output should contain "test/factories/users_factory.rb"
26
- And the output should contain "test/factories/namespaced_users_factory.rb"
27
- And the file "test/factories/users_factory.rb" should contain "factory :user do"
28
- And the file "test/factories/namespaced_users_factory.rb" should contain "factory :namespaced_user, :class => 'Namespaced::User' do"
22
+ And I write to "test/factories.rb" with:
23
+ """
24
+ FactoryGirl.define do
25
+ end
26
+ """
27
+ And I run `bundle exec rails generate model User name:string` with a clean environment
28
+ Then the file "test/factories.rb" should contain "factory :user do"
@@ -4,7 +4,6 @@ Feature: automatically load step definitions
4
4
  When I successfully run `bundle exec rails new testapp`
5
5
  And I cd to "testapp"
6
6
  And I add "factory_girl_rails" from this project as a dependency
7
- And I comment out gem "turn" from my Gemfile
8
7
  And I run `bundle install` with a clean environment
9
8
  And I write to "db/migrate/1_create_users.rb" with:
10
9
  """
@@ -23,7 +22,7 @@ Feature: automatically load step definitions
23
22
  end
24
23
  """
25
24
 
26
- Scenario: generate a rails 3 application and use factory definitions
25
+ Scenario: generate a Rails application and use factory definitions
27
26
  When I write to "test/factories.rb" with:
28
27
  """
29
28
  FactoryGirl.define do
@@ -44,7 +43,7 @@ Feature: automatically load step definitions
44
43
  end
45
44
  """
46
45
  When I run `bundle exec rake test --trace` with a clean environment
47
- Then the output should contain "1 tests, 1 assertions, 0 failures, 0 errors"
46
+ Then the output should contain "1 assertions, 0 failures, 0 errors"
48
47
 
49
48
  Scenario: use factories advertised by railties/engines/3rd-party gems
50
49
  When I append to "config/application.rb" with:
@@ -82,4 +81,4 @@ Feature: automatically load step definitions
82
81
  end
83
82
  """
84
83
  When I run `bundle exec rake test --trace` with a clean environment
85
- Then the output should contain "1 tests, 1 assertions, 0 failures, 0 errors"
84
+ Then the output should contain "1 assertions, 0 failures, 0 errors"
@@ -1,5 +1,5 @@
1
1
  When /^I run `([^"]+)` with a clean environment$/ do |command|
2
- step %{I successfully run `ruby -e 'system({"BUNDLE_GEMFILE" => nil}, "#{command}")'`}
2
+ step %{I successfully run `ruby -e 'system({"BUNDLE_GEMFILE" => nil, "DISABLE_SPRING" => "true"}, "#{command}")'`}
3
3
  end
4
4
 
5
5
  # system({'BUNDLE_GEMFILE' => nil}, "cd tmp/aruba/testapp && #{command} && cd -")
@@ -19,6 +19,14 @@ When /^I set the FactoryGirl :suffix option to "([^"]+)"$/ do |suffix|
19
19
 
20
20
  end
21
21
 
22
+ When /^I print out "([^"]*)"$/ do |path|
23
+ in_current_dir do
24
+ File.open(path, 'r') do |f|
25
+ puts f.inspect
26
+ end
27
+ end
28
+ end
29
+
22
30
  When /^I configure the factories as:$/ do |string|
23
31
  append_to_file File.join('config', 'application.rb'), <<-END
24
32
  class Testapp::Application
@@ -37,19 +45,6 @@ end
37
45
  END
38
46
  end
39
47
 
40
- When /^I configure the testing framework to use MiniTest$/ do
41
- append_to_file('Gemfile', %{gem "minitest-rails", :group => [:development, :test]\n})
42
- step %{I run `rails generate mini_test:install` with a clean environment}
43
-
44
- append_to_file File.join('config', 'application.rb'), <<-END
45
- class Testapp::Application
46
- config.generators do |g|
47
- g.test_framework :mini_test, :fixture => false, :fixture_replacement => :factory_girl
48
- end
49
- end
50
- END
51
- end
52
-
53
48
  When /^I comment out gem "([^"]*)" from my Gemfile$/ do |gem_name|
54
49
  in_current_dir do
55
50
  content = File.read('Gemfile')
@@ -2,15 +2,16 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rails", "3.2.11"
6
- gem "sass-rails"
5
+ gem "appraisal"
6
+ gem "aruba"
7
7
  gem "coffee-rails"
8
- gem "uglifier"
9
- gem "sqlite3", ">= 1.3.4", :platforms=>:mri
10
- gem "activerecord-jdbcsqlite3-adapter", "~> 1.2.5", :platforms=>:jruby
11
- gem "minitest-rails"
12
- gem "therubyrhino"
8
+ gem "cucumber"
13
9
  gem "jquery-rails"
10
+ gem "rake"
14
11
  gem "rspec-rails"
12
+ gem "uglifier"
13
+ gem "sqlite3"
14
+ gem "rails", "~> 3.2.18"
15
+ gem "sass-rails"
15
16
 
16
- gemspec :path=>"../"
17
+ gemspec :path => "../"
@@ -0,0 +1,17 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal"
6
+ gem "aruba"
7
+ gem "coffee-rails"
8
+ gem "cucumber"
9
+ gem "jquery-rails"
10
+ gem "rake"
11
+ gem "rspec-rails"
12
+ gem "uglifier"
13
+ gem "sqlite3"
14
+ gem "rails", "~> 4.0.5"
15
+ gem "sass-rails"
16
+
17
+ gemspec :path => "../"
@@ -0,0 +1,18 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal"
6
+ gem "aruba"
7
+ gem "coffee-rails"
8
+ gem "cucumber"
9
+ gem "jquery-rails"
10
+ gem "rake"
11
+ gem "rspec-rails"
12
+ gem "uglifier"
13
+ gem "sqlite3"
14
+ gem "rails", "~> 4.1.1"
15
+ gem "sass-rails", "~> 4.0.3"
16
+ gem "spring"
17
+
18
+ gemspec :path => "../"
@@ -16,7 +16,7 @@ module FactoryGirlRails
16
16
  end
17
17
 
18
18
  def factory_girl_directory
19
- @generators.options.fetch(:factory_girl, { dir: 'spec/factories' })[:dir]
19
+ @generators.options.fetch(:factory_girl, {}).fetch(:dir, 'spec/factories')
20
20
  end
21
21
  end
22
22
  end
@@ -4,28 +4,82 @@ require 'factory_girl_rails'
4
4
  module FactoryGirl
5
5
  module Generators
6
6
  class ModelGenerator < Base
7
- argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
8
- class_option :dir, :type => :string, :default => "test/factories", :desc => "The directory where the factories should go"
7
+ argument(
8
+ :attributes,
9
+ type: :array,
10
+ default: [],
11
+ banner: "field:type field:type"
12
+ )
13
+
14
+ class_option(
15
+ :dir,
16
+ type: :string,
17
+ default: "test/factories",
18
+ desc: "The directory or file root where factories belong"
19
+ )
9
20
 
10
21
  def create_fixture_file
11
- filename = [table_name, filename_suffix].compact.join('_')
12
- template 'fixtures.erb', File.join(options[:dir], "#{filename}.rb")
22
+ if File.exist?(factories_file)
23
+ insert_factory_into_existing_file
24
+ else
25
+ create_factory_file
26
+ end
13
27
  end
14
28
 
15
29
  private
16
30
 
31
+ def factories_file
32
+ options[:dir] + ".rb"
33
+ end
34
+
35
+ def insert_factory_into_existing_file
36
+ insert_into_file(
37
+ factories_file,
38
+ factory_definition,
39
+ after: "FactoryGirl.define do"
40
+ )
41
+ end
42
+
43
+ def create_factory_file
44
+ filename = [table_name, filename_suffix].compact.join('_')
45
+ file = File.join(options[:dir], "#{filename}.rb")
46
+ create_file(file, single_file_factory_definition)
47
+ end
48
+
49
+ def factory_definition
50
+ <<-RUBY
51
+ factory :#{singular_table_name}#{explicit_class_option} do
52
+ #{factory_attributes}
53
+ end
54
+ RUBY
55
+ end
56
+
57
+ def single_file_factory_definition
58
+ <<-RUBY
59
+ FactoryGirl.define do
60
+ #{factory_definition}
61
+ end
62
+ RUBY
63
+ end
64
+
65
+ def factory_attributes
66
+ attributes.map do |attribute|
67
+ "#{attribute.name} #{attribute.default.inspect}"
68
+ end.join("\n")
69
+ end
70
+
17
71
  def filename_suffix
18
72
  factory_girl_options[:suffix]
19
73
  end
20
74
 
75
+ def factory_girl_options
76
+ generators.options[:factory_girl] || {}
77
+ end
78
+
21
79
  def generators
22
80
  config = FactoryGirl::Railtie.config
23
81
  config.respond_to?(:app_generators) ? config.app_generators : config.generators
24
82
  end
25
-
26
- def factory_girl_options
27
- generators.options[:factory_girl] || {}
28
- end
29
83
  end
30
84
  end
31
85
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: factory_girl_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.4.1
4
+ version: 4.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Ferris
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-26 00:00:00.000000000 Z
11
+ date: 2014-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -30,90 +30,21 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 4.4.0
33
+ version: 4.5.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 4.4.0
41
- - !ruby/object:Gem::Dependency
42
- name: appraisal
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: 0.5.0
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: 0.5.0
55
- - !ruby/object:Gem::Dependency
56
- name: rake
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: rspec
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: 2.11.0
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: 2.11.0
83
- - !ruby/object:Gem::Dependency
84
- name: cucumber
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: 1.2.1
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: 1.2.1
97
- - !ruby/object:Gem::Dependency
98
- name: aruba
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: 0.5.1
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: 0.5.1
40
+ version: 4.5.0
111
41
  description: |-
112
42
  factory_girl_rails provides integration between
113
43
  factory_girl and rails 3 (currently just automatic factory definition
114
44
  loading)
115
45
  email: jferris@thoughtbot.com
116
- executables: []
46
+ executables:
47
+ - setup
117
48
  extensions: []
118
49
  extra_rdoc_files: []
119
50
  files:
@@ -122,10 +53,12 @@ files:
122
53
  - Appraisals
123
54
  - CONTRIBUTING.md
124
55
  - Gemfile
56
+ - Gemfile.lock
125
57
  - LICENSE
126
58
  - NEWS
127
59
  - README.md
128
60
  - Rakefile
61
+ - bin/setup
129
62
  - factory_girl_rails.gemspec
130
63
  - features/fixture_replacement_config.feature
131
64
  - features/generators.feature
@@ -133,10 +66,9 @@ files:
133
66
  - features/step_definitions/appraisal.rb
134
67
  - features/step_definitions/rails_steps.rb
135
68
  - features/support/env.rb
136
- - gemfiles/rails3.1.gemfile
137
- - gemfiles/rails3.1.gemfile.lock
138
69
  - gemfiles/rails3.2.gemfile
139
- - gemfiles/rails3.2.gemfile.lock
70
+ - gemfiles/rails4.0.gemfile
71
+ - gemfiles/rails4.1.gemfile
140
72
  - lib/factory_girl_rails.rb
141
73
  - lib/factory_girl_rails/generator.rb
142
74
  - lib/factory_girl_rails/generators/non_rspec_generator.rb
@@ -145,7 +77,6 @@ files:
145
77
  - lib/factory_girl_rails/railtie.rb
146
78
  - lib/generators/factory_girl.rb
147
79
  - lib/generators/factory_girl/model/model_generator.rb
148
- - lib/generators/factory_girl/model/templates/fixtures.erb
149
80
  homepage: http://github.com/thoughtbot/factory_girl_rails
150
81
  licenses:
151
82
  - MIT
@@ -166,19 +97,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
166
97
  version: '0'
167
98
  requirements: []
168
99
  rubyforge_project:
169
- rubygems_version: 2.2.0
100
+ rubygems_version: 2.2.2
170
101
  signing_key:
171
102
  specification_version: 4
172
103
  summary: factory_girl_rails provides integration between factory_girl and rails 3
173
104
  test_files:
174
- - Appraisals
175
105
  - features/fixture_replacement_config.feature
176
106
  - features/generators.feature
177
107
  - features/load_definitions.feature
178
108
  - features/step_definitions/appraisal.rb
179
109
  - features/step_definitions/rails_steps.rb
180
110
  - features/support/env.rb
181
- - gemfiles/rails3.1.gemfile
182
- - gemfiles/rails3.1.gemfile.lock
183
- - gemfiles/rails3.2.gemfile
184
- - gemfiles/rails3.2.gemfile.lock
111
+ has_rdoc: