hanami-minitest 3.0.0.rc1

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.
Files changed (30) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +30 -0
  3. data/LICENSE +20 -0
  4. data/README.md +183 -0
  5. data/hanami-minitest.gemspec +39 -0
  6. data/lib/hanami/minitest/commands.rb +167 -0
  7. data/lib/hanami/minitest/feature_test.rb +31 -0
  8. data/lib/hanami/minitest/generators/action.rb +61 -0
  9. data/lib/hanami/minitest/generators/mailer.rb +62 -0
  10. data/lib/hanami/minitest/generators/operation.rb +61 -0
  11. data/lib/hanami/minitest/generators/part.rb +122 -0
  12. data/lib/hanami/minitest/generators/slice.rb +47 -0
  13. data/lib/hanami/minitest/generators/templates/gemfile +5 -0
  14. data/lib/hanami/minitest/generators/templates/gemfile_db +8 -0
  15. data/lib/hanami/minitest/generators/templates/gitignore +1 -0
  16. data/lib/hanami/minitest/generators/templates/helper.rb +11 -0
  17. data/lib/hanami/minitest/generators/templates/request.rb +13 -0
  18. data/lib/hanami/minitest/generators/templates/support_db.rb +18 -0
  19. data/lib/hanami/minitest/generators/templates/support_db_cleaning.rb +71 -0
  20. data/lib/hanami/minitest/generators/templates/support_features.rb +5 -0
  21. data/lib/hanami/minitest/generators/templates/support_minitest.rb +5 -0
  22. data/lib/hanami/minitest/generators/templates/support_operations.rb +8 -0
  23. data/lib/hanami/minitest/generators/templates/support_requests.rb +5 -0
  24. data/lib/hanami/minitest/rake_tasks.rb +13 -0
  25. data/lib/hanami/minitest/request_test.rb +27 -0
  26. data/lib/hanami/minitest/test.rb +96 -0
  27. data/lib/hanami/minitest/version.rb +10 -0
  28. data/lib/hanami/minitest.rb +60 -0
  29. data/lib/hanami-minitest.rb +12 -0
  30. metadata +145 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ecb2a53d8cbcc2ca342732ce92f727c1512a833b31cbc854e6a72cca74f44dfd
4
+ data.tar.gz: b84c14c29262f12aee015437ee83a90d69e7380e287a066cb45d1222e3c22e3c
5
+ SHA512:
6
+ metadata.gz: 4527b3500752a8ab6f6cd6c7b1a2685decfdcdb0af0ab3f6116760c16b01ffa633b4fe38a0638822a7b87a0543208174025ca18b7003f1949d7fb6f2e7ec88a2
7
+ data.tar.gz: 25e7b28c6ac92c68c28c0098691d406e7cbab10dd5e1667690963f19d3291f069dce698ea4c87d46c7f102e40f06be049e65369f8e9481b51d127f11b6d60b40
data/CHANGELOG.md ADDED
@@ -0,0 +1,30 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Break Versioning](https://www.taoensso.com/break-versioning).
7
+
8
+ ## [Unreleased]
9
+
10
+ ### Added
11
+
12
+ ### Changed
13
+
14
+ ### Deprecated
15
+
16
+ ### Removed
17
+
18
+ ### Fixed
19
+
20
+ ### Security
21
+
22
+ [Unreleased]: https://github.com/hanami/hanami-minitest/compare/v3.0.0.rc1...HEAD
23
+
24
+ ## [3.0.0.rc1] - 2026-06-16
25
+
26
+ ### Added
27
+
28
+ - Create the gem. (@timriley)
29
+
30
+ [3.0.0.rc1]: https://github.com/hanami/hanami-minitest/releases/tag/v3.0.0.rc1
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015-2026 Hanakai team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,183 @@
1
+ <!--- This file is synced from hanakai-rb/repo-sync -->
2
+
3
+ [actions]: https://github.com/hanami/hanami-minitest/actions
4
+ [chat]: https://discord.gg/naQApPAsZB
5
+ [forum]: https://discourse.hanamirb.org
6
+ [rubygem]: https://rubygems.org/gems/hanami-minitest
7
+
8
+ # hanami-minitest [![Gem Version](https://badge.fury.io/rb/hanami-minitest.svg)][rubygem] [![CI Status](https://github.com/hanami/hanami-minitest/workflows/CI/badge.svg)][actions]
9
+
10
+ [![Forum](https://img.shields.io/badge/Forum-dc360f?logo=discourse&logoColor=white)][forum]
11
+ [![Chat](https://img.shields.io/badge/Chat-717cf8?logo=discord&logoColor=white)][chat]
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ group :cli, :development, :test do
19
+ gem "hanami-minitest"
20
+ end
21
+ ```
22
+
23
+ And then execute:
24
+
25
+ ```
26
+ $ bundle install
27
+ $ bundle exec hanami setup
28
+ ```
29
+
30
+ ## Usage
31
+
32
+ For detailed examples, see [EXAMPLES.md](EXAMPLES.md).
33
+
34
+ When you run `hanami setup`, this gem will automatically:
35
+
36
+ - Add test dependencies to your `Gemfile`
37
+ - Create a `test/test_helper.rb` file
38
+ - Set up support files in `test/support/`
39
+ - Generate an initial request test
40
+
41
+ ### RuboCop
42
+
43
+ The test support files generated by this gem use compact class notation to re-open existing Hanami::Minitest classes (e.g. `class Hanami::Minitest::Test`). If your RuboCop configuration enables `Style/ClassAndModuleChildren`, you'll need to exclude these files in your root `.rubocop.yml`:
44
+
45
+ ```yaml
46
+ Style/ClassAndModuleChildren:
47
+ Exclude:
48
+ - "test/support/**/*"
49
+ ```
50
+
51
+ ### Writing Tests
52
+
53
+ #### Action Tests
54
+
55
+ Generate an action with its test:
56
+
57
+ ```
58
+ $ bundle exec hanami generate action home.index --url=/
59
+ ```
60
+
61
+ This creates both the action and a corresponding test file.
62
+
63
+ #### Request Tests
64
+
65
+ Request tests use Rack::Test to test your application's HTTP interface:
66
+
67
+ ```ruby
68
+ require "test_helper"
69
+
70
+ class RootTest < RequestTest
71
+ def test_successful_response
72
+ get "/"
73
+ assert_equal 200, last_response.status
74
+ end
75
+ end
76
+ ```
77
+
78
+ #### Feature Tests
79
+
80
+ Feature tests use Capybara for browser-based integration testing:
81
+
82
+ ```ruby
83
+ require "test_helper"
84
+
85
+ class SignUpTest < FeatureTest
86
+ def test_visit_home_page
87
+ visit "/"
88
+ assert_text "Welcome to Hanami"
89
+ end
90
+ end
91
+ ```
92
+
93
+ #### Part Tests
94
+
95
+ When generating a view part, a test is automatically created:
96
+
97
+ ```ruby
98
+ require "test_helper"
99
+
100
+ class MyApp::Views::Parts::UserTest < Minitest::Test
101
+ def setup
102
+ @value = Object.new
103
+ @subject = MyApp::Views::Parts::User.new(value: @value)
104
+ end
105
+
106
+ def test_works
107
+ assert_kind_of MyApp::Views::Parts::User, @subject
108
+ end
109
+ end
110
+ ```
111
+
112
+ ### Database Cleaning
113
+
114
+ If you're using `hanami-db`, database cleaning is automatically configured using `database_cleaner-sequel`.
115
+
116
+ Feature tests automatically get database cleaning. For other tests that need database access, simply include the `TestSupport::DB` module:
117
+
118
+ ```ruby
119
+ require "test_helper"
120
+
121
+ class MyDatabaseTest < Minitest::Test
122
+ include TestSupport::DB # This test will get database cleaning
123
+
124
+ def test_database_operation
125
+ # Database is cleaned before and after this test
126
+ end
127
+ end
128
+ ```
129
+
130
+ By default, tests use database transactions (fast). If you need truncation (e.g., for JavaScript-driven tests), define a `use_truncation?` method:
131
+
132
+ ```ruby
133
+ class DynamicFormTest < FeatureTest
134
+ def use_truncation?
135
+ true # Use truncation instead of transactions
136
+ end
137
+
138
+ def test_with_javascript
139
+ # Uses truncation strategy
140
+ end
141
+ end
142
+ ```
143
+
144
+ ### Operations Testing
145
+
146
+ The gem includes support for testing operations that use `dry-monads`:
147
+
148
+ ```ruby
149
+ require "test_helper"
150
+
151
+ class MyOperationTest < Minitest::Test
152
+ def test_successful_operation
153
+ result = MyOperation.new.call(valid_params)
154
+ assert result.success?
155
+ end
156
+
157
+ def test_failed_operation
158
+ result = MyOperation.new.call(invalid_params)
159
+ assert result.failure?
160
+ end
161
+ end
162
+ ```
163
+
164
+ ## Development
165
+
166
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
167
+
168
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
169
+
170
+ ## Contributing
171
+
172
+ Bug reports and pull requests are welcome on GitHub at https://github.com/hanami/hanami-minitest. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/hanami/hanami-minitest/blob/main/CODE_OF_CONDUCT.md).
173
+
174
+ ## Links
175
+
176
+ - [User documentation](https://hanamirb.org)
177
+ - [API documentation](http://rubydoc.info/gems/hanami-minitest)
178
+
179
+
180
+ ## License
181
+
182
+ See `LICENSE` file.
183
+
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This file is synced from hanakai-rb/repo-sync. To update it, edit repo-sync.yml.
4
+
5
+ lib = File.expand_path("lib", __dir__)
6
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
7
+ require "hanami/minitest/version"
8
+
9
+ Gem::Specification.new do |spec|
10
+ spec.name = "hanami-minitest"
11
+ spec.authors = ["Hanakai team"]
12
+ spec.email = ["info@hanakai.org"]
13
+ spec.license = "MIT"
14
+ spec.version = Hanami::Minitest::VERSION.dup
15
+
16
+ spec.summary = "Minitest support for Hanami."
17
+ spec.description = spec.summary
18
+ spec.homepage = "https://hanamirb.org"
19
+ spec.files = Dir["CHANGELOG.md", "LICENSE", "README.md", "hanami-minitest.gemspec", "lib/**/*"]
20
+ spec.bindir = "exe"
21
+ spec.executables = Dir["exe/*"].map { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.extra_rdoc_files = ["README.md", "CHANGELOG.md", "LICENSE"]
25
+
26
+ spec.metadata["changelog_uri"] = "https://github.com/hanami/hanami-minitest/blob/main/CHANGELOG.md"
27
+ spec.metadata["source_code_uri"] = "https://github.com/hanami/hanami-minitest"
28
+ spec.metadata["bug_tracker_uri"] = "https://github.com/hanami/hanami-minitest/issues"
29
+ spec.metadata["funding_uri"] = "https://github.com/sponsors/hanami"
30
+
31
+ spec.required_ruby_version = ">= 3.3"
32
+
33
+ spec.add_runtime_dependency "minitest", "~> 5.25"
34
+ spec.add_runtime_dependency "zeitwerk", "~> 2.6"
35
+ spec.add_development_dependency "bundler"
36
+ spec.add_development_dependency "rspec"
37
+ spec.add_development_dependency "yard"
38
+ end
39
+
@@ -0,0 +1,167 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "shellwords"
4
+
5
+ module Hanami
6
+ module Minitest
7
+ # @api private
8
+ module Commands
9
+ class Install < Hanami::CLI::Command
10
+ def call(*, **)
11
+ append_gemfile
12
+ append_gitignore
13
+ copy_test_helper
14
+ copy_support_minitest
15
+ copy_support_db
16
+ copy_support_features
17
+ copy_support_operations
18
+ copy_support_requests
19
+
20
+ generate_request_test
21
+ end
22
+
23
+ private
24
+
25
+ def append_gemfile
26
+ gemfile_template = Hanami.bundled?("hanami-db") ? "gemfile_db" : "gemfile"
27
+
28
+ fs.append(
29
+ fs.expand_path("Gemfile"),
30
+ fs.read(fs.expand_path(fs.join("generators", "templates", gemfile_template), __dir__))
31
+ )
32
+ end
33
+
34
+ def append_gitignore
35
+ fs.append(
36
+ fs.expand_path(".gitignore"),
37
+ fs.read(fs.expand_path(fs.join("generators", "templates", "gitignore"), __dir__))
38
+ )
39
+ end
40
+
41
+ def copy_test_helper
42
+ fs.cp(
43
+ fs.expand_path(fs.join("generators", "templates", "helper.rb"), __dir__),
44
+ fs.expand_path(fs.join("test", "test_helper.rb"))
45
+ )
46
+ end
47
+
48
+ def copy_support_minitest
49
+ fs.cp(
50
+ fs.expand_path(fs.join("generators", "templates", "support_minitest.rb"), __dir__),
51
+ fs.expand_path(fs.join("test", "support", "minitest.rb"))
52
+ )
53
+ end
54
+
55
+ def copy_support_db
56
+ return unless Hanami.bundled?("hanami-db")
57
+
58
+ fs.cp(
59
+ fs.expand_path(fs.join("generators", "templates", "support_db.rb"), __dir__),
60
+ fs.expand_path(fs.join("test", "support", "db.rb"))
61
+ )
62
+
63
+ fs.cp(
64
+ fs.expand_path(fs.join("generators", "templates", "support_db_cleaning.rb"), __dir__),
65
+ fs.expand_path(fs.join("test", "support", "db", "cleaning.rb"))
66
+ )
67
+ end
68
+
69
+ def copy_support_features
70
+ fs.cp(
71
+ fs.expand_path(fs.join("generators", "templates", "support_features.rb"), __dir__),
72
+ fs.expand_path(fs.join("test", "support", "features.rb"))
73
+ )
74
+ end
75
+
76
+ def copy_support_operations
77
+ fs.cp(
78
+ fs.expand_path(fs.join("generators", "templates", "support_operations.rb"), __dir__),
79
+ fs.expand_path(fs.join("test", "support", "operations.rb"))
80
+ )
81
+ end
82
+
83
+ def copy_support_requests
84
+ fs.cp(
85
+ fs.expand_path(fs.join("generators", "templates", "support_requests.rb"), __dir__),
86
+ fs.expand_path(fs.join("test", "support", "requests.rb"))
87
+ )
88
+ end
89
+
90
+ def generate_request_test
91
+ fs.cp(
92
+ fs.expand_path(fs.join("generators", "templates", "request.rb"), __dir__),
93
+ fs.expand_path(fs.join("test", "requests", "root_test.rb"))
94
+ )
95
+ end
96
+ end
97
+
98
+ module Generate
99
+ class Slice < Hanami::CLI::Command
100
+ def call(options = nil, name: nil, **)
101
+ slice = inflector.underscore(Shellwords.shellescape(name))
102
+
103
+ generator = Generators::Slice.new(fs: fs, inflector: inflector)
104
+ generator.call(slice)
105
+ end
106
+ end
107
+
108
+ class Action < Hanami::CLI::Commands::App::Command
109
+ def call(options = nil, name: nil, slice: nil, skip_tests: false, **)
110
+ return if skip_tests
111
+
112
+ slice = inflector.underscore(Shellwords.shellescape(slice)) if slice
113
+ key = inflector.underscore(Shellwords.shellescape(name))
114
+
115
+ namespace = slice ? inflector.camelize(slice) : app.namespace
116
+ base_path = slice ? "test/slices/#{slice}" : "test"
117
+
118
+ generator = Generators::Action.new(fs:, inflector:)
119
+ generator.call(key:, namespace:, base_path:)
120
+ end
121
+ end
122
+
123
+ class Part < Hanami::CLI::Commands::App::Command
124
+ def call(options = nil, name: nil, slice: nil, skip_tests: false, **)
125
+ return if skip_tests
126
+
127
+ slice = inflector.underscore(Shellwords.shellescape(slice)) if slice
128
+ name = inflector.underscore(Shellwords.shellescape(name))
129
+
130
+ generator = Generators::Part.new(fs: fs, inflector: inflector)
131
+ generator.call(app.namespace, slice, name)
132
+ end
133
+ end
134
+
135
+ class Operation < Hanami::CLI::Commands::App::Command
136
+ def call(options = nil, name: nil, slice: nil, skip_tests: false, **)
137
+ return if skip_tests
138
+
139
+ slice = inflector.underscore(Shellwords.shellescape(slice)) if slice
140
+ key = inflector.underscore(Shellwords.shellescape(name))
141
+
142
+ namespace = slice ? inflector.camelize(slice) : app.namespace
143
+ base_path = slice ? "test/slices/#{slice}" : "test"
144
+
145
+ generator = Generators::Operation.new(fs:, inflector:)
146
+ generator.call(key:, namespace:, base_path:)
147
+ end
148
+ end
149
+
150
+ class Mailer < Hanami::CLI::Commands::App::Command
151
+ def call(options = nil, name: nil, slice: nil, skip_tests: false, **)
152
+ return if skip_tests
153
+
154
+ slice = inflector.underscore(Shellwords.shellescape(slice)) if slice
155
+ key = inflector.underscore(Shellwords.shellescape(name))
156
+
157
+ namespace = slice ? inflector.camelize(slice) : app.namespace
158
+ base_path = slice ? "test/slices/#{slice}" : "test"
159
+
160
+ generator = Generators::Mailer.new(fs:, inflector:)
161
+ generator.call(key:, namespace:, base_path:)
162
+ end
163
+ end
164
+ end
165
+ end
166
+ end
167
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "capybara/minitest"
4
+ require_relative "test"
5
+
6
+ module Hanami
7
+ module Minitest
8
+ # Base test class for feature tests in Hanami applications.
9
+ #
10
+ # Includes Capybara DSL and assertions for browser-based integration testing.
11
+ #
12
+ # @since 2.0.0
13
+ # @api public
14
+ class FeatureTest < Test
15
+ include Capybara::DSL
16
+ include Capybara::Minitest::Assertions
17
+
18
+ Capybara.app = Hanami.app
19
+
20
+ # Resets Capybara sessions after each test.
21
+ #
22
+ # @since 2.0.0
23
+ # @api public
24
+ def teardown
25
+ super
26
+ Capybara.reset_sessions!
27
+ Capybara.use_default_driver
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "hanami/cli/generators/app/ruby_class_file"
4
+ require "hanami/cli/ruby_file_generator"
5
+
6
+ module Hanami
7
+ module Minitest
8
+ module Generators
9
+ # @since 2.0.0
10
+ # @api private
11
+ class Action
12
+ # @since 2.0.0
13
+ # @api private
14
+ def initialize(fs:, inflector:)
15
+ @fs = fs
16
+ @inflector = inflector
17
+ end
18
+
19
+ # @since 2.0.0
20
+ # @api private
21
+ def call(key:, namespace:, base_path:)
22
+ ruby_class_file = action_ruby_class_file(key: key, namespace: namespace, base_path: base_path)
23
+ test_file_path = ruby_class_file.path.gsub(/\.rb$/, "_test.rb")
24
+ action_class_name = ruby_class_file.fully_qualified_name
25
+
26
+ fs.write(test_file_path, test_content(action_class_name))
27
+ end
28
+
29
+ private
30
+
31
+ attr_reader :fs, :inflector
32
+
33
+ def action_ruby_class_file(key:, namespace:, base_path:)
34
+ Hanami::CLI::Generators::App::RubyClassFile.new(
35
+ fs: fs,
36
+ inflector: inflector,
37
+ namespace: namespace,
38
+ key: inflector.underscore(key),
39
+ base_path: base_path,
40
+ extra_namespace: "Actions"
41
+ )
42
+ end
43
+
44
+ def test_content(class_name)
45
+ Hanami::CLI::RubyFileGenerator.class(
46
+ "#{class_name}Test",
47
+ header: ["# frozen_string_literal: true", "", 'require "test_helper"'],
48
+ parent_class_name: "Hanami::Minitest::Test",
49
+ body: [
50
+ "test \"works\" do",
51
+ " params = {}",
52
+ " response = #{class_name}.new.call(params)",
53
+ " assert_predicate response, :successful?",
54
+ "end"
55
+ ]
56
+ )
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "hanami/cli/generators/app/ruby_class_file"
4
+ require "hanami/cli/ruby_file_generator"
5
+
6
+ module Hanami
7
+ module Minitest
8
+ module Generators
9
+ class Mailer
10
+ def initialize(fs:, inflector:)
11
+ @fs = fs
12
+ @inflector = inflector
13
+ end
14
+
15
+ def call(key:, namespace:, base_path:)
16
+ ruby_class_file = mailer_ruby_class_file(key:, namespace:, base_path:)
17
+ test_file_path = ruby_class_file.path.gsub(/\.rb$/, "_test.rb")
18
+ mailer_class_name = ruby_class_file.fully_qualified_name
19
+
20
+ fs.write(test_file_path, test_content(mailer_class_name))
21
+ end
22
+
23
+ private
24
+
25
+ attr_reader :fs, :inflector
26
+
27
+ def mailer_ruby_class_file(key:, namespace:, base_path:)
28
+ Hanami::CLI::Generators::App::RubyClassFile.new(
29
+ fs: fs,
30
+ inflector: inflector,
31
+ namespace: namespace,
32
+ key: inflector.underscore(key),
33
+ base_path: base_path,
34
+ extra_namespace: "Mailers"
35
+ )
36
+ end
37
+
38
+ def test_content(class_name)
39
+ Hanami::CLI::RubyFileGenerator.class(
40
+ "#{class_name}Test",
41
+ header: ["# frozen_string_literal: true", "", 'require "test_helper"'],
42
+ parent_class_name: "Hanami::Minitest::Test",
43
+ body: <<~RUBY.lines(chomp: true)
44
+ # Inspect the delivered message to assert on its contents:
45
+ #
46
+ # assert_equal ["recipient@example.com"], result.message.to
47
+ # assert_equal "Welcome", result.message.subject
48
+
49
+ test "delivers" do
50
+ skip "Add assertions for your mailer"
51
+
52
+ result = #{class_name}.new.deliver
53
+
54
+ assert_predicate result, :success?
55
+ end
56
+ RUBY
57
+ )
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "hanami/cli/generators/app/ruby_class_file"
4
+ require "hanami/cli/ruby_file_generator"
5
+
6
+ module Hanami
7
+ module Minitest
8
+ module Generators
9
+ class Operation
10
+ def initialize(fs:, inflector:)
11
+ @fs = fs
12
+ @inflector = inflector
13
+ end
14
+
15
+ def call(key:, namespace:, base_path:)
16
+ ruby_class_file = operation_ruby_class_file(key: key, namespace: namespace, base_path: base_path)
17
+ test_file_path = ruby_class_file.path.gsub(/\.rb$/, "_test.rb")
18
+ operation_class_name = ruby_class_file.fully_qualified_name
19
+
20
+ fs.write(test_file_path, test_content(operation_class_name))
21
+ end
22
+
23
+ private
24
+
25
+ attr_reader :fs, :inflector
26
+
27
+ def operation_ruby_class_file(key:, namespace:, base_path:)
28
+ Hanami::CLI::Generators::App::RubyClassFile.new(
29
+ fs: fs,
30
+ inflector: inflector,
31
+ namespace: namespace,
32
+ key: inflector.underscore(key),
33
+ base_path: base_path
34
+ )
35
+ end
36
+
37
+ def test_content(class_name)
38
+ Hanami::CLI::RubyFileGenerator.class(
39
+ "#{class_name}Test",
40
+ header: ["# frozen_string_literal: true", "", 'require "test_helper"'],
41
+ parent_class_name: "Hanami::Minitest::Test",
42
+ body: <<~RUBY.lines(chomp: true)
43
+ # Use `Success` and `Failure` (from test/support/operations.rb) to assert on an operation's
44
+ # wrapped value:
45
+ #
46
+ # assert_equal Success(thing), result
47
+
48
+ test "succeeds" do
49
+ skip "Add assertions for your operation"
50
+
51
+ result = #{class_name}.new.call
52
+
53
+ assert_predicate result, :success?
54
+ end
55
+ RUBY
56
+ )
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end