assert 2.15.0 → 2.15.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -7
- data/Gemfile +0 -1
- data/{LICENSE.txt → LICENSE} +0 -0
- data/README.md +106 -35
- data/assert.gemspec +2 -2
- data/lib/assert/assert_runner.rb +19 -12
- data/lib/assert/assertions.rb +1 -0
- data/lib/assert/cli.rb +3 -0
- data/lib/assert/config.rb +24 -6
- data/lib/assert/config_helpers.rb +15 -28
- data/lib/assert/context.rb +4 -3
- data/lib/assert/context/test_dsl.rb +3 -2
- data/lib/assert/context_info.rb +19 -0
- data/lib/assert/default_runner.rb +12 -0
- data/lib/assert/default_suite.rb +64 -0
- data/lib/assert/default_view.rb +17 -15
- data/lib/assert/file_line.rb +3 -2
- data/lib/assert/result.rb +6 -0
- data/lib/assert/runner.rb +58 -21
- data/lib/assert/suite.rb +61 -100
- data/lib/assert/test.rb +3 -3
- data/lib/assert/version.rb +1 -1
- data/lib/assert/view.rb +58 -74
- data/lib/assert/view_helpers.rb +10 -48
- data/test/helper.rb +9 -0
- data/test/support/factory.rb +5 -5
- data/test/unit/assertions/assert_raises_tests.rb +20 -0
- data/test/unit/config_helpers_tests.rb +29 -29
- data/test/unit/config_tests.rb +43 -10
- data/test/unit/context/suite_dsl_tests.rb +1 -1
- data/test/unit/context_info_tests.rb +55 -0
- data/test/unit/default_runner_tests.rb +18 -0
- data/test/unit/default_suite_tests.rb +74 -0
- data/test/unit/file_line_tests.rb +6 -2
- data/test/unit/result_tests.rb +15 -4
- data/test/unit/runner_tests.rb +128 -6
- data/test/unit/suite_tests.rb +73 -182
- data/test/unit/view_helpers_tests.rb +44 -38
- data/test/unit/view_tests.rb +15 -39
- metadata +42 -28
- data/Rakefile +0 -1
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'assert'
|
2
|
+
require 'assert/context_info'
|
3
|
+
|
4
|
+
require 'assert/context'
|
5
|
+
|
6
|
+
class Assert::ContextInfo
|
7
|
+
|
8
|
+
class UnitTests < Assert::Context
|
9
|
+
desc "Assert::ContextInfo"
|
10
|
+
setup do
|
11
|
+
@caller = caller
|
12
|
+
@klass = Assert::Context
|
13
|
+
@info = Assert::ContextInfo.new(@klass, nil, @caller.first)
|
14
|
+
end
|
15
|
+
subject{ @info }
|
16
|
+
|
17
|
+
should have_readers :called_from, :klass, :file
|
18
|
+
should have_imeths :test_name
|
19
|
+
|
20
|
+
should "set its klass on init" do
|
21
|
+
assert_equal @klass, subject.klass
|
22
|
+
end
|
23
|
+
|
24
|
+
should "set its called_from to the called_from or first caller on init" do
|
25
|
+
info = Assert::ContextInfo.new(@klass, @caller.first, nil)
|
26
|
+
assert_equal @caller.first, info.called_from
|
27
|
+
|
28
|
+
info = Assert::ContextInfo.new(@klass, nil, @caller.first)
|
29
|
+
assert_equal @caller.first, info.called_from
|
30
|
+
end
|
31
|
+
|
32
|
+
should "set its file from caller info on init" do
|
33
|
+
assert_equal @caller.first.gsub(/\:[0-9]+.*$/, ''), subject.file
|
34
|
+
end
|
35
|
+
|
36
|
+
should "not have any file info if no caller is given" do
|
37
|
+
info = Assert::ContextInfo.new(@klass)
|
38
|
+
assert_nil info.file
|
39
|
+
end
|
40
|
+
|
41
|
+
should "know how to build the contextual test name for a given name" do
|
42
|
+
desc = Factory.string
|
43
|
+
name = Factory.string
|
44
|
+
|
45
|
+
assert_equal name, subject.test_name(name)
|
46
|
+
assert_equal '', subject.test_name('')
|
47
|
+
assert_equal '', subject.test_name(nil)
|
48
|
+
|
49
|
+
Assert.stub(subject.klass, :description){ desc }
|
50
|
+
assert_equal "#{desc} #{name}", subject.test_name(name)
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'assert'
|
2
|
+
require 'assert/default_runner'
|
3
|
+
|
4
|
+
require 'assert/runner'
|
5
|
+
|
6
|
+
class Assert::DefaultRunner
|
7
|
+
|
8
|
+
class UnitTests < Assert::Context
|
9
|
+
desc "Assert::DefaultRunner"
|
10
|
+
setup do
|
11
|
+
@config = Factory.modes_off_config
|
12
|
+
@runner = Assert::DefaultRunner.new(@config)
|
13
|
+
end
|
14
|
+
subject{ @runner }
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'assert'
|
2
|
+
require 'assert/default_suite'
|
3
|
+
|
4
|
+
require 'assert/suite'
|
5
|
+
|
6
|
+
class Assert::DefaultSuite
|
7
|
+
|
8
|
+
class UnitTests < Assert::Context
|
9
|
+
desc "Assert::DefaultSuite"
|
10
|
+
setup do
|
11
|
+
@config = Factory.modes_off_config
|
12
|
+
@suite = Assert::DefaultSuite.new(@config)
|
13
|
+
|
14
|
+
ci = Factory.context_info(Factory.modes_off_context_class)
|
15
|
+
[ Factory.test("should nothing", ci){ },
|
16
|
+
Factory.test("should pass", ci){ assert(1==1); refute(1==0) },
|
17
|
+
Factory.test("should fail", ci){ ignore; assert(1==0); refute(1==1) },
|
18
|
+
Factory.test("should ignored", ci){ ignore },
|
19
|
+
Factory.test("should skip", ci){ skip; ignore; assert(1==1) },
|
20
|
+
Factory.test("should error", ci){ raise Exception; ignore; assert(1==1) }
|
21
|
+
].each{ |test| @suite.tests << test }
|
22
|
+
@suite.tests.each(&:run)
|
23
|
+
end
|
24
|
+
subject{ @suite }
|
25
|
+
|
26
|
+
should "be a Suite" do
|
27
|
+
assert_kind_of Assert::Suite, subject
|
28
|
+
end
|
29
|
+
|
30
|
+
should "know its test and result attrs" do
|
31
|
+
assert_equal 6, subject.tests.size
|
32
|
+
assert_kind_of Assert::Test, subject.tests.first
|
33
|
+
|
34
|
+
assert_equal subject.tests.size, subject.test_count
|
35
|
+
assert_equal subject.tests, subject.ordered_tests
|
36
|
+
|
37
|
+
exp = subject.ordered_tests.sort{ |a, b| a.run_time <=> b.run_time }
|
38
|
+
assert_equal exp, subject.ordered_tests_by_run_time
|
39
|
+
|
40
|
+
assert_equal 8, subject.result_count
|
41
|
+
|
42
|
+
exp = subject.ordered_tests.inject([]){ |results, t| results += t.results }
|
43
|
+
assert_equal exp, subject.ordered_results
|
44
|
+
|
45
|
+
assert_equal 2, subject.result_count(:pass)
|
46
|
+
assert_equal 2, subject.result_count(:fail)
|
47
|
+
assert_equal 2, subject.result_count(:ignore)
|
48
|
+
assert_equal 1, subject.result_count(:skip)
|
49
|
+
assert_equal 1, subject.result_count(:error)
|
50
|
+
end
|
51
|
+
|
52
|
+
should "count its tests and results" do
|
53
|
+
assert_equal subject.test_count, subject.count(:tests)
|
54
|
+
assert_equal subject.result_count, subject.count(:results)
|
55
|
+
|
56
|
+
assert_equal subject.result_count(:pass), subject.count(:passed)
|
57
|
+
assert_equal subject.result_count(:pass), subject.count(:pass)
|
58
|
+
|
59
|
+
assert_equal subject.result_count(:fail), subject.count(:failed)
|
60
|
+
assert_equal subject.result_count(:fail), subject.count(:fail)
|
61
|
+
|
62
|
+
assert_equal subject.result_count(:ignore), subject.count(:ignored)
|
63
|
+
assert_equal subject.result_count(:ignore), subject.count(:ignore)
|
64
|
+
|
65
|
+
assert_equal subject.result_count(:skip), subject.count(:skipped)
|
66
|
+
assert_equal subject.result_count(:skip), subject.count(:skip)
|
67
|
+
|
68
|
+
assert_equal subject.result_count(:error), subject.count(:errored)
|
69
|
+
assert_equal subject.result_count(:error), subject.count(:error)
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
@@ -23,8 +23,12 @@ class Assert::FileLine
|
|
23
23
|
|
24
24
|
should "handle parsing bad data gracefully" do
|
25
25
|
file_line = subject.parse(@file)
|
26
|
-
assert_equal
|
27
|
-
assert_equal '',
|
26
|
+
assert_equal @file, file_line.file
|
27
|
+
assert_equal '', file_line.line
|
28
|
+
|
29
|
+
file_line = subject.parse(@line)
|
30
|
+
assert_equal @line, file_line.file
|
31
|
+
assert_equal '', file_line.line
|
28
32
|
|
29
33
|
file_line = subject.parse('')
|
30
34
|
assert_equal '', file_line.file
|
data/test/unit/result_tests.rb
CHANGED
@@ -26,7 +26,7 @@ module Assert::Result
|
|
26
26
|
end
|
27
27
|
|
28
28
|
should "create results from data hashes" do
|
29
|
-
type = Assert::Result.types.keys.
|
29
|
+
type = Assert::Result.types.keys.sample
|
30
30
|
exp = Assert::Result.types[type].new(:type => type)
|
31
31
|
|
32
32
|
assert_equal exp, Assert::Result.new(:type => type)
|
@@ -41,7 +41,9 @@ module Assert::Result
|
|
41
41
|
:type => Factory.string,
|
42
42
|
:name => Factory.string,
|
43
43
|
:test_name => Factory.string,
|
44
|
+
:test_id => Factory.string,
|
44
45
|
:message => Factory.string,
|
46
|
+
:output => Factory.text,
|
45
47
|
:backtrace => Backtrace.new(caller),
|
46
48
|
:trace => Factory.string
|
47
49
|
}
|
@@ -50,7 +52,8 @@ module Assert::Result
|
|
50
52
|
subject{ @result }
|
51
53
|
|
52
54
|
should have_cmeths :type, :name, :for_test
|
53
|
-
should have_imeths :type, :name, :test_name, :
|
55
|
+
should have_imeths :type, :name, :test_name, :test_id
|
56
|
+
should have_imeths :message, :output, :backtrace, :trace
|
54
57
|
should have_imeths *Assert::Result.types.keys.map{ |k| "#{k}?" }
|
55
58
|
should have_imeths :set_backtrace, :data, :to_sym, :to_s
|
56
59
|
|
@@ -67,7 +70,9 @@ module Assert::Result
|
|
67
70
|
exp_backtrace = Backtrace.new(bt)
|
68
71
|
exp_trace = exp_backtrace.filtered.first.to_s
|
69
72
|
|
70
|
-
assert_equal @test.name,
|
73
|
+
assert_equal @test.name, result.test_name
|
74
|
+
assert_equal @test.file_line.to_s, result.test_id
|
75
|
+
|
71
76
|
assert_equal message, result.message
|
72
77
|
assert_equal exp_backtrace, result.backtrace
|
73
78
|
assert_equal exp_trace, result.trace
|
@@ -77,7 +82,9 @@ module Assert::Result
|
|
77
82
|
assert_equal @given_data[:type].to_sym, subject.type
|
78
83
|
assert_equal @given_data[:name], subject.name
|
79
84
|
assert_equal @given_data[:test_name], subject.test_name
|
85
|
+
assert_equal @given_data[:test_id], subject.test_id
|
80
86
|
assert_equal @given_data[:message], subject.message
|
87
|
+
assert_equal @given_data[:output], subject.output
|
81
88
|
assert_equal @given_data[:backtrace], subject.backtrace
|
82
89
|
assert_equal @given_data[:trace], subject.trace
|
83
90
|
end
|
@@ -88,7 +95,9 @@ module Assert::Result
|
|
88
95
|
assert_equal :unknown, result.type
|
89
96
|
assert_equal '', result.name
|
90
97
|
assert_equal '', result.test_name
|
98
|
+
assert_equal '', result.test_id
|
91
99
|
assert_equal '', result.message
|
100
|
+
assert_equal '', result.output
|
92
101
|
assert_equal Backtrace.new([]), result.backtrace
|
93
102
|
assert_equal '', result.trace
|
94
103
|
end
|
@@ -117,7 +126,9 @@ module Assert::Result
|
|
117
126
|
:type => subject.type,
|
118
127
|
:name => subject.name,
|
119
128
|
:test_name => subject.test_name,
|
129
|
+
:test_id => subject.test_id,
|
120
130
|
:message => subject.message,
|
131
|
+
:output => subject.output,
|
121
132
|
:backtrace => subject.backtrace,
|
122
133
|
:trace => subject.trace,
|
123
134
|
}
|
@@ -148,7 +159,7 @@ module Assert::Result
|
|
148
159
|
other = Assert::Result::Base.new(@given_data)
|
149
160
|
assert_equal other, subject
|
150
161
|
|
151
|
-
Assert.stub(other, [:type, :message].
|
162
|
+
Assert.stub(other, [:type, :message].sample){ Factory.string }
|
152
163
|
assert_not_equal other, subject
|
153
164
|
end
|
154
165
|
|
data/test/unit/runner_tests.rb
CHANGED
@@ -3,7 +3,8 @@ require 'assert/runner'
|
|
3
3
|
|
4
4
|
require 'stringio'
|
5
5
|
require 'assert/config_helpers'
|
6
|
-
require 'assert/
|
6
|
+
require 'assert/default_suite'
|
7
|
+
require 'assert/result'
|
7
8
|
require 'assert/view'
|
8
9
|
|
9
10
|
class Assert::Runner
|
@@ -22,22 +23,143 @@ class Assert::Runner
|
|
22
23
|
desc "when init"
|
23
24
|
setup do
|
24
25
|
@config = Factory.modes_off_config
|
25
|
-
@config.suite Assert::
|
26
|
-
@config.view Assert::View
|
26
|
+
@config.suite Assert::DefaultSuite.new(@config)
|
27
|
+
@config.view Assert::View.new(@config, StringIO.new("", "w+"))
|
27
28
|
|
28
29
|
@runner = Assert::Runner.new(@config)
|
29
30
|
end
|
30
|
-
subject
|
31
|
+
subject{ @runner }
|
31
32
|
|
32
33
|
should have_readers :config
|
33
|
-
should have_imeths :run
|
34
|
+
should have_imeths :runner, :run
|
35
|
+
should have_imeths :before_load, :after_load
|
36
|
+
should have_imeths :on_start, :on_finish, :on_interrupt
|
37
|
+
should have_imeths :before_test, :after_test, :on_result
|
34
38
|
|
35
39
|
should "know its config" do
|
36
40
|
assert_equal @config, subject.config
|
37
41
|
end
|
38
42
|
|
43
|
+
should "override the config helper's runner value with itself" do
|
44
|
+
assert_equal subject, subject.runner
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
class RunTests < InitTests
|
50
|
+
desc "and run"
|
51
|
+
setup do
|
52
|
+
callback_mixin = Module.new
|
53
|
+
@runner_class = Class.new(Assert::Runner) do
|
54
|
+
include CallbackMixin
|
55
|
+
|
56
|
+
def run!(&block)
|
57
|
+
self.suite.tests.each(&block)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
suite_class = Class.new(Assert::DefaultSuite){ include CallbackMixin }
|
61
|
+
view_class = Class.new(Assert::View){ include CallbackMixin }
|
62
|
+
|
63
|
+
@view_output = ""
|
64
|
+
|
65
|
+
@config.suite suite_class.new(@config)
|
66
|
+
@config.view view_class.new(@config, StringIO.new(@view_output, "w+"))
|
67
|
+
|
68
|
+
@ci = Factory.context_info(Factory.modes_off_context_class)
|
69
|
+
@test = Factory.test("should pass", @ci){ assert(1==1) }
|
70
|
+
@config.suite.tests << @test
|
71
|
+
|
72
|
+
@runner = @runner_class.new(@config)
|
73
|
+
@result = @runner.run
|
74
|
+
end
|
75
|
+
|
39
76
|
should "return an integer exit code" do
|
40
|
-
assert_equal 0,
|
77
|
+
assert_equal 0, @result
|
78
|
+
end
|
79
|
+
|
80
|
+
should "run all callbacks on itself, the suite and the view" do
|
81
|
+
# itself
|
82
|
+
assert_true subject.on_start_called
|
83
|
+
assert_equal [@test], subject.before_test_called
|
84
|
+
assert_instance_of Assert::Result::Pass, subject.on_result_called.last
|
85
|
+
assert_equal [@test], subject.after_test_called
|
86
|
+
assert_true subject.on_finish_called
|
87
|
+
|
88
|
+
# suite
|
89
|
+
suite = @config.suite
|
90
|
+
assert_true suite.on_start_called
|
91
|
+
assert_equal [@test], suite.before_test_called
|
92
|
+
assert_instance_of Assert::Result::Pass, suite.on_result_called.last
|
93
|
+
assert_equal [@test], suite.after_test_called
|
94
|
+
assert_true suite.on_finish_called
|
95
|
+
|
96
|
+
# view
|
97
|
+
view = @config.view
|
98
|
+
assert_true view.on_start_called
|
99
|
+
assert_equal [@test], view.before_test_called
|
100
|
+
assert_instance_of Assert::Result::Pass, view.on_result_called.last
|
101
|
+
assert_equal [@test], view.after_test_called
|
102
|
+
assert_true view.on_finish_called
|
103
|
+
end
|
104
|
+
|
105
|
+
should "descibe running the tests in random order if there are tests" do
|
106
|
+
exp = "Running tests in random order, " \
|
107
|
+
"seeded with \"#{subject.runner_seed}\"\n"
|
108
|
+
assert_includes exp, @view_output
|
109
|
+
|
110
|
+
@view_output.gsub!(/./, '')
|
111
|
+
@config.suite.tests.clear
|
112
|
+
subject.run
|
113
|
+
assert_not_includes exp, @view_output
|
114
|
+
end
|
115
|
+
|
116
|
+
should "run only a single test if a single test is configured" do
|
117
|
+
other_test = Factory.test("should also pass", @ci){ assert(1==1) }
|
118
|
+
@config.suite.tests << other_test
|
119
|
+
|
120
|
+
@config.single_test @test.file_line.to_s
|
121
|
+
|
122
|
+
runner = @runner_class.new(@config)
|
123
|
+
runner.run
|
124
|
+
assert_equal [@test], runner.before_test_called
|
125
|
+
end
|
126
|
+
|
127
|
+
should "descibe running only a single test if a single test is configured" do
|
128
|
+
@config.single_test @test.file_line.to_s
|
129
|
+
@view_output.gsub!(/./, '')
|
130
|
+
subject.run
|
131
|
+
|
132
|
+
exp = "Running test: #{subject.single_test_file_line}\n"
|
133
|
+
assert_includes exp, @view_output
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
137
|
+
|
138
|
+
module CallbackMixin
|
139
|
+
attr_reader :on_start_called, :on_finish_called
|
140
|
+
attr_reader :before_test_called, :after_test_called, :on_result_called
|
141
|
+
|
142
|
+
def on_start
|
143
|
+
@on_start_called = true
|
144
|
+
end
|
145
|
+
|
146
|
+
def before_test(test)
|
147
|
+
@before_test_called ||= []
|
148
|
+
@before_test_called << test
|
149
|
+
end
|
150
|
+
|
151
|
+
def on_result(result)
|
152
|
+
@on_result_called ||= []
|
153
|
+
@on_result_called << result
|
154
|
+
end
|
155
|
+
|
156
|
+
def after_test(test)
|
157
|
+
@after_test_called ||= []
|
158
|
+
@after_test_called << test
|
159
|
+
end
|
160
|
+
|
161
|
+
def on_finish
|
162
|
+
@on_finish_called = true
|
41
163
|
end
|
42
164
|
|
43
165
|
end
|
data/test/unit/suite_tests.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'assert'
|
2
2
|
require 'assert/suite'
|
3
|
+
|
4
|
+
require 'assert/config_helpers'
|
3
5
|
require 'assert/test'
|
4
6
|
require 'test/support/inherited_stuff'
|
5
7
|
|
@@ -7,217 +9,106 @@ class Assert::Suite
|
|
7
9
|
|
8
10
|
class UnitTests < Assert::Context
|
9
11
|
desc "Assert::Suite"
|
10
|
-
|
11
|
-
@config = Factory.modes_off_config
|
12
|
-
@suite = Assert::Suite.new(@config)
|
13
|
-
end
|
14
|
-
subject{ @suite }
|
12
|
+
subject{ Assert::Suite }
|
15
13
|
|
16
|
-
should
|
17
|
-
|
18
|
-
should have_imeths :results, :ordered_results
|
19
|
-
should have_imeths :run_time, :test_rate, :result_rate
|
20
|
-
should have_imeths :count, :test_count, :result_count
|
21
|
-
should have_imeths :setup, :startup, :teardown, :shutdown
|
22
|
-
|
23
|
-
should "determine a klass' local public test methods" do
|
24
|
-
exp = ["test_subclass_stuff", "test_mixin_stuff", "test_repeated"].sort
|
25
|
-
act = subject.send(:local_public_test_methods, SubStuff).sort.map(&:to_s)
|
26
|
-
assert_equal(exp, act)
|
14
|
+
should "include the config helpers" do
|
15
|
+
assert_includes Assert::ConfigHelpers, subject
|
27
16
|
end
|
28
17
|
|
29
|
-
should "
|
30
|
-
|
31
|
-
|
32
|
-
assert_equal 0, subject.result_rate
|
18
|
+
should "know its test method regex" do
|
19
|
+
assert_match "test#{Factory.string}", subject::TEST_METHOD_REGEX
|
20
|
+
assert_not_match "#{Factory.string}test", subject::TEST_METHOD_REGEX
|
33
21
|
end
|
34
22
|
|
35
23
|
end
|
36
24
|
|
37
|
-
class
|
38
|
-
desc "
|
25
|
+
class InitTests < Assert::Context
|
26
|
+
desc "when init"
|
39
27
|
setup do
|
40
|
-
|
41
|
-
@suite
|
42
|
-
Factory.test("should nothing", ci){ },
|
43
|
-
Factory.test("should pass", ci){ assert(1==1); refute(1==0) },
|
44
|
-
Factory.test("should fail", ci){ ignore; assert(1==0); refute(1==1) },
|
45
|
-
Factory.test("should ignored", ci){ ignore },
|
46
|
-
Factory.test("should skip", ci){ skip; ignore; assert(1==1) },
|
47
|
-
Factory.test("should error", ci){ raise Exception; ignore; assert(1==1) }
|
48
|
-
]
|
49
|
-
@suite.tests.each(&:run)
|
50
|
-
end
|
51
|
-
|
52
|
-
should "build test instances to run" do
|
53
|
-
assert_kind_of Assert::Test, subject.tests.first
|
54
|
-
end
|
55
|
-
|
56
|
-
should "know how many tests it has" do
|
57
|
-
assert_equal 6, subject.test_count
|
58
|
-
end
|
59
|
-
|
60
|
-
should "know its ordered tests" do
|
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
|
67
|
-
end
|
68
|
-
|
69
|
-
should "know how many results it has" do
|
70
|
-
assert_equal 8, subject.result_count
|
71
|
-
end
|
72
|
-
|
73
|
-
should "know its ordered results" do
|
74
|
-
assert_equal subject.results, subject.ordered_results
|
75
|
-
end
|
76
|
-
|
77
|
-
should "know how many pass results it has" do
|
78
|
-
assert_equal 2, subject.result_count(:pass)
|
79
|
-
end
|
80
|
-
|
81
|
-
should "know how many fail results it has" do
|
82
|
-
assert_equal 2, subject.result_count(:fail)
|
83
|
-
end
|
84
|
-
|
85
|
-
should "know how many ignore results it has" do
|
86
|
-
assert_equal 2, subject.result_count(:ignore)
|
87
|
-
end
|
88
|
-
|
89
|
-
should "know how many skip results it has" do
|
90
|
-
assert_equal 1, subject.result_count(:skip)
|
91
|
-
end
|
92
|
-
|
93
|
-
should "know how many error results it has" do
|
94
|
-
assert_equal 1, subject.result_count(:error)
|
95
|
-
end
|
96
|
-
|
97
|
-
should "count its tests" do
|
98
|
-
assert_equal subject.test_count, subject.count(:tests)
|
99
|
-
end
|
100
|
-
|
101
|
-
should "count its results" do
|
102
|
-
assert_equal subject.result_count, subject.count(:results)
|
103
|
-
end
|
104
|
-
|
105
|
-
should "count its passed results" do
|
106
|
-
assert_equal subject.result_count(:pass), subject.count(:passed)
|
107
|
-
assert_equal subject.result_count(:pass), subject.count(:pass)
|
108
|
-
end
|
109
|
-
|
110
|
-
should "count its failed results" do
|
111
|
-
assert_equal subject.result_count(:fail), subject.count(:failed)
|
112
|
-
assert_equal subject.result_count(:fail), subject.count(:fail)
|
113
|
-
end
|
114
|
-
|
115
|
-
should "count its ignored results" do
|
116
|
-
assert_equal subject.result_count(:ignore), subject.count(:ignored)
|
117
|
-
assert_equal subject.result_count(:ignore), subject.count(:ignore)
|
118
|
-
end
|
119
|
-
|
120
|
-
should "count its skipped results" do
|
121
|
-
assert_equal subject.result_count(:skip), subject.count(:skipped)
|
122
|
-
assert_equal subject.result_count(:skip), subject.count(:skip)
|
123
|
-
end
|
124
|
-
|
125
|
-
should "count its errored results" do
|
126
|
-
assert_equal subject.result_count(:error), subject.count(:errored)
|
127
|
-
assert_equal subject.result_count(:error), subject.count(:error)
|
128
|
-
end
|
129
|
-
|
130
|
-
end
|
131
|
-
|
132
|
-
class SetupTests < UnitTests
|
133
|
-
desc "a suite with a setup block"
|
134
|
-
setup do
|
135
|
-
@setup_status = nil
|
136
|
-
@setup_blocks = []
|
137
|
-
@setup_blocks << ::Proc.new{ @setup_status = "setup" }
|
138
|
-
@setup_blocks << ::Proc.new{ @setup_status += " has been run" }
|
139
|
-
@setup_blocks.each{ |setup_block| @suite.setup(&setup_block) }
|
28
|
+
@config = Factory.modes_off_config
|
29
|
+
@suite = Assert::Suite.new(@config)
|
140
30
|
end
|
31
|
+
subject{ @suite }
|
141
32
|
|
142
|
-
should
|
143
|
-
|
144
|
-
|
145
|
-
|
33
|
+
should have_readers :config, :tests, :test_methods
|
34
|
+
should have_accessors :start_time, :end_time
|
35
|
+
should have_imeths :suite, :setup, :startup, :teardown, :shutdown
|
36
|
+
should have_imeths :run_time, :test_rate, :result_rate, :count
|
37
|
+
should have_imeths :ordered_tests, :reversed_tests
|
38
|
+
should have_imeths :ordered_tests_by_run_time, :reversed_tests_by_run_time
|
39
|
+
should have_imeths :test_count
|
40
|
+
should have_imeths :ordered_results, :reversed_results
|
41
|
+
should have_imeths :ordered_results_for_dump, :reversed_results_for_dump
|
42
|
+
should have_imeths :result_count
|
43
|
+
should have_imeths :before_load, :after_load
|
44
|
+
should have_imeths :on_start, :on_finish, :on_interrupt
|
45
|
+
should have_imeths :before_test, :after_test, :on_result
|
146
46
|
|
147
|
-
should "
|
148
|
-
@
|
149
|
-
assert_includes setup_block, subject.send(:setups)
|
150
|
-
end
|
47
|
+
should "know its config" do
|
48
|
+
assert_equal @config, subject.config
|
151
49
|
end
|
152
50
|
|
153
|
-
|
154
|
-
|
155
|
-
class TeardownTests < UnitTests
|
156
|
-
desc "a suite with a teardown"
|
157
|
-
setup do
|
158
|
-
@teardown_status = nil
|
159
|
-
@teardown_blocks = []
|
160
|
-
@teardown_blocks << ::Proc.new{ @teardown_status += " has been run" }
|
161
|
-
@teardown_blocks << ::Proc.new{ @teardown_status = "teardown" }
|
162
|
-
@teardown_blocks.each{ |teardown_block| @suite.teardown(&teardown_block) }
|
51
|
+
should "override the config helper's suite value with itself" do
|
52
|
+
assert_equal subject, subject.suite
|
163
53
|
end
|
164
54
|
|
165
|
-
should "
|
166
|
-
subject.
|
167
|
-
assert_equal
|
168
|
-
|
55
|
+
should "default its attrs" do
|
56
|
+
assert_equal [], subject.tests
|
57
|
+
assert_equal [], subject.test_methods
|
58
|
+
assert_equal [], subject.setups
|
59
|
+
assert_equal [], subject.teardowns
|
169
60
|
|
170
|
-
|
171
|
-
@teardown_blocks.each do |setup_block|
|
172
|
-
assert_includes setup_block, subject.send(:teardowns)
|
173
|
-
end
|
61
|
+
assert_equal subject.start_time, subject.end_time
|
174
62
|
end
|
175
63
|
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
setup do
|
181
|
-
@caller = caller
|
182
|
-
@klass = Assert::Context
|
183
|
-
@info = Assert::Suite::ContextInfo.new(@klass, nil, @caller.first)
|
184
|
-
end
|
185
|
-
subject{ @info }
|
64
|
+
should "know its run time and rates" do
|
65
|
+
assert_equal 0, subject.run_time
|
66
|
+
assert_equal 0, subject.test_rate
|
67
|
+
assert_equal 0, subject.result_rate
|
186
68
|
|
187
|
-
|
188
|
-
|
69
|
+
time = Factory.integer(3).to_f
|
70
|
+
subject.end_time = subject.start_time + time
|
71
|
+
count = Factory.integer(10)
|
72
|
+
Assert.stub(subject, :test_count){ count }
|
73
|
+
Assert.stub(subject, :result_count){ count }
|
189
74
|
|
190
|
-
|
191
|
-
assert_equal
|
75
|
+
assert_equal time, subject.run_time
|
76
|
+
assert_equal (subject.test_count / subject.run_time), subject.test_rate
|
77
|
+
assert_equal (subject.result_count / subject.run_time), subject.result_rate
|
192
78
|
end
|
193
79
|
|
194
|
-
should "
|
195
|
-
|
196
|
-
|
80
|
+
should "not provide any test or result attrs" do
|
81
|
+
assert_nil subject.ordered_tests
|
82
|
+
assert_nil subject.reversed_tests
|
83
|
+
assert_nil subject.ordered_tests_by_run_time
|
84
|
+
assert_nil subject.reversed_tests_by_run_time
|
85
|
+
assert_nil subject.test_count
|
197
86
|
|
198
|
-
|
199
|
-
|
87
|
+
assert_nil subject.ordered_results
|
88
|
+
assert_nil subject.reversed_results
|
89
|
+
assert_nil subject.ordered_results_for_dump
|
90
|
+
assert_nil subject.reversed_results_for_dump
|
91
|
+
assert_nil subject.result_count
|
200
92
|
end
|
201
93
|
|
202
|
-
should "
|
203
|
-
|
204
|
-
|
94
|
+
should "add setup procs" do
|
95
|
+
status = nil
|
96
|
+
@suite.setup{ status = "setups" }
|
97
|
+
@suite.startup{ status += " have been run" }
|
205
98
|
|
206
|
-
|
207
|
-
|
208
|
-
|
99
|
+
assert_equal 2, subject.setups.count
|
100
|
+
subject.setups.each(&:call)
|
101
|
+
assert_equal "setups have been run", status
|
209
102
|
end
|
210
103
|
|
211
|
-
should "
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
assert_equal name, subject.test_name(name)
|
216
|
-
assert_equal '', subject.test_name('')
|
217
|
-
assert_equal '', subject.test_name(nil)
|
104
|
+
should "add teardown procs" do
|
105
|
+
status = nil
|
106
|
+
@suite.teardown{ status = "teardowns" }
|
107
|
+
@suite.shutdown{ status += " have been run" }
|
218
108
|
|
219
|
-
|
220
|
-
|
109
|
+
assert_equal 2, subject.teardowns.count
|
110
|
+
subject.teardowns.each(&:call)
|
111
|
+
assert_equal "teardowns have been run", status
|
221
112
|
end
|
222
113
|
|
223
114
|
end
|