Make source a true alias of html, closes #871

This commit is contained in:
Jonas Nicklas 2012-11-20 14:22:19 +01:00
parent 00134e4773
commit ae7c56446d
9 changed files with 35 additions and 43 deletions

View File

@ -5,6 +5,11 @@
* Move the RackTest driver override with the `:respect_data_method` option
enabled from capybara/rspec to capybara/rails, so that it is enabled in
Rails projects that don't use RSpec. [Carlos Antonio da Silva]
* Source is now an alias for `body`. RackTest no longer returns modifications
to `body`. This basically codifies the behaviour which we've had for a while
anyway, and should have minimal impact for end users. It is important to
driver authors though. [Jonas Nicklas]
### Fixed
* Visiting relative URLs when `app_host` is set and no server is running works

View File

@ -11,10 +11,6 @@ class Capybara::Driver::Base
raise NotImplementedError
end
def source
raise NotImplementedError
end
def html
raise NotImplementedError
end

View File

@ -76,19 +76,15 @@ class Capybara::RackTest::Browser
@dom = nil
end
def html
dom.to_xml
end
def dom
@dom ||= Nokogiri::HTML(source)
@dom ||= Nokogiri::HTML(html)
end
def find(selector)
dom.xpath(selector).map { |node| Capybara::RackTest::Node.new(self, node) }
end
def source
def html
last_response.body
rescue Rack::Test::Error
""

View File

@ -70,10 +70,6 @@ class Capybara::RackTest::Driver < Capybara::Driver::Base
browser.html
end
def source
browser.source
end
def dom
browser.dom
end

View File

@ -34,10 +34,6 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
browser.navigate.to(path)
end
def source
browser.page_source
end
def html
browser.page_source
end

View File

@ -105,15 +105,8 @@ module Capybara
def html
driver.html
end
##
#
# @return [String] HTML source of the document, before being modified by JavaScript.
#
def source
driver.source
end
alias_method :body, :source
alias_method :body, :html
alias_method :source, :html
##
#

View File

@ -1,8 +1,5 @@
Capybara::SpecHelper.spec '#html' do
it "should return the unmodified page body" do
# html and body should be aliased, but we can't just check for
# method(:html) == method(:body) because these shared examples get run
# against the DSL, which uses forwarding methods. So we test behavior.
@session.visit('/')
@session.html.should include('Hello world!')
end
@ -13,3 +10,29 @@ Capybara::SpecHelper.spec '#html' do
@session.html.should_not include('This is text')
end
end
Capybara::SpecHelper.spec '#source' do
it "should return the unmodified page source" do
@session.visit('/')
@session.source.should include('Hello world!')
end
it "should return the current state of the page", :requires => [:js] do
@session.visit('/with_js')
@session.source.should include('I changed it')
@session.source.should_not include('This is text')
end
end
Capybara::SpecHelper.spec '#body' do
it "should return the unmodified page source" do
@session.visit('/')
@session.body.should include('Hello world!')
end
it "should return the current state of the page", :requires => [:js] do
@session.visit('/with_js')
@session.body.should include('I changed it')
@session.body.should_not include('This is text')
end
end

View File

@ -1,12 +0,0 @@
Capybara::SpecHelper.spec '#source' do
it "should return the unmodified page source" do
@session.visit('/')
@session.source.should include('Hello world!')
end
it "should return the original, unmodified source of the page", :requires => [:js, :source] do
@session.visit('/with_js')
@session.source.should include('This is text')
@session.source.should_not include('I changed it')
end
end

View File

@ -7,7 +7,6 @@ end
Capybara::SpecHelper.run_specs TestSessions::Selenium, "selenium", :skip => [
:response_headers,
:status_code,
:source,
:trigger
]