Sha256: f41d47fe621a2fb469113e2da69aceceb24e04f129e8a2760c0e82021e5382b9

Contents?: true

Size: 1.51 KB

Versions: 2

Compression:

Stored size: 1.51 KB

Contents

module Calabash

  # @!visibility private
  class AbstractMethodError < StandardError

  end

  module Utility

    # @!visibility private
    def abstract_method!
      method_name = if Kernel.method_defined?(:caller_locations)
                      caller_locations.first.label
                    else
                      caller.first[/\`(.*)\'/, 1]
                    end

      raise AbstractMethodError.new("Abstract method '#{method_name}'")
    end

    # @!visibility private
    class RetryError < RuntimeError; end

    # A convenience method for creating a percentage hash that that can be
    # passed to gestures.
    #
    # @example
    #  # These are equivalent.
    #  pan("*", percent(20, 50), percent(20, 100))
    #  pan("*", {x: 20, y: 50}, {x: 20, y: 100})
    #
    # @param [Number] x The value of the x percent.
    # @param [Number] y The value of the y percent.
    # @return [Hash] Representing the given values.
    def percent(x, y)
      {x: x, y: y}
    end

    alias_method :pct, :percent

    # A convenience method for creating a coordinate hash that that can be
    # passed to gestures.
    #
    # @example
    #  # These are equivalent.
    #  tap(query, offset: coordinate(20, 50))
    #  tap(query, offset: {x: 20, y: 50})
    #
    # @param [Number] x The value of the x.
    # @param [Number] y The value of the y.
    # @return [Hash] Representing the given values.
    # @!visibility private
    def coordinate(x, y)
      {x: x, y: y}
    end

    alias_method :coord, :coordinate
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
calabash-2.0.0.pre2 lib/calabash/utility.rb
calabash-2.0.0.pre1 lib/calabash/utility.rb