Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check content of attributes using rspec+webrat

With rspec+webrat you can check various attributes like :href, :content, :class etc but how can I check the content of html5 custom attributes. It seems to complain about the second part of the attribute name.

If attribute is 'data-random' and I try to use have_selector('li', :data-random => 'string') it will complain that random is an undefined local variable or method.

like image 206
user1116573 Avatar asked Jan 25 '26 13:01

user1116573


1 Answers

I think this has more to do with the syntax of Ruby symbols. They cannot contain hyphen characters, unless they are quoted. Try this instead:

have_selector('li', :'data-random' => 'string')
like image 137
Ben Simpson Avatar answered Jan 28 '26 04:01

Ben Simpson