Functional test and flash with an error


#1

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:inclean_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:intest_create’
    test/functional/admin/user_controller_test.rb:40:in
    assert_difference' test/functional/admin/user_controller_test.rb:40:intest_create’]:
    expected tag, but no tag found matching {:content=>“User James Apps was
    successfully created.”, :attributes=>{:id=>“notice”}, :tag=>“div”} in:
    “\n<html
    xmlns=“http://www.w3.org/1999/xhtml”>\n\n<meta
    http-equiv=“Content-Type” content=“text/html; charset=ISO-8859-1”
    />\nView Users\n<link
    href=”/stylesheets/dissertation.css?1174589813" media=“screen”
    rel=“Stylesheet” type=“text/css” />\n\n\n\n<div
    id=“header”>\n\t<div id=“metaNav”>\n\t <ul id=“nav1”>\n\t
  • User
  • \n\t
  • Sign Out
  • \n\t
  • Date
  • \n\t \n\t \n\t

    View Users

    \n \n
    \n\n
    \n\n\t\t\t
    \n\t\t\t\t\t
    \n\t

    View Users

    \n

    From here you can view the users in the system.

    \n\n\t\n\t\t\n\t\t\n\t\t\n\t\n\t\n \n \n \n\n \n \n \n\n \n \n \n\n \n \n \n\n
    NameEditDelete
    James AppsEdit
    \n
    Mark FaulknerEdit
    \n
    Andy JardineEdit
    \n
    James AppsEdit
    \n
    \n\n

    Add a User

    \n
    \n\t\n\n\t\n\t\t\t

    News

    \t\n\t\t\t

    Test, Test, Test, Test

    \n\t\n\t\t\t\n\t
    \n\t

    Projects

    \n\t\t
      \n\t\t
    • \n\t\t
    • \n\t\t
    • \n\t\t
    \n\t
    \n\t\t\n
    \n\t \n\t
    \n\n\n\n". 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-transitional.dtd”>
    2.
    3.
    4.
    5. <%= @page_title || ‘Dissertation’ -%>
    6. <%= stylesheet_link_tag “dissertation” %>
    7.
    8.
    9.
    10.


    11.

    12.
    17.

    18. <%= “

    #{@page_title}

    ” if @page_title -%>
    19.

    20.
    25.

    26.

    27.

    28.

    29. <% if flash[:notice] -%>
    30.

    31. <% flash[:notice] -%>
    32.

    33. <% end -%>
    34. <%= yield -%>
    35.
    36.

    37.
    38.

    39.

    40.

    News


    41.

    Test, Test, Test, Test


    42.

    43.
    44.

    45.

    Projects


    46.

      47.

    • 48.

    • 49.

    • 50.

    51.

    52.
    53.

    54.
    55.

    56.

    57.

    58.
    59.

    #2

    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.