assert 2.16.3 → 2.16.4
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/README.md +1 -0
- data/lib/assert.rb +9 -0
- data/lib/assert/context.rb +42 -15
- data/lib/assert/context/test_dsl.rb +6 -6
- data/lib/assert/context_info.rb +1 -1
- data/lib/assert/default_view.rb +9 -0
- data/lib/assert/macros/methods.rb +14 -14
- data/lib/assert/result.rb +83 -38
- data/lib/assert/runner.rb +11 -0
- data/lib/assert/stub.rb +12 -16
- data/lib/assert/suite.rb +1 -0
- data/lib/assert/version.rb +1 -1
- data/lib/assert/view.rb +3 -1
- data/test/unit/assert_tests.rb +3 -1
- data/test/unit/context_tests.rb +117 -19
- data/test/unit/result_tests.rb +112 -37
- data/test/unit/runner_tests.rb +1 -1
- data/test/unit/stub_tests.rb +14 -4
- data/test/unit/suite_tests.rb +1 -1
- data/test/unit/view_tests.rb +1 -1
- metadata +3 -3
data/lib/assert/runner.rb
CHANGED
@@ -29,10 +29,20 @@ module Assert
|
|
29
29
|
self.view.puts ", seeded with \"#{self.runner_seed}\""
|
30
30
|
end
|
31
31
|
|
32
|
+
# if INFO signal requested (Ctrl+T on Macs), process it
|
33
|
+
@current_running_test = nil
|
34
|
+
trap("INFO") do
|
35
|
+
self.on_info(@current_running_test)
|
36
|
+
self.suite.on_info(@current_running_test)
|
37
|
+
self.view.on_info(@current_running_test)
|
38
|
+
end
|
39
|
+
|
32
40
|
begin
|
33
41
|
self.suite.start_time = Time.now
|
34
42
|
self.suite.setups.each(&:call)
|
35
43
|
tests_to_run.tap{ self.suite.clear_tests_to_run }.delete_if do |test|
|
44
|
+
@current_running_test = test
|
45
|
+
|
36
46
|
self.before_test(test)
|
37
47
|
self.suite.before_test(test)
|
38
48
|
self.view.before_test(test)
|
@@ -76,6 +86,7 @@ module Assert
|
|
76
86
|
def on_result(result); end
|
77
87
|
def after_test(test); end
|
78
88
|
def on_finish; end
|
89
|
+
def on_info(test); end
|
79
90
|
def on_interrupt(err); end
|
80
91
|
|
81
92
|
private
|
data/lib/assert/stub.rb
CHANGED
@@ -6,8 +6,7 @@ module Assert
|
|
6
6
|
|
7
7
|
def self.stub(obj, meth, &block)
|
8
8
|
(self.stubs[Assert::Stub.key(obj, meth)] ||= begin
|
9
|
-
|
10
|
-
Assert::Stub.new(obj, meth, orig_caller)
|
9
|
+
Assert::Stub.new(obj, meth, caller_locations)
|
11
10
|
end).tap{ |s| s.do = block }
|
12
11
|
end
|
13
12
|
|
@@ -20,10 +19,9 @@ module Assert
|
|
20
19
|
end
|
21
20
|
|
22
21
|
def self.stub_send(obj, meth, *args, &block)
|
23
|
-
orig_caller =
|
22
|
+
orig_caller = caller_locations
|
24
23
|
stub = self.stubs.fetch(Assert::Stub.key(obj, meth)) do
|
25
|
-
|
26
|
-
raise NotStubbedError.new(msg).tap{ |e| e.set_backtrace(orig_caller) }
|
24
|
+
raise NotStubbedError, "`#{meth}` not stubbed.", orig_caller.map(&:to_s)
|
27
25
|
end
|
28
26
|
stub.call_method(args, &block)
|
29
27
|
end
|
@@ -45,7 +43,7 @@ module Assert
|
|
45
43
|
attr_reader :method_name, :name, :ivar_name, :do
|
46
44
|
|
47
45
|
def initialize(object, method_name, orig_caller = nil, &block)
|
48
|
-
orig_caller ||=
|
46
|
+
orig_caller ||= caller_locations
|
49
47
|
@metaclass = class << object; self; end
|
50
48
|
@method_name = method_name.to_s
|
51
49
|
@name = "__assert_stub__#{object.object_id}_#{@method_name}"
|
@@ -67,12 +65,12 @@ module Assert
|
|
67
65
|
end
|
68
66
|
|
69
67
|
def call(args, orig_caller = nil, &block)
|
70
|
-
orig_caller ||=
|
68
|
+
orig_caller ||= caller_locations
|
71
69
|
unless arity_matches?(args)
|
72
70
|
msg = "arity mismatch on `#{@method_name}`: " \
|
73
71
|
"expected #{number_of_args(@method.arity)}, " \
|
74
72
|
"called with #{args.size}"
|
75
|
-
raise StubArityError
|
73
|
+
raise StubArityError, msg, orig_caller.map(&:to_s)
|
76
74
|
end
|
77
75
|
lookup(args, orig_caller).call(*args, &block)
|
78
76
|
rescue NotStubbedError => exception
|
@@ -81,12 +79,12 @@ module Assert
|
|
81
79
|
end
|
82
80
|
|
83
81
|
def with(*args, &block)
|
84
|
-
orig_caller =
|
82
|
+
orig_caller = caller_locations
|
85
83
|
unless arity_matches?(args)
|
86
84
|
msg = "arity mismatch on `#{@method_name}`: " \
|
87
85
|
"expected #{number_of_args(@method.arity)}, " \
|
88
86
|
"stubbed with #{args.size}"
|
89
|
-
raise StubArityError
|
87
|
+
raise StubArityError, msg, orig_caller.map(&:to_s)
|
90
88
|
end
|
91
89
|
@lookup[args] = block
|
92
90
|
end
|
@@ -104,12 +102,12 @@ module Assert
|
|
104
102
|
">"
|
105
103
|
end
|
106
104
|
|
107
|
-
|
105
|
+
private
|
108
106
|
|
109
107
|
def setup(object, orig_caller)
|
110
108
|
unless object.respond_to?(@method_name)
|
111
109
|
msg = "#{object.inspect} does not respond to `#{@method_name}`"
|
112
|
-
raise StubError
|
110
|
+
raise StubError, msg, orig_caller.map(&:to_s)
|
113
111
|
end
|
114
112
|
is_constant = object.kind_of?(Module)
|
115
113
|
local_object_methods = object.methods(false).map(&:to_s)
|
@@ -130,13 +128,11 @@ module Assert
|
|
130
128
|
Assert.instance_variable_set(@ivar_name, self)
|
131
129
|
@metaclass.class_eval <<-stub_method
|
132
130
|
def #{@method_name}(*args, &block)
|
133
|
-
Assert.instance_variable_get("#{@ivar_name}").call(args,
|
131
|
+
Assert.instance_variable_get("#{@ivar_name}").call(args, caller_locations, &block)
|
134
132
|
end
|
135
133
|
stub_method
|
136
134
|
end
|
137
135
|
|
138
|
-
private
|
139
|
-
|
140
136
|
def lookup(args, orig_caller)
|
141
137
|
@lookup.fetch(args) do
|
142
138
|
self.do || begin
|
@@ -144,7 +140,7 @@ module Assert
|
|
144
140
|
inspect_lookup_stubs.tap do |stubs|
|
145
141
|
msg += "\nStubs:\n#{stubs}" if !stubs.empty?
|
146
142
|
end
|
147
|
-
raise NotStubbedError
|
143
|
+
raise NotStubbedError, msg, orig_caller.map(&:to_s)
|
148
144
|
end
|
149
145
|
end
|
150
146
|
end
|
data/lib/assert/suite.rb
CHANGED
data/lib/assert/version.rb
CHANGED
data/lib/assert/view.rb
CHANGED
@@ -74,9 +74,10 @@ module Assert
|
|
74
74
|
# * `after_test`: called after a test finishes running
|
75
75
|
# the test is passed as an arg
|
76
76
|
# * `on_finish`: called when the test suite is finished running
|
77
|
+
# * `on_info`: called when the INFO signal is triggered whil runninng
|
78
|
+
# the test suite
|
77
79
|
# * `on_interrupt`: called when the test suite is interrupted while running
|
78
80
|
# the interrupt exception is passed as an arg
|
79
|
-
|
80
81
|
def before_load(test_files); end
|
81
82
|
def after_load; end
|
82
83
|
def on_start; end
|
@@ -84,6 +85,7 @@ module Assert
|
|
84
85
|
def on_result(result); end
|
85
86
|
def after_test(test); end
|
86
87
|
def on_finish; end
|
88
|
+
def on_info(test); end
|
87
89
|
def on_interrupt(err); end
|
88
90
|
|
89
91
|
# IO capture
|
data/test/unit/assert_tests.rb
CHANGED
@@ -96,7 +96,9 @@ module Assert
|
|
96
96
|
end
|
97
97
|
|
98
98
|
should "be able to call a stub's original method" do
|
99
|
-
assert_raises(NotStubbedError){ Assert.stub_send(@myobj, :mymeth) }
|
99
|
+
err = assert_raises(NotStubbedError){ Assert.stub_send(@myobj, :mymeth) }
|
100
|
+
assert_includes 'not stubbed.', err.message
|
101
|
+
assert_includes 'test/unit/assert_tests.rb', err.backtrace.first
|
100
102
|
|
101
103
|
Assert.stub(@myobj, :mymeth){ @stub_value }
|
102
104
|
|
data/test/unit/context_tests.rb
CHANGED
@@ -2,6 +2,7 @@ require 'assert'
|
|
2
2
|
require 'assert/context'
|
3
3
|
|
4
4
|
require 'assert/config'
|
5
|
+
require 'assert/result'
|
5
6
|
require 'assert/utils'
|
6
7
|
|
7
8
|
class Assert::Context
|
@@ -32,14 +33,36 @@ class Assert::Context
|
|
32
33
|
should have_cmeths :should, :should_eventually, :should_skip
|
33
34
|
|
34
35
|
should have_imeths :assert, :assert_not, :refute
|
35
|
-
should have_imeths :
|
36
|
-
should have_imeths :with_backtrace, :subject
|
36
|
+
should have_imeths :pass, :ignore, :fail, :flunk, :skip
|
37
|
+
should have_imeths :pending, :with_backtrace, :subject
|
37
38
|
|
38
|
-
|
39
|
+
should "collect context info" do
|
39
40
|
test = @__assert_running_test__
|
40
41
|
assert_match /test\/unit\/context_tests.rb$/, test.context_info.file
|
41
42
|
assert_equal self.class, test.context_info.klass
|
42
43
|
end
|
44
|
+
private
|
45
|
+
|
46
|
+
ASSERT_TEST_PATH_REGEX = /\A#{File.join(ROOT_PATH, 'test', '')}/
|
47
|
+
|
48
|
+
def assert_with_bt_set(exp_with_bt, result)
|
49
|
+
with_backtrace(caller) do
|
50
|
+
assert_true result.with_bt_set?
|
51
|
+
|
52
|
+
exp = Assert::Result::Backtrace.to_s(exp_with_bt+[(result.backtrace.filtered.first)])
|
53
|
+
assert_equal exp, result.trace
|
54
|
+
assert_equal exp_with_bt.first, result.src_line
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def assert_not_with_bt_set(result)
|
59
|
+
with_backtrace(caller) do
|
60
|
+
assert_false result.with_bt_set?
|
61
|
+
|
62
|
+
assert_equal result.src_line, result.trace
|
63
|
+
assert_equal result.backtrace.filtered.first.to_s, result.src_line
|
64
|
+
end
|
65
|
+
end
|
43
66
|
|
44
67
|
end
|
45
68
|
|
@@ -47,7 +70,7 @@ class Assert::Context
|
|
47
70
|
desc "skip method"
|
48
71
|
setup do
|
49
72
|
@skip_msg = "I need to implement this in the future."
|
50
|
-
begin; @context.skip(@skip_msg); rescue
|
73
|
+
begin; @context.skip(@skip_msg); rescue StandardError => @exception; end
|
51
74
|
@result = Factory.skip_result(@exception)
|
52
75
|
end
|
53
76
|
subject{ @result }
|
@@ -66,7 +89,7 @@ class Assert::Context
|
|
66
89
|
assert_not_equal 1, @exception.backtrace.size
|
67
90
|
|
68
91
|
called_from = Factory.string
|
69
|
-
begin; @context.skip(@skip_msg, called_from); rescue
|
92
|
+
begin; @context.skip(@skip_msg, called_from); rescue StandardError => exception; end
|
70
93
|
assert_equal 1, exception.backtrace.size
|
71
94
|
assert_equal called_from, exception.backtrace.first
|
72
95
|
end
|
@@ -139,7 +162,7 @@ class Assert::Context
|
|
139
162
|
|
140
163
|
should "create a fail result and set its backtrace" do
|
141
164
|
assert_kind_of Assert::Result::Fail, subject
|
142
|
-
assert_equal subject.backtrace.filtered.first, subject.trace
|
165
|
+
assert_equal subject.backtrace.filtered.first.to_s, subject.trace
|
143
166
|
assert_kind_of Array, subject.backtrace
|
144
167
|
end
|
145
168
|
|
@@ -165,11 +188,7 @@ class Assert::Context
|
|
165
188
|
subject{ @result }
|
166
189
|
|
167
190
|
should "raise an exception with the failure's message" do
|
168
|
-
err
|
169
|
-
@context.fail @fail_msg
|
170
|
-
rescue Exception => exception
|
171
|
-
exception
|
172
|
-
end
|
191
|
+
begin; @context.fail(@fail_msg); rescue StandardError => err; end
|
173
192
|
assert_kind_of Assert::Result::TestFailure, err
|
174
193
|
assert_equal @fail_msg, err.message
|
175
194
|
|
@@ -275,14 +294,59 @@ class Assert::Context
|
|
275
294
|
|
276
295
|
end
|
277
296
|
|
297
|
+
class PendingTests < UnitTests
|
298
|
+
desc "`pending` method"
|
299
|
+
setup do
|
300
|
+
block2 = proc { fail; pass; }
|
301
|
+
@block1 = proc { pending(&block2) } # test nesting
|
302
|
+
end
|
303
|
+
|
304
|
+
should "make fails skips and make passes fails" do
|
305
|
+
@context.fail 'not affected'
|
306
|
+
@context.pass
|
307
|
+
@context.pending(&@block1)
|
308
|
+
|
309
|
+
assert_equal 4, @test_results.size
|
310
|
+
norm_fail, norm_pass, pending_fail, pending_pass = @test_results
|
311
|
+
|
312
|
+
assert_kind_of Assert::Result::Fail, norm_fail
|
313
|
+
assert_kind_of Assert::Result::Pass, norm_pass
|
314
|
+
|
315
|
+
assert_kind_of Assert::Result::Skip, pending_fail
|
316
|
+
assert_includes "Pending fail", pending_fail.message
|
317
|
+
|
318
|
+
assert_kind_of Assert::Result::Fail, pending_pass
|
319
|
+
assert_includes "Pending pass", pending_pass.message
|
320
|
+
end
|
321
|
+
|
322
|
+
end
|
323
|
+
|
324
|
+
class PendingWithHaltOnFailTests < PendingTests
|
325
|
+
desc "when halting on fails"
|
326
|
+
setup do
|
327
|
+
@halt_config = Assert::Config.new(:halt_on_fail => true)
|
328
|
+
@context = @context_class.new(@test, @halt_config, @result_callback)
|
329
|
+
end
|
330
|
+
subject{ @result }
|
331
|
+
|
332
|
+
should "make fails skips and stop the test" do
|
333
|
+
begin; @context.pending(&@block1); rescue StandardError => err; end
|
334
|
+
assert_kind_of Assert::Result::TestSkipped, err
|
335
|
+
assert_includes "Pending fail", err.message
|
336
|
+
|
337
|
+
assert_equal 0, @test_results.size # it halted before the pending pass
|
338
|
+
end
|
339
|
+
|
340
|
+
end
|
341
|
+
|
278
342
|
class WithBacktraceTests < UnitTests
|
279
|
-
desc "with_backtrace method"
|
343
|
+
desc "`with_backtrace` method"
|
280
344
|
setup do
|
281
|
-
@from_bt
|
345
|
+
@from_bt = ['called_from_here', Factory.string]
|
282
346
|
@from_block = proc { ignore; fail; pass; skip 'todo'; }
|
283
347
|
end
|
284
348
|
|
285
|
-
should "
|
349
|
+
should "alter non-error block results' bt with given bt's first line" do
|
286
350
|
@context.fail 'not affected'
|
287
351
|
begin
|
288
352
|
@context.with_backtrace(@from_bt, &@from_block)
|
@@ -293,11 +357,45 @@ class Assert::Context
|
|
293
357
|
assert_equal 5, @test_results.size
|
294
358
|
norm_fail, with_ignore, with_fail, with_pass, with_skip = @test_results
|
295
359
|
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
360
|
+
assert_not_with_bt_set norm_fail
|
361
|
+
|
362
|
+
exp = [@from_bt.first]
|
363
|
+
assert_with_bt_set exp, with_ignore
|
364
|
+
assert_with_bt_set exp, with_fail
|
365
|
+
assert_with_bt_set exp, with_pass
|
366
|
+
assert_with_bt_set exp, with_ignore
|
367
|
+
end
|
368
|
+
|
369
|
+
end
|
370
|
+
|
371
|
+
class WithNestedBacktraceTests < UnitTests
|
372
|
+
desc "`with_backtrace` method nested"
|
373
|
+
setup do
|
374
|
+
@from_bt1 = ['called_from_here 1', Factory.string]
|
375
|
+
@from_bt2 = from_bt2 = ['called_from_here 2', Factory.string]
|
376
|
+
|
377
|
+
from_block2 = proc { ignore; fail; pass; skip 'todo'; }
|
378
|
+
@from_block1 = proc { with_backtrace(from_bt2, &from_block2) }
|
379
|
+
end
|
380
|
+
|
381
|
+
should "alter non-error block results' bt with nested wbt accrued first lines" do
|
382
|
+
@context.fail 'not affected'
|
383
|
+
begin
|
384
|
+
@context.with_backtrace(@from_bt1, &@from_block1)
|
385
|
+
rescue Assert::Result::TestSkipped => e
|
386
|
+
@test_results << Assert::Result::Skip.for_test(@test, e)
|
387
|
+
end
|
388
|
+
|
389
|
+
assert_equal 5, @test_results.size
|
390
|
+
norm_fail, with_ignore, with_fail, with_pass, with_skip = @test_results
|
391
|
+
|
392
|
+
assert_not_with_bt_set norm_fail
|
393
|
+
|
394
|
+
exp = [@from_bt1.first, @from_bt2.first]
|
395
|
+
assert_with_bt_set exp, with_ignore
|
396
|
+
assert_with_bt_set exp, with_fail
|
397
|
+
assert_with_bt_set exp, with_pass
|
398
|
+
assert_with_bt_set exp, with_ignore
|
301
399
|
end
|
302
400
|
|
303
401
|
end
|
data/test/unit/result_tests.rb
CHANGED
@@ -28,12 +28,18 @@ module Assert::Result
|
|
28
28
|
end
|
29
29
|
|
30
30
|
should "create results from data hashes" do
|
31
|
-
type
|
32
|
-
exp
|
33
|
-
|
31
|
+
type = Assert::Result.types.keys.sample
|
32
|
+
exp = Assert::Result.types[type].new(:type => type)
|
34
33
|
assert_equal exp, Assert::Result.new(:type => type)
|
35
34
|
end
|
36
35
|
|
36
|
+
private
|
37
|
+
|
38
|
+
def build_backtrace
|
39
|
+
assert_lib_path = File.join(ROOT_PATH, "lib/#{Factory.string}:#{Factory.integer}")
|
40
|
+
(Factory.integer(3).times.map{ Factory.string } + [assert_lib_path]).shuffle
|
41
|
+
end
|
42
|
+
|
37
43
|
end
|
38
44
|
|
39
45
|
class BaseTests < UnitTests
|
@@ -46,8 +52,7 @@ module Assert::Result
|
|
46
52
|
:test_file_line => Assert::FileLine.new(Factory.string, Factory.integer),
|
47
53
|
:message => Factory.string,
|
48
54
|
:output => Factory.text,
|
49
|
-
:backtrace => Backtrace.new(
|
50
|
-
:trace => Factory.string
|
55
|
+
:backtrace => Backtrace.new(build_backtrace)
|
51
56
|
}
|
52
57
|
@result = Base.new(@given_data)
|
53
58
|
end
|
@@ -56,10 +61,12 @@ module Assert::Result
|
|
56
61
|
should have_cmeths :type, :name, :for_test
|
57
62
|
should have_imeths :type, :name, :test_name, :test_file_line
|
58
63
|
should have_imeths :test_file_name, :test_line_num, :test_id
|
59
|
-
should have_imeths :message, :output
|
60
|
-
should have_imeths :
|
64
|
+
should have_imeths :message, :output
|
65
|
+
should have_imeths :backtrace, :trace
|
66
|
+
should have_imeths :set_backtrace, :set_with_bt, :with_bt_set?
|
67
|
+
should have_imeths :src_line, :file_line, :file_name, :line_num
|
61
68
|
should have_imeths *Assert::Result.types.keys.map{ |k| "#{k}?" }
|
62
|
-
should have_imeths :
|
69
|
+
should have_imeths :to_sym, :to_s
|
63
70
|
|
64
71
|
should "know its class-level type/name" do
|
65
72
|
assert_equal :unknown, subject.class.type
|
@@ -80,6 +87,8 @@ module Assert::Result
|
|
80
87
|
assert_equal message, result.message
|
81
88
|
assert_equal exp_backtrace, result.backtrace
|
82
89
|
assert_equal exp_trace, result.trace
|
90
|
+
|
91
|
+
assert_false result.with_bt_set?
|
83
92
|
end
|
84
93
|
|
85
94
|
should "use any given attrs" do
|
@@ -90,7 +99,6 @@ module Assert::Result
|
|
90
99
|
assert_equal @given_data[:message], subject.message
|
91
100
|
assert_equal @given_data[:output], subject.output
|
92
101
|
assert_equal @given_data[:backtrace], subject.backtrace
|
93
|
-
assert_equal @given_data[:trace], subject.trace
|
94
102
|
end
|
95
103
|
|
96
104
|
should "default its attrs" do
|
@@ -114,7 +122,7 @@ module Assert::Result
|
|
114
122
|
end
|
115
123
|
|
116
124
|
should "allow setting a new backtrace" do
|
117
|
-
new_bt =
|
125
|
+
new_bt = build_backtrace
|
118
126
|
exp_backtrace = Backtrace.new(new_bt)
|
119
127
|
exp_trace = exp_backtrace.filtered.first.to_s
|
120
128
|
subject.set_backtrace(new_bt)
|
@@ -123,7 +131,7 @@ module Assert::Result
|
|
123
131
|
|
124
132
|
# test that the first bt line is used if filtered is empty
|
125
133
|
assert_lib_path = File.join(ROOT_PATH, "lib/#{Factory.string}:#{Factory.integer}")
|
126
|
-
new_bt = Factory.integer(3).times.map{ assert_lib_path }
|
134
|
+
new_bt = (Factory.integer(3)+1).times.map{ assert_lib_path }
|
127
135
|
exp_backtrace = Backtrace.new(new_bt)
|
128
136
|
exp_trace = exp_backtrace.first.to_s
|
129
137
|
subject.set_backtrace(new_bt)
|
@@ -131,19 +139,52 @@ module Assert::Result
|
|
131
139
|
assert_equal exp_trace, subject.trace
|
132
140
|
end
|
133
141
|
|
134
|
-
should "know
|
135
|
-
|
142
|
+
should "allow setting a with bt backtrace and know if one has been set" do
|
143
|
+
assert_false subject.with_bt_set?
|
144
|
+
|
145
|
+
orig_backtrace = subject.backtrace
|
146
|
+
with_bt = build_backtrace
|
147
|
+
|
148
|
+
subject.set_with_bt(with_bt)
|
149
|
+
|
150
|
+
assert_true subject.with_bt_set?
|
151
|
+
assert_equal orig_backtrace, subject.backtrace
|
152
|
+
assert_equal with_bt.first, subject.src_line
|
153
|
+
|
154
|
+
exp = Backtrace.to_s(with_bt + [orig_backtrace.filtered.first])
|
155
|
+
assert_equal exp, subject.trace
|
156
|
+
end
|
157
|
+
|
158
|
+
should "know its src/file line attrs" do
|
159
|
+
new_bt = build_backtrace
|
136
160
|
subject.set_backtrace(new_bt)
|
137
|
-
|
161
|
+
|
162
|
+
exp = Backtrace.new(new_bt).filtered.first.to_s
|
163
|
+
assert_equal exp, subject.src_line
|
164
|
+
|
165
|
+
exp = Assert::FileLine.parse(subject.src_line)
|
166
|
+
assert_equal exp, subject.file_line
|
167
|
+
assert_equal exp.file, subject.file_name
|
168
|
+
assert_equal exp.line.to_i, subject.line_num
|
169
|
+
|
170
|
+
# test you get the same file line attrs using `set_with_bt`
|
171
|
+
subject.set_with_bt(new_bt)
|
172
|
+
assert_equal new_bt.first.to_s, subject.src_line
|
173
|
+
|
174
|
+
exp = Assert::FileLine.parse(subject.src_line)
|
138
175
|
assert_equal exp, subject.file_line
|
139
176
|
assert_equal exp.file, subject.file_name
|
140
177
|
assert_equal exp.line.to_i, subject.line_num
|
141
178
|
|
142
179
|
# test that the first bt line is used if filtered is empty
|
143
180
|
assert_lib_path = File.join(ROOT_PATH, "lib/#{Factory.string}:#{Factory.integer}")
|
144
|
-
new_bt
|
181
|
+
new_bt = (Factory.integer(3)+1).times.map{ assert_lib_path }
|
145
182
|
subject.set_backtrace(new_bt)
|
146
|
-
|
183
|
+
|
184
|
+
exp = new_bt.first.to_s
|
185
|
+
assert_equal exp, subject.src_line
|
186
|
+
|
187
|
+
exp = Assert::FileLine.parse(subject.src_line)
|
147
188
|
assert_equal exp, subject.file_line
|
148
189
|
assert_equal exp.file, subject.file_name
|
149
190
|
assert_equal exp.line.to_i, subject.line_num
|
@@ -225,12 +266,24 @@ module Assert::Result
|
|
225
266
|
|
226
267
|
end
|
227
268
|
|
269
|
+
class HaltingTestResultErrorTests < UnitTests
|
270
|
+
desc "HaltingTestResultError"
|
271
|
+
subject{ HaltingTestResultError.new }
|
272
|
+
|
273
|
+
should have_accessors :assert_with_bt
|
274
|
+
|
275
|
+
should "be a runtime error" do
|
276
|
+
assert_kind_of RuntimeError, subject
|
277
|
+
end
|
278
|
+
|
279
|
+
end
|
280
|
+
|
228
281
|
class TestFailureTests < UnitTests
|
229
282
|
desc "TestFailure"
|
230
283
|
subject{ TestFailure }
|
231
284
|
|
232
|
-
should "be a
|
233
|
-
assert_kind_of
|
285
|
+
should "be a halting test result error" do
|
286
|
+
assert_kind_of HaltingTestResultError, subject.new
|
234
287
|
end
|
235
288
|
|
236
289
|
end
|
@@ -250,13 +303,24 @@ module Assert::Result
|
|
250
303
|
|
251
304
|
should "allow creating for a test with TestFailure exceptions" do
|
252
305
|
err = TestFailure.new
|
253
|
-
err.set_backtrace(
|
306
|
+
err.set_backtrace(build_backtrace)
|
254
307
|
result = Fail.for_test(@test, err)
|
255
308
|
|
256
309
|
assert_equal err.message, result.message
|
257
310
|
|
258
|
-
|
259
|
-
assert_equal
|
311
|
+
err_backtrace = Backtrace.new(err.backtrace)
|
312
|
+
assert_equal err_backtrace, result.backtrace
|
313
|
+
|
314
|
+
# test assert with bt errors
|
315
|
+
err.assert_with_bt = build_backtrace
|
316
|
+
result = Fail.for_test(@test, err)
|
317
|
+
|
318
|
+
assert_equal err.message, result.message
|
319
|
+
assert_equal err.backtrace, result.backtrace
|
320
|
+
assert_equal err.assert_with_bt.first, result.src_line
|
321
|
+
|
322
|
+
exp = Backtrace.to_s(err.assert_with_bt + [err_backtrace.filtered.first])
|
323
|
+
assert_equal exp, result.trace
|
260
324
|
end
|
261
325
|
|
262
326
|
should "not allow creating for a test with non-TestFailure exceptions" do
|
@@ -269,8 +333,8 @@ module Assert::Result
|
|
269
333
|
desc "TestSkipped"
|
270
334
|
subject{ TestSkipped }
|
271
335
|
|
272
|
-
should "be a
|
273
|
-
assert_kind_of
|
336
|
+
should "be a halting test result error" do
|
337
|
+
assert_kind_of HaltingTestResultError, subject.new
|
274
338
|
end
|
275
339
|
|
276
340
|
end
|
@@ -290,13 +354,24 @@ module Assert::Result
|
|
290
354
|
|
291
355
|
should "allow creating for a test with TestSkipped exceptions" do
|
292
356
|
err = TestSkipped.new
|
293
|
-
err.set_backtrace(
|
357
|
+
err.set_backtrace(build_backtrace)
|
294
358
|
result = Skip.for_test(@test, err)
|
295
359
|
|
296
360
|
assert_equal err.message, result.message
|
297
361
|
|
298
|
-
|
299
|
-
assert_equal
|
362
|
+
err_backtrace = Backtrace.new(err.backtrace)
|
363
|
+
assert_equal err_backtrace, result.backtrace
|
364
|
+
|
365
|
+
# test assert with bt errors
|
366
|
+
err.assert_with_bt = build_backtrace
|
367
|
+
result = Skip.for_test(@test, err)
|
368
|
+
|
369
|
+
assert_equal err.message, result.message
|
370
|
+
assert_equal err.backtrace, result.backtrace
|
371
|
+
assert_equal err.assert_with_bt.first, result.src_line
|
372
|
+
|
373
|
+
exp = Backtrace.to_s(err.assert_with_bt + [err_backtrace.filtered.first])
|
374
|
+
assert_equal exp, result.trace
|
300
375
|
end
|
301
376
|
|
302
377
|
should "not allow creating for a test with non-TestSkipped exceptions" do
|
@@ -319,15 +394,15 @@ module Assert::Result
|
|
319
394
|
|
320
395
|
should "allow creating for a test with exceptions" do
|
321
396
|
err = Exception.new
|
322
|
-
err.set_backtrace(
|
397
|
+
err.set_backtrace(build_backtrace)
|
323
398
|
result = Error.for_test(@test, err)
|
324
399
|
|
325
400
|
exp_msg = "#{err.message} (#{err.class.name})"
|
326
401
|
assert_equal exp_msg, result.message
|
327
402
|
|
328
403
|
exp_bt = Backtrace.new(err.backtrace)
|
329
|
-
assert_equal exp_bt,
|
330
|
-
assert_equal
|
404
|
+
assert_equal exp_bt, result.backtrace
|
405
|
+
assert_equal Backtrace.to_s(exp_bt), result.trace
|
331
406
|
end
|
332
407
|
|
333
408
|
should "not allow creating for a test without an exception" do
|
@@ -339,15 +414,19 @@ module Assert::Result
|
|
339
414
|
class BacktraceTests < UnitTests
|
340
415
|
desc "Backtrace"
|
341
416
|
setup do
|
342
|
-
@backtrace = Backtrace.new(
|
417
|
+
@backtrace = Backtrace.new(build_backtrace)
|
343
418
|
end
|
344
419
|
subject { @backtrace }
|
345
420
|
|
346
|
-
should have_cmeths :parse
|
347
|
-
should have_imeths :
|
421
|
+
should have_cmeths :parse, :to_s
|
422
|
+
should have_imeths :filtered
|
348
423
|
|
349
424
|
should "be parseable from its string representation" do
|
350
|
-
assert_equal subject, Backtrace.parse(
|
425
|
+
assert_equal subject, Backtrace.parse(Backtrace.to_s(subject))
|
426
|
+
end
|
427
|
+
|
428
|
+
should "render as a string by joining on the newline" do
|
429
|
+
assert_equal subject.join(Backtrace::DELIM), Backtrace.to_s(subject)
|
351
430
|
end
|
352
431
|
|
353
432
|
should "be an Array" do
|
@@ -358,10 +437,6 @@ module Assert::Result
|
|
358
437
|
assert_equal "\n", Backtrace::DELIM
|
359
438
|
end
|
360
439
|
|
361
|
-
should "render as a string by joining on the newline" do
|
362
|
-
assert_equal subject.join(Backtrace::DELIM), subject.to_s
|
363
|
-
end
|
364
|
-
|
365
440
|
should "another backtrace when filtered" do
|
366
441
|
assert_kind_of Backtrace, subject
|
367
442
|
end
|