Class: ProbeDockCucumber::Formatter
- Inherits:
-
Object
- Object
- ProbeDockCucumber::Formatter
- Defined in:
- lib/probe_dock_cucumber/formatter.rb
Instance Method Summary collapse
-
#after_feature(*args) ⇒ Object
Called after the feature has been executed.
-
#after_feature_element(*args) ⇒ Object
Called after each completed scenario.
-
#after_features(*args) ⇒ Object
Called when the test suite ends.
-
#after_step_result(keyword, step_match, multiline_arg, status, exception, *args) ⇒ Object
Called after each scenario step (Given, When, Then) is executed.
-
#before_feature(feature, *args) ⇒ Object
Called before each feature is tested.
-
#before_feature_element(feature_element, *args) ⇒ Object
Called before each scenario is tested.
-
#before_features(*args) ⇒ Object
Called when the test suite starts.
-
#comment_line(comment) ⇒ Object
Called for each comment line.
-
#feature_name(*args) ⇒ Object
Called for the feature name and after the before feature has been called.
-
#initialize(step_mother, io, options) ⇒ Formatter
constructor
A new instance of Formatter.
- #scenario_name(keyword, name, file_colon_line, *args) ⇒ Object
-
#tag_name(name, *args) ⇒ Object
Called every time a tag is encountered, either at the feature or the scenario level.
Constructor Details
#initialize(step_mother, io, options) ⇒ Formatter
Returns a new instance of Formatter.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/probe_dock_cucumber/formatter.rb', line 35 def initialize(step_mother, io, ) # Initialize the Probe Dock client and an empty test run. config = ProbeDockCucumber.config @client = ProbeDockProbe::Client.new(config.server, config.) @test_run = ProbeDockProbe::TestRun.new(config.project) # Current feature data. @current_feature_started = false @current_feature = nil @current_feature_tags = [] # Current scenario data. @current_scenario = nil @current_scenario_tags = [] @current_scenario_error = nil end |
Instance Method Details
#after_feature(*args) ⇒ Object
Called after the feature has been executed
129 130 131 132 |
# File 'lib/probe_dock_cucumber/formatter.rb', line 129 def after_feature(*args) @current_feature_started = false @feature_annotation = nil end |
#after_feature_element(*args) ⇒ Object
Called after each completed scenario.
124 125 126 |
# File 'lib/probe_dock_cucumber/formatter.rb', line 124 def after_feature_element(*args) add_result end |
#after_features(*args) ⇒ Object
Called when the test suite ends.
135 136 137 138 139 |
# File 'lib/probe_dock_cucumber/formatter.rb', line 135 def after_features(*args) end_time = Time.now @test_run.duration = ((end_time - @suite_start_time) * 1000).round @client.process(@test_run) end |
#after_step_result(keyword, step_match, multiline_arg, status, exception, *args) ⇒ Object
Called after each scenario step (Given, When, Then) is executed.
117 118 119 120 121 |
# File 'lib/probe_dock_cucumber/formatter.rb', line 117 def after_step_result(keyword, step_match, multiline_arg, status, exception, *args) # If a step fails, the exception is provided here. # It will be used in #add_result to build the error message of the test. @current_scenario_error = exception if exception end |
#before_feature(feature, *args) ⇒ Object
Called before each feature is tested.
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/probe_dock_cucumber/formatter.rb', line 59 def before_feature(feature, *args) # Store the first line of the feature's description. # It will be used in #add_result to build the complete name of the test. @current_feature = feature.name.sub(/\n.*$/m, '').strip # Reset feature and scenario data. @current_feature_tags = [] @current_scenario = nil @current_scenario_tags = [] @current_scenario_error = nil end |
#before_feature_element(feature_element, *args) ⇒ Object
Called before each scenario is tested.
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/probe_dock_cucumber/formatter.rb', line 87 def before_feature_element(feature_element, *args) # Store the first line of the scenario's description. # It will be used in #add_result to build the complete name of the test. @current_scenario = feature_element.name.sub(/\n.*$/m, '').strip # Reset scenario data. @current_scenario_tags = [] @current_scenario_error = nil @current_scenario_start_time = Time.now end |
#before_features(*args) ⇒ Object
Called when the test suite starts.
54 55 56 |
# File 'lib/probe_dock_cucumber/formatter.rb', line 54 def before_features(*args) @suite_start_time = Time.now end |
#comment_line(comment) ⇒ Object
Called for each comment line
100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/probe_dock_cucumber/formatter.rb', line 100 def comment_line(comment) # Take care of annotation only if matched if comment.match(ProbeDockProbe::Annotation::ANNOTATION_REGEXP) # If the feature already started, the annotations are for scenarios if @current_feature_started @annotation = ProbeDockProbe::Annotation.new(comment) else @feature_annotation = ProbeDockProbe::Annotation.new(comment) end end end |
#feature_name(*args) ⇒ Object
Called for the feature name and after the before feature has been called
73 74 75 |
# File 'lib/probe_dock_cucumber/formatter.rb', line 73 def feature_name(*args) @current_feature_started = true end |
#scenario_name(keyword, name, file_colon_line, *args) ⇒ Object
112 113 114 |
# File 'lib/probe_dock_cucumber/formatter.rb', line 112 def scenario_name(keyword, name, file_colon_line, *args) @current_scenario_file_colon_line = file_colon_line end |
#tag_name(name, *args) ⇒ Object
Called every time a tag is encountered, either at the feature or the scenario level.
78 79 80 81 82 83 84 |
# File 'lib/probe_dock_cucumber/formatter.rb', line 78 def tag_name(name, *args) if @current_scenario @current_scenario_tags << name.sub(/^@/, '').strip else @current_feature_tags << name.sub(/^@/, '').strip end end |