ffactory_girl_rails 4.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d027b4423c1b35fe0771923a4e978e3f3d855edd
4
+ data.tar.gz: a18d27cfd4a7c8b464a578544ded4e391fd3c72e
5
+ SHA512:
6
+ metadata.gz: dd5982bc239d3622730d2f6b266ca8138b83289b303bad423538a6ef8c937ec467441d3ea0b461bf9cb0a68a4ed21dd3b790ac53013f69010a46effa2a0a26d3
7
+ data.tar.gz: 09bd17caea660847e3710ce3f63d2e9ff0d8a5a78cc7cc12a51396b96c73699bdbc9a20fc04c395fdd7bde527596178ebd0281fdc52bd09ac94c5567e4c29715
data/Appraisals ADDED
@@ -0,0 +1,21 @@
1
+ # These are the versions of Rails we want to test against.
2
+ appraise 'rails3.2' do
3
+ gem 'rails', '~> 3.2.21'
4
+ gem 'sass-rails'
5
+ end
6
+
7
+ appraise 'rails4.1' do
8
+ gem 'rails', '~> 4.1.9'
9
+ gem 'sass-rails'
10
+ gem 'spring'
11
+ end
12
+
13
+ appraise 'rails4.2' do
14
+ gem 'rails', '~> 4.2.0'
15
+ end
16
+
17
+ appraise "rails5.0" do
18
+ gem "activerecord", "~> 5.0.0"
19
+ gem "railties", "~> 5.0.0"
20
+ gem "rspec-rails", "~> 3.5.0.beta4"
21
+ end
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,39 @@
1
+ # Contributing
2
+
3
+ We love pull requests from everyone. By participating in this project, you
4
+ agree to abide by the thoughtbot [code of conduct].
5
+
6
+ [code of conduct]: https://thoughtbot.com/open-source-code-of-conduct
7
+
8
+ Fork, then clone the repo:
9
+
10
+ git clone git@github.com:your-username/factory_girl_rails.git
11
+
12
+ Set up your machine:
13
+
14
+ ./bin/setup
15
+
16
+ Make sure the tests pass:
17
+
18
+ rake
19
+
20
+ Make your change. Add tests for your change. Make the tests pass:
21
+
22
+ rake
23
+
24
+ Push to your fork and [submit a pull request][pr].
25
+
26
+ [pr]: https://github.com/thoughtbot/factory_girl_rails/compare/
27
+
28
+ At this point you're waiting on us. We like to at least comment on pull requests
29
+ within three business days (and, typically, one business day). We may suggest
30
+ some changes or improvements or alternatives.
31
+
32
+ Some things that will increase the chance that your pull request is accepted:
33
+
34
+ * Write tests.
35
+ * Follow our [style guide][style].
36
+ * Write a [good commit message][commit].
37
+
38
+ [style]: https://github.com/thoughtbot/guides/tree/master/style
39
+ [commit]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
data/Gemfile ADDED
@@ -0,0 +1,20 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'appraisal'
6
+ gem 'aruba'
7
+ gem 'coffee-rails'
8
+ gem 'cucumber', '1.3.19'
9
+ gem 'jquery-rails'
10
+ gem 'rake'
11
+ gem 'rspec-rails'
12
+ gem 'uglifier'
13
+ gem 'test-unit'
14
+
15
+ gem 'activerecord-jdbcsqlite3-adapter', platforms: :jruby
16
+ gem 'jdbc-sqlite3', platforms: :jruby
17
+ gem 'therubyrhino', platforms: :jruby
18
+ gem 'jruby-openssl', platforms: :jruby
19
+
20
+ gem 'sqlite3', platforms: :ruby
data/Gemfile.lock ADDED
@@ -0,0 +1,144 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ factory_girl_rails (4.8.0)
5
+ factory_girl (~> 4.8.0)
6
+ railties (>= 3.0.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actionpack (4.1.1)
12
+ actionview (= 4.1.1)
13
+ activesupport (= 4.1.1)
14
+ rack (~> 1.5.2)
15
+ rack-test (~> 0.6.2)
16
+ actionview (4.1.1)
17
+ activesupport (= 4.1.1)
18
+ builder (~> 3.1)
19
+ erubis (~> 2.7.0)
20
+ activemodel (4.1.1)
21
+ activesupport (= 4.1.1)
22
+ builder (~> 3.1)
23
+ activerecord (4.1.1)
24
+ activemodel (= 4.1.1)
25
+ activesupport (= 4.1.1)
26
+ arel (~> 5.0.0)
27
+ activerecord-jdbc-adapter (1.3.15)
28
+ activerecord (>= 2.2)
29
+ activerecord-jdbcsqlite3-adapter (1.3.15)
30
+ activerecord-jdbc-adapter (~> 1.3.15)
31
+ jdbc-sqlite3 (>= 3.7.2, < 3.9)
32
+ activesupport (4.1.1)
33
+ i18n (~> 0.6, >= 0.6.9)
34
+ json (~> 1.7, >= 1.7.7)
35
+ minitest (~> 5.1)
36
+ thread_safe (~> 0.1)
37
+ tzinfo (~> 1.1)
38
+ appraisal (1.0.3)
39
+ bundler
40
+ rake
41
+ thor (>= 0.14.0)
42
+ arel (5.0.1.20140414130214)
43
+ aruba (0.5.4)
44
+ childprocess (>= 0.3.6)
45
+ cucumber (>= 1.1.1)
46
+ rspec-expectations (>= 2.7.0)
47
+ builder (3.2.2)
48
+ childprocess (0.5.3)
49
+ ffi (~> 1.0, >= 1.0.11)
50
+ coffee-rails (4.0.1)
51
+ coffee-script (>= 2.2.0)
52
+ railties (>= 4.0.0, < 5.0)
53
+ coffee-script (2.2.0)
54
+ coffee-script-source
55
+ execjs
56
+ coffee-script-source (1.7.0)
57
+ cucumber (1.3.19)
58
+ builder (>= 2.1.2)
59
+ diff-lcs (>= 1.1.3)
60
+ gherkin (~> 2.12)
61
+ multi_json (>= 1.7.5, < 2.0)
62
+ multi_test (>= 0.1.2)
63
+ diff-lcs (1.2.5)
64
+ erubis (2.7.0)
65
+ execjs (2.0.2)
66
+ factory_girl (4.8.0)
67
+ activesupport (>= 3.0.0)
68
+ ffi (1.9.3)
69
+ ffi (1.9.3-java)
70
+ gherkin (2.12.2)
71
+ multi_json (~> 1.3)
72
+ gherkin (2.12.2-java)
73
+ multi_json (~> 1.3)
74
+ i18n (0.7.0)
75
+ jdbc-sqlite3 (3.8.7)
76
+ jquery-rails (3.1.0)
77
+ railties (>= 3.0, < 5.0)
78
+ thor (>= 0.14, < 2.0)
79
+ jruby-openssl (0.9.6-java)
80
+ json (1.8.3)
81
+ json (1.8.3-java)
82
+ minitest (5.9.0)
83
+ multi_json (1.11.2)
84
+ multi_test (0.1.2)
85
+ power_assert (0.2.3)
86
+ rack (1.5.5)
87
+ rack-test (0.6.3)
88
+ rack (>= 1.0)
89
+ railties (4.1.1)
90
+ actionpack (= 4.1.1)
91
+ activesupport (= 4.1.1)
92
+ rake (>= 0.8.7)
93
+ thor (>= 0.18.1, < 2.0)
94
+ rake (11.1.2)
95
+ rspec-core (2.14.8)
96
+ rspec-expectations (2.14.5)
97
+ diff-lcs (>= 1.1.3, < 2.0)
98
+ rspec-mocks (2.14.6)
99
+ rspec-rails (2.14.2)
100
+ actionpack (>= 3.0)
101
+ activemodel (>= 3.0)
102
+ activesupport (>= 3.0)
103
+ railties (>= 3.0)
104
+ rspec-core (~> 2.14.0)
105
+ rspec-expectations (~> 2.14.0)
106
+ rspec-mocks (~> 2.14.0)
107
+ sqlite3 (1.3.9)
108
+ test-unit (3.0.9)
109
+ power_assert
110
+ therubyrhino (2.0.4)
111
+ therubyrhino_jar (>= 1.7.3)
112
+ therubyrhino_jar (1.7.4)
113
+ thor (0.19.1)
114
+ thread_safe (0.3.5)
115
+ thread_safe (0.3.5-java)
116
+ tzinfo (1.2.2)
117
+ thread_safe (~> 0.1)
118
+ uglifier (2.5.0)
119
+ execjs (>= 0.3.0)
120
+ json (>= 1.8.0)
121
+
122
+ PLATFORMS
123
+ java
124
+ ruby
125
+
126
+ DEPENDENCIES
127
+ activerecord-jdbcsqlite3-adapter
128
+ appraisal
129
+ aruba
130
+ coffee-rails
131
+ cucumber (= 1.3.19)
132
+ factory_girl_rails!
133
+ jdbc-sqlite3
134
+ jquery-rails
135
+ jruby-openssl
136
+ rake
137
+ rspec-rails
138
+ sqlite3
139
+ test-unit
140
+ therubyrhino
141
+ uglifier
142
+
143
+ BUNDLED WITH
144
+ 1.13.6
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2008-2013 Joe Ferris and thoughtbot, inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/NEWS ADDED
@@ -0,0 +1,24 @@
1
+ factory_girl_rails versioning is synced with factory_girl releases. For this reason
2
+ there might not be any notable changes in new versions of this project.
3
+
4
+ 4.7.0 (April 1, 2016)
5
+ No notable changes
6
+
7
+ 4.6.0 (February 1, 2016)
8
+ No notable changes
9
+
10
+ 4.5.0 (October 17, 2014)
11
+ Improved README
12
+
13
+ 4.4.1 (February 26, 2014)
14
+ Support Spring
15
+
16
+ 4.2.1 (February 8, 2013)
17
+ Fix bug when configuring FG and RSpec fixture directory
18
+ Remove debugging
19
+ Require factory_girl_rails explicitly in generator
20
+
21
+ 4.2.0 (January 25, 2013)
22
+ Add appraisal and get test suite working reliably with turn gem
23
+ Support MiniTest
24
+ Allow a custom directory for factories to be specified
data/README.md ADDED
@@ -0,0 +1,17 @@
1
+ ffactory_girl_rails is a factory_bot_rails but ffactory_girl_rails
2
+
3
+ ## Credits
4
+
5
+ [factory_girl][fg] was originally written by Joe Ferris.
6
+
7
+ ![thoughtbot](http://thoughtbot.com/images/tm/logo.png)
8
+
9
+ factory_girl is maintained and funded by [thoughtbot, inc](http://thoughtbot.com/community)
10
+
11
+ The names and logos for thoughtbot are trademarks of thoughtbot, inc.
12
+
13
+ ## License
14
+
15
+ factory_girl_rails is Copyright © 2008-2016 Joe Ferris and thoughtbot. It is free
16
+ software, and may be redistributed under the terms specified in the
17
+ [LICENSE](LICENSE) file.
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ require 'bundler/setup'
2
+ require 'bundler/gem_tasks'
3
+ require 'cucumber/rake/task'
4
+
5
+ Cucumber::Rake::Task.new(:cucumber) do |t|
6
+ t.fork = true
7
+ t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'progress')]
8
+ end
9
+
10
+ require 'appraisal'
11
+
12
+ desc 'Run the test suite'
13
+ task :default do |t|
14
+ if ENV['BUNDLE_GEMFILE'] =~ /gemfiles/
15
+ exec 'rake cucumber'
16
+ else
17
+ Rake::Task['appraise'].execute
18
+ end
19
+ end
20
+
21
+ task :appraise => ['appraisal:install'] do |t|
22
+ exec 'rake appraisal'
23
+ end
data/bin/setup ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env sh
2
+
3
+ # Run this script immediately after cloning the codebase.
4
+
5
+ # Exit if any subcommand fails
6
+ set -e
7
+
8
+ # Set up Ruby dependencies via Bundler
9
+ bundle install
10
+
11
+ # Add binstubs to PATH in ~/.zshenv like this:
12
+ # export PATH=".git/safe/../../bin:$PATH"
13
+ mkdir -p .git/safe
14
+
15
+ # Set up Appraisal to help us test against multiple Rails versions
16
+ bundle exec appraisal install
@@ -0,0 +1,20 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = %q{ffactory_girl_rails}
3
+ s.version = '4.8.0'
4
+ s.authors = ["Joe Ferris"]
5
+ s.email = %q{jferris@thoughtbot.com}
6
+ s.homepage = "http://github.com/kalys/ffactory_girl_rails"
7
+ s.summary = %q{ffactory_girl_rails provides integration between
8
+ ffactory_girl and rails 3 or newer}
9
+ s.description = %q{ffactory_girl_rails provides integration between
10
+ ffactory_girl and rails 3 or newer (currently just automatic factory definition
11
+ loading)}
12
+
13
+ s.files = Dir['**/*'].keep_if { |file| File.file?(file) }
14
+ s.require_paths = ["lib"]
15
+ s.executables = []
16
+ s.license = "MIT"
17
+
18
+ s.add_runtime_dependency('railties', '>= 3.0.0')
19
+ s.add_runtime_dependency('ffactory_girl', '~> 4.8.0')
20
+ end
@@ -0,0 +1,132 @@
1
+ Feature:
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
+ I would like the Factory Girl Rails gem to configure Factory Girl as the fixture replacement.
4
+
5
+ Background:
6
+ Given I successfully run `bundle exec rails new testapp`
7
+ And I cd to "testapp"
8
+ And I add "factory_girl_rails" from this project as a dependency
9
+
10
+ Scenario: Using Factory Girl and Factory Girl Rails with Test Unit generates a factory file and does not generate a fixture file
11
+ And I run `bundle install` with a clean environment
12
+ And I run `bundle exec rails generate model User name:string` with a clean environment
13
+ Then the following files should exist:
14
+ | test/factories/users.rb |
15
+ And the following files should not exist:
16
+ | test/fixtures/users.yml |
17
+
18
+ Scenario: Using Factory Girl and Factory Girl Rails with RSpec should generate a factory file
19
+ When I add "rspec-rails" as a dependency
20
+ And I configure the factories as:
21
+ """
22
+ config.generators do |g|
23
+ g.test_framework :rspec, fixture: true
24
+ g.fixture_replacement :factory_girl
25
+ end
26
+ """
27
+ And I run `bundle install` with a clean environment
28
+ Then the output should contain "rspec-rails"
29
+ And I run `bundle exec rails generate model User name:string` with a clean environment
30
+ Then the following files should exist:
31
+ | spec/factories/users.rb |
32
+ And the following files should not exist:
33
+ | spec/fixtures/users.yml |
34
+
35
+ Scenario: Using Factory Girl and Factory Girl Rails with RSpec and suffix configuration should generate a factory file with suffix
36
+ When I add "rspec-rails" as a dependency
37
+ And I configure the factories as:
38
+ """
39
+ config.generators do |g|
40
+ g.test_framework :rspec, fixture: true
41
+ g.fixture_replacement :factory_girl, suffix: 'factory'
42
+ end
43
+ """
44
+ And I run `bundle install` with a clean environment
45
+ Then the output should contain "rspec-rails"
46
+ And I run `bundle exec rails generate model User name:string` with a clean environment
47
+ Then the following files should exist:
48
+ | spec/factories/users_factory.rb |
49
+ And the following files should not exist:
50
+ | spec/fixtures/users.yml |
51
+
52
+ Scenario: Using Factory Girl and Factory Girl Rails does not override a manually-configured factories directory using RSpec
53
+ When I add "rspec-rails" as a dependency
54
+ And I configure the factories directory as "custom/dir"
55
+ And I run `bundle install` with a clean environment
56
+ Then the output should contain "rspec-rails"
57
+ And I run `bundle exec rails generate model User name:string` with a clean environment
58
+ Then the following files should not exist:
59
+ | test/factories/users.rb |
60
+ | spec/factories/users.rb |
61
+ But the following files should exist:
62
+ | custom/dir/users.rb |
63
+
64
+ Scenario: Using Factory Girl and Factory Girl Rails does not override a manually-configured factories directory using Test::Unit
65
+ When I configure the factories directory as "custom/dir"
66
+ And I run `bundle install` with a clean environment
67
+ And I run `bundle exec rails generate model User name:string` with a clean environment
68
+ Then the following files should not exist:
69
+ | test/factories/users.rb |
70
+ | spec/factories/users.rb |
71
+ But the following files should exist:
72
+ | custom/dir/users.rb |
73
+
74
+ Scenario: Using Factory Girl Rails with MiniTest should generate a factory file
75
+ When I run `bundle install` with a clean environment
76
+ And I run `bundle exec rails generate model User name:string` with a clean environment
77
+ Then the following files should exist:
78
+ | test/factories/users.rb |
79
+ But the following files should not exist:
80
+ | spec/fixtures/users.yml |
81
+
82
+ Scenario: Using Factory Girl Rails with MiniTest and a custom directory should generate a factory file
83
+ When I configure the factories directory as "custom/dir"
84
+ And I run `bundle install` with a clean environment
85
+ And I run `bundle exec rails generate model User name:string` with a clean environment
86
+ Then the following files should exist:
87
+ | custom/dir/users.rb |
88
+ But the following files should not exist:
89
+ | spec/fixtures/users.yml |
90
+
91
+ Scenario: Disable Factory Girl generator
92
+ When I configure the factories as:
93
+ """
94
+ config.generators do |g|
95
+ g.factory_girl false
96
+ end
97
+ """
98
+ And I run `bundle install` with a clean environment
99
+ And I run `bundle exec rails generate model User name:string` with a clean environment
100
+ Then the following files should not exist:
101
+ | test/factories/users.rb |
102
+ | spec/factories/users.rb |
103
+
104
+ Scenario: Use a suffix with the Factory Girl generator
105
+ When I add "rspec-rails" as a dependency
106
+ When I configure the factories as:
107
+ """
108
+ config.generators do |g|
109
+ g.factory_girl suffix: 'suffix'
110
+ end
111
+ """
112
+ And I run `bundle install` with a clean environment
113
+ And I run `bundle exec rails generate model User name:string` with a clean environment
114
+ Then the following files should exist:
115
+ | spec/factories/users_suffix.rb |
116
+ Then the following files should not exist:
117
+ | spec/factories/users.rb |
118
+
119
+ Scenario: Use a filename_proc with the Factory Girl generator
120
+ When I add "rspec-rails" as a dependency
121
+ When I configure the factories as:
122
+ """
123
+ config.generators do |g|
124
+ g.factory_girl filename_proc: Proc.new { |tb| "prefix_#{tb.singularize}_suffix" }
125
+ end
126
+ """
127
+ And I run `bundle install` with a clean environment
128
+ And I run `bundle exec rails generate model User name:string` with a clean environment
129
+ Then the following files should exist:
130
+ | spec/factories/prefix_user_suffix.rb |
131
+ Then the following files should not exist:
132
+ | spec/factories/users.rb |
@@ -0,0 +1,54 @@
1
+ Feature:
2
+ In order to easily generate factory files instead of fixture files when generating models
3
+ As a user of Rails and Factory Girl
4
+ I would like to use factory_girl_rails generators.
5
+
6
+ Background:
7
+ Given I successfully run `bundle exec rails new testapp`
8
+ And I cd to "testapp"
9
+ And I add "factory_girl_rails" from this project as a dependency
10
+
11
+ Scenario: The factory_girl_rails generators create a factory file for each model if there is not a factories.rb file
12
+ When I run `bundle install` with a clean environment
13
+ And I run `bundle exec rails generate model User name:string age:integer` with a clean environment
14
+ And I run `bundle exec rails generate model Namespaced::User name:string` with a clean environment
15
+ Then the output should contain "test/factories/users.rb"
16
+ And the output should contain "test/factories/namespaced_users.rb"
17
+ And the file "test/factories/users.rb" should contain exactly:
18
+ """
19
+ FactoryGirl.define do
20
+ factory :user do
21
+ name "MyString"
22
+ age 1
23
+ end
24
+ end
25
+
26
+ """
27
+ And the file "test/factories/namespaced_users.rb" should contain "factory :namespaced_user, class: 'Namespaced::User' do"
28
+
29
+ Scenario: The factory_girl_rails generators add a factory in the correct spot
30
+ When I run `bundle install` with a clean environment
31
+ And I write to "test/factories.rb" with:
32
+ """
33
+ FactoryGirl.define do
34
+ end
35
+ """
36
+ And I run `bundle exec rails generate model User name:string` with a clean environment
37
+ Then the file "test/factories.rb" should contain exactly:
38
+ """
39
+ FactoryGirl.define do
40
+ factory :user do
41
+ name "MyString"
42
+ end
43
+ end
44
+ """
45
+
46
+ 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
47
+ When I run `bundle install` with a clean environment
48
+ And I write to "test/factories.rb" with:
49
+ """
50
+ FactoryGirl.define do
51
+ end
52
+ """
53
+ And I run `bundle exec rails generate model User name:string` with a clean environment
54
+ Then the file "test/factories.rb" should contain "factory :user do"
@@ -0,0 +1,85 @@
1
+ Feature: automatically load step definitions
2
+
3
+ Background:
4
+ When I successfully run `bundle exec rails new testapp`
5
+ And I cd to "testapp"
6
+ And I add "factory_girl_rails" from this project as a dependency
7
+ And I add "test-unit" as a dependency
8
+ And I run `bundle install` with a clean environment
9
+ And I write to "db/migrate/1_create_users.rb" with:
10
+ """
11
+ class CreateUsers < ActiveRecord::Migration
12
+ def self.up
13
+ create_table :users do |t|
14
+ t.string :name
15
+ end
16
+ end
17
+ end
18
+ """
19
+ When I run `bundle exec rake db:migrate` with a clean environment
20
+ And I write to "app/models/user.rb" with:
21
+ """
22
+ class User < ActiveRecord::Base
23
+ end
24
+ """
25
+
26
+ Scenario: generate a Rails application and use factory definitions
27
+ When I write to "test/factories.rb" with:
28
+ """
29
+ FactoryGirl.define do
30
+ factory :user do
31
+ name "Frank"
32
+ end
33
+ end
34
+ """
35
+ When I write to "test/unit/user_test.rb" with:
36
+ """
37
+ require 'test_helper'
38
+
39
+ class UserTest < ActiveSupport::TestCase
40
+ test "use factory" do
41
+ user = FactoryGirl.create(:user)
42
+ assert_equal 'Frank', user.name
43
+ end
44
+ end
45
+ """
46
+ When I run `bundle exec rake test` with a clean environment
47
+ Then the output should contain "1 assertions, 0 failures, 0 errors"
48
+
49
+ Scenario: use factories advertised by railties/engines/3rd-party gems
50
+ When I append to "config/application.rb" with:
51
+ """
52
+ require File.expand_path('../../lib/some_railtie/railties.rb', __FILE__)
53
+ """
54
+ When I write to "lib/some_railtie/railties.rb" with:
55
+ """
56
+ module SomeRailtie
57
+ class Railtie < ::Rails::Engine
58
+
59
+ initializer "some_railtie.factories", :after => "factory_girl.set_factory_paths" do
60
+ FactoryGirl.definition_file_paths << File.expand_path('../factories', __FILE__)
61
+ end
62
+ end
63
+ end
64
+ """
65
+ When I write to "lib/some_railtie/factories.rb" with:
66
+ """
67
+ FactoryGirl.define do
68
+ factory :factory_from_some_railtie, class: 'User' do
69
+ name 'Artem'
70
+ end
71
+ end
72
+ """
73
+ When I write to "test/unit/user_test.rb" with:
74
+ """
75
+ require 'test_helper'
76
+
77
+ class UserTest < ActiveSupport::TestCase
78
+ test "use factory of some_railtie" do
79
+ user = FactoryGirl.create(:factory_from_some_railtie)
80
+ assert_equal 'Artem', user.name
81
+ end
82
+ end
83
+ """
84
+ When I run `bundle exec rake test` with a clean environment
85
+ Then the output should contain "1 assertions, 0 failures, 0 errors"
@@ -0,0 +1,5 @@
1
+ When /^I run `([^"]+)` with a clean environment$/ do |command|
2
+ step %{I successfully run `ruby -e 'system({"BUNDLE_GEMFILE" => nil, "DISABLE_SPRING" => "true"}, "#{command}")'`}
3
+ end
4
+
5
+ # system({'BUNDLE_GEMFILE' => nil}, "cd tmp/aruba/testapp && #{command} && cd -")
@@ -0,0 +1,42 @@
1
+ When /^I add "([^"]+)" from this project as a dependency$/ do |gem_name|
2
+ append_to_file('Gemfile', %{gem "#{gem_name}", :path => "#{PROJECT_ROOT}"\n})
3
+ end
4
+
5
+ When /^I add "([^"]+)" as a dependency$/ do |gem_name|
6
+ append_to_file('Gemfile', %{gem "#{gem_name}"\n})
7
+ end
8
+
9
+ When /^I print out "([^"]*)"$/ do |path|
10
+ in_current_dir do
11
+ File.open(path, 'r') do |f|
12
+ puts f.inspect
13
+ end
14
+ end
15
+ end
16
+
17
+ When /^I configure the factories as:$/ do |string|
18
+ append_to_file File.join('config', 'application.rb'), <<-END
19
+ class Testapp::Application
20
+ #{string}
21
+ end
22
+ END
23
+ end
24
+
25
+ When /^I configure the factories directory as "([^"]+)"$/ do |factory_dir|
26
+ append_to_file File.join('config', 'application.rb'), <<-END
27
+ class Testapp::Application
28
+ config.generators do |g|
29
+ g.fixture_replacement :factory_girl, :dir => "#{factory_dir}"
30
+ end
31
+ end
32
+ END
33
+ end
34
+
35
+ When /^I comment out gem "([^"]*)" from my Gemfile$/ do |gem_name|
36
+ in_current_dir do
37
+ content = File.read('Gemfile')
38
+ File.open('Gemfile', 'w') do |f|
39
+ f.write content.sub(/gem ['"]#{gem_name}/, '#\1')
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,21 @@
1
+ require 'aruba/cucumber'
2
+
3
+ PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', '..')).freeze
4
+
5
+ Aruba.configure do |config|
6
+ config.exit_timeout = Integer ENV.fetch("ARUBA_TIMEOUT") { 120 }
7
+ end
8
+
9
+ Aruba.configure do |config|
10
+ config.before_cmd do |cmd|
11
+ set_env('JRUBY_OPTS', "-X-C #{ENV['JRUBY_OPTS']}") # disable JIT since these processes are so short lived
12
+
13
+ java_options = ENV['JAVA_OPTS']
14
+
15
+ if 1.size == 4 # 4 for 32 bit java, 8 for 64 bit java.
16
+ set_env('JAVA_OPTS', "-d32 #{java_options}")
17
+ else
18
+ set_env('JAVA_OPTS', "-XX:+TieredCompilation -XX:TieredStopAtLevel=1 #{java_options}")
19
+ end
20
+ end
21
+ end if RUBY_PLATFORM == 'java'
@@ -0,0 +1,22 @@
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", "1.3.19"
9
+ gem "jquery-rails"
10
+ gem "rake"
11
+ gem "rspec-rails"
12
+ gem "uglifier"
13
+ gem "test-unit"
14
+ gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
15
+ gem "jdbc-sqlite3", :platforms => :jruby
16
+ gem "therubyrhino", :platforms => :jruby
17
+ gem "jruby-openssl", :platforms => :jruby
18
+ gem "sqlite3", :platforms => :ruby
19
+ gem "rails", "~> 3.2.21"
20
+ gem "sass-rails"
21
+
22
+ gemspec :path => "../"
@@ -0,0 +1,23 @@
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", "1.3.19"
9
+ gem "jquery-rails"
10
+ gem "rake"
11
+ gem "rspec-rails"
12
+ gem "uglifier"
13
+ gem "test-unit"
14
+ gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
15
+ gem "jdbc-sqlite3", :platforms => :jruby
16
+ gem "therubyrhino", :platforms => :jruby
17
+ gem "jruby-openssl", :platforms => :jruby
18
+ gem "sqlite3", :platforms => :ruby
19
+ gem "rails", "~> 4.1.9"
20
+ gem "sass-rails"
21
+ gem "spring"
22
+
23
+ gemspec :path => "../"
@@ -0,0 +1,21 @@
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", "1.3.19"
9
+ gem "jquery-rails"
10
+ gem "rake"
11
+ gem "rspec-rails"
12
+ gem "uglifier"
13
+ gem "test-unit"
14
+ gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
15
+ gem "jdbc-sqlite3", :platforms => :jruby
16
+ gem "therubyrhino", :platforms => :jruby
17
+ gem "jruby-openssl", :platforms => :jruby
18
+ gem "sqlite3", :platforms => :ruby
19
+ gem "rails", "~> 4.2.0"
20
+
21
+ gemspec :path => "../"
@@ -0,0 +1,22 @@
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", "1.3.19"
9
+ gem "jquery-rails"
10
+ gem "rake"
11
+ gem "rspec-rails", "~> 3.5.0.beta4"
12
+ gem "uglifier"
13
+ gem "test-unit"
14
+ gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
15
+ gem "jdbc-sqlite3", :platforms => :jruby
16
+ gem "therubyrhino", :platforms => :jruby
17
+ gem "jruby-openssl", :platforms => :jruby
18
+ gem "sqlite3", :platforms => :ruby
19
+ gem "activerecord", "~> 5.0.0"
20
+ gem "railties", "~> 5.0.0"
21
+
22
+ gemspec :path => "../"
@@ -0,0 +1,43 @@
1
+ require 'factory_girl_rails/generators/rspec_generator'
2
+ require 'factory_girl_rails/generators/non_rspec_generator'
3
+ require 'factory_girl_rails/generators/null_generator'
4
+
5
+ module FactoryGirlRails
6
+ class Generator
7
+ def initialize(config)
8
+ @generators = if config.respond_to?(:app_generators)
9
+ config.app_generators
10
+ else
11
+ config.generators
12
+ end
13
+ end
14
+
15
+ def run
16
+ generator.new(@generators).run
17
+ end
18
+
19
+ def generator
20
+ if factory_girl_disabled?
21
+ Generators::NullGenerator
22
+ else
23
+ if test_framework == :rspec
24
+ Generators::RSpecGenerator
25
+ else
26
+ Generators::NonRSpecGenerator
27
+ end
28
+ end
29
+ end
30
+
31
+ def test_framework
32
+ rails_options[:test_framework]
33
+ end
34
+
35
+ def factory_girl_disabled?
36
+ rails_options[:factory_girl] == false
37
+ end
38
+
39
+ def rails_options
40
+ @generators.options[:rails]
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,19 @@
1
+ module FactoryGirlRails
2
+ module Generators
3
+ class NonRSpecGenerator
4
+ def initialize(generators)
5
+ @generators = generators
6
+ end
7
+
8
+ def run
9
+ @generators.test_framework test_framework, fixture: false, fixture_replacement: :factory_girl
10
+ end
11
+
12
+ private
13
+
14
+ def test_framework
15
+ @generators.options[:rails][:test_framework]
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,11 @@
1
+ module FactoryGirlRails
2
+ module Generators
3
+ class NullGenerator
4
+ def initialize(generators)
5
+ end
6
+
7
+ def run
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,23 @@
1
+ module FactoryGirlRails
2
+ module Generators
3
+ class RSpecGenerator
4
+ def initialize(generators)
5
+ @generators = generators
6
+ end
7
+
8
+ def run
9
+ @generators.fixture_replacement fixture_replacement_setting, dir: factory_girl_directory
10
+ end
11
+
12
+ private
13
+
14
+ def fixture_replacement_setting
15
+ @generators.options[:rails][:fixture_replacement] || :factory_girl
16
+ end
17
+
18
+ def factory_girl_directory
19
+ @generators.options.fetch(:factory_girl, {}).fetch(:dir, 'spec/factories')
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,28 @@
1
+ require 'factory_girl'
2
+ require 'factory_girl_rails/generator'
3
+ require 'rails'
4
+
5
+ module FactoryGirl
6
+ class Railtie < Rails::Railtie
7
+
8
+ initializer "factory_girl.set_fixture_replacement" do
9
+ FactoryGirlRails::Generator.new(config).run
10
+ end
11
+
12
+ initializer "factory_girl.set_factory_paths" do
13
+ FactoryGirl.definition_file_paths = [
14
+ Rails.root.join('factories'),
15
+ Rails.root.join('test', 'factories'),
16
+ Rails.root.join('spec', 'factories')
17
+ ]
18
+ end
19
+
20
+ config.after_initialize do
21
+ FactoryGirl.find_definitions
22
+
23
+ if defined?(Spring)
24
+ Spring.after_fork { FactoryGirl.reload }
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,4 @@
1
+ require 'factory_girl_rails/railtie'
2
+
3
+ module FactoryGirlRails
4
+ end
@@ -0,0 +1,99 @@
1
+ require 'generators/factory_girl'
2
+ require 'factory_girl_rails'
3
+
4
+ module FactoryGirl
5
+ module Generators
6
+ class ModelGenerator < Base
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
+ )
20
+
21
+ class_option(
22
+ :suffix,
23
+ type: :string,
24
+ default: nil,
25
+ desc: "Suffix to add factory file"
26
+ )
27
+
28
+ def create_fixture_file
29
+ if File.exist?(factories_file)
30
+ insert_factory_into_existing_file
31
+ else
32
+ create_factory_file
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ def factories_file
39
+ options[:dir] + ".rb"
40
+ end
41
+
42
+ def insert_factory_into_existing_file
43
+ insert_into_file(
44
+ factories_file,
45
+ factory_definition,
46
+ after: "FactoryGirl.define do\n"
47
+ )
48
+ end
49
+
50
+ def create_factory_file
51
+ file = File.join(options[:dir], "#{filename}.rb")
52
+ create_file(file, single_file_factory_definition)
53
+ end
54
+
55
+ def factory_definition
56
+ <<-RUBY
57
+ factory :#{singular_table_name}#{explicit_class_option} do
58
+ #{factory_attributes.gsub(/^/, " ")}
59
+ end
60
+ RUBY
61
+ end
62
+
63
+ def single_file_factory_definition
64
+ <<-RUBY
65
+ FactoryGirl.define do
66
+ #{factory_definition.chomp}
67
+ end
68
+ RUBY
69
+ end
70
+
71
+ def factory_attributes
72
+ attributes.map do |attribute|
73
+ "#{attribute.name} #{attribute.default.inspect}"
74
+ end.join("\n")
75
+ end
76
+
77
+ def filename
78
+ if factory_girl_options[:filename_proc].present?
79
+ factory_girl_options[:filename_proc].call(table_name)
80
+ else
81
+ [table_name, filename_suffix].compact.join('_')
82
+ end
83
+ end
84
+
85
+ def filename_suffix
86
+ factory_girl_options[:suffix] || options[:suffix]
87
+ end
88
+
89
+ def factory_girl_options
90
+ generators.options[:factory_girl] || {}
91
+ end
92
+
93
+ def generators
94
+ config = FactoryGirl::Railtie.config
95
+ config.respond_to?(:app_generators) ? config.app_generators : config.generators
96
+ end
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,15 @@
1
+ require 'rails/generators/named_base'
2
+
3
+ module FactoryGirl
4
+ module Generators
5
+ class Base < Rails::Generators::NamedBase #:nodoc:
6
+ def self.source_root
7
+ @_factory_girl_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'factory_girl', generator_name, 'templates'))
8
+ end
9
+
10
+ def explicit_class_option
11
+ ", class: '#{class_name}'" unless class_name == singular_table_name.camelize
12
+ end
13
+ end
14
+ end
15
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ffactory_girl_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 4.8.0
5
+ platform: ruby
6
+ authors:
7
+ - Joe Ferris
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-10-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 3.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: ffactory_girl
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 4.8.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 4.8.0
41
+ description: |-
42
+ ffactory_girl_rails provides integration between
43
+ ffactory_girl and rails 3 or newer (currently just automatic factory definition
44
+ loading)
45
+ email: jferris@thoughtbot.com
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - Appraisals
51
+ - CONTRIBUTING.md
52
+ - Gemfile
53
+ - Gemfile.lock
54
+ - LICENSE
55
+ - NEWS
56
+ - README.md
57
+ - Rakefile
58
+ - bin/setup
59
+ - factory_girl_rails.gemspec
60
+ - features/fixture_replacement_config.feature
61
+ - features/generators.feature
62
+ - features/load_definitions.feature
63
+ - features/step_definitions/appraisal.rb
64
+ - features/step_definitions/rails_steps.rb
65
+ - features/support/env.rb
66
+ - gemfiles/rails3.2.gemfile
67
+ - gemfiles/rails4.1.gemfile
68
+ - gemfiles/rails4.2.gemfile
69
+ - gemfiles/rails5.0.gemfile
70
+ - lib/factory_girl_rails.rb
71
+ - lib/factory_girl_rails/generator.rb
72
+ - lib/factory_girl_rails/generators/non_rspec_generator.rb
73
+ - lib/factory_girl_rails/generators/null_generator.rb
74
+ - lib/factory_girl_rails/generators/rspec_generator.rb
75
+ - lib/factory_girl_rails/railtie.rb
76
+ - lib/generators/factory_girl.rb
77
+ - lib/generators/factory_girl/model/model_generator.rb
78
+ homepage: http://github.com/kalys/ffactory_girl_rails
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.4.8
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: ffactory_girl_rails provides integration between ffactory_girl and rails
102
+ 3 or newer
103
+ test_files: []