assert 2.14.0 → 2.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/assert.gemspec +0 -2
- data/lib/assert/assert_runner.rb +1 -1
- data/lib/assert/assertions.rb +1 -1
- data/lib/assert/config.rb +6 -1
- data/lib/assert/config_helpers.rb +75 -0
- data/lib/assert/context.rb +20 -14
- data/lib/assert/context/test_dsl.rb +17 -13
- data/lib/assert/{view/default_view.rb → default_view.rb} +9 -17
- data/lib/assert/factory.rb +2 -7
- data/lib/assert/file_line.rb +7 -3
- data/lib/assert/macro.rb +1 -1
- data/lib/assert/macros/methods.rb +1 -1
- data/lib/assert/result.rb +84 -90
- data/lib/assert/runner.rb +8 -2
- data/lib/assert/suite.rb +15 -5
- data/lib/assert/test.rb +112 -75
- data/lib/assert/version.rb +1 -1
- data/lib/assert/view.rb +108 -21
- data/lib/assert/view_helpers.rb +238 -0
- data/test/support/factory.rb +23 -6
- data/test/system/test_tests.rb +359 -0
- data/test/unit/assertions_tests.rb +1 -1
- data/test/unit/config_helpers_tests.rb +95 -0
- data/test/unit/config_tests.rb +5 -1
- data/test/unit/context/test_dsl_tests.rb +25 -17
- data/test/unit/context_tests.rb +45 -10
- data/test/unit/factory_tests.rb +9 -11
- data/test/unit/file_line_tests.rb +22 -0
- data/test/unit/result_tests.rb +219 -160
- data/test/unit/runner_tests.rb +19 -5
- data/test/unit/suite_tests.rb +23 -4
- data/test/unit/test_tests.rb +167 -33
- data/test/unit/view_helpers_tests.rb +210 -0
- data/test/unit/view_tests.rb +66 -26
- metadata +12 -23
- data/lib/assert/view/base.rb +0 -91
- data/lib/assert/view/helpers/ansi_styles.rb +0 -25
- data/lib/assert/view/helpers/common.rb +0 -209
- data/test/system/running_tests.rb +0 -404
@@ -8,7 +8,7 @@ module Assert::Assertions
|
|
8
8
|
setup do
|
9
9
|
@context_class = Factory.modes_off_context_class
|
10
10
|
@test = Factory.test
|
11
|
-
@context = @context_class.new(@test, @test.config)
|
11
|
+
@context = @context_class.new(@test, @test.config, proc{ |r| })
|
12
12
|
end
|
13
13
|
subject{ @context }
|
14
14
|
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'assert'
|
2
|
+
require 'assert/config_helpers'
|
3
|
+
|
4
|
+
require 'assert/config'
|
5
|
+
|
6
|
+
module Assert::ConfigHelpers
|
7
|
+
|
8
|
+
class UnitTests < Assert::Context
|
9
|
+
desc "Assert::ConfigHelpers"
|
10
|
+
setup do
|
11
|
+
@helpers_class = Class.new do
|
12
|
+
include Assert::ConfigHelpers
|
13
|
+
|
14
|
+
def config
|
15
|
+
# use the assert config since it has tests, contexts, etc
|
16
|
+
# also maybe use a fresh config that is empty
|
17
|
+
@config ||= [Assert.config, Assert::Config.new].choice
|
18
|
+
end
|
19
|
+
end
|
20
|
+
@helpers = @helpers_class.new
|
21
|
+
end
|
22
|
+
subject{ @helpers }
|
23
|
+
|
24
|
+
should have_imeths :runner_seed, :count, :tests?, :all_pass?
|
25
|
+
should have_imeths :run_time, :test_rate, :result_rate
|
26
|
+
should have_imeths :suite_contexts, :ordered_suite_contexts
|
27
|
+
should have_imeths :suite_files, :ordered_suite_files
|
28
|
+
should have_imeths :show_test_profile_info?, :show_test_verbose_info?
|
29
|
+
should have_imeths :ocurring_result_types
|
30
|
+
|
31
|
+
should "know its runner seed" do
|
32
|
+
assert_equal subject.config.runner_seed, subject.runner_seed
|
33
|
+
end
|
34
|
+
|
35
|
+
should "know how to count things on the suite" do
|
36
|
+
thing = [:pass, :fail, :results, :tests].choice
|
37
|
+
assert_equal subject.config.suite.count(thing), subject.count(thing)
|
38
|
+
end
|
39
|
+
|
40
|
+
should "know if it has tests or not" do
|
41
|
+
exp = subject.count(:tests) > 0
|
42
|
+
assert_equal exp, subject.tests?
|
43
|
+
end
|
44
|
+
|
45
|
+
should "know its formatted run time, test rate and result rate" do
|
46
|
+
format = '%.6f'
|
47
|
+
|
48
|
+
exp = format % subject.config.suite.run_time
|
49
|
+
assert_equal exp, subject.run_time(format)
|
50
|
+
|
51
|
+
exp = format % subject.config.suite.test_rate
|
52
|
+
assert_equal exp, subject.test_rate(format)
|
53
|
+
|
54
|
+
exp = format % subject.config.suite.result_rate
|
55
|
+
assert_equal exp, subject.result_rate(format)
|
56
|
+
end
|
57
|
+
|
58
|
+
should "know its suite contexts and ordered suite contexts" do
|
59
|
+
exp = subject.config.suite.tests.inject([]) do |contexts, test|
|
60
|
+
contexts << test.context_info.klass
|
61
|
+
end.uniq
|
62
|
+
assert_equal exp, subject.suite_contexts
|
63
|
+
|
64
|
+
exp = subject.suite_contexts.sort{ |a,b| a.to_s <=> b.to_s }
|
65
|
+
assert_equal exp, subject.ordered_suite_contexts
|
66
|
+
end
|
67
|
+
|
68
|
+
should "know its suite files and ordered suite files" do
|
69
|
+
exp = subject.config.suite.tests.inject([]) do |files, test|
|
70
|
+
files << test.context_info.file
|
71
|
+
end.uniq
|
72
|
+
assert_equal exp, subject.suite_files
|
73
|
+
|
74
|
+
exp = subject.suite_files.sort{ |a,b| a.to_s <=> b.to_s }
|
75
|
+
assert_equal exp, subject.ordered_suite_files
|
76
|
+
end
|
77
|
+
|
78
|
+
should "know whether to show test profile info" do
|
79
|
+
assert_equal !!subject.config.profile, subject.show_test_profile_info?
|
80
|
+
end
|
81
|
+
|
82
|
+
should "know whether to show verbose info" do
|
83
|
+
assert_equal !!subject.config.verbose, subject.show_test_verbose_info?
|
84
|
+
end
|
85
|
+
|
86
|
+
should "know what result types occur in a suite's results" do
|
87
|
+
exp = [:pass, :fail, :ignore, :skip, :error].select do |result_sym|
|
88
|
+
subject.count(result_sym) > 0
|
89
|
+
end
|
90
|
+
assert_equal exp, subject.ocurring_result_types
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
data/test/unit/config_tests.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
require 'assert'
|
2
2
|
require 'assert/config'
|
3
3
|
|
4
|
+
require 'assert/default_view'
|
5
|
+
require 'assert/runner'
|
6
|
+
require 'assert/suite'
|
7
|
+
|
4
8
|
class Assert::Config
|
5
9
|
|
6
10
|
class UnitTests < Assert::Context
|
@@ -18,7 +22,7 @@ class Assert::Config
|
|
18
22
|
should have_imeths :debug, :apply
|
19
23
|
|
20
24
|
should "default the view, suite, and runner" do
|
21
|
-
assert_kind_of Assert::
|
25
|
+
assert_kind_of Assert::DefaultView, subject.view
|
22
26
|
assert_kind_of Assert::Suite, subject.suite
|
23
27
|
assert_kind_of Assert::Runner, subject.runner
|
24
28
|
end
|
@@ -17,10 +17,11 @@ module Assert::Context::TestDSL
|
|
17
17
|
assert_equal 1, context_class.suite.tests.size
|
18
18
|
|
19
19
|
exp_test_name = @test_desc
|
20
|
-
built_test
|
20
|
+
built_test = context_class.suite.tests.first
|
21
|
+
|
21
22
|
assert_kind_of Assert::Test, built_test
|
22
23
|
assert_equal exp_test_name, built_test.name
|
23
|
-
assert_equal @test_block,
|
24
|
+
assert_equal @test_block, built_test.code
|
24
25
|
end
|
25
26
|
|
26
27
|
should "build a test using `should` with a desc and code block" do
|
@@ -30,10 +31,11 @@ module Assert::Context::TestDSL
|
|
30
31
|
assert_equal 1, context_class.suite.tests.size
|
31
32
|
|
32
33
|
exp_test_name = "should #{@test_desc}"
|
33
|
-
built_test
|
34
|
+
built_test = context_class.suite.tests.last
|
35
|
+
|
34
36
|
assert_kind_of Assert::Test, built_test
|
35
37
|
assert_equal exp_test_name, built_test.name
|
36
|
-
assert_equal @test_block,
|
38
|
+
assert_equal @test_block, built_test.code
|
37
39
|
end
|
38
40
|
|
39
41
|
should "build a test that skips with no msg when `test_eventually` called" do
|
@@ -43,8 +45,9 @@ module Assert::Context::TestDSL
|
|
43
45
|
context.instance_eval(&context.class.suite.tests.last.code)
|
44
46
|
end
|
45
47
|
|
46
|
-
assert_equal 1,
|
47
|
-
assert_equal
|
48
|
+
assert_equal 1, context.class.suite.tests.size
|
49
|
+
assert_equal 'TODO', err.message
|
50
|
+
assert_equal 1, err.backtrace.size
|
48
51
|
end
|
49
52
|
|
50
53
|
should "build a test that skips with no msg when `should_eventually` called" do
|
@@ -54,8 +57,9 @@ module Assert::Context::TestDSL
|
|
54
57
|
context.instance_eval(&context.class.suite.tests.last.code)
|
55
58
|
end
|
56
59
|
|
57
|
-
assert_equal 1,
|
58
|
-
assert_equal
|
60
|
+
assert_equal 1, context.class.suite.tests.size
|
61
|
+
assert_equal 'TODO', err.message
|
62
|
+
assert_equal 1, err.backtrace.size
|
59
63
|
end
|
60
64
|
|
61
65
|
should "skip with the msg \"TODO\" when `test` called with no block" do
|
@@ -65,8 +69,9 @@ module Assert::Context::TestDSL
|
|
65
69
|
context.instance_eval(&context.class.suite.tests.last.code)
|
66
70
|
end
|
67
71
|
|
68
|
-
assert_equal 1,
|
69
|
-
assert_equal
|
72
|
+
assert_equal 1, context.class.suite.tests.size
|
73
|
+
assert_equal 'TODO', err.message
|
74
|
+
assert_equal 1, err.backtrace.size
|
70
75
|
end
|
71
76
|
|
72
77
|
should "skip with the msg \"TODO\" when `should` called with no block" do
|
@@ -76,8 +81,9 @@ module Assert::Context::TestDSL
|
|
76
81
|
context.instance_eval(&context.class.suite.tests.last.code)
|
77
82
|
end
|
78
83
|
|
79
|
-
assert_equal 1,
|
80
|
-
assert_equal
|
84
|
+
assert_equal 1, context.class.suite.tests.size
|
85
|
+
assert_equal 'TODO', err.message
|
86
|
+
assert_equal 1, err.backtrace.size
|
81
87
|
end
|
82
88
|
|
83
89
|
should "skip with the msg \"TODO\" when `test_eventually` called with no block" do
|
@@ -87,8 +93,9 @@ module Assert::Context::TestDSL
|
|
87
93
|
context.instance_eval(&context.class.suite.tests.last.code)
|
88
94
|
end
|
89
95
|
|
90
|
-
assert_equal 1,
|
91
|
-
assert_equal
|
96
|
+
assert_equal 1, context.class.suite.tests.size
|
97
|
+
assert_equal 'TODO', err.message
|
98
|
+
assert_equal 1, err.backtrace.size
|
92
99
|
end
|
93
100
|
|
94
101
|
should "skip with the msg \"TODO\" when `should_eventually` called with no block" do
|
@@ -98,8 +105,9 @@ module Assert::Context::TestDSL
|
|
98
105
|
context.instance_eval(&context.class.suite.tests.last.code)
|
99
106
|
end
|
100
107
|
|
101
|
-
assert_equal 1,
|
102
|
-
assert_equal
|
108
|
+
assert_equal 1, context.class.suite.tests.size
|
109
|
+
assert_equal 'TODO', err.message
|
110
|
+
assert_equal 1, err.backtrace.size
|
103
111
|
end
|
104
112
|
|
105
113
|
should "build a test from a macro using `test`" do
|
@@ -147,7 +155,7 @@ module Assert::Context::TestDSL
|
|
147
155
|
context_class = Factory.modes_off_context_class &build_block
|
148
156
|
context_info = Factory.context_info(context_class)
|
149
157
|
test = Factory.test("whatever", context_info)
|
150
|
-
context_class.new(test, test.config)
|
158
|
+
context_class.new(test, test.config, proc{ |r| })
|
151
159
|
end
|
152
160
|
|
153
161
|
def capture_err(err_class, &block)
|
data/test/unit/context_tests.rb
CHANGED
@@ -11,7 +11,9 @@ class Assert::Context
|
|
11
11
|
setup do
|
12
12
|
@test = Factory.test
|
13
13
|
@context_class = @test.context_class
|
14
|
-
@
|
14
|
+
@callback_result = nil
|
15
|
+
@result_callback = proc{ |result| @callback_result = result }
|
16
|
+
@context = @context_class.new(@test, @test.config, @result_callback)
|
15
17
|
end
|
16
18
|
subject{ @context }
|
17
19
|
|
@@ -42,7 +44,7 @@ class Assert::Context
|
|
42
44
|
setup do
|
43
45
|
@skip_msg = "I need to implement this in the future."
|
44
46
|
begin; @context.skip(@skip_msg); rescue Exception => @exception; end
|
45
|
-
@result = Factory.skip_result(
|
47
|
+
@result = Factory.skip_result(@exception)
|
46
48
|
end
|
47
49
|
subject{ @result }
|
48
50
|
|
@@ -52,6 +54,19 @@ class Assert::Context
|
|
52
54
|
assert_equal @skip_msg, subject.message
|
53
55
|
end
|
54
56
|
|
57
|
+
should "not call the result callback" do
|
58
|
+
assert_nil @callback_result
|
59
|
+
end
|
60
|
+
|
61
|
+
should "use any given called from arg as the exception backtrace" do
|
62
|
+
assert_not_equal 1, @exception.backtrace.size
|
63
|
+
|
64
|
+
called_from = Factory.string
|
65
|
+
begin; @context.skip(@skip_msg, called_from); rescue Exception => exception; end
|
66
|
+
assert_equal 1, exception.backtrace.size
|
67
|
+
assert_equal called_from, exception.backtrace.first
|
68
|
+
end
|
69
|
+
|
55
70
|
end
|
56
71
|
|
57
72
|
class IgnoreTests < UnitTests
|
@@ -67,6 +82,10 @@ class Assert::Context
|
|
67
82
|
assert_equal @ignore_msg, subject.message
|
68
83
|
end
|
69
84
|
|
85
|
+
should "call the result callback" do
|
86
|
+
assert_equal @result, @callback_result
|
87
|
+
end
|
88
|
+
|
70
89
|
end
|
71
90
|
|
72
91
|
class PassTests < UnitTests
|
@@ -82,6 +101,10 @@ class Assert::Context
|
|
82
101
|
assert_equal @pass_msg, subject.message
|
83
102
|
end
|
84
103
|
|
104
|
+
should "call the result callback" do
|
105
|
+
assert_equal @result, @callback_result
|
106
|
+
end
|
107
|
+
|
85
108
|
end
|
86
109
|
|
87
110
|
class FlunkTests < UnitTests
|
@@ -97,6 +120,10 @@ class Assert::Context
|
|
97
120
|
assert_equal @flunk_msg, subject.message
|
98
121
|
end
|
99
122
|
|
123
|
+
should "call the result callback" do
|
124
|
+
assert_equal @result, @callback_result
|
125
|
+
end
|
126
|
+
|
100
127
|
end
|
101
128
|
|
102
129
|
class FailTests < UnitTests
|
@@ -118,13 +145,17 @@ class Assert::Context
|
|
118
145
|
assert_equal fail_msg, result.message
|
119
146
|
end
|
120
147
|
|
148
|
+
should "call the result callback" do
|
149
|
+
assert_equal @result, @callback_result
|
150
|
+
end
|
151
|
+
|
121
152
|
end
|
122
153
|
|
123
|
-
class HaltOnFailTests <
|
124
|
-
desc "when halting on fails"
|
154
|
+
class HaltOnFailTests < UnitTests
|
155
|
+
desc "failing when halting on fails"
|
125
156
|
setup do
|
126
157
|
@halt_config = Assert::Config.new(:halt_on_fail => true)
|
127
|
-
@context = @context_class.new(@test, @halt_config)
|
158
|
+
@context = @context_class.new(@test, @halt_config, @result_callback)
|
128
159
|
@fail_msg = "something failed"
|
129
160
|
end
|
130
161
|
subject{ @result }
|
@@ -138,10 +169,14 @@ class Assert::Context
|
|
138
169
|
assert_kind_of Assert::Result::TestFailure, err
|
139
170
|
assert_equal @fail_msg, err.message
|
140
171
|
|
141
|
-
result = Assert::Result::Fail.
|
172
|
+
result = Assert::Result::Fail.for_test(Factory.test("something"), err)
|
142
173
|
assert_equal @fail_msg, result.message
|
143
174
|
end
|
144
175
|
|
176
|
+
should "not call the result callback" do
|
177
|
+
assert_nil @callback_result
|
178
|
+
end
|
179
|
+
|
145
180
|
end
|
146
181
|
|
147
182
|
class AssertTests < UnitTests
|
@@ -154,7 +189,7 @@ class Assert::Context
|
|
154
189
|
should "return a pass result given a `true` assertion" do
|
155
190
|
result = subject.assert(true, @fail_desc){ @what_failed }
|
156
191
|
assert_kind_of Assert::Result::Pass, result
|
157
|
-
|
192
|
+
assert_equal '', result.message
|
158
193
|
end
|
159
194
|
|
160
195
|
should "return a fail result given a `false` assertion" do
|
@@ -193,7 +228,7 @@ class Assert::Context
|
|
193
228
|
should "return a pass result given a `false` assertion" do
|
194
229
|
result = subject.assert_not(false, @fail_desc)
|
195
230
|
assert_kind_of Assert::Result::Pass, result
|
196
|
-
|
231
|
+
assert_equal '', result.message
|
197
232
|
end
|
198
233
|
|
199
234
|
should "return a fail result given a `true` assertion" do
|
@@ -225,7 +260,7 @@ class Assert::Context
|
|
225
260
|
@context_class = Factory.modes_off_context_class do
|
226
261
|
subject{ @something = expected }
|
227
262
|
end
|
228
|
-
@context = @context_class.new(@test, @test.config)
|
263
|
+
@context = @context_class.new(@test, @test.config, proc{ |result| })
|
229
264
|
@subject = @context.subject
|
230
265
|
end
|
231
266
|
subject{ @subject }
|
@@ -248,7 +283,7 @@ class Assert::Context
|
|
248
283
|
begin
|
249
284
|
@context.with_backtrace(@from_bt, &@from_block)
|
250
285
|
rescue Assert::Result::TestSkipped => e
|
251
|
-
@test.results << Assert::Result::Skip.
|
286
|
+
@test.results << Assert::Result::Skip.for_test(@test, e)
|
252
287
|
end
|
253
288
|
|
254
289
|
assert_equal 5, @test.results.size
|
data/test/unit/factory_tests.rb
CHANGED
@@ -63,6 +63,15 @@ module Assert::Factory
|
|
63
63
|
assert_equal 1, subject.text(1).length
|
64
64
|
end
|
65
65
|
|
66
|
+
should "return a random string using `slug`" do
|
67
|
+
assert_kind_of String, subject.slug
|
68
|
+
assert_equal 5, subject.slug.length
|
69
|
+
end
|
70
|
+
|
71
|
+
should "allow passing a maximum length using `slug`" do
|
72
|
+
assert_equal 1, subject.slug(1).length
|
73
|
+
end
|
74
|
+
|
66
75
|
should "return a random hex string using `hex`" do
|
67
76
|
assert_kind_of String, subject.hex
|
68
77
|
assert_match /\A[0-9a-f]{10}\Z/, subject.hex
|
@@ -72,17 +81,6 @@ module Assert::Factory
|
|
72
81
|
assert_equal 1, subject.hex(1).length
|
73
82
|
end
|
74
83
|
|
75
|
-
should "return a random slug string using `slug`" do
|
76
|
-
assert_kind_of String, subject.slug
|
77
|
-
segments = subject.slug.split('-')
|
78
|
-
assert_equal 2, segments.size
|
79
|
-
segments.each{ |s| assert_match /\A[a-z]{4}\Z/, s }
|
80
|
-
end
|
81
|
-
|
82
|
-
should "allow passing a maximum length using `slug`" do
|
83
|
-
assert_equal 1, subject.slug(1).length
|
84
|
-
end
|
85
|
-
|
86
84
|
should "return a random file name string using `file_name`" do
|
87
85
|
assert_kind_of String, subject.file_name
|
88
86
|
assert_match /\A[a-z]{6}\.[a-z]{3}\Z/, subject.file_name
|
@@ -21,6 +21,20 @@ class Assert::FileLine
|
|
21
21
|
assert_equal @line, file_line.line
|
22
22
|
end
|
23
23
|
|
24
|
+
should "handle parsing bad data gracefully" do
|
25
|
+
file_line = subject.parse(@file)
|
26
|
+
assert_equal '', file_line.file
|
27
|
+
assert_equal '', file_line.line
|
28
|
+
|
29
|
+
file_line = subject.parse('')
|
30
|
+
assert_equal '', file_line.file
|
31
|
+
assert_equal '', file_line.line
|
32
|
+
|
33
|
+
file_line = subject.parse(nil)
|
34
|
+
assert_equal '', file_line.file
|
35
|
+
assert_equal '', file_line.line
|
36
|
+
end
|
37
|
+
|
24
38
|
end
|
25
39
|
|
26
40
|
class InitTests < UnitTests
|
@@ -35,6 +49,14 @@ class Assert::FileLine
|
|
35
49
|
should "know its file and line" do
|
36
50
|
assert_equal @file, subject.file
|
37
51
|
assert_equal @line, subject.line
|
52
|
+
|
53
|
+
file_line = Assert::FileLine.new(@file)
|
54
|
+
assert_equal @file, file_line.file
|
55
|
+
assert_equal '', file_line.line
|
56
|
+
|
57
|
+
file_line = Assert::FileLine.new
|
58
|
+
assert_equal '', file_line.file
|
59
|
+
assert_equal '', file_line.line
|
38
60
|
end
|
39
61
|
|
40
62
|
should "know its string representation" do
|
data/test/unit/result_tests.rb
CHANGED
@@ -3,277 +3,336 @@ require 'assert/result'
|
|
3
3
|
|
4
4
|
module Assert::Result
|
5
5
|
|
6
|
-
class
|
7
|
-
desc "Assert::Result
|
6
|
+
class UnitTests < Assert::Context
|
7
|
+
desc "Assert::Result"
|
8
8
|
setup do
|
9
|
-
@
|
9
|
+
@test = Factory.test("a test name")
|
10
10
|
end
|
11
|
-
subject
|
11
|
+
subject{ Assert::Result }
|
12
12
|
|
13
|
-
should
|
13
|
+
should have_imeths :types, :new
|
14
14
|
|
15
|
-
should "
|
16
|
-
|
17
|
-
|
15
|
+
should "know its types" do
|
16
|
+
exp = {
|
17
|
+
:pass => Pass,
|
18
|
+
:fail => Fail,
|
19
|
+
:ignore => Ignore,
|
20
|
+
:skip => Skip,
|
21
|
+
:error => Error
|
22
|
+
}
|
23
|
+
assert_equal exp, subject.types
|
18
24
|
|
19
|
-
|
20
|
-
assert_equal subject.join("\n"), subject.to_s
|
25
|
+
assert_equal Base, subject.types[Factory.string]
|
21
26
|
end
|
22
27
|
|
23
|
-
should "
|
24
|
-
|
25
|
-
|
28
|
+
should "create results from data hashes" do
|
29
|
+
type = Assert::Result.types.keys.choice
|
30
|
+
exp = Assert::Result.types[type].new(:type => type)
|
26
31
|
|
27
|
-
|
28
|
-
assert_equal ["No backtrace"], Backtrace.new
|
32
|
+
assert_equal exp, Assert::Result.new(:type => type)
|
29
33
|
end
|
30
34
|
|
31
35
|
end
|
32
36
|
|
33
|
-
class BaseTests <
|
34
|
-
desc "
|
37
|
+
class BaseTests < UnitTests
|
38
|
+
desc "Base"
|
35
39
|
setup do
|
36
|
-
@
|
37
|
-
|
40
|
+
@given_data = {
|
41
|
+
:type => Factory.string,
|
42
|
+
:name => Factory.string,
|
43
|
+
:test_name => Factory.string,
|
44
|
+
:message => Factory.string,
|
45
|
+
:backtrace => Backtrace.new(caller),
|
46
|
+
:trace => Factory.string
|
47
|
+
}
|
48
|
+
@result = Base.new(@given_data)
|
38
49
|
end
|
39
50
|
subject{ @result }
|
40
51
|
|
41
|
-
should
|
42
|
-
should have_imeths :
|
43
|
-
should
|
52
|
+
should have_cmeths :type, :name, :for_test
|
53
|
+
should have_imeths :type, :name, :test_name, :message, :backtrace, :trace
|
54
|
+
should have_imeths *Assert::Result.types.keys.map{ |k| "#{k}?" }
|
55
|
+
should have_imeths :set_backtrace, :data, :to_sym, :to_s
|
44
56
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
57
|
+
should "know its class-level type/name" do
|
58
|
+
assert_equal :unknown, subject.class.type
|
59
|
+
assert_equal '', subject.class.name
|
60
|
+
end
|
49
61
|
|
50
|
-
|
51
|
-
|
52
|
-
|
62
|
+
should "know how to build a result for a given test" do
|
63
|
+
message = Factory.text
|
64
|
+
bt = Factory.integer(3).times.map{ Factory.string }
|
65
|
+
result = Base.for_test(@test, message, bt)
|
66
|
+
|
67
|
+
exp_backtrace = Backtrace.new(bt)
|
68
|
+
exp_trace = exp_backtrace.filtered.first.to_s
|
69
|
+
|
70
|
+
assert_equal @test.name, result.test_name
|
71
|
+
assert_equal message, result.message
|
72
|
+
assert_equal exp_backtrace, result.backtrace
|
73
|
+
assert_equal exp_trace, result.trace
|
53
74
|
end
|
54
75
|
|
55
|
-
should "
|
56
|
-
assert_equal @
|
76
|
+
should "use any given attrs" do
|
77
|
+
assert_equal @given_data[:type].to_sym, subject.type
|
78
|
+
assert_equal @given_data[:name], subject.name
|
79
|
+
assert_equal @given_data[:test_name], subject.test_name
|
80
|
+
assert_equal @given_data[:message], subject.message
|
81
|
+
assert_equal @given_data[:backtrace], subject.backtrace
|
82
|
+
assert_equal @given_data[:trace], subject.trace
|
57
83
|
end
|
58
84
|
|
59
|
-
should "
|
60
|
-
|
85
|
+
should "default its attrs" do
|
86
|
+
result = Base.new({})
|
87
|
+
|
88
|
+
assert_equal :unknown, result.type
|
89
|
+
assert_equal '', result.name
|
90
|
+
assert_equal '', result.test_name
|
91
|
+
assert_equal '', result.message
|
92
|
+
assert_equal Backtrace.new([]), result.backtrace
|
93
|
+
assert_equal '', result.trace
|
61
94
|
end
|
62
95
|
|
63
|
-
should "
|
64
|
-
|
65
|
-
|
66
|
-
|
96
|
+
should "know if it is a certain type of result" do
|
97
|
+
Assert::Result.types.keys.each do |type|
|
98
|
+
assert_false subject.send("#{type}?")
|
99
|
+
Assert.stub(subject, :type){ type }
|
100
|
+
assert_true subject.send("#{type}?")
|
101
|
+
end
|
67
102
|
end
|
68
103
|
|
69
|
-
should "allow
|
70
|
-
|
104
|
+
should "allow setting a new backtrace" do
|
105
|
+
new_bt = Factory.integer(3).times.map{ Factory.string }
|
106
|
+
exp_backtrace = Backtrace.new(new_bt)
|
107
|
+
exp_trace = exp_backtrace.filtered.first.to_s
|
108
|
+
|
109
|
+
subject.set_backtrace(new_bt)
|
71
110
|
|
72
|
-
|
73
|
-
assert_equal
|
111
|
+
assert_equal exp_backtrace, subject.backtrace
|
112
|
+
assert_equal exp_trace, subject.trace
|
74
113
|
end
|
75
114
|
|
76
|
-
should "
|
77
|
-
|
115
|
+
should "know its data" do
|
116
|
+
exp = {
|
117
|
+
:type => subject.type,
|
118
|
+
:name => subject.name,
|
119
|
+
:test_name => subject.test_name,
|
120
|
+
:message => subject.message,
|
121
|
+
:backtrace => subject.backtrace,
|
122
|
+
:trace => subject.trace,
|
123
|
+
}
|
124
|
+
assert_equal exp, subject.data
|
78
125
|
end
|
79
126
|
|
80
|
-
should "
|
81
|
-
|
127
|
+
should "know its symbol representation" do
|
128
|
+
assert_equal subject.type, subject.to_sym
|
82
129
|
end
|
83
130
|
|
84
|
-
should "
|
85
|
-
|
131
|
+
should "know its string representation" do
|
132
|
+
str = subject.to_s
|
133
|
+
|
134
|
+
assert_includes subject.name.upcase, str
|
135
|
+
assert_includes subject.test_name, str
|
136
|
+
assert_includes subject.message, str
|
137
|
+
assert_includes subject.trace, str
|
138
|
+
|
139
|
+
assert_equal 3, str.split("\n").count
|
140
|
+
|
141
|
+
Assert.stub(subject, :message){ '' }
|
142
|
+
Assert.stub(subject, :trace){ '' }
|
143
|
+
|
144
|
+
assert_equal 1, subject.to_s.split("\n").count
|
86
145
|
end
|
87
146
|
|
88
|
-
should "
|
89
|
-
|
147
|
+
should "know if it is equal to another result" do
|
148
|
+
other = Assert::Result::Base.new(@given_data)
|
149
|
+
assert_equal other, subject
|
150
|
+
|
151
|
+
Assert.stub(other, [:type, :message].choice){ Factory.string }
|
152
|
+
assert_not_equal other, subject
|
90
153
|
end
|
91
154
|
|
92
|
-
should "
|
93
|
-
|
155
|
+
should "show only its class and message when inspected" do
|
156
|
+
exp = "#<#{subject.class}:#{'0x0%x' % (subject.object_id << 1)}"\
|
157
|
+
" @message=#{subject.message.inspect}>"
|
158
|
+
assert_equal exp, subject.inspect
|
94
159
|
end
|
160
|
+
|
95
161
|
end
|
96
162
|
|
97
|
-
class PassTests <
|
98
|
-
desc "
|
163
|
+
class PassTests < UnitTests
|
164
|
+
desc "Pass"
|
99
165
|
setup do
|
100
|
-
@
|
101
|
-
@result = Assert::Result::Pass.new(@test, "passed", [])
|
166
|
+
@result = Pass.new({})
|
102
167
|
end
|
103
168
|
subject { @result }
|
104
169
|
|
105
|
-
should "
|
106
|
-
assert_equal
|
170
|
+
should "know its type/name" do
|
171
|
+
assert_equal :pass, subject.type
|
172
|
+
assert_equal :pass, subject.class.type
|
173
|
+
assert_equal 'Pass', subject.class.name
|
107
174
|
end
|
108
175
|
|
109
|
-
|
110
|
-
should "not be #{type}?" do
|
111
|
-
assert_equal false, subject.send("#{type}?")
|
112
|
-
end
|
113
|
-
end
|
176
|
+
end
|
114
177
|
|
115
|
-
|
116
|
-
|
178
|
+
class IgnoreTests < UnitTests
|
179
|
+
desc "Ignore"
|
180
|
+
setup do
|
181
|
+
@result = Ignore.new({})
|
117
182
|
end
|
183
|
+
subject { @result }
|
118
184
|
|
119
|
-
should "know its name" do
|
120
|
-
assert_equal
|
185
|
+
should "know its type/name" do
|
186
|
+
assert_equal :ignore, subject.type
|
187
|
+
assert_equal :ignore, subject.class.type
|
188
|
+
assert_equal 'Ignore', subject.class.name
|
121
189
|
end
|
122
190
|
|
123
|
-
|
124
|
-
|
191
|
+
end
|
192
|
+
|
193
|
+
class TestFailureTests < UnitTests
|
194
|
+
desc "TestFailure"
|
195
|
+
subject{ TestFailure }
|
196
|
+
|
197
|
+
should "be a runtime error" do
|
198
|
+
assert_kind_of RuntimeError, subject.new
|
125
199
|
end
|
126
200
|
|
127
201
|
end
|
128
202
|
|
129
|
-
class
|
130
|
-
desc "
|
203
|
+
class FailTests < UnitTests
|
204
|
+
desc "Fail"
|
131
205
|
setup do
|
132
|
-
@
|
133
|
-
@result = Assert::Result::Ignore.new(@test, "ignored", [])
|
206
|
+
@result = Fail.new({})
|
134
207
|
end
|
135
208
|
subject { @result }
|
136
209
|
|
137
|
-
should "
|
138
|
-
assert_equal
|
210
|
+
should "know its type/name" do
|
211
|
+
assert_equal :fail, subject.type
|
212
|
+
assert_equal :fail, subject.class.type
|
213
|
+
assert_equal 'Fail', subject.class.name
|
139
214
|
end
|
140
215
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
end
|
216
|
+
should "allow creating for a test with TestFailure exceptions" do
|
217
|
+
err = TestFailure.new
|
218
|
+
err.set_backtrace(caller)
|
219
|
+
result = Fail.for_test(@test, err)
|
146
220
|
|
147
|
-
|
148
|
-
|
221
|
+
assert_equal err.message, result.message
|
222
|
+
|
223
|
+
exp_bt = Backtrace.new(err.backtrace)
|
224
|
+
assert_equal exp_bt, result.backtrace
|
149
225
|
end
|
150
226
|
|
151
|
-
should "
|
152
|
-
|
227
|
+
should "not allow creating for a test with non-TestFailure exceptions" do
|
228
|
+
assert_raises(ArgumentError){ Fail.for_test(@test, RuntimeError.new) }
|
153
229
|
end
|
154
230
|
|
155
|
-
|
156
|
-
|
231
|
+
end
|
232
|
+
|
233
|
+
class TestSkippedTests < UnitTests
|
234
|
+
desc "TestSkipped"
|
235
|
+
subject{ TestSkipped }
|
236
|
+
|
237
|
+
should "be a runtime error" do
|
238
|
+
assert_kind_of RuntimeError, subject.new
|
157
239
|
end
|
158
240
|
|
159
241
|
end
|
160
242
|
|
161
|
-
class
|
162
|
-
desc "
|
243
|
+
class SkipTests < UnitTests
|
244
|
+
desc "Skip"
|
163
245
|
setup do
|
164
|
-
@
|
165
|
-
@result = Assert::Result::Fail.new(@test, "failed", [])
|
246
|
+
@result = Skip.new({})
|
166
247
|
end
|
167
248
|
subject { @result }
|
168
249
|
|
169
|
-
should "
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
should "fail?" do
|
174
|
-
assert_equal true, subject.fail?
|
250
|
+
should "know its type/name" do
|
251
|
+
assert_equal :skip, subject.type
|
252
|
+
assert_equal :skip, subject.class.type
|
253
|
+
assert_equal 'Skip', subject.class.name
|
175
254
|
end
|
176
255
|
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
end
|
256
|
+
should "allow creating for a test with TestSkipped exceptions" do
|
257
|
+
err = TestSkipped.new
|
258
|
+
err.set_backtrace(caller)
|
259
|
+
result = Skip.for_test(@test, err)
|
182
260
|
|
183
|
-
|
184
|
-
assert_equal :fail, subject.to_sym
|
185
|
-
end
|
261
|
+
assert_equal err.message, result.message
|
186
262
|
|
187
|
-
|
188
|
-
assert_equal
|
263
|
+
exp_bt = Backtrace.new(err.backtrace)
|
264
|
+
assert_equal exp_bt, result.backtrace
|
189
265
|
end
|
190
266
|
|
191
|
-
should "
|
192
|
-
|
267
|
+
should "not allow creating for a test with non-TestSkipped exceptions" do
|
268
|
+
assert_raises(ArgumentError){ Skip.for_test(@test, RuntimeError.new) }
|
193
269
|
end
|
194
270
|
|
195
271
|
end
|
196
272
|
|
197
|
-
class
|
198
|
-
desc "
|
273
|
+
class ErrorTests < UnitTests
|
274
|
+
desc "Error"
|
199
275
|
setup do
|
200
|
-
@
|
201
|
-
@exception = nil
|
202
|
-
begin
|
203
|
-
raise TestSkipped, "test ski["
|
204
|
-
rescue Exception => err
|
205
|
-
@exception = err
|
206
|
-
end
|
207
|
-
@result = Assert::Result::Skip.new(@test, @exception)
|
276
|
+
@result = Error.new({})
|
208
277
|
end
|
209
278
|
subject { @result }
|
210
279
|
|
211
|
-
should "
|
212
|
-
|
280
|
+
should "know its class-level type/name" do
|
281
|
+
assert_equal :error, subject.class.type
|
282
|
+
assert_equal 'Error', subject.class.name
|
213
283
|
end
|
214
284
|
|
215
|
-
should "
|
216
|
-
|
217
|
-
|
285
|
+
should "allow creating for a test with exceptions" do
|
286
|
+
err = Exception.new
|
287
|
+
err.set_backtrace(caller)
|
288
|
+
result = Error.for_test(@test, err)
|
218
289
|
|
219
|
-
|
220
|
-
|
221
|
-
assert_equal false, subject.send("#{type}?")
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
|
-
should "know its to_sym" do
|
226
|
-
assert_equal :skip, subject.to_sym
|
227
|
-
end
|
290
|
+
exp_msg = "#{err.message} (#{err.class.name})"
|
291
|
+
assert_equal exp_msg, result.message
|
228
292
|
|
229
|
-
|
230
|
-
assert_equal
|
293
|
+
exp_bt = Backtrace.new(err.backtrace)
|
294
|
+
assert_equal exp_bt, result.backtrace
|
295
|
+
assert_equal exp_bt.to_s, result.trace
|
231
296
|
end
|
232
297
|
|
233
|
-
should "
|
234
|
-
|
298
|
+
should "not allow creating for a test without an exception" do
|
299
|
+
assert_raises(ArgumentError){ Error.for_test(@test, Factory.string) }
|
235
300
|
end
|
236
301
|
|
237
302
|
end
|
238
303
|
|
239
|
-
class
|
240
|
-
desc "
|
304
|
+
class BacktraceTests < UnitTests
|
305
|
+
desc "Backtrace"
|
241
306
|
setup do
|
242
|
-
@
|
243
|
-
@exception = nil
|
244
|
-
begin
|
245
|
-
raise Exception, "test error"
|
246
|
-
rescue Exception => err
|
247
|
-
@exception = err
|
248
|
-
end
|
249
|
-
@result = Assert::Result::Error.new(@test, @exception)
|
307
|
+
@backtrace = Backtrace.new(caller)
|
250
308
|
end
|
251
|
-
subject { @
|
309
|
+
subject { @backtrace }
|
252
310
|
|
253
|
-
should
|
254
|
-
|
311
|
+
should have_cmeths :parse
|
312
|
+
should have_imeths :to_s, :filtered
|
313
|
+
|
314
|
+
should "be parseable from its string representation" do
|
315
|
+
assert_equal subject, Backtrace.parse(subject.to_s)
|
255
316
|
end
|
256
317
|
|
257
|
-
|
258
|
-
|
259
|
-
assert_equal false, subject.send("#{type}?")
|
260
|
-
end
|
318
|
+
should "be an Array" do
|
319
|
+
assert_kind_of ::Array, subject
|
261
320
|
end
|
262
321
|
|
263
|
-
should "know its
|
264
|
-
assert_equal
|
322
|
+
should "know its DELIM" do
|
323
|
+
assert_equal "\n", Backtrace::DELIM
|
265
324
|
end
|
266
325
|
|
267
|
-
should "
|
268
|
-
assert_equal
|
326
|
+
should "render as a string by joining on the newline" do
|
327
|
+
assert_equal subject.join(Backtrace::DELIM), subject.to_s
|
269
328
|
end
|
270
329
|
|
271
|
-
should "
|
272
|
-
|
330
|
+
should "another backtrace when filtered" do
|
331
|
+
assert_kind_of Backtrace, subject
|
273
332
|
end
|
274
333
|
|
275
|
-
should "
|
276
|
-
assert_equal
|
334
|
+
should "default itself when created from nil" do
|
335
|
+
assert_equal ["No backtrace"], Backtrace.new
|
277
336
|
end
|
278
337
|
|
279
338
|
end
|