Sha256: 42d7044a934eb75ca1458f936d250dc0f4df3fb1888111311a37b3fff9f55f2e

Contents?: true

Size: 694 Bytes

Versions: 4

Compression:

Stored size: 694 Bytes

Contents

RSpec::Matchers.define :have_rule do |expected|
  match do |actual|
    @rules = rules_from_selector(actual)
    @rules.include? expected
  end

  failure_message do |actual|
    if @rules.empty?
      %{no CSS rules for selector #{actual} were found}
    else
      %{expected selector #{actual} to have CSS rule "#{expected}"}
    end
  end

  def rules_from_selector(selector)
    rulesets = ParserSupport.parser.find_by_selector(selector)
    if rulesets.empty?
      []
    else
      rules(rulesets)
    end
  end

  def rules(rulesets)
    rules = []
    rulesets.map do |ruleset|
      ruleset.split(";").each do |rule|
        rules << rule.strip
      end
    end
    rules
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
neat-1.7.4 spec/support/matchers/have_rule.rb
neat-1.7.3 spec/support/matchers/have_rule.rb
neat-1.7.2 spec/support/matchers/have_rule.rb
neat-1.7.1 spec/support/matchers/have_rule.rb