Class: Capybara::Mechanize::Driver

Inherits:
Driver::Base
  • Object
show all
Defined in:
lib/capybara/mechanize/driver.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Driver

Returns a new instance of Driver.



4
5
6
7
8
9
# File 'lib/capybara/mechanize/driver.rb', line 4

def initialize(app, options={})
  @app         = app
  @options     = options
  @rack_server = Capybara::Server.new(@app)
  @rack_server.boot if Capybara.run_server
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



2
3
4
# File 'lib/capybara/mechanize/driver.rb', line 2

def app
  @app
end

#optionsObject (readonly)

Returns the value of attribute options.



2
3
4
# File 'lib/capybara/mechanize/driver.rb', line 2

def options
  @options
end

#rack_serverObject (readonly)

Returns the value of attribute rack_server.



2
3
4
# File 'lib/capybara/mechanize/driver.rb', line 2

def rack_server
  @rack_server
end

Instance Method Details

#browserObject



11
12
13
# File 'lib/capybara/mechanize/driver.rb', line 11

def browser
  @browser ||= Capybara::Mechanize::Browser.new
end

#current_urlObject



33
34
35
# File 'lib/capybara/mechanize/driver.rb', line 33

def current_url
  browser.url
end

#delete(url) ⇒ Object



27
# File 'lib/capybara/mechanize/driver.rb', line 27

def delete(url); follow(:delete, url); end

#domObject



54
55
56
# File 'lib/capybara/mechanize/driver.rb', line 54

def dom
  browser.dom
end

#find(selector) ⇒ Object



45
46
47
# File 'lib/capybara/mechanize/driver.rb', line 45

def find(selector)
  dom.search(selector).map { |node| Capybara::Mechanize::Node.new(self, node) }
end

#follow(_method, path) ⇒ Object



19
20
21
22
# File 'lib/capybara/mechanize/driver.rb', line 19

def follow(_method, path)
  return if is_fragment?(path)
  browser.send(_method, make_absolute_url(path))
end

#get(url) ⇒ Object



24
# File 'lib/capybara/mechanize/driver.rb', line 24

def get(url);    follow(:get, url);    end

#post(url) ⇒ Object



25
# File 'lib/capybara/mechanize/driver.rb', line 25

def post(url);   follow(:post, url);   end

#put(url) ⇒ Object



26
# File 'lib/capybara/mechanize/driver.rb', line 26

def put(url);    follow(:put, url);    end

#reset!Object



58
59
60
# File 'lib/capybara/mechanize/driver.rb', line 58

def reset!
  @browser = nil
end

#response_headersObject



37
38
39
# File 'lib/capybara/mechanize/driver.rb', line 37

def response_headers
  browser.headers
end

#sourceObject Also known as: body



49
50
51
# File 'lib/capybara/mechanize/driver.rb', line 49

def source
  browser.source
end

#status_codeObject



41
42
43
# File 'lib/capybara/mechanize/driver.rb', line 41

def status_code
  browser.status_code
end

#submit(form) ⇒ Object



29
30
31
# File 'lib/capybara/mechanize/driver.rb', line 29

def submit(form)
  browser.submit(form)
end

#visit(path) ⇒ Object



15
16
17
# File 'lib/capybara/mechanize/driver.rb', line 15

def visit(path)
  browser.get(url(path))
end