Class: Infrataster::Contexts::CapybaraContext

Inherits:
BaseContext
  • Object
show all
Defined in:
lib/infrataster/contexts/capybara_context.rb

Constant Summary collapse

CAPYBARA_DRIVER_NAME =
:infrataster_driver

Instance Attribute Summary

Attributes inherited from BaseContext

#resource, #server

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseContext

#current_server

Constructor Details

#initialize(*args) ⇒ CapybaraContext

Returns a new instance of CapybaraContext.



23
24
25
# File 'lib/infrataster/contexts/capybara_context.rb', line 23

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

Class Method Details

.prepare_sessionObject



14
15
16
17
18
19
20
21
# File 'lib/infrataster/contexts/capybara_context.rb', line 14

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

.sessionObject



10
11
12
# File 'lib/infrataster/contexts/capybara_context.rb', line 10

def self.session
  @session ||= prepare_session
end

Instance Method Details

#before_each(example) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/infrataster/contexts/capybara_context.rb', line 35

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

#pageObject



31
32
33
# File 'lib/infrataster/contexts/capybara_context.rb', line 31

def page
  session
end

#sessionObject



27
28
29
# File 'lib/infrataster/contexts/capybara_context.rb', line 27

def session
  self.class.session
end