Skip to content

Commit

Permalink
Delegate index and values_at from Capybara::Result
Browse files Browse the repository at this point in the history
  • Loading branch information
abotalov committed Oct 29, 2013
1 parent e5108a9 commit 4df077e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/capybara/result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def initialize(elements, query)
@query = query
end

def_delegators :@result, :each, :[], :at, :size, :count, :length, :first, :last, :empty?, :inspect, :sample
def_delegators :@result, :each, :[], :at, :size, :count, :length,
:first, :last, :values_at, :empty?, :inspect, :sample, :index

def matches_count?
Capybara::Helpers.matches_count?(@result.size, @query.options)
Expand Down
10 changes: 10 additions & 0 deletions spec/result_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
result.last.text == 'Delta'
end

it 'can supports values_at method' do
result.values_at(0, 2).map(&:text).should == %w(Alpha Gamma)
end

it "can return an element by its index" do
result.at(1).text.should == 'Beta'
result[2].text.should == 'Gamma'
Expand All @@ -52,4 +56,10 @@
it 'can be sampled' do
result.should include(result.sample)
end

it 'can be indexed' do
result.index do |el|
el.text == 'Gamma'
end.should == 2
end
end

0 comments on commit 4df077e

Please sign in to comment.