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 Node::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.
26 27 28 29 30 31 |
# File 'lib/capybara/result.rb', line 26 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
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/capybara/result.rb', line 40 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
36 37 38 |
# File 'lib/capybara/result.rb', line 36 def matches_count? Capybara::Helpers.matches_count?(@result.size, @query.) end |
#negative_failure_message ⇒ Object
54 55 56 |
# File 'lib/capybara/result.rb', line 54 def .sub(/(to find)/, 'not \1') end |