Sha256: 7b42e920eb2b89e19e17210b6dfbe805135e01e3b6b414609f6ef7fdc9eba9ea

Contents?: true

Size: 866 Bytes

Versions: 16

Compression:

Stored size: 866 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

  describe { "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

16 entries across 16 versions & 1 rubygems

Version Path
roadie-2.3.3 spec/support/have_attribute_matcher.rb
roadie-2.3.2 spec/support/have_attribute_matcher.rb
roadie-2.3.1 spec/support/have_attribute_matcher.rb
roadie-2.3.0 spec/support/have_attribute_matcher.rb
roadie-2.3.0.pre1 spec/support/have_attribute_matcher.rb
roadie-2.2.0 spec/support/have_attribute_matcher.rb
roadie-2.1.0 spec/support/have_attribute_matcher.rb
roadie-2.1.0.pre2 spec/support/have_attribute_matcher.rb
roadie-2.1.0.pre1 spec/support/have_attribute_matcher.rb
roadie-2.0.0 spec/support/have_attribute_matcher.rb
roadie-1.1.3 spec/support/have_attribute_matcher.rb
roadie-1.1.1 spec/support/have_attribute_matcher.rb
roadie-1.1.2 spec/support/have_attribute_matcher.rb
roadie-1.1.0 spec/support/have_attribute_matcher.rb
roadie-1.0.1 spec/support/have_attribute_matcher.rb
roadie-1.0.0 spec/support/have_attribute_matcher.rb