Class: CucumberStatistics::Formatter

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

Instance Method Summary collapse

Constructor Details

#initialize(step_mother, io, options) ⇒ Formatter

Returns a new instance of Formatter.



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/cucumber_statistics/formatter.rb', line 3

def initialize(step_mother, io, options)
  @step_mother = step_mother
  @io = io
  @options = options

  @overall_statistics = OverallStatistics.new
  @step_statistics = StepStatistics.new
  @scenario_statistics = ScenarioStatistics.new
  @feature_statistics = FeatureStatistics.new
  @unused_steps = UnusedSteps.new
end

Instance Method Details

#after_feature(feature) ⇒ Object



77
78
79
80
81
# File 'lib/cucumber_statistics/formatter.rb', line 77

def after_feature(feature)
  @feature_file = feature.location.to_s
  @feature_duration = Time.now - @feature_start_time
  @feature_statistics.record @feature_name, @feature_duration, @feature_file
end

#after_feature_element(feature_element) ⇒ Object



43
44
45
46
# File 'lib/cucumber_statistics/formatter.rb', line 43

def after_feature_element(feature_element)
  @scenario_duration = Time.now - @scenario_start_time
  @scenario_statistics.record @scenario_name, @scenario_duration, @scenario_file_colon_line
end

#after_features(features) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/cucumber_statistics/formatter.rb', line 87

def after_features(features)

  @overall_statistics.end_time = Time.now

  # gather unused steps
  @step_mother.unmatched_step_definitions.each do |step_definition|
    @unused_steps.record step_definition.regexp_source, step_definition.location.to_s
  end

  @step_statistics.calculate

  Renderer.render_combined_statistics @step_statistics, @scenario_statistics, @feature_statistics, @overall_statistics
end

#after_step(step) ⇒ Object



73
74
75
# File 'lib/cucumber_statistics/formatter.rb', line 73

def after_step(step)
  @overall_statistics.step_count_inc
end

#after_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background, file_colon_line) ⇒ Object



26
27
28
29
30
31
# File 'lib/cucumber_statistics/formatter.rb', line 26

def after_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background, file_colon_line)
  step_definition = step_match.step_definition
  unless step_definition.nil? # nil if it's from a scenario outline
    @step_statistics.record step_definition.expression, @step_duration, file_colon_line
  end
end

#before_feature(feature) ⇒ Object


Feature callbacks




51
52
53
54
55
# File 'lib/cucumber_statistics/formatter.rb', line 51

def before_feature(feature)
  @feature_name = ''
  @feature_file = ''
  @feature_start_time = Time.now
end

#before_feature_element(feature_element) ⇒ Object


Feature Element callbacks




37
38
39
40
41
# File 'lib/cucumber_statistics/formatter.rb', line 37

def before_feature_element(feature_element)
  @scenario_name = ''
  @scenario_file_colon_line = ''
  @scenario_start_time = Time.now
end

#before_features(features) ⇒ Object



83
84
85
# File 'lib/cucumber_statistics/formatter.rb', line 83

def before_features(features)
  @overall_statistics.start_time = Time.now
end

#before_step_result(*args) ⇒ Object



22
23
24
# File 'lib/cucumber_statistics/formatter.rb', line 22

def before_step_result(*args)
  @step_duration = Time.now - @step_start_time
end

#before_test_step(step) ⇒ Object


Step callbacks




18
19
20
# File 'lib/cucumber_statistics/formatter.rb', line 18

def before_test_step(step)
  @step_start_time = Time.now
end

#feature_name(keyword, name) ⇒ Object



68
69
70
71
# File 'lib/cucumber_statistics/formatter.rb', line 68

def feature_name(keyword, name)
  @overall_statistics.feature_count_inc
  @feature_name = name
end

#scenario_name(keyword, name, file_colon_line, source_indent) ⇒ Object


Overall callbacks


def before_feature(feature) end



62
63
64
65
66
# File 'lib/cucumber_statistics/formatter.rb', line 62

def scenario_name(keyword, name, file_colon_line, source_indent)
  @overall_statistics.scenario_count_inc
  @scenario_name = name
  @scenario_file_colon_line = file_colon_line
end