Raise a Webrat::NotFoundError if the scope passed to #within doesn't exist [#90 state:resolved]

This commit is contained in:
Bryan Helmkamp 2009-01-17 13:27:32 -05:00
parent 8b652bd036
commit 3e3d8e3659
3 changed files with 22 additions and 1 deletions

View File

@ -65,6 +65,7 @@
* Bug fixes
* Raise a Webrat::NotFoundError if the scope passed to #within doesn't exist [#90]
* Match against link _text_ which decodes character references.
Useful for multibyte languages like Japanese (moronatural@gmail.com)
* Fix params hash generation for Mechanize when Merb is not defined [#62]

View File

@ -30,6 +30,10 @@ module Webrat
def initialize(session, &block) #:nodoc:
@session = session
instance_eval(&block) if block_given?
if @selector && scoped_element.nil?
raise Webrat::NotFoundError.new("The scope was not found on the page: #{@selector.inspect}")
end
end
# Verifies an input field or textarea exists on the current page, and stores a value for
@ -291,7 +295,7 @@ module Webrat
end
def scoped_dom #:nodoc:
source = Webrat::XML.to_html(Webrat::XML.css_search(@scope.dom, @selector).first)
source = Webrat::XML.to_html(scoped_element)
if @session.xml_content_type?
Webrat::XML.xml_document(source)
@ -300,6 +304,10 @@ module Webrat
end
end
def scoped_element
Webrat::XML.css_at(@scope.dom, @selector)
end
def locate_field(field_locator, *field_types) #:nodoc:
if field_locator.is_a?(Field)
field_locator

View File

@ -97,4 +97,16 @@ describe "within" do
}.should raise_error(Webrat::NotFoundError)
end
end
it "should raise a Webrat::NotFounderror error when the scope doesn't exist" do
with_html <<-HTML
<html>
</html>
HTML
lambda {
within "#form2" do
end
}.should raise_error(Webrat::NotFoundError)
end
end