warder 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5722366067d6e558ab7157e80c1694aa6e0e25d9
4
- data.tar.gz: be7feca3cb5590c036cc40fd87999d5c7a830c88
3
+ metadata.gz: 08b7e90e5910c5193dada4ec370cb0bf223bb9cc
4
+ data.tar.gz: 09733b69ddd83cb5581aa008f879fe3d2d091a18
5
5
  SHA512:
6
- metadata.gz: c13f582753760689cd4a6fceb3d01f41b755cd419da0a494aab93ba228eeb830cf604aae71b06743b90daebc0abb1e5fe3c598c7e19196b016902197e6bcb65a
7
- data.tar.gz: 3f92ce99152a65e26302c08eab72387383311370cc980d19a01d610c49240918101f26c7ccbed4544fc4fc93dce809ddb448baf6befd7f0f3b5b15ff06fa9763
6
+ metadata.gz: e602f21426ba7133738b82db52db9d20aeed3cceb2cd68d1ba5a2921be9cec2a0e96a20db2a1e8aaf56b9b7fa70b1307bd24a68cbfa797f2bc08cbe726909bbd
7
+ data.tar.gz: 2cc2b364e1172bf40ff8e031bd1a8f176e4cd78d31bd32761bda300236b3d0f55646ca844867fe4f8176a22268c83c2dc06bb822707242322bd7d7d0c71cbbf7
data/Rakefile CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'bundler/gem_tasks'
2
2
  require 'rspec/core/rake_task'
3
+ require 'cucumber/rake/task'
3
4
 
4
5
  namespace :spec do
5
6
  desc 'Run specs that should pass'
@@ -10,17 +11,43 @@ namespace :spec do
10
11
 
11
12
  desc 'Run specs that are being worked on'
12
13
  RSpec::Core::RakeTask.new(:wip) do |t|
13
- t.rspec_opts = '--tag wip'
14
+ t.rspec_opts = '--color --tag wip'
14
15
  t.pattern = './spec/**/*_spec.rb'
15
16
  end
16
17
 
17
18
  desc 'Run all specs'
18
19
  RSpec::Core::RakeTask.new(:all) do |t|
20
+ t.rspec_opts = '--color'
19
21
  t.pattern = './spec/**/*_spec.rb'
20
22
  end
21
23
  end
22
24
 
25
+ namespace :cucumber do
26
+ desc 'Run features that should pass'
27
+ Cucumber::Rake::Task.new(:ok) do |t|
28
+ t.fork = true # You may get faster startup if you set this to false
29
+ t.profile = 'ok'
30
+ end
31
+
32
+ desc 'Run features that are being worked on'
33
+ Cucumber::Rake::Task.new(:wip) do |t|
34
+ t.fork = true # You may get faster startup if you set this to false
35
+ t.profile = 'wip'
36
+ end
37
+
38
+ desc 'Run all features'
39
+ Cucumber::Rake::Task.new(:all) do |t|
40
+ t.fork = true # You may get faster startup if you set this to false
41
+ t.profile = 'default'
42
+ end
43
+ end
44
+
45
+ desc 'Alias for cucumber:ok'
46
+ task :cucumber => 'cucumber:ok'
47
+
23
48
  desc 'Alias for spec:ok'
24
49
  task :spec => 'spec:ok'
25
50
 
26
- task :default => 'spec'
51
+ task :wip => %w(spec:wip cucumber:wip)
52
+ task :all => %w(spec:all cucumber:all)
53
+ task :default => %w(spec cucumber)
data/bin/warder CHANGED
@@ -1,5 +1,26 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
4
+
5
+ require 'optparse'
3
6
  require 'warder'
4
7
 
5
- Warder::Runner.new.run!
8
+ options = {}
9
+ OptionParser.new do |opts|
10
+ desc = 'Run style guide validation'
11
+ opts.on('-s', '--[no-]style-guide', desc) do |value|
12
+ options[:style_guide] = value
13
+ end
14
+
15
+ desc = 'Run magick numbers validation'
16
+ opts.on('-n', '--[no-]magick-numbers', desc) do |value|
17
+ options[:magick_numbers] = value
18
+ end
19
+
20
+ desc = 'Run code duplication validation'
21
+ opts.on('-d', '--[no-]code-duplications', desc) do |value|
22
+ options[:code_duplications] = value
23
+ end
24
+ end.parse!
25
+
26
+ Warder::CLI.new(options).perform
@@ -0,0 +1,4 @@
1
+ <% std_opts = "--format 'pretty'" %>
2
+ default: <%= std_opts %> --strict features
3
+ ok: <%= std_opts %> --no-color --strict --tags ~@wip features
4
+ wip: <%= std_opts %> --tags @wip:1 --wip features
@@ -0,0 +1,22 @@
1
+ Feature: detects code duplications
2
+ In order to find code duplications
3
+ As a ruby developer
4
+ I want to run warder with --code-duplications option
5
+
6
+ Scenario: run warder with enabled code duplications option
7
+ Given I have valid file in directory
8
+ When I run `warder --code-duplications`
9
+ Then warder detects code duplications
10
+ Then the exit status should be 0
11
+
12
+ Scenario: run warder with enabled code duplications option on invalid file
13
+ Given I have invalid_code_duplications file in directory
14
+ When I run `warder --code-duplications`
15
+ Then warder detects code duplications
16
+ Then the exit status should be 1
17
+
18
+ Scenario: run warder with disabled code duplications option on invalid file
19
+ Given I have invalid_magick_numbers file in directory
20
+ When I run `warder --no-code-duplications`
21
+ Then warder does nothing
22
+ Then the exit status should be 0
@@ -0,0 +1,22 @@
1
+ Feature: detects magick numbers
2
+ In order to find magick numbers
3
+ As a ruby developer
4
+ I want to run warder with --magick-numbers option
5
+
6
+ Scenario: run warder with enabled magick numbers option
7
+ Given I have valid file in directory
8
+ When I run `warder --magick-numbers`
9
+ Then warder detects magick numbers
10
+ Then the exit status should be 0
11
+
12
+ Scenario: run warder with enabled magick numbers option on invalid file
13
+ Given I have invalid_magick_numbers file in directory
14
+ When I run `warder --magick-numbers`
15
+ Then warder detects magick numbers
16
+ Then the exit status should be 1
17
+
18
+ Scenario: run warder with disabled style guide option on invalid file
19
+ Given I have invalid_magick_numbers file in directory
20
+ When I run `warder --no-magick-numbers`
21
+ Then warder does nothing
22
+ Then the exit status should be 0
@@ -0,0 +1,9 @@
1
+ Feature: run warder
2
+ In order to check project codebase
3
+ I want to run warder
4
+
5
+ Scenario: run warder with no options
6
+ Given I have valid file in directory
7
+ When I run `warder`
8
+ Then warder does nothing
9
+ And the exit status should be 0
@@ -0,0 +1,8 @@
1
+ Then(/^warder detects code duplications$/) do
2
+ executing_flay_output = "executing 'flay -d -m 15 .'"
3
+ success_flay_output = `flay -d spec/fixtures/#{@filename}`
4
+ step "the output should contain \"#{executing_flay_output}\""
5
+ success_flay_output.split("\n").each do |string|
6
+ step "the output should contain \"#{string.sub('spec/fixtures/', './')}\""
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ Then(/^warder detects magick numbers$/) do
2
+ executing_mago_output = "executing 'mago'"
3
+ success_mago_output = `mago spec/fixtures/#{@filename}`
4
+ step "the output should contain \"#{executing_mago_output}\""
5
+ success_mago_output.split("\n").each do |string|
6
+ step "the output should contain \"#{string.sub('spec/fixtures/', './')}\""
7
+ end
8
+ end
@@ -0,0 +1,17 @@
1
+ Before do
2
+ FileUtils.mkdir_p 'tmp/aruba'
3
+ end
4
+
5
+ After do
6
+ FileUtils.rm_rf 'tmp/aruba'
7
+ end
8
+
9
+ Given(/^I have (\w+) file in directory$/) do |name|
10
+ @filename = "#{name}.rb"
11
+ FileUtils.ln_s "../../spec/fixtures/#{@filename}", 'tmp/aruba/'
12
+ expect(`ls tmp/aruba`).to match(@filename)
13
+ end
14
+
15
+ Then(/^warder does nothing$/) do
16
+ step 'the output should match /.{0}/'
17
+ end
@@ -0,0 +1,6 @@
1
+ Then(/^warder validates style guide$/) do
2
+ executing_rubocop_output = "executing 'rubocop'"
3
+ success_rubocop_output = `rubocop spec/fixtures/#{@filename} | grep offence`
4
+ step "the output should contain \"#{executing_rubocop_output}\""
5
+ step "the output should contain \"#{success_rubocop_output}\""
6
+ end
@@ -0,0 +1,4 @@
1
+ require 'aruba/cucumber'
2
+
3
+ bin_path = "#{File.expand_path('../../../bin', __FILE__)}"
4
+ ENV['PATH'] = "#{ENV['PATH']}#{File::PATH_SEPARATOR}#{bin_path}"
@@ -0,0 +1,22 @@
1
+ Feature: check style guide
2
+ In order to check style guide
3
+ As a ruby developer
4
+ I want to run warder with --style-guide option
5
+
6
+ Scenario: run warder with enabled style guide option
7
+ Given I have valid file in directory
8
+ When I run `warder --style-guide`
9
+ Then warder validates style guide
10
+ Then the exit status should be 0
11
+
12
+ Scenario: run warder with enabled style guide option on invalid file
13
+ Given I have invalid_style_guide file in directory
14
+ When I run `warder --style-guide`
15
+ Then warder validates style guide
16
+ Then the exit status should be 1
17
+
18
+ Scenario: run warder with disabled style guide option on invalid file
19
+ Given I have invalid_style_guide file in directory
20
+ When I run `warder --no-style-guide`
21
+ Then warder does nothing
22
+ Then the exit status should be 0
@@ -1,2 +1,6 @@
1
1
  require 'warder/version'
2
2
  require 'warder/runner'
3
+ require 'warder/style_guide_runner'
4
+ require 'warder/magick_numbers_runner'
5
+ require 'warder/code_duplication_runner'
6
+ require 'warder/cli'
@@ -0,0 +1,42 @@
1
+ module Warder
2
+ # responsible for executing warder tools
3
+ class CLI
4
+ def initialize(options)
5
+ @options = options
6
+ end
7
+
8
+ def perform
9
+ exit perform_style_guide_validation + perform_magick_numbers_validation +
10
+ perform_code_duplication_validation
11
+ end
12
+
13
+ private
14
+
15
+ def perform_style_guide_validation
16
+ if @options[:style_guide]
17
+ runner = StyleGuideRunner.new(@options)
18
+ runner.perform
19
+ else
20
+ 0
21
+ end
22
+ end
23
+
24
+ def perform_magick_numbers_validation
25
+ if @options[:magick_numbers]
26
+ runner = MagickNumbersRunner.new(@options)
27
+ runner.perform
28
+ else
29
+ 0
30
+ end
31
+ end
32
+
33
+ def perform_code_duplication_validation
34
+ if @options[:code_duplications]
35
+ runner = CodeDuplicationRunner.new(@options)
36
+ runner.perform
37
+ else
38
+ 0
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,22 @@
1
+ module Warder
2
+ # responsible for run magick numbers validation
3
+ class CodeDuplicationRunner < Runner
4
+ FLAY_SCORE = SCORE / 2
5
+
6
+ def initialize(options = {})
7
+ @options = options
8
+ end
9
+
10
+ private
11
+
12
+ def command
13
+ "flay -d -m #{FLAY_SCORE} ."
14
+ end
15
+
16
+ def failed?(line)
17
+ match = line.match(/Total score \(lower is better\) = (\d+)/)
18
+
19
+ match && match[1].to_i != 0
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,18 @@
1
+ module Warder
2
+ # responsible for run magick numbers validation
3
+ class MagickNumbersRunner < Runner
4
+ def initialize(options = {})
5
+ @options = options
6
+ end
7
+
8
+ private
9
+
10
+ def command
11
+ 'mago'
12
+ end
13
+
14
+ def failed?(line)
15
+ true
16
+ end
17
+ end
18
+ end
@@ -1,24 +1,23 @@
1
1
  module Warder
2
- # responsible for running tools
2
+ # abstract class for command runners
3
3
  class Runner
4
- def run!
5
- exit rubocop.to_i + mago.to_i
6
- end
7
-
8
- private
9
-
10
- def rubocop
11
- system('rubocop')
12
- $CHILD_STATUS
13
- end
4
+ SCORE = 30
14
5
 
15
- def mago
6
+ def perform
7
+ puts "executing '#{command}'\n"
16
8
  code = 0
17
- IO.popen('mago').each do |line|
9
+ IO.popen(command).each do |line|
18
10
  print line
19
- code = 1
11
+
12
+ code = 1 if failed?(line)
20
13
  end
21
14
  code
22
15
  end
16
+
17
+ private
18
+
19
+ def failed?(line)
20
+ false
21
+ end
23
22
  end
24
23
  end
@@ -0,0 +1,20 @@
1
+ module Warder
2
+ # responsible for run style guide validation
3
+ class StyleGuideRunner < Runner
4
+ def initialize(options = {})
5
+ @options = options
6
+ end
7
+
8
+ private
9
+
10
+ def command
11
+ 'rubocop'
12
+ end
13
+
14
+ def failed?(line)
15
+ match = line.match(/(\d+|no) offence/)
16
+
17
+ match && match[1].to_i != 0
18
+ end
19
+ end
20
+ end
@@ -1,4 +1,4 @@
1
1
  # define warder version
2
2
  module Warder
3
- VERSION = '0.0.3'
3
+ VERSION = '0.0.4'
4
4
  end
@@ -0,0 +1,18 @@
1
+ # This configuration was generated by `rubocop --auto-gen-config`.
2
+ # The point is for the user to remove these configuration records
3
+ # one by one as the offences are removed from the code base.
4
+
5
+ AssignmentInCondition:
6
+ Enabled: false
7
+
8
+ Documentation:
9
+ Enabled: false
10
+
11
+ EmptyLinesAroundBody:
12
+ Enabled: false
13
+
14
+ IfUnlessModifier:
15
+ Enabled: false
16
+
17
+ UselessAssignment:
18
+ Enabled: false
@@ -0,0 +1,40 @@
1
+ ##
2
+ # I am a dog.
3
+
4
+ class Dog
5
+ def x
6
+ return 1
7
+ end
8
+
9
+ def w
10
+ return 2 + q
11
+ end
12
+
13
+ private
14
+
15
+ def q
16
+ return 3
17
+ end
18
+ end
19
+
20
+ ##
21
+ # I
22
+ # am
23
+ # a
24
+ # cat.
25
+
26
+ class Cat
27
+ def y
28
+ return 1
29
+ end
30
+
31
+ def z
32
+ return 2 + s
33
+ end
34
+
35
+ private
36
+
37
+ def s
38
+ return 3
39
+ end
40
+ end
@@ -0,0 +1 @@
1
+ 1 + 1 / 2
@@ -0,0 +1,3 @@
1
+ module InvalidStyleGuide
2
+
3
+ end
@@ -0,0 +1,3 @@
1
+ if match = ''.match(/(\d+|no) offence/)
2
+ exit(1)
3
+ end
@@ -0,0 +1 @@
1
+ puts 'Hello world!'
@@ -15,16 +15,19 @@ Gem::Specification.new do |spec|
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(spec|features)/})
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features|cucumber)/})
19
19
  spec.require_paths = ['lib']
20
20
 
21
21
  spec.add_dependency 'rubocop'
22
22
  # spec.add_dependency 'reek'
23
- # spec.add_dependency 'flay'
23
+ spec.add_dependency 'flay'
24
+ spec.add_dependency 'ruby2ruby'
24
25
  # spec.add_dependency 'flog'
25
26
  spec.add_dependency 'mago'
26
27
 
27
28
  spec.add_development_dependency 'bundler', '~> 1.3'
28
29
  spec.add_development_dependency 'rake'
29
30
  spec.add_development_dependency 'rspec', '3.0.0.beta1'
31
+ spec.add_development_dependency 'cucumber'
32
+ spec.add_development_dependency 'aruba'
30
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: warder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yura Tolstik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-22 00:00:00.000000000 Z
11
+ date: 2013-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -24,6 +24,34 @@ dependencies:
24
24
  - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: flay
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: ruby2ruby
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: mago
29
57
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +108,34 @@ dependencies:
80
108
  - - '='
81
109
  - !ruby/object:Gem::Version
82
110
  version: 3.0.0.beta1
111
+ - !ruby/object:Gem::Dependency
112
+ name: cucumber
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: aruba
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
83
139
  description: Warder of ruby code
84
140
  email:
85
141
  - yltsrc@gmail.com
@@ -94,9 +150,29 @@ files:
94
150
  - README.md
95
151
  - Rakefile
96
152
  - bin/warder
153
+ - cucumber.yml
154
+ - features/detects_code_duplications.feature
155
+ - features/detects_magick_numbers.feature
156
+ - features/run.feature
157
+ - features/step_definitions/detects_code_duplications_steps.rb
158
+ - features/step_definitions/detects_magick_numbers_steps.rb
159
+ - features/step_definitions/run_steps.rb
160
+ - features/step_definitions/validates_style_guide_steps.rb
161
+ - features/support/env.rb
162
+ - features/validates_style_guide.feature
97
163
  - lib/warder.rb
164
+ - lib/warder/cli.rb
165
+ - lib/warder/code_duplication_runner.rb
166
+ - lib/warder/magick_numbers_runner.rb
98
167
  - lib/warder/runner.rb
168
+ - lib/warder/style_guide_runner.rb
99
169
  - lib/warder/version.rb
170
+ - rubocop-todo.yml
171
+ - spec/fixtures/invalid_code_duplications.rb
172
+ - spec/fixtures/invalid_magick_numbers.rb
173
+ - spec/fixtures/invalid_style_guide.rb
174
+ - spec/fixtures/strictly_invalid_style_guide.rb
175
+ - spec/fixtures/valid.rb
100
176
  - spec/spec_helper.rb
101
177
  - warder.gemspec
102
178
  homepage: https://github.com/yltsrc/warder
@@ -119,9 +195,23 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
195
  version: '0'
120
196
  requirements: []
121
197
  rubyforge_project:
122
- rubygems_version: 2.1.11
198
+ rubygems_version: 2.0.14
123
199
  signing_key:
124
200
  specification_version: 4
125
201
  summary: Warder of ruby code
126
202
  test_files:
203
+ - features/detects_code_duplications.feature
204
+ - features/detects_magick_numbers.feature
205
+ - features/run.feature
206
+ - features/step_definitions/detects_code_duplications_steps.rb
207
+ - features/step_definitions/detects_magick_numbers_steps.rb
208
+ - features/step_definitions/run_steps.rb
209
+ - features/step_definitions/validates_style_guide_steps.rb
210
+ - features/support/env.rb
211
+ - features/validates_style_guide.feature
212
+ - spec/fixtures/invalid_code_duplications.rb
213
+ - spec/fixtures/invalid_magick_numbers.rb
214
+ - spec/fixtures/invalid_style_guide.rb
215
+ - spec/fixtures/strictly_invalid_style_guide.rb
216
+ - spec/fixtures/valid.rb
127
217
  - spec/spec_helper.rb