hexx-suit 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +7 -0
  2. data/.rubocop.yml +71 -0
  3. data/.yardopts +3 -0
  4. data/Guardfile +29 -0
  5. data/LICENSE +21 -0
  6. data/README.md +164 -0
  7. data/Rakefile +18 -0
  8. data/bin/hexx-suit +14 -0
  9. data/config/initializers/focus.rb +5 -0
  10. data/config/initializers/garbage_collection.rb +11 -0
  11. data/config/initializers/i18n.rb +3 -0
  12. data/config/initializers/metric_fu.rb +0 -0
  13. data/config/initializers/random_order.rb +4 -0
  14. data/config/initializers/rspec.rb +11 -0
  15. data/lib/hexx-suit.rb +16 -0
  16. data/lib/hexx/suit.rb +101 -0
  17. data/lib/hexx/suit/install.rb +85 -0
  18. data/lib/hexx/suit/install/Guardfile +6 -0
  19. data/lib/hexx/suit/install/Rakefile +17 -0
  20. data/lib/hexx/suit/install/_metrics +5 -0
  21. data/lib/hexx/suit/install/_rspec +2 -0
  22. data/lib/hexx/suit/install/_rubocop.yml +74 -0
  23. data/lib/hexx/suit/install/_yardopts +2 -0
  24. data/lib/hexx/suit/install/metrics/STYLEGUIDE +230 -0
  25. data/lib/hexx/suit/install/metrics/cane.yml +5 -0
  26. data/lib/hexx/suit/install/metrics/churn.yml +6 -0
  27. data/lib/hexx/suit/install/metrics/flay.yml +2 -0
  28. data/lib/hexx/suit/install/metrics/metric_fu.yml +15 -0
  29. data/lib/hexx/suit/install/metrics/pippi.yml +3 -0
  30. data/lib/hexx/suit/install/metrics/reek.yml +1 -0
  31. data/lib/hexx/suit/install/metrics/roodi.yml +24 -0
  32. data/lib/hexx/suit/install/metrics/rubocop.yml +79 -0
  33. data/lib/hexx/suit/install/metrics/saikuro.yml +3 -0
  34. data/lib/hexx/suit/install/metrics/simplecov.yml +8 -0
  35. data/lib/hexx/suit/install/metrics/yardstick.yml +37 -0
  36. data/lib/hexx/suit/metrics/base.rb +96 -0
  37. data/lib/hexx/suit/metrics/metric_fu.rb +165 -0
  38. data/lib/hexx/suit/metrics/metric_fu/base.rb +59 -0
  39. data/lib/hexx/suit/metrics/metric_fu/cane.rb +24 -0
  40. data/lib/hexx/suit/metrics/metric_fu/churn.rb +24 -0
  41. data/lib/hexx/suit/metrics/metric_fu/flay.rb +24 -0
  42. data/lib/hexx/suit/metrics/metric_fu/reek.rb +32 -0
  43. data/lib/hexx/suit/metrics/metric_fu/roodi.rb +32 -0
  44. data/lib/hexx/suit/metrics/metric_fu/saikuro.rb +24 -0
  45. data/lib/hexx/suit/metrics/pippi.rb +89 -0
  46. data/lib/hexx/suit/metrics/rubocop.rb +39 -0
  47. data/lib/hexx/suit/metrics/simplecov.rb +119 -0
  48. data/lib/hexx/suit/metrics/yardstick.rb +91 -0
  49. data/lib/hexx/suit/utils/system.rb +66 -0
  50. data/lib/hexx/suit/version.rb +7 -0
  51. data/lib/tasks/check.rake +32 -0
  52. data/lib/tasks/check/coverage.rake +27 -0
  53. data/lib/tasks/check/fu.rake +27 -0
  54. data/lib/tasks/check/inch.rake +11 -0
  55. data/lib/tasks/check/pippi.rake +31 -0
  56. data/lib/tasks/check/rubocop.rake +39 -0
  57. data/lib/tasks/check/yardstick.rake +27 -0
  58. data/lib/tasks/debug.rake +6 -0
  59. data/lib/tasks/test.rake +6 -0
  60. data/spec/spec_helper.rb +10 -0
  61. data/spec/support/config/sandbox.rb +16 -0
  62. data/spec/support/config/tasks.rb +32 -0
  63. data/spec/support/sandbox/helpers.rb +62 -0
  64. data/spec/support/sandbox/matchers.rb +21 -0
  65. data/spec/tests/bin/install_spec.rb +29 -0
  66. data/spec/tests/lib/install_spec.rb +34 -0
  67. data/spec/tests/lib/metrics/metric_fu/cane_spec.rb +32 -0
  68. data/spec/tests/lib/metrics/metric_fu/churn_spec.rb +31 -0
  69. data/spec/tests/lib/metrics/metric_fu/flay_spec.rb +27 -0
  70. data/spec/tests/lib/metrics/metric_fu/reek_spec.rb +22 -0
  71. data/spec/tests/lib/metrics/metric_fu/roodi_spec.rb +22 -0
  72. data/spec/tests/lib/metrics/metric_fu/saikuro_spec.rb +30 -0
  73. data/spec/tests/lib/metrics/metric_fu_spec.rb +181 -0
  74. data/spec/tests/lib/metrics/pippi_spec.rb +102 -0
  75. data/spec/tests/lib/metrics/rubocop_spec.rb +58 -0
  76. data/spec/tests/lib/metrics/simplecov_spec.rb +102 -0
  77. data/spec/tests/lib/metrics/yardstick_spec.rb +110 -0
  78. data/spec/tests/lib/utils/system_spec.rb +85 -0
  79. data/spec/tests/suit_spec.rb +96 -0
  80. data/spec/tests/tasks/check/coverage/display_spec.rb +49 -0
  81. data/spec/tests/tasks/check/coverage/run_spec.rb +25 -0
  82. data/spec/tests/tasks/check/coverage_spec.rb +26 -0
  83. data/spec/tests/tasks/check/display_spec.rb +50 -0
  84. data/spec/tests/tasks/check/fu/display_spec.rb +42 -0
  85. data/spec/tests/tasks/check/fu/run_spec.rb +42 -0
  86. data/spec/tests/tasks/check/fu_spec.rb +18 -0
  87. data/spec/tests/tasks/check/inch_spec.rb +19 -0
  88. data/spec/tests/tasks/check/pippi/display_spec.rb +47 -0
  89. data/spec/tests/tasks/check/pippi/run_spec.rb +25 -0
  90. data/spec/tests/tasks/check/pippi_spec.rb +26 -0
  91. data/spec/tests/tasks/check/rubocop/display_spec.rb +61 -0
  92. data/spec/tests/tasks/check/rubocop/run_spec.rb +78 -0
  93. data/spec/tests/tasks/check/rubocop_spec.rb +26 -0
  94. data/spec/tests/tasks/check/run_spec.rb +44 -0
  95. data/spec/tests/tasks/check/yardstick/display_spec.rb +51 -0
  96. data/spec/tests/tasks/check/yardstick/run_spec.rb +20 -0
  97. data/spec/tests/tasks/check/yardstick_spec.rb +26 -0
  98. data/spec/tests/tasks/check_spec.rb +56 -0
  99. data/spec/tests/tasks/debug_spec.rb +21 -0
  100. data/spec/tests/tasks/test_spec.rb +21 -0
  101. metadata +414 -0
@@ -0,0 +1,66 @@
1
+ module Hexx
2
+ module Suit
3
+
4
+ # Contains utilitity classes
5
+ module Utils
6
+
7
+ # The utility sends multiline string to system
8
+ #
9
+ # Allows stubbing system calls in specifications.
10
+ #
11
+ # @example
12
+ # System.call %(
13
+ # inch --pedantic
14
+ # rubocop
15
+ # )
16
+ #
17
+ # @api private
18
+ class System < String
19
+
20
+ # Initializes multiline text to be sent to system
21
+ #
22
+ # Removes repetitive spaces from itself
23
+ #
24
+ # @param [#to_s] text
25
+ # Multiline text to be sent to system
26
+ #
27
+ # @return [undefined]
28
+ def initialize(text)
29
+ super
30
+ strip!
31
+ gsub!(/ {2,}/, " ")
32
+ end
33
+
34
+ # Returns non-empty lines without trailing spaces
35
+ #
36
+ # @return [Array<String>]
37
+ def lines
38
+ super.map(&:strip).reject(&:empty?)
39
+ end
40
+
41
+ # Sends itself to system line by line
42
+ #
43
+ # @return [self]
44
+ def call
45
+ lines.each(&method(:system))
46
+
47
+ self
48
+ end
49
+
50
+ # Sends multiline string to system
51
+ #
52
+ # @example (see Hexx::Suit::Utils::System)
53
+ #
54
+ # @param (see #initialize)
55
+ #
56
+ # @return [Hexx::Suit::Utils::System]
57
+ # utility object (allows chaining)
58
+ def self.call(text)
59
+ new(text).call
60
+
61
+ self
62
+ end
63
+ end # class System
64
+ end # module Utils
65
+ end # module Suit
66
+ end # module Hexx
@@ -0,0 +1,7 @@
1
+ module Hexx
2
+ module Suit
3
+ # The semantic version of the module.
4
+ # @see http://semver.org/ Semantic versioning 2.0
5
+ VERSION = "0.0.1".freeze
6
+ end # module Suit
7
+ end # module Hexx
@@ -0,0 +1,32 @@
1
+ namespace :check do
2
+
3
+ desc "Runs all tests and code metrics"
4
+ task run: %w(
5
+ pippi:run
6
+ coverage:run
7
+ rubocop:run
8
+ fu:run
9
+ yardstick:run
10
+ )
11
+
12
+ desc "Displays results of last run for any metric"
13
+ task display: %w(
14
+ pippi:display
15
+ coverage:display
16
+ rubocop:display
17
+ fu:display
18
+ inch
19
+ yardstick:display
20
+ )
21
+ end
22
+
23
+ desc "Runs all tests and code metrics and displays their results"
24
+ task check: %w(
25
+ check:pippi:configure
26
+ check:coverage
27
+ check:rubocop
28
+ check:fu
29
+ check:pippi:display
30
+ check:inch
31
+ check:yardstick
32
+ )
@@ -0,0 +1,27 @@
1
+ namespace :check do
2
+ namespace :coverage do
3
+
4
+ metric = Hexx::Suit::Metrics::SimpleCov
5
+ caller = Hexx::Suit::Utils::System
6
+ output = -> { ENV.fetch("SIMPLECOV_OUTPUT") { "coveralls/index.html" } }
7
+
8
+ # Loads settings for simplecov from the '.hexx-suit.yml'
9
+ task :configure do
10
+ metric.load
11
+ end
12
+
13
+ desc "Runs tests under the coveralls"
14
+ task run: :configure do
15
+ caller.call "rake test"
16
+ puts "see results in #{ output.call }"
17
+ end
18
+
19
+ desc "Displays results of the coveralls last run"
20
+ task display: :configure do
21
+ caller.call "launchy #{ output.call }"
22
+ end
23
+ end
24
+
25
+ desc "Runs tests under the coveralls and displays the results"
26
+ task coverage: %w(coverage:run coverage:display)
27
+ end
@@ -0,0 +1,27 @@
1
+ namespace :check do
2
+ namespace :fu do
3
+
4
+ metric = Hexx::Suit::Metrics::MetricFu
5
+ caller = Hexx::Suit::Utils::System
6
+ output = -> { ENV.fetch("METRIC_FU_OUTPUT") { "tmp/metric_fu/output" } }
7
+
8
+ # configures the metrics
9
+ task :configure do
10
+ metric.load
11
+ end
12
+
13
+ desc "Runs metric_fu"
14
+ task run: :configure do
15
+ caller.call "metric_fu --no-open --out #{ output.call }"
16
+ puts "see results in #{ output.call }"
17
+ end
18
+
19
+ desc "Displays results of metric_fu last run"
20
+ task display: :configure do
21
+ caller.call "metric_fu --open --out #{ output.call }"
22
+ end
23
+ end
24
+
25
+ desc "Runs metric_fu and displays the results"
26
+ task fu: %w(fu:display)
27
+ end
@@ -0,0 +1,11 @@
1
+ namespace :check do
2
+
3
+ caller = Hexx::Suit::Utils::System
4
+
5
+ desc "Runs inch to check quality of API docs"
6
+ task :inch do
7
+ puts "******* STARTING METRIC inch"
8
+ caller.call "inch --pedantic"
9
+ puts "******* ENDING METRIC inch"
10
+ end
11
+ end
@@ -0,0 +1,31 @@
1
+ namespace :check do
2
+ namespace :pippi do
3
+
4
+ metric = Hexx::Suit::Metrics::Pippi
5
+ caller = Hexx::Suit::Utils::System
6
+ output = -> { ENV.fetch("PIPPI_OUTPUT") { "log/pippi.log" } }
7
+
8
+ # Loads settings for pippi runtime metric from the '.hexx-suit.yml'
9
+ task :configure do
10
+ metric.load
11
+ end
12
+
13
+ desc "Runs tests with pippi runtime metric"
14
+ task run: :configure do
15
+ puts "******* STARTING METRIC pippi"
16
+ caller.call "rake test"
17
+ puts "see pippi results in #{ output.call }"
18
+ puts "******* ENDING METRIC pippi"
19
+ end
20
+
21
+ desc "Displays results of pippi last run"
22
+ task display: :configure do
23
+ puts "******* DISPLAYING METRIC pippi"
24
+ caller.call "cat #{ output.call }"
25
+ puts "******* ENDING METRIC pippi"
26
+ end
27
+ end
28
+
29
+ desc "Runs tests with pippi runtime metric and displays the results"
30
+ task pippi: %w(pippi:run pippi:display)
31
+ end
@@ -0,0 +1,39 @@
1
+ namespace :check do
2
+ namespace :rubocop do
3
+
4
+ metric = Hexx::Suit::Metrics::Rubocop
5
+ caller = Hexx::Suit::Utils::System
6
+ format = -> { ENV.fetch("RUBOCOP_FORMAT") { "html" } }
7
+ output = -> { ENV.fetch("RUBOCOP_OUTPUT") { "tmp/rubocop/index.html" } }
8
+ options = -> do
9
+ "-f #{ format.call } -o #{ output.call } -c config/metrics/rubocop.yml"
10
+ end
11
+
12
+ # Loads settings for rubocop metric from the '.hexx-suit.yml'
13
+ task :configure do
14
+ metric.load
15
+ end
16
+
17
+ desc "Runs rubocop metric"
18
+ task run: :configure do
19
+ puts "******* STARTING METRIC rubocop"
20
+ caller.call "rubocop #{ options.call }"
21
+ puts "see results in #{ output.call }"
22
+ puts "******* ENDING METRIC rubocop"
23
+ end
24
+
25
+ desc "Displays the results of rubocop last run"
26
+ task display: :configure do
27
+ if format.call == "html"
28
+ caller.call "launchy #{ output.call }"
29
+ else
30
+ puts "******* DISPLAYING METRIC rubocop"
31
+ caller.call "cat #{ output.call }"
32
+ puts "******* ENDING METRIC rubocop"
33
+ end
34
+ end
35
+ end
36
+
37
+ desc "Runs rubocop metric and displays the results"
38
+ task rubocop: %w(rubocop:run rubocop:display)
39
+ end
@@ -0,0 +1,27 @@
1
+ namespace :check do
2
+ namespace :yardstick do
3
+
4
+ metric = Hexx::Suit::Metrics::Yardstick
5
+ caller = Hexx::Suit::Utils::System
6
+ output = ->{ ENV.fetch("YARDSTICK_OUTPUT") { "tmp/yardstick/results.log" } }
7
+
8
+ desc "Runs yardstick metric"
9
+ task :run do
10
+ puts "******* STARTING METRIC yardstick"
11
+ metric.run
12
+ puts "see results in #{ output.call }"
13
+ puts "******* ENDING METRIC yardstick"
14
+ end
15
+
16
+ desc "Displays the results of yardstick last run"
17
+ task :display do
18
+ puts "******* DISPLAYING METRIC yardstick"
19
+ metric.load
20
+ caller.call "cat #{ output.call }"
21
+ puts "******* ENDING METRIC yardstick"
22
+ end
23
+ end
24
+
25
+ desc "Runs yardstick metric and displays the results"
26
+ task yardstick: %w(yardstick:run yardstick:display)
27
+ end
@@ -0,0 +1,6 @@
1
+ caller = Hexx::Suit::Utils::System
2
+
3
+ desc "Runs a test suit in a bundle environment inside pry 'rescue' wrapper."
4
+ task :debug do
5
+ caller.call "bundle exec rescue rspec spec"
6
+ end
@@ -0,0 +1,6 @@
1
+ caller = Hexx::Suit::Utils::System
2
+
3
+ desc "Runs a test suit in a bundle environment, without monitoring coverage."
4
+ task :test do
5
+ caller.call "bundle exec rspec spec"
6
+ end
@@ -0,0 +1,10 @@
1
+ # Loads the RSpec support files.
2
+ require "rspec"
3
+ Dir[File.expand_path "spec/support/config/*.rb"].each { |file| require file }
4
+
5
+ # encoding: utf-8
6
+ require "coveralls"
7
+ Coveralls.wear!
8
+
9
+ # Loads the code of the module with the RSpec test suit.
10
+ require "hexx-suit"
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+
3
+ RSpec.configure do |config|
4
+
5
+ # Prepares a sandbox before corresponding spec.
6
+ config.before :each, :sandbox do
7
+ require_relative "../sandbox/helpers"
8
+ require_relative "../sandbox/matchers"
9
+ prepare_sandbox
10
+ end
11
+
12
+ # Clears a sandbox after corresponding spec.
13
+ config.after :each, :sandbox do
14
+ clear_sandbox
15
+ end
16
+ end
@@ -0,0 +1,32 @@
1
+ # encoding: utf-8
2
+
3
+ RSpec.configure do |config|
4
+
5
+ # Array of commands that was sent to system
6
+ #
7
+ # @return [Array<String>]
8
+ def commands
9
+ @commands ||= []
10
+ end
11
+
12
+ # Checks whether a task with given name has been invoked
13
+ #
14
+ # @param [String] name
15
+ #
16
+ # @return [Boolean]
17
+ def task_invoked?(name)
18
+ Rake::Task[name].instance_eval { @already_invoked }
19
+ end
20
+
21
+ config.before :example, :tasks do
22
+
23
+ # Resets Rake application and reinstalls all tasks to be available
24
+ Rake.application = nil
25
+ Hexx::Suit.install_tasks
26
+
27
+ # Captures commands that System utility sends to system
28
+ # and stores them in {#commands} array.
29
+ allow_any_instance_of(Hexx::Suit::Utils::System)
30
+ .to receive(:system) { |command| commands << command }
31
+ end
32
+ end
@@ -0,0 +1,62 @@
1
+ # encoding: utf-8
2
+ require "yaml"
3
+
4
+ # Yields block and captures stdout stream.
5
+ #
6
+ # @example
7
+ # capture_stdout { do_something }
8
+ #
9
+ # @return [String] The captured stream.
10
+ def capture_stdout
11
+ begin
12
+ $stdout = StringIO.new
13
+ yield
14
+ result = $stdout.string
15
+ ensure
16
+ $stdout = STDOUT
17
+ end
18
+ result.to_s
19
+ end
20
+
21
+ # Returns the path to the temporary `spec/sandbox`.
22
+ # @return [String] The absolute path.
23
+ def sandbox
24
+ @sandbox ||= File.expand_path "../../../sandbox", __FILE__
25
+ end
26
+
27
+ # Clears the temporary `spec/sandbox`.
28
+ def clear_sandbox
29
+ FileUtils.rm_rf sandbox
30
+ end
31
+
32
+ # Re-creates the temporary `spec/sandbox`.
33
+ def prepare_sandbox
34
+ clear_sandbox
35
+ FileUtils.mkdir_p sandbox
36
+ end
37
+
38
+ # Runs code from the temporary `spec/sandbox`.
39
+ def try_in_sandbox
40
+ FileUtils.cd(sandbox) { capture_stdout { yield } }
41
+ end
42
+
43
+ # Reads file in sandbox and returns file content.
44
+ # Returns a blank string when the file is absent.
45
+ # @return [String] The content.
46
+ def read_in_sandbox(filename)
47
+ file = Dir[File.join(sandbox, filename)].first
48
+ file ? File.read(file) : ""
49
+ end
50
+
51
+ # Creates settings file in a sandbox
52
+ #
53
+ # @param [Hash] settings ({})
54
+ # The list of settings to be stored in 'sandbox/.metrics.yml'
55
+ #
56
+ # @return [undefined]
57
+ def prepare_settings(settings, file = ".metrics.yml")
58
+ try_in_sandbox do
59
+ ::FileUtils.mkdir_p ::File.dirname(file)
60
+ ::File.write file, settings.to_yaml
61
+ end
62
+ end
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+
3
+ # Checks if a file with given name is present in sandbox.
4
+ #
5
+ # @example
6
+ # expect("some_file.rb").to be_present_in_sandbox
7
+ RSpec::Matchers.define :be_present_in_sandbox do
8
+ match do |filename|
9
+ files = Dir[File.join(sandbox, filename)]
10
+ expect(files).to be_any
11
+ end
12
+ end
13
+
14
+ # Checks if a file with given name is absent in sandbox.
15
+ #
16
+ # @example
17
+ # expect("some_file.rb").to be_absent_in_sandbox
18
+ RSpec::Matchers.define_negated_matcher(
19
+ :be_absent_in_sandbox,
20
+ :be_present_in_sandbox
21
+ )
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+
3
+ describe "hexx-suit install", :sandbox do
4
+
5
+ describe "install" do
6
+
7
+ before { try_in_sandbox { `hexx-suit install` } }
8
+
9
+ it "creates necessary files" do
10
+ %w(
11
+ .rspec
12
+ .yardopts
13
+ Guardfile
14
+ Rakefile
15
+ config/metrics/cane.yml
16
+ config/metrics/churn.yml
17
+ config/metrics/flay.yml
18
+ config/metrics/metric_fu.yml
19
+ config/metrics/pippi.yml
20
+ config/metrics/reek.yml
21
+ config/metrics/roodi.yml
22
+ config/metrics/rubocop.yml
23
+ config/metrics/saikuro.yml
24
+ config/metrics/simplecov.yml
25
+ config/metrics/yardstick.yml
26
+ ).each { |file| expect(file).to be_present_in_sandbox }
27
+ end
28
+ end
29
+ end