class Selenium::WebDriver::Support::Guards

Constants

GUARD_TYPES

Attributes

bug_tracker[RW]
messages[R]

Public Class Methods

new(example, bug_tracker: '', conditions: nil) click to toggle source
# File lib/selenium/webdriver/support/guards.rb, line 32
def initialize(example, bug_tracker: '', conditions: nil)
  @example = example
  @bug_tracker = bug_tracker
  @guard_conditions = conditions || []
  @guards = collect_example_guards
  @messages = {}
end

Public Instance Methods

add_condition(name, condition = nil, &) click to toggle source
# File lib/selenium/webdriver/support/guards.rb, line 40
def add_condition(name, condition = nil, &)
  @guard_conditions << GuardCondition.new(name, condition, &)
end
add_message(name, message) click to toggle source
# File lib/selenium/webdriver/support/guards.rb, line 44
def add_message(name, message)
  @messages[name] = message
end
disposition() click to toggle source
# File lib/selenium/webdriver/support/guards.rb, line 48
def disposition
  if !skipping_guard.nil?
    [:skip, skipping_guard.message]
  elsif !pending_guard.nil? && ENV.fetch('SKIP_PENDING', nil)
    [:skip, pending_guard.message]
  elsif !pending_guard.nil?
    [:pending, pending_guard.message]
  end
end
satisfied?(guard) click to toggle source
# File lib/selenium/webdriver/support/guards.rb, line 58
def satisfied?(guard)
  @guard_conditions.all? { |condition| condition.satisfied?(guard) }
end

Private Instance Methods

collect_example_guards() click to toggle source
# File lib/selenium/webdriver/support/guards.rb, line 64
def collect_example_guards
  guards = []

  GUARD_TYPES.each do |guard_type|
    example_group = @example.metadata[:example_group]
    example_guards = [@example.metadata[guard_type], example_group[guard_type]]
    while example_group[:parent_example_group]
      example_group = example_group[:parent_example_group]
      example_guards << example_group[guard_type]
    end

    example_guards.flatten.uniq.compact.each do |example_guard|
      guards << Guard.new(example_guard, guard_type, self)
    end
  end

  guards
end
pending_guard() click to toggle source
# File lib/selenium/webdriver/support/guards.rb, line 88
def pending_guard
  @guards.select(&:except?).find { |guard| satisfied?(guard) } ||
    @guards.select(&:only?).find { |guard| !satisfied?(guard) }
end
skipping_guard() click to toggle source
# File lib/selenium/webdriver/support/guards.rb, line 83
def skipping_guard
  @guards.select(&:exclusive?).find { |guard| !satisfied?(guard) } ||
    @guards.select(&:exclude?).find { |guard| satisfied?(guard) }
end