From b9c88ee2a1f9231798819b12cd18ce8cc9d70631 Mon Sep 17 00:00:00 2001 From: Phil Lee Date: Mon, 16 Sep 2013 12:19:06 +0100 Subject: [PATCH] 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. --- lib/capybara/result.rb | 2 +- spec/result_spec.rb | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/capybara/result.rb b/lib/capybara/result.rb index b5afe2e5..aeb1f61d 100644 --- a/lib/capybara/result.rb +++ b/lib/capybara/result.rb @@ -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) diff --git a/spec/result_spec.rb b/spec/result_spec.rb index 82de3a6d..50f980f2 100644 --- a/spec/result_spec.rb +++ b/spec/result_spec.rb @@ -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