minitest-bonus-assertions 3.0 → 3.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.
@@ -0,0 +1,233 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "bonus_assertions/version"
4
+
5
+ module Minitest
6
+ module Assertions
7
+ ##
8
+ # Fails unless +obj+ is literally +false+.
9
+
10
+ def assert_false obj, msg = nil
11
+ msg = message(msg) { "<false> expected but was #{mu_pp(obj)}" }
12
+ assert obj == false, msg
13
+ end
14
+
15
+ ##
16
+ # Fails unless +obj+ is literally +true+.
17
+
18
+ def assert_true obj, msg = nil
19
+ msg = message(msg) { "<true> expected but was #{mu_pp(obj)}" }
20
+ assert obj == true, msg
21
+ end
22
+
23
+ ##
24
+ # Fails unless +exp+ is between +lo+ and +hi+, or is in +range+. This test
25
+ # is exclusive of the boundaries. That is:
26
+ #
27
+ # assert_between 1, 10, 1
28
+ #
29
+ # will return false, but:
30
+ #
31
+ # assert_between 0.99, 10.1, 1
32
+ #
33
+ # will return true.
34
+ #
35
+ # :call-seq:
36
+ # assert_between lo, hi, exp, msg = nil
37
+ # assert_between range, exp, msg = nil
38
+
39
+ def assert_between(*args)
40
+ lo, hi, exp, msg = if args.first.is_a?(Range)
41
+ [args.first.begin, args.first.end, args[1], args[2]]
42
+ else
43
+ args[0..3]
44
+ end
45
+ lo, hi = hi, lo if lo > hi
46
+ msg = message(msg) { "Expected #{mu_pp(exp)} to be between #{mu_pp(lo)} and #{mu_pp(hi)}" }
47
+ assert (lo < exp && exp < hi), msg
48
+ end
49
+
50
+ ##
51
+ # Fails unless +obj+ has all of the +keys+ listed.
52
+
53
+ def assert_has_keys obj, keys, msg = nil
54
+ keys = [keys] unless keys.is_a?(Array)
55
+ msg = message(msg) { "Expected #{mu_pp(obj)} to include all keys #{mu_pp(keys)}" }
56
+ keys.all? { |key| assert obj.key?(key), msg }
57
+ end
58
+ alias_method :refute_missing_keys, :assert_has_keys
59
+
60
+ ##
61
+ # Fails if +obj+ has any of the keys listed.
62
+
63
+ def assert_missing_keys obj, keys, msg = nil
64
+ keys = [keys] unless keys.is_a?(Array)
65
+ msg = message(msg) {
66
+ "Expected #{mu_pp(obj)} not to include any of these keys #{mu_pp(keys)}"
67
+ }
68
+
69
+ keys.each do |key|
70
+ refute obj.key?(key), msg
71
+ end
72
+
73
+ true
74
+ end
75
+ alias_method :refute_has_keys, :assert_missing_keys
76
+
77
+ ##
78
+ # Fails unless the block raises +exp+ with the message +exp_msg+. Returns
79
+ # the exception matched so you can check other attributes.
80
+
81
+ def assert_raises_with_message exp, exp_msg, msg = nil
82
+ msg = message(msg) { "#{mu_pp(exp)} exception expected with message #{mu_pp(exp_msg)}" }
83
+
84
+ exception = assert_raises exp do
85
+ yield
86
+ end
87
+
88
+ assert_equal exp_msg, exception.message, msg
89
+ exception
90
+ end
91
+
92
+ ##
93
+ # Fails unless the set from +actual+ matches the set from +exp+.
94
+
95
+ def assert_set_equal expected, actual, msg = nil
96
+ msg = message(msg) {
97
+ "Expected #{mu_pp(actual)} to be set equivalent to #{mu_pp(expected)}"
98
+ }
99
+ assert_equal Set.new(expected), Set.new(actual), msg
100
+ end
101
+
102
+ ##
103
+ # Fails unless the set from +actual+ differs from the set from +exp+.
104
+
105
+ def refute_set_equal expected, actual, msg = nil
106
+ msg = message(msg) {
107
+ "Expected #{mu_pp(actual)} not to be set equivalent to #{mu_pp(expected)}"
108
+ }
109
+ refute_equal Set.new(expected), Set.new(actual), msg
110
+ end
111
+
112
+ ##
113
+ # Fails unless +actual+ is the same value as the result of evaluating
114
+ # +expr+ in the context of the test case through instance_eval (when +expr+
115
+ # is a String) or instance_exec (when +expr+ is a callable).
116
+ #
117
+ # If +expr+ results in +nil+, this test delegates to #assert_nil, otherwise
118
+ # it delegates to #assert_equal.
119
+ #
120
+ # This assertion exists because Minitest 6 is changing #assert_equal so
121
+ # that it fails when comparing against +nil+.
122
+ #
123
+ # assert_result_equal -> { model.department }, response[:department]
124
+ # assert_result_equal 'model.department', response[:department]
125
+ def assert_result_equal expr, actual, msg = nil
126
+ result = if expr.respond_to?(:call)
127
+ instance_exec(&expr)
128
+ else
129
+ instance_eval(expr)
130
+ end
131
+
132
+ if result.nil?
133
+ msg = message(msg) {
134
+ "nil expected (expr #{mu_pp(expr)}) but was #{mu_pp(actual)}"
135
+ }
136
+ assert_nil actual, msg
137
+ else
138
+ msg = message(msg) {
139
+ "#{mu_pp(result)} expected (expr #{mu_pp(expr)}) but was #{mu_pp(actual)}"
140
+ }
141
+ assert_equal result, actual, msg
142
+ end
143
+ end
144
+ end
145
+
146
+ module Expectations
147
+ ##
148
+ # See Minitest::Assertions#assert_false
149
+ #
150
+ # false.must_be_false
151
+ #
152
+ # :method: must_be_false
153
+
154
+ infect_an_assertion :assert_false, :must_be_false, :unary
155
+
156
+ ##
157
+ # See Minitest::Assertions#assert_true
158
+ #
159
+ # true.must_be_true
160
+ #
161
+ # :method: must_be_true
162
+
163
+ infect_an_assertion :assert_true, :must_be_true, :unary
164
+
165
+ ##
166
+ # See Minitest::Assertions#assert_between
167
+ #
168
+ # 2.must_be_between 1, 3
169
+ # 2.must_be_between 1..3
170
+
171
+ def must_be_between *args
172
+ hi, lo, msg = if args.first.is_a?(Range)
173
+ [args.first.begin, args.first.end, args[1]]
174
+ else
175
+ args[0..2]
176
+ end
177
+ ctx.assert_between lo, hi, target, msg
178
+ end
179
+
180
+ ##
181
+ # See Minitest::Assertions#assert_has_keys
182
+ #
183
+ # hash.must_have_keys %w(a b c)
184
+ #
185
+ # :method: must_have_keys
186
+
187
+ infect_an_assertion :assert_has_keys, :must_have_keys, :unary
188
+
189
+ ##
190
+ # See Minitest::Assertions#assert_missing_keys
191
+ #
192
+ # hash.must_not_have_keys %w(a b c)
193
+ #
194
+ # :method: must_not_have_keys
195
+
196
+ infect_an_assertion :assert_missing_keys, :must_not_have_keys, :unary
197
+
198
+ ##
199
+ # See Minitest::Assertions#assert_raises_with_message
200
+ #
201
+ # proc { ... }.must_raise_with_message exception, message
202
+ #
203
+ # :method: must_raise_with_message
204
+
205
+ infect_an_assertion :assert_raises_with_message, :must_raise_with_message
206
+
207
+ ##
208
+ # See Minitest::Assertions#assert_set_equal
209
+ #
210
+ # %w(a b c).must_equal_set %(c b a)
211
+ #
212
+ # :method: must_equal_set
213
+
214
+ infect_an_assertion :assert_set_equal, :must_equal_set, :unary
215
+
216
+ ##
217
+ # See Minitest::Assertions#refute_set_equal
218
+ #
219
+ # %w(a b c).must_equal_set %(c b a)
220
+ #
221
+ # :method: must_equal_set
222
+
223
+ infect_an_assertion :refute_set_equal, :must_not_equal_set, :unary
224
+
225
+ ##
226
+ # See Minitest::Assertions#assert_result_equal
227
+ #
228
+ # response[:department].must_equal_result 'model.department'
229
+ # response[:department].must_equal_result -> { model.department }
230
+
231
+ infect_an_assertion :assert_result_equal, :must_equal_result, :unary
232
+ end
233
+ end
@@ -1,230 +1,3 @@
1
- module Minitest
2
- module BonusAssertions # :nodoc:
3
- VERSION = '3.0' # :nodoc:
4
- end
1
+ # frozen_string_literal: true
5
2
 
6
- module Assertions
7
- ##
8
- # Fails unless +obj+ is literally +false+.
9
-
10
- def assert_false obj, msg = nil
11
- msg = message(msg) { "<false> expected but was #{mu_pp(obj)}" }
12
- assert obj == false, msg
13
- end
14
-
15
- ##
16
- # Fails unless +obj+ is literally +true+.
17
-
18
- def assert_true obj, msg = nil
19
- msg = message(msg) { "<true> expected but was #{mu_pp(obj)}" }
20
- assert obj == true, msg
21
- end
22
-
23
- ##
24
- # Fails unless +exp+ is between +lo+ and +hi+, or is in +range+. This test
25
- # is exclusive of the boundaries. That is:
26
- #
27
- # assert_between 1, 10, 1
28
- #
29
- # will return false, but:
30
- #
31
- # assert_between 0.99, 10.1, 1
32
- #
33
- # will return true.
34
- #
35
- # :call-seq:
36
- # assert_between lo, hi, exp, msg = nil
37
- # assert_between range, exp, msg = nil
38
-
39
- def assert_between(*args)
40
- lo, hi, exp, msg = if args.first.kind_of?(Range)
41
- [args.first.begin, args.first.end, args[1], args[2]]
42
- else
43
- args[0..3]
44
- end
45
- lo, hi = hi, lo if lo > hi
46
- msg = message(msg) { "Expected #{mu_pp(exp)} to be between #{mu_pp(lo)} and #{mu_pp(hi)}" }
47
- assert (lo < exp && exp < hi), msg
48
- end
49
-
50
- ##
51
- # Fails unless +obj+ has all of the +keys+ listed.
52
-
53
- def assert_has_keys obj, keys, msg = nil
54
- keys = [ keys ] unless keys.kind_of?(Array)
55
- msg = message(msg) { "Expected #{mu_pp(obj)} to include all keys #{mu_pp(keys)}" }
56
- keys.all? { |key| assert obj.key?(key), msg }
57
- end
58
- alias_method :refute_missing_keys, :assert_has_keys
59
-
60
- ##
61
- # Fails if +obj+ has any of the keys listed.
62
-
63
- def assert_missing_keys obj, keys, msg = nil
64
- keys = [ keys ] unless keys.kind_of?(Array)
65
- msg = message(msg) {
66
- "Expected #{mu_pp(obj)} not to include any of these keys #{mu_pp(keys)}"
67
- }
68
- keys.none? { |key| refute obj.key?(key), msg }
69
- end
70
- alias_method :refute_has_keys, :assert_missing_keys
71
-
72
- ##
73
- # Fails unless the block raises +exp+ with the message +exp_msg+. Returns
74
- # the exception matched so you can check other attributes.
75
-
76
- def assert_raises_with_message exp, exp_msg, msg = nil
77
- msg = message(msg) { "#{mu_pp(exp)} exception expected with message #{mu_pp(exp_msg)}" }
78
-
79
- exception = assert_raises exp do
80
- yield
81
- end
82
-
83
- assert_equal exp_msg, exception.message, msg
84
- exception
85
- end
86
-
87
- ##
88
- # Fails unless the set from +actual+ matches the set from +exp+.
89
-
90
- def assert_set_equal expected, actual, msg = nil
91
- require 'set'
92
- msg = message(msg) {
93
- "Expected #{mu_pp(actual)} to be set equivalent to #{mu_pp(expected)}"
94
- }
95
- assert_equal Set.new(expected), Set.new(actual), msg
96
- end
97
-
98
- ##
99
- # Fails unless the set from +actual+ differs from the set from +exp+.
100
-
101
- def refute_set_equal expected, actual, msg = nil
102
- require 'set'
103
- msg = message(msg) {
104
- "Expected #{mu_pp(actual)} not to be set equivalent to #{mu_pp(expected)}"
105
- }
106
- refute_equal Set.new(expected), Set.new(actual), msg
107
- end
108
-
109
- ##
110
- # Fails unless +actual+ is the same value as the result of evaluating
111
- # +expr+ in the context of the test case through instance_eval (when +expr+
112
- # is a String) or instance_exec (when +expr+ is a callable).
113
- #
114
- # If +expr+ results in +nil+, this test delegates to #assert_nil, otherwise
115
- # it delegates to #assert_equal.
116
- #
117
- # This assertion exists because Minitest 6 is changing #assert_equal so
118
- # that it fails when comparing against +nil+.
119
- #
120
- # assert_result_equal -> { model.department }, response[:department]
121
- # assert_result_equal 'model.department', response[:department]
122
- def assert_result_equal expr, actual, msg = nil
123
- result = if expr.respond_to?(:call)
124
- instance_exec(&expr)
125
- else
126
- instance_eval(expr)
127
- end
128
-
129
- if result.nil?
130
- msg = message(msg) {
131
- "nil expected (expr #{mu_pp(expr)}) but was #{mu_pp(actual)}"
132
- }
133
- assert_nil actual, msg
134
- else
135
- msg = message(msg) {
136
- "#{mu_pp(result)} expected (expr #{mu_pp(expr)}) but was #{mu_pp(actual)}"
137
- }
138
- assert_equal result, actual, msg
139
- end
140
- end
141
- end
142
-
143
- module Expectations
144
- ##
145
- # See Minitest::Assertions#assert_false
146
- #
147
- # false.must_be_false
148
- #
149
- # :method: must_be_false
150
-
151
- infect_an_assertion :assert_false, :must_be_false, :unary
152
-
153
- ##
154
- # See Minitest::Assertions#assert_true
155
- #
156
- # true.must_be_true
157
- #
158
- # :method: must_be_true
159
-
160
- infect_an_assertion :assert_true, :must_be_true, :unary
161
-
162
- ##
163
- # See Minitest::Assertions#assert_between
164
- #
165
- # 2.must_be_between 1, 3
166
- # 2.must_be_between 1..3
167
-
168
- def must_be_between *args
169
- hi, lo, msg = if args.first.kind_of?(Range)
170
- [args.first.begin, args.first.end, args[1]]
171
- else
172
- args[0..2]
173
- end
174
- ctx.assert_between lo, hi, target, msg
175
- end
176
-
177
- ##
178
- # See Minitest::Assertions#assert_has_keys
179
- #
180
- # hash.must_have_keys %w(a b c)
181
- #
182
- # :method: must_have_keys
183
-
184
- infect_an_assertion :assert_has_keys, :must_have_keys, :unary
185
-
186
- ##
187
- # See Minitest::Assertions#assert_missing_keys
188
- #
189
- # hash.must_not_have_keys %w(a b c)
190
- #
191
- # :method: must_not_have_keys
192
-
193
- infect_an_assertion :assert_missing_keys, :must_not_have_keys, :unary
194
-
195
- ##
196
- # See Minitest::Assertions#assert_raises_with_message
197
- #
198
- # proc { ... }.must_raise_with_message exception, message
199
- #
200
- # :method: must_raise_with_message
201
-
202
- infect_an_assertion :assert_raises_with_message, :must_raise_with_message
203
-
204
- ##
205
- # See Minitest::Assertions#assert_set_equal
206
- #
207
- # %w(a b c).must_equal_set %(c b a)
208
- #
209
- # :method: must_equal_set
210
-
211
- infect_an_assertion :assert_set_equal, :must_equal_set, :unary
212
-
213
- ##
214
- # See Minitest::Assertions#refute_set_equal
215
- #
216
- # %w(a b c).must_equal_set %(c b a)
217
- #
218
- # :method: must_equal_set
219
-
220
- infect_an_assertion :refute_set_equal, :must_not_equal_set, :unary
221
-
222
- ##
223
- # See Minitest::Assertions#assert_result_equal
224
- #
225
- # response[:department].must_equal_result 'model.department'
226
- # response[:department].must_equal_result -> { model.department }
227
-
228
- infect_an_assertion :assert_result_equal, :must_equal_result, :unary
229
- end
230
- end
3
+ require "minitest/bonus_assertions"
data/licences/dco.txt ADDED
@@ -0,0 +1,34 @@
1
+ Developer Certificate of Origin
2
+ Version 1.1
3
+
4
+ Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
5
+
6
+ Everyone is permitted to copy and distribute verbatim copies of this
7
+ license document, but changing it is not allowed.
8
+
9
+
10
+ Developer's Certificate of Origin 1.1
11
+
12
+ By making a contribution to this project, I certify that:
13
+
14
+ (a) The contribution was created in whole or in part by me and I
15
+ have the right to submit it under the open source license
16
+ indicated in the file; or
17
+
18
+ (b) The contribution is based upon previous work that, to the best
19
+ of my knowledge, is covered under an appropriate open source
20
+ license and I have the right under that license to submit that
21
+ work with modifications, whether created in whole or in part
22
+ by me, under the same open source license (unless I am
23
+ permitted to submit under a different license), as indicated
24
+ in the file; or
25
+
26
+ (c) The contribution was provided directly to me by some other
27
+ person who certified (a), (b) or (c) and I have not modified
28
+ it.
29
+
30
+ (d) I understand and agree that this project and the contribution
31
+ are public and that a record of the contribution (including all
32
+ personal information I submit with it, including my sign-off) is
33
+ maintained indefinitely and may be redistributed consistent with
34
+ this project or the open source license(s) involved.
@@ -1,9 +1,5 @@
1
- gem 'minitest'
2
- require 'minitest/autorun'
3
- require 'minitest/pretty_diff'
4
- require 'minitest/focus'
5
- require 'minitest/moar'
6
- require 'minitest/bisect'
1
+ gem "minitest"
2
+ require "minitest/focus"
7
3
 
8
- require 'minitest-bonus-assertions'
9
- require 'minitest/assertion_tests'
4
+ require "minitest/bonus_assertions"
5
+ require "minitest/assertion_tests"