captain_hoog 1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +22 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +172 -0
  6. data/Rakefile +2 -0
  7. data/bin/githoog +110 -0
  8. data/captain_hoog.gemspec +38 -0
  9. data/features/failed_hook.feature +14 -0
  10. data/features/installing_hook.feature +35 -0
  11. data/features/moving_hooks.feature +34 -0
  12. data/features/passed_hook.feature +12 -0
  13. data/features/removing_hook.feature +33 -0
  14. data/features/support/env.rb +43 -0
  15. data/features/support/steps/hooks_steps.rb +63 -0
  16. data/features/support/world.rb +30 -0
  17. data/lib/captain_hoog/delegatable.rb +33 -0
  18. data/lib/captain_hoog/dependencies.rb +2 -0
  19. data/lib/captain_hoog/env.rb +17 -0
  20. data/lib/captain_hoog/errors/dsl_errors.rb +6 -0
  21. data/lib/captain_hoog/errors.rb +1 -0
  22. data/lib/captain_hoog/git.rb +72 -0
  23. data/lib/captain_hoog/helper_table.rb +23 -0
  24. data/lib/captain_hoog/plugin.rb +67 -0
  25. data/lib/captain_hoog/plugin_list.rb +29 -0
  26. data/lib/captain_hoog/pre_git.rb +125 -0
  27. data/lib/captain_hoog/templates/hoogfile.erb +39 -0
  28. data/lib/captain_hoog/templates/install.erb +20 -0
  29. data/lib/captain_hoog/version.rb +3 -0
  30. data/lib/captain_hoog.rb +14 -0
  31. data/spec/fixtures/code/helper.rb +13 -0
  32. data/spec/fixtures/plugins/shared/passing/simple_shared.rb +11 -0
  33. data/spec/fixtures/plugins/test_plugins/failing/simple.rb +15 -0
  34. data/spec/fixtures/plugins/test_plugins/passing/simple.rb +11 -0
  35. data/spec/fixtures/pre-commit-fail +25 -0
  36. data/spec/fixtures/pre-commit-pass +25 -0
  37. data/spec/lib/captain_hoog/env_spec.rb +31 -0
  38. data/spec/lib/captain_hoog/git_spec.rb +185 -0
  39. data/spec/lib/captain_hoog/plugin_list_spec.rb +42 -0
  40. data/spec/lib/captain_hoog/plugin_spec.rb +101 -0
  41. data/spec/lib/captain_hoog/pre_git_spec.rb +107 -0
  42. data/spec/spec_helper.rb +8 -0
  43. data/spec/support/matchers/be_subclass_of.rb +13 -0
  44. metadata +236 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 76efe495daab6c9cb797d8655f422921bb5df37b
4
+ data.tar.gz: 4af041128e853f57f09fbc8f00f38abd75c91340
5
+ SHA512:
6
+ metadata.gz: 83dca455c5b053422a4302622da2becb562c62a11ce45d5a07b363859b5caf9b813ebcd8a666c6b8d44e98dc052edeffcbd894abcf40324768b1c5b0efe401f1
7
+ data.tar.gz: 3d89084556792db6e51a56ab884065396ab41b3d074e36595c0d9f39ef0ee076f95c3a50d6876ba0e7ca185cb23cedca886243ec8dee66404b3c9f4394cbdf42
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in captain_hoog.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Daniel Schmidt
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,172 @@
1
+ # CaptainHoog
2
+
3
+ Okay. That's not such a funny gem name. But it's a reference to Git and the subject
4
+ of the gem: the Git Hooks.
5
+
6
+ <img src="http://dyxygd30hex7h.cloudfront.net/sites/www.prismaticart.com/files/PRISMATIC_ADAM.jpg" height="450">
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'captain_hoog'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install captain_hoog
21
+
22
+ ## Usage
23
+
24
+ ### Install the hook
25
+
26
+ ```
27
+ githoog install --type <GIT_HOOK_TYPE> --plugins_dir <PATH_TO_PLUGINS> --project_dir <PATH_TO_PROJECT>
28
+ ```
29
+
30
+ **Please note:** ```<PATH_TO_PLUGINS>``` and ```<PATH_TO_PROJECT>``` must be given as absolute paths.
31
+ Also make sure to run this from your git repository's root folder.
32
+
33
+ ```GIT_HOOK_TYPE``` may be something like this
34
+
35
+ * pre-commit (default)
36
+ * pre-push
37
+ * pre-rebase
38
+ * pre-applypatch
39
+
40
+ If the directory where pre-git test should be done, differs from the working directory adjust:
41
+
42
+ ```
43
+ --project_dir
44
+ ```
45
+
46
+ to your needs. You can omit this.
47
+
48
+ ```
49
+ --plugins_dir
50
+ ```
51
+
52
+ is not required anymore. If it's omited it will point to the actual directory you run the install script from. It should point to the directory you store the CaptainHoog plugins.
53
+
54
+ _A note about plugin directories:_ All plugins must be placed in one directory. You can select which plugin is called from which Git hook later by defining it in the Hoogfile.
55
+
56
+ ### Removing the hook
57
+
58
+ Remove a hook by using the
59
+
60
+ ```
61
+ githoog remove --type <GIT_HOOK_TYPE>
62
+ ```
63
+
64
+ command.
65
+
66
+ where ```<GIT_HOOK_TYPE>``` is ```pre-commit``` by default.
67
+
68
+ ### The Hoogfile
69
+
70
+ All plugin executable and ignoring power is configurable in the Hoogfile. The Hoogfile's name is ```hoogfile.yml``` and it will be installed in your Git root directory. If you install several hooks, the installer will ask you if you want to override the config file.
71
+
72
+ The Hoogfile has several sections:
73
+
74
+ * hook plugins per type
75
+ * project dir
76
+ * plugins dir
77
+
78
+ Some options are predefined from your information you provided during installation:
79
+
80
+ * project dir
81
+ * plugins dir
82
+
83
+ If this did not matches your need anymore, just pass the new paths in there.
84
+
85
+ Captain Hoog is doing nothing by default. You have explicitly define which plugins it should run or which not. You do this per hook type. E.g. for ```pre-commit```:
86
+
87
+ ```
88
+ pre-commit:
89
+ - cucumber
90
+ - rspec
91
+ ```
92
+
93
+ So the plugins named **cucumber** and **rspec** are running before your commit applies to the index.
94
+
95
+
96
+
97
+ ### Migrating from pre 1.0 versions
98
+
99
+ There is no migration path from previous versions. Just re-install and adjust the Hoogfile to your previous configuration.
100
+
101
+ ### Writing plugins
102
+
103
+ A CaptainHoog plugin is written with a very simple DSL that used with the following expressions:
104
+
105
+ * ```test```
106
+ * ```message```
107
+ * ```helper```
108
+ * ```run```
109
+
110
+ Within ```test``` any stuff is done that either forces the commit to exit or
111
+ to pass. Whatever you want to do like syntax checking, code style checking -
112
+ implement it and make sure you return a boolean value.
113
+
114
+ ```message``` is used to define a notifiaction that is shown to the user if
115
+ the test **fails**. This obviously must return a String.
116
+
117
+ You have to add a description (or name) to your plugin, this description (or name) will be used to check if the plugin should be executed or not by adding the plugins name to the section <hook plugins per type> of your Hoogfile.
118
+
119
+ ```rb
120
+ git.describe 'sample' do |pre|
121
+
122
+ pre.test do
123
+ # do any test like code style guide, syntax checking...
124
+ # Must return a boolean value.
125
+ end
126
+
127
+ pre.message do
128
+ # Define a message string here that is shown if the test fails.
129
+ end
130
+
131
+ end
132
+ ```
133
+
134
+ With ```helper``` you can extract some logic into a helper method that is useable anywhere
135
+ in the plugin.
136
+
137
+ ```rb
138
+ git.describe 'logger' do |pre|
139
+
140
+ pre.helper :collect_logger_outputs do
141
+ # do something
142
+ end
143
+
144
+ pre.test do
145
+ collect_logger_outputs.empty?
146
+ end
147
+
148
+ pre.message do
149
+ %q{ You have some logger outputs in your code! }
150
+ end
151
+ end
152
+ ```
153
+
154
+ If you don't want to test anything before commiting or pushing thus just running
155
+ a command or something similiar, use the ```run``` method.
156
+
157
+ ```rb
158
+ git.describe 'name of Git head' do |pre|
159
+
160
+ pre.run do
161
+ system "git show --name-only HEAD"
162
+ end
163
+
164
+ end
165
+
166
+ ```
167
+
168
+ ## Last stuff
169
+
170
+ Init and written by Daniel Schmidt (daniel.schmidt@gateprotect.com)
171
+
172
+ Image "Captain Hook" © 2012 Brian Patterson
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/githoog ADDED
@@ -0,0 +1,110 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'thor'
4
+ require 'colorize'
5
+
6
+ class GitHookInstall < Thor
7
+ include Thor::Actions
8
+
9
+ def self.exit_on_failure?
10
+ true
11
+ end
12
+
13
+ def self.source_root
14
+ File.join(File.dirname(__FILE__),"..", "lib", "captain_hoog", "templates")
15
+ end
16
+
17
+ class_option :type, type: :string, default: 'pre-commit'
18
+ class_option :project_dir, type: :string, default: Dir.getwd
19
+ class_option :plugins_dir, type: :string, default: Dir.getwd
20
+
21
+ desc "install","Installs the hook into your Git repository"
22
+ def install(*args)
23
+ check_if_git_present
24
+ check_if_option_present("plugins_dir")
25
+ # deprecated:
26
+ # "#{options[:plugins_dir]}/#{options[:type]}"
27
+ install_hook({ as: options[:type],
28
+ context: {
29
+ root_dir: Dir.getwd,
30
+ plugins_dir: options[:plugins_dir],
31
+ project_dir: options[:project_dir]
32
+ }
33
+ })
34
+ puts "Installed hook as #{options[:type]} hook".green
35
+ end
36
+
37
+ desc "remove", "Removes a hook from your Git repository"
38
+ def remove(*args)
39
+ check_if_git_present
40
+ remove_hook(as: options[:type])
41
+ puts "The #{options[:type]} hook is removed.".green
42
+ end
43
+
44
+ option :from, type: :string, required: true
45
+ option :to, type: :string, required: true
46
+ desc "move", "Moves a hook from type to another"
47
+ def move(*args)
48
+ check_if_git_present
49
+ if options[:from] == options[:to]
50
+ puts "--from and --to arguments are the same".red
51
+ raise Thor::Error
52
+ else
53
+ move_hook(options)
54
+ puts "The #{options[:from]} hook is moved to #{options[:to]} hook.".green
55
+ end
56
+ end
57
+
58
+ private
59
+
60
+ def is_git_repository?
61
+ File.exists?(File.join(Dir.getwd, ".git"))
62
+ end
63
+
64
+ def install_hook(config)
65
+ opts = config[:context]
66
+ opts[:type] = config[:as]
67
+ copy_config_file(opts)
68
+ template("install.erb",File.join(hooks_dir, config[:as]), opts)
69
+ FileUtils.chmod(0755,File.join(hooks_dir, config[:as]))
70
+ end
71
+
72
+ def remove_hook(config)
73
+ FileUtils.rm_rf(File.join(hooks_dir, config[:as]))
74
+ end
75
+
76
+ def move_hook(config)
77
+ from = File.join(hooks_dir, config[:from])
78
+ to = File.join(hooks_dir, config[:to])
79
+ FileUtils.mv(from, to)
80
+ end
81
+
82
+ def hooks_dir
83
+ git_dir.join(".git", "hooks")
84
+ end
85
+
86
+ def git_dir
87
+ Pathname.new(Dir.getwd)
88
+ end
89
+
90
+ def check_if_git_present
91
+ if not is_git_repository?
92
+ puts "I can't detect a Git repository".red
93
+ raise Thor::Error
94
+ end
95
+ end
96
+
97
+ def check_if_option_present(type)
98
+ unless options.has_key?(type)
99
+ puts "No value provided for required options '--#{type}'".red
100
+ raise Thor::Error
101
+ end
102
+ end
103
+
104
+ def copy_config_file(opts={})
105
+ template('hoogfile.erb', git_dir.join('hoogfile.yml'), opts)
106
+ end
107
+
108
+ end
109
+
110
+ GitHookInstall.start(ARGV)
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'captain_hoog/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "captain_hoog"
8
+ spec.version = CaptainHoog::VERSION
9
+ spec.authors = ["Daniel Schmidt"]
10
+ spec.email = ["daniel.schmidt@adytonsystems.com"]
11
+ spec.summary = %q{ Plugin based git-pre hook.}
12
+ spec.homepage = ""
13
+ spec.license = "MIT"
14
+ spec.post_install_message = %Q{
15
+ Thanks for installing the Pre-Git whatever hooker!
16
+
17
+ If you don't have already, please install the hook:
18
+
19
+ githoog install --type <GIT_HOOK_TYPE> --plugins_dir <PATH_TO_PLUGINS> \
20
+ --project_dir <PATH_TO_PROJECT>
21
+ }
22
+
23
+
24
+ spec.files = `git ls-files -z`.split("\x0")
25
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f)}
26
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_runtime_dependency "colorize", '~> 0.7', '>= 0.7.3'
30
+ spec.add_runtime_dependency "thor", '~> 0.19', '>= 0.19.1'
31
+ spec.add_runtime_dependency "terminal-table", '~> 1.4.5'
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.6"
34
+ spec.add_development_dependency "rake"
35
+ spec.add_development_dependency "rspec"
36
+ spec.add_development_dependency "cucumber"
37
+ spec.add_development_dependency "aruba"
38
+ end
@@ -0,0 +1,14 @@
1
+ Feature: Having a hook plugin that fails
2
+ In order to have a commit to take place
3
+ As developer that did something wrong
4
+ I want to see that the hook test failed
5
+
6
+ Scenario: Running a unsuccessful commit test
7
+ When I run `ruby pre-commit-fail`
8
+ Then it should fail with:
9
+ """
10
+ Commit failed. See errors below.
11
+
12
+ The test failed in with_git. Prevent you from doing anything.
13
+ """
14
+ And the exit status should be 1
@@ -0,0 +1,35 @@
1
+ Feature: Installing a Git hook with the gem
2
+ In order to use the plugin based Git hook
3
+ As developer
4
+ I want to run the install script
5
+
6
+ Scenario: Not having a Git directory
7
+ Given I am in a directory that isnt a Git repository
8
+ When I run the install script with "pre-commit" type flag
9
+ Then it should fail with:
10
+ """
11
+ I can't detect a Git repository
12
+ """
13
+
14
+ Scenario Outline: Having a Git repository and installing hook
15
+ Given I am in a directory that is a Git repository
16
+ When I run the install script with "<Hook>" type flag
17
+ Then it should pass with:
18
+ """
19
+ Installed hook as <Hook> hook
20
+ """
21
+ And a "<Hook>" hook file exists
22
+ And a hook config file exists
23
+ And the config file includes the "plugins" directory
24
+ And the config file includes the "project" directory
25
+
26
+ Examples:
27
+ | Hook |
28
+ | pre-commit |
29
+ | pre-push |
30
+ | pre-rebase |
31
+ | post-update |
32
+ | commit-msg |
33
+ | applypatch-msg |
34
+ | post-update |
35
+ | pre-applypatch |
@@ -0,0 +1,34 @@
1
+ Feature: Moving a Git hook with the gem to another hook type
2
+ In order to move an installed hook to another hook type
3
+ As developer
4
+ I want to move the hook with the script
5
+
6
+ Scenario: Not having a Git repository
7
+ Given I am in a directory that isnt a Git repository
8
+ When I run the move script with "pre-commit" from flag and "pre-push" to flag
9
+ Then it should fail with:
10
+ """
11
+ I can't detect a Git repository
12
+ """
13
+
14
+ Scenario Outline: Having a Git repository and moving a hook
15
+ Given I am in a directory that is a Git repository
16
+ And a "<From>" is present
17
+ And I run the move script with "<From>" from flag and "<To>" to flag
18
+ Then it should pass with:
19
+ """
20
+ The <From> hook is moved to <To> hook
21
+ """
22
+ And a "<To>" hook file exists
23
+ And a "<From>" hook file did not exists
24
+
25
+ Examples:
26
+ |From | To |
27
+ | pre-commit | pre-push |
28
+ | pre-push | pre-rebase |
29
+ | pre-rebase | post-update |
30
+ | post-update | commit-msg |
31
+ | commit-msg | applypatch-msg |
32
+ | applypatch-msg | post-update |
33
+ | post-update | pre-applypatch |
34
+ | pre-applypatch | pre-commit |
@@ -0,0 +1,12 @@
1
+ Feature: Having a hook plugin that passed
2
+ In order to have a commit to take place
3
+ As developer
4
+ I want to see the hook test passed
5
+
6
+ Scenario: Running a successful commit test
7
+ When I run `ruby pre-commit-pass`
8
+ Then it should pass with:
9
+ """
10
+ All tests passed. No reason to prevent the commit.
11
+ """
12
+ And the exit status should be 0
@@ -0,0 +1,33 @@
1
+ Feature: Removing a Git hook with the gem
2
+ In order to remove an installed hook
3
+ As developer
4
+ I want to remove the hook with the script
5
+
6
+ Scenario: Not having a Git repository
7
+ Given I am in a directory that isnt a Git repository
8
+ When I run the remove script with "pre-commit" type flag
9
+ Then it should fail with:
10
+ """
11
+ I can't detect a Git repository
12
+ """
13
+
14
+ Scenario Outline: Having a Git repository and removing a hook
15
+ Given I am in a directory that is a Git repository
16
+ And a "<Hook>" is present
17
+ And I run the remove script with "<Hook>" type flag
18
+ Then it should pass with:
19
+ """
20
+ The <Hook> hook is removed.
21
+ """
22
+ And a "<Hook>" hook file did not exists
23
+
24
+ Examples:
25
+ | Hook |
26
+ | pre-commit |
27
+ | pre-push |
28
+ | pre-rebase |
29
+ | post-update |
30
+ | commit-msg |
31
+ | applypatch-msg |
32
+ | post-update |
33
+ | pre-applypatch |
@@ -0,0 +1,43 @@
1
+ require 'cucumber'
2
+ require 'aruba/cucumber'
3
+
4
+ require 'rspec/expectations'
5
+
6
+ FIXTURES_PATH = File.expand_path(File.join(File.dirname(__FILE__),
7
+ "..",
8
+ "..",
9
+ "spec",
10
+ "fixtures"))
11
+
12
+ Before do
13
+ $git_fixture_dir_exists ||= false
14
+ @dirs = [FIXTURES_PATH]
15
+ ["no_git", "with_git"].each do |dir|
16
+ git_path = File.join(FIXTURES_PATH, dir)
17
+ FileUtils.mkdir_p(git_path)
18
+ if dir.eql?("with_git")
19
+ Dir.chdir(git_path)
20
+ `git init .`
21
+ end
22
+ end
23
+ $git_fixture_dir_exists = true
24
+ end
25
+
26
+
27
+ After do
28
+ FileUtils.rm_rf(File.join(FIXTURES_PATH, 'with_git', 'hoogfile.yml'))
29
+ %w{ pre-commit
30
+ pre-push
31
+ pre-rebase
32
+ post-update
33
+ commit-msg
34
+ applypatch-msg
35
+ post-update
36
+ pre-applypatch }.each do |hook_type|
37
+ FileUtils.rm_rf(File.join(FIXTURES_PATH,
38
+ "with_git",
39
+ ".git",
40
+ "hooks",
41
+ hook_type))
42
+ end
43
+ end
@@ -0,0 +1,63 @@
1
+ When(/^I run a commit hook that might succeeds$/) do
2
+ hook_path = File.expand_path(File.join(File.dirname(__FILE__),
3
+ "..",
4
+ "..",
5
+ "..",
6
+ "spec",
7
+ "fixtures"))
8
+ FileUtils.chdir(hook_path)
9
+
10
+ end
11
+
12
+ When(/^I run the install script with "(.*?)" type flag$/) do |commit_type|
13
+ @dir = git_project_path.to_s
14
+ run_simple(unescape("ruby #{bin_path}/bin/githoog install --type #{commit_type} --plugins_dir #{@dir}"),
15
+ false)
16
+ end
17
+
18
+ When(/^I run the remove script with "(.*?)" type flag$/) do |commit_type|
19
+ run_simple(unescape("ruby #{bin_path}/bin/githoog remove --type #{commit_type} --plugins_dir /home"),
20
+ false)
21
+ end
22
+
23
+ Given(/^I am in a directory that isnt a Git repository$/) do
24
+ not_git_repo = "no_git"
25
+ cd(not_git_repo)
26
+ end
27
+
28
+ Given(/^I am in a directory that is a Git repository$/) do
29
+ git_repo = "with_git"
30
+ cd(git_repo)
31
+ end
32
+
33
+ Then(/^a "(.*?)" hook file exists$/) do |hook_type|
34
+ expect(File.exists?(hooks_path(hook_type))).to be true
35
+ end
36
+
37
+ Given(/^a "(.*?)" is present$/) do |hook_type|
38
+ FileUtils.touch(hooks_path(hook_type))
39
+ end
40
+
41
+ Then(/^a "(.*?)" hook file did not exists$/) do |hook_type|
42
+ expect(File.exists?(hooks_path(hook_type))).to be false
43
+ end
44
+
45
+ When(/^I run the move script with "(.*?)" from flag and "(.*?)" to flag$/) do |from, to|
46
+ cmd = "ruby #{bin_path}/bin/githoog move --from #{from} --to #{to}"
47
+ run_simple(unescape(cmd), false)
48
+ end
49
+
50
+ When(/^I run the install script without "(.*?)" flag$/) do |type_flag|
51
+ cmd = "ruby #{bin_path}/bin/githoog install"
52
+ run_simple(unescape(cmd),false)
53
+ end
54
+
55
+ Then(/^a hook config file exists$/) do
56
+ expect(File.exists?(hook_config_file_path)).to be true
57
+ end
58
+
59
+ Then(/^the config file includes the "(.*?)" directory$/) do |config_path|
60
+ config = YAML.load_file(hook_config_file_path)
61
+ expect(config).to have_key("#{config_path}_dir")
62
+ expect(config["#{config_path}_dir"]).to include @dir
63
+ end
@@ -0,0 +1,30 @@
1
+ module FileWorld
2
+ def bin_path
3
+ File.expand_path(File.join(File.dirname(__FILE__),
4
+ "..",
5
+ ".."))
6
+ end
7
+
8
+ def git_project_path
9
+ f = File.expand_path(File.join(File.dirname(__FILE__),
10
+ "..",
11
+ "..",
12
+ "spec",
13
+ "fixtures",
14
+ "with_git"))
15
+ Pathname.new(f)
16
+ end
17
+
18
+ def hooks_path(type)
19
+ path = git_project_path.join(".git",
20
+ "hooks",
21
+ type)
22
+ path
23
+ end
24
+
25
+ def hook_config_file_path
26
+ git_project_path.join('hoogfile.yml')
27
+ end
28
+ end
29
+
30
+ World(FileWorld)
@@ -0,0 +1,33 @@
1
+ module CaptainHoog
2
+ module Delegatable
3
+ def self.included(base)
4
+ base.class_eval do
5
+ extend ClassMethods
6
+ include InstanceMethods
7
+ end
8
+ end
9
+
10
+ module ClassMethods
11
+ def delegate_to(target_object)
12
+ define_method :delegate_to do
13
+ self.instance_variable_get("@#{target_object}")
14
+ end
15
+ end
16
+ end
17
+
18
+ module InstanceMethods
19
+
20
+ def method_missing(method_name, *args, &block)
21
+ if delegate_to.respond_to?(method_name)
22
+ delegate_to.send(method_name, *args, &block)
23
+ else
24
+ super
25
+ end
26
+ end
27
+
28
+ def respond_to_missing?(method_name, include_private=false)
29
+ delegate_to.respond_to?(method_name) || super
30
+ end
31
+ end
32
+ end
33
+ end