Class: Capybara::Result
- Inherits:
-
Object
- Object
- Capybara::Result
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/capybara/result.rb
Overview
A Result represents a collection of Element on the page. It is possible to interact with this collection similar to an Array because it implements Enumerable and offers the following Array methods through delegation:
-
each()
-
at()
-
size()
-
count()
-
length()
-
first()
-
last()
-
empty?()
Instance Method Summary collapse
- #failure_message ⇒ Object
-
#initialize(elements, query) ⇒ Result
constructor
A new instance of Result.
- #matches_count? ⇒ Boolean
- #negative_failure_message ⇒ Object
Constructor Details
#initialize(elements, query) ⇒ Result
Returns a new instance of Result.
25 26 27 28 29 30 |
# File 'lib/capybara/result.rb', line 25 def initialize(elements, query) @elements = elements @result = elements.select { |node| query.matches_filters?(node) } @rest = @elements - @result @query = query end |
Instance Method Details
#failure_message ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/capybara/result.rb', line 39 def = Capybara::Helpers.(@query.description, @query.) if count > 0 << ", found #{count} #{Capybara::Helpers.declension("match", "matches", count)}: " << @result.map(&:text).map(&:inspect).join(", ") else << " but there were no matches" end unless @rest.empty? elements = @rest.map(&:text).map(&:inspect).join(", ") << ". Also found " << elements << ", which matched the selector but not all filters." end end |
#matches_count? ⇒ Boolean
35 36 37 |
# File 'lib/capybara/result.rb', line 35 def matches_count? Capybara::Helpers.matches_count?(@result.size, @query.) end |
#negative_failure_message ⇒ Object
53 54 55 |
# File 'lib/capybara/result.rb', line 53 def .sub(/(to find)/, 'not \1') end |