Skip to content

Commit

Permalink
Rename Driver#body to Driver#html
Browse files Browse the repository at this point in the history
For historical reasons, Session#html used to delegate to Driver#body,
(but Session#body & Session#source delegate to Driver#source). This
commit puts an end to this confusing state of affairs.

This change requires driver authors to update their drivers.
  • Loading branch information
joliss committed Sep 10, 2012
1 parent c77e27e commit 954fcc6
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 17 deletions.
2 changes: 2 additions & 0 deletions History.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
they are disabled. [Jonas Nicklas]
* Can no longer find elements by id via `find(:foo)`, use `find("#foo")` or
`find_by_id("foo")` instead. [Jonas Nicklas]
* Rename `Driver#body` to `Driver#html` (relevant only for driver authors) [Jo
Liss]

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion lib/capybara/driver/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def source
raise NotImplementedError
end

def body
def html
raise NotImplementedError
end

Expand Down
2 changes: 1 addition & 1 deletion lib/capybara/rack_test/browser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def reset_cache!
@dom = nil
end

def body
def html
dom.to_xml
end

Expand Down
4 changes: 2 additions & 2 deletions lib/capybara/rack_test/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ def find(selector)
browser.find(selector)
end

def body
browser.body
def html
browser.html
end

def source
Expand Down
2 changes: 1 addition & 1 deletion lib/capybara/selenium/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def source
browser.page_source
end

def body
def html
browser.page_source
end

Expand Down
4 changes: 2 additions & 2 deletions lib/capybara/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ def status_code

##
#
# @return [String] A snapshot of the HTML of the current document, as it looks right now (potentially modified by JavaScript).
# @return [String] A snapshot of the DOM of the current document, as it looks right now (potentially modified by JavaScript).
#
def html
driver.body
driver.html
end

##
Expand Down
20 changes: 10 additions & 10 deletions spec/rack_test_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,21 @@
@session.driver.options[:respect_data_method] = true
@session.visit "/with_html"
@session.click_link "A link with data-method"
@session.body.should include('The requested object was deleted')
@session.html.should include('The requested object was deleted')
end

it "should not use data-method if option is false" do
@session.driver.options[:respect_data_method] = false
@session.visit "/with_html"
@session.click_link "A link with data-method"
@session.body.should include('Not deleted')
@session.html.should include('Not deleted')
end

it "should use data-method if available even if it's capitalized" do
@session.driver.options[:respect_data_method] = true
@session.visit "/with_html"
@session.click_link "A link with capitalized data-method"
@session.body.should include('The requested object was deleted')
@session.html.should include('The requested object was deleted')
end

after do
Expand All @@ -57,7 +57,7 @@
it "should submit an empty form-data section if no file is submitted" do
@session.visit("/form")
@session.click_button("Upload Empty")
@session.body.should include('Successfully ignored empty file field.')
@session.html.should include('Successfully ignored empty file field.')
end
end
end
Expand All @@ -73,27 +73,27 @@
it 'should always set headers' do
@driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
@driver.visit('/get_header')
@driver.body.should include('foobar')
@driver.html.should include('foobar')
end

it 'should keep headers on link clicks' do
@driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
@driver.visit('/header_links')
@driver.find('.//a').first.click
@driver.body.should include('foobar')
@driver.html.should include('foobar')
end

it 'should keep headers on form submit' do
@driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
@driver.visit('/header_links')
@driver.find('.//input').first.click
@driver.body.should include('foobar')
@driver.html.should include('foobar')
end

it 'should keep headers on redirects' do
@driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
@driver.visit('/get_header_via_redirect')
@driver.body.should include('foobar')
@driver.html.should include('foobar')
end
end

Expand Down Expand Up @@ -123,7 +123,7 @@

it "should follow 5 redirects" do
@driver.visit("/redirect/5/times")
@driver.body.should include('redirection complete')
@driver.html.should include('redirection complete')
end

it "should not follow more than 6 redirects" do
Expand All @@ -140,7 +140,7 @@

it "should follow 21 redirects" do
@driver.visit("/redirect/21/times")
@driver.body.should include('redirection complete')
@driver.html.should include('redirection complete')
end

it "should not follow more than 21 redirects" do
Expand Down

0 comments on commit 954fcc6

Please sign in to comment.