minitest-should_just_work 0.1.0 → 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.
- checksums.yaml +4 -4
- data/.rubocop.yml +34 -1
- data/CHANGELOG.md +48 -0
- data/Gemfile +4 -3
- data/README.md +72 -111
- data/Rakefile +3 -0
- data/lib/minitest/should_just_work/version.rb +1 -1
- data/lib/minitest/should_just_work.rb +129 -127
- data/sig/minitest/should_just_work.rbs +45 -1
- metadata +19 -42
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 569475f4cf322d65bba65f7af827108621daf18e40ae175385b73b402766e616
|
|
4
|
+
data.tar.gz: bb2d04f22ec617d48f86d09166363281282bdadb8d3af51a69847d201b7bc517
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 42590821b85e5a88ceca0f43d982af5e508e836fb8385c9e639f1ec0b5a3075f556a9b63d2d5d8a56a338a9eb2549bc3ab1350f47d5eff755fdb60db9ed9d180
|
|
7
|
+
data.tar.gz: f3d9eb37e609b564c718391283c98dd858a0b3e0c6c9f33dc95f46329a1931737d1b6c80200f117f5bc365e3c189c4fb27df69e4add379f60e4aa65d0c645158
|
data/.rubocop.yml
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
AllCops:
|
|
2
|
-
TargetRubyVersion:
|
|
2
|
+
TargetRubyVersion: 3.1
|
|
3
|
+
NewCops: enable
|
|
4
|
+
SuggestExtensions: false
|
|
3
5
|
|
|
4
6
|
Style/StringLiterals:
|
|
5
7
|
Enabled: true
|
|
@@ -11,3 +13,34 @@ Style/StringLiteralsInInterpolation:
|
|
|
11
13
|
|
|
12
14
|
Layout/LineLength:
|
|
13
15
|
Max: 120
|
|
16
|
+
|
|
17
|
+
# The Object patch belongs next to the DSL it exists for, not hidden in a file
|
|
18
|
+
# of its own.
|
|
19
|
+
Style/OneClassPerFile:
|
|
20
|
+
Exclude:
|
|
21
|
+
- lib/minitest/should_just_work.rb
|
|
22
|
+
- test/**/*
|
|
23
|
+
|
|
24
|
+
# `obj.should == 2` is a statement by design, and `obj.should == nil` is the
|
|
25
|
+
# documented way to assert nil. These three cops object to exactly that, so any
|
|
26
|
+
# test suite using this gem has to switch them off.
|
|
27
|
+
Lint/Void:
|
|
28
|
+
Exclude:
|
|
29
|
+
- test/**/*
|
|
30
|
+
Style/NilComparison:
|
|
31
|
+
Exclude:
|
|
32
|
+
- test/**/*
|
|
33
|
+
Style/NonNilCheck:
|
|
34
|
+
Exclude:
|
|
35
|
+
- test/**/*
|
|
36
|
+
|
|
37
|
+
# A `describe` block covering the whole DSL is far longer than the default limit.
|
|
38
|
+
Metrics/BlockLength:
|
|
39
|
+
Exclude:
|
|
40
|
+
- test/**/*
|
|
41
|
+
Metrics/MethodLength:
|
|
42
|
+
Exclude:
|
|
43
|
+
- test/**/*
|
|
44
|
+
Metrics/AbcSize:
|
|
45
|
+
Exclude:
|
|
46
|
+
- test/**/*
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,53 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [1.0.0] - 2026-08-25
|
|
4
|
+
|
|
5
|
+
This release narrows the gem to the operator syntax it was really used for, and
|
|
6
|
+
fixes everything that was broken in the part that stays.
|
|
7
|
+
|
|
8
|
+
### Removed
|
|
9
|
+
|
|
10
|
+
- The chained matcher DSL. `should.be`, `.a`, `.an`, `.nil`, `.empty`,
|
|
11
|
+
`.include`, `.same`, `.instance_of`, `.kind_of`, `.respond_to`, `.close`,
|
|
12
|
+
`.in_epsilon`, `.satisfy`, `.true`, `.false`, `.match` and `.equal` are gone,
|
|
13
|
+
along with the pass-through predicates (`should.be.empty?`) and the custom
|
|
14
|
+
matcher hook (`ShouldJustWork.add` / `Should.add`).
|
|
15
|
+
|
|
16
|
+
Use plain Minitest assertions for those: `assert_empty x`, `assert_includes x, y`,
|
|
17
|
+
`assert_instance_of Y, x`, and so on. The old spellings raise `NoMethodError`
|
|
18
|
+
with a message naming what is supported, rather than silently passing.
|
|
19
|
+
|
|
20
|
+
This removes all of the metaprogramming the gem used to need: the matcher
|
|
21
|
+
proxy no longer defines `method_missing` matchers and no longer undefines the
|
|
22
|
+
methods it inherits from `Object`.
|
|
23
|
+
|
|
24
|
+
### Fixed
|
|
25
|
+
|
|
26
|
+
- Works on Minitest 6. The gem required the removed `minitest/unit`, and patched
|
|
27
|
+
the removed `MiniTest` constant alias, so on Minitest 6 it failed to load at
|
|
28
|
+
all. It now requires `minitest` and uses the `Minitest` namespace, and is
|
|
29
|
+
tested against both Minitest 5 and 6.
|
|
30
|
+
- `x.should == nil` now asserts nil. It used to become `assert_equal nil, x`,
|
|
31
|
+
which Minitest 5 deprecates and Minitest 6 fails outright.
|
|
32
|
+
- `should.raise(SomeError) { ... }` passed a `nil` message through to
|
|
33
|
+
`assert_raises`, which Minitest 6 rejects with a `TypeError`.
|
|
34
|
+
- The test currently running is kept in a thread variable instead of a class
|
|
35
|
+
variable, so assertions no longer leak between tests running in parallel
|
|
36
|
+
threads.
|
|
37
|
+
- Using `should` outside of a running test now raises a clear
|
|
38
|
+
`Minitest::ShouldJustWork::Error` instead of failing obscurely.
|
|
39
|
+
|
|
40
|
+
### Added
|
|
41
|
+
|
|
42
|
+
- `should_not.raise(SomeError) { ... }` and `should_not.throw(:sym) { ... }`,
|
|
43
|
+
which previously printed a warning and asserted nothing.
|
|
44
|
+
- A real test suite, and CI across Ruby 3.1-4.0 and Minitest 5 and 6.
|
|
45
|
+
|
|
46
|
+
### Changed
|
|
47
|
+
|
|
48
|
+
- Requires Ruby >= 3.1 (was 2.6, which has been end-of-life since 2022).
|
|
49
|
+
- The `minitest` dependency is constrained to `>= 5.0, < 7`.
|
|
50
|
+
|
|
3
51
|
## [0.1.0] - 2022-12-21
|
|
4
52
|
|
|
5
53
|
- Initial release
|
data/Gemfile
CHANGED
|
@@ -5,8 +5,9 @@ source "https://rubygems.org"
|
|
|
5
5
|
# Specify your gem's dependencies in minitest-should_just_work.gemspec
|
|
6
6
|
gemspec
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
gem "minitest",
|
|
8
|
+
# CI pins this to test against every supported Minitest line.
|
|
9
|
+
minitest_version = ENV.fetch("MINITEST_VERSION", nil)
|
|
10
|
+
gem "minitest", minitest_version if minitest_version
|
|
11
11
|
|
|
12
|
+
gem "rake", "~> 13.0"
|
|
12
13
|
gem "rubocop", "~> 1.21"
|
data/README.md
CHANGED
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
# Minitest::ShouldJustWork
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://github.com/priit/minitest-should_just_work/actions/workflows/ci.yml)
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
what has not updated a long time. Therefore we need this new gem to support .should syntax.
|
|
5
|
+
Classic RSpec-like `.should` / `.should_not` comparisons for Minitest.
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
```ruby
|
|
8
|
+
book.title.should == "Revolution"
|
|
9
|
+
```
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
That is the whole idea. The gem monkey-patches Object so that comparison
|
|
12
|
+
operators after `.should` turn into plain Minitest assertions.
|
|
13
|
+
|
|
14
|
+
(*Ouch! Monkey patch?* Yes! But it only defines `Object#should` and
|
|
13
15
|
`#should_not`.)
|
|
14
16
|
|
|
17
|
+
Requires Ruby >= 3.1. Tested against Minitest 5 and Minitest 6.
|
|
18
|
+
|
|
15
19
|
## Installation
|
|
16
20
|
|
|
17
|
-
|
|
21
|
+
Add it to your application's Gemfile:
|
|
18
22
|
|
|
19
23
|
``` ruby
|
|
20
24
|
group :test do
|
|
@@ -38,131 +42,88 @@ describe "Books" do
|
|
|
38
42
|
book.title.should == "Revolution"
|
|
39
43
|
end
|
|
40
44
|
end
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Comparisons
|
|
48
|
+
|
|
49
|
+
| Minitest::ShouldJustWork | [Minitest::Assertions] |
|
|
50
|
+
|-----------------------------------|----------------------------------|
|
|
51
|
+
| `x.should == y` | `assert_equal y, x` |
|
|
52
|
+
| `x.should == nil` | `assert_nil x` |
|
|
53
|
+
| `x.should != y` | `refute_equal y, x` |
|
|
54
|
+
| `x.should != nil` | `refute_nil x` |
|
|
55
|
+
| `x.should =~ /y/` | `assert_match /y/, x` |
|
|
56
|
+
| `x.should > y` | `assert_operator x, :>, y` |
|
|
57
|
+
| `x.should < y` | `assert_operator x, :<, y` |
|
|
58
|
+
| `x.should >= y` | `assert_operator x, :>=, y` |
|
|
59
|
+
| `x.should <= y` | `assert_operator x, :<=, y` |
|
|
41
60
|
|
|
61
|
+
Note that `x.should == nil` asserts nil rather than equality with nil. Minitest 5
|
|
62
|
+
deprecates `assert_equal nil, x` and Minitest 6 fails it outright, so this is the
|
|
63
|
+
only spelling that can work.
|
|
64
|
+
|
|
65
|
+
### Negating
|
|
66
|
+
|
|
67
|
+
Use `should_not`, or `should.not`, to turn any comparison into its `refute_`:
|
|
68
|
+
|
|
69
|
+
```ruby
|
|
70
|
+
obj.should_not == 3 # => refute_equal 3, obj
|
|
71
|
+
obj.should_not =~ /regex/ # => refute_match /regex/, obj
|
|
72
|
+
obj.should_not == nil # => refute_nil obj
|
|
42
73
|
```
|
|
43
74
|
|
|
44
|
-
|
|
75
|
+
### Exceptions and throws
|
|
45
76
|
|
|
46
77
|
```ruby
|
|
47
|
-
obj.should == 2 # => assert_equal 2, obj
|
|
48
|
-
obj.should =~ /regex/ # => assert_match /regex/, obj
|
|
49
|
-
obj.should != 3 # => assert_not_equal 3, obj
|
|
50
|
-
obj.should.nil # => assert_nil obj
|
|
51
|
-
obj.should.respond_to(:freeze) # => assert_respond_to obj, :freeze
|
|
52
|
-
|
|
53
|
-
# Note that .be, .a and .an are optional.
|
|
54
|
-
obj.should.nil # => assert_nil obj
|
|
55
|
-
obj.should.be.nil # => assert_nil obj
|
|
56
|
-
obj.should.be.a.nil # => assert_nil obj
|
|
57
|
-
|
|
58
|
-
# Use `should.not` instead `should` to negate any comparison.
|
|
59
|
-
obj.should.not == 3 # => refute_equal 3, obj
|
|
60
|
-
obj.should.not =~ /regex/ # => refute_match obj, regex
|
|
61
|
-
obj.should.not.be.nil # => refute obj.nil?
|
|
62
|
-
|
|
63
|
-
# Anything else will pass through with a ?:
|
|
64
|
-
obj.should.be.good_looking # => assert obj.good_looking?
|
|
65
|
-
|
|
66
|
-
# Testing exceptions:
|
|
67
78
|
should.raise ZeroDivisionError do
|
|
68
|
-
2/0
|
|
79
|
+
2 / 0
|
|
69
80
|
end
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
## Wrapped assertions
|
|
73
|
-
|
|
74
|
-
These are based on [MiniTest::Assertions].
|
|
75
|
-
|
|
76
|
-
| MiniTest::ShouldJustWork | [MiniTest::Assertions] |
|
|
77
|
-
|-----------------------------------------|-----------------------------|
|
|
78
|
-
| x.should.equal y | assert_equal x, y |
|
|
79
|
-
| x.should == y | assert_equal x, y |
|
|
80
|
-
| x.should.not.equal | refute_equal x, y |
|
|
81
|
-
| x.should != | refute_equal x, y |
|
|
82
|
-
| x.should.be | assert_same x, y |
|
|
83
|
-
| x.should.not.be | refute_same x, y |
|
|
84
|
-
| x.should >= *(and others)* | assert_operator x, :>=, y |
|
|
85
|
-
| x.should.not >= *(and others)* | refute_operator x, :>=, y |
|
|
86
|
-
| x.should.be.nil | assert_nil x |
|
|
87
|
-
| x.should.not.be.nil | refute_nil x |
|
|
88
|
-
| x.should.be.close y | assert_in_delta y |
|
|
89
|
-
| x.should.be.in_epsilon y | assert_in_epsilon y |
|
|
90
|
-
| x.should.match /y/ | assert_match x, /y/ |
|
|
91
|
-
| x.should =~ /y/ | assert_match x, /y/ |
|
|
92
|
-
| x.should.not.match, should.not =~ | refute_match |
|
|
93
|
-
| x.should.be.an.instance_of y | assert_instance_of x, y |
|
|
94
|
-
| x.should.be.a.kind_of x, y | assert_kind_of x, y |
|
|
95
|
-
| x.should.respond_to :y | assert_respond_to x, :y |
|
|
96
|
-
| should.raise(x) { ... } | assert_raise(x) { ... } |
|
|
97
|
-
| should.throw(x) { ... } | assert_throws(x) { ... } |
|
|
98
|
-
| should.satisfy { ... } | assert_block { ... } |
|
|
99
|
-
|
|
100
|
-
[MiniTest::Assertions]: https://github.com/seattlerb/minitest/blob/master/lib/minitest/unit.rb
|
|
101
|
-
|
|
102
|
-
## Messages
|
|
103
|
-
|
|
104
|
-
Use the `otherwise` helper:
|
|
105
81
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
82
|
+
should_not.raise ZeroDivisionError do
|
|
83
|
+
2 / 1
|
|
84
|
+
end
|
|
109
85
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
end
|
|
86
|
+
should.throw(:done) { throw :done }
|
|
87
|
+
should_not.throw(:done) { keep_going }
|
|
113
88
|
```
|
|
114
89
|
|
|
115
|
-
|
|
90
|
+
`should.raise` with no argument catches `StandardError`.
|
|
116
91
|
|
|
117
|
-
|
|
118
|
-
1) Failure:
|
|
119
|
-
should work(Test) [your_test.rb:77]:
|
|
120
|
-
The title should've been set on constructor.
|
|
121
|
-
Expected: "Pride & Prejudice"
|
|
122
|
-
Actual: nil
|
|
123
|
-
```
|
|
92
|
+
[Minitest::Assertions]: https://github.com/minitest/minitest/blob/master/lib/minitest/assertions.rb
|
|
124
93
|
|
|
125
|
-
|
|
126
|
-
syntax):
|
|
94
|
+
## RuboCop
|
|
127
95
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
96
|
+
`obj.should == 2` is a statement whose value is discarded, and `obj.should == nil`
|
|
97
|
+
compares against nil on purpose. Three cops object to exactly that, so switch
|
|
98
|
+
them off for your tests:
|
|
131
99
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
100
|
+
``` yaml
|
|
101
|
+
Lint/Void:
|
|
102
|
+
Exclude:
|
|
103
|
+
- test/**/*
|
|
104
|
+
Style/NilComparison:
|
|
105
|
+
Exclude:
|
|
106
|
+
- test/**/*
|
|
107
|
+
Style/NonNilCheck:
|
|
108
|
+
Exclude:
|
|
109
|
+
- test/**/*
|
|
135
110
|
```
|
|
136
111
|
|
|
137
|
-
|
|
112
|
+
Ruby's own `-w` will also report "useless use of == in void context" for every
|
|
113
|
+
line, so leave warnings off for your test task.
|
|
138
114
|
|
|
139
|
-
|
|
140
|
-
`MiniTest::ShouldJustWork.add`.
|
|
115
|
+
## Development
|
|
141
116
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
def boogie_all_night!
|
|
145
|
-
# Delegates to `assert(condition, message)`.
|
|
146
|
-
#
|
|
147
|
-
# positive? - returns `true` if .should, or `false` if .should.not
|
|
148
|
-
# test - the MiniTest object
|
|
149
|
-
# msg - the failure message. `nil` if not set
|
|
150
|
-
#
|
|
151
|
-
if positive?
|
|
152
|
-
test.assert left.respond_to?(:dance), msg
|
|
153
|
-
else
|
|
154
|
-
test.refute left.respond_to?(:dance), msg
|
|
155
|
-
end
|
|
156
|
-
end
|
|
157
|
-
end
|
|
117
|
+
$ bin/setup
|
|
118
|
+
$ bundle exec rake # tests and RuboCop
|
|
158
119
|
|
|
159
|
-
|
|
120
|
+
To run the suite against a particular Minitest line:
|
|
160
121
|
|
|
161
|
-
|
|
162
|
-
dancer.should.boogie_all_night!
|
|
163
|
-
```
|
|
122
|
+
$ MINITEST_VERSION="~> 5.0" bundle install && MINITEST_VERSION="~> 5.0" bundle exec rake test
|
|
164
123
|
|
|
165
124
|
## Acknowledgements & licensing
|
|
166
125
|
|
|
167
|
-
|
|
126
|
+
Inspired by the minitest-should_syntax gem.
|
|
127
|
+
|
|
128
|
+
(c) 2022-2026 Priit Tark, MIT license
|
|
168
129
|
(c) 2013 Rico Sta. Cruz, MIT license
|
data/Rakefile
CHANGED
|
@@ -7,6 +7,9 @@ Rake::TestTask.new(:test) do |t|
|
|
|
7
7
|
t.libs << "test"
|
|
8
8
|
t.libs << "lib"
|
|
9
9
|
t.test_files = FileList["test/**/test_*.rb"]
|
|
10
|
+
# The whole point of this gem is that `obj.should == 2` is a statement, which
|
|
11
|
+
# Ruby's -w flags as a useless use of == in void context on every single line.
|
|
12
|
+
t.warning = false
|
|
10
13
|
end
|
|
11
14
|
|
|
12
15
|
require "rubocop/rake_task"
|
|
@@ -1,178 +1,180 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
require "minitest"
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
# Rspec-like matching for MiniTest.
|
|
8
|
-
#
|
|
9
|
-
# == Usage
|
|
10
|
-
#
|
|
11
|
-
# # All objects get .should:
|
|
12
|
-
# obj.should == 2
|
|
13
|
-
# obj.should ~= /regex/
|
|
14
|
-
# obj.should != 3
|
|
15
|
-
# obj.should.be.true # Truthy
|
|
16
|
-
# obj.should.be.false # Falsy
|
|
17
|
-
#
|
|
18
|
-
# # Anything else will just pass thru:
|
|
19
|
-
# obj.should.nil? # same as: assert obj.nil?
|
|
20
|
-
# obj.should.be.nil? # same as: assert obj.nil?
|
|
21
|
-
# obj.should.respond_to?(:freeze)
|
|
22
|
-
#
|
|
23
|
-
# # You can also use should_not:
|
|
24
|
-
# obj.should_not == 3
|
|
25
|
-
# obj.should_not.be.nil?
|
|
26
|
-
#
|
|
27
|
-
# # Errors and throws
|
|
28
|
-
# should.raise(Error) { lol }
|
|
29
|
-
# should.throw(:x) { lol }
|
|
30
|
-
#
|
|
31
|
-
# # Messages
|
|
32
|
-
# msg "Age must be set properly"
|
|
33
|
-
# age.should == 18
|
|
34
|
-
#
|
|
5
|
+
require_relative "should_just_work/version"
|
|
35
6
|
|
|
7
|
+
# Minitest's own namespace, reopened to hold the DSL and to teach Minitest::Test
|
|
8
|
+
# about it.
|
|
36
9
|
module Minitest
|
|
10
|
+
# Rspec-like operator assertions for Minitest.
|
|
11
|
+
#
|
|
12
|
+
# == Usage
|
|
13
|
+
#
|
|
14
|
+
# obj.should == 2
|
|
15
|
+
# obj.should != 3
|
|
16
|
+
# obj.should == nil # asserts nil, not equality with nil
|
|
17
|
+
# obj.should =~ /regex/
|
|
18
|
+
# obj.should > 1
|
|
19
|
+
#
|
|
20
|
+
# # Negate with should_not, or with .not:
|
|
21
|
+
# obj.should_not == 3
|
|
22
|
+
# obj.should.not == 3
|
|
23
|
+
#
|
|
24
|
+
# # Errors and throws:
|
|
25
|
+
# should.raise(ArgumentError) { boom }
|
|
26
|
+
# should_not.throw(:x) { quiet }
|
|
27
|
+
#
|
|
28
|
+
# # Messages:
|
|
29
|
+
# otherwise "Age must be set properly"
|
|
30
|
+
# age.should == 18
|
|
31
|
+
#
|
|
37
32
|
module ShouldJustWork
|
|
33
|
+
# Raised when the DSL is used outside of a running Minitest test.
|
|
38
34
|
class Error < StandardError; end
|
|
39
35
|
|
|
36
|
+
# The object returned by Object#should. It remembers what .should was called
|
|
37
|
+
# on and forwards the comparison to the test that is currently running.
|
|
40
38
|
class Should
|
|
41
|
-
|
|
39
|
+
# The chained matcher DSL (`should.be.empty`, `should.be.nil?`) was dropped
|
|
40
|
+
# in 1.0. Object answers to some of those names itself, so without this the
|
|
41
|
+
# old spelling would quietly return a boolean and pass without asserting
|
|
42
|
+
# anything. Undefined, they raise instead.
|
|
43
|
+
%i[nil? frozen? respond_to? is_a? kind_of? instance_of? eql? equal?].each do |name|
|
|
44
|
+
undef_method name if method_defined?(name)
|
|
45
|
+
end
|
|
42
46
|
|
|
47
|
+
# Remembers the test that is currently running. Minitest can run tests in
|
|
48
|
+
# parallel threads, so the test is kept in a thread variable rather than in
|
|
49
|
+
# a class variable shared by every thread.
|
|
43
50
|
def self.init(test) # :nodoc:
|
|
44
|
-
|
|
51
|
+
::Thread.current.thread_variable_set(:minitest_should_just_work_test, test)
|
|
45
52
|
end
|
|
46
53
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
send :include, extension
|
|
54
|
+
def self.current # :nodoc:
|
|
55
|
+
::Thread.current.thread_variable_get(:minitest_should_just_work_test)
|
|
50
56
|
end
|
|
51
57
|
|
|
52
58
|
def initialize(left)
|
|
53
59
|
@left = left
|
|
60
|
+
@neg = false
|
|
54
61
|
|
|
55
|
-
|
|
62
|
+
pending = test.msg
|
|
63
|
+
return unless pending
|
|
56
64
|
|
|
57
|
-
blaming test.msg
|
|
58
65
|
test.msg = nil
|
|
59
66
|
end
|
|
60
67
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
def
|
|
68
|
+
# `should == nil` means assert_nil rather than assert_equal, which Minitest
|
|
69
|
+
# 6 refuses outright and Minitest 5 deprecates.
|
|
70
|
+
def ==(other)
|
|
71
|
+
other.nil? ? assert_or_refute(:nil, left) : assert_or_refute(:equal, other, left)
|
|
72
|
+
end
|
|
64
73
|
|
|
65
|
-
def
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
def not() @neg = true; self; end
|
|
74
|
+
def !=(other)
|
|
75
|
+
other.nil? ? refute_or_assert(:nil, left) : refute_or_assert(:equal, other, left)
|
|
76
|
+
end
|
|
69
77
|
|
|
70
|
-
def
|
|
71
|
-
def
|
|
78
|
+
def =~(other) = assert_or_refute(:match, other, left)
|
|
79
|
+
def >(other) = assert_or_refute(:operator, left, :>, other)
|
|
80
|
+
def <(other) = assert_or_refute(:operator, left, :<, other)
|
|
81
|
+
def >=(other) = assert_or_refute(:operator, left, :>=, other)
|
|
82
|
+
def <=(other) = assert_or_refute(:operator, left, :<=, other)
|
|
72
83
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
test.send method, val, [msg, 'Expected to be falsy'].compact.join("\n")
|
|
84
|
+
# Negates the comparison that follows. `should_not` is the shorthand.
|
|
85
|
+
def not
|
|
86
|
+
@neg = true
|
|
87
|
+
self
|
|
78
88
|
end
|
|
79
89
|
|
|
80
|
-
|
|
81
|
-
def
|
|
90
|
+
# should.throw(:sym) { ... } and should_not.throw(:sym) { ... }
|
|
91
|
+
def throw(sym = nil, &blk)
|
|
92
|
+
return test.send(:assert_throws, sym, msg, &blk) if positive?
|
|
82
93
|
|
|
83
|
-
|
|
84
|
-
def =~(right) assert_or_refute :match, right, left; end
|
|
85
|
-
def !=(right) refute_or_assert :equal, right, left; end
|
|
86
|
-
def >(right) assert_or_refute :operator, left, :>, right; end
|
|
87
|
-
def <(right) assert_or_refute :operator, left, :<, right; end
|
|
88
|
-
def >=(right) assert_or_refute :operator, left, :>=, right; end
|
|
89
|
-
def <=(right) assert_or_refute :operator, left, :<=, right; end
|
|
90
|
-
def include(right) assert_or_refute :includes, left, right; end
|
|
91
|
-
def instance_of(right) assert_or_refute :instance_of, right, left; end
|
|
92
|
-
def kind_of(right) assert_or_refute :kind_of, right, left; end
|
|
93
|
-
def nil() assert_or_refute :nil, left; end
|
|
94
|
-
def same(right) assert_or_refute :same, right, left; end
|
|
95
|
-
def respond_to(right) assert_or_refute :respond_to, left, right; end
|
|
96
|
-
def empty() assert_or_refute :empty, left; end
|
|
97
|
-
def satisfy(&blk) assert_or_refute :block, &blk; end
|
|
94
|
+
::Kernel.raise(Error, "should_not.throw needs a symbol to watch for") if sym.nil?
|
|
98
95
|
|
|
99
|
-
|
|
100
|
-
|
|
96
|
+
thrown = true
|
|
97
|
+
::Kernel.catch(sym) do
|
|
98
|
+
blk.call
|
|
99
|
+
thrown = false
|
|
100
|
+
end
|
|
101
|
+
test.send(:refute, thrown, [msg, "Expected the block not to throw #{sym.inspect}"].compact.join("\n"))
|
|
102
|
+
end
|
|
101
103
|
|
|
102
|
-
|
|
103
|
-
def
|
|
104
|
+
# should.raise(SomeError) { ... } and should_not.raise(SomeError) { ... }
|
|
105
|
+
def raise(exception = ::StandardError, &)
|
|
106
|
+
return test.send(:assert_raises, *[exception, msg].compact, &) if positive?
|
|
104
107
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
+
raised = capture(exception, &)
|
|
109
|
+
test.send(:refute, raised,
|
|
110
|
+
[msg, "Expected the block not to raise #{exception}, got #{raised.inspect}"].compact.join("\n"))
|
|
108
111
|
end
|
|
109
112
|
|
|
110
|
-
|
|
111
|
-
args << msg
|
|
112
|
-
test.send((negative? ? :"assert_#{what}" : :"refute_#{what}"), *args)
|
|
113
|
-
end
|
|
113
|
+
private
|
|
114
114
|
|
|
115
|
-
|
|
116
|
-
if positive?
|
|
117
|
-
test.send :assert_throws, what, msg, &blk
|
|
118
|
-
else
|
|
119
|
-
warn "ShouldJustWork: should.not.throw is not supported"
|
|
120
|
-
end
|
|
121
|
-
end
|
|
115
|
+
attr_reader :left, :msg
|
|
122
116
|
|
|
123
|
-
def
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
else
|
|
127
|
-
warn "ShouldJustWork: should.not.raise is not supported"
|
|
128
|
-
end
|
|
117
|
+
def test
|
|
118
|
+
Should.current ||
|
|
119
|
+
::Kernel.raise(Error, "#should can only be used inside a running Minitest test")
|
|
129
120
|
end
|
|
130
121
|
|
|
131
|
-
def
|
|
132
|
-
|
|
133
|
-
method = positive? ? :assert : :refute
|
|
122
|
+
def positive? = !@neg
|
|
123
|
+
def negative? = @neg
|
|
134
124
|
|
|
135
|
-
|
|
125
|
+
def assert_or_refute(what, *args)
|
|
136
126
|
args << msg if msg
|
|
137
|
-
|
|
138
|
-
test.send method, *args
|
|
127
|
+
test.send(positive? ? :"assert_#{what}" : :"refute_#{what}", *args)
|
|
139
128
|
end
|
|
140
|
-
end
|
|
141
|
-
end
|
|
142
|
-
end
|
|
143
129
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
130
|
+
def refute_or_assert(what, *args)
|
|
131
|
+
args << msg if msg
|
|
132
|
+
test.send(negative? ? :"assert_#{what}" : :"refute_#{what}", *args)
|
|
133
|
+
end
|
|
148
134
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
135
|
+
def capture(exception)
|
|
136
|
+
yield
|
|
137
|
+
nil
|
|
138
|
+
rescue exception => e
|
|
139
|
+
e
|
|
140
|
+
end
|
|
153
141
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
142
|
+
def method_missing(name, ...)
|
|
143
|
+
::Kernel.raise(NoMethodError,
|
|
144
|
+
"undefined matcher '#{name}'. minitest-should_just_work supports the operators " \
|
|
145
|
+
"==, !=, =~, <, >, <= and >=, plus should.raise and should.throw")
|
|
146
|
+
end
|
|
159
147
|
|
|
160
|
-
|
|
161
|
-
MiniTest::ShouldJustWork::Should.init self
|
|
162
|
-
mts_before_setup(*a, &block)
|
|
148
|
+
def respond_to_missing?(_name, _include_private = false) = false
|
|
163
149
|
end
|
|
164
150
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
151
|
+
# Prepended to Minitest::Test so every test hands itself to ShouldJustWork
|
|
152
|
+
# before it runs, and so tests gain the #msg and #otherwise helpers.
|
|
153
|
+
module TestHelpers
|
|
154
|
+
def before_setup
|
|
155
|
+
Should.init self
|
|
156
|
+
super
|
|
157
|
+
end
|
|
169
158
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
159
|
+
# Reads the failure message waiting to be attached to the next comparison,
|
|
160
|
+
# or sets it when given one.
|
|
161
|
+
def msg(string = nil)
|
|
162
|
+
self.msg = string if string
|
|
163
|
+
@msg
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
attr_writer :msg
|
|
173
167
|
|
|
174
|
-
|
|
175
|
-
|
|
168
|
+
# Reads better than #msg in front of an assertion.
|
|
169
|
+
def otherwise(message) = msg(message)
|
|
176
170
|
end
|
|
177
171
|
end
|
|
172
|
+
|
|
173
|
+
Test.prepend ShouldJustWork::TestHelpers
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
# The one monkey patch this gem makes: every object gains #should and #should_not.
|
|
177
|
+
class Object
|
|
178
|
+
def should = Minitest::ShouldJustWork::Should.new(self)
|
|
179
|
+
def should_not = should.not
|
|
178
180
|
end
|
|
@@ -1,6 +1,50 @@
|
|
|
1
1
|
module Minitest
|
|
2
2
|
module ShouldJustWork
|
|
3
3
|
VERSION: String
|
|
4
|
-
|
|
4
|
+
|
|
5
|
+
class Error < StandardError
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
class Should
|
|
9
|
+
def self.init: (untyped test) -> void
|
|
10
|
+
def self.current: () -> untyped
|
|
11
|
+
|
|
12
|
+
def initialize: (untyped left) -> void
|
|
13
|
+
|
|
14
|
+
def ==: (untyped other) -> untyped
|
|
15
|
+
def !=: (untyped other) -> untyped
|
|
16
|
+
def =~: (untyped other) -> untyped
|
|
17
|
+
def >: (untyped other) -> untyped
|
|
18
|
+
def <: (untyped other) -> untyped
|
|
19
|
+
def >=: (untyped other) -> untyped
|
|
20
|
+
def <=: (untyped other) -> untyped
|
|
21
|
+
|
|
22
|
+
def throw: (?Symbol sym) { () -> untyped } -> untyped
|
|
23
|
+
def raise: (?Class exception) { () -> untyped } -> untyped
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
attr_reader left: untyped
|
|
28
|
+
attr_reader msg: String?
|
|
29
|
+
|
|
30
|
+
def test: () -> untyped
|
|
31
|
+
def positive?: () -> bool
|
|
32
|
+
def negative?: () -> bool
|
|
33
|
+
def assert_or_refute: (Symbol what, *untyped args) -> untyped
|
|
34
|
+
def refute_or_assert: (Symbol what, *untyped args) -> untyped
|
|
35
|
+
def capture: (Class exception) { () -> untyped } -> Exception?
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
module TestHelpers
|
|
39
|
+
def before_setup: () -> void
|
|
40
|
+
def msg: (?String? string) -> String?
|
|
41
|
+
def msg=: (String? string) -> String?
|
|
42
|
+
def otherwise: (String message) -> String?
|
|
43
|
+
end
|
|
5
44
|
end
|
|
6
45
|
end
|
|
46
|
+
|
|
47
|
+
class Object
|
|
48
|
+
def should: () -> Minitest::ShouldJustWork::Should
|
|
49
|
+
def should_not: () -> Minitest::ShouldJustWork::Should
|
|
50
|
+
end
|
metadata
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: minitest-should_just_work
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Rico Sta. Cruz
|
|
8
8
|
- Priit Tark
|
|
9
|
-
autorequire:
|
|
10
9
|
bindir: exe
|
|
11
10
|
cert_chain: []
|
|
12
|
-
date:
|
|
11
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
13
12
|
dependencies:
|
|
14
13
|
- !ruby/object:Gem::Dependency
|
|
15
14
|
name: minitest
|
|
@@ -17,44 +16,22 @@ dependencies:
|
|
|
17
16
|
requirements:
|
|
18
17
|
- - ">="
|
|
19
18
|
- !ruby/object:Gem::Version
|
|
20
|
-
version: '0'
|
|
21
|
-
|
|
22
|
-
prerelease: false
|
|
23
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
24
|
-
requirements:
|
|
25
|
-
- - ">="
|
|
26
|
-
- !ruby/object:Gem::Version
|
|
27
|
-
version: '0'
|
|
28
|
-
- !ruby/object:Gem::Dependency
|
|
29
|
-
name: mocha
|
|
30
|
-
requirement: !ruby/object:Gem::Requirement
|
|
31
|
-
requirements:
|
|
32
|
-
- - ">="
|
|
19
|
+
version: '5.0'
|
|
20
|
+
- - "<"
|
|
33
21
|
- !ruby/object:Gem::Version
|
|
34
|
-
version: '
|
|
35
|
-
type: :
|
|
22
|
+
version: '7'
|
|
23
|
+
type: :runtime
|
|
36
24
|
prerelease: false
|
|
37
25
|
version_requirements: !ruby/object:Gem::Requirement
|
|
38
26
|
requirements:
|
|
39
27
|
- - ">="
|
|
40
28
|
- !ruby/object:Gem::Version
|
|
41
|
-
version: '0'
|
|
42
|
-
-
|
|
43
|
-
name: rake
|
|
44
|
-
requirement: !ruby/object:Gem::Requirement
|
|
45
|
-
requirements:
|
|
46
|
-
- - ">="
|
|
47
|
-
- !ruby/object:Gem::Version
|
|
48
|
-
version: '0'
|
|
49
|
-
type: :development
|
|
50
|
-
prerelease: false
|
|
51
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
52
|
-
requirements:
|
|
53
|
-
- - ">="
|
|
29
|
+
version: '5.0'
|
|
30
|
+
- - "<"
|
|
54
31
|
- !ruby/object:Gem::Version
|
|
55
|
-
version: '
|
|
32
|
+
version: '7'
|
|
56
33
|
description: Enables classic .should/.should_not syntax similar to classic RSpec on
|
|
57
|
-
your
|
|
34
|
+
your Minitest tests.
|
|
58
35
|
email:
|
|
59
36
|
- priit@domify.io
|
|
60
37
|
executables: []
|
|
@@ -70,14 +47,15 @@ files:
|
|
|
70
47
|
- lib/minitest/should_just_work.rb
|
|
71
48
|
- lib/minitest/should_just_work/version.rb
|
|
72
49
|
- sig/minitest/should_just_work.rbs
|
|
73
|
-
homepage:
|
|
50
|
+
homepage: https://github.com/priit/minitest-should_just_work
|
|
74
51
|
licenses:
|
|
75
52
|
- MIT
|
|
76
53
|
metadata:
|
|
77
|
-
homepage_uri:
|
|
78
|
-
source_code_uri:
|
|
79
|
-
|
|
80
|
-
|
|
54
|
+
homepage_uri: https://github.com/priit/minitest-should_just_work
|
|
55
|
+
source_code_uri: https://github.com/priit/minitest-should_just_work
|
|
56
|
+
bug_tracker_uri: https://github.com/priit/minitest-should_just_work/issues
|
|
57
|
+
changelog_uri: https://github.com/priit/minitest-should_just_work/blob/main/CHANGELOG.md
|
|
58
|
+
rubygems_mfa_required: 'true'
|
|
81
59
|
rdoc_options: []
|
|
82
60
|
require_paths:
|
|
83
61
|
- lib
|
|
@@ -85,15 +63,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
85
63
|
requirements:
|
|
86
64
|
- - ">="
|
|
87
65
|
- !ruby/object:Gem::Version
|
|
88
|
-
version:
|
|
66
|
+
version: 3.1.0
|
|
89
67
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
68
|
requirements:
|
|
91
69
|
- - ">="
|
|
92
70
|
- !ruby/object:Gem::Version
|
|
93
71
|
version: '0'
|
|
94
72
|
requirements: []
|
|
95
|
-
rubygems_version:
|
|
96
|
-
signing_key:
|
|
73
|
+
rubygems_version: 4.0.6
|
|
97
74
|
specification_version: 4
|
|
98
|
-
summary: RSpec-like .should/.should_not syntax for
|
|
75
|
+
summary: RSpec-like .should/.should_not syntax for Minitest.
|
|
99
76
|
test_files: []
|