Merge remote branch 'paulelliott/current_path'
This commit is contained in:
commit
8152b5505e
|
@ -152,6 +152,10 @@ You can use the <tt>visit</tt> method to navigate to other pages:
|
||||||
The visit method only takes a single parameter, the request method is *always*
|
The visit method only takes a single parameter, the request method is *always*
|
||||||
GET.
|
GET.
|
||||||
|
|
||||||
|
You can get the current path of the browsing session for test assertions:
|
||||||
|
|
||||||
|
current_path.should == post_comments_path(post)
|
||||||
|
|
||||||
=== Clicking links and buttons
|
=== Clicking links and buttons
|
||||||
|
|
||||||
You can interact with the webapp by following links and buttons. Capybara
|
You can interact with the webapp by following links and buttons. Capybara
|
||||||
|
|
|
@ -3,6 +3,10 @@ class Capybara::Driver::Base
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def current_path
|
||||||
|
URI.parse(current_url).path
|
||||||
|
end
|
||||||
|
|
||||||
def visit(path)
|
def visit(path)
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
end
|
end
|
||||||
|
|
|
@ -192,7 +192,7 @@ class Capybara::Driver::RackTest < Capybara::Driver::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def process(method, path, attributes = {})
|
def process(method, path, attributes = {})
|
||||||
return if path.gsub(/^#{current_path}/, '') =~ /^#/
|
return if path.gsub(/^#{request_path}/, '') =~ /^#/
|
||||||
send(method, path, attributes, env)
|
send(method, path, attributes, env)
|
||||||
follow_redirects!
|
follow_redirects!
|
||||||
end
|
end
|
||||||
|
@ -210,7 +210,7 @@ class Capybara::Driver::RackTest < Capybara::Driver::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def submit(method, path, attributes)
|
def submit(method, path, attributes)
|
||||||
path = current_path if not path or path.empty?
|
path = request_path if not path or path.empty?
|
||||||
send(method, path, attributes, env)
|
send(method, path, attributes, env)
|
||||||
follow_redirects!
|
follow_redirects!
|
||||||
end
|
end
|
||||||
|
@ -248,7 +248,7 @@ private
|
||||||
Rack::MockSession.new(app, Capybara.default_host || "www.example.com")
|
Rack::MockSession.new(app, Capybara.default_host || "www.example.com")
|
||||||
end
|
end
|
||||||
|
|
||||||
def current_path
|
def request_path
|
||||||
request.path rescue ""
|
request.path rescue ""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ module Capybara
|
||||||
:has_no_content?, :has_no_css?, :has_no_xpath?, :has_xpath?, :locate, :save_and_open_page, :select, :source, :uncheck,
|
:has_no_content?, :has_no_css?, :has_no_xpath?, :has_xpath?, :locate, :save_and_open_page, :select, :source, :uncheck,
|
||||||
:visit, :wait_until, :within, :within_fieldset, :within_table, :within_frame, :has_link?, :has_no_link?, :has_button?,
|
:visit, :wait_until, :within, :within_fieldset, :within_table, :within_frame, :has_link?, :has_no_link?, :has_button?,
|
||||||
:has_no_button?, :has_field?, :has_no_field?, :has_checked_field?, :has_unchecked_field?, :has_no_table?, :has_table?,
|
:has_no_button?, :has_field?, :has_no_field?, :has_checked_field?, :has_unchecked_field?, :has_no_table?, :has_table?,
|
||||||
:unselect, :has_select?, :has_no_select?
|
:unselect, :has_select?, :has_no_select?, :current_path
|
||||||
]
|
]
|
||||||
|
|
||||||
attr_reader :mode, :app
|
attr_reader :mode, :app
|
||||||
|
@ -34,6 +34,7 @@ module Capybara
|
||||||
|
|
||||||
def_delegator :driver, :cleanup!
|
def_delegator :driver, :cleanup!
|
||||||
def_delegator :driver, :current_url
|
def_delegator :driver, :current_url
|
||||||
|
def_delegator :driver, :current_path
|
||||||
def_delegator :driver, :response_headers
|
def_delegator :driver, :response_headers
|
||||||
def_delegator :driver, :status_code
|
def_delegator :driver, :status_code
|
||||||
def_delegator :driver, :visit
|
def_delegator :driver, :visit
|
||||||
|
|
|
@ -18,6 +18,11 @@ shared_examples_for 'driver' do
|
||||||
@driver.visit('/foo')
|
@driver.visit('/foo')
|
||||||
@driver.current_url.should include('/foo')
|
@driver.current_url.should include('/foo')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should show the correct location' do
|
||||||
|
@driver.visit('/foo')
|
||||||
|
@driver.current_path.should == '/foo'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#body' do
|
describe '#body' do
|
||||||
|
|
Loading…
Reference in New Issue