Sha256: 8ff310255b3c017fbd78360587c1477b41ccaeb15ea6c818897690c417f802fd

Contents?: true

Size: 1.07 KB

Versions: 29

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

module Capybara
  # @api private
  module Queries
    class StyleQuery < BaseQuery
      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

      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

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

    private

      def stringify_keys(hsh)
        hsh.each_with_object({}) { |(k, v), str_keys| str_keys[k.to_s] = v }
      end

      def valid_keys
        %i[wait]
      end
    end
  end
end

Version data entries

29 entries across 27 versions & 3 rubygems

Version Path
tdiary-5.1.3 vendor/bundle/ruby/2.6.0/gems/capybara-3.32.2/lib/capybara/queries/style_query.rb
tdiary-5.1.2 vendor/bundle/ruby/2.6.0/gems/capybara-3.29.0/lib/capybara/queries/style_query.rb
tdiary-5.1.2 vendor/bundle/ruby/2.7.0/gems/capybara-3.32.2/lib/capybara/queries/style_query.rb
capybara-3.32.2 lib/capybara/queries/style_query.rb
capybara-3.32.1 lib/capybara/queries/style_query.rb
capybara-3.32.0 lib/capybara/queries/style_query.rb
tdiary-5.1.1 vendor/bundle/ruby/2.7.0/gems/capybara-3.31.0/lib/capybara/queries/style_query.rb
tdiary-5.1.1 vendor/bundle/ruby/2.6.0/gems/capybara-3.29.0/lib/capybara/queries/style_query.rb
capybara-3.31.0 lib/capybara/queries/style_query.rb
capybara-3.30.0 lib/capybara/queries/style_query.rb
tdiary-5.1.0 vendor/bundle/gems/capybara-3.29.0/lib/capybara/queries/style_query.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/capybara-3.29.0/lib/capybara/queries/style_query.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/capybara-3.29.0/lib/capybara/queries/style_query.rb
capybara-3.29.0 lib/capybara/queries/style_query.rb
capybara-3.28.0 lib/capybara/queries/style_query.rb
capybara-3.27.0 lib/capybara/queries/style_query.rb
capybara-3.26.0 lib/capybara/queries/style_query.rb
capybara-3.25.0 lib/capybara/queries/style_query.rb
capybara-3.24.0 lib/capybara/queries/style_query.rb
capybara-3.23.0 lib/capybara/queries/style_query.rb