Skip to content
This repository was archived by the owner on Aug 16, 2024. It is now read-only.

Latest commit

 

History

History
39 lines (29 loc) · 893 Bytes

File metadata and controls

39 lines (29 loc) · 893 Bytes

Capybara all does not return an array

Although it looks like it returns an Array, Capybara's all finder actually returns a Capybara::Result. This object includes Enumerable and responds to many of the most used methods on Array such as [].

Given the following HTML:

<body>
  <p>Some content</p>
  <p>Other content</p>
  <p>Final content</p>
</body>

The following really looks like we are dealing with an array:

paragraphs = all("p")
# => [<Capybara::Element>,<Capybara::Element>,<Capybara::Element>]

paragraphs[1]
# => <Capybara::Element>

paragraphs.map(&:text)
# => ["Some content", "Other content", "Final Content"]

However, if I try to use some of the Array monkey patches provided by ActiveSupport:

paragraphs.second
# => NoMethodError: undefined method `second' for Capybara::Result

paragraphs.class
# => Capybara::Result