mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Added current_host method
This commit is contained in:
parent
1c22bbd33a
commit
6f2e8c547b
3 changed files with 20 additions and 2 deletions
|
@ -27,8 +27,8 @@ module Capybara
|
|||
#
|
||||
class Session
|
||||
DSL_METHODS = [
|
||||
:all, :first, :attach_file, :body, :html, :text, :check, :choose, :click_link_or_button, :click_button, :click_link, :current_url, :drag, :evaluate_script,
|
||||
:field_labeled, :fill_in, :find, :find_button, :find_by_id, :find_field, :find_link, :has_content?, :has_css?,
|
||||
:all, :first, :attach_file, :body, :html, :text, :check, :choose, :click_link_or_button, :click_button, :click_link, :current_url, :current_host,
|
||||
:drag, :evaluate_script, :field_labeled, :fill_in, :find, :find_button, :find_by_id, :find_field, :find_link, :has_content?, :has_css?,
|
||||
:has_no_content?, :has_no_css?, :has_no_xpath?, :has_xpath?, :locate, :save_page, :save_and_open_page, :select, :source, :uncheck,
|
||||
:visit, :wait_until, :within, :within_fieldset, :within_table, :within_frame, :within_window, :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?,
|
||||
|
@ -107,6 +107,14 @@ module Capybara
|
|||
URI.parse(current_url).path
|
||||
end
|
||||
|
||||
##
|
||||
#
|
||||
# @return [String] Host of the current page
|
||||
#
|
||||
def current_host
|
||||
URI.parse(current_url).host
|
||||
end
|
||||
|
||||
##
|
||||
#
|
||||
# @return [String] Fully qualified URL of the current page
|
||||
|
|
|
@ -81,6 +81,7 @@ shared_examples_for "session" do
|
|||
it_should_behave_like "unselect"
|
||||
it_should_behave_like "within"
|
||||
it_should_behave_like "current_url"
|
||||
it_should_behave_like "current_host"
|
||||
|
||||
it "should encode complex field names, like array[][value]" do
|
||||
@session.visit('/form')
|
||||
|
|
9
lib/capybara/spec/session/current_host_spec.rb
Normal file
9
lib/capybara/spec/session/current_host_spec.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
shared_examples_for "current_host" do
|
||||
describe '#current_host' do
|
||||
it "is affected by visiting a page directly" do
|
||||
@session.visit('http://capybara-testapp.heroku.com/')
|
||||
@session.body.should include('Hello world')
|
||||
@session.current_host.should == 'capybara-testapp.heroku.com'
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue