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,32 +8,35 @@ module Assert::Assertions
|
|
8
8
|
include Assert::Test::TestHelpers
|
9
9
|
|
10
10
|
desc "`assert_same`"
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
@test = Factory.test do
|
11
|
+
subject {
|
12
|
+
args = args1
|
13
|
+
object = object1
|
14
|
+
Factory.test do
|
16
15
|
assert_same(object, object) # pass
|
17
16
|
assert_same(*args) # fail
|
18
17
|
end
|
19
|
-
|
20
|
-
@test.run(&test_run_callback)
|
21
|
-
end
|
22
|
-
subject{ @test }
|
18
|
+
}
|
23
19
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
20
|
+
let(:class1) { Class.new }
|
21
|
+
let(:object1) { class1.new }
|
22
|
+
let(:desc1) { "assert same fail desc" }
|
23
|
+
let(:args1) { [object1, class1.new, desc1] }
|
24
|
+
let(:config1) { subject.config }
|
29
25
|
|
30
|
-
should "
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
26
|
+
should "produce results as expected" do
|
27
|
+
subject.run(&test_run_callback)
|
28
|
+
|
29
|
+
assert_that(test_run_result_count).equals(2)
|
30
|
+
assert_that(test_run_result_count(:pass)).equals(1)
|
31
|
+
assert_that(test_run_result_count(:fail)).equals(1)
|
32
|
+
|
33
|
+
exp =
|
34
|
+
"#{args1[2]}\n"\
|
35
|
+
"Expected #{Assert::U.show(args1[1], config1)}"\
|
36
|
+
" (#<#{args1[1].class}:#{"0x0%x" % (args1[1].object_id << 1)}>)"\
|
37
|
+
" to be the same as #{Assert::U.show(args1[0], config1)}"\
|
38
|
+
" (#<#{args1[0].class}:#{"0x0%x" % (args1[0].object_id << 1)}>)."
|
39
|
+
assert_that(test_run_results(:fail).first.message).equals(exp)
|
37
40
|
end
|
38
41
|
end
|
39
42
|
|
@@ -41,32 +44,36 @@ module Assert::Assertions
|
|
41
44
|
include Assert::Test::TestHelpers
|
42
45
|
|
43
46
|
desc "`assert_not_same`"
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
47
|
+
subject {
|
48
|
+
args = args1
|
49
|
+
object = object1
|
50
|
+
klass = class1
|
51
|
+
Factory.test do
|
49
52
|
assert_not_same(*args) # fail
|
50
53
|
assert_not_same(object, klass.new) # pass
|
51
54
|
end
|
52
|
-
|
53
|
-
@test.run(&test_run_callback)
|
54
|
-
end
|
55
|
-
subject{ @test }
|
55
|
+
}
|
56
56
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
57
|
+
let(:class1) { Class.new }
|
58
|
+
let(:object1) { class1.new }
|
59
|
+
let(:desc1) { "assert not same fail desc" }
|
60
|
+
let(:args1) { [object1, object1, desc1] }
|
61
|
+
let(:config1) { subject.config }
|
62
62
|
|
63
|
-
should "
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
63
|
+
should "produce results as expected" do
|
64
|
+
subject.run(&test_run_callback)
|
65
|
+
|
66
|
+
assert_that(test_run_result_count).equals(2)
|
67
|
+
assert_that(test_run_result_count(:pass)).equals(1)
|
68
|
+
assert_that(test_run_result_count(:fail)).equals(1)
|
69
|
+
|
70
|
+
exp =
|
71
|
+
"#{args1[2]}\n"\
|
72
|
+
"Expected #{Assert::U.show(args1[1], config1)}"\
|
73
|
+
" (#<#{args1[1].class}:#{"0x0%x" % (args1[1].object_id << 1)}>)"\
|
74
|
+
" to not be the same as #{Assert::U.show(args1[0], config1)}"\
|
75
|
+
" (#<#{args1[0].class}:#{"0x0%x" % (args1[0].object_id << 1)}>)."
|
76
|
+
assert_that(test_run_results(:fail).first.message).equals(exp)
|
70
77
|
end
|
71
78
|
end
|
72
79
|
|
@@ -74,62 +81,60 @@ module Assert::Assertions
|
|
74
81
|
include Assert::Test::TestHelpers
|
75
82
|
|
76
83
|
desc "with objects that should use diff when showing"
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
@c.run_diff_proc(Assert::U.syscmd_diff_proc)
|
84
|
+
let(:config1) {
|
85
|
+
Factory.modes_off_config.tap do |config|
|
86
|
+
config.use_diff_proc(Assert::U.default_use_diff_proc)
|
87
|
+
config.run_diff_proc(Assert::U.syscmd_diff_proc)
|
88
|
+
end
|
89
|
+
}
|
84
90
|
|
85
|
-
|
86
|
-
|
87
|
-
|
91
|
+
let(:exp_obj1) { "I'm a\nstring" }
|
92
|
+
let(:act_obj1) { "I am a \nstring" }
|
93
|
+
let(:exp_obj_show1) { Assert::U.show_for_diff(exp_obj1, config1) }
|
94
|
+
let(:act_obj_show1) { Assert::U.show_for_diff(act_obj1, config1) }
|
88
95
|
end
|
89
96
|
|
90
97
|
class AssertSameDiffTests < DiffTests
|
91
98
|
desc "`assert_same`"
|
92
|
-
|
93
|
-
exp_obj, act_obj =
|
94
|
-
|
99
|
+
subject {
|
100
|
+
exp_obj, act_obj = exp_obj1, act_obj1
|
101
|
+
Factory.test(config1) do
|
95
102
|
assert_same(exp_obj, act_obj)
|
96
103
|
end
|
97
|
-
|
98
|
-
end
|
99
|
-
subject{ @test }
|
104
|
+
}
|
100
105
|
|
101
106
|
should "include diff output in the fail messages" do
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
107
|
+
subject.run(&test_run_callback)
|
108
|
+
|
109
|
+
exp =
|
110
|
+
"Expected #<#{act_obj1.class}:#{"0x0%x" % (act_obj1.object_id << 1)}>"\
|
111
|
+
" to be the same as"\
|
112
|
+
" #<#{exp_obj1.class}:#{"0x0%x" % (exp_obj1.object_id << 1)}>"\
|
113
|
+
", diff:\n"\
|
114
|
+
"#{Assert::U.syscmd_diff_proc.call(exp_obj_show1, act_obj_show1)}"
|
115
|
+
assert_that(test_run_results(:fail).first.message).equals(exp)
|
108
116
|
end
|
109
117
|
end
|
110
118
|
|
111
119
|
class AssertNotSameDiffTests < DiffTests
|
112
120
|
desc "`assert_not_same`"
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
exp_obj, act_obj = @exp_obj, @act_obj
|
118
|
-
@test = Factory.test(@c) do
|
119
|
-
assert_not_same(exp_obj, exp_obj)
|
121
|
+
subject {
|
122
|
+
act_obj = act_obj1
|
123
|
+
Factory.test(config1) do
|
124
|
+
assert_not_same(act_obj, act_obj)
|
120
125
|
end
|
121
|
-
|
122
|
-
end
|
123
|
-
subject{ @test }
|
126
|
+
}
|
124
127
|
|
125
128
|
should "include diff output in the fail messages" do
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
129
|
+
subject.run(&test_run_callback)
|
130
|
+
|
131
|
+
exp =
|
132
|
+
"Expected #<#{act_obj1.class}:#{"0x0%x" % (act_obj1.object_id << 1)}>"\
|
133
|
+
" to not be the same as"\
|
134
|
+
" #<#{act_obj1.class}:#{"0x0%x" % (act_obj1.object_id << 1)}>"\
|
135
|
+
", diff:\n"\
|
136
|
+
"#{Assert::U.syscmd_diff_proc.call(act_obj_show1, act_obj_show1)}"
|
137
|
+
assert_that(test_run_results(:fail).first.message).equals(exp)
|
132
138
|
end
|
133
139
|
end
|
134
140
|
end
|
135
|
-
|
@@ -8,27 +8,27 @@ module Assert::Assertions
|
|
8
8
|
include Assert::Test::TestHelpers
|
9
9
|
|
10
10
|
desc "`assert_true`"
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
@test = Factory.test do
|
11
|
+
subject {
|
12
|
+
args = args1
|
13
|
+
Factory.test do
|
15
14
|
assert_true(true) # pass
|
16
15
|
assert_true(*args) # fail
|
17
16
|
end
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
}
|
18
|
+
|
19
|
+
let(:desc1) { "assert true fail desc" }
|
20
|
+
let(:args1) { ["whatever", desc1] }
|
21
|
+
let(:config1) { subject.config }
|
22
22
|
|
23
23
|
should "produce results as expected" do
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
subject.run(&test_run_callback)
|
25
|
+
|
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)
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
assert_equal exp, test_run_results(:fail).first.message
|
30
|
+
exp = "#{args1[1]}\nExpected #{Assert::U.show(args1[0], config1)} to be true."
|
31
|
+
assert_that(test_run_results(:fail).first.message).equals(exp)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
@@ -36,27 +36,27 @@ module Assert::Assertions
|
|
36
36
|
include Assert::Test::TestHelpers
|
37
37
|
|
38
38
|
desc "`assert_not_true`"
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
@test = Factory.test do
|
39
|
+
subject {
|
40
|
+
args = args1
|
41
|
+
Factory.test do
|
43
42
|
assert_not_true(false) # pass
|
44
43
|
assert_not_true(*args) # fail
|
45
44
|
end
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
45
|
+
}
|
46
|
+
|
47
|
+
let(:desc1) { "assert not true fail desc" }
|
48
|
+
let(:args1) { [true, desc1] }
|
49
|
+
let(:config1) { subject.config }
|
50
50
|
|
51
51
|
should "produce results as expected" do
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
52
|
+
subject.run(&test_run_callback)
|
53
|
+
|
54
|
+
assert_that(test_run_result_count).equals(2)
|
55
|
+
assert_that(test_run_result_count(:pass)).equals(1)
|
56
|
+
assert_that(test_run_result_count(:fail)).equals(1)
|
56
57
|
|
57
|
-
|
58
|
-
|
59
|
-
assert_equal exp, test_run_results(:fail).first.message
|
58
|
+
exp = "#{args1[1]}\nExpected #{Assert::U.show(args1[0], config1)} to not be true."
|
59
|
+
assert_that(test_run_results(:fail).first.message).equals(exp)
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
@@ -64,27 +64,27 @@ module Assert::Assertions
|
|
64
64
|
include Assert::Test::TestHelpers
|
65
65
|
|
66
66
|
desc "`assert_false`"
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
@test = Factory.test do
|
67
|
+
subject {
|
68
|
+
args = args1
|
69
|
+
Factory.test do
|
71
70
|
assert_false(false) # pass
|
72
71
|
assert_false(*args) # fail
|
73
72
|
end
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
73
|
+
}
|
74
|
+
|
75
|
+
let(:desc1) { "assert false fail desc" }
|
76
|
+
let(:args1) { ["whatever", desc1] }
|
77
|
+
let(:config1) { subject.config }
|
78
78
|
|
79
79
|
should "produce results as expected" do
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
80
|
+
subject.run(&test_run_callback)
|
81
|
+
|
82
|
+
assert_that(test_run_result_count).equals(2)
|
83
|
+
assert_that(test_run_result_count(:pass)).equals(1)
|
84
|
+
assert_that(test_run_result_count(:fail)).equals(1)
|
84
85
|
|
85
|
-
|
86
|
-
|
87
|
-
assert_equal exp, test_run_results(:fail).first.message
|
86
|
+
exp = "#{args1[1]}\nExpected #{Assert::U.show(args1[0], config1)} to be false."
|
87
|
+
assert_that(test_run_results(:fail).first.message).equals(exp)
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
@@ -92,27 +92,27 @@ module Assert::Assertions
|
|
92
92
|
include Assert::Test::TestHelpers
|
93
93
|
|
94
94
|
desc "`assert_not_false`"
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
@test = Factory.test do
|
95
|
+
subject {
|
96
|
+
args = args1
|
97
|
+
Factory.test do
|
99
98
|
assert_not_false(true) # pass
|
100
99
|
assert_not_false(*args) # fail
|
101
100
|
end
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
101
|
+
}
|
102
|
+
|
103
|
+
let(:desc1) { "assert not false fail desc" }
|
104
|
+
let(:args1) { [false, desc1] }
|
105
|
+
let(:config1) { subject.config }
|
106
106
|
|
107
107
|
should "produce results as expected" do
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
108
|
+
subject.run(&test_run_callback)
|
109
|
+
|
110
|
+
assert_that(test_run_result_count).equals(2)
|
111
|
+
assert_that(test_run_result_count(:pass)).equals(1)
|
112
|
+
assert_that(test_run_result_count(:fail)).equals(1)
|
112
113
|
|
113
|
-
|
114
|
-
|
115
|
-
assert_equal exp, test_run_results(:fail).first.message
|
114
|
+
exp = "#{args1[1]}\nExpected #{Assert::U.show(args1[0], config1)} to not be false."
|
115
|
+
assert_that(test_run_results(:fail).first.message).equals(exp)
|
116
116
|
end
|
117
117
|
end
|
118
118
|
end
|
@@ -6,52 +6,54 @@ module Assert::Assertions
|
|
6
6
|
include Assert::Test::TestHelpers
|
7
7
|
|
8
8
|
desc "Assert::Context"
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
14
|
-
subject{ @context }
|
9
|
+
subject { context_class1.new(test1, test1.config, proc { |r| }) }
|
10
|
+
|
11
|
+
let(:context_class1) { Factory.modes_off_context_class }
|
12
|
+
let(:test1) { Factory.test }
|
15
13
|
|
16
14
|
should have_imeths :assert_block, :assert_not_block, :refute_block
|
17
|
-
should have_imeths :assert_raises, :assert_not_raises
|
18
|
-
should have_imeths :assert_raise, :assert_not_raise, :assert_nothing_raised
|
19
|
-
should have_imeths :assert_kind_of, :assert_not_kind_of, :refute_kind_of
|
20
|
-
should have_imeths :assert_instance_of, :assert_not_instance_of, :refute_instance_of
|
21
|
-
should have_imeths :assert_respond_to, :assert_responds_to
|
22
|
-
should have_imeths :assert_not_respond_to, :assert_not_responds_to
|
23
|
-
should have_imeths :refute_respond_to, :refute_responds_to
|
24
|
-
should have_imeths :assert_same, :assert_not_same, :refute_same
|
25
|
-
should have_imeths :assert_equal, :assert_not_equal, :refute_equal
|
26
|
-
should have_imeths :assert_match, :assert_not_match, :assert_no_match, :refute_match
|
27
15
|
should have_imeths :assert_empty, :assert_not_empty, :refute_empty
|
16
|
+
should have_imeths :assert_equal, :assert_not_equal, :refute_equal
|
17
|
+
should have_imeths :assert_file_exists, :assert_not_file_exists, :refute_file_exists
|
28
18
|
should have_imeths :assert_includes, :assert_not_includes
|
29
19
|
should have_imeths :assert_included, :assert_not_included
|
30
20
|
should have_imeths :refute_includes, :refute_included
|
21
|
+
should have_imeths :assert_instance_of, :assert_not_instance_of, :refute_instance_of
|
22
|
+
should have_imeths :assert_kind_of, :assert_not_kind_of, :refute_kind_of
|
23
|
+
should have_imeths :assert_match, :assert_not_match, :assert_no_match, :refute_match
|
31
24
|
should have_imeths :assert_nil, :assert_not_nil, :refute_nil
|
32
25
|
should have_imeths :assert_true, :assert_not_true, :refute_true
|
33
26
|
should have_imeths :assert_false, :assert_not_false, :refute_false
|
34
|
-
should have_imeths :
|
27
|
+
should have_imeths :assert_raises, :assert_not_raises
|
28
|
+
should have_imeths :assert_raise, :assert_not_raise, :assert_nothing_raised
|
29
|
+
should have_imeths :assert_changes, :assert_not_changes, :refute_changes
|
30
|
+
should have_imeths :assert_respond_to, :assert_responds_to
|
31
|
+
should have_imeths :assert_not_respond_to, :assert_not_responds_to
|
32
|
+
should have_imeths :refute_respond_to, :refute_responds_to
|
33
|
+
should have_imeths :assert_same, :assert_not_same, :refute_same
|
35
34
|
end
|
36
35
|
|
37
36
|
class IgnoredTests < UnitTests
|
38
37
|
desc "ignored assertions helpers"
|
39
38
|
setup do
|
40
|
-
|
41
|
-
|
39
|
+
tests.each{ |test| test.run(&test_run_callback) }
|
40
|
+
end
|
41
|
+
|
42
|
+
let(:tests) {
|
43
|
+
context_info = Factory.context_info(context_class1)
|
44
|
+
Assert::Assertions::IGNORED_ASSERTION_HELPERS.map do |helper|
|
42
45
|
Factory.test("ignored assertion helper #{helper}", context_info) do
|
43
46
|
self.send(helper, "doesn't matter")
|
44
47
|
end
|
45
48
|
end
|
46
|
-
|
47
|
-
end
|
49
|
+
}
|
48
50
|
|
49
51
|
should "have an ignored result for each helper in the constant" do
|
50
52
|
exp = Assert::Assertions::IGNORED_ASSERTION_HELPERS.size
|
51
|
-
|
53
|
+
assert_that(test_run_result_count).equals(exp)
|
52
54
|
|
53
55
|
test_run_results.each do |result|
|
54
|
-
|
56
|
+
assert_that(result).is_kind_of(Assert::Result::Ignore)
|
55
57
|
end
|
56
58
|
end
|
57
59
|
|
@@ -60,7 +62,7 @@ module Assert::Assertions
|
|
60
62
|
"The assertion `#{helper}` is not supported."\
|
61
63
|
" Please use another assertion or the basic `assert`."
|
62
64
|
end
|
63
|
-
|
65
|
+
assert_that(test_run_results.collect(&:message)).equals(exp)
|
64
66
|
end
|
65
67
|
end
|
66
68
|
end
|