timfel-ci_reporter 1.6.2 → 1.6.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -51,50 +51,39 @@ module CI
51
51
  @report_manager = ReportManager.new("features")
52
52
  end
53
53
 
54
- def before_feature_name(name)
55
- @current_feature_name = name.split("\n").first
56
- end
57
-
58
- def before_feature_element(feature_element)
59
- @test_suite = TestSuite.new("#{@current_feature_name} #{feature_element.instance_variable_get("@name")}")
54
+ def before_feature_name(name)
55
+ @test_suite = TestSuite.new(name.split("\n").first)
60
56
  @test_suite.start
61
57
  end
62
-
63
- def after_feature_element(feature_element)
58
+
59
+ def after_feature_name(name)
64
60
  @test_suite.finish
65
61
  @report_manager.write_report(@test_suite)
66
62
  @test_suite = nil
67
63
  end
68
64
 
69
- def before_step(step)
70
- @test_case = TestCase.new(step.name)
65
+ def before_feature_element(feature_element)
66
+ @test_case = TestCase.new(feature_element.instance_variable_get("@name"))
67
+ @status = ""
71
68
  @test_case.start
72
69
  end
73
70
 
74
- def after_step(step)
75
- if @test_case.nil?
76
- $stderr << "Warning, no test case was started for #{step}. Time won't be logged."
77
- @test_case = TestCase.new(step.name)
78
- @test_case.start
79
- end
71
+ def after_feature_element(feature_element)
80
72
  @test_case.finish
73
+ @test_case.name = "#{@test_case.name} #{@status}".strip
74
+ @test_suite.testcases << @test_case
75
+ end
81
76
 
77
+ def after_step(step)
82
78
  case step.status
83
79
  when :pending, :undefined
84
- @test_case.name = "#{@test_case.name} (PENDING)"
80
+ @status = "(PENDING)" if @status.empty?
85
81
  when :skipped
86
- @test_case.name = "#{@test_case.name} (SKIPPED)"
82
+ @status = "(SKIPPED)" unless @status == "(FAILED)"
87
83
  when :failed
84
+ @status = "(FAILED)"
88
85
  @test_case.failures << CucumberFailure.new(step)
89
86
  end
90
-
91
- if @test_suite.nil?
92
- $stderr << "Warning, no test suite was started for the scenario around #{step}. Time logging will be wrong."
93
- @test_suite = TestSuite.new("#{@current_feature_name} Unspecified Feature Element")
94
- @test_suite.start
95
- end
96
- @test_case.finish
97
- @test_suite.testcases << @test_case
98
87
  end
99
88
  end
100
89
  end
@@ -1,5 +1,5 @@
1
1
  module CI
2
2
  module Reporter
3
- VERSION = "1.6.2"
3
+ VERSION = "1.6.3"
4
4
  end
5
5
  end
@@ -70,29 +70,15 @@ describe "The Cucumber reporter" do
70
70
  CI::Reporter::ReportManager.should_receive(:new)
71
71
  new_instance
72
72
  end
73
-
74
- it "should record the feature name when a new feature is visited" do
75
- cucumber = new_instance
76
- cucumber.visit_feature_name("Some feature name")
77
- cucumber.feature_name.should == "Some feature name"
78
- end
79
-
80
- it "should record only the first line of a feature name" do
81
- cucumber = new_instance
82
- cucumber.visit_feature_name("Some feature name\nLonger description")
83
- cucumber.feature_name.should == "Some feature name"
84
- end
85
-
86
- describe "when visiting a new scenario" do
73
+
74
+ describe "when visiting a new feature" do
87
75
  before(:each) do
88
76
  @cucumber = new_instance
89
- @cucumber.visit_feature_name("Demo feature")
77
+ @feature_name = "Demo Feature"
90
78
 
91
79
  @test_suite = mock("test_suite", :start => nil, :finish => nil)
92
80
  CI::Reporter::TestSuite.stub!(:new).and_return(@test_suite)
93
81
 
94
- @feature_element = mock("feature_element", :accept => true)
95
-
96
82
  @report_manager.stub!(:write_report)
97
83
  end
98
84
 
@@ -100,88 +86,182 @@ describe "The Cucumber reporter" do
100
86
  # FIXME: @name is feature_element purely as a by-product of the
101
87
  # mocking framework implementation. But then again, using
102
88
  # +instance_variable_get+ in the first place is a bit icky.
103
- CI::Reporter::TestSuite.should_receive(:new).with("Demo feature feature_element")
104
- @cucumber.visit_feature_element(@feature_element)
89
+ CI::Reporter::TestSuite.should_receive(:new).with(@feature_name)
90
+ @cucumber.before_feature_name(@feature_name)
105
91
  end
106
92
 
107
93
  it "should indicate that the test suite has started" do
108
94
  @test_suite.should_receive(:start)
109
- @cucumber.visit_feature_element(@feature_element)
95
+ @cucumber.before_feature_name(@feature_name)
110
96
  end
111
97
 
112
98
  it "should indicate that the test suite has finished" do
113
99
  @test_suite.should_receive(:finish)
114
- @cucumber.visit_feature_element(@feature_element)
100
+ @cucumber.before_feature_name(@feature_name)
101
+ @cucumber.after_feature_name(@feature_name)
115
102
  end
116
103
 
117
104
  it "should ask the report manager to write a report" do
118
105
  @report_manager.should_receive(:write_report).with(@test_suite)
119
- @cucumber.visit_feature_element(@feature_element)
106
+ @cucumber.before_feature_name(@feature_name)
107
+ @cucumber.after_feature_name(@feature_name)
120
108
  end
121
109
  end
122
110
 
123
- describe "when visiting a step inside a scenario" do
111
+ describe "when visiting a scenario" do
124
112
  before(:each) do
125
113
  @testcases = []
126
114
 
127
- @test_suite = mock("test_suite", :testcases => @testcases)
115
+ @test_suite = mock("test_suite", :testcases => @testcases, :start => nil, :finish => nil)
128
116
 
129
117
  @cucumber = new_instance
130
- @cucumber.stub!(:test_suite).and_return(@test_suite)
118
+ @cucumber.instance_variable_set("@test_suite", @test_suite)
119
+
120
+ @feature_element_name = "Feature Element Name"
121
+ @feature_element = mock(@feature_element_name, :accept => true)
131
122
 
132
- @test_case = mock("test_case", :start => nil, :finish => nil, :name => "Step Name")
123
+ @test_case = mock("test_case", :start => nil, :finish => nil, :name => @feature_element_name, :name= => nil)
133
124
  CI::Reporter::TestCase.stub!(:new).and_return(@test_case)
134
125
 
135
- @step = mock("step", :accept => true, :status => :passed)
136
- @step.stub!(:name).and_return("Step Name")
126
+ @step = mock("step", :accept => true, :status => :passed)
137
127
  end
138
128
 
139
129
  it "should create a new test case" do
140
- CI::Reporter::TestCase.should_receive(:new).with("Step Name")
141
- @cucumber.visit_step(@step)
130
+ CI::Reporter::TestCase.should_receive(:new).with(@feature_element_name)
131
+ @cucumber.before_feature_element(@feature_element)
142
132
  end
143
133
 
144
134
  it "should indicate that the test case has started" do
145
135
  @test_case.should_receive(:start)
146
- @cucumber.visit_step(@step)
136
+ @cucumber.before_feature_element(@feature_element)
147
137
  end
148
138
 
149
139
  it "should indicate that the test case has finished" do
150
140
  @test_case.should_receive(:finish)
151
- @cucumber.visit_step(@step)
141
+ @cucumber.before_feature_element(@feature_element)
142
+ @cucumber.after_feature_element(@feature_element)
152
143
  end
153
144
 
154
145
  it "should add the test case to the suite's list of cases" do
146
+ CI::Reporter::TestSuite.stub!(:new).and_return(@test_suite)
155
147
  @testcases.should be_empty
156
- @cucumber.visit_step(@step)
148
+ @cucumber.before_feature_element(@feature_element)
149
+ @cucumber.after_feature_element(@feature_element)
157
150
  @testcases.should_not be_empty
158
151
  @testcases.first.should == @test_case
159
152
  end
160
153
 
161
154
  it "should alter the name of a test case that is pending to include '(PENDING)'" do
162
155
  @step.stub!(:status).and_return(:pending)
163
- @test_case.should_receive(:name=).with("Step Name (PENDING)")
164
- @cucumber.visit_step(@step)
156
+ @test_case.should_receive(:name=).with("#{@feature_element_name} (PENDING)")
157
+ @cucumber.before_feature_element(@feature_element)
158
+ @cucumber.after_step(@step)
159
+ @cucumber.after_feature_element(@feature_element)
165
160
  end
166
161
 
167
162
  it "should alter the name of a test case that is undefined to include '(PENDING)'" do
168
163
  @step.stub!(:status).and_return(:undefined)
169
- @test_case.should_receive(:name=).with("Step Name (PENDING)")
170
- @cucumber.visit_step(@step)
164
+ @test_case.should_receive(:name=).with("#{@feature_element_name} (PENDING)")
165
+ @cucumber.before_feature_element(@feature_element)
166
+ @cucumber.after_step(@step)
167
+ @cucumber.after_feature_element(@feature_element)
171
168
  end
172
169
 
173
170
  it "should alter the name of a test case that was skipped to include '(SKIPPED)'" do
174
171
  @step.stub!(:status).and_return(:skipped)
175
- @test_case.should_receive(:name=).with("Step Name (SKIPPED)")
176
- @cucumber.visit_step(@step)
172
+ @test_case.should_receive(:name=).with("#{@feature_element_name} (SKIPPED)")
173
+ @cucumber.before_feature_element(@feature_element)
174
+ @cucumber.after_step(@step)
175
+ @cucumber.after_feature_element(@feature_element)
177
176
  end
177
+ end
178
178
 
179
+ describe "when visiting a step" do
180
+ before(:each) do
181
+ @testcases = []
182
+ @test_suite = mock("test_suite", :testcases => @testcases, :start => nil, :finish => nil)
183
+ @test_case = mock("test_case", :failures => [], :start => nil, :finish => nil, :name => "Step Name", :name= => nil)
184
+
185
+ @cucumber = new_instance
186
+ @cucumber.instance_variable_set("@test_suite", @test_suite)
187
+ @cucumber.instance_variable_set("@test_case", @test_case)
188
+ @cucumber.instance_variable_set("@status", "")
189
+
190
+ @step = mock("step", :accept => true, :status => :passed)
191
+ @step.stub!(:name).and_return("Step Name")
192
+ end
193
+
194
+ it "should alter the status of a test case that is pending to '(PENDING)'" do
195
+ @step.stub!(:status).and_return(:pending)
196
+ @cucumber.after_step(@step)
197
+ @cucumber.instance_variable_get("@status").should == "(PENDING)"
198
+ end
199
+
200
+ it "should alter the status of a test case that is skipped to '(SKIPPED)'" do
201
+ @step.stub!(:status).and_return(:skipped)
202
+ @cucumber.after_step(@step)
203
+ @cucumber.instance_variable_get("@status").should == "(SKIPPED)"
204
+ end
205
+
206
+ it "should alter the status of a test case that has failed to '(FAILED)'" do
207
+ @step.stub!(:status).and_return(:failed)
208
+ @cucumber.after_step(@step)
209
+ @cucumber.instance_variable_get("@status").should == "(FAILED)"
210
+ end
211
+
212
+ it "should not alter the status of a test case that is skipped if it has failed, before" do
213
+ @step.stub!(:status).and_return(:failed)
214
+ @cucumber.after_step(@step)
215
+ prev_status = @cucumber.instance_variable_get("@status")
216
+ @step.stub!(:status).and_return(:skipped)
217
+ @cucumber.after_step(@step)
218
+ @cucumber.instance_variable_get("@status").should == prev_status
219
+ end
220
+
221
+ it "should not alter the status of a test case that is pending if it has skipped, before" do
222
+ @step.stub!(:status).and_return(:skipped)
223
+ @cucumber.after_step(@step)
224
+ prev_status = @cucumber.instance_variable_get("@status")
225
+ @step.stub!(:status).and_return(:pending)
226
+ @cucumber.after_step(@step)
227
+ @cucumber.instance_variable_get("@status").should == prev_status
228
+ end
229
+
230
+ it "should not alter the status of a test case that is pending if it has failed, before" do
231
+ @step.stub!(:status).and_return(:failed)
232
+ @cucumber.after_step(@step)
233
+ prev_status = @cucumber.instance_variable_get("@status")
234
+ @step.stub!(:status).and_return(:pending)
235
+ @cucumber.after_step(@step)
236
+ @cucumber.instance_variable_get("@status").should == prev_status
237
+ end
238
+
239
+ it "should alter the status of a test case that is pending and has skipped, afterwards" do
240
+ @step.stub!(:status).and_return(:pending)
241
+ @cucumber.after_step(@step)
242
+ prev_status = @cucumber.instance_variable_get("@status")
243
+ @step.stub!(:status).and_return(:skipped)
244
+ @cucumber.after_step(@step)
245
+ @cucumber.instance_variable_get("@status").should_not == prev_status
246
+ end
247
+
248
+ it "should alter the status of a test case that is skipped and has failed, afterwards" do
249
+ @step.stub!(:status).and_return(:skipped)
250
+ @cucumber.after_step(@step)
251
+ prev_status = @cucumber.instance_variable_get("@status")
252
+ @step.stub!(:status).and_return(:failed)
253
+ @cucumber.after_step(@step)
254
+ @cucumber.instance_variable_get("@status").should_not == prev_status
255
+ end
256
+
179
257
  describe "that fails" do
180
258
  before(:each) do
181
259
  @step.stub!(:status).and_return(:failed)
182
260
 
183
261
  @failures = []
184
262
  @test_case.stub!(:failures).and_return(@failures)
263
+
264
+ @cucumber_failure.instance_variable_set("@test_case", @test_case)
185
265
 
186
266
  @cucumber_failure = mock("cucumber_failure")
187
267
  CI::Reporter::CucumberFailure.stub!(:new).and_return(@cucumber_failure)
@@ -189,12 +269,12 @@ describe "The Cucumber reporter" do
189
269
 
190
270
  it "should create a new cucumber failure with that step" do
191
271
  CI::Reporter::CucumberFailure.should_receive(:new).with(@step)
192
- @cucumber.visit_step(@step)
272
+ @cucumber.after_step(@step)
193
273
  end
194
274
 
195
275
  it "should add the failure to the suite's list of failures" do
196
276
  @failures.should be_empty
197
- @cucumber.visit_step(@step)
277
+ @cucumber.after_step(@step)
198
278
  @failures.should_not be_empty
199
279
  @failures.first.should == @cucumber_failure
200
280
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timfel-ci_reporter
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 9
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 6
9
- - 2
10
- version: 1.6.2
9
+ - 3
10
+ version: 1.6.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Nick Sieger
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-22 00:00:00 +02:00
18
+ date: 2010-07-07 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency