Skip to content

Commit

Permalink
Refactor project boilerplate
Browse files Browse the repository at this point in the history
* Use rspec2 instead of test unit
  to_source will be mutated with mutant soon. As mutant does only have
  an rspec2 compatible runner.
* Introuce metrics
* Bring code to 100% yard coverage
* Add multiple assignment support
  • Loading branch information
Markus Schirp committed Aug 19, 2012
1 parent 799c740 commit 388e4a3
Show file tree
Hide file tree
Showing 26 changed files with 1,763 additions and 541 deletions.
1 change: 1 addition & 0 deletions .rspec
@@ -0,0 +1 @@
--color
37 changes: 34 additions & 3 deletions Gemfile
@@ -1,5 +1,36 @@
source "http://rubygems.org"
source 'https://rubygems.org'

# Specify your gem's dependencies in to_source.gemspec
gemspec
gem 'rake'

gem 'immutable', :git => 'https://github.com/dkubb/immutable.git', :ref => '4a4b7ddd138a32944fa0ddaff8412490cf9dd875'
gem 'abstract', :git => 'https://github.com/mbj/abstract.git'

# Remove git version once original to_source is updated
#gem 'to_source', :git => 'https://github.com/mbj/to_source'
#gem 'to_source', :git => 'https://github.com/mbj/to_source.git'
gem 'to_source', :path => '../to_source'

group :development do
gem 'rake', '~> 0.9.2'
gem 'yard', '~> 0.8.1'
gem 'rspec', '~> 2'
# Remove this once https://github.com/nex3/rb-inotify/pull/20 is solved.
# This patch makes rb-inotify a nice player with listen so it does not poll.
gem 'rb-inotify', :git => 'https://github.com/mbj/rb-inotify'
end

group :guard do
gem 'guard', '~> 1.3.1'
gem 'guard-bundler', '~> 1.0.0'
gem 'guard-rspec', '~> 1.2.0'
end

group :metrics do
gem 'flay', '~> 1.4.2'
gem 'flog', '~> 2.5.1'
gem 'reek', '~> 1.2.8', :git => 'https://github.com/dkubb/reek.git'
gem 'roodi', '~> 2.1.0'
gem 'yardstick', '~> 0.5.0'
gem 'yard-spellcheck', '~> 0.1.5'
gem 'pelusa', '~> 0.2.1'
end
18 changes: 18 additions & 0 deletions Guardfile
@@ -0,0 +1,18 @@
# encoding: utf-8

guard :bundler do
watch('Gemfile')
end

guard :rspec, :version => 2 do
# run all specs if the spec_helper or supporting files files are modified
watch('spec/spec_helper.rb') { 'spec' }
watch(%r{\Aspec/(?:lib|support|shared)/.+\.rb\z}) { 'spec' }

# run unit specs if associated lib code is modified
watch(%r{\Alib/(.+)\.rb\z}) { |m| Dir["spec/unit/#{m[1]}"] }
watch("lib/#{File.basename(File.expand_path('../', __FILE__))}.rb") { 'spec' }

# run a spec if it is modified
watch(%r{\Aspec/(?:unit|integration)/.+_spec\.rb\z})
end
12 changes: 4 additions & 8 deletions Rakefile
@@ -1,10 +1,6 @@
require "bundler/gem_tasks"
require 'rake'

require 'rake/testtask'
Rake::TestTask.new do |t|
t.libs << "test"
t.test_files = FileList['test/**/*_test.rb']
t.verbose = true
end
FileList['tasks/**/*.rake'].each { |task| import task }

task :default => :test
desc 'Default: run all specs'
task :default => :spec
3 changes: 3 additions & 0 deletions TODO
@@ -0,0 +1,3 @@
* Fix parsing errors from ruby parser
It breaks on def $keyword.
* Do a metric driven refactor once flay flog and friends work.
3 changes: 3 additions & 0 deletions config/flay.yml
@@ -0,0 +1,3 @@
---
threshold: 18
total_score: 296
2 changes: 2 additions & 0 deletions config/flog.yml
@@ -0,0 +1,2 @@
---
threshold: 14.4
26 changes: 26 additions & 0 deletions config/roodi.yml
@@ -0,0 +1,26 @@
---
AbcMetricMethodCheck:
score: 12.2
AssignmentInConditionalCheck: {}
CaseMissingElseCheck: {}
ClassLineCountCheck:
line_count: 324
ClassNameCheck:
pattern: !ruby/regexp /\A(?:[A-Z]+|[A-Z][a-z](?:[A-Z]?[a-z])+)\z/
ClassVariableCheck: {}
CyclomaticComplexityBlockCheck:
complexity: 2
CyclomaticComplexityMethodCheck:
complexity: 4
EmptyRescueBodyCheck: {}
ForLoopCheck: {}
MethodLineCountCheck:
line_count: 9
MethodNameCheck:
pattern: !ruby/regexp /\A(?:[a-z\d](?:_?[a-z\d])+[?!=]?|\[\]=?|==|<=>|<<|[+*&|-])\z/
ModuleLineCountCheck:
line_count: 327
ModuleNameCheck:
pattern: !ruby/regexp /\A(?:[A-Z]+|[A-Z][a-z](?:[A-Z]?[a-z])+)\z/
ParameterNumberCheck:
parameter_count: 3
93 changes: 93 additions & 0 deletions config/site.reek
@@ -0,0 +1,93 @@
---
UncommunicativeParameterName:
accept: []
exclude: []
enabled: true
reject:
- !ruby/regexp /^.$/
- !ruby/regexp /[0-9]$/
- !ruby/regexp /[A-Z]/
LargeClass:
max_methods: 10
exclude:
- "Mutant::Matcher::Method" # 13 methods
enabled: true
max_instance_variables: 3
UncommunicativeMethodName:
accept: []
exclude: []
enabled: true
reject:
- !ruby/regexp /^[a-z]$/
- !ruby/regexp /[0-9]$/
- !ruby/regexp /[A-Z]/
LongParameterList:
max_params: 2
exclude:
- "Mutant::Context::Constant#initialize" # 3 params
enabled: true
overrides: {}
FeatureEnvy:
exclude: []
enabled: true
ClassVariable:
exclude: []
enabled: true
BooleanParameter:
exclude: []
enabled: true
IrresponsibleModule:
exclude: []
enabled: true
UncommunicativeModuleName:
accept: []
exclude: []
enabled: true
reject:
- !ruby/regexp /^.$/
- !ruby/regexp /[0-9]$/
NestedIterators:
ignore_iterators: []
exclude: []
enabled: true
max_allowed_nesting: 1
LongMethod:
max_statements: 6
exclude: []
enabled: true
Duplication:
allow_calls: []
exclude: []
enabled: true
max_calls: 1
UtilityFunction:
max_helper_calls: 0
exclude: []
enabled: true
Attribute:
exclude: []
enabled: false
UncommunicativeVariableName:
accept: []
exclude: []
enabled: true
reject:
- !ruby/regexp /^.$/
- !ruby/regexp /[0-9]$/
- !ruby/regexp /[A-Z]/
SimulatedPolymorphism:
exclude: []
enabled: true
max_ifs: 1
DataClump:
exclude: []
enabled: true
max_copies: 2
min_clump_size: 2
ControlCouple:
exclude: []
enabled: true
LongYieldList:
max_params: 1
exclude: []
enabled: true
2 changes: 2 additions & 0 deletions config/yardstick.yml
@@ -0,0 +1,2 @@
---
threshold: 100
20 changes: 12 additions & 8 deletions lib/to_source.rb
@@ -1,13 +1,17 @@
require "to_source/version"
require "to_source/visitor"
require 'to_source/version'
require 'to_source/visitor'

# Namespace of library
module ToSource
# Public: Converts the node back to its original source code.
# Convert node to string
#
# Returns the String output.
def to_source
Visitor.run(self)
# @param [Rubinius::AST::Node] node
#
# @return [String]
#
# @api private
#
def self.to_source(node)
Visitor.run(node)
end
end

Rubinius::AST::Node.send :include, ToSource
2 changes: 1 addition & 1 deletion lib/to_source/version.rb
@@ -1,3 +1,3 @@
module ToSource
VERSION = "0.1.3"
VERSION = '0.1.3'
end

0 comments on commit 388e4a3

Please sign in to comment.