Take the 2-minute tour ×

I'm using a table to represent a rota and I want to use RSpec to test that the date is appearing:

 describe "Checking the rota" do

    let(:service){ FactoryGirl.create(:service)}
    before{ visit root_path } #this is where the rota is displayed
    it{ should have_selector('td', date: service.date) }


As far as I can tell the application itself is working fine as the rota is displaying perfectly when I visit the page myself. I'm curious as to why the test is failing though. The factory script I'm using is:

factory :service do
    date Date.today
    leader "Bob"
    singers "Mr T"
    soundAM "Thor"
    soundPM "Wobbles"

Finally the stub I'm using to render the rota:

<% if(service.date < Date.today) %>
  <% service.destroy %>
<% end %>
    <td><%=link_to service.date, edit_service_path(service.id) %></td>
    <td><%= service.leader %></td>


Thanks for any help in advance.

share|improve this question
add comment

1 Answer

I think the right line is:

it{ should have_selector('td', text: service.date) }

Depends if you're using Capybara or Webrat

share|improve this answer
add comment

Your Answer


