Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes share issue with version command #83

Merged
merged 12 commits into from
Aug 31, 2021
1 change: 1 addition & 0 deletions .reek.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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?
11 changes: 2 additions & 9 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand All @@ -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.
Expand Down
6 changes: 4 additions & 2 deletions lib/skunk/cli/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions lib/skunk/cli/commands/help.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ def execute
status_reporter
end

def sharing?
false
end

private

attr_reader :options, :status_reporter
Expand Down
6 changes: 6 additions & 0 deletions lib/skunk/cli/commands/shareable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 12 additions & 6 deletions lib/skunk/cli/commands/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 9 additions & 4 deletions test/lib/skunk/application_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 10 additions & 8 deletions test/lib/skunk/cli/commands/help_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions test/lib/skunk/cli/commands/version_test.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions test/lib/skunk/rubycritic/analysed_module_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down