Sha256: 63369b0942c1d6062a9d9d0dbed12117792b4692f3f1ad3caf2a49f636039d67

Contents?: true

Size: 705 Bytes

Versions: 15

Compression:

Stored size: 705 Bytes

Contents

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

  failure_message_for_should 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

15 entries across 15 versions & 2 rubygems

Version Path
poxy-0.0.6 spec/support/matchers/have_rule.rb
poxy-0.0.5 spec/support/matchers/have_rule.rb
poxy-0.0.4 spec/support/matchers/have_rule.rb
poxy-0.0.1 spec/support/matchers/have_rule.rb
poxy-0.0.0 spec/support/matchers/have_rule.rb
neat-1.5.1 spec/support/matchers/have_rule.rb
neat-1.6.0 spec/support/matchers/have_rule.rb
neat-1.6.0.pre2 spec/support/matchers/have_rule.rb
neat-1.6.0.pre spec/support/matchers/have_rule.rb
neat-1.5.0 spec/support/matchers/have_rule.rb
neat-1.5.0.pre spec/support/matchers/have_rule.rb
neat-1.4.0 spec/support/matchers/have_rule.rb
neat-1.3.0 spec/support/matchers/have_rule.rb
neat-1.2.1 spec/support/matchers/have_rule.rb
neat-1.2.0 spec/support/matchers/have_rule.rb