# Problems with assert\_select in integration tests

**URL:** <https://www.ruby-forum.com/t/problems-with-assert-select-in-integration-tests/83451>\
**Category:** Rails\
**Created:** [January 26, 2007, 4:56am UTC](https://www.ruby-forum.com/t/problems-with-assert-select-in-integration-tests/83451 "2007-01-26T04:56:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![nielsene](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bc79bd/32.png) [@nielsene](https://www.ruby-forum.com/u/nielsene)\
**Post date:** [January 26, 2007, 4:56am UTC](https://www.ruby-forum.com/t/problems-with-assert-select-in-integration-tests/83451/1 "2007-01-26T04:56:59Z")

</div>

I’ve been battling with assert\_select in my integration tests for  
several evenings now. I’m testing a multi-step form, and after  
submitting the first step, my assert\_selects fail on the attempts to  
find the form on the next page. However if I print out the response  
object, it has the exact text of what I’m trying to match.

Here is the complete integration test. The failure occures on the  
first assert\_select in the second call to click\_button.

require “#{File.dirname( **FILE** )}/…/test\_helper”

class AccountCreationTest \< ActionController::IntegrationTest

def test\_personal\_account\_creation  
goto\_home\_page  
click\_link “Create Account”, “/account/new\_account\_step\_one”  
click\_button “Next Step”, “/account/new\_account\_step\_one”,  
:user=\>{:username=\>“TestUser”,  
:password=\>‘T3st!ng’, :password\_confirmation=\>‘T3st!ng’,  
:account\_type=\>‘Personal’, :email=\>‘removed\_email\_address@domain.invalid’}  
click\_button “Create Account”, “/account/new\_account\_step\_two”,  
{:first\_name=\>‘Test’, :last\_name=\>‘User’}  
end

private  
def goto\_home\_page  
get “/”  
assert\_response :success  
assert\_template “register/list”  
end

def click\_link(link\_text, destination)  
assert\_select “a[href\*=#{destination}]”, link\_text  
get destination  
assert\_response :success  
end

def click\_button(button\_text, destination, params={})  
assert\_select “form[action=#{destination}]” do  
assert\_select “input[type=submit][value=#{button\_text}]”  
end  
post\_via\_redirect destination, params  
assert\_response :success  
end

end

Here is the failure report:

1. Failure:  
test\_personal\_account\_creation(AccountCreationTest)  
[/Users/nielsene/ruby-work/compinabox/config/…/vendor/rails/actionpack/lib/action\_controller/assertions/selector\_assertions.rb:281:in  
`assert_select' test/integration/account_creation_test.rb:37:in `click\_button’  
test/integration/account\_creation\_test.rb:11:in  
`test_personal_account_creation' /Users/nielsene/ruby-work/compinabox/config/../vendor/rails/actionpack/lib/action_controller/integration.rb:453:in `run’]:  
Expected at least 1 elements, found 0.  
 is not true.

And here is an except from “puts response.inspect”  
#\<ActionController::CgiResponse:0x247432c @redirected\_to=nil,  
@headers={“Status”=\>“200 OK”, “type”=\>“text/html; charset=utf-8”,  
“cookie”=\>[], “Cache-Control”=\>“no-cache”, “Content-Length”=\>2247},  
@session=#\<CGI::Session:0x246e2b0  
@session\_id=“d0060c4ee33f3d58c0ef83bbfa107b6f”,  
@data={:pending\_user=\>{“password\_confirmation”=\>“T3st!ng”,  
“username”=\>“TestUser”, “account\_type”=\>“Personal”,  
“password”=\>“T3st!ng”, “email”=\>“removed\_email\_address@domain.invalid”}, “flash”=\>{}},  
@dbprot=[], @dbman=#\<CGI::Session::ActiveRecordStore:0x246d004  
@session=nil\>, @new\_session=false\>,  
@cgi=#\<ActionController::Integration::Session::MockCGI:0x24772fc  
@output\_cookies=[[“d0060c4ee33f3d58c0ef83bbfa107b6f”]],  
@env\_table={“CONTENT\_LENGTH”=\>nil, “HTTP\_HOST”=\>“[www.example.com](http://www.example.com)”,  
“REMOTE\_ADDR”=\>“127.0.0.1”,  
“CONTENT\_TYPE”=\>“application/x-www-form-urlencoded”, “HTTPS”=\>“off”,  
“HTTP\_COOKIE”=\>“\_session\_id=d0060c4ee33f3d58c0ef83bbfa107b6f; “,  
“REQUEST\_URI”=\>”/account/new\_account\_step\_two”, “SERVER\_PORT”=\>“80”,  
“QUERY\_STRING”=\>nil,  
“HTTP\_ACCEPT”=\>“text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,_/_;q=0.5”,  
“REQUEST\_METHOD”=\>“GET”},  
@output\_hidden={“\_session\_id”=\>“d0060c4ee33f3d58c0ef83bbfa107b6f”},  
@stdoutput=#StringIO:0x24771d0,  
@cookies={“\_session\_id”=\>[“d0060c4ee33f3d58c0ef83bbfa107b6f”]},  
@stdinput=#StringIO:0x24771e4, @params={}, @multipart=false\>, @body="  
[header of page cut …] \<div id="main-double"\>\n\t\t\t\n\n\<form  
action="/account/new\_account\_step\_two" method="post"\>

\<label  
for="user\_first\_name"\>First Name:  
\n\t\<input  
id="first\_name" name="first\_name" type="text" /\>

\n

\<label  
for="user\_last\_name"\>Last Name:  
\n\t\<input  
id="last\_name" name="last\_name" type="text" /\>

\n\<input  
name="commit" type="submit" value="Create Account"  
/\>\n\t\t\n\t\n \t\<div  
class="clearing"\>&nbsp;\n  
…

Can anyone help me understand what I’ve been doing wrong?
