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
|
||||
class Scope
|
||||
include Logging
|
||||
|
@ -1,8 +1,16 @@
|
||||
require "forwardable"
|
||||
|
||||
module Webrat
|
||||
class Session
|
||||
extend Forwardable
|
||||
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
|
||||
# web browser if on OS X. Useful for debugging.
|
||||
#
|
||||
@ -21,7 +29,7 @@ module Webrat
|
||||
end
|
||||
|
||||
def current_url
|
||||
@current_page.url
|
||||
@current_url
|
||||
end
|
||||
|
||||
def doc_root
|
||||
@ -48,12 +56,8 @@ module Webrat
|
||||
response_body =~ /Exception caught/
|
||||
end
|
||||
|
||||
def current_page
|
||||
@current_page ||= Page.new(self)
|
||||
end
|
||||
|
||||
def current_scope
|
||||
current_page.scope
|
||||
@scope ||= Scope.new(self, response_body)
|
||||
end
|
||||
|
||||
# Reloads the last page requested. Note that this will resubmit forms
|
||||
@ -62,7 +66,7 @@ module Webrat
|
||||
# Example:
|
||||
# reloads
|
||||
def reloads
|
||||
request_page(@current_page.url, current_page.http_method, current_page.data)
|
||||
request_page(@current_url, @http_method, @data)
|
||||
end
|
||||
|
||||
alias_method :reload, :reloads
|
||||
@ -84,8 +88,12 @@ module Webrat
|
||||
yield Scope.new(self, response_body, selector)
|
||||
end
|
||||
|
||||
def visits(*args)
|
||||
@current_page = Page.new(self, *args)
|
||||
def visits(url = nil, http_method = :get, data = {})
|
||||
@current_url = url
|
||||
@http_method = http_method
|
||||
@data = data
|
||||
|
||||
request_page(url, http_method, data)
|
||||
end
|
||||
|
||||
alias_method :visit, :visits
|
||||
|
@ -2,6 +2,7 @@ module Webrat
|
||||
class RailsSession < Session
|
||||
|
||||
def initialize(integration_session)
|
||||
super
|
||||
@integration_session = integration_session
|
||||
end
|
||||
|
||||
|
@ -2,6 +2,7 @@ module Webrat
|
||||
class SeleniumSession < Session
|
||||
|
||||
def initialize(selenium_driver)
|
||||
super
|
||||
@selenium = selenium_driver
|
||||
define_location_strategies
|
||||
end
|
||||
|
@ -213,7 +213,7 @@ describe "clicks_link" do
|
||||
end
|
||||
|
||||
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
|
||||
<a href="sub">Jump to sub page</a>
|
||||
EOS
|
||||
@ -230,7 +230,7 @@ describe "clicks_link" do
|
||||
end
|
||||
|
||||
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
|
||||
<a href="?foo=bar">Jump to foo bar</a>
|
||||
EOS
|
||||
|
Loading…
Reference in New Issue
Block a user