diff --git a/lib/webrat/core/page.rb b/lib/webrat/core/page.rb deleted file mode 100644 index 9f2683e..0000000 --- a/lib/webrat/core/page.rb +++ /dev/null @@ -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 \ No newline at end of file diff --git a/lib/webrat/core/scope.rb b/lib/webrat/core/scope.rb index c0fec28..d1b8cd0 100644 --- a/lib/webrat/core/scope.rb +++ b/lib/webrat/core/scope.rb @@ -1,3 +1,5 @@ +require "hpricot" + module Webrat class Scope include Logging diff --git a/lib/webrat/core/session.rb b/lib/webrat/core/session.rb index 6e02440..c127915 100644 --- a/lib/webrat/core/session.rb +++ b/lib/webrat/core/session.rb @@ -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 diff --git a/lib/webrat/rails/rails_session.rb b/lib/webrat/rails/rails_session.rb index 0396ba6..07f8e67 100644 --- a/lib/webrat/rails/rails_session.rb +++ b/lib/webrat/rails/rails_session.rb @@ -2,6 +2,7 @@ module Webrat class RailsSession < Session def initialize(integration_session) + super @integration_session = integration_session end diff --git a/lib/webrat/selenium/selenium_session.rb b/lib/webrat/selenium/selenium_session.rb index 87d9745..e4b9ab0 100644 --- a/lib/webrat/selenium/selenium_session.rb +++ b/lib/webrat/selenium/selenium_session.rb @@ -2,6 +2,7 @@ module Webrat class SeleniumSession < Session def initialize(selenium_driver) + super @selenium = selenium_driver define_location_strategies end diff --git a/spec/api/clicks_link_spec.rb b/spec/api/clicks_link_spec.rb index a29e1c9..c77d019 100644 --- a/spec/api/clicks_link_spec.rb +++ b/spec/api/clicks_link_spec.rb @@ -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 Jump to sub page 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 Jump to foo bar EOS