Class: CI::Reporter::Cucumber

Inherits:
Object
  • Object
show all
Defined in:
lib/ci/reporter/cucumber.rb,
lib/ci/reporter/cucumber/version.rb

Constant Summary collapse

VERSION =
"1.0.2"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(step_mother, io, options) ⇒ Cucumber

Returns a new instance of Cucumber.



41
42
43
# File 'lib/ci/reporter/cucumber.rb', line 41

def initialize(step_mother, io, options)
  @report_manager = ReportManager.new("features")
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



39
40
41
# File 'lib/ci/reporter/cucumber.rb', line 39

def name
  @name
end

#report_managerObject

Returns the value of attribute report_manager.



39
40
41
# File 'lib/ci/reporter/cucumber.rb', line 39

def report_manager
  @report_manager
end

#test_suiteObject

Returns the value of attribute test_suite.



39
40
41
# File 'lib/ci/reporter/cucumber.rb', line 39

def test_suite
  @test_suite
end

Instance Method Details

#after_background(*args) ⇒ Object



61
62
# File 'lib/ci/reporter/cucumber.rb', line 61

def after_background(*args)
end

#after_examples(*args) ⇒ Object



107
108
# File 'lib/ci/reporter/cucumber.rb', line 107

def after_examples(*args)
end

#after_feature(feature) ⇒ Object



50
51
52
53
54
55
# File 'lib/ci/reporter/cucumber.rb', line 50

def after_feature(feature)
  test_suite.name = @name
  test_suite.finish
  report_manager.write_report(@test_suite)
  @test_suite = nil
end

#after_steps(steps) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/ci/reporter/cucumber.rb', line 81

def after_steps(steps)
  @test_case.finish

  case steps.status
  when :pending, :undefined
    if treat_pending_as_failure?
      @test_case.failures << CucumberFailure.new(steps)
    else
      @test_case.name = "#{@test_case.name} (PENDING)"
      @test_case.skipped = true
    end
  when :skipped
    @test_case.name = "#{@test_case.name} (SKIPPED)"
    @test_case.skipped = true
  when :failed
    @test_case.failures << CucumberFailure.new(steps)
  end

  test_suite.testcases << @test_case
  @test_case = nil
end

#after_table_row(table_row) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/ci/reporter/cucumber.rb', line 120

def after_table_row(table_row)
  if @header_row
    @header_row = false
    return
  end
  @test_case.finish
  if table_row.respond_to? :failed?
    @test_case.failures << CucumberFailure.new(table_row) if table_row.failed?
    test_suite.testcases << @test_case
    @test_case = nil
  end
end

#before_background(*args) ⇒ Object



57
58
59
# File 'lib/ci/reporter/cucumber.rb', line 57

def before_background(*args)
  @scenario = 'Background'
end

#before_examples(*args) ⇒ Object



103
104
105
# File 'lib/ci/reporter/cucumber.rb', line 103

def before_examples(*args)
  @header_row = true
end

#before_feature(feature) ⇒ Object



45
46
47
48
# File 'lib/ci/reporter/cucumber.rb', line 45

def before_feature(feature)
  self.test_suite = TestSuite.new(@name)
  test_suite.start
end

#before_steps(steps) ⇒ Object



72
73
74
75
# File 'lib/ci/reporter/cucumber.rb', line 72

def before_steps(steps)
  @test_case = TestCase.new(@scenario)
  @test_case.start
end

#before_table_row(table_row) ⇒ Object



110
111
112
113
114
115
116
117
118
# File 'lib/ci/reporter/cucumber.rb', line 110

def before_table_row(table_row)
  row = table_row # shorthand for table_row
  # check multiple versions of the row and try to find the best fit
  outline = (row.respond_to? :name)             ? row.name :
            (row.respond_to? :scenario_outline) ? row.scenario_outline :
                                                  row.to_s
  @test_case = TestCase.new("#@scenario (outline: #{outline})")
  @test_case.start
end

#feature_name(keyword, name) ⇒ Object



64
65
66
# File 'lib/ci/reporter/cucumber.rb', line 64

def feature_name(keyword, name)
  @name = (name || "Unnamed feature").split("\n").first
end

#scenario_name(keyword, name, *args) ⇒ Object



68
69
70
# File 'lib/ci/reporter/cucumber.rb', line 68

def scenario_name(keyword, name, *args)
  @scenario = (name || "Unnamed scenario").split("\n").first
end

#treat_pending_as_failure?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/ci/reporter/cucumber.rb', line 77

def treat_pending_as_failure?
  ENV['CI_PENDING_IS_FAILURE'] == 'true'
end