class TestAssistant::FailureReporter::SummaryReporter

Base class for generating, saving and opening failure reports. Those classes that inherit from it provide further customisations to better parse and format different request and response bodies, depending on their format.

Attributes

file_extension[RW]
next[RW]

Public Class Methods

new(request, response, extension = file_extension) click to toggle source

Creates a new SummaryReport object

@param [ActionDispatch::Request] request the last request made before the test

failed

@param [ActionDispatch::TestResponse] response the response to the last request

made before the test failed

@param [String] extension what file extension should be used when saving the

failure report

@return [SummaryReport] new summary report object

# File lib/test_assistant/failure_reporter.rb, line 24
def initialize(request, response, extension = file_extension)
  @request, @response, @extension = request, response, extension
end

Public Instance Methods

open() click to toggle source

Opens the failure report file using an application that depends on the failure report's file extension. Expects that write has already been called and the file exists.

@return void

# File lib/test_assistant/failure_reporter.rb, line 44
def open
  system "open #{file_path}"
end
write() click to toggle source

Writes the failure report to the tmp directory in the root of your Rails project so that it may be opened for viewing in an appropriate application depending on the failure report's file extension

@return void

# File lib/test_assistant/failure_reporter.rb, line 33
def write
  File.open(file_path, 'w') do |file|
    file.write(summary)
  end
end

Protected Instance Methods

file_path() click to toggle source
# File lib/test_assistant/failure_reporter.rb, line 54
def file_path
  @file_path ||= "#{Rails.root}/tmp/#{DateTime.now.to_i}.#{@extension}"
end
summary() click to toggle source
# File lib/test_assistant/failure_reporter.rb, line 50
def summary
  @response.body
end