This repository has been archived by the owner on Jan 9, 2019. It is now read-only.
forked from ci-reporter/ci_reporter
-
Notifications
You must be signed in to change notification settings - Fork 1
/
cucumber.rb
99 lines (77 loc) · 2.01 KB
/
cucumber.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
# (c) Copyright 2006-2009 Nick Sieger <nicksieger@gmail.com>
# See the file LICENSE.txt included with the distribution for
# software license details.
require 'ci/reporter/core'
tried_gem = false
begin
require 'cucumber'
require 'cucumber/ast/visitor'
rescue LoadError
unless tried_gem
tried_gem = true
require 'rubygems'
gem 'cucumber'
retry
end
end
module CI
module Reporter
class CucumberFailure
attr_reader :step
def initialize(step)
@step = step
end
def failure?
true
end
def error?
!failure?
end
def name
step.exception.class.name
end
def message
step.exception.message
end
def location
step.exception.backtrace.join("\n")
end
end
class Cucumber < ::Cucumber::Ast::Visitor
attr_accessor :test_suite, :report_manager, :feature_name
def initialize(step_mother, io, options)
self.report_manager = ReportManager.new("cucumber")
super(step_mother)
end
def visit_feature_name(name)
self.feature_name = name.split("\n").first
super
end
def visit_feature_element(feature_element)
self.test_suite = TestSuite.new("#{feature_name} #{feature_element.instance_variable_get("@name")}")
test_suite.start
return_value = super
test_suite.finish
report_manager.write_report(test_suite)
self.test_suite = nil
return_value
end
def visit_step(step)
test_case = TestCase.new(step.name)
test_case.start
return_value = super
test_case.finish
case step.status
when :pending, :undefined
test_case.name = "#{test_case.name} (PENDING)"
when :skipped
test_case.name = "#{test_case.name} (SKIPPED)"
when :failed
test_case.failures << CucumberFailure.new(step)
end
test_suite.testcases << test_case
return_value
end
end
end
end