Class: Spinach::Reporter::FailureFile
- Inherits:
-
Spinach::Reporter
- Object
- Spinach::Reporter
- Spinach::Reporter::FailureFile
- Defined in:
- lib/spinach/reporter/failure_file.rb
Overview
The FailureFile reporter outputs failing scenarios to a temporary file, one per line.
Instance Attribute Summary collapse
-
#failing_scenarios ⇒ Object
readonly
Returns the value of attribute failing_scenarios.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
Attributes inherited from Spinach::Reporter
#current_feature, #current_scenario, #error_steps, #failed_steps, #options, #pending_steps, #successful_steps, #undefined_features, #undefined_steps
Instance Method Summary collapse
-
#after_run(success) ⇒ Object
Writes all failing scenarios to a file, unless our run was successful.
-
#initialize(*args) ⇒ FailureFile
constructor
Initializes the output filename and the temporary directory.
-
#on_error_step(*args) ⇒ Object
Adds a step that has raised an error to the output buffer.
-
#on_failed_step(*args) ⇒ Object
Adds a failing step to the output buffer.
Methods inherited from Spinach::Reporter
#after_feature_run, #after_scenario_run, #around_scenario_run, #before_feature_run, #before_run, #before_scenario_run, #bind, #clear_current_feature, #clear_current_scenario, #on_feature_not_found, #on_pending_step, #on_skipped_step, #on_successful_step, #on_undefined_step, #set_current_feature, #set_current_scenario
Constructor Details
#initialize(*args) ⇒ FailureFile
Initializes the output filename and the temporary directory.
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/spinach/reporter/failure_file.rb', line 13 def initialize(*args) super(*args) # Generate a unique filename for this test run, or use the supplied option @filename = [:failure_filename] || ENV['SPINACH_FAILURE_FILE'] || "tmp/spinach-failures_#{Time.now.strftime('%F_%H-%M-%S-%L')}.txt" # Create the temporary directory where we will output our file, if necessary Dir.mkdir('tmp', 0755) unless Dir.exist?('tmp') # Collect an array of failing scenarios @failing_scenarios = [] end |
Instance Attribute Details
#failing_scenarios ⇒ Object (readonly)
Returns the value of attribute failing_scenarios.
26 27 28 |
# File 'lib/spinach/reporter/failure_file.rb', line 26 def failing_scenarios @failing_scenarios end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
26 27 28 |
# File 'lib/spinach/reporter/failure_file.rb', line 26 def filename @filename end |
Instance Method Details
#after_run(success) ⇒ Object
Writes all failing scenarios to a file, unless our run was successful.
33 34 35 36 |
# File 'lib/spinach/reporter/failure_file.rb', line 33 def after_run(success) # Save our failed scenarios to a file File.open(@filename, 'w') { |f| f.write @failing_scenarios.join("\n") } unless success end |
#on_error_step(*args) ⇒ Object
Adds a step that has raised an error to the output buffer.
46 47 48 |
# File 'lib/spinach/reporter/failure_file.rb', line 46 def on_error_step(*args) add_scenario(current_feature.filename, current_scenario.lines[0]) end |
#on_failed_step(*args) ⇒ Object
Adds a failing step to the output buffer.
40 41 42 |
# File 'lib/spinach/reporter/failure_file.rb', line 40 def on_failed_step(*args) add_scenario(current_feature.filename, current_scenario.lines[0]) end |