assert 2.17.0 → 2.18.4
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 +2 -2
- data/README.md +66 -41
- data/assert.gemspec +2 -3
- data/lib/assert.rb +0 -10
- data/lib/assert/actual_value.rb +127 -0
- data/lib/assert/assert_runner.rb +0 -3
- data/lib/assert/assertions.rb +10 -23
- data/lib/assert/cli.rb +30 -46
- data/lib/assert/config.rb +0 -4
- data/lib/assert/config_helpers.rb +0 -4
- data/lib/assert/context.rb +18 -9
- data/lib/assert/context/let_dsl.rb +13 -0
- data/lib/assert/context/method_missing.rb +19 -0
- data/lib/assert/context/setup_dsl.rb +0 -4
- data/lib/assert/context/subject_dsl.rb +23 -28
- data/lib/assert/context/suite_dsl.rb +0 -4
- data/lib/assert/context/test_dsl.rb +0 -4
- data/lib/assert/context_info.rb +0 -4
- data/lib/assert/default_runner.rb +0 -4
- data/lib/assert/default_suite.rb +0 -5
- data/lib/assert/default_view.rb +0 -4
- data/lib/assert/factory.rb +0 -3
- data/lib/assert/file_line.rb +0 -4
- data/lib/assert/macro.rb +0 -3
- data/lib/assert/macros/methods.rb +4 -10
- data/lib/assert/result.rb +2 -17
- data/lib/assert/runner.rb +0 -3
- data/lib/assert/stub.rb +15 -1
- data/lib/assert/suite.rb +0 -4
- data/lib/assert/test.rb +2 -7
- data/lib/assert/utils.rb +0 -4
- data/lib/assert/version.rb +1 -1
- data/lib/assert/view.rb +0 -3
- data/lib/assert/view_helpers.rb +0 -11
- data/log/{.gitkeep → .keep} +0 -0
- data/test/helper.rb +23 -29
- data/test/support/factory.rb +14 -0
- data/test/support/inherited_stuff.rb +0 -2
- data/test/system/stub_tests.rb +332 -352
- data/test/system/test_tests.rb +98 -124
- data/test/unit/actual_value_tests.rb +335 -0
- data/test/unit/assert_tests.rb +121 -46
- data/test/unit/assertions/assert_block_tests.rb +30 -35
- data/test/unit/assertions/assert_empty_tests.rb +33 -35
- data/test/unit/assertions/assert_equal_tests.rb +75 -83
- data/test/unit/assertions/assert_file_exists_tests.rb +32 -36
- data/test/unit/assertions/assert_includes_tests.rb +38 -41
- data/test/unit/assertions/assert_instance_of_tests.rb +34 -37
- data/test/unit/assertions/assert_kind_of_tests.rb +34 -37
- data/test/unit/assertions/assert_match_tests.rb +34 -37
- data/test/unit/assertions/assert_nil_tests.rb +30 -35
- data/test/unit/assertions/assert_raises_tests.rb +54 -60
- data/test/unit/assertions/assert_respond_to_tests.rb +36 -39
- data/test/unit/assertions/assert_same_tests.rb +86 -88
- data/test/unit/assertions/assert_true_false_tests.rb +60 -66
- data/test/unit/assertions_tests.rb +14 -17
- data/test/unit/config_helpers_tests.rb +41 -39
- data/test/unit/config_tests.rb +38 -37
- data/test/unit/context/let_dsl_tests.rb +10 -0
- data/test/unit/context/setup_dsl_tests.rb +68 -87
- data/test/unit/context/subject_dsl_tests.rb +15 -49
- data/test/unit/context/suite_dsl_tests.rb +15 -20
- data/test/unit/context/test_dsl_tests.rb +50 -57
- data/test/unit/context_info_tests.rb +23 -18
- data/test/unit/context_tests.rb +183 -194
- data/test/unit/default_runner_tests.rb +1 -7
- data/test/unit/default_suite_tests.rb +57 -56
- data/test/unit/factory_tests.rb +5 -6
- data/test/unit/file_line_tests.rb +33 -39
- data/test/unit/macro_tests.rb +14 -18
- data/test/unit/result_tests.rb +159 -196
- data/test/unit/runner_tests.rb +64 -71
- data/test/unit/suite_tests.rb +58 -59
- data/test/unit/test_tests.rb +125 -136
- data/test/unit/utils_tests.rb +43 -54
- data/test/unit/view_helpers_tests.rb +54 -58
- data/test/unit/view_tests.rb +22 -27
- metadata +15 -10
- data/tmp/.gitkeep +0 -0
@@ -2,96 +2,90 @@ require "assert"
|
|
2
2
|
require "assert/assertions"
|
3
3
|
|
4
4
|
module Assert::Assertions
|
5
|
-
|
6
5
|
class AssertRaisesTests < Assert::Context
|
7
6
|
include Assert::Test::TestHelpers
|
8
7
|
|
9
8
|
desc "`assert_raises`"
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
assert_raises(StandardError, RuntimeError){ raise(StandardError) }
|
14
|
-
assert_raises(StandardError, RuntimeError,
|
15
|
-
assert_raises(RuntimeError,
|
16
|
-
assert_raises(RuntimeError,
|
17
|
-
assert_raises(
|
9
|
+
subject {
|
10
|
+
desc = desc1
|
11
|
+
Factory.test do
|
12
|
+
assert_raises(StandardError, RuntimeError) { raise(StandardError) } # pass
|
13
|
+
assert_raises(StandardError, RuntimeError, desc) { raise(Exception) } # fail
|
14
|
+
assert_raises(RuntimeError, desc) { raise(StandardError) } # fail
|
15
|
+
assert_raises(RuntimeError, desc) { true } # fail
|
16
|
+
assert_raises(desc) { true } # fail
|
18
17
|
end
|
19
|
-
|
20
|
-
end
|
21
|
-
subject{ @test }
|
18
|
+
}
|
22
19
|
|
23
|
-
|
24
|
-
assert_equal 5, test_run_result_count
|
25
|
-
assert_equal 1, test_run_result_count(:pass)
|
26
|
-
assert_equal 4, test_run_result_count(:fail)
|
27
|
-
end
|
20
|
+
let(:desc1) { "assert raises fail desc" }
|
28
21
|
|
29
|
-
should "
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
22
|
+
should "produce results as expected" do
|
23
|
+
subject.run(&test_run_callback)
|
24
|
+
|
25
|
+
assert_that(test_run_result_count).equals(5)
|
26
|
+
assert_that(test_run_result_count(:pass)).equals(1)
|
27
|
+
assert_that(test_run_result_count(:fail)).equals(4)
|
28
|
+
|
29
|
+
exp =
|
30
|
+
[ "#{desc1}\nStandardError or RuntimeError exception expected, not:",
|
31
|
+
"#{desc1}\nRuntimeError exception expected, not:",
|
32
|
+
"#{desc1}\nRuntimeError exception expected but nothing raised.",
|
33
|
+
"#{desc1}\nAn exception expected but nothing raised."
|
34
|
+
]
|
36
35
|
messages = test_run_results(:fail).map(&:message)
|
37
|
-
messages.each_with_index{ |msg, n|
|
36
|
+
messages.each_with_index{ |msg, n| assert_that(msg).matches(/^#{exp[n]}/) }
|
38
37
|
end
|
39
38
|
|
40
39
|
should "return any raised exception instance" do
|
41
40
|
error = nil
|
42
41
|
error_msg = Factory.string
|
43
|
-
|
44
|
-
|
45
|
-
|
42
|
+
|
43
|
+
test =
|
44
|
+
Factory.test do
|
45
|
+
error = assert_raises(RuntimeError) { raise(RuntimeError, error_msg) }
|
46
|
+
end
|
46
47
|
test.run
|
47
48
|
|
48
|
-
|
49
|
-
|
50
|
-
|
49
|
+
assert_that(error).is_not_nil
|
50
|
+
assert_that(error).is_kind_of(RuntimeError)
|
51
|
+
assert_that(error.message).equals(error_msg)
|
51
52
|
|
52
|
-
test = Factory.test
|
53
|
-
error = assert_raises(RuntimeError){ }
|
54
|
-
end
|
53
|
+
test = Factory.test { error = assert_raises(RuntimeError) {} }
|
55
54
|
test.run
|
56
55
|
|
57
|
-
|
56
|
+
assert_that(error).is_nil
|
58
57
|
end
|
59
|
-
|
60
58
|
end
|
61
59
|
|
62
60
|
class AssertNothingRaisedTests < Assert::Context
|
63
61
|
include Assert::Test::TestHelpers
|
64
62
|
|
65
63
|
desc "`assert_nothing_raised`"
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
self.send(anr){ true } # pass
|
64
|
+
subject {
|
65
|
+
desc = desc1
|
66
|
+
Factory.test do
|
67
|
+
assert_nothing_raised(StandardError, RuntimeError, desc) { raise(StandardError) } # fail
|
68
|
+
assert_nothing_raised(RuntimeError) { raise(StandardError) } # pass
|
69
|
+
assert_nothing_raised(desc) { raise(RuntimeError) } # fail
|
70
|
+
assert_nothing_raised { true } # pass
|
74
71
|
end
|
75
|
-
|
76
|
-
|
77
|
-
|
72
|
+
}
|
73
|
+
|
74
|
+
let(:desc1) { "assert nothing raised fail desc" }
|
78
75
|
|
79
76
|
should "produce results as expected" do
|
80
|
-
|
81
|
-
assert_equal 2, test_run_result_count(:pass)
|
82
|
-
assert_equal 2, test_run_result_count(:fail)
|
83
|
-
end
|
77
|
+
subject.run(&test_run_callback)
|
84
78
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
79
|
+
assert_that(test_run_result_count).equals(4)
|
80
|
+
assert_that(test_run_result_count(:pass)).equals(2)
|
81
|
+
assert_that(test_run_result_count(:fail)).equals(2)
|
82
|
+
|
83
|
+
exp =
|
84
|
+
[ "#{desc1}\nStandardError or RuntimeError exception not expected, but raised:",
|
85
|
+
"#{desc1}\nAn exception not expected, but raised:"
|
86
|
+
]
|
90
87
|
messages = test_run_results(:fail).map(&:message)
|
91
|
-
messages.each_with_index{ |msg, n|
|
88
|
+
messages.each_with_index{ |msg, n| assert_that(msg).matches(/^#{exp[n]}/) }
|
92
89
|
end
|
93
|
-
|
94
90
|
end
|
95
|
-
|
96
91
|
end
|
97
|
-
|
@@ -4,68 +4,65 @@ require "assert/assertions"
|
|
4
4
|
require "assert/utils"
|
5
5
|
|
6
6
|
module Assert::Assertions
|
7
|
-
|
8
7
|
class AssertRespondToTests < Assert::Context
|
9
8
|
include Assert::Test::TestHelpers
|
10
9
|
|
11
10
|
desc "`assert_respond_to`"
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
@test = Factory.test do
|
11
|
+
subject {
|
12
|
+
args = args1
|
13
|
+
Factory.test do
|
16
14
|
assert_respond_to(:abs, 1) # pass
|
17
15
|
assert_respond_to(*args) # fail
|
18
16
|
end
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
17
|
+
}
|
18
|
+
|
19
|
+
let(:desc1) { "assert respond to fail desc" }
|
20
|
+
let(:args1) { [:abs, "1", desc1] }
|
21
|
+
let(:config1) { subject.config }
|
23
22
|
|
24
23
|
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
|
24
|
+
subject.run(&test_run_callback)
|
29
25
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
" to respond to `#{@args[0]}`."
|
34
|
-
assert_equal exp, test_run_results(:fail).first.message
|
35
|
-
end
|
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)
|
36
29
|
|
30
|
+
exp =
|
31
|
+
"#{args1[2]}\n"\
|
32
|
+
"Expected #{Assert::U.show(args1[1], config1)} (#{args1[1].class})"\
|
33
|
+
" to respond to `#{args1[0]}`."
|
34
|
+
assert_that(test_run_results(:fail).first.message).equals(exp)
|
35
|
+
end
|
37
36
|
end
|
38
37
|
|
39
38
|
class AssertNotRespondToTests < Assert::Context
|
40
39
|
include Assert::Test::TestHelpers
|
41
40
|
|
42
41
|
desc "`assert_not_respond_to`"
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
@test = Factory.test do
|
42
|
+
subject {
|
43
|
+
args = args1
|
44
|
+
Factory.test do
|
47
45
|
assert_not_respond_to(*args) # fail
|
48
46
|
assert_not_respond_to(:abs, "1") # pass
|
49
47
|
end
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
48
|
+
}
|
49
|
+
|
50
|
+
let(:desc1) { "assert not respond to fail desc" }
|
51
|
+
let(:args1) { [:abs, 1, desc1] }
|
52
|
+
let(:config1) { subject.config }
|
54
53
|
|
55
54
|
should "produce results as expected" do
|
56
|
-
|
57
|
-
assert_equal 1, test_run_result_count(:pass)
|
58
|
-
assert_equal 1, test_run_result_count(:fail)
|
59
|
-
end
|
55
|
+
subject.run(&test_run_callback)
|
60
56
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
" to not respond to `#{@args[0]}`."
|
65
|
-
assert_equal exp, test_run_results(:fail).first.message
|
66
|
-
end
|
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)
|
67
60
|
|
61
|
+
exp =
|
62
|
+
"#{args1[2]}\n"\
|
63
|
+
"Expected #{Assert::U.show(args1[1], config1)} (#{args1[1].class})"\
|
64
|
+
" to not respond to `#{args1[0]}`."
|
65
|
+
assert_that(test_run_results(:fail).first.message).equals(exp)
|
66
|
+
end
|
68
67
|
end
|
69
|
-
|
70
68
|
end
|
71
|
-
|
@@ -4,139 +4,137 @@ require "assert/assertions"
|
|
4
4
|
require "assert/utils"
|
5
5
|
|
6
6
|
module Assert::Assertions
|
7
|
-
|
8
7
|
class AssertSameTests < Assert::Context
|
9
8
|
include Assert::Test::TestHelpers
|
10
9
|
|
11
10
|
desc "`assert_same`"
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
@test = Factory.test do
|
11
|
+
subject {
|
12
|
+
args = args1
|
13
|
+
object = object1
|
14
|
+
Factory.test do
|
17
15
|
assert_same(object, object) # pass
|
18
16
|
assert_same(*args) # fail
|
19
17
|
end
|
20
|
-
|
21
|
-
@test.run(&test_run_callback)
|
22
|
-
end
|
23
|
-
subject{ @test }
|
18
|
+
}
|
24
19
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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 }
|
30
25
|
|
31
|
-
should "
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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)
|
38
40
|
end
|
39
|
-
|
40
41
|
end
|
41
42
|
|
42
43
|
class AssertNotSameTests < Assert::Context
|
43
44
|
include Assert::Test::TestHelpers
|
44
45
|
|
45
46
|
desc "`assert_not_same`"
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
subject {
|
48
|
+
args = args1
|
49
|
+
object = object1
|
50
|
+
klass = class1
|
51
|
+
Factory.test do
|
51
52
|
assert_not_same(*args) # fail
|
52
53
|
assert_not_same(object, klass.new) # pass
|
53
54
|
end
|
54
|
-
|
55
|
-
@test.run(&test_run_callback)
|
56
|
-
end
|
57
|
-
subject{ @test }
|
55
|
+
}
|
58
56
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
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 }
|
64
62
|
|
65
|
-
should "
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
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)
|
72
77
|
end
|
73
|
-
|
74
78
|
end
|
75
79
|
|
76
80
|
class DiffTests < Assert::Context
|
77
81
|
include Assert::Test::TestHelpers
|
78
82
|
|
79
83
|
desc "with objects that should use diff when showing"
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
@c.run_diff_proc(Assert::U.syscmd_diff_proc)
|
87
|
-
|
88
|
-
@exp_obj_show = Assert::U.show_for_diff(@exp_obj, @c)
|
89
|
-
@act_obj_show = Assert::U.show_for_diff(@act_obj, @c)
|
90
|
-
end
|
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
|
+
}
|
91
90
|
|
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) }
|
92
95
|
end
|
93
96
|
|
94
97
|
class AssertSameDiffTests < DiffTests
|
95
98
|
desc "`assert_same`"
|
96
|
-
|
97
|
-
exp_obj, act_obj =
|
98
|
-
|
99
|
+
subject {
|
100
|
+
exp_obj, act_obj = exp_obj1, act_obj1
|
101
|
+
Factory.test(config1) do
|
99
102
|
assert_same(exp_obj, act_obj)
|
100
103
|
end
|
101
|
-
|
102
|
-
end
|
103
|
-
subject{ @test }
|
104
|
+
}
|
104
105
|
|
105
106
|
should "include diff output in the fail messages" do
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
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)
|
112
116
|
end
|
113
|
-
|
114
117
|
end
|
115
118
|
|
116
119
|
class AssertNotSameDiffTests < DiffTests
|
117
120
|
desc "`assert_not_same`"
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
exp_obj, act_obj = @exp_obj, @act_obj
|
123
|
-
@test = Factory.test(@c) do
|
124
|
-
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)
|
125
125
|
end
|
126
|
-
|
127
|
-
end
|
128
|
-
subject{ @test }
|
126
|
+
}
|
129
127
|
|
130
128
|
should "include diff output in the fail messages" do
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
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)
|
137
138
|
end
|
138
|
-
|
139
139
|
end
|
140
|
-
|
141
140
|
end
|
142
|
-
|