Class: TestAssistant::Configuration

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

Overview

Class that provides configuration methods to control what parts of Test Assistant are included in an RSpec test suite. Instances of this class are managed internally by Test Assistant when using the TestAssistant#configure method.

See Also:

  • #configure

Instance Method Summary collapse

Constructor Details

#initialize(rspec_config) ⇒ TestAssistant::Configuration

Creates a new TestAssistant::Configuration object - called internally by Test Assistant

Parameters:

  • rspec_config

    RSpec configuration object, available in the block passed to RSpec.configure



16
17
18
# File 'lib/test_assistant/configuration.rb', line 16

def initialize(rspec_config)
  @rspec_config = rspec_config
end

Instance Method Details

#debug_failed_responses(options = {}) ⇒ Object

Configures under what circumstances a failing test should open an debugger session

Examples:

Open the debugger for failing tests tagged with :focus

RSpec.configure do |config|
  TestAssistant.configure(config) do |ta_config|
    ta_config.debug_failed_responses(tag: :focus)
  end
end

Open the debugger for all failing tests

RSpec.configure do |config|
  TestAssistant.configure(config) do |ta_config|
    ta_config.debug_failed_responses(tag: false)
  end
end

Open the debugger for all failing controller tests

RSpec.configure do |config|
  TestAssistant.configure(config) do |ta_config|
    ta_config.debug_failed_responses(type: :controller)
  end
end

Parameters:

  • options (Hash{Symbol => Symbol,String,Boolean}) (defaults to: {})

    filters for when a test failure should open a debugger session

Options Hash (options):

  • :tag (Symbol, Boolean)

    The tag tests must be given in order to open the debugger. If false, no tag is needed and any test that fails (and meets any other filter options provided) will open the debugger.

  • :type (Symbol, Boolean)

    The type of test that should open the debugger if it fails. If false, no tag is needed and any test that fails (and meets any other filter options provided) will open the debugger.

Returns:

  • void



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/test_assistant/configuration.rb', line 110

def debug_failed_responses(options = {})
  tag_filter = options.fetch(:tag, :debugger)
  type_filter = options[:type]
  no_type_filter = !type_filter

  @rspec_config.after(:each) do |example|
    next unless example.exception

     = example.
    next unless (.key?(tag_filter)) && ([:type] == type_filter || no_type_filter)

    # noinspection RubyResolve
    if defined? binding
      binding.pry
    elsif defined? byebug
      byebug
    else
      debugger
    end
  end
end

#render_failed_responses(options = {}) ⇒ Object

Configures under what circumstances a failing test should open a failure report detailing the last HTTP request and response in a browser

Examples:

Show a failure report for failing tests tagged with :focus

RSpec.configure do |config|
  TestAssistant.configure(config) do |ta_config|
    ta_config.render_failed_response(tag: :focus)
  end
end

Show a failure report for all failing tests

RSpec.configure do |config|
  TestAssistant.configure(config) do |ta_config|
    ta_config.render_failed_response(tag: false)
  end
end

Show a failure report for all failing controller tests

RSpec.configure do |config|
  TestAssistant.configure(config) do |ta_config|
    ta_config.render_failed_response(type: :controller)
  end
end

Parameters:

  • options (Hash{Symbol => Symbol,String,Boolean}) (defaults to: {})

    filters for when a test failure should show a failure report

Options Hash (options):

  • :tag (Symbol, Boolean)

    The tag tests must be given in order to show a failure report. If false, no tag is needed and all tests that fail (and meet any other filter options provided) will show a failure report.

  • :type (Symbol, Boolean)

    The RSpec test type for which a failure will show a failure report. If false, tests of any type that fail (and meet any other filter options provided) will show a failure report.

Returns:

  • void

See Also:

  • FailureReporter#report


55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/test_assistant/configuration.rb', line 55

def render_failed_responses(options = {})
  tag_filter = options[:tag]
  no_tag_filter = !tag_filter

  type_filter = options[:type]
  no_type_filter = !type_filter

  @rspec_config.after(:each) do |example|
    next unless example.exception

     = example.
    next unless ([tag_filter] || no_tag_filter) && ([:type] == type_filter || no_type_filter)

    if [:type] == :feature
      save_and_open_page
    else
      reporter = FailureReporter.report(request, response)
      reporter.write
      reporter.open
    end
  end
end