Class: TeamCityFormatter::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/teamcity_formatter/formatter.rb

Instance Method Summary collapse

Constructor Details

#initialize(runtime, io, options) ⇒ Formatter

Returns a new instance of Formatter.



6
7
8
9
10
11
12
# File 'lib/teamcity_formatter/formatter.rb', line 6

def initialize(runtime, io, options)
  @logger = Logger.new(io)
  @feature = nil
  @exception = nil
  @scenario = nil
  @scenario_outline = nil
end

Instance Method Details

#after_feature(cuke_feature) ⇒ Object



22
23
24
25
26
# File 'lib/teamcity_formatter/formatter.rb', line 22

def after_feature(cuke_feature)
  @logger.test_suite_finished(@feature.name)

  @feature = nil
end

#after_feature_element(cuke_feature_element) ⇒ Object

this method gets called after a scenario or scenario outline we dispatch to our own more specific methods



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/teamcity_formatter/formatter.rb', line 42

def after_feature_element(cuke_feature_element)
  if cuke_feature_element.is_a?(Cucumber::Formatter::LegacyApi::Ast::Scenario)
    after_scenario(cuke_feature_element)
  elsif cuke_feature_element.is_a?(Cucumber::Formatter::LegacyApi::Ast::ScenarioOutline)
    after_scenario_outline(cuke_feature_element)
  else
    raise("unsupported feature element `#{cuke_feature_element.class.name}`")
  end

  @exception = nil
  @scenario = nil
  @scenario_outline = nil
end

#after_table_row(cuke_table_row) ⇒ Object

this method is called after a scenario outline row OR step data table row



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/teamcity_formatter/formatter.rb', line 69

def after_table_row(cuke_table_row)
  if cuke_table_row.is_a?(Cucumber::Formatter::LegacyApi::Ast::ExampleTableRow)
    is_not_header_row = (@scenario_outline.example_column_names != cuke_table_row.cells)
    if is_not_header_row
      # treat scenario-level exception as example exception
      # the exception could have been raised in a background section
      exception = (@exception || cuke_table_row.exception)
      example = @scenario_outline.examples.find { |example| example.column_values == cuke_table_row.cells }
      test_name = scenario_outline_test_name(@scenario_outline.name, example.column_values)
      if exception
        @logger.test_failed(test_name, exception)
      end
      @logger.test_finished(test_name)

      @exception = nil
    end
  end
end

#before_feature(cuke_feature) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/teamcity_formatter/formatter.rb', line 14

def before_feature(cuke_feature)
  @feature = Feature.new.tap do |x|
    x.name = "#{cuke_feature.keyword}: #{cuke_feature.name}"
  end

  @logger.test_suite_started(@feature.name)
end

#before_feature_element(cuke_feature_element) ⇒ Object

this method gets called before a scenario or scenario outline we dispatch to our own more specific methods



30
31
32
33
34
35
36
37
38
# File 'lib/teamcity_formatter/formatter.rb', line 30

def before_feature_element(cuke_feature_element)
  if cuke_feature_element.is_a?(Cucumber::Core::Ast::Scenario)
    before_scenario(cuke_feature_element)
  elsif cuke_feature_element.is_a?(Cucumber::Core::Ast::ScenarioOutline)
    before_scenario_outline(cuke_feature_element)
  else
    raise("unsupported feature element `#{cuke_feature_element.class.name}`")
  end
end

#before_table_row(cuke_table_row) ⇒ Object

this method is called before a scenario outline row OR step data table row



57
58
59
60
61
62
63
64
65
66
# File 'lib/teamcity_formatter/formatter.rb', line 57

def before_table_row(cuke_table_row)
  if cuke_table_row.is_a?(Cucumber::Formatter::LegacyApi::ExampleTableRow)
    is_not_header_row = (@scenario_outline.example_column_names != cuke_table_row.values)
    if is_not_header_row
      example = @scenario_outline.examples.find { |example| example.column_values == cuke_table_row.values }
      test_name = scenario_outline_test_name(@scenario_outline.name, example.column_values)
      @logger.test_started(test_name)
    end
  end
end

#exception(exception, status) ⇒ Object



88
89
90
# File 'lib/teamcity_formatter/formatter.rb', line 88

def exception(exception, status)
  @exception = exception
end