assert 2.15.2 → 2.16.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 +5 -5
- data/lib/assert/assertions.rb +6 -0
- data/lib/assert/config_helpers.rb +35 -14
- data/lib/assert/context.rb +36 -43
- data/lib/assert/context/test_dsl.rb +4 -4
- data/lib/assert/default_suite.rb +35 -40
- data/lib/assert/default_view.rb +109 -37
- data/lib/assert/file_line.rb +1 -1
- data/lib/assert/result.rb +67 -27
- data/lib/assert/runner.rb +14 -10
- data/lib/assert/suite.rb +41 -50
- data/lib/assert/test.rb +39 -81
- data/lib/assert/version.rb +1 -1
- data/lib/assert/view_helpers.rb +11 -21
- data/test/helper.rb +40 -0
- data/test/system/test_tests.rb +90 -88
- data/test/unit/assertions/assert_block_tests.rb +14 -10
- data/test/unit/assertions/assert_empty_tests.rb +14 -10
- data/test/unit/assertions/assert_equal_tests.rb +22 -14
- data/test/unit/assertions/assert_file_exists_tests.rb +14 -10
- data/test/unit/assertions/assert_includes_tests.rb +14 -10
- data/test/unit/assertions/assert_instance_of_tests.rb +14 -10
- data/test/unit/assertions/assert_kind_of_tests.rb +14 -10
- data/test/unit/assertions/assert_match_tests.rb +14 -10
- data/test/unit/assertions/assert_nil_tests.rb +14 -10
- data/test/unit/assertions/assert_raises_tests.rb +14 -10
- data/test/unit/assertions/assert_respond_to_tests.rb +14 -10
- data/test/unit/assertions/assert_same_tests.rb +20 -14
- data/test/unit/assertions/assert_true_false_tests.rb +28 -20
- data/test/unit/assertions_tests.rb +12 -9
- data/test/unit/config_helpers_tests.rb +72 -13
- data/test/unit/context/test_dsl_tests.rb +38 -45
- data/test/unit/context_tests.rb +12 -8
- data/test/unit/default_suite_tests.rb +66 -43
- data/test/unit/file_line_tests.rb +4 -1
- data/test/unit/result_tests.rb +71 -47
- data/test/unit/runner_tests.rb +34 -16
- data/test/unit/suite_tests.rb +61 -29
- data/test/unit/test_tests.rb +97 -134
- data/test/unit/view_helpers_tests.rb +17 -31
- metadata +2 -2
data/lib/assert/version.rb
CHANGED
data/lib/assert/view_helpers.rb
CHANGED
@@ -28,16 +28,6 @@ module Assert
|
|
28
28
|
|
29
29
|
module InstanceMethods
|
30
30
|
|
31
|
-
# get the formatted run time for an idividual test
|
32
|
-
def test_run_time(test, format = '%.6f')
|
33
|
-
format % test.run_time
|
34
|
-
end
|
35
|
-
|
36
|
-
# get the formatted result rate for an individual test
|
37
|
-
def test_result_rate(test, format = '%.6f')
|
38
|
-
format % test.result_rate
|
39
|
-
end
|
40
|
-
|
41
31
|
# show any captured output
|
42
32
|
def captured_output(output)
|
43
33
|
"--- stdout ---\n"\
|
@@ -50,12 +40,12 @@ module Assert
|
|
50
40
|
"assert -t #{test_id.gsub(Dir.pwd, '.')}"
|
51
41
|
end
|
52
42
|
|
53
|
-
def
|
54
|
-
"#{self.
|
43
|
+
def tests_to_run_count_statement
|
44
|
+
"#{self.tests_to_run_count} test#{'s' if self.tests_to_run_count != 1}"
|
55
45
|
end
|
56
46
|
|
57
47
|
def result_count_statement
|
58
|
-
"#{self.
|
48
|
+
"#{self.result_count} result#{'s' if self.result_count != 1}"
|
59
49
|
end
|
60
50
|
|
61
51
|
# generate a comma-seperated sentence fragment given a list of items
|
@@ -69,9 +59,9 @@ module Assert
|
|
69
59
|
|
70
60
|
# generate an appropriate result summary msg for all tests passing
|
71
61
|
def all_pass_result_summary_msg
|
72
|
-
if self.
|
62
|
+
if self.result_count < 1
|
73
63
|
"uhh..."
|
74
|
-
elsif self.
|
64
|
+
elsif self.result_count == 1
|
75
65
|
"pass"
|
76
66
|
else
|
77
67
|
"all pass"
|
@@ -83,16 +73,16 @@ module Assert
|
|
83
73
|
if result_type == :pass && self.all_pass?
|
84
74
|
self.all_pass_result_summary_msg
|
85
75
|
else
|
86
|
-
"#{self.
|
76
|
+
"#{self.send("#{result_type}_result_count")} #{result_type}"
|
87
77
|
end
|
88
78
|
end
|
89
79
|
|
90
80
|
# generate a sentence fragment describing the breakdown of test results
|
91
81
|
# if a block is given, yield each msg in the breakdown for custom formatting
|
92
82
|
def results_summary_sentence
|
93
|
-
summaries = self.ocurring_result_types.map do |
|
94
|
-
summary_msg = self.result_summary_msg(
|
95
|
-
block_given? ? yield(summary_msg,
|
83
|
+
summaries = self.ocurring_result_types.map do |result_type|
|
84
|
+
summary_msg = self.result_summary_msg(result_type)
|
85
|
+
block_given? ? yield(summary_msg, result_type) : summary_msg
|
96
86
|
end
|
97
87
|
self.to_sentence(summaries)
|
98
88
|
end
|
@@ -186,9 +176,9 @@ module Assert
|
|
186
176
|
style_names.map{ |n| "\e[#{CODES[n]}m" if CODES.key?(n) }.compact.join('')
|
187
177
|
end
|
188
178
|
|
189
|
-
def ansi_styled_msg(msg,
|
179
|
+
def ansi_styled_msg(msg, result_type)
|
190
180
|
return msg if !self.is_tty? || !self.styled
|
191
|
-
code = Assert::ViewHelpers::Ansi.code_for(*self.send("#{
|
181
|
+
code = Assert::ViewHelpers::Ansi.code_for(*self.send("#{result_type}_styles"))
|
192
182
|
return msg if code.empty?
|
193
183
|
code + msg + Assert::ViewHelpers::Ansi.code_for(:reset)
|
194
184
|
end
|
data/test/helper.rb
CHANGED
@@ -17,3 +17,43 @@ if !(a = Array.new).respond_to?(:sample) && a.respond_to?(:choice)
|
|
17
17
|
alias_method :sample, :choice
|
18
18
|
end
|
19
19
|
end
|
20
|
+
|
21
|
+
class Assert::Test
|
22
|
+
|
23
|
+
module TestHelpers
|
24
|
+
|
25
|
+
def self.included(receiver)
|
26
|
+
receiver.class_eval do
|
27
|
+
setup do
|
28
|
+
@test_run_results = []
|
29
|
+
@run_callback = proc{ |result| @test_run_results << result }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def test_run_callback
|
36
|
+
@run_callback
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_run_results(type = nil)
|
40
|
+
return @test_run_results if type.nil?
|
41
|
+
@test_run_results.select{ |r| r.type == type }
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_run_result_count(type = nil)
|
45
|
+
test_run_results(type).count
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_run_result_messages
|
49
|
+
@test_run_results.map(&:message)
|
50
|
+
end
|
51
|
+
|
52
|
+
def last_test_run_result
|
53
|
+
@test_run_results.last
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
data/test/system/test_tests.rb
CHANGED
@@ -3,6 +3,8 @@ require 'assert'
|
|
3
3
|
class Assert::Test
|
4
4
|
|
5
5
|
class SystemTests < Assert::Context
|
6
|
+
include Assert::Test::TestHelpers
|
7
|
+
|
6
8
|
desc "Assert::Test"
|
7
9
|
subject{ @test }
|
8
10
|
|
@@ -12,11 +14,11 @@ class Assert::Test
|
|
12
14
|
desc "when producing no results"
|
13
15
|
setup do
|
14
16
|
@test = Factory.test
|
15
|
-
@test.run
|
17
|
+
@test.run(&test_run_callback)
|
16
18
|
end
|
17
19
|
|
18
|
-
should "
|
19
|
-
assert_equal 0,
|
20
|
+
should "generate 0 results" do
|
21
|
+
assert_equal 0, test_run_result_count
|
20
22
|
end
|
21
23
|
|
22
24
|
end
|
@@ -25,15 +27,15 @@ class Assert::Test
|
|
25
27
|
desc "when passing a single assertion"
|
26
28
|
setup do
|
27
29
|
@test = Factory.test{ assert(1 == 1) }
|
28
|
-
@test.run
|
30
|
+
@test.run(&test_run_callback)
|
29
31
|
end
|
30
32
|
|
31
|
-
should "
|
32
|
-
assert_equal 1,
|
33
|
+
should "generate 1 result" do
|
34
|
+
assert_equal 1, test_run_result_count
|
33
35
|
end
|
34
36
|
|
35
|
-
should "
|
36
|
-
assert_equal 1,
|
37
|
+
should "generate 1 pass result" do
|
38
|
+
assert_equal 1, test_run_result_count(:pass)
|
37
39
|
end
|
38
40
|
|
39
41
|
end
|
@@ -42,15 +44,15 @@ class Assert::Test
|
|
42
44
|
desc "when failing a single assertion"
|
43
45
|
setup do
|
44
46
|
@test = Factory.test{ assert(1 == 0) }
|
45
|
-
@test.run
|
47
|
+
@test.run(&test_run_callback)
|
46
48
|
end
|
47
49
|
|
48
|
-
should "
|
49
|
-
assert_equal 1,
|
50
|
+
should "generate 1 result" do
|
51
|
+
assert_equal 1, test_run_result_count
|
50
52
|
end
|
51
53
|
|
52
|
-
should "
|
53
|
-
assert_equal 1,
|
54
|
+
should "generate 1 fail result" do
|
55
|
+
assert_equal 1, test_run_result_count(:fail)
|
54
56
|
end
|
55
57
|
|
56
58
|
end
|
@@ -59,15 +61,15 @@ class Assert::Test
|
|
59
61
|
desc "when skipping once"
|
60
62
|
setup do
|
61
63
|
@test = Factory.test{ skip }
|
62
|
-
@test.run
|
64
|
+
@test.run(&test_run_callback)
|
63
65
|
end
|
64
66
|
|
65
|
-
should "
|
66
|
-
assert_equal 1,
|
67
|
+
should "generate 1 result" do
|
68
|
+
assert_equal 1, test_run_result_count
|
67
69
|
end
|
68
70
|
|
69
|
-
should "
|
70
|
-
assert_equal 1,
|
71
|
+
should "generate 1 skip result" do
|
72
|
+
assert_equal 1, test_run_result_count(:skip)
|
71
73
|
end
|
72
74
|
|
73
75
|
end
|
@@ -76,15 +78,15 @@ class Assert::Test
|
|
76
78
|
desc "when erroring once"
|
77
79
|
setup do
|
78
80
|
@test = Factory.test{ raise("WHAT") }
|
79
|
-
@test.run
|
81
|
+
@test.run(&test_run_callback)
|
80
82
|
end
|
81
83
|
|
82
|
-
should "
|
83
|
-
assert_equal 1,
|
84
|
+
should "generate 1 result" do
|
85
|
+
assert_equal 1, test_run_result_count
|
84
86
|
end
|
85
87
|
|
86
|
-
should "
|
87
|
-
assert_equal 1,
|
88
|
+
should "generate 1 error result" do
|
89
|
+
assert_equal 1, test_run_result_count(:error)
|
88
90
|
end
|
89
91
|
|
90
92
|
end
|
@@ -96,19 +98,19 @@ class Assert::Test
|
|
96
98
|
assert(1 == 1)
|
97
99
|
assert(1 == 0)
|
98
100
|
end
|
99
|
-
@test.run
|
101
|
+
@test.run(&test_run_callback)
|
100
102
|
end
|
101
103
|
|
102
|
-
should "
|
103
|
-
assert_equal 2,
|
104
|
+
should "generate 2 total results" do
|
105
|
+
assert_equal 2, test_run_result_count
|
104
106
|
end
|
105
107
|
|
106
|
-
should "
|
107
|
-
assert_equal 1,
|
108
|
+
should "generate 1 pass result" do
|
109
|
+
assert_equal 1, test_run_result_count(:pass)
|
108
110
|
end
|
109
111
|
|
110
|
-
should "
|
111
|
-
assert_equal 1,
|
112
|
+
should "generate 1 fail result" do
|
113
|
+
assert_equal 1, test_run_result_count(:fail)
|
112
114
|
end
|
113
115
|
|
114
116
|
end
|
@@ -121,27 +123,27 @@ class Assert::Test
|
|
121
123
|
skip
|
122
124
|
assert(1 == 0)
|
123
125
|
end
|
124
|
-
@test.run
|
126
|
+
@test.run(&test_run_callback)
|
125
127
|
end
|
126
128
|
|
127
|
-
should "
|
128
|
-
assert_equal 2,
|
129
|
+
should "generate 2 total results" do
|
130
|
+
assert_equal 2, test_run_result_count
|
129
131
|
end
|
130
132
|
|
131
|
-
should "
|
132
|
-
assert_kind_of Assert::Result::Skip,
|
133
|
+
should "generate a skip for its last result" do
|
134
|
+
assert_kind_of Assert::Result::Skip, last_test_run_result
|
133
135
|
end
|
134
136
|
|
135
|
-
should "
|
136
|
-
assert_equal 1,
|
137
|
+
should "generate 1 pass result" do
|
138
|
+
assert_equal 1, test_run_result_count(:pass)
|
137
139
|
end
|
138
140
|
|
139
|
-
should "
|
140
|
-
assert_equal 1,
|
141
|
+
should "generate 1 skip result" do
|
142
|
+
assert_equal 1, test_run_result_count(:skip)
|
141
143
|
end
|
142
144
|
|
143
|
-
should "
|
144
|
-
assert_equal 0,
|
145
|
+
should "generate 0 fail results" do
|
146
|
+
assert_equal 0, test_run_result_count(:fail)
|
145
147
|
end
|
146
148
|
|
147
149
|
end
|
@@ -154,27 +156,27 @@ class Assert::Test
|
|
154
156
|
raise Exception, "something errored"
|
155
157
|
assert(1 == 0)
|
156
158
|
end
|
157
|
-
@test.run
|
159
|
+
@test.run(&test_run_callback)
|
158
160
|
end
|
159
161
|
|
160
|
-
should "
|
161
|
-
assert_equal 2,
|
162
|
+
should "generate 2 total results" do
|
163
|
+
assert_equal 2, test_run_result_count
|
162
164
|
end
|
163
165
|
|
164
|
-
should "
|
165
|
-
assert_kind_of Assert::Result::Error,
|
166
|
+
should "generate an error for its last result" do
|
167
|
+
assert_kind_of Assert::Result::Error, last_test_run_result
|
166
168
|
end
|
167
169
|
|
168
|
-
should "
|
169
|
-
assert_equal 1,
|
170
|
+
should "generate 1 pass result" do
|
171
|
+
assert_equal 1, test_run_result_count(:pass)
|
170
172
|
end
|
171
173
|
|
172
|
-
should "
|
173
|
-
assert_equal 1,
|
174
|
+
should "generate 1 error result" do
|
175
|
+
assert_equal 1, test_run_result_count(:error)
|
174
176
|
end
|
175
177
|
|
176
|
-
should "
|
177
|
-
assert_equal 0,
|
178
|
+
should "generate 0 fail results" do
|
179
|
+
assert_equal 0, test_run_result_count(:fail)
|
178
180
|
end
|
179
181
|
|
180
182
|
end
|
@@ -187,23 +189,23 @@ class Assert::Test
|
|
187
189
|
pass
|
188
190
|
assert(1 == 0)
|
189
191
|
end
|
190
|
-
@test.run
|
192
|
+
@test.run(&test_run_callback)
|
191
193
|
end
|
192
194
|
|
193
|
-
should "
|
194
|
-
assert_equal 3,
|
195
|
+
should "generate 3 total results" do
|
196
|
+
assert_equal 3, test_run_result_count
|
195
197
|
end
|
196
198
|
|
197
|
-
should "
|
198
|
-
assert_kind_of Assert::Result::Fail,
|
199
|
+
should "generate a fail for its last result" do
|
200
|
+
assert_kind_of Assert::Result::Fail, last_test_run_result
|
199
201
|
end
|
200
202
|
|
201
|
-
should "
|
202
|
-
assert_equal 2,
|
203
|
+
should "generate 2 pass results" do
|
204
|
+
assert_equal 2, test_run_result_count(:pass)
|
203
205
|
end
|
204
206
|
|
205
|
-
should "
|
206
|
-
assert_equal 1,
|
207
|
+
should "generate 1 fail result" do
|
208
|
+
assert_equal 1, test_run_result_count(:fail)
|
207
209
|
end
|
208
210
|
|
209
211
|
end
|
@@ -216,23 +218,23 @@ class Assert::Test
|
|
216
218
|
fail
|
217
219
|
assert(1 == 1)
|
218
220
|
end
|
219
|
-
@test.run
|
221
|
+
@test.run(&test_run_callback)
|
220
222
|
end
|
221
223
|
|
222
|
-
should "
|
223
|
-
assert_equal 3,
|
224
|
+
should "generate 3 total results" do
|
225
|
+
assert_equal 3, test_run_result_count
|
224
226
|
end
|
225
227
|
|
226
|
-
should "
|
227
|
-
assert_kind_of Assert::Result::Pass,
|
228
|
+
should "generate a pass for its last result" do
|
229
|
+
assert_kind_of Assert::Result::Pass, last_test_run_result
|
228
230
|
end
|
229
231
|
|
230
|
-
should "
|
231
|
-
assert_equal 1,
|
232
|
+
should "generate 1 pass result" do
|
233
|
+
assert_equal 1, test_run_result_count(:pass)
|
232
234
|
end
|
233
235
|
|
234
|
-
should "
|
235
|
-
assert_equal 2,
|
236
|
+
should "generate 2 fail results" do
|
237
|
+
assert_equal 2, test_run_result_count(:fail)
|
236
238
|
end
|
237
239
|
|
238
240
|
end
|
@@ -245,23 +247,23 @@ class Assert::Test
|
|
245
247
|
flunk
|
246
248
|
assert(1 == 1)
|
247
249
|
end
|
248
|
-
@test.run
|
250
|
+
@test.run(&test_run_callback)
|
249
251
|
end
|
250
252
|
|
251
|
-
should "
|
252
|
-
assert_equal 3,
|
253
|
+
should "generate 3 total results" do
|
254
|
+
assert_equal 3, test_run_result_count
|
253
255
|
end
|
254
256
|
|
255
|
-
should "
|
256
|
-
assert_kind_of Assert::Result::Pass,
|
257
|
+
should "generate a pass for its last result" do
|
258
|
+
assert_kind_of Assert::Result::Pass, last_test_run_result
|
257
259
|
end
|
258
260
|
|
259
|
-
should "
|
260
|
-
assert_equal 1,
|
261
|
+
should "generate 1 pass results" do
|
262
|
+
assert_equal 1, test_run_result_count(:pass)
|
261
263
|
end
|
262
264
|
|
263
|
-
should "
|
264
|
-
assert_equal 2,
|
265
|
+
should "generate 2 fail results" do
|
266
|
+
assert_equal 2, test_run_result_count(:fail)
|
265
267
|
end
|
266
268
|
|
267
269
|
end
|
@@ -276,14 +278,14 @@ class Assert::Test
|
|
276
278
|
def setup; pass 'test/unit style setup'; end
|
277
279
|
end
|
278
280
|
@test = Factory.test("t", Factory.context_info(@context_class)){ pass 'TEST' }
|
279
|
-
@test.run
|
281
|
+
@test.run(&test_run_callback)
|
280
282
|
end
|
281
283
|
|
282
284
|
should "execute all setup logic when run" do
|
283
|
-
assert_equal 3,
|
285
|
+
assert_equal 3, test_run_result_count(:pass)
|
284
286
|
|
285
287
|
exp = ['assert style setup', 'test/unit style setup', 'TEST']
|
286
|
-
assert_equal exp,
|
288
|
+
assert_equal exp, test_run_result_messages
|
287
289
|
end
|
288
290
|
|
289
291
|
end
|
@@ -298,14 +300,14 @@ class Assert::Test
|
|
298
300
|
def teardown; pass 'test/unit style teardown'; end
|
299
301
|
end
|
300
302
|
@test = Factory.test("t", Factory.context_info(@context_class)){ pass 'TEST' }
|
301
|
-
@test.run
|
303
|
+
@test.run(&test_run_callback)
|
302
304
|
end
|
303
305
|
|
304
306
|
should "execute all teardown logic when run" do
|
305
|
-
assert_equal 3,
|
307
|
+
assert_equal 3, test_run_result_count(:pass)
|
306
308
|
|
307
309
|
exp = ['TEST', 'assert style teardown', 'test/unit style teardown']
|
308
|
-
assert_equal exp,
|
310
|
+
assert_equal exp, test_run_result_messages
|
309
311
|
end
|
310
312
|
|
311
313
|
end
|
@@ -339,11 +341,11 @@ class Assert::Test
|
|
339
341
|
teardown{ pass "child teardown2" }
|
340
342
|
end
|
341
343
|
@test = Factory.test("t", Factory.context_info(@context_class)){ pass "TEST" }
|
342
|
-
@test.run
|
344
|
+
@test.run(&test_run_callback)
|
343
345
|
end
|
344
346
|
|
345
347
|
should "run the arounds outside of the setups/teardowns/test" do
|
346
|
-
assert_equal 13,
|
348
|
+
assert_equal 13, test_run_result_count(:pass)
|
347
349
|
|
348
350
|
exp = [
|
349
351
|
'parent around start', 'child around1 start', 'child around2 start',
|
@@ -351,7 +353,7 @@ class Assert::Test
|
|
351
353
|
'child teardown1', 'child teardown2', 'parent teardown',
|
352
354
|
'child around2 end', 'child around1 end', 'parent around end'
|
353
355
|
]
|
354
|
-
assert_equal exp,
|
356
|
+
assert_equal exp, test_run_result_messages
|
355
357
|
end
|
356
358
|
|
357
359
|
end
|