Sha256: e199067539443c8e86213047d645bd954f557463f9ec23c49113c3e4f39f3a5b

Contents?: true

Size: 1.9 KB

Versions: 3

Compression:

Stored size: 1.9 KB

Contents

module Symbiont
  module Factory
    # Creates a definition context for actions. If an existing context
    # exists, that context will be re-used.
    #
    # @param definition [Class] the name of a definition class
    # @param visit [Boolean] true if the context needs to be called into view
    # @param block [Proc] logic to execute in the context of the definition
    # @return [Object] instance of the definition
    def on(definition, visit = false, &block)
      unless @page.is_a?(definition)
        @page = definition.new(@browser) if @browser
        @page = definition.new unless @browser
        @page.view if visit
      end

      if @page.class.instance_variable_get(:@url_match)
        raise Symbiont::Errors::PageURLFromFactoryNotVerified unless @page.has_correct_url?
      end

      if @page.class.instance_variable_get(:@title)
        raise Symbiont::Errors::PageTitleFromFactoryNotVerified unless @page.has_correct_title?
      end

      block.call @page if block
      @page
    end

    alias_method :on_page, :on
    alias_method :while_on, :on

    # Creates a definition context for actions and establishes the
    # context for display.
    #
    # @param definition [Class] the name of a definition class
    # @param block [Proc] logic to execute in the context of the definition
    # @return [Object] instance of the definition
    def on_view(definition, &block)
      on(definition, true, &block)
    end

    alias_method :on_visit, :on_view

    # Creates a definition context for actions. Unlike the on() factory,
    # on_new will always create a new context and will never re-use an
    # existing one.
    #
    # @param definition [Class] the name of a definition class
    # @param block [Proc] logic to execute in the context of the definition
    # @return [Object] instance of the definition
    def on_new(definition, &block)
      @page = nil
      on(definition, &block)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
symbiont-1.2.0 lib/symbiont/factory.rb
symbiont-1.1.2 lib/symbiont/factory.rb
symbiont-1.1.0 lib/symbiont/factory.rb