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