Sha256: d4b15c2714fcf9ddc930af7e3def4a70467b1be3de1ea5d53f952fec2a454ea7

Contents?: true

Size: 1.14 KB

Versions: 17

Compression:

Stored size: 1.14 KB

Contents

require 'capybara'
require 'capybara/rspec/matchers'
require 'capybara/poltergeist'

module Infrataster
  module Contexts
    class CapybaraContext < BaseContext
      CAPYBARA_DRIVER_NAME = :infrataster_driver

      def self.session
        @session ||= prepare_session
      end

      def self.prepare_session
        Capybara.register_driver CAPYBARA_DRIVER_NAME do |app|
          Capybara::Poltergeist::Driver.new(
            app,
          )
        end
        Capybara::Session.new(CAPYBARA_DRIVER_NAME)
      end

      def initialize(*args)
        super(*args)
      end

      def session
        self.class.session
      end

      def page
        session
      end

      def before_each(example)
        example.example_group_instance.extend(Capybara::RSpecMatchers)

        session.driver.headers = {"Host" => resource.uri.host}

        address, port = server.forward_port(resource.uri.port)
        Capybara.app_host = "http://#{address}:#{port}"
      end

      Capybara::Session::DSL_METHODS.each do |method|
        define_method method do |*args, &block|
          page.send method, *args, &block
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
infrataster-0.3.2 lib/infrataster/contexts/capybara_context.rb
infrataster-0.3.1 lib/infrataster/contexts/capybara_context.rb
infrataster-0.3.0 lib/infrataster/contexts/capybara_context.rb
infrataster-0.2.6 lib/infrataster/contexts/capybara_context.rb
infrataster-0.2.5 lib/infrataster/contexts/capybara_context.rb
infrataster-0.2.4 lib/infrataster/contexts/capybara_context.rb
infrataster-0.2.3 lib/infrataster/contexts/capybara_context.rb
infrataster-0.2.2 lib/infrataster/contexts/capybara_context.rb
infrataster-0.2.1 lib/infrataster/contexts/capybara_context.rb
infrataster-0.2.0 lib/infrataster/contexts/capybara_context.rb
infrataster-0.2.0.beta1 lib/infrataster/contexts/capybara_context.rb
infrataster-0.1.13 lib/infrataster/contexts/capybara_context.rb
infrataster-0.1.12 lib/infrataster/contexts/capybara_context.rb
infrataster-0.1.11 lib/infrataster/contexts/capybara_context.rb
infrataster-0.1.10 lib/infrataster/contexts/capybara_context.rb
infrataster-0.1.9 lib/infrataster/contexts/capybara_context.rb
infrataster-0.1.8 lib/infrataster/contexts/capybara_context.rb