Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RSpec HtmlMatchers have_tag: can we use regular expression to match HTML attributes?

Trying to spec for a part of value of the the src attribute in an img tag rendered by one of my views, I was hoping to use the following syntax:

is_expected.to have_tag 'img', with: {src: /thumb_product\.png/}

It does not work, which is weird because the expression seems to be correctly interpreted by nokogiri (see the (?-mix:...) criteria)

expected following:
<div class='active uploaded_image'>
<img alt="Thumb product" src="/uploads/tmp/1404970363-22080-9933/thumb_product.png" />
</div>

to have at least 1 element matching "img[src='(?-mix:thumb_product\.png)']", found 0.

So I wonder if I forgot something, or if it's simply not possible. Thanks in advance

like image 551
Benj Avatar asked Oct 23 '25 17:10

Benj


1 Answers

Manually, to test that src string ends with the expected name of the file:

is_expected.to have_tag 'img[src$="thumb_product.png"]'
like image 50
Benj Avatar answered Oct 26 '25 07:10

Benj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!