Sha256: 8edd345acc0cb0b67936da91a575676cf99e76255b8de8f7e75617704fb5c0f2

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

module Testable
  module Element
    def element(name, locator = nil)
      no_locator(name) if locator.nil?
      build(name, locator) do
        define_method(name.to_s) do |*options|
          find_first(locator, *options)
        end
      end
    end

    def elements(name, locator = nil)
      no_locator(name) if locator.nil?
      build(name, locator) do
        define_method(name.to_s) do |*options|
          find_all(locator, *options)
        end
      end
    end

    private

    def build(name, locator)
      yield
      add_element_methods(name, locator)
    end

    def add_element_methods(name, locator)
      existence_check(name, locator)
      nonexistence_check(name, locator)
    end

    def existence_check(name, locator)
      method_name = "has_#{name}?"
      create_element_method(name, locator) do
        define_method(method_name) do |*args|
          element_exists?(locator, *args)
        end
      end
    end

    def nonexistence_check(name, locator)
      method_name = "has_no_#{name}?"
      create_element_method(name, locator) do
        define_method(method_name) do |*args|
          element_does_not_exist?(locator, *args)
        end
      end
    end

    def create_element_method(_name, _locator)
      yield
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
testable-0.2.0 lib/testable/element.rb