From 3f0952d9df1db6e01ca608f30ba743f3e7d54dcc Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Sun, 10 Sep 2006 02:51:38 +0000 Subject: Fix assert_tag so that :content => "foo" does not match substrings, but only exact strings. Use :content => /foo/ to match substrings. closes #2799 git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5086 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/CHANGELOG | 2 ++ .../lib/action_controller/vendor/html-scanner/html/node.rb | 2 +- actionpack/test/controller/test_test.rb | 11 +++++++++-- 3 files changed, 12 insertions(+), 3 deletions(-) (limited to 'actionpack') diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 1fb95347d2..e4d011581e 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Fix assert_tag so that :content => "foo" does not match substrings, but only exact strings. Use :content => /foo/ to match substrings. #2799 [Eric Hodel] + * Add descriptive messages to the exceptions thrown by cgi_methods. #6091, #6103 [Nicholas Seckar, Bob Silva] * Update JavaScriptGenerator#show/hide/toggle/remove to new Prototype syntax for multiple ids, #6068 [petermichaux@gmail.com] diff --git a/actionpack/lib/action_controller/vendor/html-scanner/html/node.rb b/actionpack/lib/action_controller/vendor/html-scanner/html/node.rb index 7b53af9591..a6490b1f3b 100644 --- a/actionpack/lib/action_controller/vendor/html-scanner/html/node.rb +++ b/actionpack/lib/action_controller/vendor/html-scanner/html/node.rb @@ -239,7 +239,7 @@ module HTML #:nodoc: def match(conditions) case conditions when String - @content.index(conditions) + @content == conditions when Regexp @content =~ conditions when Hash diff --git a/actionpack/test/controller/test_test.rb b/actionpack/test/controller/test_test.rb index c9a30f9332..95c75bb744 100644 --- a/actionpack/test/controller/test_test.rb +++ b/actionpack/test/controller/test_test.rb @@ -253,9 +253,9 @@ HTML process :test_html_output # the output contains the string "Name" - assert_tag :content => "Name" + assert_tag :content => /Name/ # the output does not contain the string "test" - assert_no_tag :content => "test" + assert_no_tag :content => /test/ end def test_assert_tag_multiple @@ -301,6 +301,13 @@ HTML :attributes => { :name => /^my$/, :type => 'text' } end + def test_assert_tag_content_matching + @response.body = "

hello world

" + assert_tag :tag => "p", :content => "hello world" + assert_tag :tag => "p", :content => /hello/ + assert_no_tag :tag => "p", :content => "hello" + end + def test_assert_generates assert_generates 'controller/action/5', :controller => 'controller', :action => 'action', :id => '5' end -- cgit v1.2.3