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
@@ -0,0 +1,185 @@
1
+ require 'spec_helper'
2
+
3
+ describe CaptainHoog::Git do
4
+
5
+ describe "DSL" do
6
+
7
+ subject{ CaptainHoog::Git.new }
8
+
9
+ it "has #test method" do
10
+ expect(subject).to respond_to(:test)
11
+ end
12
+
13
+ it "has #message method" do
14
+ expect(subject).to respond_to(:message)
15
+ end
16
+
17
+ it "has #env method" do
18
+ expect(subject).to respond_to(:env)
19
+ end
20
+
21
+ it "has #env= method" do
22
+ expect(subject).to respond_to(:env=)
23
+ end
24
+
25
+ it "has #helper method" do
26
+ expect(subject).to respond_to(:helper)
27
+ end
28
+
29
+ it "has #render_table method" do
30
+ expect(subject).to respond_to(:render_table)
31
+ end
32
+
33
+ it "has #run method" do
34
+ expect(subject).to respond_to(:run)
35
+ end
36
+
37
+ describe "#test" do
38
+
39
+ context "returning a non boolean value" do
40
+ before do
41
+ subject.test do
42
+ "Hello"
43
+ end
44
+ end
45
+ it "raises error" do
46
+ expect do
47
+ subject.execute
48
+ end.to raise_error(CaptainHoog::Errors::TestResultNotValidError)
49
+ end
50
+
51
+ end
52
+
53
+ context "returning a boolean value" do
54
+
55
+ it "did not raises an error" do
56
+ expect do
57
+ subject.test do
58
+ false
59
+ end
60
+ end.not_to raise_error
61
+ end
62
+
63
+ end
64
+ end
65
+
66
+ describe "#message" do
67
+
68
+ context "returning not a String" do
69
+
70
+ it "raises an error" do
71
+ expect do
72
+ subject.message do
73
+ 1
74
+ end
75
+ end.to raise_error(CaptainHoog::Errors::MessageResultNotValidError)
76
+ end
77
+ end
78
+
79
+ context "returning a String" do
80
+
81
+ it "raises not an error" do
82
+ expect do
83
+ subject.message do
84
+ "Foo"
85
+ end
86
+ end.not_to raise_error
87
+ end
88
+
89
+ end
90
+
91
+ end
92
+
93
+ describe "#helper" do
94
+
95
+ let(:git){ CaptainHoog::Git.new }
96
+
97
+ before do
98
+ git.helper :my_helper do
99
+ "foo"
100
+ end
101
+ end
102
+
103
+ it "defines a helper method with a given name" do
104
+ expect(git).to respond_to(:my_helper)
105
+ end
106
+
107
+ it "evaluates the helper" do
108
+ expect(git.my_helper).to eq 'foo'
109
+ end
110
+
111
+ context "passing variables to the helper" do
112
+
113
+ before do
114
+ git.helper :my_helper_with_vars do |a|
115
+ a
116
+ end
117
+
118
+ git.helper :setter= do |a|
119
+
120
+ end
121
+ end
122
+
123
+ it "variables will be evaluated" do
124
+ expect do
125
+ git.my_helper_with_vars
126
+ end.to raise_error ArgumentError
127
+ expect do
128
+ git.setter=22
129
+ end.to_not raise_error
130
+ expect(git.my_helper_with_vars(19)).to eq 19
131
+ end
132
+
133
+ end
134
+
135
+ describe "integrated in a plugin" do
136
+
137
+ let(:code) do
138
+ path =File.join(File.dirname(__FILE__),
139
+ "..",
140
+ "..",
141
+ "fixtures",
142
+ "code",
143
+ "helper.rb")
144
+ File.read(path)
145
+ end
146
+
147
+ it "provides access directly to the helper" do
148
+ plugin = CaptainHoog::Plugin.new(code, "")
149
+
150
+ expect do
151
+ plugin.eval_plugin
152
+ plugin.execute
153
+ end.to_not raise_error
154
+
155
+ plugin.eval_plugin
156
+ expect(plugin.execute[:message]).to eq "It's 12."
157
+ end
158
+
159
+ end
160
+
161
+ end
162
+
163
+ describe "#run" do
164
+
165
+ it "sets @test_result to true" do
166
+ subject.run do
167
+ "hello"
168
+ end
169
+ expect(subject.instance_variable_get(:@test_result)).to be true
170
+ end
171
+
172
+ it "evaluates the given block" do
173
+ subject.run do
174
+ subject.helper :foo_run do
175
+ 12
176
+ end
177
+ end
178
+ subject.execute
179
+ expect(subject).to respond_to(:foo_run)
180
+ end
181
+
182
+ end
183
+ end
184
+
185
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe CaptainHoog::PluginList do
4
+ describe 'instance methods' do
5
+ it 'provides #plugins method' do
6
+ expect(described_class.new).to respond_to(:plugins)
7
+ end
8
+
9
+ it 'provides #has?' do
10
+ expect(described_class.new).to respond_to(:has?)
11
+ end
12
+
13
+ describe '#plugins' do
14
+
15
+ let(:plugin_dir_path) do
16
+ File.join(File.dirname(__FILE__),
17
+ '..', '..',
18
+ 'fixtures',
19
+ 'plugins',
20
+ 'test_plugins',
21
+ 'passing')
22
+ end
23
+
24
+ let(:config) do
25
+ {
26
+ 'exclude' => %w(mat git log),
27
+ 'pre-commit' => %w(rspec),
28
+ 'plugins_dir' => plugin_dir_path
29
+ }
30
+ end
31
+
32
+ subject do
33
+ described_class.new(config: config)
34
+ end
35
+
36
+ it 'returns available plugins' do
37
+ expect(subject.plugins).to eq %w(rspec)
38
+ end
39
+
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,101 @@
1
+ require 'spec_helper'
2
+
3
+ describe CaptainHoog::Plugin do
4
+
5
+ let(:code) do
6
+ <<-CODE
7
+
8
+ git.describe "rspec" do |pre|
9
+ pre.helper :test_helper do
10
+ env.variable
11
+ end
12
+
13
+ pre.test do
14
+ false
15
+ end
16
+
17
+ pre.message do
18
+ "Test failed."
19
+ end
20
+ end
21
+
22
+ CODE
23
+ end
24
+
25
+ let(:env) do
26
+ env = CaptainHoog::Env.new
27
+ env[:variable] = 12
28
+ env
29
+ end
30
+
31
+ let(:plugin) do
32
+ CaptainHoog::Plugin.new(code, env)
33
+ end
34
+
35
+ it "provides access to the DSL" do
36
+ expect(plugin).to respond_to(:git)
37
+ end
38
+
39
+ it "provides access to the env" do
40
+ expect(plugin).to respond_to(:env)
41
+ end
42
+
43
+ describe "#initialize" do
44
+
45
+ it "prepares git" do
46
+ expect(plugin.instance_variable_get(:@git)).to_not be nil
47
+ end
48
+
49
+ it "assigns the plugin environment" do
50
+ expect(plugin.instance_variable_get(:@env)).to \
51
+ be_instance_of(CaptainHoog::Env)
52
+ end
53
+
54
+ it "assigns the plugin code" do
55
+ expect(plugin.instance_variable_get(:@code)).to eq code
56
+ end
57
+ end
58
+
59
+ context "evaluating a plugin" do
60
+
61
+ it "provides a #eval_plugin method" do
62
+ expect(plugin).to respond_to(:eval_plugin)
63
+ end
64
+
65
+ describe "#eval_plugin" do
66
+ before do
67
+ plugin.eval_plugin
68
+ end
69
+
70
+ it "evaluates the code abd provides #test_helper" do
71
+ expect(plugin).to respond_to(:test_helper) #be_instance_of(Hash)
72
+ end
73
+
74
+ end
75
+
76
+ describe '#execute' do
77
+
78
+ before do
79
+ plugin.eval_plugin
80
+ end
81
+
82
+ describe "the returning hash" do
83
+
84
+ subject { plugin.execute }
85
+
86
+ it "includes the test result at the :result key" do
87
+ expect(subject).to have_key(:result)
88
+ expect(subject[:result]).to be false
89
+ end
90
+
91
+ it "includes the test failure message at the :message key" do
92
+ expect(subject).to have_key(:message)
93
+ expect(subject[:message]).to eq "Test failed."
94
+ end
95
+
96
+ end
97
+ end
98
+
99
+ end
100
+
101
+ end
@@ -0,0 +1,107 @@
1
+ require 'spec_helper'
2
+
3
+ describe CaptainHoog::PreGit do
4
+
5
+ describe "class methods" do
6
+
7
+ subject{ CaptainHoog::PreGit }
8
+
9
+ it "provides #run" do
10
+ expect(subject).to respond_to(:run)
11
+ end
12
+
13
+ it "provides #project_dir getter" do
14
+ expect(subject).to respond_to(:project_dir)
15
+ end
16
+
17
+ it "provides #project_dir setter" do
18
+ expect(subject).to respond_to(:project_dir=)
19
+ end
20
+
21
+ it "provides #plugins_dir getter" do
22
+ expect(subject).to respond_to(:plugins_dir)
23
+ end
24
+
25
+ it "provides #plugins_dir setter" do
26
+ expect(subject).to respond_to(:plugins_dir=)
27
+ end
28
+
29
+ it "provides #configure" do
30
+ expect(subject).to respond_to(:configure)
31
+ end
32
+
33
+ describe "#configure" do
34
+ let(:plugins_path) do
35
+ File.join(File.dirname(__FILE__),
36
+ "..",
37
+ "..",
38
+ "fixtures",
39
+ "plugins",
40
+ "test_plugins")
41
+ end
42
+
43
+ before do
44
+ subject.configure do |config|
45
+ config.headline_on_success = "Success!"
46
+ config.headline_on_failure = "Failure!"
47
+ config.project_dir = File.dirname(__FILE__)
48
+ config.plugins_dir = plugins_path
49
+ config.suppress_headline = true
50
+ end
51
+ end
52
+
53
+ it "let you define the success headline message" do
54
+ expect(CaptainHoog::PreGit.headline_on_success).to eq "Success!"
55
+ end
56
+
57
+ it "let you define the failure headline message" do
58
+ expect(CaptainHoog::PreGit.headline_on_failure).to eq "Failure!"
59
+ end
60
+
61
+ it "let you define the project_dir" do
62
+ expect(CaptainHoog::PreGit.project_dir).to eq File.dirname(__FILE__)
63
+ end
64
+
65
+ it "let you define the plugins dir" do
66
+ expect(CaptainHoog::PreGit.plugins_dir).to eq plugins_path
67
+ end
68
+
69
+ end
70
+
71
+ describe "#run" do
72
+
73
+ let(:plugins_list) do
74
+ Class.new do
75
+ def plugins
76
+ %w(simple)
77
+ end
78
+
79
+ def has?(plugin)
80
+ plugins.include?(plugin.plugin_name)
81
+ end
82
+ end.new
83
+ end
84
+
85
+ it "returns an instance of CaptainHoog::PreGit" do
86
+ expect(CaptainHoog::PreGit.run(plugins_list: plugins_list)).to \
87
+ be_instance_of(CaptainHoog::PreGit)
88
+ end
89
+
90
+ it 'affects only configured plugins' do
91
+ pre_git = CaptainHoog::PreGit.run(plugins_list:plugins_list)
92
+ expect(pre_git.instance_variable_get(:@results).size).to eq 1
93
+ end
94
+
95
+ end
96
+
97
+ end
98
+
99
+ describe "instance methods" do
100
+
101
+ it "provides #plugins_eval" do
102
+ expect(subject).to respond_to(:plugins_eval)
103
+ end
104
+
105
+ end
106
+
107
+ end
@@ -0,0 +1,8 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+
4
+ ENV["PREGIT_ENV"] = "test"
5
+
6
+ require 'captain_hoog'
7
+
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |file| require file }
@@ -0,0 +1,13 @@
1
+ RSpec::Matchers.define :be_subclass_of do |super_class|
2
+ match do |child_class|
3
+ child_class.superclass == super_class
4
+ end
5
+
6
+ failure_message do |child_class|
7
+ "expected the #{child_class} class to be a subclass of #{super_class}"
8
+ end
9
+
10
+ description do
11
+ "expected a class to be a subclass of #{super_class}."
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,236 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: captain_hoog
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Schmidt
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colorize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.7'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.7.3
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '0.7'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.7.3
33
+ - !ruby/object:Gem::Dependency
34
+ name: thor
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '0.19'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 0.19.1
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '0.19'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 0.19.1
53
+ - !ruby/object:Gem::Dependency
54
+ name: terminal-table
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: 1.4.5
60
+ type: :runtime
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: 1.4.5
67
+ - !ruby/object:Gem::Dependency
68
+ name: bundler
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: '1.6'
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: '1.6'
81
+ - !ruby/object:Gem::Dependency
82
+ name: rake
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ - !ruby/object:Gem::Dependency
96
+ name: rspec
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ - !ruby/object:Gem::Dependency
110
+ name: cucumber
111
+ requirement: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ type: :development
117
+ prerelease: false
118
+ version_requirements: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ - !ruby/object:Gem::Dependency
124
+ name: aruba
125
+ requirement: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ type: :development
131
+ prerelease: false
132
+ version_requirements: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ description:
138
+ email:
139
+ - daniel.schmidt@adytonsystems.com
140
+ executables:
141
+ - githoog
142
+ extensions: []
143
+ extra_rdoc_files: []
144
+ files:
145
+ - ".gitignore"
146
+ - Gemfile
147
+ - LICENSE.txt
148
+ - README.md
149
+ - Rakefile
150
+ - bin/githoog
151
+ - captain_hoog.gemspec
152
+ - features/failed_hook.feature
153
+ - features/installing_hook.feature
154
+ - features/moving_hooks.feature
155
+ - features/passed_hook.feature
156
+ - features/removing_hook.feature
157
+ - features/support/env.rb
158
+ - features/support/steps/hooks_steps.rb
159
+ - features/support/world.rb
160
+ - lib/captain_hoog.rb
161
+ - lib/captain_hoog/delegatable.rb
162
+ - lib/captain_hoog/dependencies.rb
163
+ - lib/captain_hoog/env.rb
164
+ - lib/captain_hoog/errors.rb
165
+ - lib/captain_hoog/errors/dsl_errors.rb
166
+ - lib/captain_hoog/git.rb
167
+ - lib/captain_hoog/helper_table.rb
168
+ - lib/captain_hoog/plugin.rb
169
+ - lib/captain_hoog/plugin_list.rb
170
+ - lib/captain_hoog/pre_git.rb
171
+ - lib/captain_hoog/templates/hoogfile.erb
172
+ - lib/captain_hoog/templates/install.erb
173
+ - lib/captain_hoog/version.rb
174
+ - spec/fixtures/code/helper.rb
175
+ - spec/fixtures/plugins/shared/passing/simple_shared.rb
176
+ - spec/fixtures/plugins/test_plugins/failing/simple.rb
177
+ - spec/fixtures/plugins/test_plugins/passing/simple.rb
178
+ - spec/fixtures/pre-commit-fail
179
+ - spec/fixtures/pre-commit-pass
180
+ - spec/lib/captain_hoog/env_spec.rb
181
+ - spec/lib/captain_hoog/git_spec.rb
182
+ - spec/lib/captain_hoog/plugin_list_spec.rb
183
+ - spec/lib/captain_hoog/plugin_spec.rb
184
+ - spec/lib/captain_hoog/pre_git_spec.rb
185
+ - spec/spec_helper.rb
186
+ - spec/support/matchers/be_subclass_of.rb
187
+ homepage: ''
188
+ licenses:
189
+ - MIT
190
+ metadata: {}
191
+ post_install_message: "\n Thanks for installing the Pre-Git whatever hooker!\n\n
192
+ \ If you don't have already, please install the hook:\n\n githoog install --type
193
+ <GIT_HOOK_TYPE> --plugins_dir <PATH_TO_PLUGINS> --project_dir <PATH_TO_PROJECT>\n
194
+ \ "
195
+ rdoc_options: []
196
+ require_paths:
197
+ - lib
198
+ required_ruby_version: !ruby/object:Gem::Requirement
199
+ requirements:
200
+ - - ">="
201
+ - !ruby/object:Gem::Version
202
+ version: '0'
203
+ required_rubygems_version: !ruby/object:Gem::Requirement
204
+ requirements:
205
+ - - ">="
206
+ - !ruby/object:Gem::Version
207
+ version: '0'
208
+ requirements: []
209
+ rubyforge_project:
210
+ rubygems_version: 2.4.3
211
+ signing_key:
212
+ specification_version: 4
213
+ summary: Plugin based git-pre hook.
214
+ test_files:
215
+ - features/failed_hook.feature
216
+ - features/installing_hook.feature
217
+ - features/moving_hooks.feature
218
+ - features/passed_hook.feature
219
+ - features/removing_hook.feature
220
+ - features/support/env.rb
221
+ - features/support/steps/hooks_steps.rb
222
+ - features/support/world.rb
223
+ - spec/fixtures/code/helper.rb
224
+ - spec/fixtures/plugins/shared/passing/simple_shared.rb
225
+ - spec/fixtures/plugins/test_plugins/failing/simple.rb
226
+ - spec/fixtures/plugins/test_plugins/passing/simple.rb
227
+ - spec/fixtures/pre-commit-fail
228
+ - spec/fixtures/pre-commit-pass
229
+ - spec/lib/captain_hoog/env_spec.rb
230
+ - spec/lib/captain_hoog/git_spec.rb
231
+ - spec/lib/captain_hoog/plugin_list_spec.rb
232
+ - spec/lib/captain_hoog/plugin_spec.rb
233
+ - spec/lib/captain_hoog/pre_git_spec.rb
234
+ - spec/spec_helper.rb
235
+ - spec/support/matchers/be_subclass_of.rb
236
+ has_rdoc: