From 9872e601e2e56010269c5595f17089fa79b13350 Mon Sep 17 00:00:00 2001 From: Matthew Hively Date: Tue, 8 Apr 2025 15:02:54 -0700 Subject: [PATCH 01/19] Ignore vim swp files & compiled "gem build" files & log dir --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 8fd4d35..4850be5 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ /.yardoc /_yardoc/ /coverage/ +/log/ /doc/ /pkg/ /spec/reports/ @@ -10,4 +11,6 @@ *.so *.o *.a +*.swp mkmf.log +bummr-*.gem From 698d777d1352ce8144d596cdfe47ec8a0fdd0387 Mon Sep 17 00:00:00 2001 From: Matthew Hively Date: Tue, 8 Apr 2025 15:30:56 -0700 Subject: [PATCH 02/19] Cleanup the bundled gem files Don't need anything related to testing circleci spec Rakefile Don't need meta build information .ruby-version gemspec file Gemfile Gemfile.lock Don't need gitignore either --- bummr.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bummr.gemspec b/bummr.gemspec index 6a4f685..c51c035 100644 --- a/bummr.gemspec +++ b/bummr.gemspec @@ -13,7 +13,7 @@ Gem::Specification.new do |spec| spec.homepage = "https://github.com/lpender/bummr" spec.license = "MIT" - spec.files = `git ls-files -z`.split("\x0") + spec.files = Dir["{lib,bin}/**/*"] + %w|LICENSE README.md| spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ["lib"] From 989f89f55239798a1f9c92d4045a371b032cb5d6 Mon Sep 17 00:00:00 2001 From: Matthew Hively Date: Tue, 8 Apr 2025 15:44:25 -0700 Subject: [PATCH 03/19] comments --- bummr.gemspec | 2 ++ lib/bummr/git.rb | 1 + 2 files changed, 3 insertions(+) diff --git a/bummr.gemspec b/bummr.gemspec index c51c035..08e4a30 100644 --- a/bummr.gemspec +++ b/bummr.gemspec @@ -18,7 +18,9 @@ Gem::Specification.new do |spec| spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ["lib"] + # Toolkit for building powerful command-line interfaces spec.add_dependency "thor" + # Colorize printed text on ANSI terminals spec.add_dependency "rainbow" spec.add_development_dependency "rspec" diff --git a/lib/bummr/git.rb b/lib/bummr/git.rb index de4a63b..3b13e20 100644 --- a/lib/bummr/git.rb +++ b/lib/bummr/git.rb @@ -20,6 +20,7 @@ def rebase_interactive(sha) system("git rebase -i #{BASE_BRANCH}") unless HEADLESS end + # print only the commit subject line def message(sha) `git log --pretty=format:'%s' -n 1 #{sha}` end From 4710cdbfd3ba64c8ba62a6a82976b7e41123e33e Mon Sep 17 00:00:00 2001 From: Matthew Hively Date: Wed, 9 Apr 2025 13:10:58 -0700 Subject: [PATCH 04/19] Readme now lists all ENV vars in one place --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 56de231..3dfff0e 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,12 @@ Update gemname from 0.0.1 to 0.0.2 - Once the build passes, you can push your branch and create a pull-request! - You may wish to `tail -f log/bummr.log` in a separate terminal window so you can see which commits are being removed. +- Environment variables that adjust bummr behavior + - BUMMR_TEST = your app's testing suite command (default: `bundle exec rake`) + - BASE_BRANCH = your repo's primary branch (default: `main`) + - BUMMR_HEADLESS = skip interactive rebase after all updates are complete (default: `false`) + - BUMMR_GIT_COMMIT = the shell git commit command to be used (default: `git commit`) + ## License From 1889dd6a2da892ed60b596fb05ee2ec8e4ba088e Mon Sep 17 00:00:00 2001 From: Matthew Hively Date: Thu, 10 Apr 2025 00:51:39 -0700 Subject: [PATCH 05/19] Fix non fatal errors during spec tests using an invalid sha "testsha" results in: fatal: ambiguous argument 'testsha': unknown revision or path not in the working tree. Use '--' to separate paths from revisions, like this: 'git [...] -- [...]' --- spec/lib/remover_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/lib/remover_spec.rb b/spec/lib/remover_spec.rb index 9209863..5d3b8b1 100644 --- a/spec/lib/remover_spec.rb +++ b/spec/lib/remover_spec.rb @@ -3,7 +3,7 @@ describe Bummr::Remover do let(:remover) { Bummr::Remover.instance } let(:git) { Bummr::Git.instance } - let(:sha) { "testsha" } + let(:sha) { "HEAD~1" } before do allow(remover).to receive(:log) From 42935c2272f83ac2c6a6c3a12ebc07baddc872e5 Mon Sep 17 00:00:00 2001 From: Matthew Hively Date: Thu, 10 Apr 2025 01:02:57 -0700 Subject: [PATCH 06/19] Bummr::Remover.instance.remove_commit returns message instead of puts Now it is the caller's responsibility to print or not the resulting message This cleans up some pointless output during spec testing --- lib/bummr/bisecter.rb | 2 +- lib/bummr/cli.rb | 2 +- lib/bummr/remover.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/bummr/bisecter.rb b/lib/bummr/bisecter.rb index 394ce8f..af8f129 100644 --- a/lib/bummr/bisecter.rb +++ b/lib/bummr/bisecter.rb @@ -20,7 +20,7 @@ def bisect end if line == "bisect run success\n" - Bummr::Remover.instance.remove_commit(sha) + puts Bummr::Remover.instance.remove_commit(sha) end end end diff --git a/lib/bummr/cli.rb b/lib/bummr/cli.rb index f4a564d..040020b 100644 --- a/lib/bummr/cli.rb +++ b/lib/bummr/cli.rb @@ -79,7 +79,7 @@ def bisect desc "remove_commit", "Remove a commit from the history" def remove_commit(sha) - Bummr::Remover.instance.remove_commit(sha) + puts Bummr::Remover.instance.remove_commit(sha) end private diff --git a/lib/bummr/remover.rb b/lib/bummr/remover.rb index d561c4b..dd16d00 100644 --- a/lib/bummr/remover.rb +++ b/lib/bummr/remover.rb @@ -20,7 +20,7 @@ def remove_commit(sha) " - Commit the changes.\n" + " - Run `bummr update` again.\n\n" - puts message.color(:yellow) + message.color(:yellow) end end end From 0837d75ffdfbde982f75e662140f4541c3d7afeb Mon Sep 17 00:00:00 2001 From: Matthew Hively Date: Thu, 10 Apr 2025 01:21:20 -0700 Subject: [PATCH 07/19] Display messages during spec testing showing which test-spec is running --- spec/black_box/bummr_update_spec.rb | 4 ++++ spec/check_spec.rb | 4 ++++ spec/lib/bisecter_spec.rb | 4 ++++ spec/lib/cli_spec.rb | 4 ++++ spec/lib/git_spec.rb | 4 ++++ spec/lib/log_spec.rb | 4 ++++ spec/lib/outdated_spec.rb | 4 ++++ spec/lib/prompt_spec.rb | 4 ++++ spec/lib/remover_spec.rb | 4 ++++ spec/lib/updater_spec.rb | 4 ++++ 10 files changed, 40 insertions(+) diff --git a/spec/black_box/bummr_update_spec.rb b/spec/black_box/bummr_update_spec.rb index 674c4ca..d18b161 100644 --- a/spec/black_box/bummr_update_spec.rb +++ b/spec/black_box/bummr_update_spec.rb @@ -2,6 +2,10 @@ require "jet_black" describe "bummr update command" do + before(:all) do + puts "\n<< black_box/bummr_update_spec >>\n" + end + let(:session) { JetBlack::Session.new(options: { clean_bundler_env: true }) } let(:bummr_gem_path) { File.expand_path("../../", __dir__) } diff --git a/spec/check_spec.rb b/spec/check_spec.rb index 2706f4f..345d8a9 100644 --- a/spec/check_spec.rb +++ b/spec/check_spec.rb @@ -1,6 +1,10 @@ require 'spec_helper' describe Bummr::Check do + before(:all) do + puts "\n<< Bummr::Check >>\n" + end + let(:check) { Bummr::Check.instance } before(:each) do diff --git a/spec/lib/bisecter_spec.rb b/spec/lib/bisecter_spec.rb index 2cdcb5d..7289631 100644 --- a/spec/lib/bisecter_spec.rb +++ b/spec/lib/bisecter_spec.rb @@ -1,6 +1,10 @@ require 'spec_helper' describe Bummr::Bisecter do + before(:all) do + puts "\n<< Bummr::Bisecter >>\n" + end + let(:std_out_err_bad_commit) { output = String.new output += "mybadcommit is the first bad commit\n" diff --git a/spec/lib/cli_spec.rb b/spec/lib/cli_spec.rb index 2944564..acbb986 100644 --- a/spec/lib/cli_spec.rb +++ b/spec/lib/cli_spec.rb @@ -1,6 +1,10 @@ require 'spec_helper' describe Bummr::CLI do + before(:all) do + puts "\n<< Bummr::CLI >>\n" + end + # https://github.com/wireframe/gitx/blob/171da367072b0e82d5906d1e5b3f8ff38e5774e7/spec/thegarage/gitx/cli/release_command_spec.rb#L9 let(:args) { [] } let(:options) { {} } diff --git a/spec/lib/git_spec.rb b/spec/lib/git_spec.rb index 321c8d1..a6b795d 100644 --- a/spec/lib/git_spec.rb +++ b/spec/lib/git_spec.rb @@ -1,6 +1,10 @@ require "spec_helper" describe Bummr::Git do + before(:all) do + puts "\n<< Bummr::Git >>\n" + end + describe "#add" do it "stages specified files with git" do git = stub_git diff --git a/spec/lib/log_spec.rb b/spec/lib/log_spec.rb index 2087dd8..8103bc4 100644 --- a/spec/lib/log_spec.rb +++ b/spec/lib/log_spec.rb @@ -1,6 +1,10 @@ require "spec_helper" describe Bummr::Log do + before(:all) do + puts "\n<< Bummr::Log >>\n" + end + let(:object) { Object.new } let(:message) { "test message" } diff --git a/spec/lib/outdated_spec.rb b/spec/lib/outdated_spec.rb index c25abf8..072e52f 100644 --- a/spec/lib/outdated_spec.rb +++ b/spec/lib/outdated_spec.rb @@ -1,6 +1,10 @@ require 'spec_helper' describe Bummr::Outdated do + before(:all) do + puts "\n<< Bummr::Outdated >>\n" + end + # https://github.com/wireframe/gitx/blob/8e3cdc8b5d0c2082ed3daaf2fc054654b2e7a6c8/spec/gitx/executor_spec.rb#L9 let(:stdoutput_legacy) { output = String.new diff --git a/spec/lib/prompt_spec.rb b/spec/lib/prompt_spec.rb index f3fcaf7..6cca1e6 100644 --- a/spec/lib/prompt_spec.rb +++ b/spec/lib/prompt_spec.rb @@ -1,6 +1,10 @@ require "spec_helper" describe Bummr::Prompt do + before(:all) do + puts "\n<< Bummr::Prompt >>\n" + end + let(:parent_class) do Class.new do def yes?(message) diff --git a/spec/lib/remover_spec.rb b/spec/lib/remover_spec.rb index 5d3b8b1..443fb34 100644 --- a/spec/lib/remover_spec.rb +++ b/spec/lib/remover_spec.rb @@ -1,6 +1,10 @@ require "spec_helper" describe Bummr::Remover do + before(:all) do + puts "\n<< Bummr::Remover >>\n" + end + let(:remover) { Bummr::Remover.instance } let(:git) { Bummr::Git.instance } let(:sha) { "HEAD~1" } diff --git a/spec/lib/updater_spec.rb b/spec/lib/updater_spec.rb index e0482f6..113a6e2 100644 --- a/spec/lib/updater_spec.rb +++ b/spec/lib/updater_spec.rb @@ -1,6 +1,10 @@ require "spec_helper" describe Bummr::Updater do + before(:all) do + puts "\n<< Bummr::Updater >>\n" + end + let(:outdated_gems) { [ { name: "myGem", installed: "0.3.2", newest: "0.3.5" }, From cc1c401764782d435ee85118ee4642716e26bac8 Mon Sep 17 00:00:00 2001 From: Matthew Hively Date: Thu, 10 Apr 2025 11:32:39 -0700 Subject: [PATCH 08/19] Use %x{} instead of backticks (`) Also puts statements should use regular ' instead of backticks ` --- lib/bummr/check.rb | 10 +++++----- lib/bummr/cli.rb | 4 ++-- lib/bummr/git.rb | 2 +- lib/bummr/outdated.rb | 2 +- lib/bummr/remover.rb | 6 +++--- lib/bummr/updater.rb | 2 +- spec/check_spec.rb | 6 +++--- spec/lib/log_spec.rb | 6 +++--- 8 files changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/bummr/check.rb b/lib/bummr/check.rb index 74ce1f7..c37030d 100644 --- a/lib/bummr/check.rb +++ b/lib/bummr/check.rb @@ -27,7 +27,7 @@ def check(fullcheck=true) private def check_base_branch - if `git rev-parse --abbrev-ref HEAD` == "#{BASE_BRANCH}\n" + if %x{git rev-parse --abbrev-ref HEAD} == "#{BASE_BRANCH}\n" message = "Bummr is not meant to be run on your base branch" puts message.color(:red) puts "Please checkout a branch with 'git checkout -b update-gems'" @@ -44,7 +44,7 @@ def check_log end def check_status - status = `git status` + status = %x{git status} if status.index 'are currently' message = "" @@ -55,15 +55,15 @@ def check_status message += "You are already bisecting. " end - message += "Make sure `git status` is clean" + message += "Make sure 'git status' is clean" puts message.color(:red) @errors.push message end end def check_diff - unless `git diff #{BASE_BRANCH}`.empty? - message = "Please make sure that `git diff #{BASE_BRANCH}` returns empty" + unless %x{git diff #{BASE_BRANCH}}.empty? + message = "Please make sure that 'git diff #{BASE_BRANCH}' returns empty" puts message.color(:red) @errors.push message end diff --git a/lib/bummr/cli.rb b/lib/bummr/cli.rb index 040020b..8fc02df 100644 --- a/lib/bummr/cli.rb +++ b/lib/bummr/cli.rb @@ -92,7 +92,7 @@ def display_info puts "- Have a 'log' directory, where we can place logs" puts "- Have your build configured to fail fast (recommended)" puts "- Have locked any Gem version that you don't wish to update in your Gemfile" - puts "- It is recommended that you lock your versions of `ruby` and `rails` in your `Gemfile`" + puts "- It is recommended that you lock your versions of 'ruby' and 'rails' in your 'Gemfile'" puts "\n" puts "Your test command is: " + "'#{TEST_COMMAND}'".color(:yellow) puts "\n" @@ -106,7 +106,7 @@ def print_received_options puts "--#{key.color(:yellow)}: #{value}" end - puts "\nRun `#{"bummr help update".color(:yellow)}` for more information.\n\n" + puts "\nRun '#{"bummr help update".color(:yellow)}' for more information.\n\n" end end end diff --git a/lib/bummr/git.rb b/lib/bummr/git.rb index 3b13e20..6a832e8 100644 --- a/lib/bummr/git.rb +++ b/lib/bummr/git.rb @@ -22,7 +22,7 @@ def rebase_interactive(sha) # print only the commit subject line def message(sha) - `git log --pretty=format:'%s' -n 1 #{sha}` + %x{git log --pretty=format:'%s' -n 1 #{sha}} end private diff --git a/lib/bummr/outdated.rb b/lib/bummr/outdated.rb index 11e02ba..1a47b60 100644 --- a/lib/bummr/outdated.rb +++ b/lib/bummr/outdated.rb @@ -44,7 +44,7 @@ def gemfile_contains(gem_name) end def gemfile - @gemfile ||= `cat Gemfile` + @gemfile ||= %x{cat Gemfile} end end end diff --git a/lib/bummr/remover.rb b/lib/bummr/remover.rb index dd16d00..7a2d0cb 100644 --- a/lib/bummr/remover.rb +++ b/lib/bummr/remover.rb @@ -10,15 +10,15 @@ def remove_commit(sha) log "Resetting..." system("git bisect reset") - message = "\nThe commit:\n\n `#{sha} #{git.message(sha)}`\n\n" + + message = "\nThe commit:\n\n '#{sha} #{git.message(sha)}'\n\n" + "Is breaking the build.\n\n" + "Please do one of the following: \n\n" + " 1. Update your code to work with the latest version of this gem.\n\n" + " 2. Perform the following steps to lock the gem version:\n\n" + - " - `git reset --hard main`\n" + + " - 'git reset --hard main'\n" + " - Lock the version of this Gem in your Gemfile.\n" + " - Commit the changes.\n" + - " - Run `bummr update` again.\n\n" + " - Run 'bummr update' again.\n\n" message.color(:yellow) end diff --git a/lib/bummr/updater.rb b/lib/bummr/updater.rb index 174418e..17bb728 100644 --- a/lib/bummr/updater.rb +++ b/lib/bummr/updater.rb @@ -43,7 +43,7 @@ def update_gem(gem, index) end def updated_version_for(gem) - string = `bundle list --paths | grep "#{gem[:name]}"` + string = %x{bundle list --paths | grep "#{gem[:name]}"} string.match(/#{gem[:name]}-(.*)$/)[1] end end diff --git a/spec/check_spec.rb b/spec/check_spec.rb index 345d8a9..4b209cc 100644 --- a/spec/check_spec.rb +++ b/spec/check_spec.rb @@ -85,7 +85,7 @@ check.check expect(check).to have_received(:puts) - .with("You are already bisecting. Make sure `git status` is clean".color(:red)) + .with("You are already bisecting. Make sure 'git status' is clean".color(:red)) expect(check).to have_received(:yes?) expect(check).to have_received(:exit).with(0) end @@ -102,7 +102,7 @@ check.check expect(check).to have_received(:puts) - .with("You are already rebasing. Make sure `git status` is clean".color(:red)) + .with("You are already rebasing. Make sure 'git status' is clean".color(:red)) expect(check).to have_received(:yes?) expect(check).to have_received(:exit).with(0) end @@ -120,7 +120,7 @@ check.check(true) expect(check).to have_received(:puts) - .with("Please make sure that `git diff main` returns empty".color(:red)) + .with("Please make sure that 'git diff main' returns empty".color(:red)) expect(check).to have_received(:yes?) expect(check).to have_received(:exit).with(0) end diff --git a/spec/lib/log_spec.rb b/spec/lib/log_spec.rb index 8103bc4..a53aa8e 100644 --- a/spec/lib/log_spec.rb +++ b/spec/lib/log_spec.rb @@ -9,12 +9,12 @@ let(:message) { "test message" } before do - `mkdir -p log` + %x{mkdir -p log} object.extend(Bummr::Log) end after do - `rm log/bummr.log` + %x{rm log/bummr.log} end describe "#log" do @@ -29,7 +29,7 @@ it "outputs the message to log/bummr.log" do object.log message - result = `cat log/bummr.log` + result = %x{cat log/bummr.log} expect(result).to eq message + "\n" end From f1296a097b9bdd5b74ccbbc8f27e0c9e2e0c81a6 Mon Sep 17 00:00:00 2001 From: Matthew Hively Date: Thu, 10 Apr 2025 12:41:09 -0700 Subject: [PATCH 09/19] Stub out "display_info" when testing ABORTING bummr update --- spec/lib/cli_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/lib/cli_spec.rb b/spec/lib/cli_spec.rb index acbb986..497cb13 100644 --- a/spec/lib/cli_spec.rb +++ b/spec/lib/cli_spec.rb @@ -22,6 +22,7 @@ describe "#update" do context "when user rejects moving forward" do it "does not attempt to move forward" do + expect(cli).to receive(:display_info) # NOOP this function call expect(cli).to receive(:yes?).and_return(false) expect(cli).not_to receive(:check) From 80bef0567b3c780385b93ccab9d0017656fa1f9e Mon Sep 17 00:00:00 2001 From: Matthew Hively Date: Thu, 10 Apr 2025 12:49:23 -0700 Subject: [PATCH 10/19] Fix indentation --- spec/lib/outdated_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/lib/outdated_spec.rb b/spec/lib/outdated_spec.rb index 072e52f..286b472 100644 --- a/spec/lib/outdated_spec.rb +++ b/spec/lib/outdated_spec.rb @@ -32,8 +32,8 @@ describe "#outdated_gems" do { bundler2: :stdoutput, bundler1: :stdoutput_legacy }.each_pair do |version, output| - it "Correctly identifies outdated gems with bundler #{version}" do - allow(Open3).to receive(:popen2).and_yield(nil, public_send(output)) + it "Correctly identifies outdated gems with bundler #{version}" do + allow(Open3).to receive(:popen2).and_yield(nil, public_send(output)) allow_any_instance_of(described_class).to receive(:gemfile).and_return gemfile instance = Bummr::Outdated.instance From 8ffd8219de29a2b273f455dd658fb061f5eac8f7 Mon Sep 17 00:00:00 2001 From: Matthew Hively Date: Thu, 10 Apr 2025 13:35:14 -0700 Subject: [PATCH 11/19] Stub out "puts" when testing outdated_gems --- lib/bummr/outdated.rb | 2 +- spec/lib/outdated_spec.rb | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/bummr/outdated.rb b/lib/bummr/outdated.rb index 1a47b60..747cca8 100644 --- a/lib/bummr/outdated.rb +++ b/lib/bummr/outdated.rb @@ -17,7 +17,7 @@ def outdated_gems(options = {}) Open3.popen2("bundle outdated" + bundle_options) do |_std_in, std_out| while line = std_out.gets - puts line + puts line # TODO: remove this if possible (pointless for spec tests) gem = parse_gem_from(line) if gem && (options[:all_gems] || gemfile_contains(gem[:name])) diff --git a/spec/lib/outdated_spec.rb b/spec/lib/outdated_spec.rb index 286b472..bc6673b 100644 --- a/spec/lib/outdated_spec.rb +++ b/spec/lib/outdated_spec.rb @@ -31,10 +31,15 @@ } describe "#outdated_gems" do + def mock_gemfile + allow_any_instance_of(described_class).to receive(:gemfile).and_return gemfile + allow_any_instance_of(described_class).to receive(:puts) # NOOP this function call + end + { bundler2: :stdoutput, bundler1: :stdoutput_legacy }.each_pair do |version, output| it "Correctly identifies outdated gems with bundler #{version}" do allow(Open3).to receive(:popen2).and_yield(nil, public_send(output)) - allow_any_instance_of(described_class).to receive(:gemfile).and_return gemfile + mock_gemfile instance = Bummr::Outdated.instance result = instance.outdated_gems @@ -61,7 +66,7 @@ it "lists all outdated dependencies by omitting the strict option" do allow(Open3).to receive(:popen2).with("bundle outdated --parseable").and_yield(nil, stdoutput) - allow(Bummr::Outdated.instance).to receive(:gemfile).and_return gemfile + mock_gemfile results = Bummr::Outdated.instance.outdated_gems(all_gems: true) gem_names = results.map { |result| result[:name] } @@ -72,7 +77,7 @@ it "defaults to false" do expect(Open3).to receive(:popen2).with("bundle outdated --parseable --strict").and_yield(nil, stdoutput) - allow(Bummr::Outdated.instance).to receive(:gemfile).and_return gemfile + mock_gemfile results = Bummr::Outdated.instance.outdated_gems gem_names = results.map { |result| result[:name] } @@ -93,7 +98,7 @@ .with("bundle outdated --parseable --strict --group development") .and_yield(nil, stdoutput_from_development_group) - allow(Bummr::Outdated.instance).to receive(:gemfile).and_return gemfile + mock_gemfile results = Bummr::Outdated.instance.outdated_gems(group: :development) gem_names = results.map { |result| result[:name] } @@ -106,7 +111,7 @@ .with("bundle outdated --parseable --strict") .and_yield(nil, stdoutput) - allow(Bummr::Outdated.instance).to receive(:gemfile).and_return gemfile + mock_gemfile results = Bummr::Outdated.instance.outdated_gems gem_names = results.map { |result| result[:name] } @@ -127,7 +132,7 @@ .with("bundle outdated --parseable --strict spring") .and_yield(nil, stdoutput_from_spring_gem) - allow(Bummr::Outdated.instance).to receive(:gemfile).and_return gemfile + mock_gemfile results = Bummr::Outdated.instance.outdated_gems(gem: :spring) gem_names = results.map { |result| result[:name] } @@ -135,7 +140,7 @@ expect(gem_names).to match_array ['spring'] end end - end + end # end #outdated_gems describe "#parse_gem_from" do it 'line' do From c79542c64fc2840b1b7a66b02bdeaf5810dc2238 Mon Sep 17 00:00:00 2001 From: Matthew Hively Date: Thu, 10 Apr 2025 13:35:32 -0700 Subject: [PATCH 12/19] Stub out "puts" when testing writing to log/bummr.log --- spec/lib/log_spec.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/lib/log_spec.rb b/spec/lib/log_spec.rb index a53aa8e..7177421 100644 --- a/spec/lib/log_spec.rb +++ b/spec/lib/log_spec.rb @@ -27,6 +27,8 @@ end it "outputs the message to log/bummr.log" do + allow(object).to receive(:puts) # NOOP this function call + object.log message result = %x{cat log/bummr.log} From 52769a51148308eb4b5a80e1518663c7acc0cff4 Mon Sep 17 00:00:00 2001 From: Matthew Hively Date: Thu, 10 Apr 2025 13:58:45 -0700 Subject: [PATCH 13/19] Stub out "puts" when testing updater --- spec/lib/updater_spec.rb | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/spec/lib/updater_spec.rb b/spec/lib/updater_spec.rb index 113a6e2..10402be 100644 --- a/spec/lib/updater_spec.rb +++ b/spec/lib/updater_spec.rb @@ -23,6 +23,7 @@ describe "#update_gems" do it "calls update_gem on each gem" do allow(updater).to receive(:update_gem) + allow(updater).to receive(:puts) # NOOP this function call updater.update_gems @@ -33,11 +34,16 @@ end describe "#update_gem" do + def mock_log_commit_puts + allow(updater).to receive(:log) + allow(updater).to receive(:puts) # NOOP this function call + allow(git).to receive(:commit) + end + it "attempts to update the gem" do allow(updater).to receive(:system).with(update_cmd) allow(updater).to receive(:updated_version_for).with(gem).and_return installed - allow(updater).to receive(:log) - allow(git).to receive(:commit) + mock_log_commit_puts updater.update_gem(gem, 0) end @@ -46,8 +52,7 @@ it "logs that it's not updated to the latest" do allow(updater).to receive(:system).with(update_cmd) allow(updater).to receive(:updated_version_for).with(gem).and_return installed - allow(updater).to receive(:log) - allow(git).to receive(:commit) + mock_log_commit_puts updater.update_gem(gem, 0) @@ -57,8 +62,7 @@ it "doesn't commit anything" do allow(updater).to receive(:system).with(update_cmd) allow(updater).to receive(:updated_version_for).with(gem).and_return installed - allow(updater).to receive(:log) - allow(git).to receive(:commit) + mock_log_commit_puts updater.update_gem(gem, 0) @@ -77,8 +81,7 @@ not_latest_message = "#{gem[:name]} not updated from #{gem[:installed]} to latest: #{gem[:newest]}" allow(updater).to receive(:system) - allow(updater).to receive(:log) - allow(git).to receive(:commit) + mock_log_commit_puts updater.update_gem(gem, 0) @@ -89,9 +92,8 @@ commit_message = "Update #{gem[:name]} from #{gem[:installed]} to #{intermediate_version}" allow(updater).to receive(:system) - allow(updater).to receive(:log) allow(git).to receive(:add) - allow(git).to receive(:commit) + mock_log_commit_puts updater.update_gem(gem, 0) @@ -111,9 +113,8 @@ commit_message = "Update #{gem[:name]} from #{gem[:installed]} to #{gem[:newest]}" allow(updater).to receive(:system) - allow(updater).to receive(:log) allow(git).to receive(:add) - allow(git).to receive(:commit) + mock_log_commit_puts updater.update_gem(gem, 0) @@ -123,7 +124,7 @@ expect(git).to have_received(:commit).with(commit_message) end end - end + end # end #update_gem describe "#updated_version_for" do it "returns the correct version from bundle list" do From aee89c98f646a4ef5beef8e36330b5d4f2c24307 Mon Sep 17 00:00:00 2001 From: Matthew Hively Date: Thu, 10 Apr 2025 14:21:30 -0700 Subject: [PATCH 14/19] Ensure "vendor/cache" folder exists Resolves "fatal: pathspec 'vendor/cache' did not match any files" --- spec/lib/updater_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/spec/lib/updater_spec.rb b/spec/lib/updater_spec.rb index 10402be..0fd7359 100644 --- a/spec/lib/updater_spec.rb +++ b/spec/lib/updater_spec.rb @@ -34,6 +34,14 @@ end describe "#update_gem" do + # Ensure this directory exists to be added + before do + %x{mkdir -p vendor/cache} + end + after do + %x{rm -rf vendor/cache} + end + def mock_log_commit_puts allow(updater).to receive(:log) allow(updater).to receive(:puts) # NOOP this function call @@ -91,6 +99,7 @@ def mock_log_commit_puts it "commits" do commit_message = "Update #{gem[:name]} from #{gem[:installed]} to #{intermediate_version}" + allow(updater).to receive(:system) allow(git).to receive(:add) mock_log_commit_puts @@ -112,6 +121,7 @@ def mock_log_commit_puts it "commits" do commit_message = "Update #{gem[:name]} from #{gem[:installed]} to #{gem[:newest]}" + allow(updater).to receive(:system) allow(git).to receive(:add) mock_log_commit_puts From 1decadf4a710ab08975e1256507d743d4c1769f2 Mon Sep 17 00:00:00 2001 From: Matthew Hively Date: Thu, 10 Apr 2025 14:47:09 -0700 Subject: [PATCH 15/19] Exclude user CLI informational printouts from coverage tests --- lib/bummr/cli.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/bummr/cli.rb b/lib/bummr/cli.rb index 8fc02df..eb21858 100644 --- a/lib/bummr/cli.rb +++ b/lib/bummr/cli.rb @@ -84,6 +84,7 @@ def remove_commit(sha) private + # :nocov: def display_info puts "Bummr #{VERSION}" puts "To run Bummr, you must:" @@ -108,5 +109,6 @@ def print_received_options puts "\nRun '#{"bummr help update".color(:yellow)}' for more information.\n\n" end + # :nocov: end end end From d7fff3b6852f3aecf6c8287c1e821ceacc64d8fe Mon Sep 17 00:00:00 2001 From: Matthew Hively Date: Thu, 10 Apr 2025 23:42:09 -0700 Subject: [PATCH 16/19] Ignore macos DS_Store thumbnails --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 4850be5..18700ab 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ *.swp mkmf.log bummr-*.gem +.DS_Store From 1508b25bb172cf7854bd29c7642c8daf8bad23c8 Mon Sep 17 00:00:00 2001 From: Matthew Hively Date: Fri, 11 Apr 2025 11:36:07 -0700 Subject: [PATCH 17/19] Reconfigure Coverage report - Write the report into `/coverage/` - Exclude all spec files from coverage --- spec/spec_helper.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4035681..2f4c177 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,11 @@ require "simplecov" -SimpleCov.start +SimpleCov.start do + # Exclude spec files from coverage + add_filter '/spec/' + + git_branch_name = %x{git rev-parse --abbrev-ref HEAD}.strip + SimpleCov.coverage_dir("coverage/#{git_branch_name}") +end require 'pry' require 'bummr' From 3d10117f4732f24ab0d9e8fba5465aaf45618cb2 Mon Sep 17 00:00:00 2001 From: Matthew Hively Date: Mon, 14 Apr 2025 12:01:47 -0700 Subject: [PATCH 18/19] Exclude some more sections from coverage reporting Include explanations why they are excluded --- lib/bummr/cli.rb | 6 +++++- lib/bummr/outdated.rb | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/bummr/cli.rb b/lib/bummr/cli.rb index eb21858..a444fc2 100644 --- a/lib/bummr/cli.rb +++ b/lib/bummr/cli.rb @@ -8,10 +8,12 @@ class CLI < Thor include Bummr::Prompt include Bummr::Scm + # :nocov: internals are tested by spec/check_spec.rb desc "check", "Run automated checks to see if bummr can be run" def check(fullcheck=true) Bummr::Check.instance.check(fullcheck) end + # :nocov: end desc "update", "Update outdated gems, run tests, bisect if tests fail\n\n" + @@ -77,14 +79,16 @@ def bisect end end + # :nocov: internals are tested by spec/lib/remover_spec.rb desc "remove_commit", "Remove a commit from the history" def remove_commit(sha) puts Bummr::Remover.instance.remove_commit(sha) end + # :nocov: end private - # :nocov: + # :nocov: This is stubbed out during actual testing because its boilerplate information for the user def display_info puts "Bummr #{VERSION}" puts "To run Bummr, you must:" diff --git a/lib/bummr/outdated.rb b/lib/bummr/outdated.rb index 747cca8..46d14e1 100644 --- a/lib/bummr/outdated.rb +++ b/lib/bummr/outdated.rb @@ -43,8 +43,11 @@ def gemfile_contains(gem_name) /gem ['"]#{gem_name}['"]/.match gemfile end + # :nocov: no need to test whether linux "cat Gemfile" works def gemfile @gemfile ||= %x{cat Gemfile} end + # :nocov: end + end end From f3c9af90652ecf9d705a7a0fb9deb727c34f798e Mon Sep 17 00:00:00 2001 From: Matthew Hively Date: Tue, 8 Apr 2025 15:14:59 -0700 Subject: [PATCH 19/19] Update bummr version --- Gemfile.lock | 2 +- lib/bummr/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 60eea95..79d897c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - bummr (1.1.0) + bummr (1.1.1a) rainbow thor diff --git a/lib/bummr/version.rb b/lib/bummr/version.rb index 8c79693..20eccd7 100644 --- a/lib/bummr/version.rb +++ b/lib/bummr/version.rb @@ -1,3 +1,3 @@ module Bummr - VERSION = "1.1.0" + VERSION = "1.1.1a" end