Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use capybara/rspec to match a range?

I'm testing a Rails 3.2.6 app.

Is it possible to make an Rspec/Capybara assertion that expresses, eg:

'If I ask for films between 1970 and 1990, the page should contain a film between those dates:'

For example

it "should show films in the the chosen date range" do
  page.should have_selector '.year',  # then something like text: range(1970..1990)
end

And conversely, can I check that no '.year' elements contain dates that are not in that range?

Thanks for any help.

like image 661
djb Avatar asked Dec 21 '22 19:12

djb


1 Answers

Passing a block to have_selector didn't work, but within did:

within('.year') do 
  text.to_i.should be_between(1970, 1990)
end
like image 102
djb Avatar answered Dec 30 '22 07:12

djb