Results can now be sampled.

An instance of Result can now call #sample. This is delegated to Array#sample.
This allows a random result to be chosen.
This is useful if we want to check one of the results but with no particular preference as to which result.
This commit is contained in:
Phil Lee 2013-09-16 12:19:06 +01:00
parent 5e1d159adf
commit b9c88ee2a1
2 changed files with 5 additions and 1 deletions

View File

@ -29,7 +29,7 @@ module Capybara
@query = query
end
def_delegators :@result, :each, :[], :at, :size, :count, :length, :first, :last, :empty?, :inspect
def_delegators :@result, :each, :[], :at, :size, :count, :length, :first, :last, :empty?, :inspect, :sample
def matches_count?
Capybara::Helpers.matches_count?(@result.size, @query.options)

View File

@ -48,4 +48,8 @@ describe Capybara::Result do
memo += element.text[0]
end.should == 'ABGD'
end
it 'can be sampled' do
result.should include(result.sample)
end
end