minitest-fix 1.0.0

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 (5) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.md +21 -0
  3. data/README.md +104 -0
  4. data/lib/minitest/fix.rb +60 -0
  5. metadata +63 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 855aabcd41718039047ec49f36d8d5fdbe1f9eb634dac5bd3efda946fa555725
4
+ data.tar.gz: 1eeff65f63f2914b1b92b7eb8865c326f2971ae5c413bac409311c118624ce29
5
+ SHA512:
6
+ metadata.gz: d46eb0497496be18b0af0a050e0f02ca102adad11dbe8a618de7932a2c55fc1ad4f517751d6da2815a6b8b6c8a977ee204cc8683a406c033bf4f81617cc88878
7
+ data.tar.gz: 6ec37672f53ec00138d14e8d2672f46f6c4a651e78cedca4fe1ea42cd9f5ce7c5d1d790e0717c624f7968e63d2e76792c71fa4e14639dd56d220c02da404f3e7
data/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015-2026 Cyril Kato
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all 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,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,104 @@
1
+ # Minitest::Fix
2
+
3
+ [![Version](https://img.shields.io/github/v/tag/fixrb/minitest-fix?label=Version&logo=github)](https://github.com/fixrb/minitest-fix/tags)
4
+ [![Yard documentation](https://img.shields.io/badge/Yard-documentation-blue.svg?logo=github)](https://gemdocs.org/gems/minitest-fix/latest/)
5
+ [![License](https://img.shields.io/github/license/fixrb/minitest-fix?label=License&logo=github)](https://github.com/fixrb/minitest-fix/raw/main/LICENSE.md)
6
+
7
+ Minitest::Fix brings the specifications of [Fix](https://github.com/fixrb/fix) to [minitest](https://github.com/minitest/minitest), as two assertions: `assert_fix :Name, value` passes when the value meets every expectation of the specification, and its message tells which it does not; `refute_fix` is its opposite. It is the way to add a specification of Fix to a minitest suite, and to keep the suite.
8
+
9
+ [fixrb.dev](https://fixrb.dev/gems/minitest-fix/) presents the gem.
10
+
11
+ ## Installation
12
+
13
+ ```ruby
14
+ # Gemfile
15
+ gem "minitest-fix"
16
+ ```
17
+
18
+ Minitest::Fix requires Ruby 3.3 or later, and depends on [Fix](https://github.com/fixrb/fix). It asks nothing of minitest but the `assert` and the `refute` of the test class that includes it.
19
+
20
+ ## Usage
21
+
22
+ ```ruby
23
+ # duck_test.rb
24
+ require "minitest/autorun"
25
+ require "minitest/fix"
26
+
27
+ Fix :Duck do
28
+ on :walk do
29
+ it MUST eq "Klop klop!"
30
+ end
31
+
32
+ on :swim do
33
+ it SHOULD eq "Swoosh..."
34
+ end
35
+
36
+ on :speak do
37
+ it MAY eq "Quaaack!"
38
+ end
39
+ end
40
+
41
+ class Duck
42
+ def walk = "Klop klop!"
43
+ def swim = "Swoosh..."
44
+ def speak = "Quaaack!"
45
+ end
46
+
47
+ class Robot
48
+ def walk = "Klop klop!"
49
+ def swim = "Glug glug..."
50
+ end
51
+
52
+ class RubberDuck
53
+ def swim = "Swoosh..."
54
+ def speak = "Squeak!"
55
+ end
56
+
57
+ class DuckTest < Minitest::Test
58
+ include Minitest::Fix
59
+
60
+ def test_duck
61
+ assert_fix :Duck, Duck.new
62
+ end
63
+
64
+ def test_robot
65
+ assert_fix :Duck, Robot.new
66
+ end
67
+
68
+ def test_rubber_duck
69
+ assert_fix :Duck, RubberDuck.new
70
+ end
71
+ end
72
+ ```
73
+
74
+ `ruby duck_test.rb` runs three tests, and one fails:
75
+
76
+ ```text
77
+ 1) Failure:
78
+ DuckTest#test_rubber_duck [duck_test.rb:47]:
79
+ Expected the value to fix Duck:
80
+ duck_test.rb:7: Error: NoMethodError: undefined method 'walk' for an instance of RubberDuck
81
+ duck_test.rb:15: Failure: expected "Squeak!" to eq "Quaaack!"
82
+ ```
83
+
84
+ `require "minitest/fix"` requires Fix, and `include Minitest::Fix` gives the two assertions to a test class, or to all of them when it is included in `Minitest::Test` itself, or in `ActiveSupport::TestCase` in a Rails application. The name is the one of a specification registered by `Fix :Name do … end`, and `KeyError` is raised when there is none. The specification is written where the suite can require it once: in the test file as above, or in a file of its own, which a test of Fix can require too.
85
+
86
+ `assert_fix` passes when every expectation passes, a warning or an info included: the robot above passes, though it swims its own way and does not speak, and minitest says nothing of it. `Fix[:Duck].test { Robot.new }` writes every line, the warning and the info among them. Failed, the assertion gives the lines of the failures and of the errors, each pointing at its expectation. `refute_fix :Name, value` passes when one expectation is not met. Each of them counts as one assertion.
87
+
88
+ The methods of the specification are sent to the value itself, in the process of the test, where its transaction, its mocks and its coverage tool are. A method that changes the value changes it for the contexts that follow, and for the rest of the test.
89
+
90
+ `assert_fix :Name, value, fork: true` runs each context in a child process, as Fix does it, on a system with `fork`: the methods are sent to a copy of the value, and the one the test holds is left as it was. It is for a value whose state is all in the process, since what lives outside is not copied. In a Rails application with transactional tests, a child does not see a row the test has created, and a row it writes is not rolled back; a mock does not see what a child received.
91
+
92
+ The assertions take a value, not a block. Since the value is given once, the contexts cannot build it anew with their lets: a specification meant for an assertion is written without `with`. What is not an outcome of an expectation is raised: an `Interrupt`, and with `fork: true` a child that died or a Ruby without `fork`.
93
+
94
+ ## Versioning
95
+
96
+ Minitest::Fix follows [Semantic Versioning 2.0](https://semver.org/).
97
+
98
+ ## License
99
+
100
+ The [gem](https://rubygems.org/gems/minitest-fix) is available as open source under the terms of the [MIT License](https://github.com/fixrb/minitest-fix/raw/main/LICENSE.md).
101
+
102
+ ## Sponsors
103
+
104
+ This project is sponsored by [Sashité](https://sashite.com/)
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "fix"
4
+
5
+ # The tests of minitest: this gem adds two assertions to them.
6
+ module Minitest
7
+ # Two assertions for the tests of minitest: `assert_fix :Name, value`
8
+ # passes when the value meets every expectation of the specification of
9
+ # Fix registered under that name, and tells which it does not;
10
+ # `refute_fix` passes when it does not meet one. Included in a test class,
11
+ # beside the assertions of minitest.
12
+ #
13
+ # @example
14
+ # class DuckTest < Minitest::Test
15
+ # include Minitest::Fix
16
+ #
17
+ # def test_duck
18
+ # assert_fix :Duck, Duck.new
19
+ # end
20
+ # end
21
+ module Fix
22
+ # Fails unless the value meets every expectation of the specification.
23
+ #
24
+ # @param name [Symbol] the name of a registered specification
25
+ # @param value [Object] the value, the subject of every expectation
26
+ # @param fork [Boolean] whether each context runs in a child process, on a
27
+ # copy of the value, as Fix does it; by default, the methods of the
28
+ # specification are sent to the value itself, in the process of the test
29
+ # @return [true]
30
+ # @raise [Minitest::Assertion] with the expectations not met, one line each
31
+ # @raise [KeyError] when no specification has that name
32
+ # @raise [NotImplementedError] with a child per context, when this Ruby
33
+ # cannot fork
34
+ # @raise [Aw::ChildError] with a child per context, when one died or
35
+ # delivered no result; what is raised outside an expectation is raised
36
+ # here again, with children or without
37
+ def assert_fix(name, value, fork: false)
38
+ spec = ::Fix[name]
39
+ unmet = spec.run(fork:) { value }.reject(&:passed?)
40
+ assert(unmet.empty?, ["Expected the value to #{spec}:", *unmet].join("\n "))
41
+ end
42
+
43
+ # Fails when the value meets every expectation of the specification.
44
+ #
45
+ # @param (see #assert_fix)
46
+ # @return [true]
47
+ # @raise [Minitest::Assertion] with the expectations met, one line each
48
+ # @raise [KeyError] when no specification has that name
49
+ # @raise [NotImplementedError] with a child per context, when this Ruby
50
+ # cannot fork
51
+ # @raise [Aw::ChildError] with a child per context, when one died or
52
+ # delivered no result; what is raised outside an expectation is raised
53
+ # here again, with children or without
54
+ def refute_fix(name, value, fork: false)
55
+ spec = ::Fix[name]
56
+ results = spec.run(fork:) { value }
57
+ refute(results.all?(&:passed?), ["Expected the value not to #{spec}:", *results].join("\n "))
58
+ end
59
+ end
60
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: minitest-fix
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Cyril Kato
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: fix
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '1.0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '1.0'
26
+ description: 'Minitest::Fix adds two assertions to the tests of minitest: assert_fix
27
+ :Name, value passes when the value meets every expectation of that specification
28
+ of Fix, and its message tells which it does not; refute_fix is its opposite. A specification
29
+ of Fix, beside the suite a project already has.'
30
+ email: contact@cyril.email
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - LICENSE.md
36
+ - README.md
37
+ - lib/minitest/fix.rb
38
+ homepage: https://fixrb.dev/gems/minitest-fix/
39
+ licenses:
40
+ - MIT
41
+ metadata:
42
+ bug_tracker_uri: https://github.com/fixrb/minitest-fix/issues
43
+ documentation_uri: https://gemdocs.org/gems/minitest-fix/1.0.0/
44
+ rubygems_mfa_required: 'true'
45
+ source_code_uri: https://github.com/fixrb/minitest-fix
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 3.3.0
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubygems_version: 4.0.23
61
+ specification_version: 4
62
+ summary: Assertions of minitest that test a value against a specification of Fix
63
+ test_files: []