File: have_no_styling_matcher.rb

package info (click to toggle)
ruby-roadie-rails 3.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,280 kB
  • sloc: ruby: 1,670; sh: 47; makefile: 4
file content (28 lines) | stat: -rw-r--r-- 688 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# frozen_string_literal: true

RSpec::Matchers.define :have_no_styling do
  chain(:at_selector) { |selector| @selector = selector }

  match do |document|
    @selector ||= "body > *:first"
    styles_at_selector(document).empty?
  end

  description do
    "have no styles at selector #{@selector.inspect}"
  end

  failure_message do |document|
    "expected no styles at #{@selector.inspect} but had:\n" \
      "#{styles_at_selector(document)}"
  end

  failure_message_when_negated do
    "expected #{@selector.inspect} to have styles"
  end

  def styles_at_selector(document)
    expect(document).to have_selector(@selector)
    document.at_css(@selector)["style"] || ""
  end
end