File tree 4 files changed +94
-0
lines changed
lib/generators/suspenders/test
test/generators/suspenders/test
4 files changed +94
-0
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ Unreleased
18
18
* Introduce ` suspenders:prerequisites ` generator
19
19
* Introduce ` suspenders:ci ` generator
20
20
* Introduce ` suspenders:cleanup:organize_gemfile ` task
21
+ * Introduce ` suspenders:test:environment ` generator
21
22
22
23
20230113.0 (January, 13, 2023)
23
24
Original file line number Diff line number Diff line change @@ -197,6 +197,22 @@ Creates CI files for GitHub Actions.
197
197
bin/rails g suspenders:ci
198
198
```
199
199
200
+ ### Environments
201
+
202
+ #### Test
203
+
204
+ Configures test environment.
205
+
206
+ ```
207
+ bin/rails g suspenders:test:environment
208
+ ```
209
+
210
+ - Enables [ raise_on_missing_translations] [ ]
211
+ - Disables [ action_dispatch.show_exceptions] [ ]
212
+
213
+ [ raise_on_missing_translations ] : https://guides.rubyonrails.org/configuring.html#config-i18n-raise-on-missing-translations
214
+ [ action_dispatch.show_exceptions ] : https://edgeguides.rubyonrails.org/configuring.html#config-action-dispatch-show-exceptions
215
+
200
216
## Contributing
201
217
202
218
See the [ CONTRIBUTING] document.
Original file line number Diff line number Diff line change
1
+ module Suspenders
2
+ module Generators
3
+ module Test
4
+ class EnvironmentGenerator < Rails ::Generators ::Base
5
+ desc <<~MARKDOWN
6
+ Configures test environment.
7
+
8
+ ```
9
+ bin/rails g suspenders:test:environment
10
+ ```
11
+
12
+ - Enables [raise_on_missing_translations][]
13
+ - Disables [action_dispatch.show_exceptions][]
14
+
15
+ [raise_on_missing_translations]: https://guides.rubyonrails.org/configuring.html#config-i18n-raise-on-missing-translations
16
+ [action_dispatch.show_exceptions]: https://edgeguides.rubyonrails.org/configuring.html#config-action-dispatch-show-exceptions
17
+ MARKDOWN
18
+
19
+ def raise_on_missing_translations
20
+ uncomment_lines "config/environments/test.rb" , /config\. i18n\. raise_on_missing_translations\s *=\s *true/
21
+ end
22
+
23
+ def disable_action_dispatch_show_exceptions
24
+ gsub_file "config/environments/test.rb" , /^\s *config\. action_dispatch\. show_exceptions\s *=\s *:rescuable/ ,
25
+ "config.action_dispatch.show_exceptions = :none"
26
+
27
+ gsub_file "config/environments/test.rb" , /^\s *#\s *Raise exceptions instead of rendering exception templates/i , ""
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
Original file line number Diff line number Diff line change
1
+ require "test_helper"
2
+ require "generators/suspenders/test/environment_generator"
3
+
4
+ module Suspenders
5
+ module Generators
6
+ module Test
7
+ class EnvironmentGeneratorTest < Rails ::Generators ::TestCase
8
+ include Suspenders ::TestHelpers
9
+
10
+ tests Suspenders ::Generators ::Test ::EnvironmentGenerator
11
+ destination Rails . root
12
+ setup :prepare_destination
13
+ teardown :restore_destination
14
+
15
+ test "raise on missing translations" do
16
+ run_generator
17
+
18
+ assert_file app_root ( "config/environments/test.rb" ) do |file |
19
+ assert_match ( /^\s *config\. i18n\. raise_on_missing_translations\s *=\s *true/ , file )
20
+ end
21
+ end
22
+
23
+ test "disable action_dispatch.show_exceptions" do
24
+ run_generator
25
+
26
+ assert_file app_root ( "config/environments/test.rb" ) do |file |
27
+ assert_match ( /^\s *config\. action_dispatch\. show_exceptions\s *=\s *:none/ , file )
28
+ assert_no_match ( /^\s *config\. action_dispatch\. show_exceptions\s *=\s *:rescuable/ , file )
29
+ assert_no_match ( /^\s *#\s *Raise exceptions instead of rendering exception templates/i , file )
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def prepare_destination
36
+ backup_file "config/environments/test.rb"
37
+ end
38
+
39
+ def restore_destination
40
+ restore_file "config/environments/test.rb"
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
You can’t perform that action at this time.
0 commit comments