开发者

capybara how to test multiple links with href pattern

开发者 https://www.devze.com 2023-03-22 01:25 出处:网络
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 :

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'.

0

精彩评论

暂无评论...
验证码 换一张
取 消