Sha256: 83c4d6cfff5e480cf4f4944b22c8b12ab3e67f68a9ecabd754edf84680209aab

Contents?: true

Size: 856 Bytes

Versions: 16

Compression:

Stored size: 856 Bytes

Contents

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

16 entries across 16 versions & 1 rubygems

Version Path
roadie-3.5.1 spec/support/have_attribute_matcher.rb
roadie-3.5.0 spec/support/have_attribute_matcher.rb
roadie-3.4.0 spec/support/have_attribute_matcher.rb
roadie-3.3.0 spec/support/have_attribute_matcher.rb
roadie-3.2.2 spec/support/have_attribute_matcher.rb
roadie-3.2.1 spec/support/have_attribute_matcher.rb
roadie-3.2.0 spec/support/have_attribute_matcher.rb
roadie-3.1.1 spec/support/have_attribute_matcher.rb
roadie-3.1.0 spec/support/have_attribute_matcher.rb
roadie-3.1.0.rc1 spec/support/have_attribute_matcher.rb
roadie-3.0.5 spec/support/have_attribute_matcher.rb
roadie-3.0.4 spec/support/have_attribute_matcher.rb
roadie-3.0.3 spec/support/have_attribute_matcher.rb
roadie-3.0.2 spec/support/have_attribute_matcher.rb
roadie-3.0.1 spec/support/have_attribute_matcher.rb
roadie-3.0.0 spec/support/have_attribute_matcher.rb