assert 2.18.2 → 2.19.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/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
@@ -1,72 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "assert"
|
2
4
|
require "assert/context/subject_dsl"
|
3
5
|
|
4
6
|
module Assert::Context::SubjectDSL
|
5
|
-
|
6
7
|
class UnitTests < Assert::Context
|
7
8
|
desc "Assert::Context::SubjectDSL"
|
8
|
-
subject{
|
9
|
-
end
|
9
|
+
subject { Factory.modes_off_context_class(parent_class1) }
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
setup do
|
14
|
-
descs = @descs = ["something amazing", "it really is"]
|
15
|
-
@context_class = Factory.modes_off_context_class do
|
16
|
-
descs.each{ |text| desc text }
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
should "return a collection containing any descriptions defined on the class" do
|
21
|
-
assert_equal @descs, subject.send(:descriptions)
|
22
|
-
end
|
11
|
+
let(:parent_class1) { Factory.modes_off_context_class }
|
12
|
+
let(:subject_block1) { Proc.new {} }
|
23
13
|
end
|
24
14
|
|
25
15
|
class DescriptionTests < UnitTests
|
26
16
|
desc "`description` method"
|
27
|
-
setup do
|
28
|
-
parent_text = @parent_desc = "parent description"
|
29
|
-
@parent_class = Factory.modes_off_context_class do
|
30
|
-
desc parent_text
|
31
|
-
end
|
32
|
-
text = @desc = "and the description for this context"
|
33
|
-
@context_class = Factory.modes_off_context_class(@parent_class) do
|
34
|
-
desc text
|
35
|
-
end
|
36
|
-
end
|
37
17
|
|
38
18
|
should "return a string of all the inherited descriptions" do
|
39
|
-
|
40
|
-
|
19
|
+
parent_class1.desc("parent description")
|
20
|
+
subject.desc("and the description for this context")
|
21
|
+
|
22
|
+
exp = "parent description and the description for this context"
|
23
|
+
assert_that(subject.description).equals(exp)
|
41
24
|
end
|
42
25
|
end
|
43
26
|
|
44
27
|
class SubjectFromLocalTests < UnitTests
|
45
28
|
desc "`subject` method using local context"
|
46
|
-
setup do
|
47
|
-
subject_block = @subject_block = ::Proc.new{ @something }
|
48
|
-
@context_class = Factory.modes_off_context_class do
|
49
|
-
subject(&subject_block)
|
50
|
-
end
|
51
|
-
end
|
52
29
|
|
53
30
|
should "set the subject block on the context class" do
|
54
|
-
|
31
|
+
subject.subject(&subject_block1)
|
32
|
+
|
33
|
+
assert_that(subject.subject).equals(subject_block1)
|
55
34
|
end
|
56
35
|
end
|
57
36
|
|
58
37
|
class SubjectFromParentTests < UnitTests
|
59
38
|
desc "`subject` method using parent context"
|
60
|
-
setup do
|
61
|
-
parent_block = @parent_block = ::Proc.new{ @something }
|
62
|
-
@parent_class = Factory.modes_off_context_class do
|
63
|
-
subject(&parent_block)
|
64
|
-
end
|
65
|
-
@context_class = Factory.modes_off_context_class(@parent_class)
|
66
|
-
end
|
67
39
|
|
68
|
-
should "default to
|
69
|
-
|
40
|
+
should "default to its parents subject block" do
|
41
|
+
parent_class1.subject(&subject_block1)
|
42
|
+
|
43
|
+
assert_that(subject.subject).equals(subject_block1)
|
70
44
|
end
|
71
45
|
end
|
72
46
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "assert"
|
2
4
|
require "assert/context/suite_dsl"
|
3
5
|
|
@@ -6,38 +8,37 @@ require "assert/suite"
|
|
6
8
|
module Assert::Context::SuiteDSL
|
7
9
|
class UnitTests < Assert::Context
|
8
10
|
desc "Assert::Context::SuiteDSL"
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
subject{ @context_class }
|
11
|
+
subject { Factory.context_class(parent_class1) }
|
12
|
+
|
13
|
+
let(:parent_class1) { Factory.context_class }
|
14
|
+
let(:custom_suite1) { Factory.modes_off_suite }
|
14
15
|
|
15
16
|
should "use `Assert.suite` by default" do
|
16
|
-
|
17
|
+
assert_that(subject.suite).equals(Assert.suite)
|
17
18
|
end
|
18
19
|
|
19
20
|
should "use any given custom suite" do
|
20
|
-
subject.suite(
|
21
|
-
|
21
|
+
subject.suite(custom_suite1)
|
22
|
+
assert_that(subject.suite).equals(custom_suite1)
|
22
23
|
end
|
23
24
|
end
|
24
25
|
|
25
26
|
class SuiteFromParentTests < UnitTests
|
26
27
|
desc "`suite` method using parent context"
|
28
|
+
|
27
29
|
setup do
|
28
|
-
|
29
|
-
@parent_class.suite(@custom_suite)
|
30
|
-
@context_class = Factory.context_class(@parent_class)
|
30
|
+
parent_class1.suite(custom_suite1)
|
31
31
|
end
|
32
32
|
|
33
|
-
|
34
|
-
|
33
|
+
let(:custom_suite2) { Factory.modes_off_suite }
|
34
|
+
|
35
|
+
should "default to its parent's suite" do
|
36
|
+
assert_that(subject.suite).equals(custom_suite1)
|
35
37
|
end
|
36
38
|
|
37
39
|
should "use any given custom suite" do
|
38
|
-
|
39
|
-
subject.suite(
|
40
|
-
assert_equal another_suite, subject.suite
|
40
|
+
subject.suite(custom_suite2)
|
41
|
+
assert_that(subject.suite).equals(custom_suite2)
|
41
42
|
end
|
42
43
|
end
|
43
44
|
end
|
@@ -1,151 +1,151 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "assert"
|
2
4
|
require "assert/context/test_dsl"
|
3
5
|
|
4
6
|
module Assert::Context::TestDSL
|
5
7
|
class UnitTests < Assert::Context
|
6
8
|
desc "Assert::Context::TestDSL"
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
9
|
+
|
10
|
+
let(:test_desc1) { "be true" }
|
11
|
+
let(:test_block1) { Proc.new{ assert(true) } }
|
11
12
|
|
12
13
|
should "build a test using `test` with a desc and code block" do
|
13
|
-
d, b =
|
14
|
+
d, b = test_desc1, test_block1
|
14
15
|
context, test = build_eval_context{ test(d, &b) }
|
15
16
|
|
16
|
-
|
17
|
+
assert_that(context.class.suite.tests_to_run_count).equals(1)
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
assert_that(test).is_kind_of(Assert::Test)
|
20
|
+
assert_that(test.name).equals(test_desc1)
|
21
|
+
assert_that(test.code).equals(test_block1)
|
21
22
|
end
|
22
23
|
|
23
24
|
should "build a test using `should` with a desc and code block" do
|
24
|
-
d, b =
|
25
|
+
d, b = test_desc1, test_block1
|
25
26
|
context, test = build_eval_context{ should(d, &b) }
|
26
27
|
|
27
|
-
|
28
|
+
assert_that(context.class.suite.tests_to_run_count).equals(1)
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
30
|
+
assert_that(test).is_kind_of(Assert::Test)
|
31
|
+
assert_that(test.name).equals("should #{test_desc1}")
|
32
|
+
assert_that(test.code).equals(test_block1)
|
32
33
|
end
|
33
34
|
|
34
35
|
should "build a test that skips with no msg when `test_eventually` called" do
|
35
|
-
d, b =
|
36
|
+
d, b = test_desc1, test_block1
|
36
37
|
context, test = build_eval_context{ test_eventually(d, &b) }
|
37
38
|
err = capture_err(Assert::Result::TestSkipped) do
|
38
39
|
context.instance_eval(&test.code)
|
39
40
|
end
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
|
42
|
+
assert_that(context.class.suite.tests_to_run_count).equals(1)
|
43
|
+
assert_that(err.message).equals("TODO")
|
44
|
+
assert_that(err.backtrace.size).equals(1)
|
44
45
|
end
|
45
46
|
|
46
47
|
should "build a test that skips with no msg when `should_eventually` called" do
|
47
|
-
d, b =
|
48
|
+
d, b = test_desc1, test_block1
|
48
49
|
context, test = build_eval_context{ should_eventually(d, &b) }
|
49
50
|
err = capture_err(Assert::Result::TestSkipped) do
|
50
51
|
context.instance_eval(&test.code)
|
51
52
|
end
|
52
53
|
|
53
|
-
|
54
|
-
|
55
|
-
|
54
|
+
assert_that(context.class.suite.tests_to_run_count).equals(1)
|
55
|
+
assert_that(err.message).equals("TODO")
|
56
|
+
assert_that(err.backtrace.size).equals(1)
|
56
57
|
end
|
57
58
|
|
58
59
|
should "skip with the msg \"TODO\" when `test` called with no block" do
|
59
|
-
d =
|
60
|
+
d = test_desc1
|
60
61
|
context, test = build_eval_context { test(d) } # no block passed
|
61
62
|
err = capture_err(Assert::Result::TestSkipped) do
|
62
63
|
context.instance_eval(&test.code)
|
63
64
|
end
|
64
65
|
|
65
|
-
|
66
|
-
|
67
|
-
|
66
|
+
assert_that(context.class.suite.tests_to_run_count).equals(1)
|
67
|
+
assert_that(err.message).equals("TODO")
|
68
|
+
assert_that(err.backtrace.size).equals(1)
|
68
69
|
end
|
69
70
|
|
70
71
|
should "skip with the msg \"TODO\" when `should` called with no block" do
|
71
|
-
d =
|
72
|
+
d = test_desc1
|
72
73
|
context, test = build_eval_context { should(d) } # no block passed
|
73
74
|
err = capture_err(Assert::Result::TestSkipped) do
|
74
75
|
context.instance_eval(&test.code)
|
75
76
|
end
|
76
77
|
|
77
|
-
|
78
|
-
|
79
|
-
|
78
|
+
assert_that(context.class.suite.tests_to_run_count).equals(1)
|
79
|
+
assert_that(err.message).equals("TODO")
|
80
|
+
assert_that(err.backtrace.size).equals(1)
|
80
81
|
end
|
81
82
|
|
82
83
|
should "skip with the msg \"TODO\" when `test_eventually` called with no block" do
|
83
|
-
d =
|
84
|
+
d = test_desc1
|
84
85
|
context, test = build_eval_context{ test_eventually(d) } # no block given
|
85
86
|
err = capture_err(Assert::Result::TestSkipped) do
|
86
87
|
context.instance_eval(&test.code)
|
87
88
|
end
|
88
89
|
|
89
|
-
|
90
|
-
|
91
|
-
|
90
|
+
assert_that(context.class.suite.tests_to_run_count).equals(1)
|
91
|
+
assert_that(err.message).equals("TODO")
|
92
|
+
assert_that(err.backtrace.size).equals(1)
|
92
93
|
end
|
93
94
|
|
94
95
|
should "skip with the msg \"TODO\" when `should_eventually` called with no block" do
|
95
|
-
d =
|
96
|
+
d = test_desc1
|
96
97
|
context, test = build_eval_context{ should_eventually(d) } # no block given
|
97
98
|
err = capture_err(Assert::Result::TestSkipped) do
|
98
99
|
context.instance_eval(&test.code)
|
99
100
|
end
|
100
101
|
|
101
|
-
|
102
|
-
|
103
|
-
|
102
|
+
assert_that(context.class.suite.tests_to_run_count).equals(1)
|
103
|
+
assert_that(err.message).equals("TODO")
|
104
|
+
assert_that(err.backtrace.size).equals(1)
|
104
105
|
end
|
105
106
|
|
106
107
|
should "build a test from a macro using `test`" do
|
107
|
-
d, b =
|
108
|
+
d, b = test_desc1, test_block1
|
108
109
|
m = Assert::Macro.new{ test(d, &b); test(d, &b) }
|
109
110
|
context_class = Factory.modes_off_context_class{ test(m) }
|
110
111
|
|
111
|
-
|
112
|
+
assert_that(context_class.suite.tests_to_run_count).equals(2)
|
112
113
|
end
|
113
114
|
|
114
115
|
should "build a test from a macro using `should`" do
|
115
|
-
d, b =
|
116
|
+
d, b = test_desc1, test_block1
|
116
117
|
m = Assert::Macro.new{ should(d, &b); should(d, &b) }
|
117
118
|
context_class = Factory.modes_off_context_class{ should(m) }
|
118
119
|
|
119
|
-
|
120
|
+
assert_that(context_class.suite.tests_to_run_count).equals(2)
|
120
121
|
end
|
121
122
|
|
122
123
|
should "build a test that skips from a macro using `test_eventually`" do
|
123
|
-
d, b =
|
124
|
+
d, b = test_desc1, test_block1
|
124
125
|
m = Assert::Macro.new{ test(d, &b); test(d, &b) }
|
125
126
|
context, test = build_eval_context{ test_eventually(m) }
|
126
127
|
|
127
|
-
|
128
|
-
|
128
|
+
assert_that(context.class.suite.tests_to_run_count).equals(1)
|
129
|
+
assert_that {
|
129
130
|
context.instance_eval(&test.code)
|
130
|
-
|
131
|
+
}.raises(Assert::Result::TestSkipped)
|
131
132
|
end
|
132
133
|
|
133
134
|
should "build a test that skips from a macro using `should_eventually`" do
|
134
|
-
d, b =
|
135
|
+
d, b = test_desc1, test_block1
|
135
136
|
m = Assert::Macro.new{ should(d, &b); should(d, &b) }
|
136
137
|
context, test = build_eval_context{ should_eventually(m) }
|
137
138
|
|
138
|
-
|
139
|
-
|
139
|
+
assert_that(context.class.suite.tests_to_run_count).equals(1)
|
140
|
+
assert_that {
|
140
141
|
context.instance_eval(&test.code)
|
141
|
-
|
142
|
-
|
142
|
+
}.raises(Assert::Result::TestSkipped)
|
143
143
|
end
|
144
144
|
|
145
145
|
private
|
146
146
|
|
147
147
|
def build_eval_context(&build_block)
|
148
|
-
context_class = Factory.modes_off_context_class
|
148
|
+
context_class = Factory.modes_off_context_class(&build_block)
|
149
149
|
test = context_class.suite.sorted_tests_to_run.to_a.last
|
150
150
|
[context_class.new(test, test.config, proc{ |r| }), test]
|
151
151
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "assert"
|
2
4
|
require "assert/context_info"
|
3
5
|
|
@@ -6,47 +8,55 @@ require "assert/context"
|
|
6
8
|
class Assert::ContextInfo
|
7
9
|
class UnitTests < Assert::Context
|
8
10
|
desc "Assert::ContextInfo"
|
11
|
+
subject { unit_class }
|
12
|
+
|
13
|
+
let(:unit_class) { Assert::ContextInfo }
|
14
|
+
end
|
15
|
+
|
16
|
+
class InitTests < UnitTests
|
17
|
+
desc "when init"
|
18
|
+
subject { unit_class.new(context1, nil, @caller.first) }
|
19
|
+
|
9
20
|
setup do
|
10
21
|
@caller = caller
|
11
|
-
@klass = Assert::Context
|
12
|
-
@info = Assert::ContextInfo.new(@klass, nil, @caller.first)
|
13
22
|
end
|
14
|
-
|
23
|
+
|
24
|
+
let(:context1) { Assert::Context }
|
15
25
|
|
16
26
|
should have_readers :called_from, :klass, :file
|
17
27
|
should have_imeths :test_name
|
18
28
|
|
19
29
|
should "set its klass on init" do
|
20
|
-
|
30
|
+
assert_that(subject.klass).equals(context1)
|
21
31
|
end
|
22
32
|
|
23
33
|
should "set its called_from to the called_from or first caller on init" do
|
24
|
-
info = Assert::ContextInfo.new(
|
25
|
-
|
34
|
+
info = Assert::ContextInfo.new(context1, @caller.first, nil)
|
35
|
+
assert_that(info.called_from).equals(@caller.first)
|
26
36
|
|
27
|
-
info = Assert::ContextInfo.new(
|
28
|
-
|
37
|
+
info = Assert::ContextInfo.new(context1, nil, @caller.first)
|
38
|
+
assert_that(info.called_from).equals(@caller.first)
|
29
39
|
end
|
30
40
|
|
31
41
|
should "set its file from caller info on init" do
|
32
|
-
|
42
|
+
assert_that(subject.file).equals(@caller.first.gsub(/\:[0-9]+.*$/, ""))
|
33
43
|
end
|
34
44
|
|
35
45
|
should "not have any file info if no caller is given" do
|
36
|
-
info = Assert::ContextInfo.new(
|
37
|
-
|
46
|
+
info = Assert::ContextInfo.new(context1)
|
47
|
+
assert_that(info.file).is_nil
|
38
48
|
end
|
39
49
|
|
40
50
|
should "know how to build the contextual test name for a given name" do
|
41
51
|
desc = Factory.string
|
42
52
|
name = Factory.string
|
43
53
|
|
44
|
-
|
45
|
-
|
46
|
-
|
54
|
+
assert_that(subject.test_name(name)).equals(name)
|
55
|
+
assert_that(subject.test_name("")).equals("")
|
56
|
+
assert_that(subject.test_name(nil)).equals("")
|
47
57
|
|
48
58
|
Assert.stub(subject.klass, :description){ desc }
|
49
|
-
|
59
|
+
assert_that(subject.test_name(name)).equals("#{desc} #{name}")
|
50
60
|
end
|
51
61
|
end
|
52
62
|
end
|
data/test/unit/context_tests.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "assert"
|
2
4
|
require "assert/context"
|
3
5
|
|
@@ -8,345 +10,353 @@ require "assert/utils"
|
|
8
10
|
class Assert::Context
|
9
11
|
class UnitTests < Assert::Context
|
10
12
|
desc "Assert::Context"
|
13
|
+
subject { unit_class }
|
14
|
+
|
15
|
+
let(:unit_class) { Assert::Context }
|
16
|
+
|
17
|
+
# DSL methods
|
18
|
+
should have_imeths :description, :desc, :describe, :subject, :suite, :let
|
19
|
+
should have_imeths :setup_once, :before_once, :startup
|
20
|
+
should have_imeths :teardown_once, :after_once, :shutdown
|
21
|
+
should have_imeths :setup, :before, :setups, :run_setups
|
22
|
+
should have_imeths :teardown, :after, :teardowns, :run_teardowns
|
23
|
+
should have_imeths :around, :arounds, :run_arounds
|
24
|
+
should have_imeths :test, :test_eventually, :test_skip
|
25
|
+
should have_imeths :should, :should_eventually, :should_skip
|
26
|
+
end
|
27
|
+
|
28
|
+
class InitTests < UnitTests
|
29
|
+
desc "when init"
|
30
|
+
subject { context_class1.new(test1, test1.config, result_callback1) }
|
31
|
+
|
11
32
|
setup do
|
12
|
-
@test = Factory.test
|
13
|
-
@context_class = @test.context_class
|
14
33
|
@callback_result = nil
|
15
|
-
@test_results = []
|
16
|
-
@result_callback = proc do |result|
|
17
|
-
@callback_result = result
|
18
|
-
@test_results << result
|
19
|
-
end
|
20
|
-
@context = @context_class.new(@test, @test.config, @result_callback)
|
21
34
|
end
|
22
|
-
subject{ @context }
|
23
35
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
should have_imeths :assert, :assert_not, :refute
|
36
|
+
let(:test1) { Factory.test }
|
37
|
+
let(:context_class1) { test1.context_class }
|
38
|
+
let(:test_results1) { [] }
|
39
|
+
let(:result_callback1) {
|
40
|
+
proc { |result| @callback_result = result; test_results1 << result }
|
41
|
+
}
|
42
|
+
let(:halt_config1) { Assert::Config.new(:halt_on_fail => true) }
|
43
|
+
let(:msg1) { Factory.string }
|
44
|
+
|
45
|
+
should have_imeths :assert, :assert_not, :refute, :assert_that
|
35
46
|
should have_imeths :pass, :ignore, :fail, :flunk, :skip
|
36
47
|
should have_imeths :pending, :with_backtrace, :subject
|
37
48
|
|
38
49
|
should "collect context info" do
|
39
50
|
test = @__assert_running_test__
|
40
|
-
|
41
|
-
|
51
|
+
assert_that(test.context_info.file).matches(/test\/unit\/context_tests.rb$/)
|
52
|
+
assert_that(test.context_info.klass).equals(self.class)
|
42
53
|
end
|
54
|
+
|
43
55
|
private
|
44
56
|
|
45
57
|
ASSERT_TEST_PATH_REGEX = /\A#{File.join(ROOT_PATH, "test", "")}/
|
46
58
|
|
47
59
|
def assert_with_bt_set(exp_with_bt, result)
|
48
60
|
with_backtrace(caller) do
|
49
|
-
|
61
|
+
assert_that(result.with_bt_set?).is_true
|
50
62
|
|
51
63
|
exp = Assert::Result::Backtrace.to_s(exp_with_bt+[(result.backtrace.filtered.first)])
|
52
|
-
|
53
|
-
|
64
|
+
assert_that(result.trace).equals(exp)
|
65
|
+
assert_that(result.src_line).equals(exp_with_bt.first)
|
54
66
|
end
|
55
67
|
end
|
56
68
|
|
57
69
|
def assert_not_with_bt_set(result)
|
58
70
|
with_backtrace(caller) do
|
59
|
-
|
71
|
+
assert_that(result.with_bt_set?).is_false
|
60
72
|
|
61
|
-
|
62
|
-
|
73
|
+
assert_that(result.trace).equals(result.src_line)
|
74
|
+
assert_that(result.src_line).equals(result.backtrace.filtered.first.to_s)
|
63
75
|
end
|
64
76
|
end
|
65
77
|
end
|
66
78
|
|
67
|
-
class SkipTests <
|
79
|
+
class SkipTests < InitTests
|
68
80
|
desc "skip method"
|
81
|
+
|
69
82
|
setup do
|
70
|
-
|
71
|
-
begin; @context.skip(@skip_msg); rescue StandardError => @exception; end
|
83
|
+
begin; subject.skip(msg1); rescue StandardError => @exception; end
|
72
84
|
@result = Factory.skip_result(@exception)
|
73
85
|
end
|
74
|
-
subject{ @result }
|
75
86
|
|
76
87
|
should "raise a test skipped exception and set its message" do
|
77
|
-
|
78
|
-
|
79
|
-
|
88
|
+
assert_that(@exception).is_kind_of(Assert::Result::TestSkipped)
|
89
|
+
assert_that(@exception.message).equals(msg1)
|
90
|
+
assert_that(@result.message).equals(msg1)
|
80
91
|
end
|
81
92
|
|
82
93
|
should "not call the result callback" do
|
83
|
-
|
94
|
+
assert_that(@callback_result).is_nil
|
84
95
|
end
|
85
96
|
|
86
97
|
should "use any given called from arg as the exception backtrace" do
|
87
|
-
|
98
|
+
assert_that(@exception.backtrace.size).does_not_equal(1)
|
88
99
|
|
89
100
|
called_from = Factory.string
|
90
|
-
begin;
|
91
|
-
|
92
|
-
|
101
|
+
begin; subject.skip(msg1, called_from); rescue StandardError => exception; end
|
102
|
+
assert_that(exception.backtrace.size).equals(1)
|
103
|
+
assert_that(exception.backtrace.first).equals(called_from)
|
93
104
|
end
|
94
105
|
end
|
95
106
|
|
96
|
-
class IgnoreTests <
|
107
|
+
class IgnoreTests < InitTests
|
97
108
|
desc "ignore method"
|
109
|
+
|
98
110
|
setup do
|
99
|
-
@
|
100
|
-
@result = @context.ignore(@ignore_msg)
|
111
|
+
@result = subject.ignore(msg1)
|
101
112
|
end
|
102
|
-
subject{ @result }
|
103
113
|
|
104
114
|
should "create an ignore result and set its message" do
|
105
|
-
|
106
|
-
|
115
|
+
assert_that(@result).is_kind_of(Assert::Result::Ignore)
|
116
|
+
assert_that(@result.message).equals(msg1)
|
107
117
|
end
|
108
118
|
|
109
119
|
should "call the result callback" do
|
110
|
-
|
120
|
+
assert_that(@callback_result).equals(@result)
|
111
121
|
end
|
112
122
|
end
|
113
123
|
|
114
|
-
class PassTests <
|
124
|
+
class PassTests < InitTests
|
115
125
|
desc "pass method"
|
126
|
+
|
116
127
|
setup do
|
117
|
-
@
|
118
|
-
@result = @context.pass(@pass_msg)
|
128
|
+
@result = subject.pass(msg1)
|
119
129
|
end
|
120
|
-
subject{ @result }
|
121
130
|
|
122
131
|
should "create a pass result and set its message" do
|
123
|
-
|
124
|
-
|
132
|
+
assert_that(@result).is_kind_of(Assert::Result::Pass)
|
133
|
+
assert_that(@result.message).equals(msg1)
|
125
134
|
end
|
126
135
|
|
127
136
|
should "call the result callback" do
|
128
|
-
|
137
|
+
assert_that(@callback_result).equals(@result)
|
129
138
|
end
|
130
139
|
end
|
131
140
|
|
132
|
-
class FlunkTests <
|
141
|
+
class FlunkTests < InitTests
|
133
142
|
desc "flunk method"
|
143
|
+
|
134
144
|
setup do
|
135
|
-
@
|
136
|
-
@result = @context.flunk(@flunk_msg)
|
145
|
+
@result = subject.flunk(msg1)
|
137
146
|
end
|
138
|
-
subject{ @result }
|
139
147
|
|
140
148
|
should "create a fail result and set its message" do
|
141
|
-
|
142
|
-
|
149
|
+
assert_that(@result).is_kind_of(Assert::Result::Fail)
|
150
|
+
assert_that(@result.message).equals(msg1)
|
143
151
|
end
|
144
152
|
|
145
153
|
should "call the result callback" do
|
146
|
-
|
154
|
+
assert_that(@callback_result).equals(@result)
|
147
155
|
end
|
148
156
|
end
|
149
157
|
|
150
|
-
class FailTests <
|
158
|
+
class FailTests < InitTests
|
151
159
|
desc "fail method"
|
160
|
+
|
152
161
|
setup do
|
153
|
-
@result =
|
162
|
+
@result = subject.fail
|
154
163
|
end
|
155
|
-
subject{ @result }
|
156
164
|
|
157
165
|
should "create a fail result and set its backtrace" do
|
158
|
-
|
159
|
-
|
160
|
-
|
166
|
+
assert_that(@result).is_kind_of(Assert::Result::Fail)
|
167
|
+
assert_that(@result.trace).equals(@result.backtrace.filtered.first.to_s)
|
168
|
+
assert_that(@result.backtrace).is_kind_of(Array)
|
161
169
|
end
|
162
170
|
|
163
171
|
should "set any given result message" do
|
164
|
-
|
165
|
-
result
|
166
|
-
assert_equal fail_msg, result.message
|
172
|
+
result = subject.fail(msg1)
|
173
|
+
assert_that(result.message).equals(msg1)
|
167
174
|
end
|
168
175
|
|
169
176
|
should "call the result callback" do
|
170
|
-
|
177
|
+
assert_that(@callback_result).equals(@result)
|
171
178
|
end
|
172
179
|
end
|
173
180
|
|
174
|
-
class HaltOnFailTests <
|
181
|
+
class HaltOnFailTests < InitTests
|
175
182
|
desc "failing when halting on fails"
|
176
|
-
|
177
|
-
@halt_config = Assert::Config.new(:halt_on_fail => true)
|
178
|
-
@context = @context_class.new(@test, @halt_config, @result_callback)
|
179
|
-
@fail_msg = "something failed"
|
180
|
-
end
|
181
|
-
subject{ @result }
|
183
|
+
subject { context_class1.new(test1, halt_config1, result_callback1) }
|
182
184
|
|
183
185
|
should "raise an exception with the failure's message" do
|
184
|
-
begin;
|
185
|
-
|
186
|
-
|
186
|
+
begin; subject.fail(msg1); rescue StandardError => err; end
|
187
|
+
assert_that(err).is_kind_of(Assert::Result::TestFailure)
|
188
|
+
assert_that(err.message).equals(msg1)
|
187
189
|
|
188
190
|
result = Assert::Result::Fail.for_test(Factory.test("something"), err)
|
189
|
-
|
191
|
+
assert_that(result.message).equals(msg1)
|
190
192
|
end
|
191
193
|
|
192
194
|
should "not call the result callback" do
|
193
|
-
|
195
|
+
assert_that(@callback_result).is_nil
|
194
196
|
end
|
195
197
|
end
|
196
198
|
|
197
|
-
class AssertTests <
|
199
|
+
class AssertTests < InitTests
|
198
200
|
desc "assert method"
|
199
|
-
|
200
|
-
|
201
|
-
@what_failed = "what failed"
|
202
|
-
end
|
201
|
+
|
202
|
+
let(:what_failed) { Factory.string }
|
203
203
|
|
204
204
|
should "return a pass result given a `true` assertion" do
|
205
|
-
result = subject.assert(true,
|
206
|
-
|
207
|
-
|
205
|
+
result = subject.assert(true, msg1){ what_failed }
|
206
|
+
assert_that(result).is_kind_of(Assert::Result::Pass)
|
207
|
+
assert_that(result.message).equals("")
|
208
208
|
end
|
209
209
|
|
210
210
|
should "return a fail result given a `false` assertion" do
|
211
|
-
result = subject.assert(false,
|
212
|
-
|
211
|
+
result = subject.assert(false, msg1){ what_failed }
|
212
|
+
assert_that(result).is_kind_of(Assert::Result::Fail)
|
213
213
|
end
|
214
214
|
|
215
215
|
should "pp the assertion value in the fail message by default" do
|
216
|
-
exp_def_what = "Failed assert: assertion was `#{Assert::U.show(false,
|
217
|
-
result = subject.assert(false,
|
216
|
+
exp_def_what = "Failed assert: assertion was `#{Assert::U.show(false, test1.config)}`."
|
217
|
+
result = subject.assert(false, msg1)
|
218
218
|
|
219
|
-
|
219
|
+
assert_that(result.message).equals([msg1, exp_def_what].join("\n"))
|
220
220
|
end
|
221
221
|
|
222
222
|
should "use a custom fail message if one is given" do
|
223
|
-
result = subject.assert(false,
|
224
|
-
|
223
|
+
result = subject.assert(false, msg1){ what_failed }
|
224
|
+
assert_that(result.message).equals([msg1, what_failed].join("\n"))
|
225
225
|
end
|
226
226
|
|
227
227
|
should "return a pass result given a \"truthy\" assertion" do
|
228
|
-
|
228
|
+
assert_that(subject.assert(34)).is_kind_of(Assert::Result::Pass)
|
229
229
|
end
|
230
230
|
|
231
231
|
should "return a fail result gievn a `nil` assertion" do
|
232
|
-
|
232
|
+
assert_that(subject.assert(nil)).is_kind_of(Assert::Result::Fail)
|
233
233
|
end
|
234
234
|
end
|
235
235
|
|
236
|
-
class AssertNotTests <
|
236
|
+
class AssertNotTests < InitTests
|
237
237
|
desc "assert_not method"
|
238
|
-
setup do
|
239
|
-
@fail_desc = "my fail desc"
|
240
|
-
end
|
241
238
|
|
242
239
|
should "return a pass result given a `false` assertion" do
|
243
|
-
result = subject.assert_not(false,
|
244
|
-
|
245
|
-
|
240
|
+
result = subject.assert_not(false, msg1)
|
241
|
+
assert_that(result).is_kind_of(Assert::Result::Pass)
|
242
|
+
assert_that(result.message).equals("")
|
246
243
|
end
|
247
244
|
|
248
245
|
should "return a fail result given a `true` assertion" do
|
249
|
-
result = subject.assert_not(true,
|
250
|
-
|
246
|
+
result = subject.assert_not(true, msg1)
|
247
|
+
assert_that(result).is_kind_of(Assert::Result::Fail)
|
251
248
|
end
|
252
249
|
|
253
250
|
should "pp the assertion value in the fail message by default" do
|
254
|
-
exp_def_what = "Failed assert_not: assertion was `#{Assert::U.show(true,
|
255
|
-
result = subject.assert_not(true,
|
251
|
+
exp_def_what = "Failed assert_not: assertion was `#{Assert::U.show(true, test1.config)}`."
|
252
|
+
result = subject.assert_not(true, msg1)
|
256
253
|
|
257
|
-
|
254
|
+
assert_that(result.message).equals([msg1, exp_def_what].join("\n"))
|
258
255
|
end
|
259
256
|
|
260
257
|
should "return a fail result given a \"truthy\" assertion" do
|
261
|
-
|
258
|
+
assert_that(subject.assert_not(34)).is_kind_of(Assert::Result::Fail)
|
262
259
|
end
|
263
260
|
|
264
261
|
should "return a pass result given a `nil` assertion" do
|
265
|
-
|
262
|
+
assert_that(subject.assert_not(nil)).is_kind_of(Assert::Result::Pass)
|
266
263
|
end
|
267
264
|
end
|
268
265
|
|
269
|
-
class
|
266
|
+
class AssertThatTests < InitTests
|
267
|
+
desc "`assert_that` method"
|
268
|
+
|
269
|
+
setup do
|
270
|
+
Assert.stub_tap_on_call(Assert::ActualValue, :new) { |_, call|
|
271
|
+
@actual_value_new_call = call
|
272
|
+
}
|
273
|
+
end
|
274
|
+
|
275
|
+
let(:actual_value) { Factory.string }
|
276
|
+
|
277
|
+
should "build an Assert::ActualValue" do
|
278
|
+
assert_instance_of Assert::ActualValue, subject.assert_that(actual_value)
|
279
|
+
assert_equal [actual_value], @actual_value_new_call.pargs
|
280
|
+
assert_equal({ context: subject }, @actual_value_new_call.kargs)
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
284
|
+
class SubjectTests < InitTests
|
270
285
|
desc "subject method"
|
286
|
+
subject { context_class1.new(test1, test1.config, proc{ |result| }) }
|
287
|
+
|
271
288
|
setup do
|
272
|
-
expected =
|
273
|
-
@
|
274
|
-
|
275
|
-
end
|
276
|
-
@context = @context_class.new(@test, @test.config, proc{ |result| })
|
277
|
-
@subject = @context.subject
|
289
|
+
expected = expected1
|
290
|
+
context_class1.subject { @something = expected }
|
291
|
+
@subject = subject.subject
|
278
292
|
end
|
279
|
-
|
293
|
+
|
294
|
+
let(:context_class1) { Factory.modes_off_context_class }
|
295
|
+
let(:expected1) { Factory.string }
|
280
296
|
|
281
297
|
should "instance evaluate the block set with the class setup method" do
|
282
|
-
|
298
|
+
assert_that(@subject).equals(expected1)
|
283
299
|
end
|
284
300
|
end
|
285
301
|
|
286
|
-
class PendingTests <
|
302
|
+
class PendingTests < InitTests
|
287
303
|
desc "`pending` method"
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
end
|
304
|
+
|
305
|
+
let(:block2) { proc { fail; pass; } }
|
306
|
+
let(:block1) { block = block2; proc { pending(&block) } } # test nesting
|
292
307
|
|
293
308
|
should "make fails skips and make passes fails" do
|
294
|
-
|
295
|
-
|
296
|
-
|
309
|
+
subject.fail "not affected"
|
310
|
+
subject.pass
|
311
|
+
subject.pending(&block1)
|
297
312
|
|
298
|
-
|
299
|
-
norm_fail, norm_pass, pending_fail, pending_pass =
|
313
|
+
assert_that(test_results1.size).equals(4)
|
314
|
+
norm_fail, norm_pass, pending_fail, pending_pass = test_results1
|
300
315
|
|
301
|
-
|
302
|
-
|
316
|
+
assert_that(norm_fail).is_kind_of(Assert::Result::Fail)
|
317
|
+
assert_that(norm_pass).is_kind_of(Assert::Result::Pass)
|
303
318
|
|
304
|
-
|
305
|
-
|
319
|
+
assert_that(pending_fail).is_kind_of(Assert::Result::Skip)
|
320
|
+
assert_that(pending_fail.message).includes("Pending fail")
|
306
321
|
|
307
|
-
|
308
|
-
|
322
|
+
assert_that(pending_pass).is_kind_of(Assert::Result::Fail)
|
323
|
+
assert_that(pending_pass.message).includes("Pending pass")
|
309
324
|
end
|
310
325
|
end
|
311
326
|
|
312
327
|
class PendingWithHaltOnFailTests < PendingTests
|
313
328
|
desc "when halting on fails"
|
314
|
-
|
315
|
-
@halt_config = Assert::Config.new(:halt_on_fail => true)
|
316
|
-
@context = @context_class.new(@test, @halt_config, @result_callback)
|
317
|
-
end
|
318
|
-
subject{ @result }
|
329
|
+
subject { context_class1.new(test1, halt_config1, result_callback1) }
|
319
330
|
|
320
331
|
should "make fails skips and stop the test" do
|
321
|
-
begin;
|
322
|
-
|
323
|
-
|
332
|
+
begin; subject.pending(&block1); rescue StandardError => err; end
|
333
|
+
assert_that(err).is_kind_of(Assert::Result::TestSkipped)
|
334
|
+
assert_that(err.message).includes("Pending fail")
|
324
335
|
|
325
|
-
|
336
|
+
assert_that(test_results1.size).equals(0) # it halted before the pending pass
|
326
337
|
end
|
327
338
|
end
|
328
339
|
|
329
|
-
class WithBacktraceTests <
|
340
|
+
class WithBacktraceTests < InitTests
|
330
341
|
desc "`with_backtrace` method"
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
end
|
342
|
+
|
343
|
+
let(:from_bt1) { ["called_from_here", Factory.string] }
|
344
|
+
let(:from_block1) { proc { ignore; fail; pass; skip "todo"; } }
|
335
345
|
|
336
346
|
should "alter non-error block results' bt with given bt's first line" do
|
337
|
-
|
347
|
+
subject.fail "not affected"
|
338
348
|
begin
|
339
|
-
|
349
|
+
subject.with_backtrace(from_bt1, &from_block1)
|
340
350
|
rescue Assert::Result::TestSkipped => e
|
341
|
-
|
351
|
+
test_results1 << Assert::Result::Skip.for_test(test1, e)
|
342
352
|
end
|
343
353
|
|
344
|
-
|
345
|
-
norm_fail, with_ignore, with_fail, with_pass, _with_skip =
|
354
|
+
assert_that(test_results1.size).equals(5)
|
355
|
+
norm_fail, with_ignore, with_fail, with_pass, _with_skip = test_results1
|
346
356
|
|
347
357
|
assert_not_with_bt_set norm_fail
|
348
358
|
|
349
|
-
exp = [
|
359
|
+
exp = [from_bt1.first]
|
350
360
|
assert_with_bt_set exp, with_ignore
|
351
361
|
assert_with_bt_set exp, with_fail
|
352
362
|
assert_with_bt_set exp, with_pass
|
@@ -354,30 +364,32 @@ class Assert::Context
|
|
354
364
|
end
|
355
365
|
end
|
356
366
|
|
357
|
-
class WithNestedBacktraceTests <
|
367
|
+
class WithNestedBacktraceTests < InitTests
|
358
368
|
desc "`with_backtrace` method nested"
|
359
|
-
setup do
|
360
|
-
@from_bt1 = ["called_from_here 1", Factory.string]
|
361
|
-
@from_bt2 = from_bt2 = ["called_from_here 2", Factory.string]
|
362
369
|
|
363
|
-
|
364
|
-
|
365
|
-
|
370
|
+
let(:from_bt1) { ["called_from_here 1", Factory.string] }
|
371
|
+
let(:from_bt2) { ["called_from_here 2", Factory.string] }
|
372
|
+
let(:from_block2) { proc { ignore; fail; pass; skip "todo"; } }
|
373
|
+
let(:from_block1) {
|
374
|
+
from_bt = from_bt2
|
375
|
+
from_block = from_block2
|
376
|
+
proc { with_backtrace(from_bt, &from_block) }
|
377
|
+
}
|
366
378
|
|
367
379
|
should "alter non-error block results' bt with nested wbt accrued first lines" do
|
368
|
-
|
380
|
+
subject.fail "not affected"
|
369
381
|
begin
|
370
|
-
|
382
|
+
subject.with_backtrace(from_bt1, &from_block1)
|
371
383
|
rescue Assert::Result::TestSkipped => e
|
372
|
-
|
384
|
+
test_results1 << Assert::Result::Skip.for_test(test1, e)
|
373
385
|
end
|
374
386
|
|
375
|
-
|
376
|
-
norm_fail, with_ignore, with_fail, with_pass,
|
387
|
+
assert_that(test_results1.size).equals(5)
|
388
|
+
norm_fail, with_ignore, with_fail, with_pass, _with_skip = test_results1
|
377
389
|
|
378
390
|
assert_not_with_bt_set norm_fail
|
379
391
|
|
380
|
-
exp = [
|
392
|
+
exp = [from_bt1.first, from_bt2.first]
|
381
393
|
assert_with_bt_set exp, with_ignore
|
382
394
|
assert_with_bt_set exp, with_fail
|
383
395
|
assert_with_bt_set exp, with_pass
|
@@ -385,16 +397,11 @@ class Assert::Context
|
|
385
397
|
end
|
386
398
|
end
|
387
399
|
|
388
|
-
class InspectTests <
|
400
|
+
class InspectTests < InitTests
|
389
401
|
desc "inspect method"
|
390
|
-
setup do
|
391
|
-
@expected = "#<#{@context.class}>"
|
392
|
-
@inspect = @context.inspect
|
393
|
-
end
|
394
|
-
subject{ @inspect }
|
395
402
|
|
396
403
|
should "just show the name of the class" do
|
397
|
-
|
404
|
+
assert_that(subject.inspect).equals("#<#{subject.class}>")
|
398
405
|
end
|
399
406
|
end
|
400
407
|
end
|