Forum: Ruby on Rails Functional test and flash with an error

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Solidariti (Guest)
on 2007-03-22 21:57
I'm getting this error thats moaning about expected tag, but no tag
found matching {:content=>"User James Apps was successfully created.",
:attributes=>{:id=>"notice"}, :tag=>"div"} in the file application.rb.

I tried using a regular expression - /#{user.first_name}/ , but that
wouldn't work either

user_controller_test.rb

 1) Failure:
test_create(Admin::UserControllerTest)
    [/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_controller/assertions/tag_assertions.rb:102:in
`assert_tag'
     /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_controller/assertions/tag_assertions.rb:99:in
`clean_backtrace'
     /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_controller/assertions/tag_assertions.rb:99:in
`assert_tag'
     test/functional/admin/user_controller_test.rb:49:in `test_create'
     test/functional/admin/user_controller_test.rb:40:in
`assert_difference'
     test/functional/admin/user_controller_test.rb:40:in `test_create']:
expected tag, but no tag found matching {:content=>"User James Apps was
successfully created.", :attributes=>{:id=>"notice"}, :tag=>"div"} in:
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitiona...
xmlns=\"http://www.w3.org/1999/xhtml\">\n<head>\n<meta...
http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\"
/>\n<title>View Users</title>\n<link
href=\"/stylesheets/dissertation.css?1174589813\" media=\"screen\"
rel=\"Stylesheet\" type=\"text/css\" />\n</head>\n\n<body>\n<div
id=\"header\">\n\t<div id=\"metaNav\">\n\t  <ul id=\"nav1\">\n\t
<li><a href=\"#\">User</a></li>\n\t   <li><a href=\"#\">Sign
Out</a></li>\n\t   <li><a href=\"#\">Date</a></li>\n\t  </ul>\n\t
</div>\n\t<h1>View Users</h1> <div id=\"mainNav\">\n  <ul id=\"nav2\">\n
<li><a href=\"#\">Projects</a></li>\n   <li><a
href=\"#\">Settings</a></li>\n   <li><a href=\"#\">Contacts</a></li>\n
</ul>\n </div>\n</div>\n<div id=\"content\">\n<div
id=\"right\">\n\t\t\t<div id=\"notice\">\n\t\t\t\t\t</div>\n\t<h1>View
Users</h1>\n<p>From here you can view the users in the
system.</p>\n<table>\n\t<tr>\n\t\t<th>Name</th>\n\t\t<th>Edit</th>\n\t\t<th>Delete</th>\n\t</tr>\n\t<tr>\n
<td><a href=\"/admin/user/show/1\">James Apps</a></td>\n <td><a
href=\"/admin/user/edit/1\">Edit</a></td>\n <td><form method=\"post\"
action=\"/admin/user/destroy/1\" class=\"button-to\"><div><input
onclick=\"return confirm('Are you sure you want to delete user James
Apps?');\" type=\"submit\" value=\"Delete\" /></div></form>\n
</td>\n</tr><tr>\n <td><a href=\"/admin/user/show/2\">Mark
Faulkner</a></td>\n <td><a href=\"/admin/user/edit/2\">Edit</a></td>\n
<td><form method=\"post\" action=\"/admin/user/destroy/2\"
class=\"button-to\"><div><input onclick=\"return confirm('Are you sure
you want to delete user Mark Faulkner?');\" type=\"submit\"
value=\"Delete\" /></div></form>\n </td>\n</tr><tr>\n <td><a
href=\"/admin/user/show/3\">Andy Jardine</a></td>\n <td><a
href=\"/admin/user/edit/3\">Edit</a></td>\n <td><form method=\"post\"
action=\"/admin/user/destroy/3\" class=\"button-to\"><div><input
onclick=\"return confirm('Are you sure you want to delete user Andy
Jardine?');\" type=\"submit\" value=\"Delete\" /></div></form>\n
</td>\n</tr><tr>\n <td><a href=\"/admin/user/show/53\">James
Apps</a></td>\n <td><a href=\"/admin/user/edit/53\">Edit</a></td>\n
<td><form method=\"post\" action=\"/admin/user/destroy/53\"
class=\"button-to\"><div><input onclick=\"return confirm('Are you sure
you want to delete user James Apps?');\" type=\"submit\"
value=\"Delete\" /></div></form>\n </td>\n</tr>\n</table>\n\n<p><a
href=\"/admin/user/new\">Add a User</a></p>\n</div>\n\t\n<div
id=\"left\">\n\t<div
class=\"box\">\n\t\t\t<h2>News</h2>\t\n\t\t\t<p>Test, Test, Test,
Test</p>\n\t</div>\n\t\t\t\n\t<div class=\"box\">\n\t
<h2>Projects</h2>\n\t\t<ul>\n\t\t <li></li>\n\t\t <li></li>\n\t\t
<li></li>\n\t\t</ul>\n\t</div>\n\t\t\n    <div class=\"box\">\n\t
\n\t</div>\n</div>\n</div>\n</body>\n</html>".
<nil> is not true.

user_controller.rb
   1. def create
   2.     # Created a user object rom the request parameters sent from
the form on the new page.
   3.     @user = User.new(params[:user])
   4.     if @user.save
   5.       # If user is valid then save and create a flash message then
redirect to a page that lists the users
   6.       flash[:notice] = "User #{@user.name} was successfully
created."
   7.       redirect_to :action => 'index'
   8.     else
   9.       # If user couldn't be saved (due to failing the validations)
then the new page is rendered again.
  10.       @page_title = 'Create new user'
  11.       render :action => 'new'
  12.     end
  13.   end

application.rb
   1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitiona...
   2. <html xmlns="http://www.w3.org/1999/xhtml">
   3. <head>
   4. <meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1" />
   5. <title><%= @page_title || 'Dissertation' -%></title>
   6. <%= stylesheet_link_tag "dissertation" %>
   7. </head>
   8.
   9. <body>
  10. <div id="header">
  11.   <div id="metaNav">
  12.     <ul id="nav1">
  13.      <li><a href="#">User</a></li>
  14.      <li><a href="#">Sign Out</a></li>
  15.      <li><a href="#">Date</a></li>
  16.     </ul>
  17.    </div>
  18.   <%= "<h1>#{@page_title}</h1>" if @page_title -%>
  19.  <div id="mainNav">
  20.   <ul id="nav2">
  21.    <li><a href="#">Projects</a></li>
  22.    <li><a href="#">Settings</a></li>
  23.    <li><a href="#">Contacts</a></li>
  24.   </ul>
  25.  </div>
  26. </div>
  27. <div id="content">
  28. <div id="right">
  29.   <% if flash[:notice] -%>
  30.     <div id="notice">
  31.       <% flash[:notice] -%>
  32.     </div>
  33.   <% end -%>
  34. <%= yield -%>
  35.
  36. </div>
  37.
  38. <div id="left">
  39.   <div class="box">
  40.       <h2>News</h2>
  41.       <p>Test, Test, Test, Test</p>
  42.   </div>
  43.
  44.   <div class="box">
  45.    <h2>Projects</h2>
  46.     <ul>
  47.      <li></li>
  48.      <li></li>
  49.      <li></li>
  50.     </ul>
  51.   </div>
  52.
  53.     <div class="box">
  54.
  55.   </div>
  56. </div>
  57. </div>
  58. </body>
  59. </html>
Andrew S. (Guest)
on 2007-03-23 14:07
(Received via mailing list)
On 22 Mar 2007, at 19:57, Solidariti wrote:
> I'm getting this error thats moaning about expected tag, but no tag
> found matching {:content=>"User James Apps was successfully created.",
> :attributes=>{:id=>"notice"}, :tag=>"div"} in the file application.rb.
>
> I tried using a regular expression - /#{user.first_name}/ , but that
> wouldn't work either

Please post the actual assert statement that is tripping up.  You've
given us everything but the test itself!

Regards,
Andy S.
This topic is locked and can not be replied to.