Fixed that assert_template_xpath_matches did not indicate when a path was not...

Fixed that assert_template_xpath_matches did not indicate when a path was not found #658 [Eric Hodel]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@665 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 5fc48bc5
*SVN*
* Fixed that assert_template_xpath_matches did not indicate when a path was not found #658 [Eric Hodel]
* Added TextHelper#auto_link, TextHelper#auto_link_urls, and TextHelper#auto_link_email_addresses to turn those elements into ahrefs
* Fixed that on validation errors, scaffold couldn't find template #654 [mindel]
......
......@@ -217,7 +217,14 @@ def assert_template_xpath_match(expression=nil, expected=nil, message=nil)
response = acquire_assertion_target
xml, matches = REXML::Document.new(response.body), []
xml.elements.each(expression) { |e| matches << e.text }
matches = matches.first if matches.length < 2
if matches.empty? then
msg = build_message(message, "<?> not found in document",
expression)
flunk(msg)
return
elsif matches.length < 2 then
matches = matches.first
end
msg = build_message(message, "<?> found <?>, not <?>", expression, matches, expected)
assert_block(msg) { matches == expected }
......
......@@ -7,4 +7,5 @@
require 'action_controller/test_process'
ActionController::Base.logger = nil
ActionController::Base.ignore_missing_templates = true
\ No newline at end of file
ActionController::Base.ignore_missing_templates = true
ActionController::Routing::Routes.reload
\ No newline at end of file
......@@ -337,6 +337,13 @@ def test_render_based_on_parameters
assert_equal "Mr. David", @response.body
end
def test_assert_template_xpath_match_no_matches
process :hello_xml_world
assert_raises Test::Unit::AssertionFailedError do
assert_template_xpath_match('/no/such/node/in/document')
end
end
def test_simple_one_element_xpath_match
process :hello_xml_world
assert_template_xpath_match('//title', "Hello World")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册