spec/spec_helper.rb in git-topic-0.2.5 vs spec/spec_helper.rb in git-topic-0.2.6

- old
+ new

@@ -13,14 +13,14 @@ class << GitTopic %w( current_branch remote_branches remote_branches_organized branches ).each do |m| define_method( "#{m}_with_nocache" ) do - rv = send( "#{m}_without_nocache" ) - GitTopic::Naming::ClassMethods.class_variable_set( "@@#{m}", nil ) - GitTopic::Git::ClassMethods.class_variable_set( "@@#{m}", nil ) - rv + send( "#{m}_without_nocache" ).tap do + GitTopic::Naming::ClassMethods.class_variable_set( "@@#{m}", nil ) + GitTopic::Git::ClassMethods.class_variable_set( "@@#{m}", nil ) + end end alias_method_chain m.to_sym, :nocache end def git_with_implicit_capture( cmds=[], opts={} ) @@ -30,20 +30,27 @@ git_without_implicit_capture( cmds, opts ) end end alias_method_chain :git, :implicit_capture - def invoke_git_editor( file ) + def invoke_git_editor file raise " invoke_git_editor invoked with (#{file}). If you expect this method to be called, mock or stub it. ".oneline end end +class << GitTopic::Logger + def logger_with_nocache + logger_without_nocache.tap{ @logger = nil } + end + alias_method_chain :logger, :nocache +end + # Track original $stdout, $stderr write methods so we can “unmock” them for # debugging class << $stdout alias_method :real_write, :write @@ -61,10 +68,11 @@ end class << $stderr alias_method :write, :real_write end + $debugging = true require 'ruby-debug' debugger end end @@ -74,16 +82,18 @@ Rspec.configure do |c| c.before( :all ) do @starting_dir = Dir.pwd @user = ENV['USER'] || `whoami` + ENV['HOME'] = "#{@starting_dir}/tmp/home" end c.before( :each ) do # setup the directories FileUtils.rm_rf './tmp' FileUtils.mkdir './tmp' + FileUtils.mkdir './tmp/home' # Copy our repos into tmp %w(fresh in-progress).each do |d| FileUtils.mkdir "./tmp/#{d}" FileUtils.cp_r "spec/template/#{d}", "./tmp/#{d}/.git" @@ -103,10 +113,14 @@ end if File.exists? ".git/refs/notes/reviews/USER" FileUtils.mv ".git/refs/notes/reviews/USER", ".git/refs/notes/reviews/#{@user}" end + if File.exists? "./refs/notes/reviews/USER" + FileUtils.mv "./refs/notes/reviews/USER", + "./refs/notes/reviews/#{@user}" + end Dir.chdir @starting_dir end Dir.chdir "#{@starting_dir}/tmp" # capture output @@ -125,11 +139,11 @@ # helpers # {{{ def use_repo( repo ) - Dir.chdir( repo ) + Dir.chdir( "#{@starting_dir}/tmp/#{repo}" ) # Exit if e.g. GIT_DIR is set raise "Spec error" unless git_dir == '.git' end @@ -142,19 +156,23 @@ current_branch = all_branches.find{|b| b =~ /^\*/} current_branch[ 2..-1 ] unless current_branch.nil? end -def git_head - `git rev-parse HEAD`.chomp +def git_head suffix=nil + `git rev-parse HEAD#{suffix}`.chomp end +def git_remote branch + `git rev-parse #{branch}`.chomp +end + def git_origin_master `git rev-parse origin/master`.chomp end -def git_config( key ) +def git_config key `git config #{key}`.chomp end def git_branch_merge git_config "branch.#{git_branch}.merge" @@ -176,11 +194,11 @@ bn.gsub! %r{ ->.*$}, '' bn end end -def git_notes_list( ref ) +def git_notes_list ref `git notes --ref #{ref}`.split( "\n" ) end def git_notes_show( ref, commit='HEAD' ) `git notes --ref #{ref} show #{commit}`.chomp @@ -195,15 +213,16 @@ File.open( 'dirty', 'w' ){|f| f.puts "some content" } system "git add -N dirty" end -def with_argv( val ) +def with_argv *val restore = ARGV.dup - ARGV.replace( val ) + ARGV.replace( val.flatten ) rv = yield ARGV.replace( restore ) rv end + # }}}