Sha256: f34d5777220cf40513ec24bfdbbcc5eac192a83d814715a0335a39fbff0214b3

Contents?: true

Size: 886 Bytes

Versions: 7

Compression:

Stored size: 886 Bytes

Contents

# frozen_string_literal: true

RSpec::Matchers.define :have_attribute do |attribute|
  @selector = "body > *:first"

  chain :at_selector do |selector|
    @selector = selector
  end

  match do |document|
    name, expected = attribute.first
    expected == attribute(document, name)
  end

  description { "have attribute #{attribute.inspect} at selector #{@selector.inspect}" }
  failure_message do |document|
    name, expected = attribute.first
    "expected #{name} attribute at #{@selector.inspect} to be #{expected.inspect} but was #{attribute(document, name).inspect}"
  end
  failure_message_when_negated do |document|
    name, expected = attribute.first
    "expected #{name} attribute at #{@selector.inspect} to not be #{expected.inspect}"
  end

  def attribute(document, attribute_name)
    node = document.css(@selector).first
    node && node[attribute_name]
  end
end

Version data entries

7 entries across 6 versions & 2 rubygems

Version Path
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/roadie-5.2.1/spec/support/have_attribute_matcher.rb
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.1.0/gems/roadie-5.2.1/spec/support/have_attribute_matcher.rb
roadie-5.2.1 spec/support/have_attribute_matcher.rb
roadie-5.2.0 spec/support/have_attribute_matcher.rb
roadie-5.1.0 spec/support/have_attribute_matcher.rb
roadie-5.0.1 spec/support/have_attribute_matcher.rb
roadie-5.0.0 spec/support/have_attribute_matcher.rb