devtools 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +37 -0
  3. data/.rspec +5 -0
  4. data/.rubocop.yml +5 -0
  5. data/.ruby-gemset +1 -0
  6. data/.travis.yml +15 -0
  7. data/Gemfile +5 -0
  8. data/LICENSE +20 -0
  9. data/README.md +47 -0
  10. data/Rakefile +5 -0
  11. data/TODO +0 -0
  12. data/bin/devtools +18 -0
  13. data/circle.yml +7 -0
  14. data/config/flay.yml +3 -0
  15. data/config/flog.yml +2 -0
  16. data/config/mutant.yml +2 -0
  17. data/config/reek.yml +107 -0
  18. data/config/rubocop.yml +117 -0
  19. data/config/yardstick.yml +2 -0
  20. data/default/config/devtools.yml +2 -0
  21. data/default/config/flay.yml +3 -0
  22. data/default/config/flog.yml +2 -0
  23. data/default/config/mutant.yml +3 -0
  24. data/default/config/reek.yml +103 -0
  25. data/default/config/rubocop.yml +91 -0
  26. data/default/config/yardstick.yml +2 -0
  27. data/devtools.gemspec +33 -0
  28. data/lib/devtools.rb +143 -0
  29. data/lib/devtools/config.rb +158 -0
  30. data/lib/devtools/platform.rb +118 -0
  31. data/lib/devtools/project.rb +157 -0
  32. data/lib/devtools/project/initializer.rb +21 -0
  33. data/lib/devtools/project/initializer/rake.rb +19 -0
  34. data/lib/devtools/project/initializer/rspec.rb +105 -0
  35. data/lib/devtools/site.rb +41 -0
  36. data/lib/devtools/site/initializer.rb +57 -0
  37. data/lib/devtools/spec_helper.rb +5 -0
  38. data/shared/spec/shared/abstract_type_behavior.rb +18 -0
  39. data/shared/spec/shared/command_method_behavior.rb +7 -0
  40. data/shared/spec/shared/each_method_behaviour.rb +15 -0
  41. data/shared/spec/shared/hash_method_behavior.rb +9 -0
  42. data/shared/spec/shared/idempotent_method_behavior.rb +12 -0
  43. data/shared/spec/support/ice_nine_config.rb +14 -0
  44. data/spec/spec_helper.rb +31 -0
  45. data/tasks/metrics/ci.rake +18 -0
  46. data/tasks/metrics/coverage.rake +13 -0
  47. data/tasks/metrics/flay.rake +48 -0
  48. data/tasks/metrics/flog.rake +40 -0
  49. data/tasks/metrics/mutant.rake +50 -0
  50. data/tasks/metrics/reek.rake +7 -0
  51. data/tasks/metrics/rubocop.rake +15 -0
  52. data/tasks/metrics/yardstick.rake +26 -0
  53. data/tasks/spec.rake +36 -0
  54. data/tasks/yard.rake +11 -0
  55. metadata +284 -0
@@ -0,0 +1,118 @@
1
+ # encoding: utf-8
2
+
3
+ module Devtools
4
+
5
+ # Provides methods to determine the ruby platform
6
+ module Platform
7
+
8
+ DEFAULT_RVM_NAME = 'mri'.freeze
9
+
10
+ # Return Ruby engine string
11
+ #
12
+ # @return [String]
13
+ #
14
+ # @api private
15
+ def ruby_engine
16
+ @ruby_engine ||= (defined?(RUBY_ENGINE) && RUBY_ENGINE || 'ruby').freeze
17
+ end
18
+
19
+ # Return RVM name
20
+ #
21
+ # @return [String]
22
+ #
23
+ # @api private
24
+ def rvm_name
25
+ @rvm_name ||= begin
26
+ engine = ruby_engine
27
+ engine == 'ruby' ? DEFAULT_RVM_NAME : engine
28
+ end
29
+ end
30
+
31
+ # Return RVM string
32
+ #
33
+ # @return [String]
34
+ #
35
+ # @api private
36
+ def rvm
37
+ @rvm ||= "#{rvm_name}-#{RUBY_VERSION}".freeze
38
+ end
39
+
40
+ # Test for being executed under JRuby
41
+ #
42
+ # @return [true]
43
+ # if running under JRuby
44
+ #
45
+ # @return [false]
46
+ # otherwise
47
+ #
48
+ # @api private
49
+ def jruby?
50
+ ruby_engine == 'jruby'
51
+ end
52
+
53
+ # Test for being executed under rbx
54
+ #
55
+ # @return [true]
56
+ # if running under rbx
57
+ #
58
+ # @return [false]
59
+ # otherwise
60
+ #
61
+ # @api private
62
+ def rbx?
63
+ ruby_engine == 'rbx'
64
+ end
65
+
66
+ # Test for being executed under rubies with a JIT
67
+ #
68
+ # @return [true]
69
+ # if running under JRuby or rbx
70
+ #
71
+ # @return [false]
72
+ # otherwise
73
+ #
74
+ # @api private
75
+ def jit?
76
+ jruby? || rbx?
77
+ end
78
+
79
+ # Test for 1.8 mode
80
+ #
81
+ # @return [true]
82
+ # if running under 1.8.x
83
+ #
84
+ # @return [false]
85
+ # otherwise
86
+ #
87
+ # @api private
88
+ def ruby18?
89
+ RUBY_VERSION.start_with?('1.8.')
90
+ end
91
+
92
+ # Test for 1.9 mode
93
+ #
94
+ # @return [true]
95
+ # if running under 1.9.x
96
+ #
97
+ # @return [false]
98
+ # otherwise
99
+ #
100
+ # @api private
101
+ def ruby19?
102
+ RUBY_VERSION.start_with?('1.9.')
103
+ end
104
+
105
+ # Test for 2.0 mode
106
+ #
107
+ # @return [true]
108
+ # if running under 2.0.x
109
+ #
110
+ # @return [false]
111
+ # otherwise
112
+ #
113
+ # @api private
114
+ def ruby20?
115
+ RUBY_VERSION.start_with?('2.0.')
116
+ end
117
+ end # module Platform
118
+ end # module Devtools
@@ -0,0 +1,157 @@
1
+ # encoding: utf-8
2
+
3
+ module Devtools
4
+
5
+ # The project devtools supports
6
+ class Project
7
+
8
+ # The reek configuration
9
+ #
10
+ # @return [Config::Reek]
11
+ #
12
+ # @api private
13
+ attr_reader :reek
14
+
15
+ # The rubocop configuration
16
+ #
17
+ # @return [Config::Rubocop]
18
+ #
19
+ # @api private
20
+ attr_reader :rubocop
21
+
22
+ # The flog configuration
23
+ #
24
+ # @return [Config::Flog]
25
+ #
26
+ # @api private
27
+ attr_reader :flog
28
+
29
+ # The yardstick configuration
30
+ #
31
+ # @return [Config::Yardstick]
32
+ #
33
+ # @api private
34
+ attr_reader :yardstick
35
+
36
+ # The flay configuration
37
+ #
38
+ # @return [Config::Flay]
39
+ #
40
+ # @api private
41
+ attr_reader :flay
42
+
43
+ # The mutant configuration
44
+ #
45
+ # @return [Config::Mutant]
46
+ #
47
+ # @api private
48
+ attr_reader :mutant
49
+
50
+ # The devtools configuration
51
+ #
52
+ # @return [Config::Devtools]
53
+ #
54
+ # @api private
55
+ attr_reader :devtools
56
+
57
+ # Return project root
58
+ #
59
+ # @return [Pathname]
60
+ #
61
+ # @api private
62
+ #
63
+ attr_reader :root
64
+
65
+ # The default config path
66
+ #
67
+ # @return [Pathname]
68
+ #
69
+ # @api private
70
+ attr_reader :default_config_path
71
+
72
+ # The lib directory
73
+ #
74
+ # @return [Pathname]
75
+ #
76
+ # @api private
77
+ attr_reader :lib_dir
78
+
79
+ # The Ruby file pattern
80
+ #
81
+ # @return [Pathname]
82
+ #
83
+ # @api private
84
+ attr_reader :file_pattern
85
+
86
+ # The spec root
87
+ #
88
+ # @return [Pathname]
89
+ #
90
+ # @api private
91
+ attr_reader :spec_root
92
+
93
+ # Return config directory
94
+ #
95
+ # @return [Pathname]
96
+ #
97
+ # @api private
98
+ attr_reader :config_dir
99
+
100
+ # The unit test timeout
101
+ #
102
+ # @return [Numeric]
103
+ #
104
+ # @api private
105
+ attr_reader :unit_test_timeout
106
+
107
+ # Initialize object
108
+ #
109
+ # @param [Pathname] root
110
+ #
111
+ # @return [undefined]
112
+ #
113
+ # @api private
114
+ #
115
+ def initialize(root)
116
+ @root = root
117
+
118
+ initialize_environment
119
+ initialize_configs
120
+
121
+ @unit_test_timeout = @devtools.unit_test_timeout
122
+ end
123
+
124
+ private
125
+
126
+ # Initialize environment
127
+ #
128
+ # @return [undefined]
129
+ #
130
+ # @api private
131
+ #
132
+ def initialize_environment
133
+ @default_config_path = @root.join(DEFAULT_CONFIG_DIR_NAME).freeze
134
+ @lib_dir = @root.join(LIB_DIRECTORY_NAME).freeze
135
+ @spec_root = @root.join(SPEC_DIRECTORY_NAME).freeze
136
+ @file_pattern = @lib_dir.join(RB_FILE_PATTERN).freeze
137
+ @config_dir = @default_config_path
138
+ end
139
+
140
+ # Initialize configs
141
+ #
142
+ # @return [undefined]
143
+ #
144
+ # @api private
145
+ #
146
+ def initialize_configs
147
+ @reek = Config::Reek.new(self)
148
+ @rubocop = Config::Rubocop.new(self)
149
+ @flog = Config::Flog.new(self)
150
+ @yardstick = Config::Yardstick.new(self)
151
+ @flay = Config::Flay.new(self)
152
+ @mutant = Config::Mutant.new(self)
153
+ @devtools = Config::Devtools.new(self)
154
+ end
155
+
156
+ end # class Project
157
+ end # module Devtools
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+
3
+ module Devtools
4
+ class Project
5
+
6
+ # Base class for project initializers
7
+ class Initializer
8
+
9
+ attr_reader :project
10
+ protected :project
11
+
12
+ def initialize(project)
13
+ @project = project
14
+ end
15
+
16
+ def call
17
+ fail NotImplementedError, "#{self.class}##{__method__} must be implemented"
18
+ end
19
+ end # class Initializer
20
+ end # class Project
21
+ end # module Devtools
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+
3
+ module Devtools
4
+ class Project
5
+ class Initializer
6
+
7
+ # Imports all devtools rake tasks into a project
8
+ class Rake
9
+
10
+ extend ::Rake::DSL
11
+
12
+ def self.call
13
+ FileList[RAKE_FILES_GLOB].each(&method(:import))
14
+ end
15
+
16
+ end # class Rake
17
+ end # class Initializer
18
+ end # class Project
19
+ end # module Devtools
@@ -0,0 +1,105 @@
1
+ # encoding: utf-8
2
+
3
+ module Devtools
4
+ class Project
5
+ class Initializer
6
+
7
+ # Requires all shared specs in a project's spec_helper
8
+ # Also installs a configurable unit test timeout
9
+ class Rspec < self
10
+
11
+ def self.require_files(directory)
12
+ Devtools.require_files(directory, SHARED_SPEC_PATTERN)
13
+ end
14
+
15
+ # Initialize RSpec for +project+
16
+ #
17
+ # @param [Project] project
18
+ # the project to initialize
19
+ #
20
+ # @return [Rspec]
21
+ #
22
+ # @api private
23
+ def self.call(project)
24
+ new(project).call
25
+ end
26
+
27
+ # The spec root
28
+ #
29
+ # @return [Pathname]
30
+ #
31
+ # @api private
32
+ attr_reader :spec_root
33
+ private :spec_root
34
+
35
+ # The unit test timeout
36
+ #
37
+ # @return [Numeric]
38
+ #
39
+ # @api private
40
+ attr_reader :unit_test_timeout
41
+ private :unit_test_timeout
42
+
43
+ # Initialize a new instance
44
+ #
45
+ # @param [Project] project
46
+ # the project to initialize
47
+ #
48
+ # @param [Numeric] unit_test_timeout
49
+ # the maximum time a single unit test can take
50
+ #
51
+ # @return [undefined]
52
+ #
53
+ # @api private
54
+ def initialize(project)
55
+ super
56
+ @spec_root = project.spec_root
57
+ @unit_test_timeout = project.unit_test_timeout
58
+ end
59
+
60
+ # Setup RSpec for {#project}
61
+ #
62
+ # @return [self]
63
+ #
64
+ # @api private
65
+ def call
66
+ require 'rspec'
67
+ require 'rspec/its'
68
+ require_shared_spec_files
69
+ enable_unit_test_timeout unless Devtools.jit?
70
+ self
71
+ end
72
+
73
+ private
74
+
75
+ # Timeout unit tests that take longer than 1/10th of a second
76
+ #
77
+ # @param [Numeric] timeout
78
+ #
79
+ # @return [undefined]
80
+ #
81
+ # @raise [Timeout::Error]
82
+ # raised when the times are outside the timeout
83
+ #
84
+ # @api private
85
+ #
86
+ def enable_unit_test_timeout
87
+ timeout = unit_test_timeout # support the closure
88
+ RSpec.configuration.around file_path: UNIT_TEST_PATH_REGEXP do |example|
89
+ Timeout.timeout(timeout, &example)
90
+ end
91
+ end
92
+
93
+ def require_shared_spec_files
94
+ require_files(SHARED_SPEC_PATH)
95
+ require_files(spec_root)
96
+ end
97
+
98
+ def require_files(directory)
99
+ self.class.require_files(directory)
100
+ end
101
+
102
+ end # class Rspec
103
+ end # class Initializer
104
+ end # class Project
105
+ end # module Devtools
@@ -0,0 +1,41 @@
1
+ # encoding: utf-8
2
+
3
+ module Devtools
4
+
5
+ # Encapsulates a specific {Project} devtools is used for
6
+ class Site
7
+
8
+ attr_reader :root
9
+
10
+ attr_reader :project
11
+
12
+ def initialize(project)
13
+ @project = project
14
+ @root = project.root
15
+ end
16
+
17
+ # Initialize project and load shared specs
18
+ #
19
+ # Expects to be called from $application_root/spec/spec_helper.rb
20
+ #
21
+ # @return [self]
22
+ #
23
+ # @api private
24
+ def init_spec_helper
25
+ Project::Initializer::Rspec.call(project)
26
+ self
27
+ end
28
+
29
+ # Initialize devtools using default config
30
+ #
31
+ # @return [undefined]
32
+ #
33
+ # @api private
34
+ def init
35
+ Initializer.call(self)
36
+ puts 'Run bundle install to complete the devtools installation'
37
+ self
38
+ end
39
+
40
+ end # class Site
41
+ end # module Devtools