Sha256: 1115fe545f3c4556006daad4b3df20ae2183034c7a119b3a1018d350f4798c8b

Contents?: true

Size: 505 Bytes

Versions: 4

Compression:

Stored size: 505 Bytes

Contents

RSpec::Matchers.define :have_css do |expected, times|
  match do |actual|
    selector = Nokogiri::HTML(actual).css(expected)

    if times
      expect(selector.size).to eq times
    else
      expect(selector.size).to be >= 1
    end
  end

  failure_message do |actual|
    "expected #{actual.to_s} to have #{times || 1} elements matching '#{expected}'"
  end

  failure_message_when_negated do |actual|
    "expected #{actual.to_s} not to have #{times || 1} elements matching '#{expected}'"
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
simple-navigation-4.4.0 spec/initializers/have_css_matcher.rb
simple-navigation-4.3.0 spec/initializers/have_css_matcher.rb
simple-navigation-4.2.0 spec/initializers/have_css_matcher.rb
simple-navigation-4.1.0 spec/initializers/have_css_matcher.rb