diff --git a/.reek.yml b/.reek.yml index 6a46a3d..c080fbf 100644 --- a/.reek.yml +++ b/.reek.yml @@ -26,3 +26,4 @@ detectors: exclude: - Skunk::Cli::Command::Compare#analyse_modified_files - Skunk::Cli::Command::Compare#build_details_path + - Skunk::Cli::Command::Shareable#sharing? diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 5d8604d..c2f3a3c 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2021-02-12 01:27:25 UTC using RuboCop version 1.9.1. +# on 2021-08-31 01:33:08 UTC using RuboCop version 1.9.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -26,13 +26,6 @@ Layout/HeredocIndentation: Exclude: - 'lib/skunk/cli/commands/status_reporter.rb' -# Offense count: 1 -# Configuration parameters: AllowedMethods. -# AllowedMethods: enums -Lint/ConstantDefinitionInBlock: - Exclude: - - 'test/lib/skunk/cli/commands/help_test.rb' - # Offense count: 2 Lint/MissingSuper: Exclude: @@ -48,7 +41,7 @@ Metrics/AbcSize: # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods. # IgnoredMethods: refine Metrics/BlockLength: - Max: 72 + Max: 76 # Offense count: 2 # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods. diff --git a/lib/skunk/cli/application.rb b/lib/skunk/cli/application.rb index 88a6555..138647b 100644 --- a/lib/skunk/cli/application.rb +++ b/lib/skunk/cli/application.rb @@ -30,8 +30,10 @@ def execute reporter = command.execute print(reporter.status_message) - share_status_message = command.share(reporter) - print(share_status_message) + if command.sharing? + share_status_message = command.share(reporter) + print(share_status_message) + end reporter.status rescue OptionParser::InvalidOption => e diff --git a/lib/skunk/cli/commands/help.rb b/lib/skunk/cli/commands/help.rb index a9133fa..3a7bbdb 100644 --- a/lib/skunk/cli/commands/help.rb +++ b/lib/skunk/cli/commands/help.rb @@ -14,6 +14,10 @@ def execute status_reporter end + def sharing? + false + end + private attr_reader :options, :status_reporter diff --git a/lib/skunk/cli/commands/shareable.rb b/lib/skunk/cli/commands/shareable.rb index ca2c4d8..9459398 100644 --- a/lib/skunk/cli/commands/shareable.rb +++ b/lib/skunk/cli/commands/shareable.rb @@ -15,6 +15,12 @@ def share(reporter) sharer.status_reporter = reporter sharer.share end + + # @return [Boolean] If the environment is set to share to an external + # service + def sharing? + ENV["SHARE"] == "true" + end end end end diff --git a/lib/skunk/cli/commands/version.rb b/lib/skunk/cli/commands/version.rb index 8631d43..844e93b 100644 --- a/lib/skunk/cli/commands/version.rb +++ b/lib/skunk/cli/commands/version.rb @@ -4,12 +4,18 @@ # nodoc # module Skunk - module Command - # Shows skunk version - class Version < RubyCritic::Command::Version - def execute - print Skunk::VERSION - status_reporter + module Cli + module Command + # Shows skunk version + class Version < RubyCritic::Command::Version + def execute + print Skunk::VERSION + status_reporter + end + + def sharing? + false + end end end end diff --git a/test/lib/skunk/application_test.rb b/test/lib/skunk/application_test.rb index 77d9c01..ff0a435 100644 --- a/test/lib/skunk/application_test.rb +++ b/test/lib/skunk/application_test.rb @@ -21,12 +21,17 @@ end context "when passing a valid option" do - let(:argv) { ["--help"] } let(:success_code) { 0 } - it "returns a success code (0)" do - result = application.execute - _(result).must_equal success_code + %w[help version].each do |argument| + context "and option is #{argument}" do + let(:argv) { ["--#{argument}"] } + + it "returns a success code (0)" do + result = application.execute + _(result).must_equal success_code + end + end end end diff --git a/test/lib/skunk/cli/commands/help_test.rb b/test/lib/skunk/cli/commands/help_test.rb index 55c991b..ca961ad 100644 --- a/test/lib/skunk/cli/commands/help_test.rb +++ b/test/lib/skunk/cli/commands/help_test.rb @@ -7,20 +7,22 @@ describe Skunk::Cli::Command::Help do describe "#execute" do - MSG = <<~HELP - Usage: skunk [options] [paths] - -b, --branch BRANCH Set branch to compare - -o, --out FILE Output report to file - -v, --version Show gem's version - -h, --help Show this message - HELP + let(:msg) do + <<~HELP + Usage: skunk [options] [paths] + -b, --branch BRANCH Set branch to compare + -o, --out FILE Output report to file + -v, --version Show gem's version + -h, --help Show this message + HELP + end it "outputs the right help message" do options = ["--help"] opts = Skunk::Cli::Options.new(options).parse subject = Skunk::Cli::Command::Help.new(opts.to_h) - assert_output(MSG) do + assert_output(msg) do subject.execute end end diff --git a/test/lib/skunk/cli/commands/version_test.rb b/test/lib/skunk/cli/commands/version_test.rb new file mode 100644 index 0000000..ded860a --- /dev/null +++ b/test/lib/skunk/cli/commands/version_test.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +require "test_helper" + +require "skunk/cli/commands/version" +require "skunk/cli/options" + +describe Skunk::Cli::Command::Version do + describe "#execute" do + let(:msg) { Skunk::VERSION } + + it "outputs the right version message" do + options = ["--version"] + opts = Skunk::Cli::Options.new(options).parse + subject = Skunk::Cli::Command::Version.new(opts.to_h) + + assert_output(msg) do + subject.execute + end + end + end +end diff --git a/test/lib/skunk/rubycritic/analysed_module_test.rb b/test/lib/skunk/rubycritic/analysed_module_test.rb index 98ba1bf..fd133ec 100644 --- a/test/lib/skunk/rubycritic/analysed_module_test.rb +++ b/test/lib/skunk/rubycritic/analysed_module_test.rb @@ -60,8 +60,8 @@ { file: "samples/rubycritic/analysed_module.rb", skunk_score: 58.88, - churn_times_cost: 2.36, - churn: 4, + churn_times_cost: 2.94, + churn: 5, cost: 0.59, coverage: 0.0 }