assert 2.17.0 → 2.18.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -2
- data/README.md +66 -41
- data/assert.gemspec +2 -3
- data/lib/assert.rb +0 -10
- data/lib/assert/actual_value.rb +127 -0
- data/lib/assert/assert_runner.rb +0 -3
- data/lib/assert/assertions.rb +10 -23
- data/lib/assert/cli.rb +30 -46
- data/lib/assert/config.rb +0 -4
- data/lib/assert/config_helpers.rb +0 -4
- data/lib/assert/context.rb +18 -9
- data/lib/assert/context/let_dsl.rb +13 -0
- data/lib/assert/context/method_missing.rb +19 -0
- data/lib/assert/context/setup_dsl.rb +0 -4
- data/lib/assert/context/subject_dsl.rb +23 -28
- data/lib/assert/context/suite_dsl.rb +0 -4
- data/lib/assert/context/test_dsl.rb +0 -4
- data/lib/assert/context_info.rb +0 -4
- data/lib/assert/default_runner.rb +0 -4
- data/lib/assert/default_suite.rb +0 -5
- data/lib/assert/default_view.rb +0 -4
- data/lib/assert/factory.rb +0 -3
- data/lib/assert/file_line.rb +0 -4
- data/lib/assert/macro.rb +0 -3
- data/lib/assert/macros/methods.rb +4 -10
- data/lib/assert/result.rb +2 -17
- data/lib/assert/runner.rb +0 -3
- data/lib/assert/stub.rb +15 -1
- data/lib/assert/suite.rb +0 -4
- data/lib/assert/test.rb +2 -7
- data/lib/assert/utils.rb +0 -4
- data/lib/assert/version.rb +1 -1
- data/lib/assert/view.rb +0 -3
- data/lib/assert/view_helpers.rb +0 -11
- data/log/{.gitkeep → .keep} +0 -0
- data/test/helper.rb +23 -29
- data/test/support/factory.rb +14 -0
- data/test/support/inherited_stuff.rb +0 -2
- data/test/system/stub_tests.rb +332 -352
- data/test/system/test_tests.rb +98 -124
- data/test/unit/actual_value_tests.rb +335 -0
- data/test/unit/assert_tests.rb +121 -46
- data/test/unit/assertions/assert_block_tests.rb +30 -35
- data/test/unit/assertions/assert_empty_tests.rb +33 -35
- data/test/unit/assertions/assert_equal_tests.rb +75 -83
- data/test/unit/assertions/assert_file_exists_tests.rb +32 -36
- data/test/unit/assertions/assert_includes_tests.rb +38 -41
- data/test/unit/assertions/assert_instance_of_tests.rb +34 -37
- data/test/unit/assertions/assert_kind_of_tests.rb +34 -37
- data/test/unit/assertions/assert_match_tests.rb +34 -37
- data/test/unit/assertions/assert_nil_tests.rb +30 -35
- data/test/unit/assertions/assert_raises_tests.rb +54 -60
- data/test/unit/assertions/assert_respond_to_tests.rb +36 -39
- data/test/unit/assertions/assert_same_tests.rb +86 -88
- data/test/unit/assertions/assert_true_false_tests.rb +60 -66
- data/test/unit/assertions_tests.rb +14 -17
- data/test/unit/config_helpers_tests.rb +41 -39
- data/test/unit/config_tests.rb +38 -37
- data/test/unit/context/let_dsl_tests.rb +10 -0
- data/test/unit/context/setup_dsl_tests.rb +68 -87
- data/test/unit/context/subject_dsl_tests.rb +15 -49
- data/test/unit/context/suite_dsl_tests.rb +15 -20
- data/test/unit/context/test_dsl_tests.rb +50 -57
- data/test/unit/context_info_tests.rb +23 -18
- data/test/unit/context_tests.rb +183 -194
- data/test/unit/default_runner_tests.rb +1 -7
- data/test/unit/default_suite_tests.rb +57 -56
- data/test/unit/factory_tests.rb +5 -6
- data/test/unit/file_line_tests.rb +33 -39
- data/test/unit/macro_tests.rb +14 -18
- data/test/unit/result_tests.rb +159 -196
- data/test/unit/runner_tests.rb +64 -71
- data/test/unit/suite_tests.rb +58 -59
- data/test/unit/test_tests.rb +125 -136
- data/test/unit/utils_tests.rb +43 -54
- data/test/unit/view_helpers_tests.rb +54 -58
- data/test/unit/view_tests.rb +22 -27
- metadata +15 -10
- data/tmp/.gitkeep +0 -0
data/test/unit/runner_tests.rb
CHANGED
@@ -8,27 +8,27 @@ require "assert/result"
|
|
8
8
|
require "assert/view"
|
9
9
|
|
10
10
|
class Assert::Runner
|
11
|
-
|
12
11
|
class UnitTests < Assert::Context
|
13
12
|
desc "Assert::Runner"
|
14
|
-
subject{
|
13
|
+
subject { unit_class }
|
14
|
+
|
15
|
+
let(:unit_class) { Assert::Runner }
|
15
16
|
|
16
17
|
should "include the config helpers" do
|
17
|
-
|
18
|
+
assert_that(subject).includes(Assert::ConfigHelpers)
|
18
19
|
end
|
19
|
-
|
20
20
|
end
|
21
21
|
|
22
22
|
class InitTests < UnitTests
|
23
23
|
desc "when init"
|
24
|
-
|
25
|
-
@config = Factory.modes_off_config
|
26
|
-
@config.suite Assert::DefaultSuite.new(@config)
|
27
|
-
@config.view Assert::View.new(@config, StringIO.new("", "w+"))
|
24
|
+
subject { unit_class.new(config1) }
|
28
25
|
|
29
|
-
|
26
|
+
setup do
|
27
|
+
config1.suite Assert::DefaultSuite.new(config1)
|
28
|
+
config1.view Assert::View.new(config1, StringIO.new("", "w+"))
|
30
29
|
end
|
31
|
-
|
30
|
+
|
31
|
+
let(:config1) { Factory.modes_off_config }
|
32
32
|
|
33
33
|
should have_readers :config
|
34
34
|
should have_imeths :runner, :run
|
@@ -37,120 +37,115 @@ class Assert::Runner
|
|
37
37
|
should have_imeths :before_test, :after_test, :on_result
|
38
38
|
|
39
39
|
should "know its config" do
|
40
|
-
|
40
|
+
assert_that(subject.config).equals(config1)
|
41
41
|
end
|
42
42
|
|
43
43
|
should "override the config helper's runner value with itself" do
|
44
|
-
|
44
|
+
assert_that(subject.runner).equals(subject)
|
45
45
|
end
|
46
|
-
|
47
46
|
end
|
48
47
|
|
49
48
|
class RunTests < InitTests
|
50
49
|
desc "and run"
|
51
|
-
|
52
|
-
callback_mixin = Module.new
|
53
|
-
@runner_class = Class.new(Assert::Runner) do
|
54
|
-
include CallbackMixin
|
55
|
-
end
|
56
|
-
suite_class = Class.new(Assert::DefaultSuite){ include CallbackMixin }
|
57
|
-
view_class = Class.new(Assert::View){ include CallbackMixin }
|
50
|
+
subject { runner_class1.new(config1) }
|
58
51
|
|
52
|
+
setup do
|
59
53
|
@view_output = ""
|
60
54
|
|
61
|
-
|
62
|
-
|
55
|
+
suite_class = Class.new(Assert::DefaultSuite){ include CallbackMixin }
|
56
|
+
view_class = Class.new(Assert::View){ include CallbackMixin }
|
63
57
|
|
64
|
-
|
65
|
-
|
66
|
-
|
58
|
+
config1.suite suite_class.new(config1)
|
59
|
+
config1.view view_class.new(config1, StringIO.new(@view_output, "w+"))
|
60
|
+
config1.suite.on_test(test1)
|
67
61
|
|
68
|
-
@
|
69
|
-
@result = @runner.run
|
62
|
+
@result_count = subject.run
|
70
63
|
end
|
71
64
|
|
65
|
+
let(:runner_class1) { Class.new(unit_class) { include CallbackMixin } }
|
66
|
+
let(:ci1) { Factory.context_info(Factory.modes_off_context_class) }
|
67
|
+
let(:test1) { Factory.test("should pass", ci1){ assert(1==1) } }
|
68
|
+
|
72
69
|
should "return the fail+error result count as an integer exit code" do
|
73
|
-
|
70
|
+
assert_that(@result_count).equals(0)
|
74
71
|
|
75
72
|
fail_count = Factory.integer
|
76
73
|
error_count = Factory.integer
|
77
74
|
Assert.stub(subject, :fail_result_count){ fail_count }
|
78
75
|
Assert.stub(subject, :error_result_count){ error_count }
|
79
|
-
Assert.stub(
|
80
|
-
|
76
|
+
Assert.stub(test1, :run){ } # no-op
|
77
|
+
result_count = subject.run
|
81
78
|
|
82
|
-
|
83
|
-
assert_equal exp, result
|
79
|
+
assert_that(result_count).equals(fail_count + error_count)
|
84
80
|
end
|
85
81
|
|
86
82
|
should "run all callbacks on itself, the suite and the view" do
|
87
83
|
# itself
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
84
|
+
assert_that(subject.on_start_called).is_true
|
85
|
+
assert_that(subject.before_test_called).equals([test1])
|
86
|
+
assert_that(subject.on_result_called.last).is_instance_of(Assert::Result::Pass)
|
87
|
+
assert_that(subject.after_test_called).equals([test1])
|
88
|
+
assert_that(subject.on_finish_called).is_true
|
93
89
|
|
94
90
|
# suite
|
95
|
-
suite =
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
91
|
+
suite = config1.suite
|
92
|
+
assert_that(suite.on_start_called).is_true
|
93
|
+
assert_that(suite.before_test_called).equals([test1])
|
94
|
+
assert_that(suite.on_result_called.last).is_instance_of(Assert::Result::Pass)
|
95
|
+
assert_that(suite.after_test_called).equals([test1])
|
96
|
+
assert_that(suite.on_finish_called).is_true
|
101
97
|
|
102
98
|
# view
|
103
|
-
view =
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
99
|
+
view = config1.view
|
100
|
+
assert_that(view.on_start_called).is_true
|
101
|
+
assert_that(view.before_test_called).equals([test1])
|
102
|
+
assert_that(view.on_result_called.last).is_instance_of(Assert::Result::Pass)
|
103
|
+
assert_that(view.after_test_called).equals([test1])
|
104
|
+
assert_that(view.on_finish_called).is_true
|
109
105
|
end
|
110
106
|
|
111
107
|
should "describe running the tests in random order if there are tests" do
|
112
108
|
exp = "Running tests in random order, " \
|
113
109
|
"seeded with \"#{subject.runner_seed}\"\n"
|
114
|
-
|
110
|
+
assert_that(@view_output).includes(exp)
|
115
111
|
|
116
112
|
@view_output.gsub!(/./, "")
|
117
|
-
|
113
|
+
config1.suite.clear_tests_to_run
|
118
114
|
subject.run
|
119
|
-
|
115
|
+
assert_that(@view_output).does_not_include(exp)
|
120
116
|
end
|
121
117
|
|
122
118
|
should "run only a single test if a single test is configured" do
|
123
|
-
test = Factory.test("should pass",
|
124
|
-
|
125
|
-
|
126
|
-
|
119
|
+
test = Factory.test("should pass", ci1){ assert(1==1) }
|
120
|
+
config1.suite.clear_tests_to_run
|
121
|
+
config1.suite.on_test(test)
|
122
|
+
config1.single_test test.file_line.to_s
|
127
123
|
|
128
|
-
runner =
|
129
|
-
|
124
|
+
runner = runner_class1.new(config1).tap(&:run)
|
125
|
+
assert_that(runner.before_test_called).equals([test])
|
130
126
|
end
|
131
127
|
|
132
128
|
should "not run any tests if a single test is configured but can't be found" do
|
133
|
-
test = Factory.test("should pass",
|
134
|
-
|
135
|
-
|
136
|
-
|
129
|
+
test = Factory.test("should pass", ci1){ assert(1==1) }
|
130
|
+
config1.suite.clear_tests_to_run
|
131
|
+
config1.suite.on_test(test)
|
132
|
+
config1.single_test Factory.string
|
137
133
|
|
138
|
-
runner =
|
139
|
-
|
134
|
+
runner = runner_class1.new(config1).tap(&:run)
|
135
|
+
assert_that(runner.before_test_called).is_nil
|
140
136
|
end
|
141
137
|
|
142
138
|
should "describe running only a single test if a single test is configured" do
|
143
|
-
|
144
|
-
|
145
|
-
|
139
|
+
config1.suite.clear_tests_to_run
|
140
|
+
config1.suite.on_test(test1)
|
141
|
+
config1.single_test test1.file_line.to_s
|
146
142
|
@view_output.gsub!(/./, "")
|
147
143
|
subject.run
|
148
144
|
|
149
145
|
exp = "Running test: #{subject.single_test_file_line}, " \
|
150
146
|
"seeded with \"#{subject.runner_seed}\"\n"
|
151
|
-
|
147
|
+
assert_that(@view_output).includes(exp)
|
152
148
|
end
|
153
|
-
|
154
149
|
end
|
155
150
|
|
156
151
|
module CallbackMixin
|
@@ -179,7 +174,5 @@ class Assert::Runner
|
|
179
174
|
def on_finish
|
180
175
|
@on_finish_called = true
|
181
176
|
end
|
182
|
-
|
183
177
|
end
|
184
|
-
|
185
178
|
end
|
data/test/unit/suite_tests.rb
CHANGED
@@ -6,29 +6,27 @@ require "assert/test"
|
|
6
6
|
require "test/support/inherited_stuff"
|
7
7
|
|
8
8
|
class Assert::Suite
|
9
|
-
|
10
9
|
class UnitTests < Assert::Context
|
11
10
|
desc "Assert::Suite"
|
12
|
-
subject{
|
11
|
+
subject { unit_class }
|
12
|
+
|
13
|
+
let(:unit_class) { Assert::Suite }
|
13
14
|
|
14
15
|
should "include the config helpers" do
|
15
|
-
|
16
|
+
assert_that(subject).includes(Assert::ConfigHelpers)
|
16
17
|
end
|
17
18
|
|
18
19
|
should "know its test method regex" do
|
19
|
-
|
20
|
-
|
20
|
+
assert_that(subject::TEST_METHOD_REGEX).matches("test#{Factory.string}")
|
21
|
+
assert_that(subject::TEST_METHOD_REGEX).does_not_match("#{Factory.string}test")
|
21
22
|
end
|
22
|
-
|
23
23
|
end
|
24
24
|
|
25
25
|
class InitTests < UnitTests
|
26
26
|
desc "when init"
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
31
|
-
subject{ @suite }
|
27
|
+
subject { unit_class.new(config1) }
|
28
|
+
|
29
|
+
let(:config1) { Factory.modes_off_config }
|
32
30
|
|
33
31
|
should have_readers :config, :test_methods, :setups, :teardowns
|
34
32
|
should have_accessors :start_time, :end_time
|
@@ -44,34 +42,34 @@ class Assert::Suite
|
|
44
42
|
should have_imeths :before_test, :after_test, :on_result
|
45
43
|
|
46
44
|
should "know its config" do
|
47
|
-
|
45
|
+
assert_that(subject.config).equals(config1)
|
48
46
|
end
|
49
47
|
|
50
48
|
should "default its attrs" do
|
51
|
-
|
52
|
-
|
53
|
-
|
49
|
+
assert_that(subject.test_methods).equals([])
|
50
|
+
assert_that(subject.setups).equals([])
|
51
|
+
assert_that(subject.teardowns).equals([])
|
54
52
|
|
55
|
-
|
53
|
+
assert_that(subject.end_time).equals(subject.start_time)
|
56
54
|
end
|
57
55
|
|
58
56
|
should "override the config helper's suite value with itself" do
|
59
|
-
|
57
|
+
assert_that(subject.suite).equals(subject)
|
60
58
|
end
|
61
59
|
|
62
60
|
should "not provide any test/result count implementations" do
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
61
|
+
assert_that(subject.test_count).is_nil
|
62
|
+
assert_that(subject.pass_result_count).is_nil
|
63
|
+
assert_that(subject.fail_result_count).is_nil
|
64
|
+
assert_that(subject.error_result_count).is_nil
|
65
|
+
assert_that(subject.skip_result_count).is_nil
|
66
|
+
assert_that(subject.ignore_result_count).is_nil
|
69
67
|
end
|
70
68
|
|
71
69
|
should "know its run time and rates" do
|
72
|
-
|
73
|
-
|
74
|
-
|
70
|
+
assert_that(subject.run_time).equals(0)
|
71
|
+
assert_that(subject.test_rate).equals(0)
|
72
|
+
assert_that(subject.result_rate).equals(0)
|
75
73
|
|
76
74
|
time = Factory.integer(3).to_f
|
77
75
|
subject.end_time = subject.start_time + time
|
@@ -79,70 +77,71 @@ class Assert::Suite
|
|
79
77
|
Assert.stub(subject, :test_count){ count }
|
80
78
|
Assert.stub(subject, :result_count){ count }
|
81
79
|
|
82
|
-
|
83
|
-
|
84
|
-
|
80
|
+
assert_that(subject.run_time).equals(time)
|
81
|
+
assert_that(subject.test_rate).equals((subject.test_count / subject.run_time))
|
82
|
+
assert_that(subject.result_rate).equals((subject.result_count / subject.run_time))
|
85
83
|
end
|
86
84
|
|
87
85
|
should "add setup procs" do
|
88
86
|
status = nil
|
89
|
-
|
90
|
-
|
87
|
+
subject.setup{ status = "setups" }
|
88
|
+
subject.startup{ status += " have been run" }
|
91
89
|
|
92
|
-
|
90
|
+
assert_that(subject.setups.count).equals(2)
|
93
91
|
subject.setups.each(&:call)
|
94
|
-
|
92
|
+
assert_that(status).equals("setups have been run")
|
95
93
|
end
|
96
94
|
|
97
95
|
should "add teardown procs" do
|
98
96
|
status = nil
|
99
|
-
|
100
|
-
|
97
|
+
subject.teardown{ status = "teardowns" }
|
98
|
+
subject.shutdown{ status += " have been run" }
|
101
99
|
|
102
|
-
|
100
|
+
assert_that(subject.teardowns.count).equals(2)
|
103
101
|
subject.teardowns.each(&:call)
|
104
|
-
|
102
|
+
assert_that(status).equals("teardowns have been run")
|
105
103
|
end
|
106
|
-
|
107
104
|
end
|
108
105
|
|
109
106
|
class WithTestsLoadedTests < InitTests
|
110
107
|
desc "with tests loaded"
|
108
|
+
|
111
109
|
setup do
|
112
|
-
|
113
|
-
@tests = [
|
114
|
-
Factory.test("should nothing", ci.call){ },
|
115
|
-
Factory.test("should pass", ci.call){ assert(1==1); refute(1==0) },
|
116
|
-
Factory.test("should fail", ci.call){ ignore; assert(1==0); refute(1==1) },
|
117
|
-
Factory.test("should ignore", ci.call){ ignore },
|
118
|
-
Factory.test("should skip", ci.call){ skip; ignore; assert(1==1) },
|
119
|
-
Factory.test("should error", ci.call){ raise Exception; ignore; assert(1==1) }
|
120
|
-
]
|
121
|
-
@tests.each{ |test| @suite.on_test(test) }
|
110
|
+
tests1.each{ |test| subject.on_test(test) }
|
122
111
|
end
|
123
112
|
|
113
|
+
let(:ci1) { proc{ Factory.context_info(Factory.modes_off_context_class) } }
|
114
|
+
let(:tests1) {
|
115
|
+
[
|
116
|
+
Factory.test("should nothing", ci1.call){ },
|
117
|
+
Factory.test("should pass", ci1.call){ assert(1==1); refute(1==0) },
|
118
|
+
Factory.test("should fail", ci1.call){ ignore; assert(1==0); refute(1==1) },
|
119
|
+
Factory.test("should ignore", ci1.call){ ignore },
|
120
|
+
Factory.test("should skip", ci1.call){ skip; ignore; assert(1==1) },
|
121
|
+
Factory.test("should error", ci1.call){ raise Exception; ignore; assert(1==1) }
|
122
|
+
]
|
123
|
+
}
|
124
|
+
|
124
125
|
should "know its tests-to-run attrs" do
|
125
|
-
|
126
|
-
|
126
|
+
assert_that(subject.tests_to_run_count).equals(tests1.size)
|
127
|
+
assert_that(subject.tests_to_run?).is_true
|
127
128
|
|
128
129
|
subject.clear_tests_to_run
|
129
130
|
|
130
|
-
|
131
|
-
|
131
|
+
assert_that(subject.tests_to_run_count).equals(0)
|
132
|
+
assert_that(subject.tests_to_run?).is_false
|
132
133
|
end
|
133
134
|
|
134
135
|
should "find a test to run given a file line" do
|
135
|
-
test =
|
136
|
-
|
136
|
+
test = tests1.sample
|
137
|
+
assert_that(subject.find_test_to_run(test.file_line)).is_the_same_as(test)
|
137
138
|
end
|
138
139
|
|
139
140
|
should "know its sorted tests to run" do
|
140
141
|
sorted_tests = subject.sorted_tests_to_run{ 1 }
|
141
|
-
|
142
|
-
|
143
|
-
|
142
|
+
assert_that(sorted_tests.size).equals(tests1.size)
|
143
|
+
assert_that(sorted_tests.first).is_kind_of(Assert::Test)
|
144
|
+
assert_that(subject.sorted_tests_to_run{ 1 }.first).is_the_same_as(sorted_tests.first)
|
144
145
|
end
|
145
|
-
|
146
146
|
end
|
147
|
-
|
148
147
|
end
|
data/test/unit/test_tests.rb
CHANGED
@@ -6,125 +6,124 @@ require "assert/file_line"
|
|
6
6
|
require "assert/result"
|
7
7
|
|
8
8
|
class Assert::Test
|
9
|
-
|
10
9
|
class UnitTests < Assert::Context
|
11
10
|
desc "Assert::Test"
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
11
|
+
subject { unit_class }
|
12
|
+
|
13
|
+
let(:unit_class) { Assert::Test }
|
14
|
+
|
15
|
+
let(:context_class1) { Factory.modes_off_context_class { desc "context class" } }
|
16
|
+
let(:context_info1) { Factory.context_info(context_class1) }
|
17
|
+
let(:config1) { Factory.modes_off_config }
|
18
|
+
let(:test_code1) { proc { assert(true) } }
|
19
19
|
|
20
20
|
should have_imeths :name_file_line_context_data, :for_block, :for_method
|
21
21
|
|
22
22
|
should "know how to build the name and file line given context" do
|
23
23
|
test_name = Factory.string
|
24
|
-
data = subject.name_file_line_context_data(
|
24
|
+
data = subject.name_file_line_context_data(context_info1, test_name)
|
25
25
|
|
26
|
-
exp =
|
27
|
-
|
26
|
+
exp = context_info1.test_name(test_name)
|
27
|
+
assert_that(data[:name]).equals(exp)
|
28
28
|
|
29
|
-
exp =
|
30
|
-
|
29
|
+
exp = context_info1.called_from
|
30
|
+
assert_that(data[:file_line]).equals(exp)
|
31
31
|
end
|
32
32
|
|
33
33
|
should "build tests for a block" do
|
34
34
|
name = Factory.string
|
35
|
-
test = subject.for_block(name,
|
35
|
+
test = subject.for_block(name, context_info1, config1, &test_code1)
|
36
36
|
|
37
|
-
exp = Assert::FileLine.parse(
|
38
|
-
|
37
|
+
exp = Assert::FileLine.parse(context_info1.called_from)
|
38
|
+
assert_that(test.file_line).equals(exp)
|
39
39
|
|
40
|
-
exp =
|
41
|
-
|
40
|
+
exp = context_info1.test_name(name)
|
41
|
+
assert_that(test.name).equals(exp)
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
|
43
|
+
assert_that(test.context_info).equals(context_info1)
|
44
|
+
assert_that(test.config).equals(config1)
|
45
|
+
assert_that(test.code).equals(test_code1)
|
46
46
|
end
|
47
47
|
|
48
48
|
should "build tests for a method" do
|
49
49
|
meth = "a_test_method"
|
50
|
-
test = subject.for_method(meth,
|
50
|
+
test = subject.for_method(meth, context_info1, config1)
|
51
51
|
|
52
|
-
exp = Assert::FileLine.parse(
|
53
|
-
|
52
|
+
exp = Assert::FileLine.parse(context_info1.called_from)
|
53
|
+
assert_that(test.file_line).equals(exp)
|
54
54
|
|
55
|
-
exp =
|
56
|
-
|
55
|
+
exp = context_info1.test_name(meth)
|
56
|
+
assert_that(test.name).equals(exp)
|
57
57
|
|
58
|
-
|
59
|
-
|
58
|
+
assert_that(test.context_info).equals(context_info1)
|
59
|
+
assert_that(test.config).equals(config1)
|
60
60
|
|
61
|
-
|
61
|
+
assert_that(test.code).is_kind_of(Proc)
|
62
62
|
self.instance_eval(&test.code)
|
63
|
-
|
63
|
+
assert_that(@a_test_method_called).is_true
|
64
64
|
end
|
65
65
|
|
66
66
|
def a_test_method
|
67
67
|
@a_test_method_called = true
|
68
68
|
end
|
69
|
-
|
70
69
|
end
|
71
70
|
|
72
71
|
class InitWithDataTests < UnitTests
|
73
72
|
desc "when init with data"
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
73
|
+
subject { unit_class.new(meta_data1.merge(run_data1)) }
|
74
|
+
|
75
|
+
let(:file_line1) { Assert::FileLine.new(Factory.string, Factory.integer.to_s) }
|
76
|
+
let(:meta_data1) {
|
77
|
+
{
|
78
|
+
:file_line => file_line1.to_s,
|
78
79
|
:name => Factory.string,
|
79
80
|
:output => Factory.string,
|
80
81
|
:run_time => Factory.float(1.0),
|
81
82
|
}
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
:
|
86
|
-
:
|
83
|
+
}
|
84
|
+
let(:run_data1) {
|
85
|
+
{
|
86
|
+
:context_info => context_info1,
|
87
|
+
:config => config1,
|
88
|
+
:code => test_code1
|
87
89
|
}
|
88
|
-
|
89
|
-
@test = Assert::Test.new(@meta_data.merge(@run_data))
|
90
|
-
end
|
91
|
-
subject{ @test }
|
90
|
+
}
|
92
91
|
|
93
92
|
should have_imeths :file_line, :file_name, :line_num
|
94
93
|
should have_imeths :name, :output, :run_time
|
95
94
|
should have_imeths :context_info, :context_class, :config, :code, :run
|
96
95
|
|
97
96
|
should "use any given attrs" do
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
97
|
+
assert_that(subject.file_line).equals(file_line1)
|
98
|
+
assert_that(subject.name).equals(meta_data1[:name])
|
99
|
+
assert_that(subject.output).equals(meta_data1[:output])
|
100
|
+
assert_that(subject.run_time).equals(meta_data1[:run_time])
|
102
101
|
|
103
|
-
|
104
|
-
|
105
|
-
|
102
|
+
assert_that(subject.context_info).equals(context_info1)
|
103
|
+
assert_that(subject.config).equals(config1)
|
104
|
+
assert_that(subject.code).equals(test_code1)
|
106
105
|
end
|
107
106
|
|
108
107
|
should "default its attrs" do
|
109
|
-
test =
|
108
|
+
test = unit_class.new
|
110
109
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
110
|
+
assert_that(test.file_line).equals(Assert::FileLine.parse(""))
|
111
|
+
assert_that(test.name).equals("")
|
112
|
+
assert_that(test.output).equals("")
|
113
|
+
assert_that(test.run_time).equals(0)
|
115
114
|
|
116
|
-
|
117
|
-
|
118
|
-
|
115
|
+
assert_that(test.context_info).is_nil
|
116
|
+
assert_that(test.config).is_nil
|
117
|
+
assert_that(test.code).is_nil
|
119
118
|
end
|
120
119
|
|
121
120
|
should "know its context class" do
|
122
|
-
|
121
|
+
assert_that(subject.context_class).equals(context_class1)
|
123
122
|
end
|
124
123
|
|
125
124
|
should "know its file line attrs" do
|
126
|
-
|
127
|
-
|
125
|
+
assert_that(subject.file_name).equals(subject.file_line.file)
|
126
|
+
assert_that(subject.line_num).equals(subject.file_line.line.to_i)
|
128
127
|
end
|
129
128
|
|
130
129
|
should "have a custom inspect that only shows limited attributes" do
|
@@ -132,62 +131,62 @@ class Assert::Test
|
|
132
131
|
"@#{method}=#{subject.send(method).inspect}"
|
133
132
|
end.join(" ")
|
134
133
|
exp = "#<#{subject.class}:#{"0x0%x" % (subject.object_id << 1)} #{attrs}>"
|
135
|
-
|
134
|
+
assert_that(subject.inspect).equals(exp)
|
136
135
|
end
|
137
|
-
|
138
136
|
end
|
139
137
|
|
140
138
|
class PassFailIgnoreHandlingTests < UnitTests
|
141
139
|
include Assert::Test::TestHelpers
|
142
140
|
|
143
|
-
|
144
|
-
|
141
|
+
subject {
|
142
|
+
Factory.test("pass fail ignore test", context_info1) do
|
145
143
|
ignore("something")
|
146
144
|
assert(true)
|
147
145
|
assert(false)
|
148
146
|
end
|
149
|
-
|
147
|
+
}
|
148
|
+
|
149
|
+
setup do
|
150
|
+
subject.context_class.setup do
|
150
151
|
ignore("something")
|
151
152
|
assert(true)
|
152
153
|
assert(false)
|
153
154
|
end
|
154
|
-
|
155
|
+
subject.context_class.teardown do
|
155
156
|
ignore("something")
|
156
157
|
assert(true)
|
157
158
|
assert(false)
|
158
159
|
end
|
159
|
-
|
160
|
+
subject.run(&test_run_callback)
|
160
161
|
end
|
161
|
-
subject{ @test }
|
162
162
|
|
163
163
|
should "capture results in the test and any setups/teardowns" do
|
164
|
-
|
164
|
+
assert_that(test_run_results.size).equals(9)
|
165
165
|
test_run_results.each do |result|
|
166
|
-
|
166
|
+
assert_that(result).is_kind_of(Assert::Result::Base)
|
167
167
|
end
|
168
168
|
end
|
169
169
|
|
170
170
|
should "capture pass results in the test and any setups/teardowns" do
|
171
|
-
|
171
|
+
assert_that(test_run_results(:pass).size).equals(3)
|
172
172
|
test_run_results(:pass).each do |result|
|
173
|
-
|
173
|
+
assert_that(result).is_kind_of(Assert::Result::Pass)
|
174
174
|
end
|
175
175
|
end
|
176
176
|
|
177
177
|
should "capture fail results in the test and any setups/teardowns" do
|
178
|
-
|
178
|
+
assert_that(test_run_results(:fail).size).equals(3)
|
179
179
|
test_run_results(:fail).each do |result|
|
180
|
-
|
180
|
+
assert_that(result).is_kind_of(Assert::Result::Fail)
|
181
181
|
end
|
182
182
|
end
|
183
183
|
|
184
184
|
should "capture ignore results in the test and any setups/teardowns" do
|
185
|
-
|
185
|
+
assert_that(test_run_results(:ignore).size).equals(3)
|
186
186
|
test_run_results(:ignore).each do |result|
|
187
|
-
|
187
|
+
assert_that(result).is_kind_of(Assert::Result::Ignore)
|
188
188
|
end
|
189
189
|
end
|
190
|
-
|
191
190
|
end
|
192
191
|
|
193
192
|
class FailHandlingTests < UnitTests
|
@@ -196,7 +195,7 @@ class Assert::Test
|
|
196
195
|
desc "when in halt-on-fail mode"
|
197
196
|
|
198
197
|
should "capture fail results" do
|
199
|
-
test = Factory.test("halt-on-fail test",
|
198
|
+
test = Factory.test("halt-on-fail test", context_info1) do
|
200
199
|
raise Assert::Result::TestFailure
|
201
200
|
end
|
202
201
|
test.run(&test_run_callback)
|
@@ -205,7 +204,7 @@ class Assert::Test
|
|
205
204
|
end
|
206
205
|
|
207
206
|
should "capture fails in the context setup" do
|
208
|
-
test = Factory.test("setup halt-on-fail test",
|
207
|
+
test = Factory.test("setup halt-on-fail test", context_info1){ }
|
209
208
|
test.context_class.setup{ raise Assert::Result::TestFailure }
|
210
209
|
test.run(&test_run_callback)
|
211
210
|
|
@@ -213,7 +212,7 @@ class Assert::Test
|
|
213
212
|
end
|
214
213
|
|
215
214
|
should "capture fails in the context teardown" do
|
216
|
-
test = Factory.test("teardown halt-on-fail test",
|
215
|
+
test = Factory.test("teardown halt-on-fail test", context_info1){ }
|
217
216
|
test.context_class.teardown{ raise Assert::Result::TestFailure }
|
218
217
|
test.run(&test_run_callback)
|
219
218
|
|
@@ -224,27 +223,26 @@ class Assert::Test
|
|
224
223
|
|
225
224
|
def assert_failed(test)
|
226
225
|
with_backtrace(caller) do
|
227
|
-
|
226
|
+
assert_that(test_run_result_count).equals(1, "too many/few fail results")
|
228
227
|
test_run_results.each do |result|
|
229
|
-
|
228
|
+
assert_that(result).is_kind_of(Assert::Result::Fail, "not a fail result")
|
230
229
|
end
|
231
230
|
end
|
232
231
|
end
|
233
|
-
|
234
232
|
end
|
235
233
|
|
236
234
|
class SkipHandlingTests < UnitTests
|
237
235
|
include Assert::Test::TestHelpers
|
238
236
|
|
239
237
|
should "capture skip results" do
|
240
|
-
test = Factory.test("skip test",
|
238
|
+
test = Factory.test("skip test", context_info1){ skip }
|
241
239
|
test.run(&test_run_callback)
|
242
240
|
|
243
241
|
assert_skipped(test)
|
244
242
|
end
|
245
243
|
|
246
244
|
should "capture skips in the context setup" do
|
247
|
-
test = Factory.test("setup skip test",
|
245
|
+
test = Factory.test("setup skip test", context_info1){ }
|
248
246
|
test.context_class.setup{ skip }
|
249
247
|
test.run(&test_run_callback)
|
250
248
|
|
@@ -252,7 +250,7 @@ class Assert::Test
|
|
252
250
|
end
|
253
251
|
|
254
252
|
should "capture skips in the context teardown" do
|
255
|
-
test = Factory.test("teardown skip test",
|
253
|
+
test = Factory.test("teardown skip test", context_info1){ }
|
256
254
|
test.context_class.teardown{ skip }
|
257
255
|
test.run(&test_run_callback)
|
258
256
|
|
@@ -263,20 +261,19 @@ class Assert::Test
|
|
263
261
|
|
264
262
|
def assert_skipped(test)
|
265
263
|
with_backtrace(caller) do
|
266
|
-
|
264
|
+
assert_that(test_run_result_count).equals(1, "too many/few skip results")
|
267
265
|
test_run_results.each do |result|
|
268
|
-
|
266
|
+
assert_that(result).is_kind_of(Assert::Result::Skip, "not a skip result")
|
269
267
|
end
|
270
268
|
end
|
271
269
|
end
|
272
|
-
|
273
270
|
end
|
274
271
|
|
275
272
|
class ErrorHandlingTests < UnitTests
|
276
273
|
include Assert::Test::TestHelpers
|
277
274
|
|
278
275
|
should "capture error results" do
|
279
|
-
test = Factory.test("error test",
|
276
|
+
test = Factory.test("error test", context_info1) do
|
280
277
|
raise StandardError, "WHAT"
|
281
278
|
end
|
282
279
|
test.run(&test_run_callback)
|
@@ -285,7 +282,7 @@ class Assert::Test
|
|
285
282
|
end
|
286
283
|
|
287
284
|
should "capture errors in the context setup" do
|
288
|
-
test = Factory.test("setup error test",
|
285
|
+
test = Factory.test("setup error test", context_info1){ }
|
289
286
|
test.context_class.setup{ raise "an error" }
|
290
287
|
test.run(&test_run_callback)
|
291
288
|
|
@@ -293,7 +290,7 @@ class Assert::Test
|
|
293
290
|
end
|
294
291
|
|
295
292
|
should "capture errors in the context teardown" do
|
296
|
-
test = Factory.test("teardown error test",
|
293
|
+
test = Factory.test("teardown error test", context_info1){ }
|
297
294
|
test.context_class.teardown{ raise "an error" }
|
298
295
|
test.run(&test_run_callback)
|
299
296
|
|
@@ -304,106 +301,98 @@ class Assert::Test
|
|
304
301
|
|
305
302
|
def assert_errored(test)
|
306
303
|
with_backtrace(caller) do
|
307
|
-
|
304
|
+
assert_that(test_run_result_count).equals(1, "too many/few error results")
|
308
305
|
test_run_results.each do |result|
|
309
|
-
|
306
|
+
assert_that(result).is_kind_of(Assert::Result::Error, "not an error result")
|
310
307
|
end
|
311
308
|
end
|
312
309
|
end
|
313
|
-
|
314
310
|
end
|
315
311
|
|
316
312
|
class SignalExceptionHandlingTests < UnitTests
|
317
|
-
|
318
313
|
should "raise any signal exceptions and not capture as an error" do
|
319
|
-
test = Factory.test("signal test",
|
314
|
+
test = Factory.test("signal test", context_info1) do
|
320
315
|
raise SignalException, "USR1"
|
321
316
|
end
|
322
317
|
|
323
|
-
|
318
|
+
assert_that(-> { test.run }).raises(SignalException)
|
324
319
|
end
|
325
320
|
|
326
321
|
should "raises signal exceptions in the context setup" do
|
327
|
-
test = Factory.test("setup signal test",
|
322
|
+
test = Factory.test("setup signal test", context_info1){ }
|
328
323
|
test.context_class.setup{ raise SignalException, "INT" }
|
329
324
|
|
330
|
-
|
325
|
+
assert_that(-> { test.run }).raises(SignalException)
|
331
326
|
end
|
332
327
|
|
333
328
|
should "raises signal exceptions in the context teardown" do
|
334
|
-
test = Factory.test("teardown signal test",
|
329
|
+
test = Factory.test("teardown signal test", context_info1){ }
|
335
330
|
test.context_class.teardown{ raise SignalException, "TERM" }
|
336
331
|
|
337
|
-
|
332
|
+
assert_that(-> { test.run }).raises(SignalException)
|
338
333
|
end
|
339
|
-
|
340
334
|
end
|
341
335
|
|
342
336
|
class ComparingTests < UnitTests
|
343
337
|
desc "<=> another test"
|
344
|
-
|
345
|
-
@test = Factory.test("mmm")
|
346
|
-
end
|
347
|
-
subject{ @test }
|
338
|
+
subject { Factory.test("mmm") }
|
348
339
|
|
349
340
|
should "return 1 with a test named 'aaa' (greater than it)" do
|
350
|
-
|
351
|
-
assert_equal(1, result)
|
341
|
+
assert_that(subject <=> Factory.test("aaa")).equals(1)
|
352
342
|
end
|
353
343
|
|
354
344
|
should "return 0 with a test named the same" do
|
355
|
-
|
356
|
-
assert_equal(0, result)
|
345
|
+
assert_that(subject <=> Factory.test(subject.name)).equals(0)
|
357
346
|
end
|
358
347
|
|
359
348
|
should "return -1 with a test named 'zzz' (less than it)" do
|
360
|
-
|
361
|
-
assert_equal(-1, result)
|
349
|
+
assert_that(subject <=> Factory.test("zzz")).equals(-1)
|
362
350
|
end
|
363
|
-
|
364
351
|
end
|
365
352
|
|
366
353
|
class CaptureOutTests < UnitTests
|
367
354
|
desc "when capturing std out"
|
368
|
-
|
369
|
-
|
370
|
-
@test = Factory.test("stdout", @capture_config) do
|
355
|
+
subject {
|
356
|
+
Factory.test("stdout", capture_config1) do
|
371
357
|
puts "std out from the test"
|
372
358
|
assert true
|
373
359
|
end
|
374
|
-
|
360
|
+
}
|
361
|
+
|
362
|
+
let(:capture_config1) { Assert::Config.new(:capture_output => true) }
|
375
363
|
|
376
364
|
should "capture any io from the test" do
|
377
|
-
|
378
|
-
|
365
|
+
subject.run
|
366
|
+
assert_that(subject.output).equals("std out from the test\n")
|
379
367
|
end
|
380
|
-
|
381
368
|
end
|
382
369
|
|
383
370
|
class FullCaptureOutTests < CaptureOutTests
|
384
371
|
desc "across setup, teardown, and meth calls"
|
385
|
-
|
386
|
-
|
372
|
+
subject {
|
373
|
+
Factory.test("fullstdouttest", capture_config1) do
|
387
374
|
puts "std out from the test"
|
388
375
|
assert a_method_an_assert_calls
|
389
376
|
end
|
390
|
-
|
391
|
-
|
392
|
-
|
377
|
+
}
|
378
|
+
|
379
|
+
setup do
|
380
|
+
subject.context_class.setup{ puts "std out from the setup" }
|
381
|
+
subject.context_class.teardown{ puts "std out from the teardown" }
|
382
|
+
subject.context_class.send(:define_method, "a_method_an_assert_calls") do
|
393
383
|
puts "std out from a method an assert called"
|
394
384
|
end
|
395
385
|
end
|
396
386
|
|
397
387
|
should "collect all stdout in the output accessor" do
|
398
|
-
|
388
|
+
subject.run
|
399
389
|
|
400
|
-
exp_out =
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
390
|
+
exp_out =
|
391
|
+
"std out from the setup\n"\
|
392
|
+
"std out from the test\n"\
|
393
|
+
"std out from a method an assert called\n"\
|
394
|
+
"std out from the teardown\n"
|
395
|
+
assert_that(subject.output).equals(exp_out)
|
405
396
|
end
|
406
|
-
|
407
397
|
end
|
408
|
-
|
409
398
|
end
|