renuo-bin-check 0.2.1 → 1.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ff44c0cca4c757a3b2217a89ace55403cf337e9d
4
- data.tar.gz: 7961ea8b231c3066b7424b41e78fef4528308f8f
3
+ metadata.gz: 49b29562f89e957c52c206a952c8f84b3856915d
4
+ data.tar.gz: 0d97bdbf04362dce1aac65134a65b42cecbcb30a
5
5
  SHA512:
6
- metadata.gz: cef222fd0620af85910bca2755a36a47ad6adb8bb0a2c9b93bcf9455cd0c5f100c30db793bb8878e0982312de493c5f9c3065f9cfa5dd5814b789a2594424955
7
- data.tar.gz: 67242eb0cddc9323f27ae1652fd9d401d5677eeffd496c7b2e12bc808c2fd83c912784706a7f0729c63987ee7adc509e7e668898d0380d0054a1591d98a0448a
6
+ metadata.gz: d61ab0b4118331bfa28413ec370a9d4f2d9bb5af2cf17bae2f3cef757613a8ff9d153beeb027ab92c5635ac339486c7fde0bbe351bcb9ca86a3d2fe842c48c09
7
+ data.tar.gz: d6982dd518a622bd5c55a4e2ac73ce95c63553e21395a4fc7c34982e147a1f316343cfbe0bf9c6a0d62f52be1c052fdea4a29a0462a95632808082b217b0ec80
data/CHANGELOG.md CHANGED
@@ -39,3 +39,17 @@ This was implemented as many Scripts use the Standard-Output for Outputs even if
39
39
 
40
40
  * fixed typos
41
41
  * refined readme
42
+
43
+ ## Version 1.0.0.beta1
44
+
45
+ This release introduces a new fancy DSL (yeyy) which is easier to use and brings in much more possibilities
46
+
47
+ ### New Features
48
+
49
+ * New DSL is implemented (old one still works for now, but the following features only work with the new one.)
50
+
51
+ * Common Configuration for multiple checks
52
+
53
+ * Defaults are available and can be used
54
+
55
+ * Possibility to exclude specific checks of a default
data/README.md CHANGED
@@ -11,27 +11,55 @@ For faster runtime it makes use of caching and parallel execution.
11
11
  Add renuo-bin-check to your Gemfile:
12
12
 
13
13
  ```rb
14
- gem 'renuo-bin-check'
14
+ gem 'renuo-bin-check', group: :bin_check
15
15
  ```
16
16
 
17
17
  Create a file at any place you want. Usually it would be called `bin/check though.
18
- You can now configure your scripts like that:
18
+ You can now configure your checks like that:
19
19
 
20
20
  ```rb
21
- require 'renuo-bin-check'
21
+ #require renuo_bin_check in your file
22
+ require 'bundler/setup'
23
+ Bundler.require(:bin_check)
24
+
25
+ # run bin-check with rails-defaults
26
+ BinCheck.run do
27
+ #add a new check
28
+ <name-of-check> do
29
+ command "<a one line command or a path to a script>"
30
+ files ['<path-to-file-1>', '<path-to-file-2>']
31
+ reversed_exit <true or false>
32
+ success_message '<output to display if script succeeds>'
33
+ error_message '<output to display if script fails>'
34
+ end
35
+
36
+ #exclude a default check
37
+ exclude :<name-of-default-check>
38
+ end
22
39
 
23
- bin_check = RenuoBinCheck::Initializer.new
40
+ ```
24
41
 
25
- # add a script, do this for as many scripts as you would like to run
26
- bin_check.check do |config|
27
- config.command "<a one line command or a path to a script>"
28
- config.name "<name-of-script>"
29
- config.files ['<path-to-file-1>', '<path-to-file-2>']
30
- config.reversed_exit <true or false>
31
- end
42
+ It is also possible to have common configurations and to not run the rails-defaults:
32
43
 
33
- #run all scripts configured above
34
- bin_check.run
44
+ ```rb
45
+ #run bin without defaults
46
+ BinCheck.run :no_defaults do
47
+ # define common settings for all checks in the block
48
+ <name of your common configuration> do
49
+ reversed_exit <true or false>
50
+ success_message '<output to display if script succeeds>'
51
+ error_message '<output to display if script fails>'
52
+
53
+ # add check
54
+ <name-of-check> do
55
+ # add specific settings for this check
56
+ command "<a one line command or a path to a script>"
57
+ files ['<path-to-file-1>', '<path-to-file-2>']
58
+ # override common settings
59
+ reversed_exit <true or false>
60
+ end
61
+ end
62
+ end
35
63
  ```
36
64
 
37
65
  ## Setup
@@ -55,16 +83,6 @@ The following script will run *rspec*, *rubocop*, *reek*, scanner for debugging
55
83
  This option is required. It is either a one-liner such as `ls -al` or a path to a script, that will be runned.
56
84
  If command is not configured, the program will raise a RuntimeError.
57
85
 
58
- #### name
59
-
60
- This option is optional. It makes it possible to configure the name of the script.
61
- It will be used as folder name in the cache.
62
-
63
- If it is not set, the hashed command will be used as folder name in the cache.
64
-
65
- Attention: If you set the same name twice, it won't raise an error,
66
- but it can cause unexpected behaviour, hence it is not recommanded to do so.
67
-
68
86
  #### files
69
87
 
70
88
  This option is optional. If configured the script output will be cached. You need to list all files in array form,
@@ -99,23 +117,83 @@ If set to truthy, the output of the configured script will be reversed. Which me
99
117
  An example where this option is used, is the command that searches for TODOs.
100
118
  The script should fail though if something is found and not if nothing is found.
101
119
 
120
+ ### Defaults
121
+
122
+ For using renuo-bin-check for checking rails applications we have defaults the following defaults:
123
+
124
+ Usage of defaults:
125
+
126
+ ```
127
+ # use defaults, or don't use any by using :no-defaults
128
+ BinCheck.run :<name-of-default> {}
129
+ ```
130
+
131
+ Excluding specific checks from defaults example:
132
+
133
+ ```
134
+ BinCheck.run :rails_coffee_script_defaults do
135
+ exclude :todo
136
+ exclude :reek
137
+ end
138
+ ```
139
+
140
+ #### rails_defaults (will be used if no default is given)
141
+
142
+ It includes following checks:
143
+ * todo (searches for todos in the code)
144
+ * console_log (searches for console_log in the code)
145
+ * puts_with_brackets (searches for puts( in the code)
146
+ * puts_without_brackets (searches for puts in the code)
147
+ * pp_and_p (searches for p and pp in the code)
148
+ * p_with_brackets (searches for p( in the code)
149
+ * rubocop_autocorrect (runs rubocop with autocorrection)
150
+ * slim_lint (runs slim_lint)
151
+ * scss_lint (runs scss_lint ATTENTION: THIS DOESN'T WORK YET)
152
+ * tslint (runs tslint)
153
+ * brakeman (runs brakeman)
154
+ * reek (runs reek ATTENTION: THIS DOESN'T WORK YET)
155
+ * rspec (runs rspec)
156
+
157
+ #### rails_coffee_script_defaults
158
+
159
+ It includes following checks:
160
+ * todo (searches for todos in the code)
161
+ * console_log (searches for console_log in the code)
162
+ * puts_with_brackets (searches for puts( in the code)
163
+ * puts_without_brackets (searches for puts in the code)
164
+ * pp_and_p (searches for p and pp in the code)
165
+ * p_with_brackets (searches for p( in the code)
166
+ * rubocop_autocorrect (runs rubocop with autocorrection)
167
+ * slim_lint (runs slim_lint)
168
+ * scss_lint (runs scss_lint ATTENTION: THIS DOESN'T WORK YET)
169
+ * coffeelint (runs coffeelint ATTENTION: THIS ISN'T TESTED YET)
170
+ * brakeman (runs brakeman)
171
+ * reek (runs reek ATTENTION: THIS DOESN'T WORK YET)
172
+ * rspec (runs rspec)
173
+
102
174
  ### Example
103
175
 
104
176
  The following example configures a script that looks for TODOs in a project.
105
177
  The configuration options can be called in any order.
106
178
 
107
179
  ```rb
108
- bin_check.check do |config|
109
- config.command "grep --exclude-dir='app/assets/typings/**' -i -r 'TODO'"\
110
- "app spec config db Rakefile README.md Gemfile"
111
- config.name "todo-grepper"
112
- config.files ['app/**/*', 'spec/**/*', 'config/**/*', 'db/**/*', 'Rakefile', 'README.md', 'Gemfile']
113
- config.success_message "No TODO was found :)"
114
- config.error_message "+TODO found! Please get rid of them"
115
- config.reversed_exit true
180
+ BinCheck do
181
+ todo-grepper do
182
+ command "grep --exclude-dir='app/assets/typings/**' -i -r 'TODO'"\
183
+ "app spec config db Rakefile README.md Gemfile"
184
+ files ['app/**/*', 'spec/**/*', 'config/**/*', 'db/**/*', 'Rakefile', 'README.md', 'Gemfile']
185
+ success_message "No TODO was found :)"
186
+ error_message "+TODO found! Please get rid of them"
187
+ reversed_exit true
188
+ end
116
189
  end
117
190
  ```
118
191
 
192
+ ## Known Bugs
193
+
194
+ * scss-lint doesnt work yet with renuo-bin-check
195
+ * reek doesnt work yet with renuo-bin-check
196
+
119
197
  ## Contribute
120
198
 
121
199
  If you would like to contribute, you're very welcome to.
@@ -127,7 +205,7 @@ Please follow these instructions:
127
205
 
128
206
  ## License
129
207
 
130
- Copyright (c) 2016 [Renuo GmbH]
208
+ Copyright (c) 2016 [Renuo AG]
131
209
 
132
210
  [MIT License][6]
133
211
 
@@ -140,4 +218,4 @@ Copyright (c) 2016 [Renuo GmbH]
140
218
  [5]: https://github.com/renuo/renuo-bin-check/blob/develop/CODE_OF_CONDUCT.md
141
219
  [6]: https://github.com/renuo/renuo-bin-check/blob/develop/LICENSE
142
220
 
143
- [Renuo GmbH]: https://www.renuo.ch
221
+ [Renuo AG]: https://www.renuo.ch
data/bin/check CHANGED
@@ -9,37 +9,37 @@ if [ $? -eq 0 ]; then
9
9
  exit 1
10
10
  fi
11
11
 
12
- grep --exclude-dir="lib/renuo_bin_check/default_scripts" -i -r 'TODO' lib spec Gemfile
12
+ grep --exclude-dir={"lib/renuo_bin_check/default_scripts","spec/renuo/bin-check/default_scripts"} -i -r 'TODO' lib spec Gemfile
13
13
  if [ $? -eq 0 ]; then
14
14
  echo 'TODOs found. Please fix them and try again, commit aborted'
15
15
  exit 1
16
16
  fi
17
17
 
18
- grep --exclude-dir="lib/renuo_bin_check/default_scripts" -i -r 'console.log' lib spec
18
+ grep --exclude-dir={"lib/renuo_bin_check/default_scripts","spec/renuo/bin-check/default_scripts"} -i -r 'console.log' lib spec
19
19
  if [ $? -eq 0 ]; then
20
20
  echo 'console.log found. Please fix them and try again, commit aborted'
21
21
  exit 1
22
22
  fi
23
23
 
24
- grep --exclude-dir="lib/renuo_bin_check/default_scripts" -i -r ' puts ' lib spec
24
+ grep --exclude-dir={"lib/renuo_bin_check/default_scripts","spec/renuo/bin-check/default_scripts"} -i -r ' puts ' lib spec
25
25
  if [ $? -eq 0 ]; then
26
26
  echo 'puts found. Please fix them and try again, commit aborted'
27
27
  exit 1
28
28
  fi
29
29
 
30
- grep --exclude-dir="lib/renuo_bin_check/default_scripts" -i -r ' puts(' lib spec
30
+ grep --exclude-dir={"lib/renuo_bin_check/default_scripts","spec/renuo/bin-check/default_scripts"} -i -r ' puts(' lib spec
31
31
  if [ $? -eq 0 ]; then
32
32
  echo 'puts found. Please fix them and try again, commit aborted'
33
33
  exit 1
34
34
  fi
35
35
 
36
- grep --exclude-dir="lib/renuo_bin_check/default_scripts" -i -r ' p ' lib spec
36
+ grep --exclude-dir={"lib/renuo_bin_check/default_scripts","spec/renuo/bin-check/default_scripts"} -i -r ' p ' lib spec
37
37
  if [ $? -eq 0 ]; then
38
38
  echo 'p found. Please fix them and try again, commit aborted'
39
39
  exit 1
40
40
  fi
41
41
 
42
- grep --exclude-dir="lib/renuo_bin_check/default_scripts" -i -r ' p(' lib spec
42
+ grep --exclude-dir={"lib/renuo_bin_check/default_scripts","spec/renuo/bin-check/default_scripts"} -i -r ' p(' lib spec
43
43
  if [ $? -eq 0 ]; then
44
44
  echo 'p found. Please fix them and try again, commit aborted'
45
45
  exit 1
@@ -1,3 +1,4 @@
1
+ require 'renuo_bin_check/bin_check'
1
2
  require 'renuo_bin_check/cacher'
2
3
  require 'renuo_bin_check/initializer'
3
4
  require 'renuo_bin_check/master_thread'
@@ -0,0 +1,59 @@
1
+ require 'renuo_bin_check/dsl_config'
2
+ require 'renuo_bin_check/default_scripts/default_scripts'
3
+
4
+ class BinCheck
5
+ def self.method_missing(name, *_params, &configs)
6
+ if block_given?
7
+ @configs << DSLConfig.new(name.to_s, &configs)
8
+ else
9
+ super
10
+ end
11
+ end
12
+
13
+ def respond_to_missing?
14
+ #:nocov:
15
+ true
16
+ #:nocov:
17
+ end
18
+
19
+ def self.run(default = :rails_defaults, &check)
20
+ @configs = DefaultScripts.new.send(default)
21
+ instance_eval(&check)
22
+ initialize_checks
23
+ end
24
+
25
+ def self.initialize_checks
26
+ @initializer = RenuoBinCheck::Initializer.new
27
+ @configs.each do |config|
28
+ if config.children?
29
+ add_children(config)
30
+ else
31
+ add_check(config.configs)
32
+ end
33
+ end
34
+ @initializer.run
35
+ end
36
+
37
+ def self.add_children(config)
38
+ config.children.each do |child|
39
+ add_check(child.parent.configs.merge(child.configs))
40
+ end
41
+ end
42
+
43
+ # :reek:NestedIterators initializer.check is not an iterator
44
+ def self.add_check(configs)
45
+ @initializer.check do |config|
46
+ configs.each do |key, value|
47
+ config.send key, value
48
+ end
49
+ end
50
+ end
51
+
52
+ def self.exclude(check_name)
53
+ @configs.delete_if { |config| config.configs[:name] == check_name.to_s }
54
+ end
55
+
56
+ class << self
57
+ attr_reader :configs
58
+ end
59
+ end
@@ -10,8 +10,8 @@ module RenuoBinCheck
10
10
  mini_profiler(bin_check)
11
11
  todo(bin_check)
12
12
  console_log(bin_check)
13
- put_without_brackets(bin_check)
14
- put_with_brackets(bin_check)
13
+ puts_without_brackets(bin_check)
14
+ puts_with_brackets(bin_check)
15
15
  pp_and_p(bin_check)
16
16
  p_with_brackets(bin_check)
17
17
  rubocop_autocorrect(bin_check)
@@ -52,7 +52,7 @@ module RenuoBinCheck
52
52
  end
53
53
  end
54
54
 
55
- def put_without_brackets(bin_check)
55
+ def puts_without_brackets(bin_check)
56
56
  bin_check.check do |config|
57
57
  config.command "grep -i -r ' puts ' app spec"
58
58
  config.reversed_exit true
@@ -60,7 +60,7 @@ module RenuoBinCheck
60
60
  end
61
61
  end
62
62
 
63
- def put_with_brackets(bin_check)
63
+ def puts_with_brackets(bin_check)
64
64
  bin_check.check do |config|
65
65
  config.command "grep -i -r ' puts(' app spec"
66
66
  config.reversed_exit true
@@ -143,8 +143,8 @@ module RenuoBinCheck
143
143
  module_function :mini_profiler
144
144
  module_function :todo
145
145
  module_function :console_log
146
- module_function :put_without_brackets
147
- module_function :put_with_brackets
146
+ module_function :puts_without_brackets
147
+ module_function :puts_with_brackets
148
148
  module_function :pp_and_p
149
149
  module_function :p_with_brackets
150
150
  module_function :rubocop_autocorrect
@@ -0,0 +1,168 @@
1
+ require 'renuo_bin_check/dsl_config'
2
+
3
+ # rubocop:disable Metrics/ClassLength
4
+ # :reek:TooManyMethods
5
+ class DefaultScripts
6
+ def initialize
7
+ @default_scripts = []
8
+ end
9
+
10
+ def no_defaults
11
+ []
12
+ end
13
+
14
+ # rubocop:disable Metrics/MethodLength
15
+ # :reek:TooManyStatements
16
+ def rails_defaults
17
+ todo
18
+ console_log
19
+ puts_with_brackets
20
+ puts_without_brackets
21
+ pp_and_p
22
+ p_with_brackets
23
+ rubocop_autocorrect
24
+ slim_lint
25
+ scss_lint
26
+ tslint
27
+ brakeman
28
+ reek
29
+ rspec
30
+ @default_scripts
31
+ end
32
+
33
+ # :reek:TooManyStatements
34
+ def rails_coffee_script_defaults
35
+ todo
36
+ console_log
37
+ puts_with_brackets
38
+ puts_without_brackets
39
+ pp_and_p
40
+ p_with_brackets
41
+ rubocop_autocorrect
42
+ slim_lint
43
+ scss_lint
44
+ coffeelint
45
+ brakeman
46
+ reek
47
+ rspec
48
+ @default_scripts
49
+ end
50
+ # rubocop:enable Metrics/MethodLength
51
+
52
+ def todo
53
+ @default_scripts << DSLConfig.new('todo') do
54
+ command "grep --exclude-dir='app/assets/typings/**' -i -r 'TODO' app spec config db Rakefile README.md Gemfile"
55
+ reversed_exit true
56
+ files ['app/**/*', 'spec/**/*', 'config/**/*', 'db/**/*', 'Rakefile', 'README.md', 'Gemfile']
57
+ success_message '+TODOs found. Please fix them and try again, commit aborted'
58
+ end
59
+ end
60
+
61
+ def console_log
62
+ @default_scripts << DSLConfig.new('console_log') do
63
+ command "grep -i -r 'console.log' app spec"
64
+ reversed_exit true
65
+ files ['app/**/*', 'spec/**/*']
66
+ success_message '+console.log found. Please fix them and try again, commit aborted'
67
+ end
68
+ end
69
+
70
+ def puts_without_brackets
71
+ @default_scripts << DSLConfig.new('puts_without_brackets') do
72
+ command "grep -i -r ' puts ' app spec"
73
+ reversed_exit true
74
+ files ['app/**/*', 'spec/**/*']
75
+ success_message '+puts found. Please fix them and try again, commit aborted'
76
+ end
77
+ end
78
+
79
+ def puts_with_brackets
80
+ @default_scripts << DSLConfig.new('puts_with_brackets') do
81
+ command "grep -i -r ' puts(' app spec"
82
+ reversed_exit true
83
+ files ['app/**/*', 'spec/**/*']
84
+ success_message '+puts( found. Please fix them and try again, commit aborted'
85
+ end
86
+ end
87
+
88
+ def pp_and_p
89
+ @default_scripts << DSLConfig.new('pp_and_p') do
90
+ command "grep -i -r '( pp? [^=])|(= pp? )' app spec"
91
+ reversed_exit true
92
+ files ['app/**/*', 'spec/**/*']
93
+ success_message '+p or pp found. Please fix them and try again, commit aborted'
94
+ end
95
+ end
96
+
97
+ def p_with_brackets
98
+ @default_scripts << DSLConfig.new('p_with_brackets') do
99
+ command "grep -i -r ' p(' app spec"
100
+ reversed_exit true
101
+ files ['app/**/*', 'spec/**/*']
102
+ success_message '+p( found. Please fix them and try again, commit aborted'
103
+ end
104
+ end
105
+
106
+ def rubocop_autocorrect
107
+ @default_scripts << DSLConfig.new('rubocop_autocorrect') do
108
+ command 'bundle exec rubocop -a -D -c .rubocop.yml'
109
+ files ['app/**/*.rb', 'spec/**/*.rb']
110
+ end
111
+ end
112
+
113
+ def slim_lint
114
+ @default_scripts << DSLConfig.new('slim_lint') do
115
+ command 'bundle exec slim-lint app/views/ -c .slim-lint.yml'
116
+ files ['app/views/**/*.slim']
117
+ error_message '+slim-lint detected issues, commit aborted'
118
+ end
119
+ end
120
+
121
+ def scss_lint
122
+ @default_scripts << DSLConfig.new('scss_lint') do
123
+ command 'scss-lint app/assets/stylesheets/**/*.scss'
124
+ files ['app/assets/stylesheets/**/*.scss']
125
+ error_message '+scss-lint detected issues, commit aborted'
126
+ end
127
+ end
128
+
129
+ def tslint
130
+ @default_scripts << DSLConfig.new('tslint') do
131
+ command 'tslint -c tslint.json app/assets/javascripts/**/*.ts'
132
+ files ['app/assets/javascripts/**/*.ts']
133
+ error_message '+tslint detected issues, commit aborted'
134
+ end
135
+ end
136
+
137
+ def coffeelint
138
+ @default_scripts << DSLConfig.new('coffeelint') do
139
+ command 'coffeelint -f .coffeelint.json app/assets/javascripts/**/*.coffee'
140
+ files ['app/assets/javascripts/**/*.coffee']
141
+ error_message '+coffeelint detected issues, commit aborted'
142
+ end
143
+ end
144
+
145
+ def brakeman
146
+ @default_scripts << DSLConfig.new('brakeman') do
147
+ command 'bundle exec brakeman -q -z --summary > /dev/null'
148
+ error_message '+Brakeman has detected one or more security vulnerabilities, please review them and re-commit ' \
149
+ 'your changes, commit aborted'
150
+ end
151
+ end
152
+
153
+ def reek
154
+ @default_scripts << DSLConfig.new('reek') do
155
+ command 'bundle exec reek'
156
+ files ['app/**/*.rb']
157
+ error_message '+reek detected code smells, commit aborted'
158
+ end
159
+ end
160
+
161
+ def rspec
162
+ @default_scripts << DSLConfig.new('rspec') do
163
+ command 'bundle exec rspec'
164
+ files ['app/**/*.rb', 'spec/**/*.rb']
165
+ end
166
+ end
167
+ end
168
+ # rubocop:enable Metrics/ClassLength
@@ -0,0 +1,47 @@
1
+ class DSLConfig
2
+ attr_reader :configs, :children, :parent
3
+ def initialize(name, parent = nil, &configs)
4
+ @parent = parent
5
+ @children = []
6
+ @configs = { name: name }
7
+ instance_eval(&configs)
8
+ end
9
+
10
+ def method_missing(name, *_params, &configs)
11
+ if block_given?
12
+ @children << DSLConfig.new(name.to_s, self, &configs)
13
+ else
14
+ super
15
+ end
16
+ end
17
+
18
+ def respond_to_missing?(_method_name, _include_private)
19
+ #:nocov:
20
+ true
21
+ #:nocov:
22
+ end
23
+
24
+ def files(files)
25
+ @configs[:files] = files
26
+ end
27
+
28
+ def command(command)
29
+ @configs[:command] = command
30
+ end
31
+
32
+ def reversed_exit(reversed_exit)
33
+ @configs[:reversed_exit] = reversed_exit
34
+ end
35
+
36
+ def error_message(error_message)
37
+ @configs[:error_message] = error_message
38
+ end
39
+
40
+ def success_message(success_message)
41
+ @configs[:success_message] = success_message
42
+ end
43
+
44
+ def children?
45
+ !@children.empty?
46
+ end
47
+ end
@@ -22,7 +22,7 @@ module RenuoBinCheck
22
22
  until waiter.empty?
23
23
  result = waiter.next_wait[:result]
24
24
  @results << result
25
- exit_with_error(result) if result.exit_code == 1
25
+ exit_with_error(result) if result.exit_code.nonzero?
26
26
  end
27
27
  exit_with_success
28
28
  end
@@ -37,7 +37,7 @@ module RenuoBinCheck
37
37
  end
38
38
 
39
39
  def reverse_result
40
- Result.new(@result.error_output, @result.standard_output, @result.exit_code == 0 ? 1 : 0)
40
+ Result.new(@result.error_output, @result.standard_output, @result.exit_code.zero? ? 1 : 0)
41
41
  end
42
42
  end
43
43
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module RenuoBinCheck
3
- VERSION = '0.2.1'
3
+ VERSION = '1.0.0.beta1'
4
4
  end
@@ -0,0 +1,213 @@
1
+ require 'spec_helper'
2
+ require './lib/renuo_bin_check/bin_check'
3
+
4
+ RSpec.describe BinCheck do
5
+ context 'without caching' do
6
+ it 'returns exit-code 0 and expected output' do
7
+ expect do
8
+ begin
9
+ BinCheck.run :no_defaults do
10
+ exit0_script do
11
+ command './spec/spec-files/test_script_exit0'
12
+ end
13
+ end
14
+ rescue SystemExit => se
15
+ expect(se.status).to eq(0)
16
+ end
17
+ end.to output("I passed\nThis is the second line\n").to_stdout
18
+ end
19
+
20
+ it 'returns exit-code 0 and expected output' do
21
+ expect do
22
+ begin
23
+ BinCheck.run :no_defaults do
24
+ hello_script do
25
+ command 'echo hello'
26
+ end
27
+ end
28
+ rescue SystemExit => se
29
+ expect(se.status).to eq(0)
30
+ end
31
+ end.to output("hello\n").to_stdout
32
+ end
33
+
34
+ it 'returns exit-code 0 and expected overridden output' do
35
+ expect do
36
+ begin
37
+ BinCheck.run :no_defaults do
38
+ hello_script do
39
+ command 'echo hello'
40
+ success_message 'I passed :)'
41
+ end
42
+ end
43
+ rescue SystemExit => se
44
+ expect(se.status).to eq(0)
45
+ end
46
+ end.to output("I passed :)\n").to_stdout
47
+ end
48
+
49
+ it 'returns exit-code 0 and expected appended output' do
50
+ expect do
51
+ begin
52
+ BinCheck.run :no_defaults do
53
+ hello_script do
54
+ command 'echo hello'
55
+ success_message '+I passed :)'
56
+ end
57
+ end
58
+ rescue SystemExit => se
59
+ expect(se.status).to eq(0)
60
+ end
61
+ end.to output("hello\nI passed :)\n").to_stdout
62
+ end
63
+
64
+ it 'returns exit-code 1 and expected error-output' do
65
+ expect do
66
+ begin
67
+ BinCheck.run :no_defaults do
68
+ exit1_script do
69
+ command './spec/spec-files/test_script_exit1'
70
+ end
71
+ end
72
+ rescue SystemExit => se
73
+ expect(se.status).to eq(1)
74
+ end
75
+ end.to output("I failed\nThis is the second line\n").to_stderr
76
+ end
77
+
78
+ it 'returns exit-code 1 and expected non-error-output' do
79
+ expect do
80
+ begin
81
+ BinCheck.run :no_defaults do
82
+ exit1_script do
83
+ command './spec/spec-files/test_script_exit1_no_error_output'
84
+ end
85
+ end
86
+ rescue SystemExit => se
87
+ expect(se.status).to eq(1)
88
+ end
89
+ end.to output("I failed\nThis is the second line\n").to_stderr
90
+ end
91
+
92
+ it 'returns exit-code 1 and expected overridden error-output' do
93
+ expect do
94
+ begin
95
+ BinCheck.run :no_defaults do
96
+ exit1_script do
97
+ command './spec/spec-files/test_script_exit1'
98
+ error_message 'it failed...'
99
+ end
100
+ end
101
+ rescue SystemExit => se
102
+ expect(se.status).to eq(1)
103
+ end
104
+ end.to output("it failed...\n").to_stderr
105
+ end
106
+
107
+ it 'returns exit-code 1 and expected appended error-output' do
108
+ expect do
109
+ begin
110
+ BinCheck.run :no_defaults do
111
+ exit1_script do
112
+ command './spec/spec-files/test_script_exit1'
113
+ error_message '+it failed...'
114
+ end
115
+ end
116
+ rescue SystemExit => se
117
+ expect(se.status).to eq(1)
118
+ end
119
+ end.to output("I failed\nThis is the second line\nit failed...\n").to_stderr
120
+ end
121
+
122
+ it 'uses the common configuration right' do
123
+ expect do
124
+ begin
125
+ BinCheck.run :no_defaults do
126
+ cute_scripts do
127
+ success_message '+common configuration'
128
+ hello_script do
129
+ command 'echo hello'
130
+ end
131
+ bye_script do
132
+ command 'sleep 1 && echo bye'
133
+ end
134
+ end
135
+ end
136
+ rescue SystemExit => se
137
+ expect(se.status).to eq(0)
138
+ end
139
+ end.to output("hello\ncommon configuration\nbye\ncommon configuration\n").to_stdout
140
+ end
141
+
142
+ it 'runns scripts parallel' do
143
+ start_time = Time.now
144
+ begin
145
+ BinCheck.run :no_defaults do
146
+ sleep1 do
147
+ command './spec/spec-files/test_script_sleep1'
148
+ end
149
+ sleep2 do
150
+ command './spec/spec-files/test_script_sleep2'
151
+ end
152
+ end
153
+ rescue SystemExit => se
154
+ expect(se.status).to eq(0)
155
+ end
156
+ end_time = Time.now
157
+ expect(end_time - start_time).to be_within(0.4).of(2)
158
+ end
159
+ end
160
+
161
+ context 'cached script' do
162
+ before(:each) do
163
+ FileUtils.mkdir_p 'tmp/bin-check/exit0/df57ab93c06ded11a01f2de950307019'
164
+ File.write 'tmp/bin-check/exit0/df57ab93c06ded11a01f2de950307019/standard_output',
165
+ "I'm cached\npassed\n"
166
+ File.write 'tmp/bin-check/exit0/df57ab93c06ded11a01f2de950307019/error_output',
167
+ "I'm cached\npassed\n"
168
+ File.write 'tmp/bin-check/exit0/df57ab93c06ded11a01f2de950307019/exit_code', 0
169
+ end
170
+
171
+ after(:each) { FileUtils.remove_dir('./tmp/bin-check') }
172
+
173
+ it 'returns cached output and exit-code' do
174
+ expect do
175
+ begin
176
+ BinCheck.run :no_defaults do
177
+ exit0 do
178
+ command './spec/spec-files/test_script_exit0'
179
+ files %w(./spec/spec-files/file1 ./spec/spec-files/file2)
180
+ end
181
+ end
182
+ rescue SystemExit => se
183
+ expect(se.status).to eq(0)
184
+ end
185
+ end.to output("I'm cached\npassed\n").to_stdout
186
+ end
187
+ end
188
+
189
+ context 'saving to exit0 folder' do
190
+ after(:each) { FileUtils.remove_dir('./tmp/bin-check') }
191
+
192
+ it 'saves output and exit-code to files in folder named by given name' do
193
+ expect do
194
+ begin
195
+ BinCheck.run :no_defaults do
196
+ exit0 do
197
+ command './spec/spec-files/test_script_exit0'
198
+ files %w(./spec/spec-files/file1 ./spec/spec-files/file2)
199
+ end
200
+ end
201
+ rescue SystemExit => se
202
+ expect(se.status).to eq(0)
203
+ end
204
+ end.to output("I passed\nThis is the second line\n").to_stdout
205
+
206
+ expect(File.read('./tmp/bin-check/exit0/df57ab93c06ded11a01f2de950307019/error_output'))
207
+ .to eq("I failed\nThis is the second line\n")
208
+ expect(File.read('./tmp/bin-check/exit0/df57ab93c06ded11a01f2de950307019/standard_output'))
209
+ .to eq("I passed\nThis is the second line\n")
210
+ expect(File.read('./tmp/bin-check/exit0/df57ab93c06ded11a01f2de950307019/exit_code').to_i).to eq(0)
211
+ end
212
+ end
213
+ end
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+ require './lib/renuo_bin_check/bin_check'
3
+
4
+ RSpec.describe BinCheck do
5
+ it 'gets the right infos out of a new check' do
6
+ expect(BinCheck).to receive(:initialize_checks).and_return(true)
7
+ expect_any_instance_of(DefaultScripts).to receive(:rails_defaults).and_return([])
8
+
9
+ BinCheck.run do
10
+ rubocop do
11
+ files 'lib/**/*.rb'
12
+ command 'rubocop'
13
+ reversed_exit false
14
+ end
15
+
16
+ t0d0_finder do
17
+ files 'lib/**/*.*'
18
+ command 'blubb-blubb'
19
+ reversed_exit true
20
+ end
21
+ end
22
+
23
+ expect(BinCheck.configs.first.configs)
24
+ .to eq(name: 'rubocop', files: 'lib/**/*.rb', command: 'rubocop', reversed_exit: false)
25
+ expect(BinCheck.configs[1].configs)
26
+ .to eq(name: 't0d0_finder', files: 'lib/**/*.*', command: 'blubb-blubb', reversed_exit: true)
27
+ end
28
+
29
+ it 'understands common configs' do
30
+ expect(BinCheck).to receive(:initialize_checks).and_return(true)
31
+ expect_any_instance_of(DefaultScripts).to receive(:rails_defaults).and_return([])
32
+
33
+ BinCheck.run do
34
+ ruby_files do
35
+ files 'lib/**/*.rb'
36
+ rubocop do
37
+ command 'rubocop'
38
+ reversed_exit false
39
+ end
40
+ p_finder do
41
+ command 'blubb-blubb'
42
+ reversed_exit true
43
+ end
44
+ end
45
+ end
46
+ expect(BinCheck.configs.first.configs.merge(BinCheck.configs.first.children.first.configs))
47
+ .to eq(name: 'rubocop', files: 'lib/**/*.rb', command: 'rubocop', reversed_exit: false)
48
+ expect(BinCheck.configs.first.configs.merge(BinCheck.configs.first.children[1].configs))
49
+ .to eq(name: 'p_finder', files: 'lib/**/*.rb', command: 'blubb-blubb', reversed_exit: true)
50
+ end
51
+
52
+ it 'excluds unwanted default checks' do
53
+ expect(BinCheck).to receive(:initialize_checks).and_return(true)
54
+
55
+ BinCheck.run do
56
+ exclude :config_log
57
+ end
58
+
59
+ BinCheck.configs.each do |config|
60
+ expect(config.configs).not_to include(name: 'config_log')
61
+ end
62
+ end
63
+
64
+ it 'calls super if no block is given' do
65
+ expect { BinCheck.blubb }.to raise_error(NoMethodError)
66
+ end
67
+ end
@@ -0,0 +1,191 @@
1
+ require 'spec_helper'
2
+ require './lib/renuo_bin_check/default_scripts/default_scripts'
3
+
4
+ RSpec.describe DefaultScripts do
5
+ let(:default_scripts) { DefaultScripts.new }
6
+
7
+ it 'uses all scripts needed for rails default' do
8
+ expect(default_scripts).to receive(:todo)
9
+ expect(default_scripts).to receive(:console_log)
10
+ expect(default_scripts).to receive(:puts_with_brackets)
11
+ expect(default_scripts).to receive(:puts_without_brackets)
12
+ expect(default_scripts).to receive(:pp_and_p)
13
+ expect(default_scripts).to receive(:p_with_brackets)
14
+ expect(default_scripts).to receive(:rubocop_autocorrect)
15
+ expect(default_scripts).to receive(:slim_lint)
16
+ expect(default_scripts).to receive(:scss_lint)
17
+ expect(default_scripts).to receive(:tslint)
18
+ expect(default_scripts).to receive(:brakeman)
19
+ expect(default_scripts).to receive(:reek)
20
+ expect(default_scripts).to receive(:rspec)
21
+
22
+ default_scripts.rails_defaults
23
+ end
24
+
25
+ it 'uses all scripts needed for rails default if coffee is used' do
26
+ expect(default_scripts).to receive(:todo)
27
+ expect(default_scripts).to receive(:console_log)
28
+ expect(default_scripts).to receive(:puts_with_brackets)
29
+ expect(default_scripts).to receive(:puts_without_brackets)
30
+ expect(default_scripts).to receive(:pp_and_p)
31
+ expect(default_scripts).to receive(:p_with_brackets)
32
+ expect(default_scripts).to receive(:rubocop_autocorrect)
33
+ expect(default_scripts).to receive(:slim_lint)
34
+ expect(default_scripts).to receive(:scss_lint)
35
+ expect(default_scripts).to receive(:coffeelint)
36
+ expect(default_scripts).to receive(:brakeman)
37
+ expect(default_scripts).to receive(:reek)
38
+ expect(default_scripts).to receive(:rspec)
39
+
40
+ default_scripts.rails_coffee_script_defaults
41
+ end
42
+
43
+ it '#no_default' do
44
+ expect(default_scripts.no_defaults).to eq([])
45
+ end
46
+
47
+ it '#todo' do
48
+ expect(default_scripts.todo.last.configs)
49
+ .to eq(
50
+ name: 'todo',
51
+ command: "grep --exclude-dir='app/assets/typings/**' -i -r 'TODO' app spec config db Rakefile README.md" \
52
+ ' Gemfile',
53
+ reversed_exit: true,
54
+ files: ['app/**/*', 'spec/**/*', 'config/**/*', 'db/**/*', 'Rakefile', 'README.md', 'Gemfile'],
55
+ success_message: '+TODOs found. Please fix them and try again, commit aborted'
56
+ )
57
+ end
58
+
59
+ it '#console_log' do
60
+ expect(default_scripts.console_log.last.configs)
61
+ .to eq(
62
+ name: 'console_log',
63
+ command: "grep -i -r 'console.log' app spec",
64
+ reversed_exit: true,
65
+ files: ['app/**/*', 'spec/**/*'],
66
+ success_message: '+console.log found. Please fix them and try again, commit aborted'
67
+ )
68
+ end
69
+
70
+ it '#puts_without_brackets' do
71
+ expect(default_scripts.puts_without_brackets.last.configs)
72
+ .to eq(
73
+ name: 'puts_without_brackets',
74
+ command: "grep -i -r ' puts ' app spec",
75
+ reversed_exit: true,
76
+ files: ['app/**/*', 'spec/**/*'],
77
+ success_message: '+puts found. Please fix them and try again, commit aborted'
78
+ )
79
+ end
80
+
81
+ it '#puts_with_brackets' do
82
+ expect(default_scripts.puts_with_brackets.last.configs)
83
+ .to eq(
84
+ name: 'puts_with_brackets',
85
+ command: "grep -i -r ' puts(' app spec",
86
+ reversed_exit: true,
87
+ files: ['app/**/*', 'spec/**/*'],
88
+ success_message: '+puts( found. Please fix them and try again, commit aborted'
89
+ )
90
+ end
91
+
92
+ it '#pp_and_p' do
93
+ expect(default_scripts.pp_and_p.last.configs)
94
+ .to eq(
95
+ name: 'pp_and_p',
96
+ command: "grep -i -r '( pp? [^=])|(= pp? )' app spec",
97
+ reversed_exit: true,
98
+ files: ['app/**/*', 'spec/**/*'],
99
+ success_message: '+p or pp found. Please fix them and try again, commit aborted'
100
+ )
101
+ end
102
+
103
+ it '#p_with_brackets' do
104
+ expect(default_scripts.p_with_brackets.last.configs)
105
+ .to eq(
106
+ name: 'p_with_brackets',
107
+ command: "grep -i -r ' p(' app spec",
108
+ reversed_exit: true,
109
+ files: ['app/**/*', 'spec/**/*'],
110
+ success_message: '+p( found. Please fix them and try again, commit aborted'
111
+ )
112
+ end
113
+
114
+ it '#rubocop_autocorrect' do
115
+ expect(default_scripts.rubocop_autocorrect.last.configs)
116
+ .to eq(
117
+ name: 'rubocop_autocorrect',
118
+ command: 'bundle exec rubocop -a -D -c .rubocop.yml',
119
+ files: ['app/**/*.rb', 'spec/**/*.rb']
120
+ )
121
+ end
122
+
123
+ it '#slim_lint' do
124
+ expect(default_scripts.slim_lint.last.configs)
125
+ .to eq(
126
+ name: 'slim_lint',
127
+ command: 'bundle exec slim-lint app/views/ -c .slim-lint.yml',
128
+ files: ['app/views/**/*.slim'],
129
+ error_message: '+slim-lint detected issues, commit aborted'
130
+ )
131
+ end
132
+
133
+ it '#scss_lint' do
134
+ expect(default_scripts.scss_lint.last.configs)
135
+ .to eq(
136
+ name: 'scss_lint',
137
+ command: 'scss-lint app/assets/stylesheets/**/*.scss',
138
+ files: ['app/assets/stylesheets/**/*.scss'],
139
+ error_message: '+scss-lint detected issues, commit aborted'
140
+ )
141
+ end
142
+
143
+ it '#tslint' do
144
+ expect(default_scripts.tslint.last.configs)
145
+ .to eq(
146
+ name: 'tslint',
147
+ command: 'tslint -c tslint.json app/assets/javascripts/**/*.ts',
148
+ files: ['app/assets/javascripts/**/*.ts'],
149
+ error_message: '+tslint detected issues, commit aborted'
150
+ )
151
+ end
152
+
153
+ it '#coffeelint' do
154
+ expect(default_scripts.coffeelint.last.configs)
155
+ .to eq(
156
+ name: 'coffeelint',
157
+ command: 'coffeelint -f .coffeelint.json app/assets/javascripts/**/*.coffee',
158
+ files: ['app/assets/javascripts/**/*.coffee'],
159
+ error_message: '+coffeelint detected issues, commit aborted'
160
+ )
161
+ end
162
+
163
+ it '#brakeman' do
164
+ expect(default_scripts.brakeman.last.configs)
165
+ .to eq(
166
+ name: 'brakeman',
167
+ command: 'bundle exec brakeman -q -z --summary > /dev/null',
168
+ error_message: '+Brakeman has detected one or more security vulnerabilities, please review them and re-commit' \
169
+ ' your changes, commit aborted'
170
+ )
171
+ end
172
+
173
+ it '#reek' do
174
+ expect(default_scripts.reek.last.configs)
175
+ .to eq(
176
+ name: 'reek',
177
+ command: 'bundle exec reek',
178
+ files: ['app/**/*.rb'],
179
+ error_message: '+reek detected code smells, commit aborted'
180
+ )
181
+ end
182
+
183
+ it '#rspec' do
184
+ expect(default_scripts.rspec.last.configs)
185
+ .to eq(
186
+ name: 'rspec',
187
+ command: 'bundle exec rspec',
188
+ files: ['app/**/*.rb', 'spec/**/*.rb']
189
+ )
190
+ end
191
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+ require './lib/renuo_bin_check/dsl_config'
3
+
4
+ RSpec.describe DSLConfig do
5
+ it 'gets the right infos out of a new check' do
6
+ dsl_config = DSLConfig.new('rspec') do
7
+ files 'lib/**/*.rb'
8
+ command 'rubocop'
9
+ reversed_exit false
10
+ end
11
+
12
+ expect(dsl_config.configs).to eq(name: 'rspec', files: 'lib/**/*.rb', command: 'rubocop', reversed_exit: false)
13
+ expect(dsl_config.children?).to eq(false)
14
+ end
15
+
16
+ it 'creates new children if there are nested checks' do
17
+ dsl_config = DSLConfig.new('ruby_files') do
18
+ files 'lib/**/*.rb'
19
+ rubocop do
20
+ command 'rubocop'
21
+ reversed_exit false
22
+ end
23
+ error_message 'an error occured'
24
+ p_finder do
25
+ command 'find p'
26
+ reversed_exit true
27
+ end
28
+ end
29
+
30
+ expect(dsl_config.configs).to eq(name: 'ruby_files', files: 'lib/**/*.rb', error_message: 'an error occured')
31
+ expect(dsl_config.children.first.configs).to eq(name: 'rubocop', command: 'rubocop', reversed_exit: false)
32
+ expect(dsl_config.children[1].configs).to eq(name: 'p_finder', command: 'find p', reversed_exit: true)
33
+ expect(dsl_config.children?).to eq(true)
34
+ end
35
+
36
+ it 'method_missing calls super if no block is given' do
37
+ expect { DSLConfig.new('ruby_files') { blubb } }.to raise_error(NameError)
38
+ end
39
+ end
@@ -1,2 +1,3 @@
1
+ #!/bin/zsh
1
2
  sleep 1
2
3
  exit 0
@@ -1,2 +1,3 @@
1
+ #!/bin/zsh
1
2
  sleep 2
2
- exit 0
3
+ exit 0
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: renuo-bin-check
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 1.0.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zora Fuchs
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-06-15 00:00:00.000000000 Z
11
+ date: 2016-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print
@@ -205,8 +205,11 @@ files:
205
205
  - bin/check
206
206
  - bin/setup
207
207
  - lib/renuo-bin-check.rb
208
+ - lib/renuo_bin_check/bin_check.rb
208
209
  - lib/renuo_bin_check/cacher.rb
209
210
  - lib/renuo_bin_check/default_scripts/default_rails.rb
211
+ - lib/renuo_bin_check/default_scripts/default_scripts.rb
212
+ - lib/renuo_bin_check/dsl_config.rb
210
213
  - lib/renuo_bin_check/initializer.rb
211
214
  - lib/renuo_bin_check/master_thread.rb
212
215
  - lib/renuo_bin_check/printer.rb
@@ -220,8 +223,12 @@ files:
220
223
  - spec/factories/cacher.rb
221
224
  - spec/factories/result.rb
222
225
  - spec/factories/script_config.rb
226
+ - spec/integration/bin_check_spec.rb
223
227
  - spec/integration/initializer_spec.rb
228
+ - spec/renuo/bin-check/bin_check_spec.rb
224
229
  - spec/renuo/bin-check/cacher_spec.rb
230
+ - spec/renuo/bin-check/default_scripts/default_scripts_spec.rb
231
+ - spec/renuo/bin-check/dsl_config_spec.rb
225
232
  - spec/renuo/bin-check/initializer_spec.rb
226
233
  - spec/renuo/bin-check/master_thread_spec.rb
227
234
  - spec/renuo/bin-check/printer_spec.rb
@@ -252,9 +259,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
252
259
  version: '0'
253
260
  required_rubygems_version: !ruby/object:Gem::Requirement
254
261
  requirements:
255
- - - ">="
262
+ - - ">"
256
263
  - !ruby/object:Gem::Version
257
- version: '0'
264
+ version: 1.3.1
258
265
  requirements: []
259
266
  rubyforge_project:
260
267
  rubygems_version: 2.5.1
@@ -268,8 +275,12 @@ test_files:
268
275
  - spec/factories/cacher.rb
269
276
  - spec/factories/result.rb
270
277
  - spec/factories/script_config.rb
278
+ - spec/integration/bin_check_spec.rb
271
279
  - spec/integration/initializer_spec.rb
280
+ - spec/renuo/bin-check/bin_check_spec.rb
272
281
  - spec/renuo/bin-check/cacher_spec.rb
282
+ - spec/renuo/bin-check/default_scripts/default_scripts_spec.rb
283
+ - spec/renuo/bin-check/dsl_config_spec.rb
273
284
  - spec/renuo/bin-check/initializer_spec.rb
274
285
  - spec/renuo/bin-check/master_thread_spec.rb
275
286
  - spec/renuo/bin-check/printer_spec.rb
@@ -285,4 +296,3 @@ test_files:
285
296
  - spec/spec-files/test_script_sleep1
286
297
  - spec/spec-files/test_script_sleep2
287
298
  - spec/spec_helper.rb
288
- has_rdoc: