snusnu (owner)

Revisions

gist: 92470 Download_button fork
public
Public Clone URL: git://gist.github.com/92470.git
Embed All Files: show embed
Ruby #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# 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 = { '&'=>'&amp;', '<'=>'&lt;', '>'=>'&gt;', '"'=>'&quot;', "'"=>'&#039;', }
  def h(value)
    value.to_s.gsub(/[&<>"]/) {|s| ESCAPE_TABLE[s] }
  end
  
end