File tree 8 files changed +89
-0
lines changed
test/generators/suspenders
8 files changed +89
-0
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ Unreleased
8
8
* Introduce ` suspenders:styles ` generator
9
9
* Introduce ` suspenders:jobs ` generator
10
10
* Introduce ` suspenders:lint ` generator
11
+ * Introduce ` suspenders:rake ` generator
11
12
12
13
20230113.0 (January, 13, 2023)
13
14
Original file line number Diff line number Diff line change @@ -116,6 +116,16 @@ Installs [Sidekiq][] for background job processing and configures ActiveJob for
116
116
117
117
[ Sidekiq ] : https://github.com/sidekiq/sidekiq
118
118
119
+ ### Rake
120
+
121
+ Configures the default Rake task to audit and lint the codebase with
122
+ [ bundler-audit] [ ] and [ standard] [ ] in addition to running the test suite.
123
+
124
+ ` bin/rails g suspenders:rake `
125
+
126
+ [ bundler-audit ] : https://github.com/rubysec/bundler-audit
127
+ [ standard ] : https://github.com/standardrb/standard
128
+
119
129
## Contributing
120
130
121
131
See the [ CONTRIBUTING] document.
Original file line number Diff line number Diff line change 3
3
# installed from the root of your application.
4
4
5
5
ENGINE_ROOT = File . expand_path ( ".." , __dir__ )
6
+ ENGINE_PATH = File . expand_path ( "../lib/suspenders/engine" , __dir__ )
6
7
APP_PATH = File . expand_path ( "../test/dummy/config/application" , __dir__ )
7
8
8
9
# Set up gems listed in the Gemfile.
Original file line number Diff line number Diff line change
1
+ module Suspenders
2
+ module Generators
3
+ class RakeGenerator < Rails ::Generators ::Base
4
+ source_root File . expand_path ( "../../templates/rake" , __FILE__ )
5
+ desc ( <<~TEXT )
6
+ Configures the default Rake task to audit and lint the codebase with
7
+ `bundler-audit` and `standard`, in addition to running the test suite.
8
+ TEXT
9
+
10
+ def configure_default_rake_task
11
+ append_to_file "Rakefile" , %(task default: "suspenders:rake")
12
+ end
13
+ end
14
+ end
15
+ end
Original file line number Diff line number Diff line change 1
1
require "suspenders/version"
2
+ require "suspenders/engine"
2
3
require "suspenders/railtie"
3
4
require "suspenders/generators"
4
5
Original file line number Diff line number Diff line change
1
+ module Suspenders
2
+ class Engine < ::Rails ::Engine
3
+ isolate_namespace Suspenders
4
+ end
5
+ end
Original file line number Diff line number Diff line change
1
+ namespace :suspenders do
2
+ desc "Extend the default Rails Rake task"
3
+ task :rake do
4
+ if Bundler . rubygems . find_name ( "bundler-audit" ) . any?
5
+ Rake ::Task [ :"bundle:audit" ] . invoke
6
+ end
7
+
8
+ if Bundler . rubygems . find_name ( "standard" ) . any?
9
+ Rake ::Task [ :standard ] . invoke
10
+ end
11
+ end
12
+ end
Original file line number Diff line number Diff line change
1
+ require "test_helper"
2
+ require "generators/suspenders/rake_generator"
3
+
4
+ module Suspenders
5
+ module Generators
6
+ class RakeGeneratorTest < Rails ::Generators ::TestCase
7
+ include Suspenders ::TestHelpers
8
+
9
+ tests Suspenders ::Generators ::RakeGenerator
10
+ destination Rails . root
11
+ setup :prepare_destination
12
+ teardown :restore_destination
13
+
14
+ test "modifies existing Rakefile" do
15
+ run_generator
16
+
17
+ assert_file app_root ( "Rakefile" ) do |file |
18
+ assert_match /task default: "suspenders:rake"/ , file
19
+ end
20
+ end
21
+
22
+ test "generator has a description" do
23
+ description = <<~TEXT
24
+ Configures the default Rake task to audit and lint the codebase with
25
+ `bundler-audit` and `standard`, in addition to running the test suite.
26
+ TEXT
27
+
28
+ assert_equal description , generator_class . desc
29
+ end
30
+
31
+ private
32
+
33
+ def prepare_destination
34
+ touch "Gemfile"
35
+ backup_file "Rakefile"
36
+ end
37
+
38
+ def restore_destination
39
+ remove_file_if_exists "Gemfile"
40
+ restore_file "Rakefile"
41
+ end
42
+ end
43
+ end
44
+ end
You can’t perform that action at this time.
0 commit comments