diff --git a/History.txt b/History.txt index 22fb15f..1197882 100644 --- a/History.txt +++ b/History.txt @@ -68,6 +68,8 @@ * Bug fixes + * Fixed bug where Scope was creating a new DOM rather than re-using the existing DOM. + [#105] (Zach Dennis) * Support Rails > v2.2 by using ActionController::RequestParser for param parsing [#107] (Marcello Nuccio) * Raise a Webrat::NotFoundError if the scope passed to #within doesn't exist [#90] diff --git a/lib/webrat/core/scope.rb b/lib/webrat/core/scope.rb index 2f0becb..a02a67b 100644 --- a/lib/webrat/core/scope.rb +++ b/lib/webrat/core/scope.rb @@ -31,7 +31,7 @@ module Webrat @session = session instance_eval(&block) if block_given? - if @selector && scoped_element.nil? + if @selector && scoped_dom.nil? raise Webrat::NotFoundError.new("The scope was not found on the page: #{@selector.inspect}") end end @@ -316,17 +316,7 @@ module Webrat return dom end - def scoped_dom #:nodoc: - source = Webrat::XML.to_html(scoped_element) - - if @session.xml_content_type? - Webrat::XML.xml_document(source) - else - Webrat::XML.html_document(source) - end - end - - def scoped_element + def scoped_dom Webrat::XML.css_at(@scope.dom, @selector) end diff --git a/spec/public/within_spec.rb b/spec/public/within_spec.rb index 90db20e..8b98d01 100644 --- a/spec/public/within_spec.rb +++ b/spec/public/within_spec.rb @@ -59,7 +59,6 @@ describe "within" do end it "should work when the scope is inside the form" do - pending "needs bug fix" do with_html <<-HTML
@@ -77,6 +76,51 @@ describe "within" do end submit_form "form2" + end + + it "should work when the form submission occurs inside a scope" do + with_html <<-HTML + + +
+ + + + +
+ + + HTML + + webrat_session.should_receive(:get).with("/form2", "email" => "test@example.com") + within "form[@action='/form2']" do + fill_in "Email", :with => "test@example.com" + click_button "Add" + end + end + + it "should work when there are multiple forms with the same label text" do + with_html <<-HTML + + +
+
+ + +
+
+ + +
+
+ + + HTML + + webrat_session.should_receive(:get).with("/form2", "email2" => "test@example.com") + within "form[@action='/form2']" do + fill_in "Email", :with => "test@example.com" + click_button "Add" end end