Is it possible to use capybara / rspec to match the range?

I am testing a Rails 3.2.6 application.

Is it possible to make an Rspec / Capybara statement that expresses, for example:

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

for instance

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 vice versa, can I verify that the '.year' elements contain dates that are not in this range?

Thanks for any help.

+4
source share
3 answers

Passing the block to has_selector did not work, but within did:

 within('.year') do text.to_i.should be_between(1970, 1990) end 
+8
source

try something like:

 page.should have_selector('.year') do |year| range(1970..1990).should include(year.text.to_i) end 
+1
source

In my opinion, the syntax of target.should be_between(x, y) rspec is more readable:

 page.should have_selector('.year') do |year| i_year = year.text.to_i i_year.should be_between(1970, 1990) end 
+1
source

All Articles