Module: CapybaraPageObject::InstanceMethods

Included in:
Page
Defined in:
lib/capybara-page-object/page.rb

Instance Method Summary collapse

Instance Method Details

#path(*args) ⇒ Object

Raises:



7
8
9
# File 'lib/capybara-page-object/page.rb', line 7

def path(*args)
  raise MissingPath, "You need to override #path in #{self.class}"
end

#root_pathObject



11
12
13
# File 'lib/capybara-page-object/page.rb', line 11

def root_path
  '/'
end

#visit_path(attr) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/capybara-page-object/page.rb', line 15

def visit_path(attr)
  target = root_path + path
  if attr.kind_of?(String)
    target += '/' + attr
  elsif attr.kind_of?(Integer)
    target += '/' + attr.to_s
  elsif attr.kind_of?(Hash)
    pairs = attr.map { |k, v| "#{k}=#{v}" }
    target += '?' + pairs.join('&') if pairs.any?
  elsif attr != nil
    raise ArgumentError, 'Expected a String, Integer or Hash'
  end
  source.visit target
end