Class: Test::Unit::TestCase
Instance Method Summary collapse
- #create_rgithook_instance ⇒ Object
-
#in_runner(code, file = nil, line = nil) ⇒ Object
Execute something in the runner.
- #in_sample_repo ⇒ Object
- #in_temp_dir(&block) ⇒ Object
- #mock_repo ⇒ Object
- #with_sample_rgithook ⇒ Object
Instance Method Details
#create_rgithook_instance ⇒ Object
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_repo ⇒ Object
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
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.(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_repo ⇒ Object
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 |