Sha256: c9f35db96d0bffe15dfc7a1f14e0f324b4caf8f7a767de45070f9bc4e0385284

Contents?: true

Size: 1.5 KB

Versions: 7

Compression:

Stored size: 1.5 KB

Contents

module Howitzer
  module Utils
    # This module extends standard String class with useful methods for Cucumber step definitions
    module StringExtensions
      # Opens a page by name
      # @example
      #   'home'.open #=> HomePage.open
      # @see Howitzer::Web::Page.open

      def open(*args)
        as_page_class.open(*args)
      end

      # Returns an instantiated page by name
      # @example
      #   'home'.given #=> HomePage.given
      # @see Howitzer::Web::Page.given

      def given
        as_page_class.given
      end

      # Waits until a page is opened or raises error
      # @example
      #   'home'.displayed? #=> HomePage.displayed?
      # @see Howitzer::Web::Page.displayed?

      def displayed?
        as_page_class.displayed?
      end

      # Returns a page class by name
      # @example
      #   'home'.as_page_class #=> HomePage
      # @see Howitzer::Web::Page

      def as_page_class
        as_class('Page')
      end

      # Returns an email class by name
      # @example
      #   'Reset Password'.as_email_class #=> ResetPasswordEmail
      # @see Howitzer::Email

      def as_email_class
        as_class('Email')
      end

      # Executes code in context of the page
      # @example
      #   'home'.on { puts 1 } #=> HomePage.on { puts 1 }
      # @see Howitzer::Web::Page.on

      def on(&block)
        as_page_class.on(&block)
      end

      private

      def as_class(type)
        "#{gsub(/\s/, '_').camelize}#{type}".constantize
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
howitzer-2.2.0 lib/howitzer/utils/string_extensions.rb
howitzer-2.1.1 lib/howitzer/utils/string_extensions.rb
howitzer-2.1.0 lib/howitzer/utils/string_extensions.rb
howitzer-2.0.3 lib/howitzer/utils/string_extensions.rb
howitzer-2.0.2 lib/howitzer/utils/string_extensions.rb
howitzer-2.0.1 lib/howitzer/utils/string_extensions.rb
howitzer-2.0.0 lib/howitzer/utils/string_extensions.rb