minitest-should_just_work 0.1.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 +7 -0
- data/.rubocop.yml +13 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +12 -0
- data/LICENSE.txt +21 -0
- data/README.md +168 -0
- data/Rakefile +16 -0
- data/lib/minitest/should_just_work/version.rb +7 -0
- data/lib/minitest/should_just_work.rb +178 -0
- data/sig/minitest/should_just_work.rbs +6 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c51d03bb5868a93ef411c8bea2965fda5f5c5c2f46027a0b33eaefbe47875f06
|
4
|
+
data.tar.gz: d2d76601465d49af062147d9865690748bb28469e0c27741027226fd8f77c71b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6ff1d470e6cf19c68732168cc553a220bddfdb2f0710c3d3dcc7ac861dcee4ed0fc399bc76f3b7e8c76deb701c503b15c77fde2bb4008a358dddf89f7e664139
|
7
|
+
data.tar.gz: d3effe294c0a229ea5ddde236d1756ee7b0beb9cccdfdc794874908dfdb8606034b2a800186ec2162513a7d4b0fd373f78da270e22da86db588c4c5bded9028c
|
data/.rubocop.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 Priit Tark
|
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,168 @@
|
|
1
|
+
# Minitest::ShouldJustWork
|
2
|
+
|
3
|
+
Classic Rspec-like .should/.should_not matching for MiniTest.
|
4
|
+
|
5
|
+
This gem is heavely inspired from the minitest-should_syntax gem,
|
6
|
+
what has not updated a long time. Therefore we need this new gem to support .should syntax.
|
7
|
+
|
8
|
+
*minitest-should_just_work* lets you use a syntax similar to classic RSpec on your MiniTest
|
9
|
+
tests. It monkey-patches Object to translate RSpec-like sugar into plain
|
10
|
+
MiniTest `assert` matchers.
|
11
|
+
|
12
|
+
(*Ouch! Monkey patch?* Yes! But it only defines `Object#should` and
|
13
|
+
`#should_not`.)
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
Install the gem and add to the application's Gemfile by executing:
|
18
|
+
|
19
|
+
``` ruby
|
20
|
+
group :test do
|
21
|
+
gem 'minitest-spec-rails'
|
22
|
+
gem 'minitest-should_just_work'
|
23
|
+
end
|
24
|
+
```
|
25
|
+
|
26
|
+
$ bundle
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
``` ruby
|
31
|
+
require 'minitest/autorun'
|
32
|
+
require 'minitest/should_just_work'
|
33
|
+
|
34
|
+
describe "Books" do
|
35
|
+
it "should work" do
|
36
|
+
book = Book.new title: "Revolution"
|
37
|
+
|
38
|
+
book.title.should == "Revolution"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
```
|
43
|
+
|
44
|
+
Then you may use it as so:
|
45
|
+
|
46
|
+
```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
|
+
should.raise ZeroDivisionError do
|
68
|
+
2/0
|
69
|
+
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
|
+
|
106
|
+
``` ruby
|
107
|
+
it "should work" do
|
108
|
+
book = Book.new title: "Pride & Prejudice"
|
109
|
+
|
110
|
+
otherwise "The title should've been set on constructor"
|
111
|
+
book.title.should == "Pride & Prejudice"
|
112
|
+
end
|
113
|
+
```
|
114
|
+
|
115
|
+
Result:
|
116
|
+
|
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
|
+
```
|
124
|
+
|
125
|
+
Or you can use `.blaming` which does the same thing (with a more cumbersome
|
126
|
+
syntax):
|
127
|
+
|
128
|
+
``` ruby
|
129
|
+
it "should work" do
|
130
|
+
book = Book.new title: "Pride & Prejudice"
|
131
|
+
|
132
|
+
message = "The title should've been set on constructor"
|
133
|
+
book.title.should.blaming(message) == "Pride & Prejudice"
|
134
|
+
end
|
135
|
+
```
|
136
|
+
|
137
|
+
## Extending
|
138
|
+
|
139
|
+
Need to create your own matchers? Create your new matcher in a module, then use
|
140
|
+
`MiniTest::ShouldJustWork.add`.
|
141
|
+
|
142
|
+
```ruby
|
143
|
+
module DanceMatcher
|
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
|
158
|
+
|
159
|
+
MiniTest::ShouldJustWork.add DanceMatcher
|
160
|
+
|
161
|
+
# Then in your tests, use:
|
162
|
+
dancer.should.boogie_all_night!
|
163
|
+
```
|
164
|
+
|
165
|
+
## Acknowledgements & licensing
|
166
|
+
|
167
|
+
(c) 2022 Priit Tark, MIT license
|
168
|
+
(c) 2013 Rico Sta. Cruz, MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rake/testtask"
|
5
|
+
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
7
|
+
t.libs << "test"
|
8
|
+
t.libs << "lib"
|
9
|
+
t.test_files = FileList["test/**/test_*.rb"]
|
10
|
+
end
|
11
|
+
|
12
|
+
require "rubocop/rake_task"
|
13
|
+
|
14
|
+
RuboCop::RakeTask.new
|
15
|
+
|
16
|
+
task default: %i[test rubocop]
|
@@ -0,0 +1,178 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "should_just_work/version"
|
4
|
+
|
5
|
+
require 'minitest/unit'
|
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
|
+
#
|
35
|
+
|
36
|
+
module Minitest
|
37
|
+
module ShouldJustWork
|
38
|
+
class Error < StandardError; end
|
39
|
+
|
40
|
+
class Should
|
41
|
+
attr_reader :left, :msg
|
42
|
+
|
43
|
+
def self.init(test) # :nodoc:
|
44
|
+
@@test = test
|
45
|
+
end
|
46
|
+
|
47
|
+
# Includes a module to extend .should with more matchers.
|
48
|
+
def self.add(extension)
|
49
|
+
send :include, extension
|
50
|
+
end
|
51
|
+
|
52
|
+
def initialize(left)
|
53
|
+
@left = left
|
54
|
+
|
55
|
+
return unless test.msg
|
56
|
+
|
57
|
+
blaming test.msg
|
58
|
+
test.msg = nil
|
59
|
+
end
|
60
|
+
|
61
|
+
def be(right=nil) self.same(right) if right; self; end
|
62
|
+
def a() self; end
|
63
|
+
def an() self; end
|
64
|
+
|
65
|
+
def negative?() @neg; end
|
66
|
+
def positive?() !@neg; end
|
67
|
+
def test() @@test; end
|
68
|
+
def not() @neg = true; self; end
|
69
|
+
|
70
|
+
def true() true_or_false(true); end
|
71
|
+
def false() true_or_false(false); end
|
72
|
+
|
73
|
+
def true_or_false(bool)
|
74
|
+
val = !! left
|
75
|
+
val = !val if bool == false
|
76
|
+
method = (positive? ? :"assert" : :"refute")
|
77
|
+
test.send method, val, [msg, 'Expected to be falsy'].compact.join("\n")
|
78
|
+
end
|
79
|
+
|
80
|
+
def blaming(msg); @msg = msg; self; end
|
81
|
+
def messaging(msg); @msg = msg; self; end
|
82
|
+
|
83
|
+
def ==(right) assert_or_refute :equal, right, left; end
|
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
|
98
|
+
|
99
|
+
def match(right) self =~ right; end
|
100
|
+
def equal(right) self == right; end
|
101
|
+
|
102
|
+
def close(right, d=0.001) assert_or_refute :in_delta, right, left, d; end
|
103
|
+
def in_epsilon(right, d=0.001) assert_or_refute :in_epsilon, right, left, d; end
|
104
|
+
|
105
|
+
def assert_or_refute(what, *args, &blk)
|
106
|
+
args << msg
|
107
|
+
test.send((positive? ? :"assert_#{what}" : :"refute_#{what}"), *args, &blk)
|
108
|
+
end
|
109
|
+
|
110
|
+
def refute_or_assert(what, *args)
|
111
|
+
args << msg
|
112
|
+
test.send((negative? ? :"assert_#{what}" : :"refute_#{what}"), *args)
|
113
|
+
end
|
114
|
+
|
115
|
+
def throw(what=nil, &blk)
|
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
|
122
|
+
|
123
|
+
def raise(ex=StandardError, &blk)
|
124
|
+
if positive?
|
125
|
+
test.send :assert_raises, ex, msg, &blk
|
126
|
+
else
|
127
|
+
warn "ShouldJustWork: should.not.raise is not supported"
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def method_missing(meth, *args, &blk)
|
132
|
+
result = left.send(:"#{meth}?", *args, &blk)
|
133
|
+
method = positive? ? :assert : :refute
|
134
|
+
|
135
|
+
args = [result]
|
136
|
+
args << msg if msg
|
137
|
+
|
138
|
+
test.send method, *args
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
class Object
|
145
|
+
def should
|
146
|
+
MiniTest::ShouldJustWork::Should.new(self)
|
147
|
+
end
|
148
|
+
|
149
|
+
def should_not
|
150
|
+
should.not
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
# Patch MiniTest::Test:before_setup to invoke ShouldJustWork,
|
155
|
+
# and inject the #msg and #otherwise helper.
|
156
|
+
module MiniTest
|
157
|
+
class Test
|
158
|
+
alias mts_before_setup before_setup
|
159
|
+
|
160
|
+
def before_setup(*a, &block)
|
161
|
+
MiniTest::ShouldJustWork::Should.init self
|
162
|
+
mts_before_setup(*a, &block)
|
163
|
+
end
|
164
|
+
|
165
|
+
def msg(string=nil)
|
166
|
+
self.msg = string if string
|
167
|
+
@msg
|
168
|
+
end
|
169
|
+
|
170
|
+
def msg=(string)
|
171
|
+
@msg = string
|
172
|
+
end
|
173
|
+
|
174
|
+
def otherwise(message)
|
175
|
+
msg message
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: minitest-should_just_work
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rico Sta. Cruz
|
8
|
+
- Priit Tark
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2022-12-21 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: minitest
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
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
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
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
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
description: Enables classic .should/.should_not syntax similar to classic RSpec on
|
57
|
+
your MiniTest tests.
|
58
|
+
email:
|
59
|
+
- priit@domify.io
|
60
|
+
executables: []
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- ".rubocop.yml"
|
65
|
+
- CHANGELOG.md
|
66
|
+
- Gemfile
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- lib/minitest/should_just_work.rb
|
71
|
+
- lib/minitest/should_just_work/version.rb
|
72
|
+
- sig/minitest/should_just_work.rbs
|
73
|
+
homepage: http://github.com/priit/minitest-should_just_work
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata:
|
77
|
+
homepage_uri: http://github.com/priit/minitest-should_just_work
|
78
|
+
source_code_uri: http://github.com/priit/minitest-should_just_work
|
79
|
+
changelog_uri: http://github.com/priit/minitest-should_just_work/CHANGELOG.md
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 2.6.0
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubygems_version: 3.3.26
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: RSpec-like .should/.should_not syntax for MiniTest.
|
99
|
+
test_files: []
|