forked from gollum/gollum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.rb
96 lines (80 loc) · 2.1 KB
/
helper.rb
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
require 'rubygems'
require 'rack/test'
require 'test/unit'
require 'shoulda'
require 'mocha/setup'
require 'fileutils'
require 'minitest/reporters'
require 'twitter_cldr'
require 'tmpdir'
# Silence locale validation warning
require 'i18n'
I18n.enforce_available_locales = false
MiniTest::Reporters.use!
dir = File.dirname(File.expand_path(__FILE__))
$LOAD_PATH.unshift(File.join(dir, '..', 'lib'))
$LOAD_PATH.unshift(dir)
module Gollum
end
if ENV['GIT_ADAPTER']
Gollum::GIT_ADAPTER = ENV['GIT_ADAPTER']
else
Gollum::GIT_ADAPTER = RUBY_PLATFORM == 'java' ? 'rjgit' : 'rugged'
end
ENV['RACK_ENV'] = 'test'
require 'gollum'
require 'gollum/app'
# Disable the metadata feature
$METADATA = false
# Make sure we're in the test dir, the tests expect that to be the current
# directory.
TEST_DIR = File.join(File.dirname(__FILE__), *%w[.])
def testpath(path)
File.join(TEST_DIR, path)
end
def cloned_testpath(path, bare = false)
repo = File.expand_path(testpath(path))
tmpdir = Dir.mktmpdir(self.class.name)
bare = bare ? "--bare" : ""
redirect = Gem.win_platform? ? '' : '2>/dev/null'
%x{git clone #{bare} '#{repo}' #{tmpdir} #{redirect}}
tmpdir
end
def commit_details
{ :message => "Did something at #{Time.now}",
:name => "Tom Preston-Werner",
:email => "[email protected]" }
end
def normal(text)
text.gsub!(' ', '')
text.gsub!("\n", '')
text
end
# test/spec/mini 3
# http://gist.github.com/25455
# file:lib/test/spec/mini.rb
def context(*args, &block)
return super unless (name = args.first) && block
require 'test/unit'
klass = Class.new(defined?(ActiveSupport::TestCase) ? ActiveSupport::TestCase : Test::Unit::TestCase) do
def self.test(name, &block)
define_method("test_#{name.gsub(/\W/, '_')}", &block) if block
end
def self.xtest(*args)
end
def self.setup(&block)
define_method(:setup, &block)
end
def self.teardown(&block)
define_method(:teardown, &block)
end
end
(
class << klass;
self
end).send(:define_method, :name) { name.gsub(/\W/, '_') }
$contexts << klass
klass.class_eval &block
end
$contexts = []