Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test what image is being displayed using rspec?

Depending on what page is being viewed I want to use a different image for my logo; the logo on the homepage is bigger. I like using request specs to test behaviour, 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 runs agains some haml generated html:

<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 doesn't work. Is this possible, and how?

like image 388
Jasper Kennis Avatar asked Sep 19 '12 15:09

Jasper Kennis


1 Answers

Did you try the have_css method?

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

(Selects every <img> element whose src attribute value contains the substring "w3schools")

like image 138
hjblok Avatar answered Nov 16 '22 02:11

hjblok