How to test if an img tag points to an existing image?

I'm using Cucumber and Capybara for BDD on a RoR application. I have the following feature

Feature: List profiles
  In order to know that the people behind the profiles are real people 
  As a lurker
  I want to be able to find who is registed and see their profile picture

Background: Profiles have been added to the database, some with picture attached
  Given some profiles exist
  And  I am on the home page

Scenario: Search by city, avatars should be there
  When I search for a city with profiles
  Then I should see some result profiles with avatar

The underlying Capybara steps file contains:

Then /^I should see some result profiles with avatar$/ do
  page.should have_css("#profile_search_results .profile img.avatar", :count => some_profiles)

This step checks that the page contains

<div id="#profile_search_results>
  <img class="avatar" src="" />

BUT... I also want to check if the image exists (it is not a broken image).

How can I do this in my Capybara steps?


The way to check, without having to use Selenium or any other drivers, was to extract the src attribute from the img element (Thanks MrDanA), and check the status code after visiting that URL:

page.should have_css("#profile_search_results .profile img.avatar", :count => some_profiles)
img = page.first(:css, "#profile_search_results .profile img.avatar")
visit img[:src]
page.status_code.should be 200 

Need Your Help

Is it possible to swap System.Data.SqlServerCe with version at runtime?

c# dll assemblies sql-server-ce assemblybinding

My application references a library project that has System.Data.SqlServerCe as a dependency.

How to add a 2nd argument to doInBackground for android?

android android-asynctask

I have this asynctask working fine for what I want with a single argument (remove the param2 and it runs) but as soon as I attempt to add the 2nd argument I receive:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.