From 3a193a4c018d7070564bcec925417f663ddef65d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20V=C3=A1squez?= Date: Fri, 14 Nov 2025 11:37:36 -0600 Subject: [PATCH 1/6] chore: update rubocop todo configuration Update rubocop todo file with latest offense counts and configurations --- CHANGELOG.md | 3 +-- test/lib/skunk/cli/options/argv_test.rb | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c15596..c2849cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,8 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## main [(unreleased)](https://github.com/fastruby/skunk/compare/v0.5.4...HEAD) -* BUGFIX: Pin path_expander < 2.0 for Ruby 2.7 compatibility -* [FEATURE: Add `--formats` CLI flag to select report formats (json, html, console)](https://github.com/fastruby/skunk/pull/130) +* [FEATURE: Add `--formats` CLI flag to select report formats (json, html, console)] * [REFACTOR: Move Console Report](https://github.com/fastruby/skunk/pull/128) * [BUGFIX: Set the right content type in the share HTTP request](https://github.com/fastruby/skunk/pull/129) * [REFACTOR: Centralize Skunk analysis into RubyCritic module](https://github.com/fastruby/skunk/pull/127) diff --git a/test/lib/skunk/cli/options/argv_test.rb b/test/lib/skunk/cli/options/argv_test.rb index 20bfb45..320c712 100644 --- a/test/lib/skunk/cli/options/argv_test.rb +++ b/test/lib/skunk/cli/options/argv_test.rb @@ -29,7 +29,6 @@ after do Skunk::Config.reset end - context "passing --formats option" do let(:argv) { ["--formats=json,html"] } From a718082ab4da11e68cd170b197a7cc6325887848 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20V=C3=A1squez?= Date: Fri, 14 Nov 2025 17:14:33 -0600 Subject: [PATCH 2/6] Apply suggestions from code review --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c2849cf..f9217bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## main [(unreleased)](https://github.com/fastruby/skunk/compare/v0.5.4...HEAD) -* [FEATURE: Add `--formats` CLI flag to select report formats (json, html, console)] +* [FEATURE: Add `--formats` CLI flag to select report formats (json, html, console)](https://github.com/fastruby/skunk/pull/130) * [REFACTOR: Move Console Report](https://github.com/fastruby/skunk/pull/128) * [BUGFIX: Set the right content type in the share HTTP request](https://github.com/fastruby/skunk/pull/129) * [REFACTOR: Centralize Skunk analysis into RubyCritic module](https://github.com/fastruby/skunk/pull/127) From 58a2180eab3d13dcd1972e427122ed39c384f14b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20V=C3=A1squez?= Date: Fri, 14 Nov 2025 16:56:40 -0600 Subject: [PATCH 3/6] refactor(config): centralize output path configuration and simplify printing Move output path configuration to Skunk::Config and remove file output logic from Application#print Update tests and documentation to reflect changes in output path handling Even if the default path where the JSON and HTML reports are generated are `tmp/rubycritic` you can now modify them. --- CHANGELOG.md | 1 + README.md | 6 +- bin/console | 3 +- lib/skunk/cli/application.rb | 8 +-- lib/skunk/cli/options/argv.rb | 69 ++++++------------- lib/skunk/config.rb | 13 ++++ lib/skunk/generators/console_report.rb | 16 ++++- lib/skunk/generators/html/overview.rb | 4 ++ lib/skunk/generators/json/simple.rb | 4 +- test/lib/skunk/cli/options/argv_test.rb | 26 ++++--- test/lib/skunk/commands/help_test.rb | 4 +- test/lib/skunk/config_test.rb | 9 +++ .../skunk/generators/console_report_test.rb | 15 ++++ .../skunk/generators/html/overview_test.rb | 26 +++++++ 14 files changed, 127 insertions(+), 77 deletions(-) create mode 100644 test/lib/skunk/generators/html/overview_test.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index f9217bd..1a80f1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## main [(unreleased)](https://github.com/fastruby/skunk/compare/v0.5.4...HEAD) +* [FEATURE: Indicate `--out PATH` location](https://github.com/fastruby/skunk/pull/131) * [FEATURE: Add `--formats` CLI flag to select report formats (json, html, console)](https://github.com/fastruby/skunk/pull/130) * [REFACTOR: Move Console Report](https://github.com/fastruby/skunk/pull/128) * [BUGFIX: Set the right content type in the share HTTP request](https://github.com/fastruby/skunk/pull/129) diff --git a/README.md b/README.md index 1792f04..21a93ca 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ Run `skunk -h` to check out the help options: ``` Usage: skunk [options] [paths] -b, --branch BRANCH Set branch to compare - -o, --out FILE Output report to file + -o, --out PATH Output report path -v, --version Show gem's version -h, --help Show this message ``` @@ -127,7 +127,9 @@ To only run skunk on specific folders, pass a list of directories in the command ### Generate JSON report in background -When the Skunk command is run, it will generate a JSON report file in the `RubyCritic::Config.root` location. +When the Skunk command is run, it will generate a JSON report file in the configured output path. + +Skunk also writes the console report to `skunk_console.txt` under the same output path. ### Comparing feature branches diff --git a/bin/console b/bin/console index 00c2b0a..623d374 100755 --- a/bin/console +++ b/bin/console @@ -13,5 +13,6 @@ puts ARGV.inspect require "skunk/cli/application" require "skunk/config" -Skunk::Config.formats = %i[json console html] +Skunk::Config.formats = %i[json console html] # supported output formats +Skunk::Config.root = "tmp/rubycritic" # default path to store generated JSON and HTML reports. Skunk::Cli::Application.new(ARGV).execute diff --git a/lib/skunk/cli/application.rb b/lib/skunk/cli/application.rb index d7c00b4..482178d 100644 --- a/lib/skunk/cli/application.rb +++ b/lib/skunk/cli/application.rb @@ -50,14 +50,8 @@ def warn_coverage_info warn "warning: Having no coverage metrics will make your SkunkScore worse." end - # :reek:NilCheck def print(message) - filename = @parsed_options[:output_filename] - if filename.nil? - $stdout.puts(message) - else - File.open(filename, "a") { |file| file << message } - end + $stdout.puts(message) end end end diff --git a/lib/skunk/cli/options/argv.rb b/lib/skunk/cli/options/argv.rb index 26825cd..e43038e 100644 --- a/lib/skunk/cli/options/argv.rb +++ b/lib/skunk/cli/options/argv.rb @@ -10,59 +10,32 @@ class Options # Extends RubyCritic::Cli::Options::Argv to parse a subset of the # parameters accepted by RubyCritic class Argv < RubyCritic::Cli::Options::Argv - # :reek:Attribute - attr_accessor :output_filename - def parse parser.new do |opts| opts.banner = "Usage: skunk [options] [paths]\n" - add_branch_option(opts) - add_output_option(opts) - add_formats_option(opts) - add_tail_options(opts) + opts.on("-b", "--branch BRANCH", "Set branch to compare") do |branch| + self.base_branch = String(branch) + set_current_branch + self.mode = :compare_branches + end + + opts.on("-o", "--out PATH", "Output report path") do |path| + Skunk::Config.root = path + end + + opts.on("-f", "--formats json,html,console", Array, "Output formats: json,html,console") do |list| + Skunk::Config.formats = Array(list).map(&:to_sym) + end + + opts.on_tail("-v", "--version", "Show gem's version") do + self.mode = :version + end + + opts.on_tail("-h", "--help", "Show this message") do + self.mode = :help + end end.parse!(@argv) end - - def to_h - super.merge(output_filename: output_filename) - end - - private - - def add_branch_option(opts) - opts.on("-b", "--branch BRANCH", "Set branch to compare") do |branch| - self.base_branch = String(branch) - set_current_branch - self.mode = :compare_branches - end - end - - def add_output_option(opts) - opts.on("-o", "--out FILE", "Output report to file") do |filename| - self.output_filename = filename - end - end - - def add_formats_option(opts) - opts.on( - "-f", - "--formats json,html,console", - Array, - "Output formats: json,html,console (default: console)" - ) do |list| - Skunk::Config.formats = Array(list).map(&:to_sym) - end - end - - def add_tail_options(opts) - opts.on_tail("-v", "--version", "Show gem's version") do - self.mode = :version - end - - opts.on_tail("-h", "--help", "Show this message") do - self.mode = :help - end - end end end end diff --git a/lib/skunk/config.rb b/lib/skunk/config.rb index 769590d..aeec57b 100644 --- a/lib/skunk/config.rb +++ b/lib/skunk/config.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require "rubycritic/configuration" + module Skunk # Utility module for format validation module FormatValidator @@ -28,10 +30,12 @@ class Configuration def initialize @formats = [DEFAULT_FORMAT] + @root = RubyCritic::Config.root end def set(options = {}) self.formats = options[:formats] if options.key?(:formats) + self.root = options[:root] if options.key?(:root) end # Get the configured formats @@ -46,6 +50,14 @@ def formats=(format_list) @formats = [DEFAULT_FORMAT] if @formats.empty? end + def root + @root || File.expand_path("tmp/rubycritic", Dir.pwd) + end + + def root=(path) + @root = path.nil? || path.to_s.empty? ? nil : File.expand_path(path.to_s) + end + # Add a format to the existing list # @param format [Symbol] Format to add def add_format(format) @@ -77,6 +89,7 @@ def supported_formats # Reset to default configuration def reset @formats = [DEFAULT_FORMAT] + @root = RubyCritic::Config.root end end diff --git a/lib/skunk/generators/console_report.rb b/lib/skunk/generators/console_report.rb index 3b1958e..2154f0e 100644 --- a/lib/skunk/generators/console_report.rb +++ b/lib/skunk/generators/console_report.rb @@ -2,8 +2,11 @@ require "erb" require "terminal-table" +require "pathname" +require "fileutils" require "skunk/generators/console/simple" +require "skunk/config" module Skunk module Generator @@ -14,7 +17,10 @@ def initialize(analysed_modules) end def generate_report - puts generator.render + content = generator.render + puts content + FileUtils.mkdir_p(file_directory) + File.write(file_pathname, content) end private @@ -22,6 +28,14 @@ def generate_report def generator @generator ||= Skunk::Generator::Console::Simple.new(@analysed_modules) end + + def file_directory + @file_directory ||= Pathname.new(Skunk::Config.root) + end + + def file_pathname + Pathname.new(file_directory).join("skunk_console.txt") + end end end end diff --git a/lib/skunk/generators/html/overview.rb b/lib/skunk/generators/html/overview.rb index 78e7d2b..a3c60f8 100644 --- a/lib/skunk/generators/html/overview.rb +++ b/lib/skunk/generators/html/overview.rb @@ -49,6 +49,10 @@ def files FileData.new(module_data) end end + + def root_directory + @root_directory ||= Pathname.new(Skunk::Config.root) + end end end end diff --git a/lib/skunk/generators/json/simple.rb b/lib/skunk/generators/json/simple.rb index 0a686ce..353d767 100644 --- a/lib/skunk/generators/json/simple.rb +++ b/lib/skunk/generators/json/simple.rb @@ -2,7 +2,7 @@ require "pathname" -require "rubycritic/configuration" +require "skunk/config" require "skunk/rubycritic/analysed_modules_collection" module Skunk @@ -25,7 +25,7 @@ def data end def file_directory - @file_directory ||= Pathname.new(RubyCritic::Config.root) + @file_directory ||= Pathname.new(Skunk::Config.root) end def file_pathname diff --git a/test/lib/skunk/cli/options/argv_test.rb b/test/lib/skunk/cli/options/argv_test.rb index 320c712..d26fb74 100644 --- a/test/lib/skunk/cli/options/argv_test.rb +++ b/test/lib/skunk/cli/options/argv_test.rb @@ -5,23 +5,21 @@ require "skunk/cli/options/argv" describe Skunk::Cli::Options::Argv do - describe "#output_filename" do - context "passing --out=FILE options" do - let(:argv) { ["--out=file.txt"] } + describe "--out path" do + after do + Skunk::Config.reset + end - it "parses passed filename" do - parser = Skunk::Cli::Options::Argv.new(argv) - parser.parse - _(parser.output_filename).must_equal "file.txt" - end + it "sets Skunk::Config.root to the provided path" do + parser = Skunk::Cli::Options::Argv.new(["--out=tmp/custom"]) + parser.parse + _(Skunk::Config.root).must_match(/tmp\/custom$/) end - context "not passing the --out option" do - it "is nil" do - parser = Skunk::Cli::Options::Argv.new([]) - parser.parse - _(parser.output_filename).must_be_nil - end + it "defaults to tmp/rubycritic when not provided" do + parser = Skunk::Cli::Options::Argv.new([]) + parser.parse + _(Skunk::Config.root).must_match(/tmp\/rubycritic$/) end end diff --git a/test/lib/skunk/commands/help_test.rb b/test/lib/skunk/commands/help_test.rb index 4f25c0d..6ff3d24 100644 --- a/test/lib/skunk/commands/help_test.rb +++ b/test/lib/skunk/commands/help_test.rb @@ -11,8 +11,8 @@ <<~HELP Usage: skunk [options] [paths] -b, --branch BRANCH Set branch to compare - -o, --out FILE Output report to file - -f, --formats json,html,console Output formats: json,html,console (default: console) + -o, --out PATH Output report path + -f, --formats json,html,console Output formats: json,html,console -v, --version Show gem's version -h, --help Show this message HELP diff --git a/test/lib/skunk/config_test.rb b/test/lib/skunk/config_test.rb index a04e1c6..342cb34 100644 --- a/test/lib/skunk/config_test.rb +++ b/test/lib/skunk/config_test.rb @@ -79,5 +79,14 @@ def test_reset Config.reset assert_equal [:console], Config.formats end + + def test_default_root + assert_match(/tmp\/rubycritic$/, Config.root) + end + + def test_set_root_expands_path + Config.root = "tmp/custom" + assert_equal File.expand_path("tmp/custom", Dir.pwd), Config.root + end end end diff --git a/test/lib/skunk/generators/console_report_test.rb b/test/lib/skunk/generators/console_report_test.rb index 6f880de..39c98e9 100644 --- a/test/lib/skunk/generators/console_report_test.rb +++ b/test/lib/skunk/generators/console_report_test.rb @@ -187,6 +187,21 @@ def test_generate_report_calls_generator_render assert_equal "test output\n", output mock_generator.verify end + + def test_generate_report_writes_console_file + Skunk::Config.root = "tmp/console_report" + begin + path = File.join(Skunk::Config.root, "skunk_console.txt") + File.delete(path) if File.exist?(path) + + @console_report.generate_report + + assert File.exist?(path) + assert_includes File.read(path), "SkunkScore Total" + ensure + FileUtils.rm_rf(Skunk::Config.root) + end + end end end end diff --git a/test/lib/skunk/generators/html/overview_test.rb b/test/lib/skunk/generators/html/overview_test.rb new file mode 100644 index 0000000..5f5d018 --- /dev/null +++ b/test/lib/skunk/generators/html/overview_test.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +require "minitest/autorun" +require "skunk/generators/html/overview" +require "skunk/config" + +module Skunk + module Generator + module Html + class OverviewTest < Minitest::Test + def teardown + Skunk::Config.reset + end + + def test_root_directory_uses_skunk_config_root + Skunk::Config.root = "tmp/custom_html" + analysed_modules = Minitest::Mock.new + generator = Overview.new(analysed_modules) + + root = generator.send(:root_directory) + assert_equal File.expand_path("tmp/custom_html", Dir.pwd), root.to_s + end + end + end + end +end \ No newline at end of file From 5166cf159f07cff8fc5fc7faf53dddcaa4cfaec3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20V=C3=A1squez?= Date: Mon, 17 Nov 2025 15:20:17 -0600 Subject: [PATCH 4/6] Use same name on JSON, Console and HTML reports Skunk_report (txt,json,html) --- README.md | 2 +- lib/skunk/generators/console_report.rb | 2 +- lib/skunk/generators/html/overview.rb | 2 +- test/lib/skunk/generators/console_report_test.rb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 21a93ca..e16be5c 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,7 @@ To only run skunk on specific folders, pass a list of directories in the command When the Skunk command is run, it will generate a JSON report file in the configured output path. -Skunk also writes the console report to `skunk_console.txt` under the same output path. +Skunk also writes the console report to `skunk_report.txt` under the same output path. ### Comparing feature branches diff --git a/lib/skunk/generators/console_report.rb b/lib/skunk/generators/console_report.rb index 2154f0e..774eae7 100644 --- a/lib/skunk/generators/console_report.rb +++ b/lib/skunk/generators/console_report.rb @@ -34,7 +34,7 @@ def file_directory end def file_pathname - Pathname.new(file_directory).join("skunk_console.txt") + Pathname.new(file_directory).join("skunk_report.txt") end end end diff --git a/lib/skunk/generators/html/overview.rb b/lib/skunk/generators/html/overview.rb index a3c60f8..fec1033 100644 --- a/lib/skunk/generators/html/overview.rb +++ b/lib/skunk/generators/html/overview.rb @@ -25,7 +25,7 @@ def initialize(analysed_modules) end def file_name - "skunk_overview.html" + "skunk_report.html" end def render diff --git a/test/lib/skunk/generators/console_report_test.rb b/test/lib/skunk/generators/console_report_test.rb index 39c98e9..c63e9d5 100644 --- a/test/lib/skunk/generators/console_report_test.rb +++ b/test/lib/skunk/generators/console_report_test.rb @@ -191,7 +191,7 @@ def test_generate_report_calls_generator_render def test_generate_report_writes_console_file Skunk::Config.root = "tmp/console_report" begin - path = File.join(Skunk::Config.root, "skunk_console.txt") + path = File.join(Skunk::Config.root, "skunk_report.txt") File.delete(path) if File.exist?(path) @console_report.generate_report From 2679663ccd4068bb091c45fdcd13dddccca96d22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20V=C3=A1squez?= Date: Mon, 17 Nov 2025 15:57:13 -0600 Subject: [PATCH 5/6] test: fix share report sharing output --- lib/skunk/commands/status_sharer.rb | 6 ++++- test/lib/skunk/application_test.rb | 35 ++++++++++++++++------------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/lib/skunk/commands/status_sharer.rb b/lib/skunk/commands/status_sharer.rb index f46971a..653e21b 100644 --- a/lib/skunk/commands/status_sharer.rb +++ b/lib/skunk/commands/status_sharer.rb @@ -73,7 +73,11 @@ def share_enabled? # @return [Boolean] Check if share URL is empty def share_url_empty? - ENV["SHARE_URL"].to_s == "" + share_url == "" + end + + def share_url + ENV["SHARE_URL"].to_s end def payload diff --git a/test/lib/skunk/application_test.rb b/test/lib/skunk/application_test.rb index 8055646..5e2cc3f 100644 --- a/test/lib/skunk/application_test.rb +++ b/test/lib/skunk/application_test.rb @@ -2,6 +2,7 @@ require "test_helper" require "skunk/cli/application" +require "skunk/commands/default" require "rubycritic/core/analysed_module" require "minitest/stub_const" @@ -46,14 +47,15 @@ end context "when passing an environment variable SHARE=true" do - let(:argv) { ["--out=tmp/shared_report.txt", "samples/rubycritic"] } + let(:argv) { ["--out=tmp", "samples/rubycritic"] } let(:success_code) { 0 } - let(:shared_message) do - "Shared at: https://skunk.fastruby.io/j" - end + let(:generated_message) { "Generated with Skunk" } + let(:shared_message) { "Shared at: https://skunk.fastruby.io/j" } + let(:share_url) { "https://skunk.fastruby.io" } + let(:report_path) { "tmp/skunk_report.txt" } around do |example| - stub_request(:post, "https://skunk.fastruby.io/reports").to_return( + stub_request(:post, "#{share_url}/reports").to_return( status: 200, body: '{"id":"j"}', headers: { "Content-Type" => "application/json" } @@ -62,20 +64,21 @@ end it "share report to default server" do - FileUtils.rm("tmp/shared_report.txt", force: true) + FileUtils.rm(report_path, force: true) FileUtils.mkdir_p("tmp") - RubyCritic::AnalysedModule.stub_any_instance(:churn, 1) do - RubyCritic::AnalysedModule.stub_any_instance(:coverage, 100.0) do - Skunk::Command::Default.stub_any_instance(:share_enabled?, true) do - Skunk::Command::StatusSharer.stub_any_instance(:not_sharing?, false) do - Skunk::Command::StatusSharer.stub_any_instance(:share, "Shared at: https://skunk.fastruby.io/j") do - result = application.execute - _(result).must_equal success_code - output = File.read("tmp/shared_report.txt") - _(output).must_include(shared_message) - end + Skunk::Command::Default.stub_any_instance(:share_enabled?, true) do + Skunk::Command::StatusSharer.stub_any_instance(:share_url, share_url) do + Skunk::Command::StatusSharer.stub_any_instance(:share, "Shared at: #{share_url}/j") do + stdout = capture_stdout do + result = application.execute + _(result).must_equal success_code end + _(File.exist?(report_path)).must_equal true + file_output = File.read(report_path) + + _(file_output).must_include(generated_message) + _(stdout).must_include(shared_message) end end end From 23da5f1f04cf1b2f1f2911e0238dc903d797472e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20V=C3=A1squez?= Date: Thu, 5 Feb 2026 23:27:39 -0600 Subject: [PATCH 6/6] qwerty --- lib/skunk/cli/application.rb | 8 ++------ lib/skunk/commands/status_sharer.rb | 6 +++--- lib/skunk/config.rb | 3 ++- samples/rubycritic/compare/skunk_report.txt | 1 + test/lib/skunk/cli/options/argv_test.rb | 17 +++++++++++++---- test/lib/skunk/config_test.rb | 9 ++++++++- test/lib/skunk/generators/html/overview_test.rb | 2 +- 7 files changed, 30 insertions(+), 16 deletions(-) create mode 100644 samples/rubycritic/compare/skunk_report.txt diff --git a/lib/skunk/cli/application.rb b/lib/skunk/cli/application.rb index 482178d..06df963 100644 --- a/lib/skunk/cli/application.rb +++ b/lib/skunk/cli/application.rb @@ -31,10 +31,10 @@ def execute command = Skunk::CommandFactory.create(@parsed_options) reporter = command.execute - print(reporter.status_message) + $stdout.puts(reporter.status_message) if command.sharing? share_status_message = command.share(reporter) - print(share_status_message) + $stdout.puts(share_status_message) end reporter.status @@ -49,10 +49,6 @@ def warn_coverage_info warn "warning: Couldn't find coverage info at #{COVERAGE_FILE}." warn "warning: Having no coverage metrics will make your SkunkScore worse." end - - def print(message) - $stdout.puts(message) - end end end end diff --git a/lib/skunk/commands/status_sharer.rb b/lib/skunk/commands/status_sharer.rb index 653e21b..6e87d05 100644 --- a/lib/skunk/commands/status_sharer.rb +++ b/lib/skunk/commands/status_sharer.rb @@ -35,7 +35,7 @@ def share # :reek:UtilityFunction def base_url - ENV["SHARE_URL"] || DEFAULT_URL + @base_url ||= ENV["SHARE_URL"] || DEFAULT_URL end def json_summary @@ -73,11 +73,11 @@ def share_enabled? # @return [Boolean] Check if share URL is empty def share_url_empty? - share_url == "" + share_url.empty? end def share_url - ENV["SHARE_URL"].to_s + @share_url ||= ENV["SHARE_URL"].to_s end def payload diff --git a/lib/skunk/config.rb b/lib/skunk/config.rb index aeec57b..1cfb060 100644 --- a/lib/skunk/config.rb +++ b/lib/skunk/config.rb @@ -55,7 +55,8 @@ def root end def root=(path) - @root = path.nil? || path.to_s.empty? ? nil : File.expand_path(path.to_s) + path_str = path.to_s + @root = path_str.empty? ? nil : File.expand_path(path_str) end # Add a format to the existing list diff --git a/samples/rubycritic/compare/skunk_report.txt b/samples/rubycritic/compare/skunk_report.txt new file mode 100644 index 0000000..0866893 --- /dev/null +++ b/samples/rubycritic/compare/skunk_report.txt @@ -0,0 +1 @@ +test output \ No newline at end of file diff --git a/test/lib/skunk/cli/options/argv_test.rb b/test/lib/skunk/cli/options/argv_test.rb index d26fb74..29dec0f 100644 --- a/test/lib/skunk/cli/options/argv_test.rb +++ b/test/lib/skunk/cli/options/argv_test.rb @@ -13,13 +13,22 @@ it "sets Skunk::Config.root to the provided path" do parser = Skunk::Cli::Options::Argv.new(["--out=tmp/custom"]) parser.parse - _(Skunk::Config.root).must_match(/tmp\/custom$/) + _(Skunk::Config.root).must_match(%r{tmp/custom$}) end it "defaults to tmp/rubycritic when not provided" do - parser = Skunk::Cli::Options::Argv.new([]) - parser.parse - _(Skunk::Config.root).must_match(/tmp\/rubycritic$/) + begin + prior_root = RubyCritic::Config.root + default_root = File.expand_path("tmp/rubycritic_default", Dir.pwd) + RubyCritic::Config.root = default_root + Skunk::Config.reset + parser = Skunk::Cli::Options::Argv.new([]) + parser.parse + _(Skunk::Config.root).must_equal default_root + ensure + RubyCritic::Config.root = prior_root || default_root + Skunk::Config.reset + end end end diff --git a/test/lib/skunk/config_test.rb b/test/lib/skunk/config_test.rb index 342cb34..b63401c 100644 --- a/test/lib/skunk/config_test.rb +++ b/test/lib/skunk/config_test.rb @@ -81,7 +81,14 @@ def test_reset end def test_default_root - assert_match(/tmp\/rubycritic$/, Config.root) + prior_root = RubyCritic::Config.root + default_root = File.expand_path("tmp/rubycritic_default", Dir.pwd) + RubyCritic::Config.root = default_root + Config.reset + assert_equal default_root, Config.root + ensure + RubyCritic::Config.root = prior_root || default_root + Config.reset end def test_set_root_expands_path diff --git a/test/lib/skunk/generators/html/overview_test.rb b/test/lib/skunk/generators/html/overview_test.rb index 5f5d018..05ecf5f 100644 --- a/test/lib/skunk/generators/html/overview_test.rb +++ b/test/lib/skunk/generators/html/overview_test.rb @@ -23,4 +23,4 @@ def test_root_directory_uses_skunk_config_root end end end -end \ No newline at end of file +end