Assert_select / assert_tag issue

Upgraded to RoR 2.0 on Mac OS X -
and cannot seem to get assert_select or the supposedly deprecated
assert_tag to work. - Asserts are fairly simple and so is the page being
tested - see below for HTML and different errors.

Any help is greatly appreciated!

thanks
Jim.

class UserControllerTest < Test::Unit::TestCase
def setup
@controller = UserController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
end

Make sure the registration page responds with the proper form.

Make sure the registration page responds with the proper form.

def test_registration_page
get :register
title = assigns(:title)
assert_equal “Register”, title

assert_response :success
assert_template "register"
# NONE OF THESE WORK....
assert_select "title", "Register"
assert_select "form"
assert_select "form[action=/user/register]"
assert_tag "form", :attributes => { :action => "/user/register",
                                    :method => "post" }

end
end

None of the 4 assert_* at the end work…
These are the errors I get as I rotate the asserts…

  1. Failure:
    test_registration_page(UserControllerTest)
    [/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/assertions/selector_assertions.rb:296:in
    assert_select' ./test/functional/user_controller_test.rb:24:intest_registration_page’]:
    Expected at least 1 element matching “title”, found 0.
    is not true.

  2. Failure:
    test_registration_page(UserControllerTest)
    [/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/assertions/selector_assertions.rb:296:in
    assert_select' ./test/functional/user_controller_test.rb:24:intest_registration_page’]:
    Expected at least 1 element matching “form”, found 0.
    is not true.

  3. Failure:
    test_registration_page(UserControllerTest)
    [/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/assertions/selector_assertions.rb:296:in
    assert_select' ./test/functional/user_controller_test.rb:24:intest_registration_page’]:
    Expected at least 1 element matching “form[action=’/user/register’]”,
    found 0.
    is not true.

  4. Failure:
    test_registration_page(UserControllerTest)
    [./test/functional/user_controller_test.rb:24]:
    expected tag, but no tag found matching {:tag=>“form”,
    :attributes=>{:action=>"/user/register", :method=>“post”}} in:
    “\n\n\n\tRegister\n\t<link
    href=”/stylesheets/site.css?1199235828" media=“screen”
    rel=“stylesheet” type=“text/css” />\n\n\n\t<div
    id=“whole_page”>\n\t\t<div id=“header”>RailsSpace\n\t\t<div
    id=“nav”>\n\t\t\t<a href="/">Home |\n\t\t\t<a
    href="/site/about">About Us |\n\t\t\t<a
    href="/site/help">Help |\n\t\t\tRegister\n\t\t\n\t\t<div
    id=“content”>\t\n\t\t\t\t\n\t\t\t

    Register

    \n<form
    action="/user/register" method=“post”>\n\n Enter
    Your Details \n \n <div class=“form_row”> \n<label
    for=“screen_name”>Screen name:\n<input id=“user_screen_name”
    maxlength=“20” name=“user[screen_name]” size=“20” type=“text”
    />\n\n <div class=“form_row”> \n<label
    for=“email”>Email:\n<input id=“user_email” maxlength=“50”
    name=“user[email]” size=“30” type=“text” />\n\n <div
    class=“form_row”> \n<label for=“password”>Password:\n<input
    id=“user_password” maxlength=“40” name=“user[password]”
    size=“10” type=“text” />\n\n\n <div class=“form_row”> \n
    <input class=“submit” name=“commit” type=“submit”
    value=“Register!” /> \n \n
    \n\n\t\t\t\n\t\t\n\t\n\n".
    is not true.

I get this same issue where both assert_tag and assert_select fail.
I have found that if tested with simplified html, i.e. just a H1 in
the body and it works just fine.

It only fails is there are attributes on any of the tags in the html.

Do you have any ideas how to resolve this issue?

On Jan 4, 7:52 am, Jim L. [email protected]

I had a problem similar to this and just could not get assert_tag to
work,
but I did not want to use a regex as the order of different attributes
makes complex testing difficult to maintain.

so after some testing I found that if I replaced the strict
declaration in the application layout with the transitional one

replace this

with

then it worked just fine.

On Jan 4, 7:52 am, Jim L. [email protected]

Did you get an answer? I am having issues with assert_select not
working as well. I have been trying assert_select “div#…” and get
the same failures you describe.

On Jan 3 2008, 10:52 pm, Jim L. [email protected]