test-unit 2.1.2 → 2.2.0
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.
- data/History.txt +43 -1
- data/Manifest.txt +1 -1
- data/html/index.html +57 -24
- data/html/index.html.ja +49 -25
- data/html/test-unit.css +3 -3
- data/lib/test/unit/assertions.rb +493 -40
- data/lib/test/unit/autorunner.rb +24 -0
- data/lib/test/unit/collector.rb +6 -4
- data/lib/test/unit/collector/load.rb +48 -5
- data/lib/test/unit/fixture.rb +12 -3
- data/lib/test/unit/testsuite.rb +11 -3
- data/lib/test/unit/ui/console/testrunner.rb +42 -8
- data/lib/test/unit/version.rb +1 -1
- data/test/run-test.rb +7 -0
- data/test/{test_assertions.rb → test-assertions.rb} +717 -65
- data/test/test-fixture.rb +37 -0
- data/test/test-testcase.rb +11 -3
- metadata +5 -6
data/lib/test/unit/autorunner.rb
CHANGED
@@ -199,6 +199,18 @@ module Test
|
|
199
199
|
end
|
200
200
|
end
|
201
201
|
|
202
|
+
o.on('--ignore-name=NAME', String,
|
203
|
+
"Ignores tests matching NAME.",
|
204
|
+
"(patterns may be used).") do |n|
|
205
|
+
n = (%r{\A/(.*)/\Z} =~ n ? Regexp.new($1) : n)
|
206
|
+
case n
|
207
|
+
when Regexp
|
208
|
+
@filters << proc {|t| n =~ t.method_name ? false : true}
|
209
|
+
else
|
210
|
+
@filters << proc {|t| n != t.method_name}
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
202
214
|
o.on('-t', '--testcase=TESTCASE', String,
|
203
215
|
"Runs tests in TestCases matching TESTCASE.",
|
204
216
|
"(patterns may be used).") do |n|
|
@@ -211,6 +223,18 @@ module Test
|
|
211
223
|
end
|
212
224
|
end
|
213
225
|
|
226
|
+
o.on('--ignore-testcase=TESTCASE', String,
|
227
|
+
"Ignores tests in TestCases matching TESTCASE.",
|
228
|
+
"(patterns may be used).") do |n|
|
229
|
+
n = (%r{\A/(.*)/\Z} =~ n ? Regexp.new($1) : n)
|
230
|
+
case n
|
231
|
+
when Regexp
|
232
|
+
@filters << proc {|t| n =~ t.class.name ? false : true}
|
233
|
+
else
|
234
|
+
@filters << proc {|t| n != t.class.name}
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
214
238
|
priority_filter = Proc.new do |test|
|
215
239
|
if @filters == [priority_filter]
|
216
240
|
Priority::Checker.new(test).need_to_run?
|
data/lib/test/unit/collector.rb
CHANGED
@@ -15,9 +15,9 @@ module Test
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def add_suite(destination, suite)
|
18
|
-
to_delete = suite.tests.find_all{|t| !include?(t)}
|
19
|
-
to_delete.each{|t| suite.delete(t)}
|
20
|
-
destination << suite unless
|
18
|
+
to_delete = suite.tests.find_all {|t| !include?(t)}
|
19
|
+
to_delete.each {|t| suite.delete(t)}
|
20
|
+
destination << suite unless suite.empty?
|
21
21
|
end
|
22
22
|
|
23
23
|
def include?(test)
|
@@ -29,7 +29,9 @@ module Test
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def sort(suites)
|
32
|
-
suites.sort_by
|
32
|
+
suites.sort_by do |suite|
|
33
|
+
[suite.priority, suite.name || suite.to_s]
|
34
|
+
end
|
33
35
|
end
|
34
36
|
end
|
35
37
|
end
|
@@ -18,6 +18,7 @@ module Test
|
|
18
18
|
@patterns = [/\Atest[_\-].+\.rb\z/m, /[_\-]test\.rb\z/]
|
19
19
|
@excludes = []
|
20
20
|
@base = nil
|
21
|
+
@require_failed_infos = []
|
21
22
|
end
|
22
23
|
|
23
24
|
def base=(base)
|
@@ -39,16 +40,18 @@ module Test
|
|
39
40
|
collect_file(from, test_suites, already_gathered)
|
40
41
|
end
|
41
42
|
end
|
43
|
+
add_require_failed_test_suite(test_suites)
|
42
44
|
|
43
45
|
if test_suites.size > 1
|
44
46
|
test_suite = TestSuite.new("[#{froms.join(', ')}]")
|
45
47
|
sort(test_suites).each do |sub_test_suite|
|
46
48
|
test_suite << sub_test_suite
|
47
49
|
end
|
48
|
-
test_suite
|
49
50
|
else
|
50
|
-
test_suites.first
|
51
|
+
test_suite = test_suites.first
|
51
52
|
end
|
53
|
+
|
54
|
+
test_suite
|
52
55
|
end
|
53
56
|
end
|
54
57
|
|
@@ -95,9 +98,14 @@ module Test
|
|
95
98
|
|
96
99
|
def collect_file(path, test_suites, already_gathered)
|
97
100
|
@program_file ||= File.expand_path($0)
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
+
expanded_path = path.expand_path
|
102
|
+
return if @program_file == expanded_path.to_s
|
103
|
+
add_load_path(expanded_path.dirname) do
|
104
|
+
begin
|
105
|
+
require(path.to_s)
|
106
|
+
rescue LoadError
|
107
|
+
@require_failed_infos << {:path => expanded_path, :exception => $!}
|
108
|
+
end
|
101
109
|
find_test_cases(already_gathered).each do |test_case|
|
102
110
|
add_suite(test_suites, test_case.suite)
|
103
111
|
end
|
@@ -138,6 +146,41 @@ module Test
|
|
138
146
|
|
139
147
|
false
|
140
148
|
end
|
149
|
+
|
150
|
+
def add_require_failed_test_suite(test_suites)
|
151
|
+
return if @require_failed_infos.empty?
|
152
|
+
|
153
|
+
require_failed_infos = @require_failed_infos
|
154
|
+
require_failed_omissions = Class.new(Test::Unit::TestCase)
|
155
|
+
require_failed_omissions.class_eval do
|
156
|
+
class << self
|
157
|
+
def name
|
158
|
+
"RequireFailedOmissions"
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
require_failed_infos.each do |info|
|
163
|
+
path = info[:path]
|
164
|
+
normalized_path = path.to_s.gsub(/[^a-z0-9\_]+/i, '_')
|
165
|
+
normalized_path = normalized_path.gsub(/\A_+/, '')
|
166
|
+
exception = info[:exception]
|
167
|
+
define_method("test_require_#{normalized_path}") do
|
168
|
+
@require_failed_exception = exception
|
169
|
+
omit("failed to load: <#{path}>: <#{exception.message}>")
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
def priority
|
174
|
+
100
|
175
|
+
end
|
176
|
+
|
177
|
+
def filter_backtrace(location)
|
178
|
+
super(@require_failed_exception.backtrace)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
add_suite(test_suites, require_failed_omissions.suite)
|
183
|
+
end
|
141
184
|
end
|
142
185
|
end
|
143
186
|
end
|
data/lib/test/unit/fixture.rb
CHANGED
@@ -154,13 +154,22 @@ module Test
|
|
154
154
|
end
|
155
155
|
|
156
156
|
private
|
157
|
-
def run_fixture(fixture)
|
157
|
+
def run_fixture(fixture, options={})
|
158
158
|
[
|
159
159
|
self.class.send("before_#{fixture}_methods"),
|
160
160
|
fixture,
|
161
161
|
self.class.send("after_#{fixture}_methods")
|
162
162
|
].flatten.each do |method_name|
|
163
|
-
|
163
|
+
next unless respond_to?(method_name, true)
|
164
|
+
if options[:handle_exception]
|
165
|
+
begin
|
166
|
+
send(method_name)
|
167
|
+
rescue Exception
|
168
|
+
raise unless handle_exception($!)
|
169
|
+
end
|
170
|
+
else
|
171
|
+
send(method_name)
|
172
|
+
end
|
164
173
|
end
|
165
174
|
end
|
166
175
|
|
@@ -169,7 +178,7 @@ module Test
|
|
169
178
|
end
|
170
179
|
|
171
180
|
def run_teardown
|
172
|
-
run_fixture(:teardown)
|
181
|
+
run_fixture(:teardown, :handle_exception => true)
|
173
182
|
end
|
174
183
|
end
|
175
184
|
end
|
data/lib/test/unit/testsuite.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
#
|
3
3
|
# Author:: Nathaniel Talbott.
|
4
4
|
# Copyright:: Copyright (c) 2000-2003 Nathaniel Talbott. All rights reserved.
|
5
|
+
# Copyright:: Copyright (c) 2008-2011 Kouhei Sutou. All rights reserved.
|
5
6
|
# License:: Ruby license.
|
6
7
|
|
7
8
|
require 'test/unit/error'
|
@@ -18,7 +19,11 @@ module Test
|
|
18
19
|
# meaningful TestSuite instance.
|
19
20
|
class TestSuite
|
20
21
|
attr_reader :name, :tests
|
21
|
-
|
22
|
+
|
23
|
+
# Test suite that has higher priority is ran prior to
|
24
|
+
# test suites that have lower priority.
|
25
|
+
attr_accessor :priority
|
26
|
+
|
22
27
|
STARTED = name + "::STARTED"
|
23
28
|
FINISHED = name + "::FINISHED"
|
24
29
|
|
@@ -27,6 +32,8 @@ module Test
|
|
27
32
|
@name = name
|
28
33
|
@tests = []
|
29
34
|
@test_case = test_case
|
35
|
+
@n_tests = 0
|
36
|
+
@priority = 0
|
30
37
|
end
|
31
38
|
|
32
39
|
# Runs the tests and/or suites contained in this
|
@@ -34,7 +41,8 @@ module Test
|
|
34
41
|
def run(result, &progress_block)
|
35
42
|
yield(STARTED, name)
|
36
43
|
run_startup(result)
|
37
|
-
@tests.
|
44
|
+
while test = @tests.shift
|
45
|
+
@n_tests += test.size
|
38
46
|
test.run(result, &progress_block)
|
39
47
|
end
|
40
48
|
run_shutdown(result)
|
@@ -55,7 +63,7 @@ module Test
|
|
55
63
|
# i.e. if the suite contains other suites, it counts the
|
56
64
|
# tests within those suites, not the suites themselves.
|
57
65
|
def size
|
58
|
-
total_size =
|
66
|
+
total_size = @n_tests
|
59
67
|
@tests.each { |test| total_size += test.size }
|
60
68
|
total_size
|
61
69
|
end
|
@@ -64,13 +64,13 @@ module Test
|
|
64
64
|
@mediator.add_listener(TestSuite::STARTED, &method(:test_suite_started))
|
65
65
|
@mediator.add_listener(TestSuite::FINISHED, &method(:test_suite_finished))
|
66
66
|
end
|
67
|
-
|
67
|
+
|
68
68
|
def add_fault(fault)
|
69
69
|
@faults << fault
|
70
70
|
output_progress(fault.single_character_display, fault_color(fault))
|
71
71
|
@already_outputted = true if fault.critical?
|
72
72
|
end
|
73
|
-
|
73
|
+
|
74
74
|
def started(result)
|
75
75
|
@result = result
|
76
76
|
output_started
|
@@ -92,6 +92,15 @@ module Test
|
|
92
92
|
nl
|
93
93
|
output(@result, result_color)
|
94
94
|
output("%g%% passed" % @result.pass_percentage, result_color)
|
95
|
+
unless elapsed_time.zero?
|
96
|
+
nl
|
97
|
+
throuputs =
|
98
|
+
[
|
99
|
+
"%.2f tests/s" % [@result.run_count / elapsed_time],
|
100
|
+
"%.2f assertions/s" % [@result.assertion_count / elapsed_time],
|
101
|
+
]
|
102
|
+
output(throuputs.join(", "))
|
103
|
+
end
|
95
104
|
end
|
96
105
|
|
97
106
|
def output_fault(fault)
|
@@ -133,18 +142,43 @@ module Test
|
|
133
142
|
end
|
134
143
|
|
135
144
|
def output_fault_message(fault)
|
145
|
+
if fault.expected.respond_to?(:encoding) and
|
146
|
+
fault.actual.respond_to?(:encoding) and
|
147
|
+
fault.expected.encoding != fault.actual.encoding
|
148
|
+
need_encoding = true
|
149
|
+
else
|
150
|
+
need_encoding = false
|
151
|
+
end
|
136
152
|
output(fault.user_message) if fault.user_message
|
137
153
|
output_single("<")
|
138
154
|
output_single(fault.inspected_expected, color("pass"))
|
139
|
-
|
155
|
+
output_single(">")
|
156
|
+
if need_encoding
|
157
|
+
output_single("(")
|
158
|
+
output_single(fault.expected.encoding.name, color("pass"))
|
159
|
+
output_single(")")
|
160
|
+
end
|
161
|
+
output(" expected but was")
|
140
162
|
output_single("<")
|
141
163
|
output_single(fault.inspected_actual, color("failure"))
|
142
|
-
|
164
|
+
output_single(">")
|
165
|
+
if need_encoding
|
166
|
+
output_single("(")
|
167
|
+
output_single(fault.actual.encoding.name, color("failure"))
|
168
|
+
output_single(")")
|
169
|
+
end
|
170
|
+
output("")
|
143
171
|
from, to = prepare_for_diff(fault.expected, fault.actual)
|
144
172
|
if from and to
|
145
|
-
|
146
|
-
|
147
|
-
|
173
|
+
from_lines = from.split(/\r?\n/)
|
174
|
+
to_lines = to.split(/\r?\n/)
|
175
|
+
if need_encoding
|
176
|
+
from_lines << ""
|
177
|
+
to_lines << ""
|
178
|
+
from_lines << "Encoding: #{fault.expected.encoding.name}"
|
179
|
+
to_lines << "Encoding: #{fault.actual.encoding.name}"
|
180
|
+
end
|
181
|
+
differ = ColorizedReadableDiffer.new(from_lines, to_lines, self)
|
148
182
|
if differ.need_diff?
|
149
183
|
output("")
|
150
184
|
output("diff:")
|
@@ -286,7 +320,7 @@ module Test
|
|
286
320
|
end
|
287
321
|
|
288
322
|
def guess_term_width
|
289
|
-
Integer(ENV["TERM_WIDTH"] || 0)
|
323
|
+
Integer(ENV["COLUMNS"] || ENV["TERM_WIDTH"] || 0)
|
290
324
|
rescue ArgumentError
|
291
325
|
0
|
292
326
|
end
|
data/lib/test/unit/version.rb
CHANGED
data/test/run-test.rb
CHANGED
@@ -12,4 +12,11 @@ $LOAD_PATH.unshift(lib_dir)
|
|
12
12
|
|
13
13
|
require 'test/unit'
|
14
14
|
|
15
|
+
test_unit_notify_base_dir = File.join(base_dir, "..", "test-unit-notify")
|
16
|
+
test_unit_notify_base_dir = File.expand_path(test_unit_notify_base_dir)
|
17
|
+
if File.exist?(test_unit_notify_base_dir)
|
18
|
+
$LOAD_PATH.unshift(File.join(test_unit_notify_base_dir, "lib"))
|
19
|
+
require 'test/unit/notify'
|
20
|
+
end
|
21
|
+
|
15
22
|
exit Test::Unit::AutoRunner.run(true, test_dir)
|
@@ -9,11 +9,12 @@ require 'test/unit'
|
|
9
9
|
|
10
10
|
module Test
|
11
11
|
module Unit
|
12
|
-
|
12
|
+
module AssertionCheckable
|
13
13
|
backtrace_pre = "---Backtrace---"
|
14
14
|
backtrace_post = "---------------"
|
15
15
|
BACKTRACE_RE = /#{backtrace_pre}\n.+\n#{backtrace_post}/m
|
16
16
|
|
17
|
+
private
|
17
18
|
def check(value, message="")
|
18
19
|
add_assertion
|
19
20
|
raise AssertionFailedError.new(message) unless value
|
@@ -92,6 +93,24 @@ module Test
|
|
92
93
|
end
|
93
94
|
end
|
94
95
|
|
96
|
+
def add_failure(message, location=caller, options=nil)
|
97
|
+
unless @catch_assertions
|
98
|
+
super
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def add_assertion
|
103
|
+
if @catch_assertions
|
104
|
+
@actual_assertion_count += 1
|
105
|
+
else
|
106
|
+
super
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
class TestAssertions < TestCase
|
112
|
+
include AssertionCheckable
|
113
|
+
|
95
114
|
def test_assert_block
|
96
115
|
check_nothing_fails {
|
97
116
|
assert_block {true}
|
@@ -109,16 +128,7 @@ module Test
|
|
109
128
|
assert_block("failed assert_block") {false}
|
110
129
|
}
|
111
130
|
end
|
112
|
-
|
113
|
-
def test_assert
|
114
|
-
check_nothing_fails{assert("a")}
|
115
|
-
check_nothing_fails{assert(true)}
|
116
|
-
check_nothing_fails{assert(true, "successful assert")}
|
117
|
-
check_fails("<nil> is not true."){assert(nil)}
|
118
|
-
check_fails("<false> is not true."){assert(false)}
|
119
|
-
check_fails("failed assert.\n<false> is not true."){assert(false, "failed assert")}
|
120
|
-
end
|
121
|
-
|
131
|
+
|
122
132
|
def test_assert_equal
|
123
133
|
check_nothing_fails {
|
124
134
|
assert_equal("string1", "string1")
|
@@ -328,6 +338,24 @@ EOM
|
|
328
338
|
end
|
329
339
|
end
|
330
340
|
|
341
|
+
def test_assert_equal_with_different_hash
|
342
|
+
designers = {
|
343
|
+
"Ruby" => "Matz",
|
344
|
+
"Lisp" => "John McCarthy",
|
345
|
+
}
|
346
|
+
categories = {
|
347
|
+
"LL" => ["Ruby", "Python"],
|
348
|
+
"Heavy" => ["C", "C++"],
|
349
|
+
}
|
350
|
+
message = <<-EOM.chomp
|
351
|
+
<{"Lisp"=>"John McCarthy", "Ruby"=>"Matz"}> expected but was
|
352
|
+
<{"Heavy"=>["C", "C++"], "LL"=>["Ruby", "Python"]}>.
|
353
|
+
EOM
|
354
|
+
check_fails(message) do
|
355
|
+
assert_equal(designers, categories)
|
356
|
+
end
|
357
|
+
end
|
358
|
+
|
331
359
|
def test_assert_raise_success
|
332
360
|
return_value = nil
|
333
361
|
check_nothing_fails(true) do
|
@@ -729,7 +757,44 @@ EOM
|
|
729
757
|
assert_not_equal("string", "string", "message")
|
730
758
|
}
|
731
759
|
end
|
732
|
-
|
760
|
+
|
761
|
+
def test_assert_not_match_pass
|
762
|
+
check_nothing_fails do
|
763
|
+
assert_not_match(/sling/, "string")
|
764
|
+
end
|
765
|
+
end
|
766
|
+
|
767
|
+
def test_assert_not_match_pass_with_message
|
768
|
+
check_nothing_fails do
|
769
|
+
assert_not_match(/sling/, "string", "message")
|
770
|
+
end
|
771
|
+
end
|
772
|
+
|
773
|
+
def test_assert_not_match_fail_not_regexp
|
774
|
+
check_fails("<REGEXP> in assert_not_match(<REGEXP>, ...) " +
|
775
|
+
"should be a Regexp.\n" +
|
776
|
+
"<\"asdf\"> expected to be an instance of\n" +
|
777
|
+
"<Regexp> but was\n" +
|
778
|
+
"<String>.") do
|
779
|
+
assert_not_match("asdf", "asdf")
|
780
|
+
end
|
781
|
+
end
|
782
|
+
|
783
|
+
def test_assert_not_match_fail_match
|
784
|
+
check_fails("</string/> expected to not match\n" +
|
785
|
+
"<\"string\">.") do
|
786
|
+
assert_not_match(/string/, "string")
|
787
|
+
end
|
788
|
+
end
|
789
|
+
|
790
|
+
def test_assert_not_match_fail_match_with_message
|
791
|
+
check_fails("message.\n" +
|
792
|
+
"</string/> expected to not match\n" +
|
793
|
+
"<\"string\">.") do
|
794
|
+
assert_not_match(/string/, "string", "message")
|
795
|
+
end
|
796
|
+
end
|
797
|
+
|
733
798
|
def test_assert_no_match
|
734
799
|
check_nothing_fails{assert_no_match(/sling/, "string")}
|
735
800
|
check_nothing_fails{assert_no_match(/sling/, "string", "message")}
|
@@ -743,7 +808,7 @@ EOM
|
|
743
808
|
assert_no_match(/string/, "string", "message")
|
744
809
|
end
|
745
810
|
end
|
746
|
-
|
811
|
+
|
747
812
|
def test_assert_throw
|
748
813
|
check_nothing_fails do
|
749
814
|
assert_throw(:thing, "message") do
|
@@ -795,7 +860,7 @@ EOM
|
|
795
860
|
assert_operator("thing1", :==, "thing2", "message")
|
796
861
|
}
|
797
862
|
end
|
798
|
-
|
863
|
+
|
799
864
|
def test_assert_respond_to
|
800
865
|
check_nothing_fails {
|
801
866
|
assert_respond_to("thing", :to_s, "message")
|
@@ -808,48 +873,39 @@ EOM
|
|
808
873
|
assert_respond_to("thing", 0.15)
|
809
874
|
}
|
810
875
|
check_fails("message.\n" +
|
811
|
-
"<:symbol>.respond_to?(:
|
876
|
+
"<:symbol>.respond_to?(:nonexistence) expected\n" +
|
812
877
|
"(Class: <Symbol>)") {
|
813
|
-
assert_respond_to(:symbol, :
|
878
|
+
assert_respond_to(:symbol, :nonexistence, "message")
|
814
879
|
}
|
815
880
|
end
|
816
|
-
|
817
|
-
def
|
818
|
-
check_nothing_fails
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
check_nothing_fails
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
881
|
+
|
882
|
+
def test_assert_not_respond_to_pass_symbol
|
883
|
+
check_nothing_fails do
|
884
|
+
assert_not_respond_to("thing", :nonexistent, "message")
|
885
|
+
end
|
886
|
+
end
|
887
|
+
|
888
|
+
def test_assert_not_respond_to_pass_string
|
889
|
+
check_nothing_fails do
|
890
|
+
assert_not_respond_to("thing", :nonexistent, "message")
|
891
|
+
end
|
892
|
+
end
|
893
|
+
|
894
|
+
def test_assert_not_respond_to_fail_number
|
895
|
+
check_fails("<0.15>.kind_of?(Symbol) or\n" +
|
896
|
+
"<0.15>.respond_to?(:to_str) expected") do
|
897
|
+
assert_respond_to("thing", 0.15)
|
898
|
+
end
|
899
|
+
end
|
900
|
+
|
901
|
+
def tset_assert_not_respond_to_fail_existence
|
831
902
|
check_fails("message.\n" +
|
832
|
-
"
|
833
|
-
"
|
834
|
-
|
835
|
-
|
836
|
-
"<<0.4> < <0.5>-<0.05>(0.45) <= <0.5>+<0.05>(0.55)>") {
|
837
|
-
assert_in_delta(0.5, 0.4, 0.05, "message")
|
838
|
-
}
|
839
|
-
object = Object.new
|
840
|
-
inspected_object = AssertionMessage.convert(object)
|
841
|
-
check_fails("The arguments must respond to to_f; " +
|
842
|
-
"the first float did not.\n" +
|
843
|
-
"<#{inspected_object}>.respond_to?(:to_f) expected\n" +
|
844
|
-
"(Class: <Object>)") {
|
845
|
-
assert_in_delta(object, 0.4, 0.1)
|
846
|
-
}
|
847
|
-
check_fails("The delta should not be negative.\n" +
|
848
|
-
"<-0.1> expected to be\n>=\n<0.0>.") {
|
849
|
-
assert_in_delta(0.5, 0.4, -0.1, "message")
|
850
|
-
}
|
903
|
+
"!<:symbol>.respond_to?(:to_s) expected\n" +
|
904
|
+
"(Class: <Symbol>)") do
|
905
|
+
assert_respond_to(:symbol, :to_s, "message")
|
906
|
+
end
|
851
907
|
end
|
852
|
-
|
908
|
+
|
853
909
|
def test_assert_send
|
854
910
|
object = Object.new
|
855
911
|
class << object
|
@@ -858,14 +914,22 @@ EOM
|
|
858
914
|
return argument
|
859
915
|
end
|
860
916
|
end
|
861
|
-
check_nothing_fails
|
917
|
+
check_nothing_fails do
|
862
918
|
assert_send([object, :return_argument, true, "bogus"], "message")
|
863
|
-
|
864
|
-
|
919
|
+
end
|
920
|
+
|
921
|
+
inspected_object = AssertionMessage.convert(object)
|
922
|
+
expected_message = <<-EOM
|
923
|
+
message.
|
924
|
+
<#{inspected_object}> expected to respond to
|
925
|
+
<return_argument(*[false, "bogus"])> with a true value but was
|
926
|
+
<false>.
|
927
|
+
EOM
|
928
|
+
check_fails(expected_message.chomp) do
|
865
929
|
assert_send([object, :return_argument, false, "bogus"], "message")
|
866
|
-
|
930
|
+
end
|
867
931
|
end
|
868
|
-
|
932
|
+
|
869
933
|
def test_condition_invariant
|
870
934
|
object = Object.new
|
871
935
|
def object.inspect
|
@@ -1177,19 +1241,607 @@ EOM
|
|
1177
1241
|
assert_path_not_exist(__FILE__)
|
1178
1242
|
end
|
1179
1243
|
end
|
1244
|
+
end
|
1180
1245
|
|
1181
|
-
|
1182
|
-
|
1183
|
-
|
1184
|
-
|
1246
|
+
class TestAssert < TestCase
|
1247
|
+
include AssertionCheckable
|
1248
|
+
|
1249
|
+
def test_pass
|
1250
|
+
check_nothing_fails do
|
1251
|
+
assert(true)
|
1185
1252
|
end
|
1186
1253
|
end
|
1187
1254
|
|
1188
|
-
def
|
1189
|
-
|
1190
|
-
|
1191
|
-
|
1192
|
-
|
1255
|
+
def test_pass_neither_false_or_nil
|
1256
|
+
check_nothing_fails do
|
1257
|
+
assert("a")
|
1258
|
+
end
|
1259
|
+
end
|
1260
|
+
|
1261
|
+
def test_pass_with_message
|
1262
|
+
check_nothing_fails do
|
1263
|
+
assert(true, "successful assert")
|
1264
|
+
end
|
1265
|
+
end
|
1266
|
+
|
1267
|
+
def test_fail_nil
|
1268
|
+
check_fails("<nil> is not true.") do
|
1269
|
+
assert(nil)
|
1270
|
+
end
|
1271
|
+
end
|
1272
|
+
|
1273
|
+
def test_fail_false
|
1274
|
+
check_fails("<false> is not true.") do
|
1275
|
+
assert(false)
|
1276
|
+
end
|
1277
|
+
end
|
1278
|
+
|
1279
|
+
def test_fail_false_with_message
|
1280
|
+
check_fails("failed assert.\n" +
|
1281
|
+
"<false> is not true.") do
|
1282
|
+
assert(false, "failed assert")
|
1283
|
+
end
|
1284
|
+
end
|
1285
|
+
|
1286
|
+
def test_error_invalid_message
|
1287
|
+
check_fails("assertion message must be String or Proc: " +
|
1288
|
+
"<true>(<TrueClass>)") do
|
1289
|
+
begin
|
1290
|
+
assert(true, true)
|
1291
|
+
rescue ArgumentError
|
1292
|
+
raise AssertionFailedError, $!.message
|
1293
|
+
end
|
1294
|
+
end
|
1295
|
+
end
|
1296
|
+
end
|
1297
|
+
|
1298
|
+
class TestAssertInDelta < TestCase
|
1299
|
+
include AssertionCheckable
|
1300
|
+
|
1301
|
+
def test_pass
|
1302
|
+
check_nothing_fails do
|
1303
|
+
assert_in_delta(1.4, 1.4, 0)
|
1304
|
+
end
|
1305
|
+
end
|
1306
|
+
|
1307
|
+
def test_pass_without_delta
|
1308
|
+
check_nothing_fails do
|
1309
|
+
assert_in_delta(1.401, 1.402)
|
1310
|
+
end
|
1311
|
+
end
|
1312
|
+
|
1313
|
+
def test_pass_with_message
|
1314
|
+
check_nothing_fails do
|
1315
|
+
assert_in_delta(0.5, 0.4, 0.1, "message")
|
1316
|
+
end
|
1317
|
+
end
|
1318
|
+
|
1319
|
+
def test_pass_float_like_object
|
1320
|
+
check_nothing_fails do
|
1321
|
+
float_thing = Object.new
|
1322
|
+
def float_thing.to_f
|
1323
|
+
0.2
|
1324
|
+
end
|
1325
|
+
assert_in_delta(0.1, float_thing, 0.1)
|
1326
|
+
end
|
1327
|
+
end
|
1328
|
+
|
1329
|
+
def test_pass_string_expected
|
1330
|
+
check_nothing_fails do
|
1331
|
+
assert_in_delta("0.5", 0.4, 0.1)
|
1332
|
+
end
|
1333
|
+
end
|
1334
|
+
|
1335
|
+
def test_fail_with_message
|
1336
|
+
check_fails("message.\n" +
|
1337
|
+
"<0.5> -/+ <0.05> expected to include\n" +
|
1338
|
+
"<0.4>.\n" +
|
1339
|
+
"\n" +
|
1340
|
+
"Relation:\n" +
|
1341
|
+
"<<0.4> < <0.5>-<0.05>[0.45] <= <0.5>+<0.05>[0.55]>") do
|
1342
|
+
assert_in_delta(0.5, 0.4, 0.05, "message")
|
1343
|
+
end
|
1344
|
+
end
|
1345
|
+
|
1346
|
+
def test_fail_because_not_float_like_object
|
1347
|
+
object = Object.new
|
1348
|
+
inspected_object = AssertionMessage.convert(object)
|
1349
|
+
check_fails("The arguments must respond to to_f; " +
|
1350
|
+
"the first float did not.\n" +
|
1351
|
+
"<#{inspected_object}>.respond_to?(:to_f) expected\n" +
|
1352
|
+
"(Class: <Object>)") do
|
1353
|
+
assert_in_delta(object, 0.4, 0.1)
|
1354
|
+
end
|
1355
|
+
end
|
1356
|
+
|
1357
|
+
def test_fail_because_negaitve_delta
|
1358
|
+
check_fails("The delta should not be negative.\n" +
|
1359
|
+
"<-0.1> expected to be\n>=\n<0.0>.") do
|
1360
|
+
assert_in_delta(0.5, 0.4, -0.1, "message")
|
1361
|
+
end
|
1362
|
+
end
|
1363
|
+
|
1364
|
+
def test_fail_without_delta
|
1365
|
+
check_fails("<1.402> -/+ <0.001> expected to include\n" +
|
1366
|
+
"<1.404>.\n" +
|
1367
|
+
"\n" +
|
1368
|
+
"Relation:\n" +
|
1369
|
+
"<" +
|
1370
|
+
"<1.402>-<0.001>[#{1.402 - 0.001}] <= " +
|
1371
|
+
"<1.402>+<0.001>[#{1.402 + 0.001}] < " +
|
1372
|
+
"<1.404>" +
|
1373
|
+
">") do
|
1374
|
+
assert_in_delta(1.402, 1.404)
|
1375
|
+
end
|
1376
|
+
end
|
1377
|
+
end
|
1378
|
+
|
1379
|
+
class TestAssertNotInDelta < Test::Unit::TestCase
|
1380
|
+
include AssertionCheckable
|
1381
|
+
|
1382
|
+
def test_pass
|
1383
|
+
check_nothing_fails do
|
1384
|
+
assert_not_in_delta(1.42, 1.44, 0.01)
|
1385
|
+
end
|
1386
|
+
end
|
1387
|
+
|
1388
|
+
def test_pass_without_delta
|
1389
|
+
check_nothing_fails do
|
1390
|
+
assert_not_in_delta(1.402, 1.404)
|
1391
|
+
end
|
1392
|
+
end
|
1393
|
+
|
1394
|
+
def test_pass_with_message
|
1395
|
+
check_nothing_fails do
|
1396
|
+
assert_not_in_delta(0.5, 0.4, 0.09, "message")
|
1397
|
+
end
|
1398
|
+
end
|
1399
|
+
|
1400
|
+
def test_pass_float_like_object
|
1401
|
+
check_nothing_fails do
|
1402
|
+
float_thing = Object.new
|
1403
|
+
def float_thing.to_f
|
1404
|
+
0.2
|
1405
|
+
end
|
1406
|
+
assert_not_in_delta(0.1, float_thing, 0.09)
|
1407
|
+
end
|
1408
|
+
end
|
1409
|
+
|
1410
|
+
def test_pass_string_epxected
|
1411
|
+
check_nothing_fails do
|
1412
|
+
assert_not_in_delta("0.5", 0.4, 0.09)
|
1413
|
+
end
|
1414
|
+
end
|
1415
|
+
|
1416
|
+
def test_fail
|
1417
|
+
check_fails("<1.4> -/+ <0.11> expected to not include\n" +
|
1418
|
+
"<1.5>.\n" +
|
1419
|
+
"\n" +
|
1420
|
+
"Relation:\n" +
|
1421
|
+
"<" +
|
1422
|
+
"<1.4>-<0.11>[#{1.4 - 0.11}] <= " +
|
1423
|
+
"<1.5> <= " +
|
1424
|
+
"<1.4>+<0.11>[#{1.4 + 0.11}]" +
|
1425
|
+
">") do
|
1426
|
+
assert_not_in_delta(1.4, 1.5, 0.11)
|
1427
|
+
end
|
1428
|
+
end
|
1429
|
+
|
1430
|
+
def test_fail_without_delta
|
1431
|
+
check_fails("<1.402> -/+ <0.001> expected to not include\n" +
|
1432
|
+
"<1.4021>.\n" +
|
1433
|
+
"\n" +
|
1434
|
+
"Relation:\n" +
|
1435
|
+
"<" +
|
1436
|
+
"<1.402>-<0.001>[#{1.402 - 0.001}] <= " +
|
1437
|
+
"<1.4021> <= " +
|
1438
|
+
"<1.402>+<0.001>[#{1.402 + 0.001}]" +
|
1439
|
+
">") do
|
1440
|
+
assert_not_in_delta(1.402, 1.4021)
|
1441
|
+
end
|
1442
|
+
end
|
1443
|
+
|
1444
|
+
def test_fail_with_message
|
1445
|
+
check_fails("message.\n" +
|
1446
|
+
"<0.5> -/+ <0.11> expected to not include\n" +
|
1447
|
+
"<0.4>.\n" +
|
1448
|
+
"\n" +
|
1449
|
+
"Relation:\n" +
|
1450
|
+
"<" +
|
1451
|
+
"<0.5>-<0.11>[0.39] <= " +
|
1452
|
+
"<0.4> <= " +
|
1453
|
+
"<0.5>+<0.11>[0.61]" +
|
1454
|
+
">") do
|
1455
|
+
assert_not_in_delta(0.5, 0.4, 0.11, "message")
|
1456
|
+
end
|
1457
|
+
end
|
1458
|
+
|
1459
|
+
def test_fail_because_not_float_like_object
|
1460
|
+
object = Object.new
|
1461
|
+
inspected_object = AssertionMessage.convert(object)
|
1462
|
+
check_fails("The arguments must respond to to_f; " +
|
1463
|
+
"the first float did not.\n" +
|
1464
|
+
"<#{inspected_object}>.respond_to?(:to_f) expected\n" +
|
1465
|
+
"(Class: <Object>)") do
|
1466
|
+
assert_not_in_delta(object, 0.4, 0.1)
|
1467
|
+
end
|
1468
|
+
end
|
1469
|
+
|
1470
|
+
def test_fail_because_negaitve_delta
|
1471
|
+
check_fails("The delta should not be negative.\n" +
|
1472
|
+
"<-0.11> expected to be\n>=\n<0.0>.") do
|
1473
|
+
assert_not_in_delta(0.5, 0.4, -0.11, "message")
|
1474
|
+
end
|
1475
|
+
end
|
1476
|
+
end
|
1477
|
+
|
1478
|
+
class TestAssertInEpsilon < TestCase
|
1479
|
+
include AssertionCheckable
|
1480
|
+
|
1481
|
+
def test_pass
|
1482
|
+
check_nothing_fails do
|
1483
|
+
assert_in_epsilon(10000, 9000, 0.1)
|
1484
|
+
end
|
1485
|
+
end
|
1486
|
+
|
1487
|
+
def test_pass_without_epsilon
|
1488
|
+
check_nothing_fails do
|
1489
|
+
assert_in_epsilon(10000, 9991)
|
1490
|
+
end
|
1491
|
+
end
|
1492
|
+
|
1493
|
+
def test_pass_with_message
|
1494
|
+
check_nothing_fails do
|
1495
|
+
assert_in_epsilon(10000, 9000, 0.1, "message")
|
1496
|
+
end
|
1497
|
+
end
|
1498
|
+
|
1499
|
+
def test_pass_float_like_object
|
1500
|
+
check_nothing_fails do
|
1501
|
+
float_thing = Object.new
|
1502
|
+
def float_thing.to_f
|
1503
|
+
9000.0
|
1504
|
+
end
|
1505
|
+
assert_in_epsilon(10000, float_thing, 0.1)
|
1506
|
+
end
|
1507
|
+
end
|
1508
|
+
|
1509
|
+
def test_pass_string_expected
|
1510
|
+
check_nothing_fails do
|
1511
|
+
assert_in_epsilon("10000", 9000, 0.1)
|
1512
|
+
end
|
1513
|
+
end
|
1514
|
+
|
1515
|
+
def test_fail_with_message
|
1516
|
+
check_fails("message.\n" +
|
1517
|
+
"<10000> -/+ (<10000> * <0.1>)[1000.0] " +
|
1518
|
+
"expected to include\n" +
|
1519
|
+
"<8999>.\n" +
|
1520
|
+
"\n" +
|
1521
|
+
"Relation:\n" +
|
1522
|
+
"<" +
|
1523
|
+
"<8999> < " +
|
1524
|
+
"<10000>-(<10000>*<0.1>)[9000.0] <= " +
|
1525
|
+
"<10000>+(<10000>*<0.1>)[11000.0]" +
|
1526
|
+
">") do
|
1527
|
+
assert_in_epsilon(10000, 8999, 0.1, "message")
|
1528
|
+
end
|
1529
|
+
end
|
1530
|
+
|
1531
|
+
def test_fail_because_not_float_like_object
|
1532
|
+
object = Object.new
|
1533
|
+
inspected_object = AssertionMessage.convert(object)
|
1534
|
+
check_fails("The arguments must respond to to_f; " +
|
1535
|
+
"the first float did not.\n" +
|
1536
|
+
"<#{inspected_object}>.respond_to?(:to_f) expected\n" +
|
1537
|
+
"(Class: <Object>)") do
|
1538
|
+
assert_in_epsilon(object, 9000, 0.1)
|
1539
|
+
end
|
1540
|
+
end
|
1541
|
+
|
1542
|
+
def test_fail_because_negaitve_epsilon
|
1543
|
+
check_fails("The epsilon should not be negative.\n" +
|
1544
|
+
"<-0.1> expected to be\n>=\n<0.0>.") do
|
1545
|
+
assert_in_epsilon(10000, 9000, -0.1, "message")
|
1546
|
+
end
|
1547
|
+
end
|
1548
|
+
|
1549
|
+
def test_fail_without_epsilon
|
1550
|
+
check_fails("<10000> -/+ (<10000> * <0.001>)[10.0] " +
|
1551
|
+
"expected to include\n" +
|
1552
|
+
"<10011>.\n" +
|
1553
|
+
"\n" +
|
1554
|
+
"Relation:\n" +
|
1555
|
+
"<" +
|
1556
|
+
"<10000>-(<10000>*<0.001>)[9990.0] <= " +
|
1557
|
+
"<10000>+(<10000>*<0.001>)[10010.0] < " +
|
1558
|
+
"<10011>" +
|
1559
|
+
">") do
|
1560
|
+
assert_in_epsilon(10000, 10011)
|
1561
|
+
end
|
1562
|
+
end
|
1563
|
+
end
|
1564
|
+
|
1565
|
+
class TestAssertNotInEpsilon < Test::Unit::TestCase
|
1566
|
+
include AssertionCheckable
|
1567
|
+
|
1568
|
+
def test_pass
|
1569
|
+
check_nothing_fails do
|
1570
|
+
assert_not_in_epsilon(10000, 8999, 0.1)
|
1571
|
+
end
|
1572
|
+
end
|
1573
|
+
|
1574
|
+
def test_pass_without_epsilon
|
1575
|
+
check_nothing_fails do
|
1576
|
+
assert_not_in_epsilon(10000, 9989)
|
1577
|
+
end
|
1578
|
+
end
|
1579
|
+
|
1580
|
+
def test_pass_with_message
|
1581
|
+
check_nothing_fails do
|
1582
|
+
assert_not_in_epsilon(10000, 8999, 0.1, "message")
|
1583
|
+
end
|
1584
|
+
end
|
1585
|
+
|
1586
|
+
def test_pass_float_like_object
|
1587
|
+
check_nothing_fails do
|
1588
|
+
float_thing = Object.new
|
1589
|
+
def float_thing.to_f
|
1590
|
+
8999.0
|
1591
|
+
end
|
1592
|
+
assert_not_in_epsilon(10000, float_thing, 0.1)
|
1593
|
+
end
|
1594
|
+
end
|
1595
|
+
|
1596
|
+
def test_pass_string_epxected
|
1597
|
+
check_nothing_fails do
|
1598
|
+
assert_not_in_epsilon("10000", 8999, 0.1)
|
1599
|
+
end
|
1600
|
+
end
|
1601
|
+
|
1602
|
+
def test_fail
|
1603
|
+
check_fails("<10000> -/+ (<10000> * <0.1>)[1000.0] " +
|
1604
|
+
"expected to not include\n" +
|
1605
|
+
"<9000>.\n" +
|
1606
|
+
"\n" +
|
1607
|
+
"Relation:\n" +
|
1608
|
+
"<" +
|
1609
|
+
"<10000>-(<10000>*<0.1>)[9000.0] <= " +
|
1610
|
+
"<9000> <= " +
|
1611
|
+
"<10000>+(<10000>*<0.1>)[11000.0]" +
|
1612
|
+
">") do
|
1613
|
+
assert_not_in_epsilon(10000, 9000, 0.1)
|
1614
|
+
end
|
1615
|
+
end
|
1616
|
+
|
1617
|
+
def test_fail_without_epsilon
|
1618
|
+
check_fails("<10000> -/+ (<10000> * <0.001>)[10.0] " +
|
1619
|
+
"expected to not include\n" +
|
1620
|
+
"<9990>.\n" +
|
1621
|
+
"\n" +
|
1622
|
+
"Relation:\n" +
|
1623
|
+
"<" +
|
1624
|
+
"<10000>-(<10000>*<0.001>)[9990.0] <= " +
|
1625
|
+
"<9990> <= " +
|
1626
|
+
"<10000>+(<10000>*<0.001>)[10010.0]" +
|
1627
|
+
">") do
|
1628
|
+
assert_not_in_epsilon(10000, 9990)
|
1629
|
+
end
|
1630
|
+
end
|
1631
|
+
|
1632
|
+
def test_fail_with_message
|
1633
|
+
check_fails("message.\n" +
|
1634
|
+
"<10000> -/+ (<10000> * <0.1>)[1000.0] " +
|
1635
|
+
"expected to not include\n" +
|
1636
|
+
"<9000>.\n" +
|
1637
|
+
"\n" +
|
1638
|
+
"Relation:\n" +
|
1639
|
+
"<" +
|
1640
|
+
"<10000>-(<10000>*<0.1>)[9000.0] <= " +
|
1641
|
+
"<9000> <= " +
|
1642
|
+
"<10000>+(<10000>*<0.1>)[11000.0]" +
|
1643
|
+
">") do
|
1644
|
+
assert_not_in_epsilon(10000, 9000, 0.1, "message")
|
1645
|
+
end
|
1646
|
+
end
|
1647
|
+
|
1648
|
+
def test_fail_because_not_float_like_object
|
1649
|
+
object = Object.new
|
1650
|
+
inspected_object = AssertionMessage.convert(object)
|
1651
|
+
check_fails("The arguments must respond to to_f; " +
|
1652
|
+
"the first float did not.\n" +
|
1653
|
+
"<#{inspected_object}>.respond_to?(:to_f) expected\n" +
|
1654
|
+
"(Class: <Object>)") do
|
1655
|
+
assert_not_in_epsilon(object, 9000, 0.1)
|
1656
|
+
end
|
1657
|
+
end
|
1658
|
+
|
1659
|
+
def test_fail_because_negaitve_epsilon
|
1660
|
+
check_fails("The epsilon should not be negative.\n" +
|
1661
|
+
"<-0.1> expected to be\n>=\n<0.0>.") do
|
1662
|
+
assert_not_in_epsilon(10000, 9000, -0.1, "message")
|
1663
|
+
end
|
1664
|
+
end
|
1665
|
+
end
|
1666
|
+
|
1667
|
+
class TestAssertInclude < Test::Unit::TestCase
|
1668
|
+
include AssertionCheckable
|
1669
|
+
|
1670
|
+
def test_pass
|
1671
|
+
check_nothing_fails do
|
1672
|
+
assert_include([1, 2, 3], 1)
|
1673
|
+
end
|
1674
|
+
end
|
1675
|
+
|
1676
|
+
def test_pass_with_message
|
1677
|
+
check_nothing_fails do
|
1678
|
+
assert_include([1, 2, 3], 1, "message")
|
1679
|
+
end
|
1680
|
+
end
|
1681
|
+
|
1682
|
+
def test_fail
|
1683
|
+
check_fails("<[1, 2, 3]> expected to include\n" +
|
1684
|
+
"<4>.") do
|
1685
|
+
assert_include([1, 2, 3], 4)
|
1686
|
+
end
|
1687
|
+
end
|
1688
|
+
|
1689
|
+
def test_fail_with_message
|
1690
|
+
check_fails("message.\n" +
|
1691
|
+
"<[1, 2, 3]> expected to include\n" +
|
1692
|
+
"<4>.") do
|
1693
|
+
assert_include([1, 2, 3], 4, "message")
|
1694
|
+
end
|
1695
|
+
end
|
1696
|
+
|
1697
|
+
def test_fail_because_not_collection_like_object
|
1698
|
+
object = Object.new
|
1699
|
+
inspected_object = AssertionMessage.convert(object)
|
1700
|
+
check_fails("The collection must respond to :include?.\n" +
|
1701
|
+
"<#{inspected_object}>.respond_to?(:include?) expected\n" +
|
1702
|
+
"(Class: <Object>)") do
|
1703
|
+
assert_include(object, 1)
|
1704
|
+
end
|
1705
|
+
end
|
1706
|
+
end
|
1707
|
+
|
1708
|
+
class TestAssertNotInclude < Test::Unit::TestCase
|
1709
|
+
include AssertionCheckable
|
1710
|
+
|
1711
|
+
def test_pass
|
1712
|
+
check_nothing_fails do
|
1713
|
+
assert_not_include([1, 2, 3], 5)
|
1714
|
+
end
|
1715
|
+
end
|
1716
|
+
|
1717
|
+
def test_pass_with_message
|
1718
|
+
check_nothing_fails do
|
1719
|
+
assert_not_include([1, 2, 3], 5, "message")
|
1720
|
+
end
|
1721
|
+
end
|
1722
|
+
|
1723
|
+
def test_fail
|
1724
|
+
check_fails("<[1, 2, 3]> expected to not include\n" +
|
1725
|
+
"<2>.") do
|
1726
|
+
assert_not_include([1, 2, 3], 2)
|
1727
|
+
end
|
1728
|
+
end
|
1729
|
+
|
1730
|
+
def test_fail_with_message
|
1731
|
+
check_fails("message.\n" +
|
1732
|
+
"<[1, 2, 3]> expected to not include\n" +
|
1733
|
+
"<2>.") do
|
1734
|
+
assert_not_include([1, 2, 3], 2, "message")
|
1735
|
+
end
|
1736
|
+
end
|
1737
|
+
|
1738
|
+
def test_fail_because_not_collection_like_object
|
1739
|
+
object = Object.new
|
1740
|
+
inspected_object = AssertionMessage.convert(object)
|
1741
|
+
check_fails("The collection must respond to :include?.\n" +
|
1742
|
+
"<#{inspected_object}>.respond_to?(:include?) expected\n" +
|
1743
|
+
"(Class: <Object>)") do
|
1744
|
+
assert_not_include(object, 1)
|
1745
|
+
end
|
1746
|
+
end
|
1747
|
+
end
|
1748
|
+
|
1749
|
+
class TestAssertEmpty < Test::Unit::TestCase
|
1750
|
+
include AssertionCheckable
|
1751
|
+
|
1752
|
+
def test_pass
|
1753
|
+
check_nothing_fails do
|
1754
|
+
assert_empty([])
|
1755
|
+
end
|
1756
|
+
end
|
1757
|
+
|
1758
|
+
def test_pass_with_message
|
1759
|
+
check_nothing_fails do
|
1760
|
+
assert_empty([], "message")
|
1761
|
+
end
|
1762
|
+
end
|
1763
|
+
|
1764
|
+
def test_fail
|
1765
|
+
check_fails("<[1]> expected to be empty.") do
|
1766
|
+
assert_empty([1])
|
1767
|
+
end
|
1768
|
+
end
|
1769
|
+
|
1770
|
+
def test_fail_with_message
|
1771
|
+
check_fails("message.\n" +
|
1772
|
+
"<[1]> expected to be empty.") do
|
1773
|
+
assert_empty([1], "message")
|
1774
|
+
end
|
1775
|
+
end
|
1776
|
+
|
1777
|
+
def test_fail_because_no_empty_method
|
1778
|
+
object = Object.new
|
1779
|
+
inspected_object = AssertionMessage.convert(object)
|
1780
|
+
check_fails("The object must respond to :empty?.\n" +
|
1781
|
+
"<#{inspected_object}>.respond_to?(:empty?) expected\n" +
|
1782
|
+
"(Class: <Object>)") do
|
1783
|
+
assert_empty(object)
|
1784
|
+
end
|
1785
|
+
end
|
1786
|
+
end
|
1787
|
+
|
1788
|
+
class TestAssertNotEmpty < Test::Unit::TestCase
|
1789
|
+
include AssertionCheckable
|
1790
|
+
|
1791
|
+
def test_pass
|
1792
|
+
check_nothing_fails do
|
1793
|
+
assert_not_empty([1])
|
1794
|
+
end
|
1795
|
+
end
|
1796
|
+
|
1797
|
+
def test_pass_with_message
|
1798
|
+
check_nothing_fails do
|
1799
|
+
assert_not_empty([1], "message")
|
1800
|
+
end
|
1801
|
+
end
|
1802
|
+
|
1803
|
+
def test_fail
|
1804
|
+
check_fails("<[]> expected to not be empty.") do
|
1805
|
+
assert_not_empty([])
|
1806
|
+
end
|
1807
|
+
end
|
1808
|
+
|
1809
|
+
def test_fail_with_message
|
1810
|
+
check_fails("message.\n" +
|
1811
|
+
"<[]> expected to not be empty.") do
|
1812
|
+
assert_not_empty([], "message")
|
1813
|
+
end
|
1814
|
+
end
|
1815
|
+
|
1816
|
+
def test_fail_because_no_empty_method
|
1817
|
+
object = Object.new
|
1818
|
+
inspected_object = AssertionMessage.convert(object)
|
1819
|
+
check_fails("The object must respond to :empty?.\n" +
|
1820
|
+
"<#{inspected_object}>.respond_to?(:empty?) expected\n" +
|
1821
|
+
"(Class: <Object>)") do
|
1822
|
+
assert_not_empty(object)
|
1823
|
+
end
|
1824
|
+
end
|
1825
|
+
end
|
1826
|
+
|
1827
|
+
class TestAssertNotSend < Test::Unit::TestCase
|
1828
|
+
include AssertionCheckable
|
1829
|
+
|
1830
|
+
def test_pass
|
1831
|
+
check_nothing_fails do
|
1832
|
+
assert_not_send([[1, 2], :member?, 4], "message")
|
1833
|
+
end
|
1834
|
+
end
|
1835
|
+
|
1836
|
+
def test_fail
|
1837
|
+
expected_message = <<-EOM
|
1838
|
+
message.
|
1839
|
+
<[1, 2]> expected to respond to
|
1840
|
+
<member?(*[2])> with not a true value but was
|
1841
|
+
<true>.
|
1842
|
+
EOM
|
1843
|
+
check_fails(expected_message.chomp) do
|
1844
|
+
assert_not_send([[1, 2], :member?, 2], "message")
|
1193
1845
|
end
|
1194
1846
|
end
|
1195
1847
|
end
|