module WatirSpec::Guards

Public Class Methods

guards() click to toggle source
# File lib/watirspec/guards.rb, line 4
def guards
  @guards ||= Hash.new { |hash, key| hash[key] = [] }
end
record(guard_name, impls, data) click to toggle source
# File lib/watirspec/guards.rb, line 8
def record(guard_name, impls, data)
  guards[impls] << {name: guard_name, data: data}
end
report() click to toggle source
# File lib/watirspec/guards.rb, line 12
def report
  gs = WatirSpec.implementation.matching_guards_in(guards)
  str = "WatirSpec guards for this implementation: \n"

  if gs.empty?
    "\tnone."
  else
    gs.each do |guard|
      guard[:data][:file] = guard[:data][:file][%r{/spec/(.*):}, 1]
      guard_name = "#{guard[:name]}:".ljust(15)
      str << " \t#{guard_name} #{guard[:data].inspect}\n"
    end
    Watir.logger.warn str, ids: [:guard_names]
  end
end

Private Instance Methods

bug(key, *impls) { || ... } click to toggle source
# File lib/watirspec/guards.rb, line 52
def bug(key, *impls)
  Guards.record :bug, impls, file: caller(1..1).first, key: key
  return yield if WatirSpec.unguarded?

  yield if impls.any? && !WatirSpec.implementation.matches_guard?(impls)
end
compliant_on(*impls) { || ... } click to toggle source
# File lib/watirspec/guards.rb, line 45
def compliant_on(*impls)
  Guards.record :compliant, impls, file: caller(1..1).first
  return yield if WatirSpec.unguarded?

  yield if WatirSpec.implementation.matches_guard?(impls)
end
deviates_on(*impls) { || ... } click to toggle source
# File lib/watirspec/guards.rb, line 31
def deviates_on(*impls)
  Guards.record :deviates, impls, file: caller(1..1).first
  return yield if WatirSpec.unguarded?

  yield if WatirSpec.implementation.matches_guard?(impls)
end
not_compliant_on(*impls) { || ... } click to toggle source
# File lib/watirspec/guards.rb, line 38
def not_compliant_on(*impls)
  Guards.record :not_compliant, impls, file: caller(1..1).first
  return yield if WatirSpec.unguarded?

  yield unless WatirSpec.implementation.matches_guard?(impls)
end