# Assert\_select tag in Rails 1.2.2

**URL:** <https://www.ruby-forum.com/t/assert-select-tag-in-rails-1-2-2/87169>\
**Category:** Rails\
**Created:** [February 28, 2007, 6:03pm UTC](https://www.ruby-forum.com/t/assert-select-tag-in-rails-1-2-2/87169 "2007-02-28T18:03:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 28, 2007, 6:03pm UTC](https://www.ruby-forum.com/t/assert-select-tag-in-rails-1-2-2/87169/1 "2007-02-28T18:03:22Z")

</div>

Rails 1.2.2 names the form elements like contact[subject],  
contact[body] and so on. The following code does not work in latest  
version.

def test\_login\_form\_has\_all\_fields  
get :login  
assert\_select “form[action=http://myapp/login] input” do |inputs|  
assert\_equal 3, inputs.size  
assert\_select inputs[0], “input[type=name][name=username]”  
assert\_select inputs[1], “input[type=password][name=password]”  
assert\_select inputs[2], “input[type=submit][value=Login]”  
end  
end

When the name is changed to contact[subject] format, it bombs out  
saying square brackets are not right selector.

Does anyone know how to check the form elements using assert\_select  
tag? TIA.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 28, 2007, 8:25pm UTC](https://www.ruby-forum.com/t/assert-select-tag-in-rails-1-2-2/87169/2 "2007-02-28T20:25:52Z")

</div>

bcparanj wrote:

> Does anyone know how to check the form elements using assert\_select  
> tag? TIA.

You could query by id, typically “user\_username”.

I just do this. Much more powerful:

form = select\_form ‘my\_form\_id’  
assert\_equal ‘foo’, form[‘user[username]’]  
form.submit

–  
Phlip  
[http://c2.com/cgi/wiki?ZeekLand](http://c2.com/cgi/wiki?ZeekLand) ← NOT a blog!!
