assert 2.18.0 → 2.19.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +66 -37
- data/assert.gemspec +4 -3
- data/lib/assert/actual_value.rb +140 -0
- data/lib/assert/assertions.rb +80 -20
- data/lib/assert/context.rb +31 -37
- data/lib/assert/context/let_dsl.rb +13 -0
- data/lib/assert/context/method_missing.rb +19 -0
- data/lib/assert/context/subject_dsl.rb +23 -24
- data/lib/assert/macros/methods.rb +4 -4
- data/lib/assert/result.rb +5 -1
- data/lib/assert/stub.rb +16 -0
- data/lib/assert/suite.rb +7 -10
- data/lib/assert/test.rb +0 -8
- data/lib/assert/version.rb +1 -1
- data/test/helper.rb +23 -25
- data/test/support/factory.rb +15 -0
- data/test/system/stub_tests.rb +332 -333
- data/test/system/test_tests.rb +99 -109
- data/test/unit/actual_value_tests.rb +371 -0
- data/test/unit/assert_tests.rb +111 -43
- data/test/unit/assertions/assert_block_tests.rb +30 -31
- data/test/unit/assertions/assert_changes_tests.rb +97 -0
- data/test/unit/assertions/assert_empty_tests.rb +33 -32
- data/test/unit/assertions/assert_equal_tests.rb +94 -74
- data/test/unit/assertions/assert_file_exists_tests.rb +32 -33
- data/test/unit/assertions/assert_includes_tests.rb +38 -37
- data/test/unit/assertions/assert_instance_of_tests.rb +34 -33
- data/test/unit/assertions/assert_kind_of_tests.rb +34 -33
- data/test/unit/assertions/assert_match_tests.rb +34 -33
- data/test/unit/assertions/assert_nil_tests.rb +30 -31
- data/test/unit/assertions/assert_raises_tests.rb +55 -55
- data/test/unit/assertions/assert_respond_to_tests.rb +36 -35
- data/test/unit/assertions/assert_same_tests.rb +86 -81
- data/test/unit/assertions/assert_true_false_tests.rb +60 -60
- data/test/unit/assertions_tests.rb +26 -24
- data/test/unit/config_helpers_tests.rb +43 -38
- data/test/unit/config_tests.rb +38 -34
- data/test/unit/context/let_dsl_tests.rb +10 -0
- data/test/unit/context/setup_dsl_tests.rb +70 -81
- data/test/unit/context/subject_dsl_tests.rb +15 -43
- data/test/unit/context/suite_dsl_tests.rb +15 -16
- data/test/unit/context/test_dsl_tests.rb +50 -52
- data/test/unit/context_info_tests.rb +23 -15
- data/test/unit/context_tests.rb +184 -179
- data/test/unit/default_runner_tests.rb +2 -5
- data/test/unit/default_suite_tests.rb +57 -53
- data/test/unit/factory_tests.rb +5 -3
- data/test/unit/file_line_tests.rb +33 -35
- data/test/unit/macro_tests.rb +14 -10
- data/test/unit/result_tests.rb +159 -183
- data/test/unit/runner_tests.rb +64 -64
- data/test/unit/suite_tests.rb +56 -59
- data/test/unit/test_tests.rb +118 -139
- data/test/unit/utils_tests.rb +43 -45
- data/test/unit/view_helpers_tests.rb +54 -52
- data/test/unit/view_tests.rb +22 -23
- metadata +29 -7
@@ -8,28 +8,29 @@ module Assert::Assertions
|
|
8
8
|
include Assert::Test::TestHelpers
|
9
9
|
|
10
10
|
desc "`assert_equal`"
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
assert_equal(
|
16
|
-
assert_equal(*a) # fail
|
11
|
+
subject {
|
12
|
+
args = args1
|
13
|
+
Factory.test do
|
14
|
+
assert_equal(1, 1) # pass
|
15
|
+
assert_equal(*args) # fail
|
17
16
|
end
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
}
|
18
|
+
|
19
|
+
let(:desc1) { "assert equal fail desc" }
|
20
|
+
let(:args1) { ["1", "2", desc1] }
|
21
|
+
let(:config1) { subject.config }
|
22
22
|
|
23
23
|
should "produce results as expected" do
|
24
|
-
|
25
|
-
assert_equal 1, test_run_result_count(:pass)
|
26
|
-
assert_equal 1, test_run_result_count(:fail)
|
27
|
-
end
|
24
|
+
subject.run(&test_run_callback)
|
28
25
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
26
|
+
assert_that(test_run_result_count).equals(2)
|
27
|
+
assert_that(test_run_result_count(:pass)).equals(1)
|
28
|
+
assert_that(test_run_result_count(:fail)).equals(1)
|
29
|
+
|
30
|
+
exp =
|
31
|
+
"#{args1[2]}\nExpected #{Assert::U.show(args1[1], config1)}"\
|
32
|
+
" to be equal to #{Assert::U.show(args1[0], config1)}."
|
33
|
+
assert_that(test_run_results(:fail).first.message).equals(exp)
|
33
34
|
end
|
34
35
|
end
|
35
36
|
|
@@ -37,28 +38,29 @@ module Assert::Assertions
|
|
37
38
|
include Assert::Test::TestHelpers
|
38
39
|
|
39
40
|
desc "`assert_not_equal`"
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
assert_not_equal(
|
45
|
-
assert_not_equal(1, 2) # pass
|
41
|
+
subject {
|
42
|
+
args = args1
|
43
|
+
Factory.test do
|
44
|
+
assert_not_equal(*args) # fail
|
45
|
+
assert_not_equal(1, 2) # pass
|
46
46
|
end
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
}
|
48
|
+
|
49
|
+
let(:desc1) { "assert not equal fail desc" }
|
50
|
+
let(:args1) { ["1", "1", desc1] }
|
51
|
+
let(:config1) { subject.config }
|
51
52
|
|
52
53
|
should "produce results as expected" do
|
53
|
-
|
54
|
-
assert_equal 1, test_run_result_count(:pass)
|
55
|
-
assert_equal 1, test_run_result_count(:fail)
|
56
|
-
end
|
54
|
+
subject.run(&test_run_callback)
|
57
55
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
56
|
+
assert_that(test_run_result_count).equals(2)
|
57
|
+
assert_that(test_run_result_count(:pass)).equals(1)
|
58
|
+
assert_that(test_run_result_count(:fail)).equals(1)
|
59
|
+
|
60
|
+
exp =
|
61
|
+
"#{args1[2]}\nExpected #{Assert::U.show(args1[1], config1)}"\
|
62
|
+
" to not be equal to #{Assert::U.show(args1[0], config1)}."
|
63
|
+
assert_that(test_run_results(:fail).first.message).equals(exp)
|
62
64
|
end
|
63
65
|
end
|
64
66
|
|
@@ -66,21 +68,36 @@ module Assert::Assertions
|
|
66
68
|
include Assert::Test::TestHelpers
|
67
69
|
|
68
70
|
desc "with objects that define custom equality operators"
|
69
|
-
setup do
|
70
|
-
is_class = Class.new do
|
71
|
-
def ==(other); true; end
|
72
|
-
end
|
73
|
-
@is = is_class.new
|
74
71
|
|
75
|
-
|
76
|
-
|
72
|
+
let(:is_class) {
|
73
|
+
Class.new do
|
74
|
+
def ==(other)
|
75
|
+
if other.is_a?(Assert::ActualValue.not_given.class)
|
76
|
+
super
|
77
|
+
else
|
78
|
+
true
|
79
|
+
end
|
80
|
+
end
|
77
81
|
end
|
78
|
-
|
79
|
-
|
82
|
+
}
|
83
|
+
let(:is_not_class) {
|
84
|
+
Class.new do
|
85
|
+
def ==(other)
|
86
|
+
if other.is_a?(Assert::ActualValue.not_given.class)
|
87
|
+
super
|
88
|
+
else
|
89
|
+
false
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
}
|
94
|
+
|
95
|
+
let(:is1) { is_class.new }
|
96
|
+
let(:is_not1) { is_not_class.new }
|
80
97
|
|
81
98
|
should "use the equality operator of the exp value" do
|
82
|
-
|
83
|
-
|
99
|
+
assert_that(is1).equals(is_not1)
|
100
|
+
assert_that(is_not1).does_not_equal(is1)
|
84
101
|
end
|
85
102
|
end
|
86
103
|
|
@@ -88,52 +105,55 @@ module Assert::Assertions
|
|
88
105
|
include Assert::Test::TestHelpers
|
89
106
|
|
90
107
|
desc "with objects that should use diff when showing"
|
91
|
-
setup do
|
92
|
-
@exp_obj = "I'm a\nstring"
|
93
|
-
@act_obj = "I am a \nstring"
|
94
108
|
|
95
|
-
|
96
|
-
|
97
|
-
|
109
|
+
let(:config1) {
|
110
|
+
Factory.modes_off_config.tap do |config|
|
111
|
+
config.use_diff_proc(Assert::U.default_use_diff_proc)
|
112
|
+
config.run_diff_proc(Assert::U.syscmd_diff_proc)
|
113
|
+
end
|
114
|
+
}
|
98
115
|
|
99
|
-
|
100
|
-
|
101
|
-
|
116
|
+
let(:exp_obj1) { "I'm a\nstring" }
|
117
|
+
let(:act_obj1) { "I am a \nstring" }
|
118
|
+
let(:exp_obj_show1) { Assert::U.show_for_diff(exp_obj1, config1) }
|
119
|
+
let(:act_obj_show1) { Assert::U.show_for_diff(act_obj1, config1) }
|
102
120
|
end
|
103
121
|
|
104
122
|
class AssertEqualDiffTests < DiffTests
|
105
123
|
desc "`assert_equal`"
|
106
|
-
|
107
|
-
exp_obj, act_obj =
|
108
|
-
|
124
|
+
subject {
|
125
|
+
exp_obj, act_obj = exp_obj1, act_obj1
|
126
|
+
Factory.test(config1) do
|
109
127
|
assert_equal(exp_obj, act_obj)
|
110
128
|
end
|
111
|
-
|
112
|
-
end
|
113
|
-
subject{ @test }
|
129
|
+
}
|
114
130
|
|
115
131
|
should "include diff output in the fail messages" do
|
116
|
-
|
117
|
-
|
118
|
-
|
132
|
+
subject.run(&test_run_callback)
|
133
|
+
|
134
|
+
exp =
|
135
|
+
"Expected does not equal actual, diff:\n"\
|
136
|
+
"#{Assert::U.syscmd_diff_proc.call(exp_obj_show1, act_obj_show1)}"
|
137
|
+
assert_that(test_run_results(:fail).first.message).equals(exp)
|
119
138
|
end
|
120
139
|
end
|
121
140
|
|
122
141
|
class AssertNotEqualDiffTests < DiffTests
|
123
142
|
desc "`assert_not_equal`"
|
124
|
-
|
125
|
-
exp_obj
|
126
|
-
|
143
|
+
subject {
|
144
|
+
exp_obj = exp_obj1
|
145
|
+
Factory.test(config1) do
|
127
146
|
assert_not_equal(exp_obj, exp_obj)
|
128
147
|
end
|
129
|
-
|
130
|
-
end
|
131
|
-
subject{ @test }
|
148
|
+
}
|
132
149
|
|
133
150
|
should "include diff output in the fail messages" do
|
134
|
-
|
135
|
-
|
136
|
-
|
151
|
+
subject.run(&test_run_callback)
|
152
|
+
|
153
|
+
exp =
|
154
|
+
"Expected equals actual, diff:\n"\
|
155
|
+
"#{Assert::U.syscmd_diff_proc.call(exp_obj_show1, exp_obj_show1)}"
|
156
|
+
assert_that(test_run_results(:fail).first.message).equals(exp)
|
137
157
|
end
|
138
158
|
end
|
139
159
|
end
|
@@ -9,27 +9,27 @@ module Assert::Assertions
|
|
9
9
|
include Assert::Test::TestHelpers
|
10
10
|
|
11
11
|
desc "`assert_file_exists`"
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
@test = Factory.test do
|
12
|
+
subject {
|
13
|
+
args = args1
|
14
|
+
Factory.test do
|
16
15
|
assert_file_exists(__FILE__) # pass
|
17
16
|
assert_file_exists(*args) # fail
|
18
17
|
end
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
}
|
19
|
+
|
20
|
+
let(:desc1) { "assert file exists fail desc" }
|
21
|
+
let(:args1) { ["/a/path/to/some/file/that/no/exists", desc1] }
|
22
|
+
let(:config1) { subject.config }
|
23
23
|
|
24
24
|
should "produce results as expected" do
|
25
|
-
|
26
|
-
assert_equal 1, test_run_result_count(:pass)
|
27
|
-
assert_equal 1, test_run_result_count(:fail)
|
28
|
-
end
|
25
|
+
subject.run(&test_run_callback)
|
29
26
|
|
30
|
-
|
31
|
-
|
32
|
-
|
27
|
+
assert_that(test_run_result_count).equals(2)
|
28
|
+
assert_that(test_run_result_count(:pass)).equals(1)
|
29
|
+
assert_that(test_run_result_count(:fail)).equals(1)
|
30
|
+
|
31
|
+
exp = "#{args1[1]}\nExpected #{Assert::U.show(args1[0], config1)} to exist."
|
32
|
+
assert_that(test_run_results(:fail).first.message).equals(exp)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -37,28 +37,27 @@ module Assert::Assertions
|
|
37
37
|
include Assert::Test::TestHelpers
|
38
38
|
|
39
39
|
desc "`assert_not_file_exists`"
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
assert_not_file_exists(
|
45
|
-
assert_not_file_exists(*args) # fail
|
40
|
+
subject {
|
41
|
+
args = args1
|
42
|
+
Factory.test do
|
43
|
+
assert_not_file_exists("/file/path") # pass
|
44
|
+
assert_not_file_exists(*args) # fail
|
46
45
|
end
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
46
|
+
}
|
47
|
+
|
48
|
+
let(:desc1) { "assert not file exists fail desc" }
|
49
|
+
let(:args1) { [__FILE__, desc1] }
|
50
|
+
let(:config1) { subject.config }
|
51
51
|
|
52
52
|
should "produce results as expected" do
|
53
|
-
|
54
|
-
assert_equal 1, test_run_result_count(:pass)
|
55
|
-
assert_equal 1, test_run_result_count(:fail)
|
56
|
-
end
|
53
|
+
subject.run(&test_run_callback)
|
57
54
|
|
58
|
-
|
59
|
-
|
60
|
-
|
55
|
+
assert_that(test_run_result_count).equals(2)
|
56
|
+
assert_that(test_run_result_count(:pass)).equals(1)
|
57
|
+
assert_that(test_run_result_count(:fail)).equals(1)
|
58
|
+
|
59
|
+
exp = "#{args1[1]}\nExpected #{Assert::U.show(args1[0], config1)} to not exist."
|
60
|
+
assert_that(test_run_results(:fail).first.message).equals(exp)
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|
64
|
-
|
@@ -8,29 +8,30 @@ module Assert::Assertions
|
|
8
8
|
include Assert::Test::TestHelpers
|
9
9
|
|
10
10
|
desc "`assert_includes`"
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
@test = Factory.test do
|
11
|
+
subject {
|
12
|
+
args = args1
|
13
|
+
Factory.test do
|
15
14
|
assert_includes(1, [1]) # pass
|
16
|
-
assert_includes(*args)
|
15
|
+
assert_includes(*args) # fail
|
17
16
|
end
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
}
|
18
|
+
|
19
|
+
let(:desc1) { "assert includes fail desc" }
|
20
|
+
let(:args1) { [2, [1], desc1] }
|
21
|
+
let(:config1) { subject.config }
|
22
22
|
|
23
23
|
should "produce results as expected" do
|
24
|
-
|
25
|
-
assert_equal 1, test_run_result_count(:pass)
|
26
|
-
assert_equal 1, test_run_result_count(:fail)
|
27
|
-
end
|
24
|
+
subject.run(&test_run_callback)
|
28
25
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
26
|
+
assert_that(test_run_result_count).equals(2)
|
27
|
+
assert_that(test_run_result_count(:pass)).equals(1)
|
28
|
+
assert_that(test_run_result_count(:fail)).equals(1)
|
29
|
+
|
30
|
+
exp =
|
31
|
+
"#{args1[2]}\n"\
|
32
|
+
"Expected #{Assert::U.show(args1[1], config1)}"\
|
33
|
+
" to include #{Assert::U.show(args1[0], config1)}."
|
34
|
+
assert_that(test_run_results(:fail).first.message).equals(exp)
|
34
35
|
end
|
35
36
|
end
|
36
37
|
|
@@ -38,30 +39,30 @@ module Assert::Assertions
|
|
38
39
|
include Assert::Test::TestHelpers
|
39
40
|
|
40
41
|
desc "`assert_not_included`"
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
@test = Factory.test do
|
42
|
+
subject {
|
43
|
+
args = args1
|
44
|
+
Factory.test do
|
45
45
|
assert_not_included(2, [1]) # pass
|
46
|
-
assert_not_included(*args)
|
46
|
+
assert_not_included(*args) # fail
|
47
47
|
end
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
48
|
+
}
|
49
|
+
|
50
|
+
let(:desc1) { "assert not included fail desc" }
|
51
|
+
let(:args1) { [1, [1], desc1] }
|
52
|
+
let(:config1) { subject.config }
|
52
53
|
|
53
54
|
should "produce results as expected" do
|
54
|
-
|
55
|
-
assert_equal 1, test_run_result_count(:pass)
|
56
|
-
assert_equal 1, test_run_result_count(:fail)
|
57
|
-
end
|
55
|
+
subject.run(&test_run_callback)
|
58
56
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
57
|
+
assert_that(test_run_result_count).equals(2)
|
58
|
+
assert_that(test_run_result_count(:pass)).equals(1)
|
59
|
+
assert_that(test_run_result_count(:fail)).equals(1)
|
60
|
+
|
61
|
+
exp =
|
62
|
+
"#{args1[2]}\n"\
|
63
|
+
"Expected #{Assert::U.show(args1[1], config1)}"\
|
64
|
+
" to not include #{Assert::U.show(args1[0], config1)}."
|
65
|
+
assert_that(test_run_results(:fail).first.message).equals(exp)
|
64
66
|
end
|
65
67
|
end
|
66
68
|
end
|
67
|
-
|
@@ -8,28 +8,29 @@ module Assert::Assertions
|
|
8
8
|
include Assert::Test::TestHelpers
|
9
9
|
|
10
10
|
desc "`assert_instance_of`"
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
@test = Factory.test do
|
11
|
+
subject {
|
12
|
+
args = args1
|
13
|
+
Factory.test do
|
15
14
|
assert_instance_of(String, "object") # pass
|
16
15
|
assert_instance_of(*args) # fail
|
17
16
|
end
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
}
|
18
|
+
|
19
|
+
let(:desc1) { "assert instance of fail desc" }
|
20
|
+
let(:args1) { [Array, "object", desc1] }
|
21
|
+
let(:config1) { subject.config }
|
22
22
|
|
23
23
|
should "produce results as expected" do
|
24
|
-
|
25
|
-
assert_equal 1, test_run_result_count(:pass)
|
26
|
-
assert_equal 1, test_run_result_count(:fail)
|
27
|
-
end
|
24
|
+
subject.run(&test_run_callback)
|
28
25
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
26
|
+
assert_that(test_run_result_count).equals(2)
|
27
|
+
assert_that(test_run_result_count(:pass)).equals(1)
|
28
|
+
assert_that(test_run_result_count(:fail)).equals(1)
|
29
|
+
|
30
|
+
exp =
|
31
|
+
"#{args1[2]}\nExpected #{Assert::U.show(args1[1], config1)} (#{args1[1].class})"\
|
32
|
+
" to be an instance of #{args1[0]}."
|
33
|
+
assert_that(test_run_results(:fail).first.message).equals(exp)
|
33
34
|
end
|
34
35
|
end
|
35
36
|
|
@@ -37,29 +38,29 @@ module Assert::Assertions
|
|
37
38
|
include Assert::Test::TestHelpers
|
38
39
|
|
39
40
|
desc "`assert_not_instance_of`"
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
@test = Factory.test do
|
41
|
+
subject {
|
42
|
+
args = args1
|
43
|
+
Factory.test do
|
44
44
|
assert_not_instance_of(*args) # fail
|
45
45
|
assert_not_instance_of(Array, "object") # pass
|
46
46
|
end
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
}
|
48
|
+
|
49
|
+
let(:desc1) { "assert not instance of fail desc" }
|
50
|
+
let(:args1) { [String, "object", desc1] }
|
51
|
+
let(:config1) { subject.config }
|
51
52
|
|
52
53
|
should "produce results as expected" do
|
53
|
-
|
54
|
-
assert_equal 1, test_run_result_count(:pass)
|
55
|
-
assert_equal 1, test_run_result_count(:fail)
|
56
|
-
end
|
54
|
+
subject.run(&test_run_callback)
|
57
55
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
56
|
+
assert_that(test_run_result_count).equals(2)
|
57
|
+
assert_that(test_run_result_count(:pass)).equals(1)
|
58
|
+
assert_that(test_run_result_count(:fail)).equals(1)
|
59
|
+
|
60
|
+
exp =
|
61
|
+
"#{args1[2]}\nExpected #{Assert::U.show(args1[1], config1)} (#{args1[1].class})"\
|
62
|
+
" to not be an instance of #{args1[0]}."
|
63
|
+
assert_that(test_run_results(:fail).first.message).equals(exp)
|
62
64
|
end
|
63
65
|
end
|
64
66
|
end
|
65
|
-
|