Sha256: 7e24e7a453275e554e5be077cd022875bbfdb3d08a4e504d9012f6b73f25a9b2

Contents?: true

Size: 1.68 KB

Versions: 1

Compression:

Stored size: 1.68 KB

Contents

require 'capybara'
require 'capybara/dsl'

require 'symbiont/capybara/element'
require 'symbiont/capybara/ready'

module Symbiont
  class Page
    include Capybara::DSL
    include Ready
    extend Element

    class << self
      attr_reader :url

      def url_is(url)
        @url = url.to_s
      end

      def url_matches(url)
        @url_matcher = url
      end

      def url_matcher
        @url_matcher || url
      end
    end

    def initialize(&block)
      super
      instance_eval(&block) if block
    end

    page_ready do
      [displayed?, "Expected #{current_url} to match #{url_matcher} but it did not."]
    end

    def view(content = {}, &block)
      self.ready = false

      if content.is_a?(String)
        @page = Capybara.string(content)
      else
        location = url
        fail Symbiont::Errors::NoUrlForDefinition if location.nil?
        visit url
      end

      when_ready(&block) if block_given?
    end

    alias_method :load, :view
    alias_method :markup, :html
    alias_method :run_script, :execute_script

    def perform(*args)
      view(*args)
      self
    end

    def url
      self.class.url
    end

    def url_matcher
      self.class.url_matcher
    end

    def displayed?
      fail Symbiont::Errors::NoUrlMatchForDefinition if url_matcher.nil?
      true
    end

    def secure?
      !current_url.match(/^https/).nil?
    end

    private

    def find_first(*identifier)
      find(*identifier)
    end

    def find_all(*identifier)
      all(*identifier)
    end

    def element_exists?(*identifier)
      has_selector?(*identifier)
    end

    def element_does_not_exist?(*identifier)
      has_no_selector?(*identifier)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
symbiont-1.1.2 lib/symbiont/capybara/page.rb