Sha256: b9017f2caa790f02cd7886d6c16dae90311af353014bfca1800d6a01c6e2ef25

Contents?: true

Size: 869 Bytes

Versions: 7

Compression:

Stored size: 869 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_for_should 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_for_should_not 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 7 versions & 2 rubygems

Version Path
roadie-2.4.3 spec/support/have_attribute_matcher.rb
roadie-3.0.0.pre1 spec/support/have_attribute_matcher.rb
md-roadie-2.4.2.md.1 spec/support/have_attribute_matcher.rb
roadie-2.4.2 spec/support/have_attribute_matcher.rb
roadie-2.4.1 spec/support/have_attribute_matcher.rb
roadie-2.4.0 spec/support/have_attribute_matcher.rb
roadie-2.3.4 spec/support/have_attribute_matcher.rb