assert 2.16.5 → 2.18.3

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 (82) hide show
  1. checksums.yaml +7 -7
  2. data/Gemfile +3 -1
  3. data/README.md +79 -54
  4. data/assert.gemspec +6 -5
  5. data/bin/assert +4 -4
  6. data/lib/assert.rb +8 -18
  7. data/lib/assert/actual_value.rb +127 -0
  8. data/lib/assert/assert_runner.rb +7 -10
  9. data/lib/assert/assertions.rb +15 -28
  10. data/lib/assert/cli.rb +41 -57
  11. data/lib/assert/config.rb +8 -12
  12. data/lib/assert/config_helpers.rb +6 -10
  13. data/lib/assert/context.rb +30 -24
  14. data/lib/assert/context/let_dsl.rb +13 -0
  15. data/lib/assert/context/method_missing.rb +19 -0
  16. data/lib/assert/context/setup_dsl.rb +0 -4
  17. data/lib/assert/context/subject_dsl.rb +0 -4
  18. data/lib/assert/context/suite_dsl.rb +0 -4
  19. data/lib/assert/context/test_dsl.rb +5 -9
  20. data/lib/assert/context_info.rb +2 -6
  21. data/lib/assert/default_runner.rb +1 -5
  22. data/lib/assert/default_suite.rb +1 -6
  23. data/lib/assert/default_view.rb +8 -12
  24. data/lib/assert/factory.rb +1 -4
  25. data/lib/assert/file_line.rb +0 -4
  26. data/lib/assert/macro.rb +1 -4
  27. data/lib/assert/macros/methods.rb +5 -11
  28. data/lib/assert/result.rb +19 -34
  29. data/lib/assert/runner.rb +12 -11
  30. data/lib/assert/stub.rb +16 -2
  31. data/lib/assert/suite.rb +3 -7
  32. data/lib/assert/test.rb +13 -18
  33. data/lib/assert/utils.rb +8 -12
  34. data/lib/assert/version.rb +1 -1
  35. data/lib/assert/view.rb +18 -21
  36. data/lib/assert/view_helpers.rb +6 -17
  37. data/log/{.gitkeep → .keep} +0 -0
  38. data/test/helper.rb +26 -41
  39. data/test/support/factory.rb +20 -6
  40. data/test/support/inherited_stuff.rb +0 -2
  41. data/test/system/stub_tests.rb +350 -354
  42. data/test/system/test_tests.rb +119 -133
  43. data/test/unit/actual_value_tests.rb +335 -0
  44. data/test/unit/assert_tests.rb +125 -52
  45. data/test/unit/assertions/assert_block_tests.rb +34 -37
  46. data/test/unit/assertions/assert_empty_tests.rb +38 -38
  47. data/test/unit/assertions/assert_equal_tests.rb +84 -86
  48. data/test/unit/assertions/assert_file_exists_tests.rb +37 -39
  49. data/test/unit/assertions/assert_includes_tests.rb +45 -46
  50. data/test/unit/assertions/assert_instance_of_tests.rb +39 -40
  51. data/test/unit/assertions/assert_kind_of_tests.rb +39 -40
  52. data/test/unit/assertions/assert_match_tests.rb +39 -40
  53. data/test/unit/assertions/assert_nil_tests.rb +35 -38
  54. data/test/unit/assertions/assert_raises_tests.rb +58 -62
  55. data/test/unit/assertions/assert_respond_to_tests.rb +41 -42
  56. data/test/unit/assertions/assert_same_tests.rb +94 -90
  57. data/test/unit/assertions/assert_true_false_tests.rb +67 -69
  58. data/test/unit/assertions_tests.rb +17 -19
  59. data/test/unit/config_helpers_tests.rb +41 -43
  60. data/test/unit/config_tests.rb +42 -46
  61. data/test/unit/context/let_dsl_tests.rb +10 -0
  62. data/test/unit/context/setup_dsl_tests.rb +72 -91
  63. data/test/unit/context/subject_dsl_tests.rb +18 -51
  64. data/test/unit/context/suite_dsl_tests.rb +19 -23
  65. data/test/unit/context/test_dsl_tests.rb +52 -59
  66. data/test/unit/context_info_tests.rb +19 -21
  67. data/test/unit/context_tests.rb +175 -178
  68. data/test/unit/default_runner_tests.rb +4 -10
  69. data/test/unit/default_suite_tests.rb +54 -59
  70. data/test/unit/factory_tests.rb +6 -9
  71. data/test/unit/file_line_tests.rb +34 -40
  72. data/test/unit/macro_tests.rb +11 -20
  73. data/test/unit/result_tests.rb +156 -182
  74. data/test/unit/runner_tests.rb +72 -79
  75. data/test/unit/suite_tests.rb +62 -63
  76. data/test/unit/test_tests.rb +143 -147
  77. data/test/unit/utils_tests.rb +49 -62
  78. data/test/unit/view_helpers_tests.rb +67 -70
  79. data/test/unit/view_tests.rb +26 -32
  80. metadata +54 -47
  81. data/.assert.rb +0 -3
  82. data/.gitignore +0 -19
@@ -1,4 +1,4 @@
1
- require 'assert'
1
+ require "assert"
2
2
 
3
3
  class Assert::Test
4
4
 
@@ -6,356 +6,342 @@ class Assert::Test
6
6
  include Assert::Test::TestHelpers
7
7
 
8
8
  desc "Assert::Test"
9
- subject{ @test }
9
+ subject { test1 }
10
10
 
11
+ setup do
12
+ test1.run(&test_run_callback)
13
+ end
11
14
  end
12
15
 
13
16
  class NoResultsTests < SystemTests
14
17
  desc "when producing no results"
15
- setup do
16
- @test = Factory.test
17
- @test.run(&test_run_callback)
18
- end
18
+
19
+ let(:test1) { Factory.test }
19
20
 
20
21
  should "generate 0 results" do
21
- assert_equal 0, test_run_result_count
22
+ assert_that(test_run_result_count).equals(0)
22
23
  end
23
-
24
24
  end
25
25
 
26
26
  class PassTests < SystemTests
27
27
  desc "when passing a single assertion"
28
- setup do
29
- @test = Factory.test{ assert(1 == 1) }
30
- @test.run(&test_run_callback)
31
- end
28
+
29
+ let(:test1) { Factory.test{ assert(1 == 1) } }
32
30
 
33
31
  should "generate 1 result" do
34
- assert_equal 1, test_run_result_count
32
+ assert_that(test_run_result_count).equals(1)
35
33
  end
36
34
 
37
35
  should "generate 1 pass result" do
38
- assert_equal 1, test_run_result_count(:pass)
36
+ assert_that(test_run_result_count(:pass)).equals(1)
39
37
  end
40
-
41
38
  end
42
39
 
43
40
  class FailTests < SystemTests
44
41
  desc "when failing a single assertion"
45
- setup do
46
- @test = Factory.test{ assert(1 == 0) }
47
- @test.run(&test_run_callback)
48
- end
42
+
43
+ let(:test1) { Factory.test{ assert(1 == 0) } }
49
44
 
50
45
  should "generate 1 result" do
51
- assert_equal 1, test_run_result_count
46
+ assert_that(test_run_result_count).equals(1)
52
47
  end
53
48
 
54
49
  should "generate 1 fail result" do
55
- assert_equal 1, test_run_result_count(:fail)
50
+ assert_that(test_run_result_count(:fail)).equals(1)
56
51
  end
57
-
58
52
  end
59
53
 
60
54
  class SkipTests < SystemTests
61
55
  desc "when skipping once"
62
- setup do
63
- @test = Factory.test{ skip }
64
- @test.run(&test_run_callback)
65
- end
56
+
57
+ let(:test1) { Factory.test{ skip } }
66
58
 
67
59
  should "generate 1 result" do
68
- assert_equal 1, test_run_result_count
60
+ assert_that(test_run_result_count).equals(1)
69
61
  end
70
62
 
71
63
  should "generate 1 skip result" do
72
- assert_equal 1, test_run_result_count(:skip)
64
+ assert_that(test_run_result_count(:skip)).equals(1)
73
65
  end
74
-
75
66
  end
76
67
 
77
68
  class ErrorTests < SystemTests
78
69
  desc "when erroring once"
79
- setup do
80
- @test = Factory.test{ raise("WHAT") }
81
- @test.run(&test_run_callback)
82
- end
70
+
71
+ let(:test1) { Factory.test{ raise("WHAT") } }
83
72
 
84
73
  should "generate 1 result" do
85
- assert_equal 1, test_run_result_count
74
+ assert_that(test_run_result_count).equals(1)
86
75
  end
87
76
 
88
77
  should "generate 1 error result" do
89
- assert_equal 1, test_run_result_count(:error)
78
+ assert_that(test_run_result_count(:error)).equals(1)
90
79
  end
91
-
92
80
  end
93
81
 
94
82
  class MixedTests < SystemTests
95
83
  desc "when passing 1 assertion and failing 1 assertion"
96
- setup do
97
- @test = Factory.test do
84
+
85
+ let(:test1) {
86
+ Factory.test do
98
87
  assert(1 == 1)
99
88
  assert(1 == 0)
100
89
  end
101
- @test.run(&test_run_callback)
102
- end
90
+ }
103
91
 
104
92
  should "generate 2 total results" do
105
- assert_equal 2, test_run_result_count
93
+ assert_that(test_run_result_count).equals(2)
106
94
  end
107
95
 
108
96
  should "generate 1 pass result" do
109
- assert_equal 1, test_run_result_count(:pass)
97
+ assert_that(test_run_result_count(:pass)).equals(1)
110
98
  end
111
99
 
112
100
  should "generate 1 fail result" do
113
- assert_equal 1, test_run_result_count(:fail)
101
+ assert_that(test_run_result_count(:fail)).equals(1)
114
102
  end
115
-
116
103
  end
117
104
 
118
105
  class MixedSkipTests < SystemTests
119
106
  desc "when passing 1 assertion and failing 1 assertion with a skip call in between"
120
- setup do
121
- @test = Factory.test do
107
+
108
+ let(:test1) {
109
+ Factory.test do
122
110
  assert(1 == 1)
123
111
  skip
124
112
  assert(1 == 0)
125
113
  end
126
- @test.run(&test_run_callback)
127
- end
114
+ }
128
115
 
129
116
  should "generate 2 total results" do
130
- assert_equal 2, test_run_result_count
117
+ assert_that(test_run_result_count).equals(2)
131
118
  end
132
119
 
133
120
  should "generate a skip for its last result" do
134
- assert_kind_of Assert::Result::Skip, last_test_run_result
121
+ assert_that(last_test_run_result).is_kind_of(Assert::Result::Skip)
135
122
  end
136
123
 
137
124
  should "generate 1 pass result" do
138
- assert_equal 1, test_run_result_count(:pass)
125
+ assert_that(test_run_result_count(:pass)).equals(1)
139
126
  end
140
127
 
141
128
  should "generate 1 skip result" do
142
- assert_equal 1, test_run_result_count(:skip)
129
+ assert_that(test_run_result_count(:skip)).equals(1)
143
130
  end
144
131
 
145
132
  should "generate 0 fail results" do
146
- assert_equal 0, test_run_result_count(:fail)
133
+ assert_that(test_run_result_count(:fail)).equals(0)
147
134
  end
148
-
149
135
  end
150
136
 
151
137
  class MixedErrorTests < SystemTests
152
138
  desc "when passing 1 assertion and failing 1 assertion with an exception raised in between"
153
- setup do
154
- @test = Factory.test do
139
+
140
+ let(:test1) {
141
+ Factory.test do
155
142
  assert(1 == 1)
156
143
  raise Exception, "something errored"
157
144
  assert(1 == 0)
158
145
  end
159
- @test.run(&test_run_callback)
160
- end
146
+ }
161
147
 
162
148
  should "generate 2 total results" do
163
- assert_equal 2, test_run_result_count
149
+ assert_that(test_run_result_count).equals(2)
164
150
  end
165
151
 
166
152
  should "generate an error for its last result" do
167
- assert_kind_of Assert::Result::Error, last_test_run_result
153
+ assert_that(last_test_run_result).is_kind_of(Assert::Result::Error)
168
154
  end
169
155
 
170
156
  should "generate 1 pass result" do
171
- assert_equal 1, test_run_result_count(:pass)
157
+ assert_that(test_run_result_count(:pass)).equals(1)
172
158
  end
173
159
 
174
160
  should "generate 1 error result" do
175
- assert_equal 1, test_run_result_count(:error)
161
+ assert_that(test_run_result_count(:error)).equals(1)
176
162
  end
177
163
 
178
164
  should "generate 0 fail results" do
179
- assert_equal 0, test_run_result_count(:fail)
165
+ assert_that(test_run_result_count(:fail)).equals(0)
180
166
  end
181
-
182
167
  end
183
168
 
184
169
  class MixedPassTests < SystemTests
185
170
  desc "when passing 1 assertion and failing 1 assertion with a pass call in between"
186
- setup do
187
- @test = Factory.test do
171
+
172
+ let(:test1) {
173
+ Factory.test do
188
174
  assert(1 == 1)
189
175
  pass
190
176
  assert(1 == 0)
191
177
  end
192
- @test.run(&test_run_callback)
193
- end
178
+ }
194
179
 
195
180
  should "generate 3 total results" do
196
- assert_equal 3, test_run_result_count
181
+ assert_that(test_run_result_count).equals(3)
197
182
  end
198
183
 
199
184
  should "generate a fail for its last result" do
200
- assert_kind_of Assert::Result::Fail, last_test_run_result
185
+ assert_that(last_test_run_result).is_kind_of(Assert::Result::Fail)
201
186
  end
202
187
 
203
188
  should "generate 2 pass results" do
204
- assert_equal 2, test_run_result_count(:pass)
189
+ assert_that(test_run_result_count(:pass)).equals(2)
205
190
  end
206
191
 
207
192
  should "generate 1 fail result" do
208
- assert_equal 1, test_run_result_count(:fail)
193
+ assert_that(test_run_result_count(:fail)).equals(1)
209
194
  end
210
-
211
195
  end
212
196
 
213
197
  class MixedFailTests < SystemTests
214
198
  desc "when failing 1 assertion and passing 1 assertion with a fail call in between"
215
- setup do
216
- @test = Factory.test do
199
+
200
+ let(:test1) {
201
+ Factory.test do
217
202
  assert(1 == 0)
218
203
  fail
219
204
  assert(1 == 1)
220
205
  end
221
- @test.run(&test_run_callback)
222
- end
206
+ }
223
207
 
224
208
  should "generate 3 total results" do
225
- assert_equal 3, test_run_result_count
209
+ assert_that(test_run_result_count).equals(3)
226
210
  end
227
211
 
228
212
  should "generate a pass for its last result" do
229
- assert_kind_of Assert::Result::Pass, last_test_run_result
213
+ assert_that(last_test_run_result).is_kind_of(Assert::Result::Pass)
230
214
  end
231
215
 
232
216
  should "generate 1 pass result" do
233
- assert_equal 1, test_run_result_count(:pass)
217
+ assert_that(test_run_result_count(:pass)).equals(1)
234
218
  end
235
219
 
236
220
  should "generate 2 fail results" do
237
- assert_equal 2, test_run_result_count(:fail)
221
+ assert_that(test_run_result_count(:fail)).equals(2)
238
222
  end
239
-
240
223
  end
241
224
 
242
225
  class MixedFlunkTests < SystemTests
243
226
  desc "has failing 1 assertion and passing 1 assertion with a flunk call in between"
244
- setup do
245
- @test = Factory.test do
227
+
228
+ let(:test1) {
229
+ Factory.test do
246
230
  assert(1 == 0)
247
231
  flunk
248
232
  assert(1 == 1)
249
233
  end
250
- @test.run(&test_run_callback)
251
- end
234
+ }
252
235
 
253
236
  should "generate 3 total results" do
254
- assert_equal 3, test_run_result_count
237
+ assert_that(test_run_result_count).equals(3)
255
238
  end
256
239
 
257
240
  should "generate a pass for its last result" do
258
- assert_kind_of Assert::Result::Pass, last_test_run_result
241
+ assert_that(last_test_run_result).is_kind_of(Assert::Result::Pass)
259
242
  end
260
243
 
261
244
  should "generate 1 pass results" do
262
- assert_equal 1, test_run_result_count(:pass)
245
+ assert_that(test_run_result_count(:pass)).equals(1)
263
246
  end
264
247
 
265
248
  should "generate 2 fail results" do
266
- assert_equal 2, test_run_result_count(:fail)
249
+ assert_that(test_run_result_count(:fail)).equals(2)
267
250
  end
268
-
269
251
  end
270
252
 
271
253
  class WithSetupsTests < SystemTests
272
254
  desc "that has setup logic"
273
- setup do
274
- @context_class = Factory.context_class do
255
+
256
+ let(:context_class1) {
257
+ Factory.context_class do
275
258
  # assert style
276
- setup{ pass 'assert style setup' }
259
+ setup { pass "assert style setup" }
277
260
  # test/unit style
278
- def setup; pass 'test/unit style setup'; end
261
+ def setup; pass "test/unit style setup"; end
279
262
  end
280
- @test = Factory.test("t", Factory.context_info(@context_class)){ pass 'TEST' }
281
- @test.run(&test_run_callback)
282
- end
263
+ }
264
+ let(:test1) {
265
+ Factory.test("t", Factory.context_info(context_class1)) { pass "TEST" }
266
+ }
283
267
 
284
268
  should "execute all setup logic when run" do
285
- assert_equal 3, test_run_result_count(:pass)
269
+ assert_that(test_run_result_count(:pass)).equals(3)
286
270
 
287
- exp = ['assert style setup', 'test/unit style setup', 'TEST']
288
- assert_equal exp, test_run_result_messages
271
+ exp = ["assert style setup", "test/unit style setup", "TEST"]
272
+ assert_that(test_run_result_messages).equals(exp)
289
273
  end
290
-
291
274
  end
292
275
 
293
276
  class WithTeardownsTests < SystemTests
294
277
  desc "that has teardown logic"
295
- setup do
296
- @context_class = Factory.context_class do
278
+
279
+ let(:context_class1) {
280
+ Factory.context_class do
297
281
  # assert style
298
- teardown{ pass 'assert style teardown' }
282
+ teardown { pass "assert style teardown" }
299
283
  # test/unit style
300
- def teardown; pass 'test/unit style teardown'; end
284
+ def teardown; pass "test/unit style teardown"; end
301
285
  end
302
- @test = Factory.test("t", Factory.context_info(@context_class)){ pass 'TEST' }
303
- @test.run(&test_run_callback)
304
- end
286
+ }
287
+ let(:test1) {
288
+ Factory.test("t", Factory.context_info(context_class1)) { pass "TEST" }
289
+ }
305
290
 
306
291
  should "execute all teardown logic when run" do
307
- assert_equal 3, test_run_result_count(:pass)
292
+ assert_that(test_run_result_count(:pass)).equals(3)
308
293
 
309
- exp = ['TEST', 'assert style teardown', 'test/unit style teardown']
310
- assert_equal exp, test_run_result_messages
294
+ exp = ["TEST", "assert style teardown", "test/unit style teardown"]
295
+ assert_that(test_run_result_messages).equals(exp)
311
296
  end
312
-
313
297
  end
314
298
 
315
299
  class WithAroundsTests < SystemTests
316
300
  desc "that has around logic (in addition to setups/teardowns)"
317
- setup do
318
- @parent_context_class = Factory.modes_off_context_class do
301
+
302
+ let(:parent_context_class1) {
303
+ Factory.modes_off_context_class do
319
304
  around do |block|
320
305
  pass "parent around start"
321
306
  block.call
322
307
  pass "parent around end"
323
308
  end
324
- setup{ pass "parent setup" }
325
- teardown{ pass "parent teardown" }
309
+ setup { pass "parent setup" }
310
+ teardown { pass "parent teardown" }
326
311
  end
327
- @context_class = Factory.modes_off_context_class(@parent_context_class) do
328
- setup{ pass "child setup1" }
312
+ }
313
+ let(:context_class1) {
314
+ Factory.modes_off_context_class(parent_context_class1) do
315
+ setup { pass "child setup1" }
329
316
  around do |block|
330
317
  pass "child around1 start"
331
318
  block.call
332
319
  pass "child around1 end"
333
320
  end
334
- teardown{ pass "child teardown1" }
335
- setup{ pass "child setup2" }
321
+ teardown { pass "child teardown1" }
322
+ setup { pass "child setup2" }
336
323
  around do |block|
337
324
  pass "child around2 start"
338
325
  block.call
339
326
  pass "child around2 end"
340
327
  end
341
- teardown{ pass "child teardown2" }
328
+ teardown { pass "child teardown2" }
342
329
  end
343
- @test = Factory.test("t", Factory.context_info(@context_class)){ pass "TEST" }
344
- @test.run(&test_run_callback)
345
- end
330
+ }
331
+ let(:test1) {
332
+ Factory.test("t", Factory.context_info(context_class1)) { pass "TEST" }
333
+ }
346
334
 
347
335
  should "run the arounds outside of the setups/teardowns/test" do
348
- assert_equal 13, test_run_result_count(:pass)
336
+ assert_that(test_run_result_count(:pass)).equals(13)
349
337
 
350
338
  exp = [
351
- 'parent around start', 'child around1 start', 'child around2 start',
352
- 'parent setup', 'child setup1', 'child setup2', 'TEST',
353
- 'child teardown1', 'child teardown2', 'parent teardown',
354
- 'child around2 end', 'child around1 end', 'parent around end'
339
+ "parent around start", "child around1 start", "child around2 start",
340
+ "parent setup", "child setup1", "child setup2", "TEST",
341
+ "child teardown1", "child teardown2", "parent teardown",
342
+ "child around2 end", "child around1 end", "parent around end"
355
343
  ]
356
- assert_equal exp, test_run_result_messages
344
+ assert_that(test_run_result_messages).equals(exp)
357
345
  end
358
-
359
346
  end
360
-
361
347
  end