Class: Parklife::Browser

Inherits:
Object
  • Object
show all
Defined in:
lib/parklife/browser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, base) ⇒ Browser

Returns a new instance of Browser.



10
11
12
13
14
15
16
17
18
19
# File 'lib/parklife/browser.rb', line 10

def initialize(app, base)
  @app = app
  @base = base
  @session = Rack::Test::Session.new(app)
  @env = {
    'HTTP_HOST' => Utils.host_with_port(base),
    'HTTPS' => base.scheme == 'https' ? 'on' : 'off',
    script_name: base.path.chomp('/'),
  }
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



8
9
10
# File 'lib/parklife/browser.rb', line 8

def app
  @app
end

#baseObject (readonly)

Returns the value of attribute base.



8
9
10
# File 'lib/parklife/browser.rb', line 8

def base
  @base
end

#envObject (readonly)

Returns the value of attribute env.



8
9
10
# File 'lib/parklife/browser.rb', line 8

def env
  @env
end

#sessionObject (readonly)

Returns the value of attribute session.



8
9
10
# File 'lib/parklife/browser.rb', line 8

def session
  @session
end

Instance Method Details

#get(path, headers: nil) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/parklife/browser.rb', line 21

def get(path, headers: nil)
  session.get(
    path,
    nil,
    headers ? headers.merge(env) : env
  )
end

#uri_for(path) ⇒ Object



29
30
31
# File 'lib/parklife/browser.rb', line 29

def uri_for(path)
  base.dup.tap { |uri| uri.path = path }
end