assert 2.19.2 → 2.19.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.
- checksums.yaml +4 -4
- data/assert.gemspec +10 -7
- data/lib/assert.rb +18 -6
- data/lib/assert/actual_value.rb +8 -6
- data/lib/assert/assert_runner.rb +36 -17
- data/lib/assert/assertions.rb +83 -50
- data/lib/assert/cli.rb +17 -66
- data/lib/assert/clirb.rb +55 -0
- data/lib/assert/config.rb +7 -7
- data/lib/assert/config_helpers.rb +55 -22
- data/lib/assert/context.rb +14 -18
- data/lib/assert/context/let_dsl.rb +5 -2
- data/lib/assert/context/setup_dsl.rb +21 -16
- data/lib/assert/context/subject_dsl.rb +6 -7
- data/lib/assert/context/suite_dsl.rb +2 -1
- data/lib/assert/context/test_dsl.rb +55 -19
- data/lib/assert/default_suite.rb +25 -15
- data/lib/assert/default_view.rb +47 -30
- data/lib/assert/file_line.rb +6 -6
- data/lib/assert/macro.rb +1 -1
- data/lib/assert/macros/methods.rb +71 -45
- data/lib/assert/result.rb +111 -62
- data/lib/assert/runner.rb +68 -51
- data/lib/assert/stub.rb +4 -4
- data/lib/assert/suite.rb +67 -28
- data/lib/assert/test.rb +40 -35
- data/lib/assert/utils.rb +19 -10
- data/lib/assert/version.rb +1 -1
- data/lib/assert/view.rb +44 -18
- data/lib/assert/view_helpers.rb +100 -92
- data/test/helper.rb +3 -1
- data/test/support/factory.rb +38 -21
- data/test/system/stub_tests.rb +180 -144
- data/test/system/test_tests.rb +86 -60
- data/test/unit/actual_value_tests.rb +69 -50
- data/test/unit/assert_tests.rb +39 -22
- data/test/unit/assertions/assert_block_tests.rb +10 -10
- data/test/unit/assertions/assert_changes_tests.rb +25 -21
- data/test/unit/assertions/assert_empty_tests.rb +14 -12
- data/test/unit/assertions/assert_equal_tests.rb +26 -26
- data/test/unit/assertions/assert_file_exists_tests.rb +15 -13
- data/test/unit/assertions/assert_includes_tests.rb +10 -10
- data/test/unit/assertions/assert_instance_of_tests.rb +14 -14
- data/test/unit/assertions/assert_is_a_tests.rb +128 -0
- data/test/unit/assertions/assert_match_tests.rb +10 -10
- data/test/unit/assertions/assert_nil_tests.rb +16 -12
- data/test/unit/assertions/assert_raises_tests.rb +27 -20
- data/test/unit/assertions/assert_respond_to_tests.rb +10 -10
- data/test/unit/assertions/assert_same_tests.rb +24 -24
- data/test/unit/assertions/assert_true_false_tests.rb +32 -24
- data/test/unit/assertions_tests.rb +14 -9
- data/test/unit/config_helpers_tests.rb +15 -10
- data/test/unit/config_tests.rb +10 -9
- data/test/unit/context/setup_dsl_tests.rb +24 -14
- data/test/unit/context/subject_dsl_tests.rb +3 -3
- data/test/unit/context/suite_dsl_tests.rb +4 -4
- data/test/unit/context/test_dsl_tests.rb +37 -17
- data/test/unit/context_info_tests.rb +4 -4
- data/test/unit/context_tests.rb +110 -54
- data/test/unit/default_suite_tests.rb +10 -6
- data/test/unit/factory_tests.rb +2 -2
- data/test/unit/file_line_tests.rb +7 -7
- data/test/unit/macro_tests.rb +11 -11
- data/test/unit/result_tests.rb +47 -41
- data/test/unit/runner_tests.rb +29 -16
- data/test/unit/suite_tests.rb +37 -15
- data/test/unit/test_tests.rb +63 -50
- data/test/unit/utils_tests.rb +48 -35
- data/test/unit/view_helpers_tests.rb +21 -14
- data/test/unit/view_tests.rb +5 -5
- metadata +26 -11
- data/test/unit/assertions/assert_kind_of_tests.rb +0 -68
data/lib/assert/result.rb
CHANGED
@@ -5,39 +5,44 @@ require "assert/file_line"
|
|
5
5
|
module Assert; end
|
6
6
|
|
7
7
|
module Assert::Result
|
8
|
-
class Base
|
9
|
-
class Pass < Base
|
10
|
-
class Ignore < Base
|
11
|
-
class Fail < Base
|
12
|
-
class Error < Base
|
13
|
-
class Skip < Base
|
8
|
+
class Base; end
|
9
|
+
class Pass < Base; end
|
10
|
+
class Ignore < Base; end
|
11
|
+
class Fail < Base; end
|
12
|
+
class Error < Base; end
|
13
|
+
class Skip < Base; end
|
14
14
|
|
15
15
|
def self.types
|
16
|
-
@types ||= Hash.new{ |
|
16
|
+
@types ||= Hash.new{ |_h, _k| Base }.tap{ |hash|
|
17
17
|
hash[:pass] = Pass
|
18
18
|
hash[:fail] = Fail
|
19
19
|
hash[:ignore] = Ignore
|
20
20
|
hash[:skip] = Skip
|
21
21
|
hash[:error] = Error
|
22
|
-
|
22
|
+
}.freeze
|
23
23
|
end
|
24
24
|
|
25
25
|
def self.new(data = nil)
|
26
26
|
data ||= {}
|
27
|
-
|
27
|
+
types[data[:type]].new(data)
|
28
28
|
end
|
29
29
|
|
30
30
|
class Base
|
31
|
-
def self.type
|
32
|
-
|
31
|
+
def self.type
|
32
|
+
:unknown
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.name
|
36
|
+
""
|
37
|
+
end
|
33
38
|
|
34
39
|
def self.for_test(test, message, bt)
|
35
|
-
|
36
|
-
:
|
37
|
-
:
|
38
|
-
:
|
39
|
-
:
|
40
|
-
:
|
40
|
+
new({
|
41
|
+
test_name: test.name,
|
42
|
+
test_file_line: test.file_line,
|
43
|
+
message: message,
|
44
|
+
output: test.output,
|
45
|
+
backtrace: Backtrace.new(bt),
|
41
46
|
})
|
42
47
|
end
|
43
48
|
|
@@ -59,14 +64,20 @@ module Assert::Result
|
|
59
64
|
end
|
60
65
|
|
61
66
|
def test_file_line
|
62
|
-
@test_file_line ||=
|
67
|
+
@test_file_line ||=
|
68
|
+
(@build_data[:test_file_line] || Assert::FileLine.parse(""))
|
63
69
|
end
|
64
70
|
|
65
|
-
def test_file_name
|
66
|
-
|
71
|
+
def test_file_name
|
72
|
+
test_file_line.file
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_line_num
|
76
|
+
test_file_line.line.to_i
|
77
|
+
end
|
67
78
|
|
68
79
|
def test_id
|
69
|
-
|
80
|
+
test_file_line.to_s
|
70
81
|
end
|
71
82
|
|
72
83
|
def message
|
@@ -108,32 +119,38 @@ module Assert::Result
|
|
108
119
|
end
|
109
120
|
|
110
121
|
def src_line
|
111
|
-
@src_line ||= first_filtered_bt_line(
|
122
|
+
@src_line ||= first_filtered_bt_line(backtrace)
|
112
123
|
end
|
113
124
|
|
114
125
|
def file_line
|
115
|
-
@file_line ||= Assert::FileLine.parse(
|
126
|
+
@file_line ||= Assert::FileLine.parse(src_line)
|
116
127
|
end
|
117
128
|
|
118
|
-
def file_name
|
119
|
-
|
129
|
+
def file_name
|
130
|
+
file_line.file
|
131
|
+
end
|
132
|
+
|
133
|
+
def line_num
|
134
|
+
file_line.line.to_i
|
135
|
+
end
|
120
136
|
|
121
137
|
Assert::Result.types.keys.each do |type|
|
122
138
|
define_method("#{type}?"){ self.type == type }
|
123
139
|
end
|
124
140
|
|
125
|
-
def to_sym
|
141
|
+
def to_sym
|
142
|
+
type
|
143
|
+
end
|
126
144
|
|
127
145
|
def to_s
|
128
|
-
[
|
129
|
-
|
130
|
-
|
131
|
-
].reject(&:empty?).join("\n")
|
146
|
+
["#{name.upcase}: #{test_name}", message, trace]
|
147
|
+
.reject(&:empty?)
|
148
|
+
.join("\n")
|
132
149
|
end
|
133
150
|
|
134
|
-
def ==(
|
135
|
-
if
|
136
|
-
|
151
|
+
def ==(other)
|
152
|
+
if other.is_a?(self.class)
|
153
|
+
type == other.type && message == other.message
|
137
154
|
else
|
138
155
|
super
|
139
156
|
end
|
@@ -141,9 +158,9 @@ module Assert::Result
|
|
141
158
|
|
142
159
|
def inspect
|
143
160
|
"#<#{self.class}:#{"0x0%x" % (object_id << 1)} "\
|
144
|
-
"@message=#{
|
145
|
-
"@file_line=#{
|
146
|
-
"@test_file_line=#{
|
161
|
+
"@message=#{message.inspect} "\
|
162
|
+
"@file_line=#{file_line.to_s.inspect} "\
|
163
|
+
"@test_file_line=#{test_file_line.to_s.inspect}>"
|
147
164
|
end
|
148
165
|
|
149
166
|
private
|
@@ -153,10 +170,10 @@ module Assert::Result
|
|
153
170
|
# filtered line of the backtrace). This is overridden for error results
|
154
171
|
# as they always show their full backtrace.
|
155
172
|
def build_trace
|
156
|
-
if
|
157
|
-
Backtrace.to_s(@with_bt+[first_filtered_bt_line(
|
173
|
+
if with_bt_set?
|
174
|
+
Backtrace.to_s(@with_bt + [first_filtered_bt_line(backtrace)])
|
158
175
|
else
|
159
|
-
|
176
|
+
src_line
|
160
177
|
end
|
161
178
|
end
|
162
179
|
|
@@ -169,13 +186,23 @@ module Assert::Result
|
|
169
186
|
end
|
170
187
|
|
171
188
|
class Pass < Base
|
172
|
-
def self.type
|
173
|
-
|
189
|
+
def self.type
|
190
|
+
:pass
|
191
|
+
end
|
192
|
+
|
193
|
+
def self.name
|
194
|
+
"Pass"
|
195
|
+
end
|
174
196
|
end
|
175
197
|
|
176
198
|
class Ignore < Base
|
177
|
-
def self.type
|
178
|
-
|
199
|
+
def self.type
|
200
|
+
:ignore
|
201
|
+
end
|
202
|
+
|
203
|
+
def self.name
|
204
|
+
"Ignore"
|
205
|
+
end
|
179
206
|
end
|
180
207
|
|
181
208
|
class HaltingTestResultError < RuntimeError
|
@@ -186,17 +213,26 @@ module Assert::Result
|
|
186
213
|
TestFailure = Class.new(HaltingTestResultError)
|
187
214
|
|
188
215
|
class Fail < Base
|
189
|
-
def self.type
|
190
|
-
|
216
|
+
def self.type
|
217
|
+
:fail
|
218
|
+
end
|
219
|
+
|
220
|
+
def self.name
|
221
|
+
"Fail"
|
222
|
+
end
|
191
223
|
|
192
|
-
# fail results can be generated manually or by raising
|
224
|
+
# fail results can be generated manually or by raising
|
225
|
+
# Assert::Result::TestFailure
|
193
226
|
def self.for_test(test, msg_or_err, bt = nil)
|
194
|
-
if msg_or_err.
|
227
|
+
if msg_or_err.is_a?(TestFailure)
|
195
228
|
super(test, msg_or_err.message, msg_or_err.backtrace).tap do |result|
|
196
229
|
result.set_with_bt(msg_or_err.assert_with_bt)
|
197
230
|
end
|
198
|
-
elsif msg_or_err.
|
199
|
-
raise
|
231
|
+
elsif msg_or_err.is_a?(Exception)
|
232
|
+
raise(
|
233
|
+
ArgumentError,
|
234
|
+
"generate fail results by raising Assert::Result::TestFailure",
|
235
|
+
)
|
200
236
|
else
|
201
237
|
super(test, msg_or_err, bt)
|
202
238
|
end
|
@@ -207,17 +243,25 @@ module Assert::Result
|
|
207
243
|
TestSkipped = Class.new(HaltingTestResultError)
|
208
244
|
|
209
245
|
class Skip < Base
|
210
|
-
def self.type
|
211
|
-
|
246
|
+
def self.type
|
247
|
+
:skip
|
248
|
+
end
|
249
|
+
|
250
|
+
def self.name
|
251
|
+
"Skip"
|
252
|
+
end
|
212
253
|
|
213
254
|
# skip results are generated by raising Assert::Result::TestSkipped
|
214
255
|
def self.for_test(test, msg_or_err, bt = nil)
|
215
|
-
if msg_or_err.
|
256
|
+
if msg_or_err.is_a?(TestSkipped)
|
216
257
|
super(test, msg_or_err.message, msg_or_err.backtrace).tap do |result|
|
217
258
|
result.set_with_bt(msg_or_err.assert_with_bt)
|
218
259
|
end
|
219
|
-
elsif msg_or_err.
|
220
|
-
raise
|
260
|
+
elsif msg_or_err.is_a?(Exception)
|
261
|
+
raise(
|
262
|
+
ArgumentError,
|
263
|
+
"generate skip results by raising Assert::Result::TestSkipped",
|
264
|
+
)
|
221
265
|
else
|
222
266
|
super(test, msg_or_err, bt)
|
223
267
|
end
|
@@ -225,12 +269,17 @@ module Assert::Result
|
|
225
269
|
end
|
226
270
|
|
227
271
|
class Error < Base
|
228
|
-
def self.type
|
229
|
-
|
272
|
+
def self.type
|
273
|
+
:error
|
274
|
+
end
|
275
|
+
|
276
|
+
def self.name
|
277
|
+
"Error"
|
278
|
+
end
|
230
279
|
|
231
280
|
# error results are generated by raising exceptions in tests
|
232
281
|
def self.for_test(test, err)
|
233
|
-
if err.
|
282
|
+
if err.is_a?(Exception)
|
234
283
|
super(test, "#{err.message} (#{err.class.name})", err.backtrace)
|
235
284
|
else
|
236
285
|
raise ArgumentError, "generate error results by raising an exception"
|
@@ -246,10 +295,10 @@ module Assert::Result
|
|
246
295
|
end
|
247
296
|
|
248
297
|
class Backtrace < ::Array
|
249
|
-
DELIM = "\n"
|
298
|
+
DELIM = "\n"
|
250
299
|
|
251
300
|
def self.parse(bt)
|
252
|
-
|
301
|
+
new(bt.to_s.split(DELIM))
|
253
302
|
end
|
254
303
|
|
255
304
|
def self.to_s(bt_array)
|
@@ -261,7 +310,7 @@ module Assert::Result
|
|
261
310
|
end
|
262
311
|
|
263
312
|
def filtered
|
264
|
-
self.class.new(
|
313
|
+
self.class.new(reject{ |line| filter_out?(line.to_s) })
|
265
314
|
end
|
266
315
|
|
267
316
|
protected
|
@@ -271,8 +320,8 @@ module Assert::Result
|
|
271
320
|
# "./lib" in project dir, or "/usr/local/blahblah" if installed
|
272
321
|
assert_lib_path = File.expand_path("../..", __FILE__)
|
273
322
|
assert_macros_path = File.join(assert_lib_path, "assert/macros")
|
274
|
-
assert_bin_regex = /
|
275
|
-
(
|
323
|
+
assert_bin_regex = %r{bin/assert\:}
|
324
|
+
(line.rindex(assert_lib_path, 0) &&
|
276
325
|
!line.rindex(assert_macros_path, 0)
|
277
326
|
) ||
|
278
327
|
line =~ assert_bin_regex
|
data/lib/assert/runner.rb
CHANGED
@@ -14,21 +14,21 @@ module Assert
|
|
14
14
|
@config = config
|
15
15
|
end
|
16
16
|
|
17
|
-
def runner
|
17
|
+
def runner
|
18
|
+
self
|
19
|
+
end
|
18
20
|
|
19
21
|
def run
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
if
|
25
|
-
|
26
|
-
elsif
|
27
|
-
|
28
|
-
end
|
29
|
-
if self.tests_to_run?
|
30
|
-
self.view.puts ", seeded with \"#{self.runner_seed}\""
|
22
|
+
on_start
|
23
|
+
suite.on_start
|
24
|
+
view.on_start
|
25
|
+
|
26
|
+
if single_test?
|
27
|
+
view.print "Running test: #{single_test_file_line}"
|
28
|
+
elsif tests_to_run?
|
29
|
+
view.print "Running tests in random order"
|
31
30
|
end
|
31
|
+
view.puts ", seeded with \"#{runner_seed}\"" if tests_to_run?
|
32
32
|
|
33
33
|
@current_running_test = nil
|
34
34
|
|
@@ -36,46 +36,46 @@ module Assert
|
|
36
36
|
# (Ctrl+T on Macs), process it
|
37
37
|
if Signal.list.keys.include?("INFO")
|
38
38
|
Signal.trap("INFO") do
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
on_info(@current_running_test)
|
40
|
+
suite.on_info(@current_running_test)
|
41
|
+
view.on_info(@current_running_test)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
45
|
begin
|
46
|
-
|
47
|
-
|
48
|
-
tests_to_run.tap{
|
46
|
+
suite.start_time = Time.now
|
47
|
+
suite.setups.each(&:call)
|
48
|
+
tests_to_run.tap{ suite.clear_tests_to_run }.delete_if do |test|
|
49
49
|
@current_running_test = test
|
50
50
|
|
51
|
-
|
52
|
-
|
53
|
-
|
51
|
+
before_test(test)
|
52
|
+
suite.before_test(test)
|
53
|
+
view.before_test(test)
|
54
54
|
test.run do |result|
|
55
|
-
|
56
|
-
|
57
|
-
|
55
|
+
on_result(result)
|
56
|
+
suite.on_result(result)
|
57
|
+
view.on_result(result)
|
58
58
|
end
|
59
|
-
|
60
|
-
|
61
|
-
|
59
|
+
after_test(test)
|
60
|
+
suite.after_test(test)
|
61
|
+
view.after_test(test)
|
62
62
|
|
63
63
|
# always delete `test` from `tests_to_run` since it has been run
|
64
64
|
true
|
65
65
|
end
|
66
|
-
|
67
|
-
|
68
|
-
rescue Interrupt =>
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
raise(
|
66
|
+
suite.teardowns.each(&:call)
|
67
|
+
suite.end_time = Time.now
|
68
|
+
rescue Interrupt => ex
|
69
|
+
on_interrupt(ex)
|
70
|
+
suite.on_interrupt(ex)
|
71
|
+
view.on_interrupt(ex)
|
72
|
+
raise(ex)
|
73
73
|
end
|
74
74
|
|
75
|
-
(
|
76
|
-
|
77
|
-
|
78
|
-
|
75
|
+
(fail_result_count + error_result_count).tap do
|
76
|
+
view.on_finish
|
77
|
+
suite.on_finish
|
78
|
+
on_finish
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
@@ -84,24 +84,41 @@ module Assert
|
|
84
84
|
# define callback handlers to do special behavior during the test run. These
|
85
85
|
# will be called by the test runner
|
86
86
|
|
87
|
-
def before_load(test_files)
|
88
|
-
|
89
|
-
|
90
|
-
def
|
91
|
-
|
92
|
-
|
93
|
-
def
|
94
|
-
|
95
|
-
|
87
|
+
def before_load(test_files)
|
88
|
+
end
|
89
|
+
|
90
|
+
def after_load
|
91
|
+
end
|
92
|
+
|
93
|
+
def on_start
|
94
|
+
end
|
95
|
+
|
96
|
+
def before_test(test)
|
97
|
+
end
|
98
|
+
|
99
|
+
def on_result(result)
|
100
|
+
end
|
101
|
+
|
102
|
+
def after_test(test)
|
103
|
+
end
|
104
|
+
|
105
|
+
def on_finish
|
106
|
+
end
|
107
|
+
|
108
|
+
def on_info(test)
|
109
|
+
end
|
110
|
+
|
111
|
+
def on_interrupt(err)
|
112
|
+
end
|
96
113
|
|
97
114
|
private
|
98
115
|
|
99
116
|
def tests_to_run
|
100
|
-
srand
|
101
|
-
if
|
102
|
-
[
|
117
|
+
srand runner_seed
|
118
|
+
if single_test?
|
119
|
+
[suite.find_test_to_run(single_test_file_line)].compact
|
103
120
|
else
|
104
|
-
|
121
|
+
suite.sorted_tests_to_run{ rand tests_to_run_count }
|
105
122
|
end
|
106
123
|
end
|
107
124
|
end
|