Sha256: f3984cceb3cba2a3090fc19b988377895b86c49555384b402be289bb76669861

Contents?: true

Size: 670 Bytes

Versions: 7

Compression:

Stored size: 670 Bytes

Contents

# frozen_string_literal: true

RSpec::Matchers.define :have_node do |selector|
  chain(:with_attributes) { |attributes| @attributes = attributes }
  match do |document|
    node = document.at_css(selector)
    if @attributes
      node && match_attributes(node.attributes)
    else
      node
    end
  end

  failure_message { "expected document to #{name_to_sentence}#{expected_to_sentence}" }
  failure_message_when_negated { "expected document to not #{name_to_sentence}#{expected_to_sentence}" }

  def match_attributes(node_attributes)
    attributes = node_attributes.map { |name, attribute| [name, attribute.value] }.to_h
    @attributes == attributes
  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_node_matcher.rb
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.1.0/gems/roadie-5.2.1/spec/support/have_node_matcher.rb
roadie-5.2.1 spec/support/have_node_matcher.rb
roadie-5.2.0 spec/support/have_node_matcher.rb
roadie-5.1.0 spec/support/have_node_matcher.rb
roadie-5.0.1 spec/support/have_node_matcher.rb
roadie-5.0.0 spec/support/have_node_matcher.rb