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