assert_select for attributes that have square brackets

106 views
Skip to first unread message

James K

unread,
Sep 3, 2008, 4:15:26 PM9/3/08
to Boston Ruby Group
Hey folks, wondering if there's a way to use assert_select with an
attribute selector for an element with a square bracket in the name,
as all rails form elements do:

assert_select 'input[name=model_name[field_name]]' gives
ArgumentError: Invalid selector: ]

I know I can work around this by iterating over all the input elements
in the form, but it seems like there must be a way of escaping the
selector to make this case work (which must be somewhat common among
rails apps)

-James

Mike Burns

unread,
Sep 3, 2008, 4:18:15 PM9/3/08
to boston-r...@googlegroups.com
On 2008-09-03 13.15.26 -0700, James K wrote:
> assert_select 'input[name=model_name[field_name]]' gives
> ArgumentError: Invalid selector: ]

assert_select 'input[name=?]', 'model_name[field_name]'

--
Mike Burns mi...@mike-burns.com http://mike-burns.com

James K

unread,
Sep 3, 2008, 4:24:59 PM9/3/08
to Boston Ruby Group
Thanks so much, works like a charm!

On Sep 3, 4:18 pm, Mike Burns <m...@mike-burns.com> wrote:
> On 2008-09-03 13.15.26 -0700, James K wrote:
>
> > assert_select 'input[name=model_name[field_name]]' gives
> > ArgumentError: Invalid selector: ]
>
> assert_select 'input[name=?]', 'model_name[field_name]'
>
> --
> Mike Burns m...@mike-burns.comhttp://mike-burns.com
Reply all
Reply to author
Forward
0 new messages