/
junit_spec.rb
174 lines (143 loc) · 4.96 KB
/
junit_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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
require 'spec_helper'
require 'cucumber/formatter/spec_helper'
require 'cucumber/formatter/junit'
require 'nokogiri'
module Cucumber::Formatter
describe Junit do
extend SpecHelperDsl
include SpecHelper
class TestDoubleJunitFormatter < Junit
attr_reader :written_files
def write_file(feature_filename, data)
@written_files ||= {}
@written_files[feature_filename] = data
end
end
before(:each) do
File.stub!(:directory?).and_return(true)
@formatter = TestDoubleJunitFormatter.new(step_mother, '', {})
end
describe "should be able to strip control chars from cdata" do
before(:each) do
run_defined_feature
@doc = Nokogiri.XML(@formatter.written_files.values.first)
end
define_feature "
Feature: One passing scenario, one failing scenario
Scenario: Passing
Given a passing ctrl scenario
"
class Junit
def before_step(step)
if step.name.match("a passing ctrl scenario")
Interceptor::Pipe.unwrap! :stdout
@fake_io = $stdout = StringIO.new
$stdout.sync = true
@interceptedout = Interceptor::Pipe.wrap(:stdout)
end
end
def after_step(step)
if step.name.match("a passing ctrl scenario")
@interceptedout.write("boo\b\cx\e\a\f boo ")
$stdout = STDOUT
@fake_io.close
end
end
end
it { @doc.xpath('//testsuite/system-out').first.content.should match(/\s+boo boo\s+/) }
end
describe "a feature with no name" do
define_feature <<-FEATURE
Feature:
Scenario: Passing
Given a passing scenario
FEATURE
it "should raise an exception" do
lambda { run_defined_feature }.should raise_error(Junit::UnNamedFeatureError)
end
end
describe "given a single feature" do
before(:each) do
run_defined_feature
@doc = Nokogiri.XML(@formatter.written_files.values.first)
end
describe "with a single scenario" do
define_feature <<-FEATURE
Feature: One passing scenario, one failing scenario
Scenario: Passing
Given a passing scenario
FEATURE
it { @doc.to_s.should =~ /One passing scenario, one failing scenario/ }
it 'should have a root system-out node' do
@doc.xpath('//testsuite/system-out').size.should == 1
end
it 'should have a root system-err node' do
@doc.xpath('//testsuite/system-err').size.should == 1
end
it 'should have a system-out node under <testcase/>' do
@doc.xpath('//testcase/system-out').size.should == 1
end
it 'should have a system-err node under <testcase/>' do
@doc.xpath('//testcase/system-err').size.should == 1
end
end
describe "with a scenario in a subdirectory" do
define_feature %{
Feature: One passing scenario, one failing scenario
Scenario: Passing
Given a passing scenario
}, File.join('features', 'some', 'path', 'spec.feature')
it 'writes the filename including the subdirectory' do
@formatter.written_files.keys.first.should == File.join('', 'TEST-features-some-path-spec.xml')
end
end
describe "with a scenario outline table" do
define_steps do
Given(/.*/) { }
end
define_feature <<-FEATURE
Feature: Eat things when hungry
Scenario Outline: Eat things
Given <Things>
And stuff:
| foo |
| bar |
Examples: Good
| Things |
| Cucumber |
| Whisky |
Examples: Evil
| Things |
| Big Mac |
FEATURE
it { @doc.to_s.should =~ /Eat things when hungry/ }
it { @doc.to_s.should =~ /Cucumber/ }
it { @doc.to_s.should =~ /Whisky/ }
it { @doc.to_s.should =~ /Big Mac/ }
it { @doc.to_s.should_not =~ /Things/ }
it { @doc.to_s.should_not =~ /Good|Evil/ }
it { @doc.to_s.should_not =~ /type="skipped"/}
end
describe "with a regular data table scenario" do
define_steps do
Given(/the following items on a shortlist/) { |table| }
When(/I go.*/) { }
Then(/I should have visited at least/) { |table| }
end
define_feature <<-FEATURE
Feature: Shortlist
Scenario: Procure items
Given the following items on a shortlist:
| item |
| milk |
| cookies |
When I get some..
Then I'll eat 'em
FEATURE
# these type of tables shouldn't crash (or generate test cases)
it { @doc.to_s.should_not =~ /milk/ }
it { @doc.to_s.should_not =~ /cookies/ }
end
end
end
end