assert 2.14.0 → 2.15.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 +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
data/test/unit/runner_tests.rb
CHANGED
@@ -1,16 +1,30 @@
|
|
1
1
|
require 'assert'
|
2
|
-
require 'assert/suite'
|
3
|
-
require 'assert/view/base'
|
4
2
|
require 'assert/runner'
|
5
3
|
|
4
|
+
require 'stringio'
|
5
|
+
require 'assert/config_helpers'
|
6
|
+
require 'assert/suite'
|
7
|
+
require 'assert/view'
|
8
|
+
|
6
9
|
class Assert::Runner
|
7
10
|
|
8
11
|
class UnitTests < Assert::Context
|
9
12
|
desc "Assert::Runner"
|
13
|
+
subject{ Assert::Runner }
|
14
|
+
|
15
|
+
should "include the config helpers" do
|
16
|
+
assert_includes Assert::ConfigHelpers, subject
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
class InitTests < UnitTests
|
22
|
+
desc "when init"
|
10
23
|
setup do
|
11
24
|
@config = Factory.modes_off_config
|
12
|
-
@suite
|
13
|
-
@view
|
25
|
+
@config.suite Assert::Suite.new(@config)
|
26
|
+
@config.view Assert::View::Base.new(@config, StringIO.new("", "w+"))
|
27
|
+
|
14
28
|
@runner = Assert::Runner.new(@config)
|
15
29
|
end
|
16
30
|
subject { @runner }
|
@@ -23,7 +37,7 @@ class Assert::Runner
|
|
23
37
|
end
|
24
38
|
|
25
39
|
should "return an integer exit code" do
|
26
|
-
assert_equal 0, subject.run
|
40
|
+
assert_equal 0, subject.run
|
27
41
|
end
|
28
42
|
|
29
43
|
end
|
data/test/unit/suite_tests.rb
CHANGED
@@ -14,7 +14,8 @@ class Assert::Suite
|
|
14
14
|
subject{ @suite }
|
15
15
|
|
16
16
|
should have_accessors :config, :tests, :test_methods, :start_time, :end_time
|
17
|
-
should have_imeths :ordered_tests, :
|
17
|
+
should have_imeths :ordered_tests, :ordered_tests_by_run_time
|
18
|
+
should have_imeths :results, :ordered_results
|
18
19
|
should have_imeths :run_time, :test_rate, :result_rate
|
19
20
|
should have_imeths :count, :test_count, :result_count
|
20
21
|
should have_imeths :setup, :startup, :teardown, :shutdown
|
@@ -57,7 +58,12 @@ class Assert::Suite
|
|
57
58
|
end
|
58
59
|
|
59
60
|
should "know its ordered tests" do
|
60
|
-
assert_equal subject.
|
61
|
+
assert_equal subject.tests, subject.ordered_tests
|
62
|
+
end
|
63
|
+
|
64
|
+
should "know its tests ordered by run time" do
|
65
|
+
exp = subject.ordered_tests.sort{ |a, b| a.run_time <=> b.run_time }
|
66
|
+
assert_equal exp, subject.ordered_tests_by_run_time
|
61
67
|
end
|
62
68
|
|
63
69
|
should "know how many results it has" do
|
@@ -65,7 +71,7 @@ class Assert::Suite
|
|
65
71
|
end
|
66
72
|
|
67
73
|
should "know its ordered results" do
|
68
|
-
assert_equal subject.
|
74
|
+
assert_equal subject.results, subject.ordered_results
|
69
75
|
end
|
70
76
|
|
71
77
|
should "know how many pass results it has" do
|
@@ -170,7 +176,7 @@ class Assert::Suite
|
|
170
176
|
end
|
171
177
|
|
172
178
|
class ContextInfoTests < UnitTests
|
173
|
-
desc "
|
179
|
+
desc "ContextInfo"
|
174
180
|
setup do
|
175
181
|
@caller = caller
|
176
182
|
@klass = Assert::Context
|
@@ -179,6 +185,7 @@ class Assert::Suite
|
|
179
185
|
subject{ @info }
|
180
186
|
|
181
187
|
should have_readers :called_from, :klass, :file
|
188
|
+
should have_imeths :test_name
|
182
189
|
|
183
190
|
should "set its klass on init" do
|
184
191
|
assert_equal @klass, subject.klass
|
@@ -201,6 +208,18 @@ class Assert::Suite
|
|
201
208
|
assert_nil info.file
|
202
209
|
end
|
203
210
|
|
211
|
+
should "know how to build the contextual test name for a given name" do
|
212
|
+
desc = Factory.string
|
213
|
+
name = Factory.string
|
214
|
+
|
215
|
+
assert_equal name, subject.test_name(name)
|
216
|
+
assert_equal '', subject.test_name('')
|
217
|
+
assert_equal '', subject.test_name(nil)
|
218
|
+
|
219
|
+
Assert.stub(subject.klass, :description){ desc }
|
220
|
+
assert_equal "#{desc} #{name}", subject.test_name(name)
|
221
|
+
end
|
222
|
+
|
204
223
|
end
|
205
224
|
|
206
225
|
end
|
data/test/unit/test_tests.rb
CHANGED
@@ -3,68 +3,201 @@ require 'assert/test'
|
|
3
3
|
|
4
4
|
require 'assert/config'
|
5
5
|
require 'assert/file_line'
|
6
|
+
require 'assert/result'
|
6
7
|
|
7
8
|
class Assert::Test
|
8
9
|
|
9
10
|
class UnitTests < Assert::Context
|
10
11
|
desc "Assert::Test"
|
11
12
|
setup do
|
12
|
-
@test_code = lambda{ assert(true) }
|
13
13
|
@context_class = Factory.modes_off_context_class{ desc "context class" }
|
14
14
|
@context_info = Factory.context_info(@context_class)
|
15
|
-
@
|
15
|
+
@config = Factory.modes_off_config
|
16
|
+
@test_code = proc{ assert(true) }
|
17
|
+
end
|
18
|
+
subject{ Assert::Test }
|
19
|
+
|
20
|
+
should have_imeths :result_count_meth, :name_file_line_context_data
|
21
|
+
should have_imeths :for_block, :for_method
|
22
|
+
|
23
|
+
should "know the result count method name for a given type" do
|
24
|
+
type = Factory.string
|
25
|
+
exp = "#{type}_result_count".to_sym
|
26
|
+
assert_equal exp, subject.result_count_meth(type)
|
27
|
+
end
|
28
|
+
|
29
|
+
should "know how to build the name and file line given context" do
|
30
|
+
test_name = Factory.string
|
31
|
+
data = subject.name_file_line_context_data(@context_info, test_name)
|
32
|
+
|
33
|
+
exp = @context_info.test_name(test_name)
|
34
|
+
assert_equal exp, data[:name]
|
35
|
+
|
36
|
+
exp = @context_info.called_from
|
37
|
+
assert_equal exp, data[:file_line]
|
38
|
+
end
|
39
|
+
|
40
|
+
should "build tests for a block" do
|
41
|
+
name = Factory.string
|
42
|
+
test = subject.for_block(name, @context_info, @config, &@test_code)
|
43
|
+
|
44
|
+
exp = Assert::FileLine.parse(@context_info.called_from)
|
45
|
+
assert_equal exp, test.file_line
|
46
|
+
|
47
|
+
exp = @context_info.test_name(name)
|
48
|
+
assert_equal exp, test.name
|
49
|
+
|
50
|
+
assert_equal @context_info, test.context_info
|
51
|
+
assert_equal @config, test.config
|
52
|
+
assert_equal @test_code, test.code
|
53
|
+
end
|
54
|
+
|
55
|
+
should "build tests for a method" do
|
56
|
+
meth = 'a_test_method'
|
57
|
+
test = subject.for_method(meth, @context_info, @config)
|
58
|
+
|
59
|
+
exp = Assert::FileLine.parse(@context_info.called_from)
|
60
|
+
assert_equal exp, test.file_line
|
61
|
+
|
62
|
+
exp = @context_info.test_name(meth)
|
63
|
+
assert_equal exp, test.name
|
64
|
+
|
65
|
+
assert_equal @context_info, test.context_info
|
66
|
+
assert_equal @config, test.config
|
67
|
+
|
68
|
+
assert_kind_of Proc, test.code
|
69
|
+
self.instance_eval(&test.code)
|
70
|
+
assert_true @a_test_method_called
|
71
|
+
end
|
72
|
+
|
73
|
+
def a_test_method
|
74
|
+
@a_test_method_called = true
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
class InitWithDataTests < UnitTests
|
80
|
+
desc "when init with data"
|
81
|
+
setup do
|
82
|
+
@file_line = Assert::FileLine.new(Factory.string, Factory.integer.to_s)
|
83
|
+
@meta_data = {
|
84
|
+
:file_line => @file_line.to_s,
|
85
|
+
:name => Factory.string,
|
86
|
+
:output => Factory.string,
|
87
|
+
:run_time => Factory.float(1.0),
|
88
|
+
}
|
89
|
+
@meta_data[:total_result_count] = Factory.integer(100)
|
90
|
+
Assert::Result.types.keys.each do |type|
|
91
|
+
@meta_data[Assert::Test.result_count_meth(type)] = Factory.integer(100)
|
92
|
+
end
|
93
|
+
@run_data = {
|
94
|
+
:context_info => @context_info,
|
95
|
+
:config => @config,
|
96
|
+
:code => @test_code
|
97
|
+
}
|
98
|
+
|
99
|
+
@test = Assert::Test.new(@meta_data.merge(@run_data))
|
16
100
|
end
|
17
101
|
subject{ @test }
|
18
102
|
|
19
|
-
should have_readers :
|
20
|
-
should
|
21
|
-
should
|
22
|
-
should have_imeths :context_class, :file, :line_number
|
23
|
-
should have_imeths :
|
24
|
-
should have_imeths *Assert::Result.types.keys.
|
103
|
+
should have_readers :file_line, :name, :output, :run_time, :total_result_count
|
104
|
+
should have_imeths *Assert::Result.types.keys.map{ |k| Assert::Test.result_count_meth(k) }
|
105
|
+
should have_readers :context_info, :config, :code, :results
|
106
|
+
should have_imeths :data, :context_class, :file, :line_number
|
107
|
+
should have_imeths :result_rate, :result_count, :capture_result, :run
|
108
|
+
should have_imeths *Assert::Result.types.keys.map{ |k| "#{k}_results" }
|
25
109
|
|
26
|
-
should "
|
27
|
-
assert_equal @
|
110
|
+
should "use any given attrs" do
|
111
|
+
assert_equal @file_line, subject.file_line
|
112
|
+
assert_equal @meta_data[:name], subject.name
|
113
|
+
assert_equal @meta_data[:output], subject.output
|
114
|
+
assert_equal @meta_data[:run_time], subject.run_time
|
115
|
+
|
116
|
+
assert_equal @meta_data[:total_result_count], subject.total_result_count
|
117
|
+
|
118
|
+
Assert::Result.types.keys.each do |type|
|
119
|
+
n = Assert::Test.result_count_meth(type)
|
120
|
+
assert_equal @meta_data[n], subject.send(n)
|
121
|
+
end
|
122
|
+
|
123
|
+
assert_equal @context_info, subject.context_info
|
124
|
+
assert_equal @config, subject.config
|
125
|
+
assert_equal @test_code, subject.code
|
126
|
+
end
|
127
|
+
|
128
|
+
should "default its attrs" do
|
129
|
+
test = Assert::Test.new
|
130
|
+
|
131
|
+
assert_equal Assert::FileLine.parse(''), test.file_line
|
132
|
+
assert_equal '', test.name
|
133
|
+
assert_equal '', test.output
|
134
|
+
assert_equal 0, test.run_time
|
135
|
+
assert_equal 0, test.total_result_count
|
136
|
+
|
137
|
+
Assert::Result.types.keys.each do |type|
|
138
|
+
assert_equal 0, test.send(Assert::Test.result_count_meth(type))
|
139
|
+
end
|
140
|
+
|
141
|
+
assert_nil test.context_info
|
142
|
+
assert_nil test.config
|
143
|
+
assert_nil test.code
|
28
144
|
end
|
29
145
|
|
30
|
-
should "
|
31
|
-
|
32
|
-
assert_equal cust_config, Factory.test(cust_config).config
|
146
|
+
should "have no results before running" do
|
147
|
+
assert_empty subject.results
|
33
148
|
end
|
34
149
|
|
35
|
-
should "know its
|
36
|
-
|
37
|
-
|
150
|
+
should "know its data hash" do
|
151
|
+
assert_equal @meta_data, subject.data
|
152
|
+
end
|
38
153
|
|
39
|
-
|
40
|
-
assert_equal
|
154
|
+
should "know its context class" do
|
155
|
+
assert_equal @context_class, subject.context_class
|
156
|
+
end
|
41
157
|
|
158
|
+
should "file line and number" do
|
42
159
|
assert_equal subject.file_line.file, subject.file
|
43
160
|
assert_equal subject.file_line.line, subject.line_number
|
44
161
|
end
|
45
162
|
|
46
|
-
should "
|
47
|
-
|
163
|
+
should "know its result rate" do
|
164
|
+
count = Factory.integer(100)
|
165
|
+
time = Factory.float(1.0) + 1.0
|
48
166
|
|
49
|
-
|
50
|
-
|
167
|
+
Assert.stub(subject, :result_count){ count }
|
168
|
+
Assert.stub(subject, :run_time){ time }
|
169
|
+
exp = count / time
|
170
|
+
assert_equal exp, subject.result_rate
|
51
171
|
|
52
|
-
|
53
|
-
|
172
|
+
Assert.stub(subject, :run_time){ 0 }
|
173
|
+
assert_equal 0.0, subject.result_rate
|
54
174
|
|
55
|
-
|
56
|
-
assert_equal 0, subject.
|
175
|
+
Assert.stub(subject, :run_time){ 0.0 }
|
176
|
+
assert_equal 0.0, subject.result_rate
|
57
177
|
end
|
58
178
|
|
59
|
-
should "
|
60
|
-
assert_equal
|
61
|
-
|
179
|
+
should "know its result counts" do
|
180
|
+
assert_equal subject.total_result_count, subject.result_count
|
181
|
+
|
182
|
+
Assert::Result.types.keys.each do |type|
|
183
|
+
exp = subject.send(Assert::Test.result_count_meth(type))
|
184
|
+
assert_equal exp, subject.result_count(type)
|
185
|
+
end
|
62
186
|
end
|
63
187
|
|
64
|
-
should "
|
65
|
-
|
66
|
-
|
67
|
-
|
188
|
+
should "capture results" do
|
189
|
+
result = Factory.pass_result
|
190
|
+
prev_total_count = subject.total_result_count
|
191
|
+
prev_pass_count = subject.pass_result_count
|
192
|
+
callback_result = nil
|
193
|
+
callback = proc{ |r| callback_result = r}
|
194
|
+
|
195
|
+
subject.capture_result(result, callback)
|
196
|
+
|
197
|
+
assert_equal result, subject.results.last
|
198
|
+
assert_equal prev_total_count + 1, subject.total_result_count
|
199
|
+
assert_equal prev_pass_count + 1, subject.pass_result_count
|
200
|
+
assert_equal result, callback_result
|
68
201
|
end
|
69
202
|
|
70
203
|
should "have a custom inspect that only shows limited attributes" do
|
@@ -307,6 +440,7 @@ class Assert::Test
|
|
307
440
|
"std out from the teardown\n"
|
308
441
|
assert_equal(exp_out, @test.output)
|
309
442
|
end
|
443
|
+
|
310
444
|
end
|
311
445
|
|
312
446
|
end
|
@@ -0,0 +1,210 @@
|
|
1
|
+
require 'assert'
|
2
|
+
require 'assert/view_helpers'
|
3
|
+
|
4
|
+
require 'assert/config'
|
5
|
+
require 'assert/config_helpers'
|
6
|
+
require 'assert/result'
|
7
|
+
|
8
|
+
module Assert::ViewHelpers
|
9
|
+
|
10
|
+
class UnitTests < Assert::Context
|
11
|
+
desc "Assert::ViewHelpers"
|
12
|
+
setup do
|
13
|
+
test_opt_val = @test_opt_val = Factory.string
|
14
|
+
@helpers_class = Class.new do
|
15
|
+
include Assert::ViewHelpers
|
16
|
+
|
17
|
+
option 'test_opt', test_opt_val
|
18
|
+
|
19
|
+
def config
|
20
|
+
# use the assert config since it has tests, contexts, etc
|
21
|
+
# also maybe use a fresh config that is empty
|
22
|
+
@config ||= [Assert.config, Assert::Config.new].choice
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
subject{ @helpers_class }
|
27
|
+
|
28
|
+
should have_imeths :option
|
29
|
+
|
30
|
+
should "include the config helpers" do
|
31
|
+
assert_includes Assert::ConfigHelpers, subject
|
32
|
+
end
|
33
|
+
|
34
|
+
should "write option values" do
|
35
|
+
helpers = @helpers_class.new
|
36
|
+
assert_equal @test_opt_val, helpers.test_opt
|
37
|
+
|
38
|
+
new_val = Factory.integer
|
39
|
+
helpers.test_opt new_val
|
40
|
+
assert_equal new_val, helpers.test_opt
|
41
|
+
|
42
|
+
other_val = Factory.integer
|
43
|
+
helpers.test_opt new_val, other_val
|
44
|
+
assert_equal [new_val, other_val], helpers.test_opt
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
class InitTests < UnitTests
|
50
|
+
desc "when init"
|
51
|
+
setup do
|
52
|
+
@helpers = @helpers_class.new
|
53
|
+
end
|
54
|
+
subject{ @helpers }
|
55
|
+
|
56
|
+
should have_imeths :test_run_time, :test_result_rate
|
57
|
+
should have_imeths :result_details_for, :matched_result_details_for
|
58
|
+
should have_imeths :show_result_details?, :captured_output
|
59
|
+
should have_imeths :test_count_statement, :result_count_statement
|
60
|
+
should have_imeths :to_sentence
|
61
|
+
should have_imeths :all_pass_result_summary_msg, :result_summary_msg
|
62
|
+
should have_imeths :results_summary_sentence
|
63
|
+
|
64
|
+
should "know a test's formatted run time and result rate" do
|
65
|
+
test = Factory.test
|
66
|
+
format = '%.6f'
|
67
|
+
|
68
|
+
exp = format % test.run_time
|
69
|
+
assert_equal exp, subject.test_run_time(test, format)
|
70
|
+
assert_equal exp, subject.test_run_time(test)
|
71
|
+
|
72
|
+
exp = format % test.result_rate
|
73
|
+
assert_equal exp, subject.test_result_rate(test, format)
|
74
|
+
assert_equal exp, subject.test_result_rate(test)
|
75
|
+
end
|
76
|
+
|
77
|
+
# note: not formally testing the result details for methods as the views
|
78
|
+
# will break if these are broken.
|
79
|
+
|
80
|
+
should "know whether to show result details" do
|
81
|
+
assert_false subject.show_result_details?(Factory.pass_result)
|
82
|
+
|
83
|
+
assert_true subject.show_result_details?(Factory.fail_result)
|
84
|
+
assert_true subject.show_result_details?(Factory.error_result)
|
85
|
+
|
86
|
+
skip_res, ignore_res = Factory.skip_result, Factory.ignore_result
|
87
|
+
assert_true subject.show_result_details?(skip_res)
|
88
|
+
assert_true subject.show_result_details?(ignore_res)
|
89
|
+
|
90
|
+
Assert.stub(skip_res, :message){ nil}
|
91
|
+
Assert.stub(ignore_res, :message){ nil}
|
92
|
+
assert_false subject.show_result_details?(skip_res)
|
93
|
+
assert_false subject.show_result_details?(ignore_res)
|
94
|
+
end
|
95
|
+
|
96
|
+
should "know how to build captured output" do
|
97
|
+
output = Factory.string
|
98
|
+
exp = "--- stdout ---\n"\
|
99
|
+
"#{output}"\
|
100
|
+
"--------------"
|
101
|
+
assert_equal exp, subject.captured_output(output)
|
102
|
+
end
|
103
|
+
|
104
|
+
should "know its test count and result count statements" do
|
105
|
+
exp = "#{subject.count(:tests)} test#{'s' if subject.count(:tests) != 1}"
|
106
|
+
assert_equal exp, subject.test_count_statement
|
107
|
+
|
108
|
+
exp = "#{subject.count(:results)} result#{'s' if subject.count(:results) != 1}"
|
109
|
+
assert_equal exp, subject.result_count_statement
|
110
|
+
end
|
111
|
+
|
112
|
+
should "know how to build a sentence from a list of items" do
|
113
|
+
items = 1.times.map{ Factory.string }
|
114
|
+
assert_equal items.first, subject.to_sentence(items)
|
115
|
+
|
116
|
+
items = 2.times.map{ Factory.string }
|
117
|
+
assert_equal items.join(' and '), subject.to_sentence(items)
|
118
|
+
|
119
|
+
items = (Factory.integer(3)+2).times.map{ Factory.string }
|
120
|
+
exp = [items[0..-2].join(", "), items.last].join(", and ")
|
121
|
+
assert_equal exp, subject.to_sentence(items)
|
122
|
+
end
|
123
|
+
|
124
|
+
should "know its all pass result summary message" do
|
125
|
+
Assert.stub(subject, :count).with(:results){ 0 }
|
126
|
+
assert_equal "uhh...", subject.all_pass_result_summary_msg
|
127
|
+
|
128
|
+
Assert.stub(subject, :count).with(:results){ 1 }
|
129
|
+
assert_equal "pass", subject.all_pass_result_summary_msg
|
130
|
+
|
131
|
+
Assert.stub(subject, :count).with(:results){ Factory.integer(10)+1 }
|
132
|
+
assert_equal "all pass", subject.all_pass_result_summary_msg
|
133
|
+
end
|
134
|
+
|
135
|
+
should "know its result summary msg" do
|
136
|
+
res_type = :pass
|
137
|
+
Assert.stub(subject, :all_pass?){ true }
|
138
|
+
exp = subject.all_pass_result_summary_msg
|
139
|
+
assert_equal exp, subject.result_summary_msg(res_type)
|
140
|
+
|
141
|
+
Assert.stub(subject, :all_pass?){ false }
|
142
|
+
res_type = [:pass, :ignore, :fail, :skip, :error].choice
|
143
|
+
exp = "#{subject.count(res_type)} #{res_type.to_s}"
|
144
|
+
assert_equal exp, subject.result_summary_msg(res_type)
|
145
|
+
end
|
146
|
+
|
147
|
+
should "know its results summary sentence" do
|
148
|
+
items = subject.ocurring_result_types.map do |result_sym|
|
149
|
+
subject.result_summary_msg(result_sym)
|
150
|
+
end
|
151
|
+
exp = subject.to_sentence(items)
|
152
|
+
assert_equal exp, subject.results_summary_sentence
|
153
|
+
|
154
|
+
block = proc{ |summary, result| "#{summary}--#{result}" }
|
155
|
+
items = subject.ocurring_result_types.map do |result_sym|
|
156
|
+
block.call(subject.result_summary_msg(result_sym), result_sym)
|
157
|
+
end
|
158
|
+
exp = subject.to_sentence(items)
|
159
|
+
assert_equal exp, subject.results_summary_sentence(&block)
|
160
|
+
end
|
161
|
+
|
162
|
+
end
|
163
|
+
|
164
|
+
class AnsiTests < UnitTests
|
165
|
+
desc "Ansi"
|
166
|
+
subject{ Ansi }
|
167
|
+
|
168
|
+
should have_imeths :code_for
|
169
|
+
|
170
|
+
should "know its codes" do
|
171
|
+
assert_not_empty subject::CODES
|
172
|
+
end
|
173
|
+
|
174
|
+
should "map its code style names to ansi code strings" do
|
175
|
+
styles = Factory.integer(3).times.map{ subject::CODES.keys.choice }
|
176
|
+
exp = styles.map{ |n| "\e[#{subject::CODES[n]}m" }.join('')
|
177
|
+
assert_equal exp, subject.code_for(*styles)
|
178
|
+
|
179
|
+
styles = Factory.integer(3).times.map{ Factory.string }
|
180
|
+
assert_equal '', subject.code_for(*styles)
|
181
|
+
|
182
|
+
styles = []
|
183
|
+
assert_equal '', subject.code_for(*styles)
|
184
|
+
end
|
185
|
+
|
186
|
+
end
|
187
|
+
|
188
|
+
class ResultDetailsTests < UnitTests
|
189
|
+
desc "ResultDetails"
|
190
|
+
setup do
|
191
|
+
@result = Factory.string
|
192
|
+
@test = Factory.test
|
193
|
+
@index = Factory.integer
|
194
|
+
|
195
|
+
@details = ResultDetails.new(@result, @test, @index)
|
196
|
+
end
|
197
|
+
subject{ @details }
|
198
|
+
|
199
|
+
should have_readers :result, :test_index, :test, :output
|
200
|
+
|
201
|
+
should "know its attrs" do
|
202
|
+
assert_equal @result, subject.result
|
203
|
+
assert_equal @test, subject.test
|
204
|
+
assert_equal @index, subject.test_index
|
205
|
+
assert_equal @test.output, subject.output
|
206
|
+
end
|
207
|
+
|
208
|
+
end
|
209
|
+
|
210
|
+
end
|