# Assert\_select / assert\_tag issue

**URL:** <https://www.ruby-forum.com/t/assert-select-assert-tag-issue/124974>\
**Category:** Rails\
**Created:** [January 4, 2008, 7:52am UTC](https://www.ruby-forum.com/t/assert-select-assert-tag-issue/124974 "2008-01-04T07:52:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimlast](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/eb9ed0/32.png) [@jimlast](https://www.ruby-forum.com/u/jimlast)\
**Post date:** [January 4, 2008, 7:52am UTC](https://www.ruby-forum.com/t/assert-select-assert-tag-issue/124974/1 "2008-01-04T07:52:41Z")

</div>

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:in`test\_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:in`test\_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:in`test\_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

---

<div class="post-metadata">

**Author:** ![jimlast](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/eb9ed0/32.png) [@jimlast](https://www.ruby-forum.com/u/jimlast)\
**Post date:** [June 30, 2008, 5:32pm UTC](https://www.ruby-forum.com/t/assert-select-assert-tag-issue/124974/2 "2008-06-30T17:32:38Z")

</div>

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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![jimlast](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/eb9ed0/32.png) [@jimlast](https://www.ruby-forum.com/u/jimlast)\
**Post date:** [July 2, 2008, 10:41pm UTC](https://www.ruby-forum.com/t/assert-select-assert-tag-issue/124974/3 "2008-07-02T22:41:23Z")

</div>

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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![jimlast](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/eb9ed0/32.png) [@jimlast](https://www.ruby-forum.com/u/jimlast)\
**Post date:** [January 21, 2009, 1:07pm UTC](https://www.ruby-forum.com/t/assert-select-assert-tag-issue/124974/4 "2009-01-21T13:07:26Z")

</div>

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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
