Class: Test::Unit::TestCase

Inherits:
Object show all
Defined in:
lib/rgithook/test/unit.rb

Instance Method Summary collapse

Instance Method Details

#create_rgithook_instanceObject



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rgithook/test/unit.rb', line 11

def create_rgithook_instance
  # This is not really a rgithook_instance ;-P
  ::RGitHook::Plugin.stubs(:load!)
  ::RGitHook::RGitHook.stubs(:parse_path).with(@repo).returns(@repo)
  ::RGitHook::Runner.stubs(:new).with(@repo).returns(@runner)
  @runner.stubs(:load_options).with('plugin_conf_file')
  @runner.stubs(:load).with('hooks_file')
  ::RGitHook::RGitHook.any_instance.stubs(:plugin_conf_file).returns('plugin_conf_file')
  ::RGitHook::RGitHook.any_instance.stubs(:hooks_file).returns('hooks_file')
  ::RGitHook::RGitHook.new(@repo)
end

#in_runner(code, file = nil, line = nil) ⇒ Object

Execute something in the runner



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/rgithook/test/unit.rb', line 53

def in_runner(code,file=nil,line=nil)
  file,line = caller.first.split(":") unless file && line
  if @rgithook
    @rgithook.run(code,file,line)
  else
    with_sample_rgithook do
      RGitHook::Plugin.load!
      @rgithook.run(code,file,line)
    end
  end
end

#in_sample_repoObject



36
37
38
39
40
41
# File 'lib/rgithook/test/unit.rb', line 36

def in_sample_repo
  in_temp_dir do |temp_file|
    %x(unzip #{fixture_path('sample_repo.zip')})
    yield ::Grit::Repo.new(temp_file)
  end
end

#in_temp_dir(&block) ⇒ Object

Raises:

  • (LocalJumpError)


23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rgithook/test/unit.rb', line 23

def in_temp_dir(&block)
  old_dir = Dir.pwd
  raise LocalJumpError, 'no block given' unless block_given?

  tmpdir = File.expand_path(File.join(Dir.tmpdir,'rgithook-'+Time.now.usec.to_s+rand.to_s[2..-1]))
  FileUtils.mkdir_p(tmpdir)
  Dir.chdir tmpdir
  ret_val = yield tmpdir
  Dir.chdir old_dir
  FileUtils.remove_dir(tmpdir)
  ret_val
end

#mock_repoObject



4
5
6
7
8
9
# File 'lib/rgithook/test/unit.rb', line 4

def mock_repo
  repo = mock('grit_repo')
  repo.stubs(:'is_a?').with(::Grit::Repo).returns(true)
  repo.stubs(:path).returns('path')
  repo
end

#with_sample_rgithookObject



44
45
46
47
48
49
# File 'lib/rgithook/test/unit.rb', line 44

def with_sample_rgithook
  in_sample_repo do |repo|
    @rgithook = ::RGitHook::RGitHook.new(repo)
    yield @rgithook
  end
end