How to check which image is displayed using rspec?

Depending on which page is being viewed, I want to use a different image for my logo; logo on the main page more. I like to use query specifications to test behavior, so I would like to do something like this:

describe 'Visit "advertentie/1"' do
    it 'contains add details' do
        add = create(:add_with_photos)
        visit add_path add
        page.should have_selector( 'img[alt="logo-small"]' ) # CHECK IMAGE ALT
        page.should have_content( add.name )
    end
end

and the test starts some kind of haml-generated html again:

<div class='logo-wrapper'>
  <h1>
    <a href="/"><img alt="Logo-big" src="/assets/logo-small.png" />
    <br>
    <span>UpMarket</span>
    </a>
  </h1>
</div>

however, this selector does not work. Is this possible and how?

+5
source share
1 answer

Have you tried the method have_css?

have_css("img[src*='w3schools']")

(selects each element <img>, the value of the src attribute contains the substring "w3schools")

+15
source

All Articles