Sha256: 18f9a5cf18807be79901755b71ab4229de551cf69175b5ef1325572e05d702ad

Contents?: true

Size: 889 Bytes

Versions: 1

Compression:

Stored size: 889 Bytes

Contents

module Screengem
  #
  # Singleton that gives the ability to get references to page objects.
  #
  # On initialization generate a factory method for each page object we can find. Example:
  #
  #   def login_page
  #     Pages::LoginPage.new
  #   end
  #
  class PageReferences
    include Singleton

    def initialize
      generated_method_names = []

      Screengem::FeaturePage.descendants.each do |page_object|
        class_name = page_object.name
        method_name = class_name.demodulize.underscore

        if generated_method_names.include?(method_name)
          raise "Name collision: two page objects resolve to '#{method_name}'."
        end

        generated_method_names << method_name

        class_eval(<<~RUBY, __FILE__, __LINE__ + 1)
          def #{method_name}(*args)
            #{class_name}.new(*args)
          end
        RUBY
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
screengem-0.3.0 lib/screengem/page_references.rb