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.
@@ -1,98 +1,96 @@
1
- # coding: utf-8
2
-
3
- require 'minitest_config'
1
+ require "minitest_config"
4
2
 
5
3
  describe Minitest::BonusAssertions do
6
4
  include Minitest::AssertionTests
7
5
 
8
- describe '.assert_true' do
9
- it 'returns true for true' do
6
+ describe ".assert_true" do
7
+ it "returns true for true" do
10
8
  assert_expected_assertions do
11
- assert_equal true, tc.assert_true(true), 'returns true for true'
9
+ assert_equal true, tc.assert_true(true), "returns true for true"
12
10
  end
13
11
  end
14
12
 
15
- it 'be triggered for false or nil' do
13
+ it "be triggered for false or nil" do
16
14
  assert_expected_assertions 2 do
17
- assert_assertion_triggered '<true> expected but was false.' do
15
+ assert_assertion_triggered "<true> expected but was false." do
18
16
  tc.assert_true false
19
17
  end
20
18
 
21
- assert_assertion_triggered '<true> expected but was nil.' do
19
+ assert_assertion_triggered "<true> expected but was nil." do
22
20
  tc.assert_true nil
23
21
  end
24
22
  end
25
23
  end
26
24
 
27
- it %q(be triggered for things that aren't true but evaluate to true) do
25
+ it "be triggered for things that aren't true but evaluate to true" do
28
26
  assert_expected_assertions do
29
- assert_assertion_triggered '<true> expected but was Object.' do
27
+ assert_assertion_triggered "<true> expected but was Object." do
30
28
  tc.assert_true Object
31
29
  end
32
30
  end
33
31
  end
34
32
  end
35
33
 
36
- describe '.assert_false' do
37
- it 'returns true for false' do
34
+ describe ".assert_false" do
35
+ it "returns true for false" do
38
36
  assert_expected_assertions do
39
- assert_equal true, tc.assert_false(false), 'returns true for false'
37
+ assert_equal true, tc.assert_false(false), "returns true for false"
40
38
  end
41
39
  end
42
40
 
43
- it 'be triggered for nil' do
41
+ it "be triggered for nil" do
44
42
  assert_expected_assertions do
45
- assert_assertion_triggered '<false> expected but was nil.' do
43
+ assert_assertion_triggered "<false> expected but was nil." do
46
44
  tc.assert_false nil
47
45
  end
48
46
  end
49
47
  end
50
48
 
51
- it 'be triggered for things that evalute to true' do
49
+ it "be triggered for things that evaluate to true" do
52
50
  assert_expected_assertions do
53
- assert_assertion_triggered '<false> expected but was Object.' do
51
+ assert_assertion_triggered "<false> expected but was Object." do
54
52
  tc.assert_false Object
55
53
  end
56
54
  end
57
55
  end
58
56
  end
59
57
 
60
- describe '.assert_between' do
61
- it 'returns true for basic integers' do
58
+ describe ".assert_between" do
59
+ it "returns true for basic integers" do
62
60
  assert_expected_assertions do
63
- assert_equal true, tc.assert_between(1, 10, 5), 'returns true for 1 to 10 and 5'
61
+ assert_equal true, tc.assert_between(1, 10, 5), "returns true for 1 to 10 and 5"
64
62
  end
65
63
  end
66
64
 
67
- it 'returns true for the range case' do
65
+ it "returns true for the range case" do
68
66
  assert_expected_assertions do
69
- assert_equal true, tc.assert_between((1..10), 5), 'returns true for 1..10 with 5'
67
+ assert_equal true, tc.assert_between(1..10, 5), "returns true for 1..10 with 5"
70
68
  end
71
69
  end
72
70
 
73
- it 'handle the case where the hi part is first' do
71
+ it "handle the case where the hi part is first" do
74
72
  assert_expected_assertions do
75
- assert_equal true, tc.assert_between(10, 1, 5), 'returns true for 10 to 1, with 5'
73
+ assert_equal true, tc.assert_between(10, 1, 5), "returns true for 10 to 1, with 5"
76
74
  end
77
75
  end
78
76
 
79
- it 'returns false for values outside the bounds' do
77
+ it "returns false for values outside the bounds" do
80
78
  assert_expected_assertions do
81
- assert_assertion_triggered 'Expected 100 to be between 1 and 10.' do
79
+ assert_assertion_triggered "Expected 100 to be between 1 and 10." do
82
80
  tc.assert_between(1, 10, 100)
83
81
  end
84
82
  end
85
83
  end
86
84
 
87
- it 'returns false for values strictly on the bounds' do
85
+ it "returns false for values strictly on the bounds" do
88
86
  assert_expected_assertions do
89
- assert_assertion_triggered 'Expected 1 to be between 1 and 10.' do
87
+ assert_assertion_triggered "Expected 1 to be between 1 and 10." do
90
88
  tc.assert_between(1, 10, 1)
91
89
  end
92
90
  end
93
91
  end
94
92
 
95
- it 'raise error for incompatible values' do
93
+ it "raise error for incompatible values" do
96
94
  assert_expected_assertions 0 do
97
95
  assert_raises ArgumentError do
98
96
  tc.assert_between(1, 10, Time.now)
@@ -100,254 +98,309 @@ describe Minitest::BonusAssertions do
100
98
  end
101
99
  end
102
100
 
103
- it 'works correctly with the new expectation format' do
101
+ it "works correctly with the new expectation format" do
104
102
  assert_expected_assertions do
105
103
  assert_equal true, spec._(5).must_be_between(1, 10)
106
104
  end
107
105
  end
108
106
  end
109
107
 
110
- describe '.assert_has_keys' do
111
- it 'returns true if the keys are present' do
108
+ describe ".assert_has_keys" do
109
+ it "returns true if the keys are present" do
112
110
  assert_expected_assertions do
113
- assert_equal true, tc.assert_has_keys({ 'a' => 1 }, 'a'),
114
- %q(returns true for key 'a' in { 'a' => 1 })
111
+ assert_equal true, tc.assert_has_keys({"a" => 1}, "a"),
112
+ "returns true for key 'a' in { 'a' => 1 }"
115
113
  end
116
114
  end
117
115
 
118
- it 'be triggered for a missing value' do
119
- hash = { 'a' => 1 }
120
- keys = %w(a b)
116
+ it "be triggered for a missing value" do
117
+ hash = {"a" => 1}
118
+ keys = %w[a b]
121
119
  assert_expected_assertions 2 do
122
- assert_assertion_triggered %Q(Expected #{mu_pp(hash)} to include all keys #{mu_pp(keys)}.) do
120
+ assert_assertion_triggered %(Expected #{mu_pp(hash)} to include all keys #{mu_pp(keys)}.) do
123
121
  tc.assert_has_keys(hash, keys)
124
122
  end
125
123
  end
126
124
  end
127
125
 
128
- it 'raise error for incompatible values' do
126
+ it "raise error for incompatible values" do
129
127
  assert_expected_assertions 0 do
130
128
  assert_raises NoMethodError do
131
- tc.assert_has_keys([], 'a')
129
+ tc.assert_has_keys([], "a")
132
130
  end
133
131
  end
134
132
  end
135
133
  end
136
134
 
137
- describe '.assert_missing_keys' do
138
- it 'returns true if the keys are missing' do
135
+ describe ".assert_missing_keys" do
136
+ it "returns true if the keys are missing" do
139
137
  assert_expected_assertions do
140
- assert_equal true, tc.assert_missing_keys({ 'a' => 1 }, 'b'),
141
- %q(returns true for key 'b' missing from { 'a' => 1 })
138
+ assert_equal true, tc.assert_missing_keys({"a" => 1}, "b"),
139
+ "returns true for key 'b' missing from { 'a' => 1 }"
142
140
  end
143
141
  end
144
142
 
145
- it 'be triggered for a present value' do
146
- hash = { 'a' => 1 }
147
- keys = %w(a b)
143
+ it "be triggered for a present value" do
144
+ hash = {"a" => 1}
145
+ keys = %w[a b]
148
146
  assert_expected_assertions do
149
- assert_assertion_triggered %Q(Expected #{mu_pp(hash)} not to include any of these keys #{mu_pp(keys)}.) do
147
+ assert_assertion_triggered %(Expected #{mu_pp(hash)} not to include any of these keys #{mu_pp(keys)}.) do
150
148
  tc.assert_missing_keys(hash, keys)
151
149
  end
152
150
  end
153
151
  end
154
152
 
155
- it 'raise error for incompatible values' do
153
+ it "raise error for incompatible values" do
156
154
  assert_expected_assertions 0 do
157
155
  assert_raises NoMethodError do
158
- tc.assert_missing_keys([], 'a')
156
+ tc.assert_missing_keys([], "a")
159
157
  end
160
158
  end
161
159
  end
162
160
  end
163
161
 
164
- describe '.assert_raises_with_message' do
165
- it 'returns the matched exception if the exception and message match' do
162
+ describe ".assert_raises_with_message" do
163
+ it "returns the matched exception if the exception and message match" do
166
164
  assert_expected_assertions 2 do
167
- res = tc.assert_raises_with_message(ArgumentError, %q(Don't have a cow, man!)) do
168
- raise ArgumentError, %q(Don't have a cow, man!)
165
+ res = tc.assert_raises_with_message(ArgumentError, "Don't have a cow, man!") do
166
+ raise ArgumentError, "Don't have a cow, man!"
169
167
  end
170
168
 
171
169
  assert_kind_of ArgumentError, res
172
170
  end
173
171
  end
174
172
 
175
- it 'is triggered with a different exception' do
173
+ it "is triggered with a different exception" do
176
174
  assert_expected_assertions do
177
- assert_assertion_triggered %Q(#{mu_pp([ArgumentError])} exception expected, not\nClass: <NoMethodError>\nMessage: <"NoMethodError">\n---Backtrace---) do
178
- tc.assert_raises_with_message(ArgumentError, 'Don’t have a cow, man!') do
175
+ assert_assertion_triggered %(#{mu_pp([ArgumentError])} exception expected, not\nClass: <NoMethodError>\nMessage: <"NoMethodError">\n---Backtrace---) do
176
+ tc.assert_raises_with_message(ArgumentError, "Don’t have a cow, man!") do
179
177
  raise NoMethodError
180
178
  end
181
179
  end
182
180
  end
183
181
  end
184
182
 
185
- it 'be triggered with a different message' do
183
+ it "be triggered with a different message" do
186
184
  assert_expected_assertions 2 do
187
- assert_assertion_triggered %Q(ArgumentError exception expected with message "Don’t have a cow, man!".\nExpected: "Don’t have a cow, man!"\n Actual: "Have a cow, man!") do
188
- tc.assert_raises_with_message(ArgumentError, 'Don’t have a cow, man!') do
189
- raise ArgumentError, 'Have a cow, man!'
185
+ expectation = expectation(
186
+ %(ArgumentError exception expected with message "Don’t have a cow, man!".),
187
+ %(Expected: "Don’t have a cow, man!"\n Actual: "Have a cow, man!")
188
+ )
189
+
190
+ assert_assertion_triggered expectation do
191
+ tc.assert_raises_with_message(ArgumentError, "Don’t have a cow, man!") do
192
+ raise ArgumentError, "Have a cow, man!"
190
193
  end
191
194
  end
192
195
  end
193
196
  end
194
197
  end
195
198
 
196
- describe '.assert_set_equal' do
197
- it 'returns true if the sets are equal' do
199
+ describe ".assert_set_equal" do
200
+ it "returns true if the sets are equal" do
198
201
  assert_expected_assertions do
199
- assert_equal true, tc.assert_set_equal(%w(a b c), %w(c b a)),
200
- %q(returns true for sets %w(a b c) and %w(c b a))
202
+ assert_equal true, tc.assert_set_equal(%w[a b c], %w[c b a]),
203
+ "returns true for sets %w(a b c) and %w(c b a)"
201
204
  end
202
205
  end
203
206
 
204
- it 'is triggered if they are not equal' do
207
+ it "is triggered if they are not equal" do
205
208
  assert_expected_assertions do
206
- assert_assertion_triggered %Q(Expected [\n \"c\",\n \"b\"\n] to be set equivalent to [\n \"a\",\n \"b\",\n \"c\"\n].\nExpected: #<Set: {\"a\", \"b\", \"c\"}>\n Actual: #<Set: {\"c\", \"b\"}>) do
207
- tc.assert_set_equal %w(a b c), %w(c b)
209
+ expectation = expectation(
210
+ %(Expected ["c", "b"] to be set equivalent to ["a", "b", "c"].),
211
+ %(Expected: #<Set: {"a", "b", "c"}>\n Actual: #<Set: {"c", "b"}>)
212
+ )
213
+
214
+ assert_assertion_triggered expectation do
215
+ tc.assert_set_equal %w[a b c], %w[c b]
208
216
  end
209
217
  end
210
218
  end
211
219
  end
212
220
 
213
- describe '.refute_set_equal' do
214
- it 'returns true if the sets are not equal' do
221
+ describe ".refute_set_equal" do
222
+ it "returns true if the sets are not equal" do
215
223
  assert_expected_assertions do
216
- assert_equal false, tc.refute_set_equal(%w(a b c), %w(c b)),
217
- %q(returns true for sets %w(a b c) and %w(c b))
224
+ assert_equal true, tc.refute_set_equal(%w[a b c], %w[c b]),
225
+ "returns true for sets %w(a b c) and %w(c b)"
218
226
  end
219
227
  end
220
228
 
221
- it 'is triggered if they are not equal' do
229
+ it "is triggered if they are not equal" do
230
+ expectation = expectation(
231
+ %(Expected ["c", "b", "a"] not to be set equivalent to ["a", "b", "c"].),
232
+ %(Expected #<Set: {"c", "b", "a"}> to not be equal to #<Set: {"a", "b", "c"}>.)
233
+ )
234
+
222
235
  assert_expected_assertions do
223
- assert_assertion_triggered %Q(Expected [\n \"c\",\n \"b\",\n \"a\"\n] not to be set equivalent to [\n \"a\",\n \"b\",\n \"c\"\n].\nExpected #<Set: {\"c\", \"b\", \"a\"}> to not be equal to #<Set: {\"a\", \"b\", \"c\"}>.) do
224
- tc.refute_set_equal %w(a b c), %w(c b a)
236
+ assert_assertion_triggered expectation do
237
+ tc.refute_set_equal %w[a b c], %w[c b a]
225
238
  end
226
239
  end
227
240
  end
228
241
  end
229
242
 
230
- describe '.assert_result_equal' do
231
- describe 'when expr is a string' do
232
- let(:expr) { 'expected' }
243
+ describe ".assert_result_equal" do
244
+ describe "when expr is a string" do
245
+ let(:expr) { "expected" }
233
246
 
234
- describe 'when expr yields nil' do
247
+ describe "when expr yields nil" do
235
248
  before do
236
249
  tc.define_singleton_method(:expected) { nil }
237
250
  spec.define_singleton_method(:expected) { nil }
238
251
  end
239
252
 
240
- it 'returns true if the actual is nil' do
253
+ it "returns true if the actual is nil" do
241
254
  assert_expected_assertions do
242
- assert_equal true, tc.assert_result_equal('expected', nil),
243
- %q(returns true for expr-string result nil and nil)
255
+ assert_equal true, tc.assert_result_equal("expected", nil),
256
+ "returns true for expr-string result nil and nil"
244
257
  end
245
258
  end
246
259
 
247
- it 'returns true if the actual is nil' do
260
+ it "returns true if the actual is nil" do
248
261
  assert_expected_assertions do
249
- assert_equal true, tc.assert_result_equal('expected', nil),
250
- %q(returns true for expr-string result nil and nil)
262
+ assert_equal true, tc.assert_result_equal("expected", nil),
263
+ "returns true for expr-string result nil and nil"
251
264
  end
252
265
  end
253
266
 
254
- it 'is triggered if the actual is not nil' do
267
+ it "is triggered if the actual is not nil" do
255
268
  assert_expected_assertions do
256
- assert_assertion_triggered %Q(nil expected (expr \"expected\") but was 3.\nExpected 3 to be nil.) do
257
- assert_equal true, tc.assert_result_equal('expected', 3),
258
- %q(returns true for expr-string result nil and nil)
269
+ expectation = expectation(
270
+ %(nil expected (expr "expected") but was 3.),
271
+ %(Expected 3 to be nil.)
272
+ )
273
+ assert_assertion_triggered expectation do
274
+ assert_equal true, tc.assert_result_equal("expected", 3),
275
+ "returns true for expr-string result nil and nil"
259
276
  end
260
277
  end
261
278
  end
262
279
  end
263
280
 
264
- describe 'when expr yields a non-nil value' do
281
+ describe "when expr yields a non-nil value" do
265
282
  before do
266
283
  tc.define_singleton_method(:expected) { 3 }
267
284
  end
268
285
 
269
- it 'returns true if the actual is equal' do
286
+ it "returns true if the actual is equal" do
270
287
  assert_expected_assertions do
271
- assert_equal true, tc.assert_result_equal('expected', 3),
272
- %q(returns true for expr-string result 3 and 3)
288
+ assert_equal true, tc.assert_result_equal("expected", 3),
289
+ "returns true for expr-string result 3 and 3"
273
290
  end
274
291
  end
275
292
 
276
- it 'is triggered if the actual is nil' do
293
+ it "is triggered if the actual is nil" do
277
294
  assert_expected_assertions do
278
- assert_assertion_triggered %Q(3 expected (expr \"expected\") but was nil.\nExpected: 3\n Actual: nil) do
279
- assert_equal true, tc.assert_result_equal('expected', nil),
280
- %q(returns true for expr-string result 3 and 3)
295
+ expectation = expectation(
296
+ %(3 expected (expr "expected") but was nil.),
297
+ %(Expected: 3\n Actual: nil)
298
+ )
299
+ assert_assertion_triggered expectation do
300
+ assert_equal true, tc.assert_result_equal("expected", nil),
301
+ "returns true for expr-string result 3 and 3"
281
302
  end
282
303
  end
283
304
  end
284
305
 
285
- it 'is triggered if the actual is not equal' do
306
+ it "is triggered if the actual is not equal" do
286
307
  assert_expected_assertions do
287
- assert_assertion_triggered %Q(3 expected (expr \"expected\") but was 5.\nExpected: 3\n Actual: 5) do
288
- assert_equal true, tc.assert_result_equal('expected', 5),
289
- %q(returns true for expr-string result 3 and 3)
308
+ expectation = expectation(
309
+ %(3 expected (expr "expected") but was 5.),
310
+ %(Expected: 3\n Actual: 5)
311
+ )
312
+
313
+ assert_assertion_triggered expectation do
314
+ assert_equal true, tc.assert_result_equal("expected", 5),
315
+ "returns true for expr-string result 3 and 3"
290
316
  end
291
317
  end
292
318
  end
293
319
  end
294
320
  end
295
321
 
296
- describe 'when expr is a proc' do
322
+ describe "when expr is a proc" do
297
323
  let(:expr) { -> { expected } }
298
324
 
299
- describe 'when expr yields nil' do
325
+ describe "when expr yields nil" do
300
326
  before do
301
327
  tc.define_singleton_method(:expected) { nil }
302
328
  end
303
329
 
304
- it 'returns true if the actual is nil' do
330
+ it "returns true if the actual is nil" do
305
331
  assert_expected_assertions do
306
- assert_equal true, tc.assert_result_equal('expected', nil),
307
- %q(returns true for expr-proc result nil and nil)
332
+ assert_equal true, tc.assert_result_equal("expected", nil),
333
+ "returns true for expr-proc result nil and nil"
308
334
  end
309
335
  end
310
336
 
311
- it 'is triggered if the actual is not nil' do
337
+ it "is triggered if the actual is not nil" do
312
338
  assert_expected_assertions do
313
- assert_assertion_triggered %Q(nil expected (expr \"expected\") but was 3.\nExpected 3 to be nil.) do
314
- assert_equal true, tc.assert_result_equal('expected', 3),
315
- %q(returns true for expr-proc result nil and nil)
339
+ expectation = expectation(
340
+ %(nil expected (expr "expected") but was 3.),
341
+ %(Expected 3 to be nil.)
342
+ )
343
+
344
+ assert_assertion_triggered expectation do
345
+ assert_equal true, tc.assert_result_equal("expected", 3),
346
+ "returns true for expr-proc result nil and nil"
316
347
  end
317
348
  end
318
349
  end
319
350
  end
320
351
 
321
- describe 'when expr yields a non-nil value' do
352
+ describe "when expr yields a non-nil value" do
322
353
  before do
323
354
  tc.define_singleton_method(:expected) { 3 }
324
355
  end
325
356
 
326
- it 'returns true if the actual is equal' do
357
+ it "returns true if the actual is equal" do
327
358
  assert_expected_assertions do
328
- assert_equal true, tc.assert_result_equal('expected', 3),
329
- %q(returns true for expr-proc result 3 and 3)
359
+ assert_equal true, tc.assert_result_equal("expected", 3),
360
+ "returns true for expr-proc result 3 and 3"
330
361
  end
331
362
  end
332
363
 
333
- it 'is triggered if the actual is nil' do
364
+ it "is triggered if the actual is nil" do
334
365
  assert_expected_assertions do
335
- assert_assertion_triggered %Q(3 expected (expr \"expected\") but was nil.\nExpected: 3\n Actual: nil) do
336
- assert_equal true, tc.assert_result_equal('expected', nil),
337
- %q(returns true for expr-proc result 3 and 3)
366
+ expectation = expectation(
367
+ %(3 expected (expr "expected") but was nil.),
368
+ %(Expected: 3\n Actual: nil)
369
+ )
370
+
371
+ assert_assertion_triggered expectation do
372
+ assert_equal true, tc.assert_result_equal("expected", nil),
373
+ "returns true for expr-proc result 3 and 3"
338
374
  end
339
375
  end
340
376
  end
341
377
 
342
- it 'is triggered if the actual is not equal' do
378
+ it "is triggered if the actual is not equal" do
343
379
  assert_expected_assertions do
344
- assert_assertion_triggered %Q(3 expected (expr \"expected\") but was 5.\nExpected: 3\n Actual: 5) do
345
- assert_equal true, tc.assert_result_equal('expected', 5),
346
- %q(returns true for expr-proc result 3 and 3)
380
+ expectation = expectation(
381
+ %(3 expected (expr "expected") but was 5.),
382
+ %(Expected: 3\n Actual: 5)
383
+ )
384
+
385
+ assert_assertion_triggered expectation do
386
+ assert_equal true, tc.assert_result_equal("expected", 5),
387
+ "returns true for expr-proc result 3 and 3"
347
388
  end
348
389
  end
349
390
  end
350
391
  end
351
392
  end
352
393
  end
394
+
395
+ def expectation(*args)
396
+ if RUBY_VERSION >= "4.0"
397
+ args.map! { |arg| arg.gsub(/#<Set: \{([^}]+)\}>/) { "Set[#{$1}]" } }
398
+ end
399
+
400
+ if Minitest::VERSION >= "6.0"
401
+ args.first
402
+ else
403
+ args.join("\n")
404
+ end
405
+ end
353
406
  end