Created
April 9, 2009 13:35
-
-
Save snusnu/92470 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1) put it somewhere (e.g. 'specs/shared/rspec_tmbundle_support') | |
# 2) require it from spec_helper.rb like so (put it at the bottom) | |
# allow people to opt out | |
# set to false if not using textmate | |
USE_TEXTMATE_RSPEC_BUNDLE = true | |
if USE_TEXTMATE_RSPEC_BUNDLE | |
require Pathname(__FILE__).dirname.expand_path + 'shared/rspec_tmbundle_support' | |
# use the tmbundle logger | |
RSpecTmBundleHelpers::TextmateRspecLogger.new(STDOUT, :off) | |
# make it available everywhere during spec runs | |
class Object | |
include RSpecTmBundleHelpers | |
end | |
end | |
# ----------------------------------------------- | |
# support for nice html output in rspec tmbundle | |
# ----------------------------------------------- | |
module RSpecTmBundleHelpers | |
class TextmateRspecLogger < DataMapper::Logger | |
def prep_msg(message, level) | |
"#{super}<br />" | |
end | |
end | |
def with_dm_logger(level = :debug) | |
DataMapper.logger.level = level | |
yield | |
ensure | |
DataMapper.logger.level = :off | |
end | |
def print_call_stack(from = 2, to = nil, html = true) | |
(from..(to ? to : caller.length)).each do |idx| | |
p "[#{idx}]: #{caller[idx]}#{html ? '<br />' : ''}" | |
end | |
end | |
def puth(html) | |
print "#{h(html)}<br />" | |
end | |
ESCAPE_TABLE = { '&'=>'&', '<'=>'<', '>'=>'>', '"'=>'"', "'"=>''', } | |
def h(value) | |
value.to_s.gsub(/[&<>"]/) {|s| ESCAPE_TABLE[s] } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment