@@ -31,71 +31,77 @@ class FactoriesGenerator::DefaultTest < Rails::Generators::TestCase
31
31
end
32
32
33
33
test "installs gem with Bundler" do
34
- Bundler . stubs ( :with_unbundled_env ) . yields
35
- generator . expects ( :run ) . with ( "bundle install" ) . once
34
+ with_test_suite :minitest do
35
+ Bundler . stubs ( :with_unbundled_env ) . yields
36
+ generator . expects ( :run ) . with ( "bundle install" ) . once
36
37
37
- capture ( :stdout ) do
38
- generator . add_factory_bot
38
+ capture ( :stdout ) do
39
+ generator . add_factory_bot
40
+ end
39
41
end
40
42
end
41
43
42
44
test "removes fixture definitions" do
43
- touch "test/test_helper.rb" , content : test_helper
44
-
45
- run_generator
45
+ with_test_suite :minitest do
46
+ run_generator
46
47
47
- assert_file app_root ( "test/test_helper.rb" ) do |file |
48
- assert_match ( /# fixtures :all/ , file )
48
+ assert_file app_root ( "test/test_helper.rb" ) do |file |
49
+ assert_match ( /# fixtures :all/ , file )
50
+ end
49
51
end
50
52
end
51
53
52
54
test "adds gem to Gemfile" do
53
- run_generator
55
+ with_test_suite :minitest do
56
+ run_generator
54
57
55
- assert_file app_root ( "Gemfile" ) do |file |
56
- assert_match ( /group :development, :test do\n gem "factory_bot_rails"\n end/ , file )
58
+ assert_file app_root ( "Gemfile" ) do |file |
59
+ assert_match ( /group :development, :test do\n gem "factory_bot_rails"\n end/ , file )
60
+ end
57
61
end
58
62
end
59
63
60
64
test "includes syntax methods" do
61
- touch "test/test_helper.rb" , content : test_helper
65
+ with_test_suite :minitest do
66
+ run_generator
62
67
63
- run_generator
64
-
65
- assert_file app_root ( "test/test_helper.rb" ) do |file |
66
- assert_match ( /class TestCase\n include FactoryBot::Syntax::Methods/ , file )
68
+ assert_file app_root ( "test/test_helper.rb" ) do |file |
69
+ assert_match ( /class TestCase\n include FactoryBot::Syntax::Methods/ , file )
70
+ end
67
71
end
68
72
end
69
73
70
74
test "creates definition file" do
71
- definition_file = file_fixture ( "factories.rb" ) . read
75
+ with_test_suite :minitest do
76
+ definition_file = file_fixture ( "factories.rb" ) . read
72
77
73
- run_generator
78
+ run_generator
74
79
75
- assert_file app_root ( "test/factories.rb" ) do |file |
76
- assert_match definition_file , file
80
+ assert_file app_root ( "test/factories.rb" ) do |file |
81
+ assert_match definition_file , file
82
+ end
77
83
end
78
84
end
79
85
80
86
test "creates linting test" do
81
- factories_test = file_fixture ( "factories_test_lint.rb" ) . read
87
+ with_test_suite :minitest do
88
+ factories_test = file_fixture ( "factories_test_lint.rb" ) . read
82
89
83
- run_generator
90
+ run_generator
84
91
85
- assert_file app_root ( "test/factory_bots/factories_test.rb" ) do |file |
86
- assert_match factories_test , file
92
+ assert_file app_root ( "test/factory_bots/factories_test.rb" ) do |file |
93
+ assert_match factories_test , file
94
+ end
87
95
end
88
96
end
89
97
90
98
private
91
99
92
100
def prepare_destination
93
- mkdir "test"
94
101
touch "Gemfile"
95
102
end
96
103
97
104
def restore_destination
98
- remove_dir_if_exists "test"
99
105
remove_file_if_exists "Gemfile"
100
106
remove_dir_if_exists "lib/tasks"
101
107
end
@@ -114,68 +120,73 @@ class FactoriesGenerator::RSpecTest < Rails::Generators::TestCase
114
120
teardown :restore_destination
115
121
116
122
test "includes syntax methods" do
117
- touch ( "spec/rails_helper.rb" )
118
- factory_bot_config = <<~RUBY
119
- FactoryBot.use_parent_strategy = true
123
+ with_test_suite :rspec do
124
+ touch ( "spec/rails_helper.rb" )
125
+ factory_bot_config = <<~RUBY
126
+ FactoryBot.use_parent_strategy = true
120
127
121
- RSpec.configure do |config|
122
- config.include FactoryBot::Syntax::Methods
123
- end
124
- RUBY
128
+ RSpec.configure do |config|
129
+ config.include FactoryBot::Syntax::Methods
130
+ end
131
+ RUBY
125
132
126
- run_generator
133
+ run_generator
127
134
128
- assert_file app_root ( "spec/support/factory_bot.rb" ) do |file |
129
- assert_match factory_bot_config , file
130
- end
131
- assert_file app_root ( "spec/rails_helper.rb" ) do |file |
132
- assert_match ( /Dir\[ Rails\. root\. join\( "spec\/ support\/ \* \* \/ \* \. rb"\) \] \. sort\. each { \| file\| require file }/ , file )
135
+ assert_file app_root ( "spec/support/factory_bot.rb" ) do |file |
136
+ assert_match factory_bot_config , file
137
+ end
138
+ assert_file app_root ( "spec/rails_helper.rb" ) do |file |
139
+ assert_match ( /Dir\[ Rails\. root\. join\( "spec\/ support\/ \* \* \/ \* \. rb"\) \] \. sort\. each { \| file\| require file }/ , file )
140
+ end
133
141
end
134
142
end
135
143
136
144
test "creates definition file" do
137
- definition_file = file_fixture ( "factories.rb" ) . read
145
+ with_test_suite :rspec do
146
+ definition_file = file_fixture ( "factories.rb" ) . read
138
147
139
- run_generator
148
+ run_generator
140
149
141
- assert_file app_root ( "spec/factories.rb" ) do |file |
142
- assert_match definition_file , file
150
+ assert_file app_root ( "spec/factories.rb" ) do |file |
151
+ assert_match definition_file , file
152
+ end
143
153
end
144
154
end
145
155
146
156
test "does not modify rails_helper if it's configured to include support files" do
147
- rails_helper = <<~RUBY
148
- Dir[Rails.root.join("spec/support/**/*.rb")].sort.each { |file| require file }
149
- RUBY
150
- touch "spec/rails_helper.rb" , content : rails_helper
157
+ with_test_suite :rspec do
158
+ rails_helper = <<~RUBY
159
+ Dir[Rails.root.join("spec/support/**/*.rb")].sort.each { |file| require file }
160
+ RUBY
161
+ touch "spec/rails_helper.rb" , content : rails_helper
151
162
152
- run_generator
163
+ run_generator
153
164
154
- assert_file app_root ( "spec/rails_helper.rb" ) do |file |
155
- assert_equal rails_helper , file
165
+ assert_file app_root ( "spec/rails_helper.rb" ) do |file |
166
+ assert_equal rails_helper , file
167
+ end
156
168
end
157
169
end
158
170
159
171
test "creates linting test" do
160
- factories_spec = file_fixture ( "factories_spec_lint.rb" ) . read
172
+ with_test_suite :rspec do
173
+ factories_spec = file_fixture ( "factories_spec_lint.rb" ) . read
161
174
162
- run_generator
175
+ run_generator
163
176
164
- assert_file app_root ( "spec/factory_bots/factories_spec.rb" ) do |file |
165
- assert_match factories_spec , file
177
+ assert_file app_root ( "spec/factory_bots/factories_spec.rb" ) do |file |
178
+ assert_match factories_spec , file
179
+ end
166
180
end
167
181
end
168
182
169
183
private
170
184
171
185
def prepare_destination
172
- mkdir "spec"
173
- touch "spec/spec_helper.rb"
174
186
touch "Gemfile"
175
187
end
176
188
177
189
def restore_destination
178
- remove_dir_if_exists "spec"
179
190
remove_file_if_exists "Gemfile"
180
191
remove_dir_if_exists "lib/tasks"
181
192
end
0 commit comments