class Spinach::Reporter::FailureFile
The FailureFile
reporter outputs failing scenarios to a temporary file, one per line.
Attributes
failing_scenarios[R]
filename[R]
Public Class Methods
new(*args)
click to toggle source
Initializes the output filename and the temporary directory.
Calls superclass method
Spinach::Reporter::new
# 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 = options[: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
Public Instance Methods
after_run(success)
click to toggle source
Writes all failing scenarios to a file, unless our run was successful.
@param [Boolean] success
Indicates whether the entire test run was successful
# 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)
click to toggle source
Adds a step that has raised an error to the output buffer.
# 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)
click to toggle source
Adds a failing step to the output buffer.
# File lib/spinach/reporter/failure_file.rb, line 40 def on_failed_step(*args) add_scenario(current_feature.filename, current_scenario.lines[0]) end
Private Instance Methods
add_scenario(filename, line)
click to toggle source
Adds a filename and line number to the output buffer, suitable for rerunning.
# File lib/spinach/reporter/failure_file.rb, line 54 def add_scenario(filename, line) @failing_scenarios << "#{filename}:#{line}" end