Sha256: 38adae9891472bdaf2da8a4ca1207fa8ba8fff92b222bdc2ae91abdb8e436e5b

Contents?: true

Size: 851 Bytes

Versions: 56

Compression:

Stored size: 851 Bytes

Contents

RSpec::Matchers.define :have_content do |xpath, content|
  match do |document|
    @elements = document.search(xpath)

    if @elements.empty?
      false
    else
      element_with_content = document.at("#{xpath}[contains(.,'#{content}')]")

      if element_with_content.nil?
        @found = @elements.collect { |element| element.content }

        false
      else
        true
      end
    end
  end

  failure_message_for_should do |document|
    if @elements.empty?
      "In XML:\n#{document}\nNo element at #{xpath}"
    else
      "In XML:\n#{document}\nGot content #{@found.inspect} at #{xpath} instead of #{content.inspect}"
    end
  end

  failure_message_for_should_not do |document|
    unless @elements.empty?
      "In XML:\n#{document}\nExpcted no content #{content.inspect} at #{xpath}"
    end
  end
end

World(RSpec::Matchers)

Version data entries

56 entries across 56 versions & 6 rubygems

Version Path
cloudtrapper-0.0.3.pre features/support/matchers.rb
cloudtrapper-0.0.2.pre features/support/matchers.rb
airbrake-3.1.1 features/support/matchers.rb
airbrake-3.1.0 features/support/matchers.rb
airbrake-3.0.9 features/support/matchers.rb
airbrake-3.0.8 features/support/matchers.rb
airbrake-3.0.7 features/support/matchers.rb
airbrake-3.0.6 features/support/matchers.rb
airbrake-3.0.5 features/support/matchers.rb
airbrake-3.0.4 features/support/matchers.rb
airbrake-3.0.3 features/support/matchers.rb
airbrake-3.0.2 features/support/matchers.rb
airbrake-3.0.1 features/support/matchers.rb
airbrake-3.0 features/support/matchers.rb
airbrake-3.0.rc2 features/support/matchers.rb
airbrake-3.0.rc1 features/support/matchers.rb