Ruby-on-rails – How to test an image src and alt value using capybara

capybararuby-on-rails

I'm trying to write test the value of alt text + src of an image using capybara and the css selectors.

any idea s to test both in single xpath ?

Best Answer

A slightly simpler way will be to use an id for that image:

page.find('#profile-avatar')['src'].should have_content 'default.png'

Updated for rspec 3:

expect(page.find('#profile-avatar')['src']).to have_content 'default.png' expect(page.find('#profile-avatar')['alt']).to match(/some-value/)