123456789_123456789_123456789_123456789_123456789_

Class: Selenium::WebDriver::Support::Guards

Constant Summary

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(example, bug_tracker: '', conditions: nil) ⇒ Guards

[ GitHub ]

  
# File 'rb/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

Instance Attribute Details

#bug_tracker (rw)

[ GitHub ]

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

attr_accessor :bug_tracker

#messages (readonly)

[ GitHub ]

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

attr_reader :messages

Instance Method Details

#add_condition(name, condition = nil)

[ GitHub ]

  
# File 'rb/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)

[ GitHub ]

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

def add_message(name, message)
  @messages[name] = message
end

#collect_example_guards (private)

[ GitHub ]

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

def collect_example_guards
  guards = []

  GUARD_TYPES.each do |guard_type|
    example_group = @example.[:example_group]
    example_guards = [@example.[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

#disposition

[ GitHub ]

  
# File 'rb/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

#pending_guard (private)

[ GitHub ]

  
# File 'rb/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

#satisfied?(guard) ⇒ Boolean

[ GitHub ]

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

def satisfied?(guard)
  @guard_conditions.all? { |condition| condition.satisfied?(guard) }
end

#skipping_guard (private)

[ GitHub ]

  
# File 'rb/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