Sha256: 473cfe5791cfaa384abcc230686c4065e914aef35115e4654f3552b8fe569d93

Contents?: true

Size: 1.62 KB

Versions: 20

Compression:

Stored size: 1.62 KB

Contents

module WatirSpec
  module Guards

    class << self
      def guards
        @guards ||= Hash.new { |hash, key| hash[key] = [] }
      end

      def record(guard_name, impls, data)
        guards[impls] << {name: guard_name, data: data}
      end

      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][/\/spec\/(.*):/, 1]
            guard_name = "#{guard[:name]}:".ljust(15)
            str << " \t#{guard_name} #{guard[:data].inspect}\n"
          end
          Watir.logger.warn str
        end
      end
    end # class << self

    private

    def deviates_on(*impls)
      Guards.record :deviates, impls, file: caller.first
      return yield if WatirSpec.unguarded?
      yield if WatirSpec.implementation.matches_guard?(impls)
    end

    def not_compliant_on(*impls)
      Guards.record :not_compliant, impls, file: caller.first
      return yield if WatirSpec.unguarded?
      yield unless WatirSpec.implementation.matches_guard?(impls)
    end

    def compliant_on(*impls)
      Guards.record :compliant, impls, file: caller.first
      return yield if WatirSpec.unguarded?
      yield if WatirSpec.implementation.matches_guard?(impls)
    end

    def bug(key, *impls)
      Guards.record :bug, impls, file: caller.first, key: key
      return yield if WatirSpec.unguarded?
      yield if impls.any? && !WatirSpec.implementation.matches_guard?(impls)
    end
  end
end

class Object
  include WatirSpec::Guards
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
watir-6.11.0 lib/watirspec/guards.rb
watir-6.11.0.beta2 lib/watirspec/guards.rb
watir-6.11.0.beta1 lib/watirspec/guards.rb
watir-6.10.3 lib/watirspec/guards.rb
watir-6.10.2 lib/watirspec/guards.rb
watir-6.10.0 lib/watirspec/guards.rb
watir-6.9.1 lib/watirspec/guards.rb
watir-6.9.0 lib/watirspec/guards.rb
watir-6.8.4 lib/watirspec/guards.rb
watir-6.8.3 lib/watirspec/guards.rb
watir-6.8.2 lib/watirspec/guards.rb
watir-6.8.1 lib/watirspec/guards.rb
watir-6.8.0 lib/watirspec/guards.rb
watir-6.7.3 lib/watirspec/guards.rb
watir-6.7.2 lib/watirspec/guards.rb
watir-6.7.1 lib/watirspec/guards.rb
watir-6.7.0 lib/watirspec/guards.rb
watir-6.6.3 lib/watirspec/guards.rb
watir-6.6.2 lib/watirspec/guards.rb
watir-6.6.1 lib/watirspec/guards.rb