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 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
require File.expand_path(File.dirname(__FILE__) + "/../lib/ticgit-ng")
require 'fileutils'
require 'logger'
require 'tempfile'
TICGITNG_HISTORY = StringIO.new
module TicGitNGSpecHelper
=begin
tempdir -
test => "content"
subdir -
testfile => "content2"
=end
def setup_new_git_repo prefix='ticgit-ng-gitdir-'
tempdir = Dir.mktmpdir prefix
Dir.chdir(tempdir) do
git = Git.init
new_file('test', 'content')
Dir.mkdir('subdir')
new_file('subdir/testfile', 'content2')
git.add
git.commit('first commit')
end
tempdir
end
def test_opts
tempdir = Dir.mktmpdir 'ticgit-ng-ticdir-'
logger = Logger.new(Tempfile.new('ticgit-ng-log-'))
{ :tic_dir => tempdir, :logger => logger, :init => true }
end
def new_file(name, contents)
File.open(name, 'w') do |f|
f.puts contents
end
end
def format_expected(string)
string.enum_for(:each_line).map{|line| line.strip }
end
def cli(path, *args, &block)
TICGITNG_HISTORY.truncate 0
TICGITNG_HISTORY.rewind
ticgitng = TicGitNG::CLI.new(args.flatten, path, TICGITNG_HISTORY)
ticgitng.parse_options!
ticgitng.execute!
replay_history(&block)
rescue SystemExit => error
replay_history(&block)
end
def replay_history
TICGITNG_HISTORY.rewind
return unless block_given?
while line = TICGITNG_HISTORY.gets
yield(line.strip)
end
end
def read_line_of filename
File.open(filename, "r").each_line do |line|
return line
end
end
def time_skew
Time.now.to_i + rand(1000)
end
end
##
# rSpec Hash additions.
#
# From
# * http://wincent.com/knowledge-base/Fixtures_considered_harmful%3F
# * Neil Rahilly
class Hash
##
# Filter keys out of a Hash.
#
# { :a => 1, :b => 2, :c => 3 }.except(:a)
# => { :b => 2, :c => 3 }
def except(*keys)
self.reject { |k,v| keys.include?(k || k.to_sym) }
end
##
# Override some keys.
#
# { :a => 1, :b => 2, :c => 3 }.with(:a => 4)
# => { :a => 4, :b => 2, :c => 3 }
def with(overrides = {})
self.merge overrides
end
##
# Returns a Hash with only the pairs identified by +keys+.
#
# { :a => 1, :b => 2, :c => 3 }.only(:a)
# => { :a => 1 }
def only(*keys)
self.reject { |k,v| !keys.include?(k || k.to_sym) }
end
end
|