From 8c9410508c3154ab483823a0ccc516492512ea30 Mon Sep 17 00:00:00 2001 From: Ernesto Tagwerker Date: Mon, 30 Aug 2021 19:31:11 -0400 Subject: [PATCH 01/12] Add test coverage for version command --- test/lib/skunk/cli/commands/version_test.rb | 22 +++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 test/lib/skunk/cli/commands/version_test.rb 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..6f98ad3 --- /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::Command::Version do + describe "#execute" do + MSG = Skunk::VERSION + + it "outputs the right version message" do + options = ["--version"] + opts = Skunk::Cli::Options.new(options).parse + subject = Skunk::Command::Version.new(opts.to_h) + + assert_output(MSG) do + subject.execute + end + end + end +end From 2c162f2d068f9b8c015706923d1246c0f7f1c464 Mon Sep 17 00:00:00 2001 From: Ernesto Tagwerker Date: Mon, 30 Aug 2021 19:34:28 -0400 Subject: [PATCH 02/12] Improve coverage to run application with help and version arguments --- test/lib/skunk/application_test.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/test/lib/skunk/application_test.rb b/test/lib/skunk/application_test.rb index 77d9c01..250c944 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 + ["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 From 5583989bd0795d03a1363638f744e35a83e72de7 Mon Sep 17 00:00:00 2001 From: Ernesto Tagwerker Date: Mon, 30 Aug 2021 19:36:39 -0400 Subject: [PATCH 03/12] Add Cli module to be consistent across commands --- lib/skunk/cli/commands/version.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/skunk/cli/commands/version.rb b/lib/skunk/cli/commands/version.rb index 8631d43..fe93c0c 100644 --- a/lib/skunk/cli/commands/version.rb +++ b/lib/skunk/cli/commands/version.rb @@ -4,12 +4,14 @@ # 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 end end end From a5d86d7639f4db47e54ed2f64ae7ca8c224de0c1 Mon Sep 17 00:00:00 2001 From: Ernesto Tagwerker Date: Mon, 30 Aug 2021 19:36:59 -0400 Subject: [PATCH 04/12] Use updated reference to test Version command --- test/lib/skunk/cli/commands/version_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/lib/skunk/cli/commands/version_test.rb b/test/lib/skunk/cli/commands/version_test.rb index 6f98ad3..760cac1 100644 --- a/test/lib/skunk/cli/commands/version_test.rb +++ b/test/lib/skunk/cli/commands/version_test.rb @@ -5,14 +5,14 @@ require "skunk/cli/commands/version" require "skunk/cli/options" -describe Skunk::Command::Version do +describe Skunk::Cli::Command::Version do describe "#execute" do MSG = Skunk::VERSION it "outputs the right version message" do options = ["--version"] opts = Skunk::Cli::Options.new(options).parse - subject = Skunk::Command::Version.new(opts.to_h) + subject = Skunk::Cli::Command::Version.new(opts.to_h) assert_output(MSG) do subject.execute From 7be5a5eaee5704b1952e3d86d3dcb91e6acbdb67 Mon Sep 17 00:00:00 2001 From: Ernesto Tagwerker Date: Mon, 30 Aug 2021 19:43:53 -0400 Subject: [PATCH 05/12] Add `sharing?` method at the commnand level to guide the application's execution This fixes #81 --- lib/skunk/cli/application.rb | 6 ++++-- lib/skunk/cli/commands/shareable.rb | 6 ++++++ lib/skunk/cli/commands/version.rb | 4 ++++ 3 files changed, 14 insertions(+), 2 deletions(-) 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/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 fe93c0c..844e93b 100644 --- a/lib/skunk/cli/commands/version.rb +++ b/lib/skunk/cli/commands/version.rb @@ -12,6 +12,10 @@ def execute print Skunk::VERSION status_reporter end + + def sharing? + false + end end end end From ea9f33df0017fd497e373b0045d73f19f3d628a0 Mon Sep 17 00:00:00 2001 From: Ernesto Tagwerker Date: Mon, 30 Aug 2021 19:44:49 -0400 Subject: [PATCH 06/12] Set help command to never share --- lib/skunk/cli/commands/help.rb | 4 ++++ 1 file changed, 4 insertions(+) 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 From 1837d0cdb2ea7246891fc49644822900944f74b9 Mon Sep 17 00:00:00 2001 From: Ernesto Tagwerker Date: Mon, 30 Aug 2021 21:26:09 -0400 Subject: [PATCH 07/12] Update churn times cost --- test/lib/skunk/rubycritic/analysed_module_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/lib/skunk/rubycritic/analysed_module_test.rb b/test/lib/skunk/rubycritic/analysed_module_test.rb index 98ba1bf..0af6cf6 100644 --- a/test/lib/skunk/rubycritic/analysed_module_test.rb +++ b/test/lib/skunk/rubycritic/analysed_module_test.rb @@ -60,7 +60,7 @@ { file: "samples/rubycritic/analysed_module.rb", skunk_score: 58.88, - churn_times_cost: 2.36, + churn_times_cost: 2.94, churn: 4, cost: 0.59, coverage: 0.0 From be0136d1732fc97fe1b1b766de4012b63956986e Mon Sep 17 00:00:00 2001 From: Ernesto Tagwerker Date: Mon, 30 Aug 2021 21:27:02 -0400 Subject: [PATCH 08/12] Updated churn expectation --- test/lib/skunk/rubycritic/analysed_module_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/lib/skunk/rubycritic/analysed_module_test.rb b/test/lib/skunk/rubycritic/analysed_module_test.rb index 0af6cf6..fd133ec 100644 --- a/test/lib/skunk/rubycritic/analysed_module_test.rb +++ b/test/lib/skunk/rubycritic/analysed_module_test.rb @@ -61,7 +61,7 @@ file: "samples/rubycritic/analysed_module.rb", skunk_score: 58.88, churn_times_cost: 2.94, - churn: 4, + churn: 5, cost: 0.59, coverage: 0.0 } From 593eadb03a2dcaca5a26d36465a40ab6a46eb396 Mon Sep 17 00:00:00 2001 From: Ernesto Tagwerker Date: Mon, 30 Aug 2021 21:29:07 -0400 Subject: [PATCH 09/12] Use let instead of constant This avoids a race condition --- test/lib/skunk/cli/commands/help_test.rb | 18 ++++++++++-------- test/lib/skunk/cli/commands/version_test.rb | 4 ++-- 2 files changed, 12 insertions(+), 10 deletions(-) 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 index 760cac1..ded860a 100644 --- a/test/lib/skunk/cli/commands/version_test.rb +++ b/test/lib/skunk/cli/commands/version_test.rb @@ -7,14 +7,14 @@ describe Skunk::Cli::Command::Version do describe "#execute" do - MSG = Skunk::VERSION + 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 + assert_output(msg) do subject.execute end end From 8377664b9d23c2ec4d986516a49a8153912fd175 Mon Sep 17 00:00:00 2001 From: Ernesto Tagwerker Date: Mon, 30 Aug 2021 21:31:18 -0400 Subject: [PATCH 10/12] Ignore warning by reek re: sharing? method --- .reek.yml | 1 + 1 file changed, 1 insertion(+) 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? From 039a12b8b21854b7a4bb9fc319c4fed88a4ada5c Mon Sep 17 00:00:00 2001 From: Ernesto Tagwerker Date: Mon, 30 Aug 2021 21:33:30 -0400 Subject: [PATCH 11/12] Ignore two new issues with two test files --- .rubocop_todo.yml | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) 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. From c80e274463496e26c044ca99eb0baf21eba3a547 Mon Sep 17 00:00:00 2001 From: Ernesto Tagwerker Date: Mon, 30 Aug 2021 21:33:45 -0400 Subject: [PATCH 12/12] Apply rubocop suggestion re: string array --- test/lib/skunk/application_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/lib/skunk/application_test.rb b/test/lib/skunk/application_test.rb index 250c944..ff0a435 100644 --- a/test/lib/skunk/application_test.rb +++ b/test/lib/skunk/application_test.rb @@ -23,7 +23,7 @@ context "when passing a valid option" do let(:success_code) { 0 } - ["help", "version"].each do |argument| + %w[help version].each do |argument| context "and option is #{argument}" do let(:argv) { ["--#{argument}"] }