1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00
haml--haml/test/test_helper.rb

97 lines
2 KiB
Ruby
Raw Normal View History

begin
if RUBY_VERSION == '2.1.0' && !defined?(Rubinius)
require 'coveralls'
Coveralls.wear!
end
rescue LoadError
# ignore error for other test Gemfiles
end
2013-11-06 15:00:41 -07:00
2012-05-22 16:03:27 -03:00
if ENV["COVERAGE"]
require "simplecov"
SimpleCov.start
end
require 'bundler/setup'
require 'minitest/autorun'
require 'action_pack'
require 'action_controller'
require 'action_view'
require 'nokogiri'
2012-05-29 15:30:36 -03:00
require 'rails'
2013-12-24 11:50:10 -07:00
if defined?(I18n.enforce_available_locales)
I18n.enforce_available_locales = true
end
2012-05-29 15:30:36 -03:00
class TestApp < Rails::Application
config.root = ""
end
2012-05-29 15:30:36 -03:00
Rails.application = TestApp
ActionController::Base.logger = Logger.new(nil)
require 'fileutils'
$VERBOSE = true
require 'haml'
2010-05-12 15:39:42 -07:00
require 'haml/template'
2012-05-21 19:10:51 -03:00
Haml::Template.options[:ugly] = false
Haml::Template.options[:format] = :xhtml
2012-05-21 19:10:51 -03:00
module Declarative
def test(name, &block)
define_method("test #{name}", &block)
end
end
class MiniTest::Unit::TestCase
2012-05-21 19:10:51 -03:00
extend Declarative
2012-07-31 01:35:08 +00:00
def render(text, options = {}, base = nil, &block)
2012-05-22 01:37:24 -03:00
scope = options.delete(:scope) || Object.new
locals = options.delete(:locals) || {}
2012-07-31 01:35:08 +00:00
engine = Haml::Engine.new(text, options)
return engine.to_html(base) if base
engine.to_html(scope, locals, &block)
2012-05-22 01:37:24 -03:00
end
def assert_warning(message)
the_real_stderr, $stderr = $stderr, StringIO.new
yield
if message.is_a?(Regexp)
assert_match message, $stderr.string.strip
else
assert_equal message.strip, $stderr.string.strip
end
ensure
$stderr = the_real_stderr
end
def silence_warnings(&block)
Haml::Util.silence_warnings(&block)
end
def rails_form_opener
2012-05-29 16:00:41 -03:00
'<div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div>'
end
def assert_raises_message(klass, message)
yield
rescue Exception => e
assert_instance_of(klass, e)
assert_equal(message, e.message)
else
flunk "Expected exception #{klass}, none raised"
end
def self.error(*args)
Haml::Error.message(*args)
end
2012-07-31 01:35:08 +00:00
end