module RSpec::CSS

Constants

CSS_PROPERTIES

rubocop:disable Layout/LineLength referenced by 'List of CSS properties, both proposed and standard' 536 distinct property names @see www.w3.org/Style/CSS/all-properties.en.html

VERSION

Public Class Methods

print_silk(store_path, page_session) click to toggle source
register(matchers = RSpec::Matchers) click to toggle source

rubocop:enable Layout/LineLength

# File lib/rspec/css.rb, line 19
def self.register(matchers = RSpec::Matchers)
  matchers.define :eq_screen_css do |expected|
    match do |actual|
      screen = {}
      actual.all(:xpath, '//*').each_with_index do |x, i|
        screen["#{i}_#{x.tag_name}"] = x.style(CSS_PROPERTIES)
      end
      @actual = screen.to_yaml
      expected == @actual
    end

    failure_message do |_|
      "\nexpected: #{expected}\n     got: #{@actual}\n\n(compared using ==)\n"
    end

    failure_message_when_negated do |_|
      "\nexpected: value != #{expected}\n     got: #{@actual}\n\n(compared using ==)\n"
    end

    description do
      "eq_screen_css #{expected}"
    end

    diffable
  end
end