/
test_suite_spec.rb
144 lines (123 loc) · 4.62 KB
/
test_suite_spec.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# (c) Copyright 2006-2007 Nick Sieger <nicksieger@gmail.com>
# See the file LICENSE.txt included with the distribution for
# software license details.
require File.dirname(__FILE__) + "/../../spec_helper.rb"
require 'rexml/document'
describe "A TestSuite" do
before(:each) do
@suite = CI::Reporter::TestSuite.new("example suite")
end
it "should collect timings when start and finish are invoked in sequence" do
@suite.start
@suite.finish
@suite.time.should > 0
end
it "should aggregate tests" do
@suite.start
@suite.testcases << CI::Reporter::TestCase.new("example test")
@suite.finish
@suite.tests.should == 1
end
it "should indicate number of failures and errors" do
failure = mock("failure")
failure.stub!(:failure?).and_return true
failure.stub!(:error?).and_return false
error = mock("error")
error.stub!(:failure?).and_return false
error.stub!(:error?).and_return true
@suite.start
@suite.testcases << CI::Reporter::TestCase.new("example test")
@suite.testcases << CI::Reporter::TestCase.new("failure test")
@suite.testcases.last.failure = failure
@suite.testcases << CI::Reporter::TestCase.new("error test")
@suite.testcases.last.failure = error
@suite.finish
@suite.tests.should == 3
@suite.failures.should == 1
@suite.errors.should == 1
end
end
describe "TestSuite xml" do
before(:each) do
@suite = CI::Reporter::TestSuite.new("example suite")
@suite.assertions = 11
begin
raise StandardError, "an exception occurred"
rescue => e
@exception = e
end
end
it "should contain Ant/JUnit-formatted description of entire suite" do
failure = mock("failure")
failure.stub!(:failure?).and_return true
failure.stub!(:error?).and_return false
failure.stub!(:name).and_return "failure"
failure.stub!(:message).and_return "There was a failure"
failure.stub!(:location).and_return @exception.backtrace.join("\n")
error = mock("error")
error.stub!(:failure?).and_return false
error.stub!(:error?).and_return true
error.stub!(:name).and_return "error"
error.stub!(:message).and_return "There was a error"
error.stub!(:location).and_return @exception.backtrace.join("\n")
@suite.start
@suite.testcases << CI::Reporter::TestCase.new("example test")
@suite.testcases << CI::Reporter::TestCase.new("failure test")
@suite.testcases.last.failure = failure
@suite.testcases << CI::Reporter::TestCase.new("error test")
@suite.testcases.last.failure = error
@suite.finish
xml = @suite.to_xml
doc = REXML::Document.new(xml)
testsuite = doc.root.elements.to_a("/testsuite")
testsuite.length.should == 1
testsuite = testsuite.first
testsuite.attributes["name"].should == "example suite"
testsuite.attributes["assertions"].should == "11"
testcases = testsuite.elements.to_a("testcase")
testcases.length.should == 3
end
it "should contain full exception type and message in location element" do
failure = mock("failure")
failure.stub!(:failure?).and_return true
failure.stub!(:error?).and_return false
failure.stub!(:name).and_return "failure"
failure.stub!(:message).and_return "There was a failure"
failure.stub!(:location).and_return @exception.backtrace.join("\n")
@suite.start
@suite.testcases << CI::Reporter::TestCase.new("example test")
@suite.testcases << CI::Reporter::TestCase.new("failure test")
@suite.testcases.last.failure = failure
@suite.finish
xml = @suite.to_xml
doc = REXML::Document.new(xml)
elem = doc.root.elements.to_a("/testsuite/testcase[@name='failure test']/failure").first
location = elem.texts.join
location.should =~ Regexp.new(failure.message)
location.should =~ Regexp.new(failure.name)
end
it "should filter attributes properly for invalid characters" do
failure = mock("failure")
failure.stub!(:failure?).and_return true
failure.stub!(:error?).and_return false
failure.stub!(:name).and_return "failure"
failure.stub!(:message).and_return "There was a <failure>\nReason: blah"
failure.stub!(:location).and_return @exception.backtrace.join("\n")
@suite.start
@suite.testcases << CI::Reporter::TestCase.new("failure test")
@suite.testcases.last.failure = failure
@suite.finish
xml = @suite.to_xml
xml.should =~ %r/message="There was a <failure>\.\.\."/
end
end
describe "A TestCase" do
before(:each) do
@tc = CI::Reporter::TestCase.new("example test")
end
it "should collect timings when start and finish are invoked in sequence" do
@tc.start
@tc.finish
@tc.time.should > 0
end
end