Class: TestAssistant::FailureReporter::SummaryReporter

Inherits:
Object
  • Object
show all
Defined in:
lib/test_assistant/failure_reporter.rb

Overview

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.

Direct Known Subclasses

JsonReporter, TextReporter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request, response, extension = file_extension) ⇒ SummaryReport

Creates a new SummaryReport object

Parameters:

  • request (ActionDispatch::Request)

    the last request made before the test failed

  • response (ActionDispatch::TestResponse)

    the response to the last request made before the test failed

  • extension (String) (defaults to: file_extension)

    what file extension should be used when saving the failure report



24
25
26
# File 'lib/test_assistant/failure_reporter.rb', line 24

def initialize(request, response, extension = file_extension)
  @request, @response, @extension = request, response, extension
end

Instance Attribute Details

#file_extensionObject

Returns the value of attribute file_extension.



13
14
15
# File 'lib/test_assistant/failure_reporter.rb', line 13

def file_extension
  @file_extension
end

#nextObject

Returns the value of attribute next.



13
14
15
# File 'lib/test_assistant/failure_reporter.rb', line 13

def next
  @next
end

Instance Method Details

#openObject

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.

Returns:

  • void



44
45
46
# File 'lib/test_assistant/failure_reporter.rb', line 44

def open
  system "open #{file_path}"
end

#writeObject

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

Returns:

  • void



33
34
35
36
37
# File 'lib/test_assistant/failure_reporter.rb', line 33

def write
  File.open(file_path, 'w') do |file|
    file.write(summary)
  end
end