Sha256: fba73c94bb4aef2158d73a2a329332bfafead51a5dd842d7733bad2064f76864

Contents?: true

Size: 1.01 KB

Versions: 5

Compression:

Stored size: 1.01 KB

Contents

# coding: UTF-8
$:.unshift(File.expand_path('../../lib', __FILE__))
Encoding.default_internal = 'UTF-8'

gem 'test-unit', '>= 2' # necessary when not using bundle exec

require 'test/unit'
require 'nokogiri'

require 'greenmat'
require 'greenmat/render_strip'
require 'greenmat/render_man'

class Greenmat::TestCase < Test::Unit::TestCase
  def assert_renders(html, markdown)
    assert_equal html, render(markdown)
  end

  def render(markdown, options = {})
    options = options.fetch(:with, {})

    if options.kind_of?(Array)
      options = Hash[options.map {|o| [o, true]}]
    end

    render = begin
      renderer.new(options)
    rescue ArgumentError
      renderer.new
    end

    parser = Greenmat::Markdown.new(render, options)

    parser.render(markdown).chomp
  end

  private

  def renderer
    @renderer ||= Greenmat::Render::HTML
  end

  # Imported from Active Support
  class ::String
    def strip_heredoc
      indent = scan(/^ *(?=\S)/).min.size || 0
      gsub(/^[ \t]{#{indent}}/, '')
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
greenmat-3.5.1.4 test/test_helper.rb
greenmat-3.5.1.3 test/test_helper.rb
greenmat-3.5.1.2 test/test_helper.rb
greenmat-3.5.1.1 test/test_helper.rb
greenmat-3.5.1.0 test/test_helper.rb