Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to test html attributes with rspec?

the html I have is generated by ruby with:

<%= link_to "change", "http://gravatar.com/emails" %>

which results in:

<a href="http://gravatar.com/emails">change</a>

but I want to ensure that the link opens in a new tab with the

target="blank"

attribute

the rspec test looks like:

it { should have_link('change', href: 'http://gravatar.com/emails', target: '_blank') }

but the test still passes when I don't have the target attribute being generated.

like image 715
not_shitashi Avatar asked Jul 03 '12 15:07

not_shitashi


1 Answers

The following works for me with capybara 1.1.2:

it { should have_selector("a[href='http://gravatar.com/emails'][target='_blank']") }
like image 128
pward123 Avatar answered Oct 17 '22 03:10

pward123