git-hooks-helper 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6f421a953099372d3bb6facc4d392a7d7c35eac4
4
+ data.tar.gz: bbb5630d7bf4b522bcde98c6fd4aed3cef89a3db
5
+ SHA512:
6
+ metadata.gz: b999cd12782c11420f2aa58e95e652ee5029735a4eb07284447b6f345b936ea14ec76038e6865be5e26ac9e8ac06916b163994aabcb90eb754dc5755f9ce50f1
7
+ data.tar.gz: 04b2b0016dd0483fe0fc20a2064f707aa492b18f93dba58405ce2c194f18ab158efc1c46e6f3a9cd5cb3dc443ff46bec90a7a9d75edafea79eb2fff2aecf682f
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ cache: bundler
3
+
4
+ rvm:
5
+ - 1.9.3
6
+ - jruby-18mode # JRuby in 1.8 mode
7
+ - jruby-19mode # JRuby in 1.9 mode
8
+ - rbx-2.1.1
9
+ - 1.8.7
data/Gemfile CHANGED
@@ -1,11 +1,11 @@
1
1
  source :rubygems
2
2
  gemspec
3
- gem 'rspec', '2.6.0'
4
- gem 'pry', '0.9.7.4'
5
- gem 'rails_best_practices', '1.7.2'
6
- gem 'sexp_processor', '3.0.9'
3
+ gem 'rspec'
4
+ gem 'pry'
5
+ gem 'rails_best_practices'
6
+ gem 'sexp_processor'
7
7
 
8
8
  group :test do
9
- gem 'rails-erb-check', '0.1.0'
10
- gem 'slim', '1.1.0'
9
+ gem 'rails-erb-check'
10
+ gem 'slim'
11
11
  end
data/Gemfile.lock CHANGED
@@ -1,88 +1,85 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- git-hooks-helper (0.0.2)
4
+ git-hooks-helper (0.0.3)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
8
8
  specs:
9
- actionpack (3.2.8)
10
- activemodel (= 3.2.8)
11
- activesupport (= 3.2.8)
12
- builder (~> 3.0.0)
13
- erubis (~> 2.7.0)
14
- journey (~> 1.0.4)
15
- rack (~> 1.4.0)
16
- rack-cache (~> 1.2)
17
- rack-test (~> 0.6.1)
18
- sprockets (~> 2.1.3)
19
- activemodel (3.2.8)
20
- activesupport (= 3.2.8)
21
- builder (~> 3.0.0)
22
- activesupport (3.2.8)
23
- i18n (~> 0.6)
24
- multi_json (~> 1.0)
25
- builder (3.0.0)
26
- coderay (0.9.8)
9
+ abstract (1.0.0)
10
+ actionpack (3.0.20)
11
+ activemodel (= 3.0.20)
12
+ activesupport (= 3.0.20)
13
+ builder (~> 2.1.2)
14
+ erubis (~> 2.6.6)
15
+ i18n (~> 0.5.0)
16
+ rack (~> 1.2.5)
17
+ rack-mount (~> 0.6.14)
18
+ rack-test (~> 0.5.7)
19
+ tzinfo (~> 0.3.23)
20
+ activemodel (3.0.20)
21
+ activesupport (= 3.0.20)
22
+ builder (~> 2.1.2)
23
+ i18n (~> 0.5.0)
24
+ activesupport (3.0.20)
25
+ awesome_print (1.2.0)
26
+ builder (2.1.2)
27
+ code_analyzer (0.4.5)
28
+ sexp_processor
29
+ coderay (1.1.0)
27
30
  colored (1.2)
28
- diff-lcs (1.1.3)
29
- erubis (2.7.0)
30
- hike (1.2.1)
31
- i18n (0.6.0)
32
- journey (1.0.4)
33
- method_source (0.6.7)
34
- ruby_parser (>= 2.3.1)
35
- multi_json (1.3.6)
36
- progressbar (0.9.2)
37
- pry (0.9.7.4)
38
- coderay (~> 0.9.8)
39
- method_source (~> 0.6.7)
40
- ruby_parser (>= 2.3.1)
41
- slop (~> 2.1.0)
42
- rack (1.4.1)
43
- rack-cache (1.2)
44
- rack (>= 0.4)
45
- rack-test (0.6.1)
31
+ diff-lcs (1.2.5)
32
+ erubis (2.6.6)
33
+ abstract (>= 1.0.0)
34
+ i18n (0.5.3)
35
+ method_source (0.8.2)
36
+ pry (0.9.12.6)
37
+ coderay (~> 1.0)
38
+ method_source (~> 0.8)
39
+ slop (~> 3.4)
40
+ rack (1.2.8)
41
+ rack-mount (0.6.14)
42
+ rack (>= 1.0.0)
43
+ rack-test (0.5.7)
46
44
  rack (>= 1.0)
47
45
  rails-erb-check (0.1.0)
48
46
  actionpack (~> 3.0)
49
- rails_best_practices (1.7.2)
47
+ rails_best_practices (1.15.2)
50
48
  activesupport
49
+ awesome_print
50
+ code_analyzer (>= 0.4.3)
51
51
  colored
52
52
  erubis
53
53
  i18n
54
- progressbar
55
- sexp_processor
56
- rspec (2.6.0)
57
- rspec-core (~> 2.6.0)
58
- rspec-expectations (~> 2.6.0)
59
- rspec-mocks (~> 2.6.0)
60
- rspec-core (2.6.4)
61
- rspec-expectations (2.6.0)
62
- diff-lcs (~> 1.1.2)
63
- rspec-mocks (2.6.0)
64
- ruby_parser (2.3.1)
65
- sexp_processor (~> 3.0)
66
- sexp_processor (3.0.9)
67
- slim (1.1.0)
68
- temple (~> 0.3.5)
69
- tilt (~> 1.3.2)
70
- slop (2.1.0)
71
- sprockets (2.1.3)
72
- hike (~> 1.2)
73
- rack (~> 1.0)
74
- tilt (~> 1.1, != 1.3.0)
75
- temple (0.3.5)
76
- tilt (1.3.3)
54
+ require_all
55
+ ruby-progressbar
56
+ require_all (1.3.2)
57
+ rspec (2.14.1)
58
+ rspec-core (~> 2.14.0)
59
+ rspec-expectations (~> 2.14.0)
60
+ rspec-mocks (~> 2.14.0)
61
+ rspec-core (2.14.8)
62
+ rspec-expectations (2.14.5)
63
+ diff-lcs (>= 1.1.3, < 2.0)
64
+ rspec-mocks (2.14.6)
65
+ ruby-progressbar (1.4.2)
66
+ sexp_processor (4.4.3)
67
+ slim (2.0.2)
68
+ temple (~> 0.6.6)
69
+ tilt (>= 1.3.3, < 2.1)
70
+ slop (3.5.0)
71
+ temple (0.6.7)
72
+ tilt (2.0.1)
73
+ tzinfo (0.3.39)
77
74
 
78
75
  PLATFORMS
79
76
  ruby
80
77
 
81
78
  DEPENDENCIES
82
79
  git-hooks-helper!
83
- pry (= 0.9.7.4)
84
- rails-erb-check (= 0.1.0)
85
- rails_best_practices (= 1.7.2)
86
- rspec (= 2.6.0)
87
- sexp_processor (= 3.0.9)
88
- slim (= 1.1.0)
80
+ pry
81
+ rails-erb-check
82
+ rails_best_practices
83
+ rspec
84
+ sexp_processor
85
+ slim
data/README.md CHANGED
@@ -4,13 +4,12 @@ Instalation
4
4
 
5
5
  Dependencies
6
6
  ------------
7
- This gem has will have no dependencies and it will be up to you to provide required and possible dependencies.
7
+ This gem has no dependencies and it will be up to you to provide required and possible dependencies.
8
8
  Possible dependencies are tied to checks you want to use:
9
- * check_erb - rails-erb-check
10
- * check_slim - slim
11
- * check_haml - haml
12
- * check_best_practices - rails_best_practices
13
-
9
+ * check_erb - gem install rails-erb-check
10
+ * check_slim - gem install slim
11
+ * check_haml - gem install haml
12
+ * check_best_practices - gem install rails_best_practices
14
13
 
15
14
  File clasification
16
15
  ------------------
@@ -18,9 +17,9 @@ File clasification
18
17
  Most commands use file classes internally or accept type class as a param.
19
18
  File type classes and associated file extensions:
20
19
 
21
- 1. :rb - .rb .rake .task .prawn
22
- 2. :js - .js
23
- 3. :erb - .erb
20
+ 1. :rb - .rb .rake .task .prawn
21
+ 2. :js - .js
22
+ 3. :erb - .erb
24
23
  3. :slim - .slim
25
24
 
26
25
  Usage
@@ -29,12 +28,12 @@ Create your hit hook in .git/hooks directory and make it executable.
29
28
 
30
29
  My example pre-commit hook that i use myself.
31
30
  To create such a hook type in console:
32
-
31
+ ```
33
32
  cd your/project/
34
33
  touch .git/hooks/pre-commit
35
34
  chmod +x .git/hooks/pre-commit
36
35
  vim .git/hooks/pre-commit
37
-
36
+ ```
38
37
  and paste following code:
39
38
 
40
39
 
@@ -54,6 +53,7 @@ and paste following code:
54
53
  check_erb # errors when ERB syntax is invalid
55
54
  check_slim # errors when SLIM syntax is invalid
56
55
  check_haml # errors when HAML syntax is invalid
56
+ flog_methods 20 # warnings when FLOG reports more than 20 on method
57
57
  check_best_practices # warnings when ruby best practices are violated
58
58
  warning_on "WTF?", "binding.pry", "<<<<<<<" # warnings when any of these texts are present in any commited files
59
59
  warning_on "console.log", "debugger", {:in => [:js]} # warning when any of these texts are present in JS files
@@ -63,4 +63,8 @@ and paste following code:
63
63
  notice "Or bad things will happen" # Yellow text
64
64
  warn "Cthulhu" # Red text
65
65
  end
66
- ```
66
+ ```
67
+
68
+ Badges
69
+ ------
70
+ [![Code Climate](https://codeclimate.com/github/MartynasM/git-hooks-helper.png)](https://codeclimate.com/github/MartynasM/git-hooks-helper)
@@ -1,7 +1,7 @@
1
1
  module GitHooksHelper
2
2
  class Git
3
3
  class << self
4
- FILES_TO_WATCH = /(.+\.(e?rb|rake|prawn|haml|coffee|slim|task)|[Rr]akefile)/
4
+ FILES_TO_WATCH = /(.+\.(e?rb|js|rake|prawn|haml|coffee|slim|task)|[Rr]akefile)/
5
5
 
6
6
  def in_index
7
7
  all_files = `git diff --cached --name-only --diff-filter=AM HEAD`.split("\n").map(&:chomp)
@@ -8,12 +8,12 @@ require 'pry'
8
8
  module GitHooksHelper
9
9
  class Hook
10
10
 
11
- RB_REGEXP = /\.(rb|rake|task|prawn|[Rr]akefile|task)\z/
12
- ERB_REGEXP = /\.erb\z/
13
- JS_REGEXP = /\.js\z/
14
- HAML_REGEXP = /\.haml\z/
15
- COFFEE_REGEXP = /\.coffee\z/
16
- SLIM_REGEXP = /\.slim\z/
11
+ RB_REGEXP = /\.(rb|rake|task|prawn|[Rr]akefile|task)\z/.freeze
12
+ ERB_REGEXP = /\.erb\z/.freeze
13
+ JS_REGEXP = /\.js\z/.freeze
14
+ HAML_REGEXP = /\.haml\z/.freeze
15
+ COFFEE_REGEXP = /\.coffee\z/.freeze
16
+ SLIM_REGEXP = /\.slim\z/.freeze
17
17
 
18
18
  FILETYPES = {
19
19
  rb: RB_REGEXP,
@@ -22,13 +22,13 @@ module GitHooksHelper
22
22
  haml: HAML_REGEXP,
23
23
  coffee: COFFEE_REGEXP,
24
24
  slim: SLIM_REGEXP
25
- }
25
+ }.freeze
26
26
 
27
- RB_WARNING_REGEXP = /[0-9]+:\s+warning:/
28
- HAML_INVALID_REGEXP = /error/
29
- ERB_INVALID_REGEXP = /invalid\z/
30
- SLIM_INVALID_REGEXP = /invalid1\z/
31
- COLOR_REGEXP = /\e\[(\d+)m/
27
+ RB_WARNING_REGEXP = /[0-9]+:\s+warning:/.freeze
28
+ HAML_INVALID_REGEXP = /error/.freeze
29
+ ERB_INVALID_REGEXP = /invalid\z/.freeze
30
+ SLIM_INVALID_REGEXP = /invalid1\z/.freeze
31
+ COLOR_REGEXP = /\e\[(\d+)m/.freeze
32
32
 
33
33
  # Set this to true if you want warnings to stop your commit
34
34
  def initialize(&block)
@@ -101,24 +101,26 @@ module GitHooksHelper
101
101
  end
102
102
 
103
103
  def each_changed_file(filetypes = [:all])
104
- filetypes = [filetypes] unless filetypes.class == Array
104
+ filetypes = Array(filetypes)
105
105
  if @result.continue?
106
106
  debug("Can continue")
107
- @changed_files.each do |file|
108
- next unless file_matches_filetypes?(file, filetypes)
109
- yield file if File.readable?(file)
107
+ changed_files(filetypes).each do |file|
108
+ yield file
110
109
  end
111
110
  else
112
111
  debug("Cannot continue")
113
112
  end
114
113
  end
115
114
 
115
+ def changed_files(filetypes = [:all])
116
+ filetypes = Array(filetypes)
117
+ @changed_files.select{ |file| file_matches_filetypes?(file, filetypes) and File.readable?(file) }
118
+ end
119
+
116
120
  def file_matches_filetypes?(file, filetypes)
117
- return true if filetypes.include?(:all)
118
- filetypes.each do |type|
119
- return true if file =~ FILETYPES[type]
121
+ filetypes.any? do |type|
122
+ file =~ FILETYPES[type] || type == :all
120
123
  end
121
- return false
122
124
  end
123
125
 
124
126
  def check_ruby_syntax
@@ -135,9 +137,9 @@ module GitHooksHelper
135
137
  each_changed_file([:erb]) do |file|
136
138
  Open3.popen3("rails-erb-check #{file}") do |stdin, stdout, stderr|
137
139
  lines = stdout.read.split("\n")
138
- errors = lines.map do |line|
140
+ errors = lines.map do |line|
139
141
  if line.gsub(COLOR_REGEXP, '') =~ ERB_INVALID_REGEXP
140
- "#{file} => invalid ERB syntax"
142
+ "#{file} => invalid ERB syntax"
141
143
  end
142
144
  end.compact
143
145
  @result.errors.concat errors
@@ -145,7 +147,6 @@ module GitHooksHelper
145
147
  end
146
148
  end
147
149
 
148
-
149
150
  def check_slim
150
151
  each_changed_file([:slim]) do |file|
151
152
  Open3.popen3("slimrb -c #{file}") do |stdin, stdout, stderr|
@@ -162,9 +163,9 @@ module GitHooksHelper
162
163
  each_changed_file([:haml]) do |file|
163
164
  Open3.popen3("haml --check #{file}") do |stdin, stdout, stderr|
164
165
  lines = stderr.read.split("\n")
165
- errors = lines.map do |line|
166
+ errors = lines.map do |line|
166
167
  if line.gsub(COLOR_REGEXP, '') =~ HAML_INVALID_REGEXP
167
- "#{file} => invalid HAML syntax\n #{line}"
168
+ "#{file} => invalid HAML syntax\n #{line}"
168
169
  end
169
170
  end.compact
170
171
  @result.errors.concat errors
@@ -173,6 +174,9 @@ module GitHooksHelper
173
174
  end
174
175
 
175
176
  def check_best_practices
177
+ Open3.popen3("pwd") do |stdin, stdout, stderr|
178
+ puts stdout.read
179
+ end
176
180
  each_changed_file([:rb, :erb, :haml]) do |file|
177
181
  Open3.popen3("rails_best_practices --spec --test #{file}") do |stdin, stdout, stderr|
178
182
  @result.warn(stdout.read.split("\n").map do |line|
@@ -184,6 +188,26 @@ module GitHooksHelper
184
188
  end
185
189
  end
186
190
 
191
+ def flog_methods(threshold = 20)
192
+ files = changed_files(:rb).join(' ')
193
+ if files != ''
194
+ Open3.popen3("flog -m #{files}") do |stdin, stdout, stderr|
195
+ punishment = stdout.read.split("\n")[3..-1]
196
+ punishment.each do |line|
197
+ line = line.split(" ")
198
+ score = line[0].to_f
199
+ method = line[1].strip
200
+ path = line[2].strip
201
+ if score >= threshold
202
+ @result.warn("Flog for #{method} in #{path} returned #{score}")
203
+ else
204
+ break
205
+ end
206
+ end
207
+ end
208
+ end
209
+ end
210
+
187
211
  # Maybe need options for different file types :rb :erb :js
188
212
  def warning_on(*args)
189
213
  options = (args[-1].kind_of?(Hash) ? args.pop : {})
@@ -216,4 +240,4 @@ module GitHooksHelper
216
240
  end
217
241
 
218
242
  end
219
- end
243
+ end
@@ -1,3 +1,3 @@
1
1
  module GitHooksHelper
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -1,155 +1,213 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe GitHooksHelper do
4
+ before(:each) { clear_screen }
4
5
 
5
- it "should run empty hook" do
6
+ it 'should run empty hook' do
6
7
  GitHooksHelper::Git.should_receive(:in_index).and_return([])
7
8
 
8
- begin
9
+ expect do
9
10
  GitHooksHelper.results do
10
11
  end
11
- rescue SystemExit
12
- $!.status.should eql 0
12
+ end.to(raise_exception(SystemExit) do |e|
13
+ positinve_ending(e)
14
+ end)
15
+ end
16
+
17
+ describe '#info' do
18
+ it 'should output simple text' do
19
+ expect do
20
+ GitHooksHelper.results do
21
+ info 'Test info text'
22
+ end
23
+ end.to(raise_exception(SystemExit) do |e|
24
+ positinve_ending(e)
25
+ in_screen("[1m\e[32mTest info text") # green
26
+ end)
27
+ end
28
+ end
29
+
30
+ describe '#notice' do
31
+ it 'should output simple text' do
32
+ expect do
33
+ GitHooksHelper.results do
34
+ notice 'Test info text'
35
+ end
36
+ end.to(raise_exception(SystemExit) do |e|
37
+ positinve_ending(e)
38
+ in_screen("[1m\e[33mTest info text") # yellow
39
+ end)
40
+ end
41
+ end
42
+
43
+ describe '#info' do
44
+ it 'should output simple text' do
45
+ expect do
46
+ GitHooksHelper.results do
47
+ warn 'Test info text'
48
+ end
49
+ end.to(raise_exception(SystemExit) do |e|
50
+ positinve_ending(e)
51
+ in_screen("[1m\e[31mTest info text") # red
52
+ end)
13
53
  end
14
54
  end
15
55
 
16
- describe "check_ruby_syntax" do
56
+
57
+ describe 'check_ruby_syntax' do
17
58
  before(:each) do
18
59
  @files = [
19
- "spec/git_files/bad_syntax.rb",
20
- "spec/git_files/good_syntax.rb"
60
+ 'spec/git_files/bad_syntax.rb',
61
+ 'spec/git_files/good_syntax.rb'
21
62
  ]
22
63
  end
23
64
 
24
- it "should fail on bad rb syntax" do
65
+ it 'should fail on bad rb syntax' do
25
66
  GitHooksHelper::Git.should_receive(:in_index).and_return(@files)
26
- begin
67
+ expect do
27
68
  GitHooksHelper.results do
28
69
  check_ruby_syntax
29
70
  end
30
- rescue SystemExit => e
31
- $!.status.should eql 1
32
- end
71
+ end.to(raise_exception(SystemExit) do |e|
72
+ hook_fails(e)
73
+ not_see_perfect_commit
74
+ see_warning
75
+ in_screen("spec/git_files/bad_syntax.rb:4: syntax error, unexpected end-of-input, expecting keyword_end")
76
+ in_screen("spec/git_files/bad_syntax.rb:4: warning: mismatched indentations at 'end' with 'def' at 2")
77
+ end)
33
78
  end
34
79
 
35
- it "should pass good rb syntax" do
36
- GitHooksHelper::Git.should_receive(:in_index).and_return(["spec/git_files/good_syntax.rb"])
37
- begin
80
+ it 'should pass good rb syntax' do
81
+ GitHooksHelper::Git.should_receive(:in_index).and_return(['spec/git_files/good_syntax.rb'])
82
+ expect do
38
83
  GitHooksHelper.results do
39
84
  check_ruby_syntax
40
85
  end
41
- rescue SystemExit => e
42
- $!.status.should eql 0
43
- end
86
+ end.to(raise_exception(SystemExit) do |e|
87
+ positinve_ending(e)
88
+ end)
44
89
  end
45
90
  end
46
91
 
47
- describe "never_stop" do
48
- it "should pass even on errors and warnings" do
49
- GitHooksHelper::Git.should_receive(:in_index).and_return(["spec/git_files/bad_syntax.rb"])
50
- begin
92
+ describe 'never_stop' do
93
+ it 'should pass even on errors and warnings' do
94
+ GitHooksHelper::Git.should_receive(:in_index).and_return(['spec/git_files/bad_syntax.rb'])
95
+ expect do
51
96
  GitHooksHelper.results do
52
97
  never_stop
53
98
  check_ruby_syntax
54
99
  end
55
- rescue SystemExit => e
56
- $!.status.should eql 0
57
- end
100
+ end.to(raise_exception(SystemExit) do |e|
101
+ see_warning
102
+ hook_passes(e)
103
+ end)
58
104
  end
59
105
  end
60
106
 
61
- describe "stop_on_warnings" do # also sort of checks best practices
62
- it "should stop even on warnings" do
63
- GitHooksHelper::Git.should_receive(:in_index).and_return(["spec/git_files/no_best_practices.rb"])
64
- begin
107
+ describe 'stop_on_warnings' do # also sort of checks best practices
108
+ it 'should stop even on warnings' do
109
+ GitHooksHelper::Git.should_receive(:in_index).and_return(['spec/git_files/no_best_practices.rb'])
110
+ expect do
65
111
  GitHooksHelper.results do
66
112
  stop_on_warnings
67
113
  check_best_practices
68
114
  end
69
- rescue SystemExit => e
70
- $!.status.should eql 1
71
- end
115
+ end.to(raise_exception(SystemExit) do |e|
116
+ hook_fails(e)
117
+ in_screen("WARNINGS") # special case - upercase when FAIL on warning
118
+ in_screen 'git_files/no_best_practices.rb:2 - remove trailing whitespace'
119
+ end)
72
120
  end
73
121
 
74
- it "should run OK when no errors" do
75
- GitHooksHelper::Git.should_receive(:in_index).and_return(["spec/git_files/ok_best_practices.rb"])
76
- begin
122
+ it 'should run OK when no errors' do
123
+ GitHooksHelper::Git.should_receive(:in_index).and_return(['spec/git_files/ok_best_practices.rb'])
124
+ expect do
77
125
  GitHooksHelper.results do
78
126
  stop_on_warnings
79
127
  check_best_practices
80
128
  end
81
- rescue SystemExit => e
82
- $!.status.should eql 0
83
- end
129
+ end.to(raise_exception(SystemExit) do |e|
130
+ positinve_ending(e)
131
+ end)
84
132
  end
85
133
  end
86
134
 
87
- describe "check_erb" do
88
- it "should stop on syntax error in ERB" do
89
- GitHooksHelper::Git.should_receive(:in_index).and_return(["spec/git_files/syntax_error.html.erb"])
90
- begin
135
+ describe 'check_erb' do
136
+ it 'should stop on syntax error in ERB' do
137
+ GitHooksHelper::Git.should_receive(:in_index).and_return(['spec/git_files/syntax_error.html.erb'])
138
+ expect do
91
139
  GitHooksHelper.results do
92
140
  stop_on_warnings
93
141
  check_erb
94
142
  end
95
- rescue SystemExit => e
96
- $!.status.should eql 1
97
- end
143
+ end.to(raise_exception(SystemExit) do |e|
144
+ hook_fails(e)
145
+ see_error
146
+ in_screen('spec/git_files/syntax_error.html.erb => invalid ERB syntax')
147
+ end)
98
148
  end
99
149
 
100
- it "should show no error on correct ERB" do
101
- GitHooksHelper::Git.should_receive(:in_index).and_return(["spec/git_files/ok.html.erb"])
102
- begin
150
+ it 'should show no error on correct ERB' do
151
+ GitHooksHelper::Git.should_receive(:in_index).and_return(['spec/git_files/ok.html.erb'])
152
+ expect do
103
153
  GitHooksHelper.results do
104
154
  stop_on_warnings
105
155
  check_erb
106
156
  end
107
- rescue SystemExit => e
108
- $!.status.should eql 0
109
- end
157
+ end.to(raise_exception(SystemExit) do |e|
158
+ positinve_ending(e)
159
+ end)
110
160
  end
111
161
  end
112
162
 
113
163
  describe 'check_slim' do
114
164
 
115
165
  it 'should stop on error in SLIM template' do
116
- GitHooksHelper::Git.should_receive(:in_index).and_return(["spec/git_files/syntax_error.html.slim"])
117
- begin
166
+ GitHooksHelper::Git.should_receive(:in_index).and_return(['spec/git_files/syntax_error.html.slim'])
167
+ expect do
118
168
  GitHooksHelper.results do
119
169
  stop_on_warnings
120
170
  check_slim
121
171
  end
122
- rescue SystemExit => e
123
- $!.status.should eql 1
124
- end
172
+ end.to(raise_exception(SystemExit) do |e|
173
+ see_error
174
+ in_screen("spec/git_files/syntax_error.html.slim => invalid SLIM syntax")
175
+ in_screen("Slim::Parser::SyntaxError: Expected closing brace }")
176
+ in_screen("spec/git_files/syntax_error.html.slim, Line 1, Column 25")
177
+ in_screen("div class='\#{@some_class'\n")
178
+ hook_fails(e)
179
+ end)
125
180
  end
126
181
 
127
182
  it 'should show to error in correct SLIM template' do
128
- GitHooksHelper::Git.should_receive(:in_index).and_return(["spec/git_files/ok.html.slim"])
129
- begin
183
+ GitHooksHelper::Git.should_receive(:in_index).and_return(['spec/git_files/ok.html.slim'])
184
+ expect do
130
185
  GitHooksHelper.results do
131
186
  stop_on_warnings
132
187
  check_slim
133
188
  end
134
- rescue SystemExit => e
135
- $!.status.should eql 0
136
- end
189
+ end.to(raise_exception(SystemExit) do |e|
190
+ positinve_ending(e)
191
+ end)
137
192
  end
138
193
 
139
194
  end
140
195
 
141
- describe "warning_on" do
142
- it "should show error when file contains specific text" do
143
- GitHooksHelper::Git.should_receive(:in_index).and_return(["spec/git_files/ok.html.erb"])
144
- begin
196
+ describe 'warning_on' do
197
+ it 'should show error when file contains specific text' do
198
+ GitHooksHelper::Git.should_receive(:in_index).and_return(['spec/git_files/ok.html.erb'])
199
+ expect do
145
200
  GitHooksHelper.results do
146
201
  stop_on_warnings
147
- check_erb
202
+ check_erb
148
203
  end
149
- rescue SystemExit => e
150
- $!.status.should eql 0
151
- end
204
+ end.to(raise_exception(SystemExit) do |e|
205
+ positinve_ending(e)
206
+ end)
152
207
  end
153
208
  end
154
209
 
155
- end
210
+ describe 'flog_methods' do
211
+ end
212
+
213
+ end
data/spec/spec_helper.rb CHANGED
@@ -4,4 +4,58 @@ require 'bundler/setup'
4
4
  require 'git-hooks-helper'
5
5
 
6
6
  RSpec.configure do |config|
7
- end
7
+ config.before(:all) do
8
+ # Redirect stderr and stdout
9
+ sio = StringIO.new
10
+ $stderr = sio
11
+ $stdout = sio
12
+ # $stderr = File.new(File.join(File.dirname(__FILE__), 'dev', 'null.txt'), 'w')
13
+ # $stdout = File.new(File.join(File.dirname(__FILE__), 'dev', 'null.txt'), 'w')
14
+ end
15
+ config.after(:all) do
16
+ $stderr = STDERR
17
+ $stdout = STDOUT
18
+ end
19
+ end
20
+
21
+ def clear_screen
22
+ $stdout.truncate(0)
23
+ end
24
+
25
+ def get_screen
26
+ $stdout.string.gsub("\u0000", '')
27
+ end
28
+
29
+ def in_screen(string)
30
+ expect(get_screen).to include(string)
31
+ end
32
+
33
+ def not_in_screen(string)
34
+ expect(get_screen).not_to include(string)
35
+ end
36
+
37
+ { perfect_commit: "Perfect commit!", error: "ERRORS", warning: 'Warnings'}.each do |method, message|
38
+ define_method(:"see_#{method}") do
39
+ in_screen(message)
40
+ end
41
+
42
+ define_method(:"not_see_#{method}") do
43
+ not_in_screen(message)
44
+ end
45
+ end
46
+
47
+ def hook_passes(e)
48
+ expect(e.status).to eql 0
49
+ end
50
+
51
+ def hook_fails(e)
52
+ in_screen('COMMIT FAILED')
53
+ expect(e.status).to eql 1
54
+ end
55
+
56
+ def positinve_ending(e)
57
+ not_see_error
58
+ not_see_warning
59
+ see_perfect_commit
60
+ hook_passes(e)
61
+ end
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-hooks-helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
5
- prerelease:
4
+ version: 0.0.4
6
5
  platform: ruby
7
6
  authors:
8
7
  - Martynas Margis
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-09-30 00:00:00.000000000Z
11
+ date: 2014-04-15 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: Gem for creating simple pre-commit git hooks in ruby.
15
14
  email:
@@ -18,7 +17,8 @@ executables: []
18
17
  extensions: []
19
18
  extra_rdoc_files: []
20
19
  files:
21
- - .gitignore
20
+ - ".gitignore"
21
+ - ".travis.yml"
22
22
  - Gemfile
23
23
  - Gemfile.lock
24
24
  - HISTORY
@@ -46,26 +46,26 @@ files:
46
46
  - spec/spec_helper.rb
47
47
  homepage: https://github.com/BuGo/git-hooks-helper
48
48
  licenses: []
49
+ metadata: {}
49
50
  post_install_message:
50
51
  rdoc_options: []
51
52
  require_paths:
52
53
  - lib
53
54
  required_ruby_version: !ruby/object:Gem::Requirement
54
- none: false
55
55
  requirements:
56
- - - ! '>='
56
+ - - ">="
57
57
  - !ruby/object:Gem::Version
58
58
  version: '0'
59
59
  required_rubygems_version: !ruby/object:Gem::Requirement
60
- none: false
61
60
  requirements:
62
- - - ! '>='
61
+ - - ">="
63
62
  - !ruby/object:Gem::Version
64
63
  version: '0'
65
64
  requirements: []
66
65
  rubyforge_project:
67
- rubygems_version: 1.8.10
66
+ rubygems_version: 2.1.11
68
67
  signing_key:
69
- specification_version: 3
68
+ specification_version: 4
70
69
  summary: Small gem to help write simple git hooks
71
70
  test_files: []
71
+ has_rdoc: