assert 2.15.2 → 2.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +5 -5
  2. data/lib/assert/assertions.rb +6 -0
  3. data/lib/assert/config_helpers.rb +35 -14
  4. data/lib/assert/context.rb +36 -43
  5. data/lib/assert/context/test_dsl.rb +4 -4
  6. data/lib/assert/default_suite.rb +35 -40
  7. data/lib/assert/default_view.rb +109 -37
  8. data/lib/assert/file_line.rb +1 -1
  9. data/lib/assert/result.rb +67 -27
  10. data/lib/assert/runner.rb +14 -10
  11. data/lib/assert/suite.rb +41 -50
  12. data/lib/assert/test.rb +39 -81
  13. data/lib/assert/version.rb +1 -1
  14. data/lib/assert/view_helpers.rb +11 -21
  15. data/test/helper.rb +40 -0
  16. data/test/system/test_tests.rb +90 -88
  17. data/test/unit/assertions/assert_block_tests.rb +14 -10
  18. data/test/unit/assertions/assert_empty_tests.rb +14 -10
  19. data/test/unit/assertions/assert_equal_tests.rb +22 -14
  20. data/test/unit/assertions/assert_file_exists_tests.rb +14 -10
  21. data/test/unit/assertions/assert_includes_tests.rb +14 -10
  22. data/test/unit/assertions/assert_instance_of_tests.rb +14 -10
  23. data/test/unit/assertions/assert_kind_of_tests.rb +14 -10
  24. data/test/unit/assertions/assert_match_tests.rb +14 -10
  25. data/test/unit/assertions/assert_nil_tests.rb +14 -10
  26. data/test/unit/assertions/assert_raises_tests.rb +14 -10
  27. data/test/unit/assertions/assert_respond_to_tests.rb +14 -10
  28. data/test/unit/assertions/assert_same_tests.rb +20 -14
  29. data/test/unit/assertions/assert_true_false_tests.rb +28 -20
  30. data/test/unit/assertions_tests.rb +12 -9
  31. data/test/unit/config_helpers_tests.rb +72 -13
  32. data/test/unit/context/test_dsl_tests.rb +38 -45
  33. data/test/unit/context_tests.rb +12 -8
  34. data/test/unit/default_suite_tests.rb +66 -43
  35. data/test/unit/file_line_tests.rb +4 -1
  36. data/test/unit/result_tests.rb +71 -47
  37. data/test/unit/runner_tests.rb +34 -16
  38. data/test/unit/suite_tests.rb +61 -29
  39. data/test/unit/test_tests.rb +97 -134
  40. data/test/unit/view_helpers_tests.rb +17 -31
  41. metadata +2 -2
@@ -1,3 +1,3 @@
1
1
  module Assert
2
- VERSION = "2.15.2"
2
+ VERSION = "2.16.0"
3
3
  end
@@ -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 test_count_statement
54
- "#{self.count(:tests)} test#{'s' if self.count(:tests) != 1}"
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.count(:results)} result#{'s' if self.count(:results) != 1}"
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.count(:results) < 1
62
+ if self.result_count < 1
73
63
  "uhh..."
74
- elsif self.count(:results) == 1
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.count(result_type)} #{result_type.to_s}"
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 |result_sym|
94
- summary_msg = self.result_summary_msg(result_sym)
95
- block_given? ? yield(summary_msg, result_sym) : 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, result_or_sym)
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("#{result_or_sym.to_sym}_styles"))
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
@@ -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 "have 0 results" do
19
- assert_equal 0, subject.result_count
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 "have 1 result" do
32
- assert_equal 1, subject.result_count
33
+ should "generate 1 result" do
34
+ assert_equal 1, test_run_result_count
33
35
  end
34
36
 
35
- should "have 1 pass result" do
36
- assert_equal 1, subject.result_count(:pass)
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 "have 1 result" do
49
- assert_equal 1, subject.result_count
50
+ should "generate 1 result" do
51
+ assert_equal 1, test_run_result_count
50
52
  end
51
53
 
52
- should "have 1 fail result" do
53
- assert_equal 1, subject.result_count(:fail)
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 "have 1 result" do
66
- assert_equal 1, subject.result_count
67
+ should "generate 1 result" do
68
+ assert_equal 1, test_run_result_count
67
69
  end
68
70
 
69
- should "have 1 skip result" do
70
- assert_equal 1, subject.result_count(:skip)
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 "have 1 result" do
83
- assert_equal 1, subject.result_count
84
+ should "generate 1 result" do
85
+ assert_equal 1, test_run_result_count
84
86
  end
85
87
 
86
- should "have 1 error result" do
87
- assert_equal 1, subject.result_count(:error)
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 "have 2 total results" do
103
- assert_equal 2, subject.result_count
104
+ should "generate 2 total results" do
105
+ assert_equal 2, test_run_result_count
104
106
  end
105
107
 
106
- should "have 1 pass result" do
107
- assert_equal 1, subject.result_count(:pass)
108
+ should "generate 1 pass result" do
109
+ assert_equal 1, test_run_result_count(:pass)
108
110
  end
109
111
 
110
- should "have 1 fail result" do
111
- assert_equal 1, subject.result_count(:fail)
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 "have 2 total results" do
128
- assert_equal 2, subject.result_count
129
+ should "generate 2 total results" do
130
+ assert_equal 2, test_run_result_count
129
131
  end
130
132
 
131
- should "have a skip for its last result" do
132
- assert_kind_of Assert::Result::Skip, subject.results.last
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 "have 1 pass result" do
136
- assert_equal 1, subject.result_count(:pass)
137
+ should "generate 1 pass result" do
138
+ assert_equal 1, test_run_result_count(:pass)
137
139
  end
138
140
 
139
- should "have 1 skip result" do
140
- assert_equal 1, subject.result_count(:skip)
141
+ should "generate 1 skip result" do
142
+ assert_equal 1, test_run_result_count(:skip)
141
143
  end
142
144
 
143
- should "have 0 fail results" do
144
- assert_equal 0, subject.result_count(:fail)
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 "have 2 total results" do
161
- assert_equal 2, subject.result_count
162
+ should "generate 2 total results" do
163
+ assert_equal 2, test_run_result_count
162
164
  end
163
165
 
164
- should "have an error for its last result" do
165
- assert_kind_of Assert::Result::Error, subject.results.last
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 "have 1 pass result" do
169
- assert_equal 1, subject.result_count(:pass)
170
+ should "generate 1 pass result" do
171
+ assert_equal 1, test_run_result_count(:pass)
170
172
  end
171
173
 
172
- should "have 1 error result" do
173
- assert_equal 1, subject.result_count(:error)
174
+ should "generate 1 error result" do
175
+ assert_equal 1, test_run_result_count(:error)
174
176
  end
175
177
 
176
- should "have 0 fail results" do
177
- assert_equal 0, subject.result_count(:fail)
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 "have 3 total results" do
194
- assert_equal 3, subject.result_count
195
+ should "generate 3 total results" do
196
+ assert_equal 3, test_run_result_count
195
197
  end
196
198
 
197
- should "have a fail for its last result" do
198
- assert_kind_of Assert::Result::Fail, subject.results.last
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 "have 2 pass results" do
202
- assert_equal 2, subject.result_count(:pass)
203
+ should "generate 2 pass results" do
204
+ assert_equal 2, test_run_result_count(:pass)
203
205
  end
204
206
 
205
- should "have 1 fail result" do
206
- assert_equal 1, subject.result_count(:fail)
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 "have 3 total results" do
223
- assert_equal 3, subject.result_count
224
+ should "generate 3 total results" do
225
+ assert_equal 3, test_run_result_count
224
226
  end
225
227
 
226
- should "have a pass for its last result" do
227
- assert_kind_of Assert::Result::Pass, subject.results.last
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 "have 1 pass result" do
231
- assert_equal 1, subject.result_count(:pass)
232
+ should "generate 1 pass result" do
233
+ assert_equal 1, test_run_result_count(:pass)
232
234
  end
233
235
 
234
- should "have 2 fail results" do
235
- assert_equal 2, subject.result_count(:fail)
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 "have 3 total results" do
252
- assert_equal 3, subject.result_count
253
+ should "generate 3 total results" do
254
+ assert_equal 3, test_run_result_count
253
255
  end
254
256
 
255
- should "have a pass for its last result" do
256
- assert_kind_of Assert::Result::Pass, subject.results.last
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 "have 1 pass results" do
260
- assert_equal 1, subject.result_count(:pass)
261
+ should "generate 1 pass results" do
262
+ assert_equal 1, test_run_result_count(:pass)
261
263
  end
262
264
 
263
- should "have 2 fail results" do
264
- assert_equal 2, subject.result_count(:fail)
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, subject.result_count(:pass)
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, subject.results.map(&:message)
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, subject.result_count(:pass)
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, subject.results.map(&:message)
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, subject.result_count(:pass)
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, subject.results.map(&:message)
356
+ assert_equal exp, test_run_result_messages
355
357
  end
356
358
 
357
359
  end