Sha256: 75faa914b3cfdcba424caf54c9cd4bf1c223118d1167e3d95878501353ea6122

Contents?: true

Size: 860 Bytes

Versions: 2

Compression:

Stored size: 860 Bytes

Contents

require "nokogiri"

def equal_to_dom(text)
  EqualToDom.new(text)
end


def include_dom(text)
  IncludeDom.new(text)
end

class IncludeDom
  def initialize(expectation)
    @expectation = Nokogiri::HTML::DocumentFragment.parse(expectation).to_s
  end

  def matches?(text)
    @matcher = Nokogiri::HTML::DocumentFragment.parse(text).to_s
    @matcher.include?(@expectation)
  end

  def failure_message
    "Expected dom #{@matcher.inspect} to include #{@expectation.inspect}, but it wasn't"
  end
end


class EqualToDom

  def initialize(expectation)
    @expectation = Nokogiri::HTML::DocumentFragment.parse(expectation).to_s
  end

  def matches?(text)
    @matcher = Nokogiri::HTML::DocumentFragment.parse(text).to_s
    @matcher == @expectation
  end

  def failure_message
    "Expected dom #{@matcher} to match #{@expectation}, but it wasn't"
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
datagrid-0.2.0 spec/support/equal_to_dom.rb
datagrid-0.1.2 spec/support/equal_to_dom.rb