Sha256: 8133ca19298ec166bd10a4ca348445f7dde3597f2a20e3673feaea40dbd80318

Contents?: true

Size: 1.12 KB

Versions: 49

Compression:

Stored size: 1.12 KB

Contents

require 'rubygems'
require 'hpricot'
require 'riot'

$:.unshift File.dirname(__FILE__)
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')

require 'toto'

module Toto
  class IncludesHTMLMacro < Riot::AssertionMacro
    register :includes_html

    def evaluate(actual, expected)
      doc = Hpricot.parse(actual)
      expected = expected.to_a.flatten

      if (doc/expected.first).empty?
        fail("expected #{actual} to contain a <#{expected.first}>")
      elsif !(doc/expected.first).inner_html.match(expected.last)
        fail("expected <#{expected.first}> to contain #{expected.last}")
      else
        pass
      end
    end
  end

  class IncludesElementsMacro < Riot::AssertionMacro
    register :includes_elements

    def evaluate(actual, selector, count)
      doc = Hpricot.parse(actual)
      (doc/selector).size == count ? pass : fail("expected #{actual} to contain #{count} #{selector}(s)")
    end
  end

  class WithinMacro < Riot::AssertionMacro
    register :within

    def evaluate(actual, expected)
      expected.include?(actual) ? pass : fail("expected #{actual} to be within #{expected}")
    end
  end
end

Version data entries

49 entries across 49 versions & 11 rubygems

Version Path
toto-0.2.5 test/test_helper.rb
toto-0.2.4 test/test_helper.rb
toto-0.2.3 test/test_helper.rb
toto-0.2.2 test/test_helper.rb
toto-0.2.1 test/test_helper.rb
toto-0.2.0 test/test_helper.rb
toto-0.1.6 test/test_helper.rb
toto-0.1.5 test/test_helper.rb
toto-0.1.4 test/test_helper.rb