-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.rb
91 lines (76 loc) · 1.68 KB
/
test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
require_relative './autorun'
class NothingRaised < StandardError
end
class AssertionTests < TestSuite
def test_true
assert(true)
end
def test_truthy
assert("")
assert([])
assert("foo")
assert(Object.new)
end
def test_false
assert_error { assert(false) }
end
def test_falsy
assert_error { assert(nil) }
end
def test_equal
assert_equal("foo", 'foo')
assert_equal(1, 1)
end
def test_not_equal
assert_error { assert_equal(1, 2) }
assert_error { assert_equal("foo", "bar") }
end
def assert_error(&block)
raised = false
begin
yield
rescue AssertionError
raised = true
end
raise NothingRaised unless raised
end
end
class ReportingTests < TestSuite
def test_statistics
suite = define_suite do
def test_equality
assert_equal(1, 2)
end
def test_the_truth
assert(true)
end
end
output = StringIO.new
report = suite.new.run(output)
assert_equal(2, report.runs)
assert_equal(1, report.failures)
assert(output.string.include?("2 runs, 1 failures"),
"Report does not include statistics")
end
def test_summary
suite = define_suite do
def test_1
assert(false, "failure1")
end
def test_2
assert(false, "failure2")
end
end
output = StringIO.new
suite.new.run(output)
assert(output.string.include?("failure1"),
"Report does not include error details")
assert(output.string.include?("failure2"),
"Report does not include error details")
end
end
def define_suite(&block)
suite = Class.new(TestSuite, &block)
TestSuite.unregister(suite)
suite
end