Sha256: 6b8bea243294549ddb66eaf6258c01ec78ea5c180af11af5b03799ac888b4a02

Contents?: true

Size: 755 Bytes

Versions: 50

Compression:

Stored size: 755 Bytes

Contents

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

  failure_message do |selector|
    if @rules.empty?
      %{no CSS for selector #{selector} were found}
    else
      rules = @rules.join("; ")
      %{Expected selector #{selector} to have CSS rule "#{expected}".
        Had "#{rules}".}
    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

50 entries across 50 versions & 5 rubygems

Version Path
bourbon-7.3.0 spec/support/matchers/have_rule.rb
bourbon-7.2.0 spec/support/matchers/have_rule.rb
bourbon-7.1.0 spec/support/matchers/have_rule.rb
bourbon-7.0.0 spec/support/matchers/have_rule.rb
neat-4.0.0 spec/support/matchers/have_rule.rb
bourbon-6.0.0 spec/support/matchers/have_rule.rb
neat-3.0.1 spec/support/matchers/have_rule.rb
neat-1.9.1 spec/support/matchers/have_rule.rb
bourbon-5.1.0 spec/support/matchers/have_rule.rb
neat-3.0.0 spec/support/matchers/have_rule.rb
bourbon-5.0.1 spec/support/matchers/have_rule.rb
bourbon-5.0.0 spec/support/matchers/have_rule.rb
neat-1.9.0 spec/support/matchers/have_rule.rb
neat-2.1.0 spec/support/matchers/have_rule.rb
bourbon-5.0.0.beta.8 spec/support/matchers/have_rule.rb
bourbon-4.3.4 spec/support/matchers/have_rule.rb
bourbon-4.3.3 spec/support/matchers/have_rule.rb
neat-2.0.0 spec/support/matchers/have_rule.rb
bourbon-4.3.2 spec/support/matchers/have_rule.rb
bourbon-4.3.1 spec/support/matchers/have_rule.rb