123456789_123456789_123456789_123456789_123456789_

Class: Selenium::WebDriver::Support::Guards::Guard Private

Relationships & Source Files
Inherits: Object
Defined in: rb/lib/selenium/webdriver/support/guards/guard.rb

Overview

Guard derived from RSpec example metadata.

Class Method Summary

Instance Attribute Summary

  • #except? ⇒ Boolean readonly Internal use only

    Test is expected to fail on the configurations specified (marked pending).

  • #exception? ⇒ Boolean readonly Internal use only

    A pending guard that only applies when the failure matches an expected exception.

  • #exclude? ⇒ Boolean readonly Internal use only

    Test is skipped on the configurations specified because it breaks the run or is unreliable.

  • #exclusive? ⇒ Boolean readonly Internal use only

    Test is skipped on every configuration except those specified (it only applies there).

  • #guarded readonly Internal use only
  • #messages readonly Internal use only
  • #only? ⇒ Boolean readonly Internal use only

    Test is expected to fail on every configuration except those specified (marked pending).

  • #reason readonly Internal use only
  • #tracker readonly Internal use only
  • #type readonly Internal use only

Instance Method Summary

Constructor Details

.new(guarded, type, guards = nil) ⇒ Guard

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/support/guards/guard.rb', line 32

def initialize(guarded, type, guards = nil)
  @guarded = guarded.dup
  @tracker = guards&.bug_tracker || ''
  @messages = guards&.messages || {}
  @messages[:unknown] = 'TODO: Investigate why this is failing and file a bug report'
  @type = type

  @reason = @guarded[:reason] || 'No reason given'
  @guarded[:reason] = @reason
end

Instance Attribute Details

#except?Boolean (readonly)

Test is expected to fail on the configurations specified (marked pending).

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/support/guards/guard.rb', line 68

def except?
  @type == :pending_if || @type == :except
end

#exception?Boolean (readonly)

A pending guard that only applies when the failure matches an expected exception.

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/support/guards/guard.rb', line 88

def exception?
  (except? || only?) && !@guarded[:exception].nil?
end

#exclude?Boolean (readonly)

Test is skipped on the configurations specified because it breaks the run or is unreliable.

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/support/guards/guard.rb', line 78

def exclude?
  @type == :skip_if || @type == :exclude || @type == :flaky
end

#exclusive?Boolean (readonly)

Test is skipped on every configuration except those specified (it only applies there).

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/support/guards/guard.rb', line 83

def exclusive?
  @type == :skip_unless || @type == :exclusive
end

#guarded (readonly)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/support/guards/guard.rb', line 30

attr_reader :guarded, :type, :messages, :reason, :tracker

#messages (readonly)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/support/guards/guard.rb', line 30

attr_reader :guarded, :type, :messages, :reason, :tracker

#only?Boolean (readonly)

Test is expected to fail on every configuration except those specified (marked pending).

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/support/guards/guard.rb', line 73

def only?
  @type == :pending_unless || @type == :only
end

#reason (readonly)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/support/guards/guard.rb', line 30

attr_reader :guarded, :type, :messages, :reason, :tracker

#tracker (readonly)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/support/guards/guard.rb', line 30

attr_reader :guarded, :type, :messages, :reason, :tracker

#type (readonly)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/support/guards/guard.rb', line 30

attr_reader :guarded, :type, :messages, :reason, :tracker

Instance Method Details

#matches_exception?(exception) ⇒ Boolean

Whether the exception is the guard's exception: class and matches its optional message: (Regexp pattern or exact String), following RSpec's raise_error semantics.

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/support/guards/guard.rb', line 94

def matches_exception?(exception)
  spec = @guarded[:exception]
  return false unless spec && exception.is_a?(spec[:class])

  message = spec[:message]
  message.nil? || (message.is_a?(Regexp) ? message.match?(exception.message) : message == exception.message)
end

#message

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/support/guards/guard.rb', line 43

def message
  details = case reason
            when Integer
              "Bug Filed: #{tracker}/#{reason}"
            when Symbol
              messages[reason]
            else
              "#{type.to_s.tr('_', ' ')} #{guarded};"
            end

  case type
  when :skip_if, :exclude
    "Test skipped because it breaks test run; #{details}"
  when :flaky
    "Test skipped because it is unreliable in this configuration; #{details}"
  when :skip_unless, :exclusive
    "Test does not apply to this configuration; #{details}"
  when :pending_if, :pending_unless, :except, :only
    "Test guarded; #{details}"
  else
    raise ArgumentError, "unknown guard type: #{type}"
  end
end