Class: Capybara::Queries::BaseQuery Private
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Subclasses:
|
|
Inherits: | Object |
Defined in: | lib/capybara/queries/base_query.rb |
Constant Summary
-
COUNT_KEYS =
# File 'lib/capybara/queries/base_query.rb', line 7%i[count minimum maximum between].freeze
Class Method Summary
- .new(options) ⇒ BaseQuery constructor Internal use only
- .wait(options, default = Capybara.default_max_wait_time) Internal use only
Instance Attribute Summary
-
#expects_none? ⇒ Boolean
readonly
Internal use only
Checks if a count of 0 is valid for the query Returns false if query does not have any count options specified.
- #options readonly Internal use only
- #session_options rw Internal use only
- #session_options=(value) rw Internal use only
- #count_specified? ⇒ Boolean readonly private Internal use only
Instance Method Summary
-
#failure_message
Internal use only
Generates a failure message from the query description and count options.
-
#matches_count?(count) ⇒ Boolean
Internal use only
Checks if the given count matches the query count options.
- #negative_failure_message Internal use only
- #wait Internal use only
- #assert_valid_keys private Internal use only
- #count_message private Internal use only
- #occurrences(count) private Internal use only
Constructor Details
.new(options) ⇒ BaseQuery
# File 'lib/capybara/queries/base_query.rb', line 12
def initialize( ) @session_options = .delete(: ) end
Class Method Details
.wait(options, default = Capybara.default_max_wait_time)
[ GitHub ]# File 'lib/capybara/queries/base_query.rb', line 24
def self.wait(, default = Capybara.default_max_wait_time) # if no value or nil for the :wait option is passed it should default to the default wait = .fetch(:wait, nil) wait = default if wait.nil? wait || 0 end
Instance Attribute Details
#count_specified? ⇒ Boolean
(readonly, private)
# File 'lib/capybara/queries/base_query.rb', line 72
def count_specified? COUNT_KEYS.any? { |key| .key? key } end
#expects_none? ⇒ Boolean
(readonly)
Checks if a count of 0 is valid for the query Returns false if query does not have any count options specified.
# File 'lib/capybara/queries/base_query.rb', line 36
def expects_none? count_specified? ? matches_count?(0) : false end
#options (readonly)
[ GitHub ]# File 'lib/capybara/queries/base_query.rb', line 9
attr_reader :
#session_options (rw)
[ GitHub ]# File 'lib/capybara/queries/base_query.rb', line 16
def @session_options || Capybara. end
#session_options=(value) (rw)
[ GitHub ]# File 'lib/capybara/queries/base_query.rb', line 10
attr_writer :
Instance Method Details
#assert_valid_keys (private)
# File 'lib/capybara/queries/base_query.rb', line 96
def assert_valid_keys invalid_keys = @options.keys - valid_keys return if invalid_keys.empty? invalid_names = invalid_keys.map(&:inspect).join(', ') valid_names = valid_keys.map(&:inspect).join(', ') raise ArgumentError, "Invalid option(s) #{invalid_names}, should be one of #{valid_names}" end
#count_message (private)
[ GitHub ]# File 'lib/capybara/queries/base_query.rb', line 76
def = +'' count, between, maximum, minimum = .values_at(:count, :between, :maximum, :minimum) if count << " #{occurrences count}" elsif between << " between #{between.begin ? between.first : 1} and " \ "#{between.end ? between.last : 'infinite'} times" elsif maximum << " at most #{occurrences maximum}" elsif minimum << " at least #{occurrences minimum}" end end
#failure_message
Generates a failure message from the query description and count options.
# File 'lib/capybara/queries/base_query.rb', line 62
def +"expected to find #{description}" << end
#matches_count?(count) ⇒ Boolean
Checks if the given count matches the query count options. Defaults to true if no count options are specified. If multiple count options exist, it tests that all conditions are met; however, if :count
is specified, all other options are ignored.
# File 'lib/capybara/queries/base_query.rb', line 49
def matches_count?(count) return (Integer( [:count]) == count) if [:count] return false if [:maximum] && (Integer( [:maximum]) < count) return false if [:minimum] && (Integer( [:minimum]) > count) return false if [:between] && ! [:between].include?(count) true end
#negative_failure_message
[ GitHub ]# File 'lib/capybara/queries/base_query.rb', line 66
def +"expected not to find #{description}" << end
#occurrences(count) (private)
[ GitHub ]# File 'lib/capybara/queries/base_query.rb', line 92
def occurrences(count) "#{count} #{Capybara::Helpers.declension('time', 'times', count)}" end
#wait
[ GitHub ]# File 'lib/capybara/queries/base_query.rb', line 20
def wait self.class.wait(, .default_max_wait_time) end