123456789_123456789_123456789_123456789_123456789_

Class: Capybara::Queries::StyleQuery Private

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, BaseQuery
Instance Chain:
self, BaseQuery
Inherits: Capybara::Queries::BaseQuery
Defined in: lib/capybara/queries/style_query.rb

Constant Summary

BaseQuery - Inherited

COUNT_KEYS

Class Method Summary

Instance Attribute Summary

BaseQuery - Inherited

#expects_none?

Checks if a count of 0 is valid for the query Returns false if query does not have any count options specified.

#options, #session_options, #session_options=, #count_specified?

Instance Method Summary

BaseQuery - Inherited

#failure_message

Generates a failure message from the query description and count options.

#matches_count?

Checks if the given count matches the query count options.

#negative_failure_message, #wait, #assert_valid_keys, #count_message, #occurrences

Constructor Details

.new(expected_styles, session_options:, **options) ⇒ StyleQuery

[ GitHub ]

  
# File 'lib/capybara/queries/style_query.rb', line 7

def initialize(expected_styles, session_options:, **options)
  @expected_styles = stringify_keys(expected_styles)
  @options = options
  @actual_styles = {}
  super(@options)
  self.session_options = session_options

  assert_valid_keys
end

Instance Method Details

#failure_message

[ GitHub ]

  
# File 'lib/capybara/queries/style_query.rb', line 29

def failure_message
  +"Expected node to have styles #{@expected_styles.inspect}. " \
   "Actual styles were #{@actual_styles.inspect}"
end

#resolves_for?(node) ⇒ Boolean

[ GitHub ]

  
# File 'lib/capybara/queries/style_query.rb', line 17

def resolves_for?(node)
  @node = node
  @actual_styles = node.style(*@expected_styles.keys)
  @expected_styles.all? do |style, value|
    if value.is_a? Regexp
      value.match? @actual_styles[style]
    else
      @actual_styles[style] == value
    end
  end
end

#stringify_keys(hsh) (private)

[ GitHub ]

  
# File 'lib/capybara/queries/style_query.rb', line 36

def stringify_keys(hsh)
  hsh.transform_keys(&:to_s)
end

#valid_keys (private)

[ GitHub ]

  
# File 'lib/capybara/queries/style_query.rb', line 40

def valid_keys
  %i[wait]
end