Given I have a page with a 10 users listing, How can I test that I have 10 user show links ?
I've tried this :
Then /^I should see a list of (\d+) users$/ do |num|
page.should have_selector('a', {:href=>"users/*", :count => num})
end
And this :
Then /^I should see a list of (\d+) users$/ do |num|
page.should have_selector('a', {:href=>/users\/\d+/, :count => num})
end
But both return expected css "a" to return something (RSpec::Expectations::ExpectationNotMetError)
If I omit the :count paramet开发者_开发问答er, however, the test always passes whatever I have (even faulty pattern) in the :href param.
I would use an xpath with the contains
function for this:
page.should have_xpath("//a[contains(@href,'users')]"), :count => num)
Should match num
occurrences of any a
element with an href
attribute containing the text 'users'.
精彩评论