/
verification_spec.rb
144 lines (127 loc) · 5.71 KB
/
verification_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
#--
# Copyright (c) 2006-2012 Nick Sieger <nicksieger@gmail.com>
# See the file LICENSE.txt included with the distribution for
# software license details.
#++
require 'rexml/document'
REPORTS_DIR = File.dirname(__FILE__) + '/reports'
describe "Test::Unit acceptance" do
it "should generate two XML files" do
File.exist?(File.join(REPORTS_DIR, 'TEST-TestUnitExampleTestOne.xml')).should == true
File.exist?(File.join(REPORTS_DIR, 'TEST-TestUnitExampleTestTwo.xml')).should == true
end
it "should have one error and one failure for TestUnitExampleTestOne" do
doc = File.open(File.join(REPORTS_DIR, 'TEST-TestUnitExampleTestOne.xml')) do |f|
REXML::Document.new(f)
end
doc.root.attributes["errors"].should == "1"
doc.root.attributes["failures"].should == "1"
doc.root.attributes["assertions"].should == "1"
doc.root.attributes["tests"].should == "1"
doc.root.elements.to_a("/testsuite/testcase").size.should == 1
doc.root.elements.to_a("/testsuite/testcase/error").size.should == 1
doc.root.elements.to_a("/testsuite/testcase/failure").size.should == 1
doc.root.elements.to_a("/testsuite/system-out").first.texts.inject("") do |c,e|
c << e.value; c
end.strip.should == "Some <![CDATA[on stdout]]>"
end
it "should have no errors or failures for TestUnitExampleTestTwo" do
doc = File.open(File.join(REPORTS_DIR, 'TEST-TestUnitExampleTestTwo.xml')) do |f|
REXML::Document.new(f)
end
doc.root.attributes["errors"].should == "0"
doc.root.attributes["failures"].should == "0"
doc.root.attributes["assertions"].should == "1"
doc.root.attributes["tests"].should == "1"
doc.root.elements.to_a("/testsuite/testcase").size.should == 1
doc.root.elements.to_a("/testsuite/testcase/failure").size.should == 0
end
end
describe "MiniTest::Unit acceptance" do
it "should generate two XML files" do
File.exist?(File.join(REPORTS_DIR, 'TEST-MiniTestExampleTestOne.xml')).should == true
File.exist?(File.join(REPORTS_DIR, 'TEST-MiniTestExampleTestTwo.xml')).should == true
end
it "should have one error and one failure for MiniTestExampleTestOne" do
doc = File.open(File.join(REPORTS_DIR, 'TEST-MiniTestExampleTestOne.xml')) do |f|
REXML::Document.new(f)
end
doc.root.attributes["errors"].should == "1"
doc.root.attributes["failures"].should == "1"
doc.root.attributes["assertions"].should == "1"
doc.root.attributes["tests"].should == "1"
doc.root.elements.to_a("/testsuite/testcase").size.should == 1
doc.root.elements.to_a("/testsuite/testcase/error").size.should == 1
doc.root.elements.to_a("/testsuite/testcase/failure").size.should == 1
doc.root.elements.to_a("/testsuite/system-out").first.texts.inject("") do |c,e|
c << e.value; c
end.strip.should == "Some <![CDATA[on stdout]]>"
end
it "should have no errors or failures for MiniTestExampleTestTwo" do
doc = File.open(File.join(REPORTS_DIR, 'TEST-MiniTestExampleTestTwo.xml')) do |f|
REXML::Document.new(f)
end
doc.root.attributes["errors"].should == "0"
doc.root.attributes["failures"].should == "0"
doc.root.attributes["assertions"].should == "1"
doc.root.attributes["tests"].should == "1"
doc.root.elements.to_a("/testsuite/testcase").size.should == 1
doc.root.elements.to_a("/testsuite/testcase/failure").size.should == 0
end
end
describe "RSpec acceptance" do
it "should generate two XML files" do
File.exist?(File.join(REPORTS_DIR, 'SPEC-RSpec-example.xml')).should == true
File.exist?(File.join(REPORTS_DIR, 'SPEC-RSpec-example-nested.xml')).should == true
end
it "should have two tests and one failure" do
doc = File.open(File.join(REPORTS_DIR, 'SPEC-RSpec-example.xml')) do |f|
REXML::Document.new(f)
end
doc.root.attributes["errors"].should == "0"
doc.root.attributes["failures"].should == "1"
doc.root.attributes["tests"].should == "3"
doc.root.elements.to_a("/testsuite/testcase").size.should == 3
failures = doc.root.elements.to_a("/testsuite/testcase/failure")
failures.size.should == 1
failures.first.attributes["type"].should =~ /ExpectationNotMetError/
end
it "should have one test in the nested example report" do
doc = File.open(File.join(REPORTS_DIR, 'SPEC-RSpec-example-nested.xml')) do |f|
REXML::Document.new(f)
end
doc.root.attributes["errors"].should == "0"
doc.root.attributes["failures"].should == "0"
doc.root.attributes["tests"].should == "1"
doc.root.elements.to_a("/testsuite/testcase").size.should == 1
end
end
describe "Cucumber acceptance" do
it "should generate three XML files" do
File.exist?(File.join(REPORTS_DIR, 'FEATURES-Example-feature.xml')).should == true
Dir["#{REPORTS_DIR}/FEATURES-*.xml"].length.should == 1
end
context "FEATURES report file" do
before :each do
@doc = File.open(File.join(REPORTS_DIR, 'FEATURES-Example-feature.xml')) do |f|
REXML::Document.new(f)
end
end
it "should have three tests and two failures" do
@doc.root.attributes["errors"].should == "0"
@doc.root.attributes["failures"].should == "2"
@doc.root.attributes["tests"].should == "3"
@doc.root.elements.to_a("/testsuite/testcase").size.should == 3
end
it "should have one failure for the lazy hacker" do
failures = @doc.root.elements.to_a("/testsuite/testcase[@name='Lazy hacker']/failure")
failures.size.should == 1
failures.first.attributes["type"].should =~ /ExpectationNotMetError/
end
it "should have one failure for the bad coder" do
failures = @doc.root.elements.to_a("/testsuite/testcase[@name='Bad coder']/failure")
failures.size.should == 1
failures.first.attributes["type"].should == "RuntimeError"
end
end
end