Sha256: e64c8773d33be1f4ffb149477df2ca1727cad85357d7fd41bbf379f10d0bffa8

Contents?: true

Size: 1018 Bytes

Versions: 1

Compression:

Stored size: 1018 Bytes

Contents

require "capybara/node/matchers"

module WildcardFinders
  module Matchers
    METHODS = []

    def self.method_added(name)
      METHODS.push(name)
    end

    ::WildcardFinders::Finders::METHODS.each do |method|
      if method =~ /\Afind_/
        matcher_method    = method.to_s.sub("find", "has") + "?"
        no_matcher_method = method.to_s.sub("find", "has_no") + "?"

        define_method(matcher_method) do |*args, &block|
          wait_method = respond_to?(:synchronize) ? :synchronize : :wait_until

          __send__(wait_method) do
            result = __send__(method, *args, &block)
            result or return(false)
          end

          true
        end

        define_method(no_matcher_method) do |*args, &block|
          wait_method = respond_to?(:synchronize) ? :synchronize : :wait_until

          __send__(wait_method) do
            result = __send__(method, *args, &block)
            result and return(false)
          end

          true
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wildcard_finders-0.1.0 lib/wildcard_finders/matchers.rb