...">

How to check html attributes with rspec?

The html I created is generated by ruby ​​with:

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

that leads to:

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

but I want to make sure the link opens in a new tab with

 target="blank" 

Attribute

The rspec test looks like this:

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

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

+6
source share
2 answers

The following works for me with capybara 1.1.2:

 it { should have_selector("a[href='http://gravatar.com/emails'][target='_blank']") } 
+16
source

I use has_selector to process each attribute:

 should have_selector('a', :href => 'http://gravatar.com/emails', :target => '_blank', :content => 'change' ) 

I think you need capybara to have this matches http://rubydoc.info/github/jnicklas/capybara/Capybara/RSpecMatchers/HaveSelector

0
source

Source: https://habr.com/ru/post/919597/


All Articles