Removing Page class (functionality is now in Session and Scope)
This commit is contained in:
parent
1d39fe71d4
commit
a610d1f9e0
@ -1,32 +0,0 @@
|
|||||||
require "rubygems"
|
|
||||||
require "hpricot"
|
|
||||||
require "forwardable"
|
|
||||||
require "English"
|
|
||||||
|
|
||||||
module Webrat
|
|
||||||
class Page
|
|
||||||
extend Forwardable
|
|
||||||
include Logging
|
|
||||||
include Flunk
|
|
||||||
|
|
||||||
attr_reader :url
|
|
||||||
attr_reader :data
|
|
||||||
attr_reader :http_method
|
|
||||||
|
|
||||||
def initialize(session, url = nil, method = :get, data = {})
|
|
||||||
@session = session
|
|
||||||
@url = url
|
|
||||||
@http_method = method
|
|
||||||
@data = data
|
|
||||||
|
|
||||||
session.request_page(@url, @http_method, @data) if @url
|
|
||||||
|
|
||||||
@scope = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
def scope
|
|
||||||
@scope ||= Scope.new(@session, @session.response_body)
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
@ -1,3 +1,5 @@
|
|||||||
|
require "hpricot"
|
||||||
|
|
||||||
module Webrat
|
module Webrat
|
||||||
class Scope
|
class Scope
|
||||||
include Logging
|
include Logging
|
||||||
|
@ -1,8 +1,16 @@
|
|||||||
|
require "forwardable"
|
||||||
|
|
||||||
module Webrat
|
module Webrat
|
||||||
class Session
|
class Session
|
||||||
extend Forwardable
|
extend Forwardable
|
||||||
include Logging
|
include Logging
|
||||||
|
|
||||||
|
def initialize
|
||||||
|
@current_url = nil
|
||||||
|
@http_method = :get
|
||||||
|
@data = {}
|
||||||
|
end
|
||||||
|
|
||||||
# Saves the page out to RAILS_ROOT/tmp/ and opens it in the default
|
# Saves the page out to RAILS_ROOT/tmp/ and opens it in the default
|
||||||
# web browser if on OS X. Useful for debugging.
|
# web browser if on OS X. Useful for debugging.
|
||||||
#
|
#
|
||||||
@ -21,7 +29,7 @@ module Webrat
|
|||||||
end
|
end
|
||||||
|
|
||||||
def current_url
|
def current_url
|
||||||
@current_page.url
|
@current_url
|
||||||
end
|
end
|
||||||
|
|
||||||
def doc_root
|
def doc_root
|
||||||
@ -48,12 +56,8 @@ module Webrat
|
|||||||
response_body =~ /Exception caught/
|
response_body =~ /Exception caught/
|
||||||
end
|
end
|
||||||
|
|
||||||
def current_page
|
|
||||||
@current_page ||= Page.new(self)
|
|
||||||
end
|
|
||||||
|
|
||||||
def current_scope
|
def current_scope
|
||||||
current_page.scope
|
@scope ||= Scope.new(self, response_body)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Reloads the last page requested. Note that this will resubmit forms
|
# Reloads the last page requested. Note that this will resubmit forms
|
||||||
@ -62,7 +66,7 @@ module Webrat
|
|||||||
# Example:
|
# Example:
|
||||||
# reloads
|
# reloads
|
||||||
def reloads
|
def reloads
|
||||||
request_page(@current_page.url, current_page.http_method, current_page.data)
|
request_page(@current_url, @http_method, @data)
|
||||||
end
|
end
|
||||||
|
|
||||||
alias_method :reload, :reloads
|
alias_method :reload, :reloads
|
||||||
@ -84,8 +88,12 @@ module Webrat
|
|||||||
yield Scope.new(self, response_body, selector)
|
yield Scope.new(self, response_body, selector)
|
||||||
end
|
end
|
||||||
|
|
||||||
def visits(*args)
|
def visits(url = nil, http_method = :get, data = {})
|
||||||
@current_page = Page.new(self, *args)
|
@current_url = url
|
||||||
|
@http_method = http_method
|
||||||
|
@data = data
|
||||||
|
|
||||||
|
request_page(url, http_method, data)
|
||||||
end
|
end
|
||||||
|
|
||||||
alias_method :visit, :visits
|
alias_method :visit, :visits
|
||||||
|
@ -2,6 +2,7 @@ module Webrat
|
|||||||
class RailsSession < Session
|
class RailsSession < Session
|
||||||
|
|
||||||
def initialize(integration_session)
|
def initialize(integration_session)
|
||||||
|
super
|
||||||
@integration_session = integration_session
|
@integration_session = integration_session
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ module Webrat
|
|||||||
class SeleniumSession < Session
|
class SeleniumSession < Session
|
||||||
|
|
||||||
def initialize(selenium_driver)
|
def initialize(selenium_driver)
|
||||||
|
super
|
||||||
@selenium = selenium_driver
|
@selenium = selenium_driver
|
||||||
define_location_strategies
|
define_location_strategies
|
||||||
end
|
end
|
||||||
|
@ -213,7 +213,7 @@ describe "clicks_link" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "should follow relative links" do
|
it "should follow relative links" do
|
||||||
@session.current_page.stub!(:url).and_return("/page")
|
@session.stub!(:current_url).and_return("/page")
|
||||||
@session.response_body = <<-EOS
|
@session.response_body = <<-EOS
|
||||||
<a href="sub">Jump to sub page</a>
|
<a href="sub">Jump to sub page</a>
|
||||||
EOS
|
EOS
|
||||||
@ -230,7 +230,7 @@ describe "clicks_link" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "should follow query parameters" do
|
it "should follow query parameters" do
|
||||||
@session.current_page.stub!(:url).and_return("/page")
|
@session.stub!(:current_url).and_return("/page")
|
||||||
@session.response_body = <<-EOS
|
@session.response_body = <<-EOS
|
||||||
<a href="?foo=bar">Jump to foo bar</a>
|
<a href="?foo=bar">Jump to foo bar</a>
|
||||||
EOS
|
EOS
|
||||||
|
Loading…
Reference in New Issue
Block a user