diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8bffc6c..ef57021 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,11 +2,12 @@ name: CI on: [push, pull_request] jobs: test: - runs-on: ubuntu-18.04 + runs-on: ubuntu-latest continue-on-error: ${{ matrix.flaky }} strategy: matrix: - ruby-version: ["2.5", "2.6", "2.7", "3.0", "3.1", "jruby-9.2", "jruby-9.3", "truffleruby-21" ,"truffleruby-22"] + ruby-version: + ["3.0", "3.1", "3.2", "3.3", "jruby-9.4", "truffleruby-23"] flaky: [false] include: - ruby-version: "ruby-head" @@ -16,7 +17,7 @@ jobs: - ruby-version: "truffleruby-head" flaky: true steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v4 - name: Set up Ruby ${{ matrix.ruby-version }} uses: ruby/setup-ruby@v1 diff --git a/gemdiff.gemspec b/gemdiff.gemspec index 33fb027..7aefe0c 100644 --- a/gemdiff.gemspec +++ b/gemdiff.gemspec @@ -6,7 +6,7 @@ Gem::Specification.new do |spec| spec.name = "gemdiff" spec.version = Gemdiff::VERSION spec.authors = ["Tee Parham"] - spec.email = ["tee@neighborland.com"] + spec.email = ["parhameter@gmail.com"] spec.summary = "Find source repositories for ruby gems. Open, compare, and update outdated gem versions" spec.description = "Command-line utility to find source repositories for ruby gems, open common GitHub pages, "\ "compare gem versions, and simplify gem update workflow in git." @@ -17,13 +17,13 @@ Gem::Specification.new do |spec| spec.executables = %w[gemdiff] spec.require_paths = %w[lib] - spec.required_ruby_version = ">= 2.5.0" + spec.required_ruby_version = ">= 3.0.0" spec.add_dependency "launchy", "~> 2.4" spec.add_dependency "octokit", "~> 4.0" spec.add_dependency "thor", "~> 1.0" - spec.add_development_dependency "minitest", "~> 5.4" - spec.add_development_dependency "mocha", "~> 1.1" + spec.add_development_dependency "minitest", "~> 5.21" + spec.add_development_dependency "mocha", "~> 2.0" spec.add_development_dependency "rake", "~> 13.0" end diff --git a/test/bundle_inspector_test.rb b/test/bundle_inspector_test.rb index 55318fe..89db89e 100644 --- a/test/bundle_inspector_test.rb +++ b/test/bundle_inspector_test.rb @@ -2,61 +2,61 @@ require "test_helper" -class BundleInspectorTest < MiniTest::Spec - let(:inspector) { Gemdiff::BundleInspector.new } - - describe "#list" do - it "returns outdated gems" do - inspector.stubs bundle_outdated_strict: fake_outdated_parseable - inspector.list.tap do |list| - assert_equal 3, list.size - assert_equal "paperclip", list[0].name - assert_equal "4.2.2", list[0].old_version - assert_equal "4.3.0", list[0].new_version - assert_equal "rails", list[1].name - assert_equal "4.2.1", list[1].old_version - assert_equal "4.2.2", list[1].new_version - assert_equal "web-console", list[2].name - assert_equal "2.1.2", list[2].old_version - assert_equal "2.1.3", list[2].new_version - end - end +def inspector + @inspector ||= Gemdiff::BundleInspector.new +end - it "returns empty list when bundle is up to date" do - inspector.stubs bundle_outdated_strict: fake_up_to_date - assert_empty inspector.list +describe "#list" do + it "returns outdated gems" do + inspector.stubs bundle_outdated_strict: fake_outdated_parseable + inspector.list.tap do |list| + assert_equal 3, list.size + assert_equal "paperclip", list[0].name + assert_equal "4.2.2", list[0].old_version + assert_equal "4.3.0", list[0].new_version + assert_equal "rails", list[1].name + assert_equal "4.2.1", list[1].old_version + assert_equal "4.2.2", list[1].new_version + assert_equal "web-console", list[2].name + assert_equal "2.1.2", list[2].old_version + assert_equal "2.1.3", list[2].new_version end end - describe "#get" do - it "returns single outdated gem" do - inspector.stubs bundle_outdated_strict: fake_outdated_parseable - inspector.get("rails").tap do |gem| - assert_equal "rails", gem.name - assert_equal "4.2.1", gem.old_version - assert_equal "4.2.2", gem.new_version - end - end + it "returns empty list when bundle is up to date" do + inspector.stubs bundle_outdated_strict: fake_up_to_date + assert_empty inspector.list + end +end - it "returns nil when gem is not outdated" do - inspector.stubs bundle_outdated_strict: fake_up_to_date - assert_nil inspector.get("notfound") +describe "#get" do + it "returns single outdated gem" do + inspector.stubs bundle_outdated_strict: fake_outdated_parseable + inspector.get("rails").tap do |gem| + assert_equal "rails", gem.name + assert_equal "4.2.1", gem.old_version + assert_equal "4.2.2", gem.new_version end end - private - - def fake_outdated_parseable - <<~OUT - paperclip (newest 4.3.0, installed 4.2.2) - rails (newest 4.2.2, installed 4.2.1, requested ~> 4.2.1) - web-console (newest 2.1.3, installed 2.1.2) - OUT + it "returns nil when gem is not outdated" do + inspector.stubs bundle_outdated_strict: fake_up_to_date + assert_nil inspector.get("notfound") end +end - def fake_up_to_date - <<~OUT +private - OUT - end +def fake_outdated_parseable + <<~OUT + paperclip (newest 4.3.0, installed 4.2.2) + rails (newest 4.2.2, installed 4.2.1, requested ~> 4.2.1) + web-console (newest 2.1.3, installed 2.1.2) + OUT +end + +def fake_up_to_date + <<~OUT + + OUT end diff --git a/test/cli_test.rb b/test/cli_test.rb index 7e5ea0f..c515e22 100644 --- a/test/cli_test.rb +++ b/test/cli_test.rb @@ -2,200 +2,200 @@ require "test_helper" -class CLITest < MiniTest::Spec - let(:cli) { Gemdiff::CLI.new } - - describe "#find" do - it "finds" do - mock_gem "haml" - cli.expects(:puts).with("http://github.com/haml/haml") - cli.find "haml" - end - - it "does not find" do - mock_missing_gem - cli.expects(:puts).with("Could not find github repository for notfound.") - cli.find "notfound" - end - end - - describe "#open" do - it "opens repo" do - outdated_gem = mock_gem("haml") - cli.expects(:puts).with("http://github.com/haml/haml") - outdated_gem.expects :open - cli.open "haml" - end - end - - describe "#releases" do - it "opens releases page" do - outdated_gem = mock_gem("haml") - cli.expects(:puts).with("http://github.com/haml/haml") - outdated_gem.expects :releases - cli.releases "haml" - end - end - - describe "#main" do - it "opens commits page" do - outdated_gem = mock_gem("haml") - cli.expects(:puts).with("http://github.com/haml/haml") - outdated_gem.expects :main - cli.main "haml" - end - end - - describe "#compare" do - it "opens compare view using bundle" do - outdated_gem = mock_gem("haml") - cli.expects(:puts).with("http://github.com/haml/haml") - outdated_gem.expects(:set_versions).with(nil, nil) - outdated_gem.expects(:missing_versions?).returns(true) - cli.expects(:puts).with(Gemdiff::CLI::CHECKING_FOR_OUTDATED) - outdated_gem.expects(:load_bundle_versions).returns(true) - outdated_gem.expects(:compare_message).returns("compare message") - cli.expects(:puts).with("compare message") - outdated_gem.expects :compare - cli.compare "haml" - end - - it "opens compare view with versions" do - outdated_gem = mock_gem("haml") - cli.expects(:puts).with("http://github.com/haml/haml") - outdated_gem.expects(:set_versions).with("4.0.4", "4.0.5") - outdated_gem.expects(:missing_versions?).returns(false) - outdated_gem.expects(:compare_message).returns("compare message") - cli.expects(:puts).with("compare message") - outdated_gem.expects :compare - cli.compare "haml", "4.0.4", "4.0.5" - end - - it "returns when the gem is not found" do - mock_missing_gem - cli.expects(:puts).with("Could not find github repository for notfound.") - cli.compare "notfound" - end - end - - describe "#each" do - it "does nothing when nothing to update" do - mock_inspector = stub list: [], outdated: "" - Gemdiff::BundleInspector.stubs new: mock_inspector - cli.expects(:puts).with(Gemdiff::CLI::CHECKING_FOR_OUTDATED) - cli.expects(:puts).with("") - cli.each - end - - it "compares outdated gems with responses of y" do - outdated_gem = Gemdiff::OutdatedGem.new("haml", "4.0.4", "4.0.5") - mock_inspector = stub list: [outdated_gem], outdated: "outdated" - Gemdiff::BundleInspector.stubs new: mock_inspector - cli.stubs ask: "y" - cli.expects(:puts).with(Gemdiff::CLI::CHECKING_FOR_OUTDATED) - cli.expects(:puts).with("outdated") - cli.expects(:puts).with("haml: 4.0.5 > 4.0.4") - outdated_gem.expects :compare - cli.each - end - - it "show compare urls of outdated gems with responses of s" do - outdated_gem = Gemdiff::OutdatedGem.new("haml", "4.0.4", "4.0.5") - mock_inspector = stub list: [outdated_gem], outdated: "outdated" - Gemdiff::BundleInspector.stubs new: mock_inspector - cli.stubs ask: "s" - cli.expects(:puts).with(Gemdiff::CLI::CHECKING_FOR_OUTDATED) - cli.expects(:puts).with("outdated") - cli.expects(:puts).with("haml: 4.0.5 > 4.0.4") - outdated_gem.expects(:compare_url).returns("https://github.com/haml/haml/compare/4.0.4...4.0.5") - cli.expects(:puts).with("https://github.com/haml/haml/compare/4.0.4...4.0.5") - cli.each - end - - it "skips outdated gems without responses of y" do - outdated_gem = Gemdiff::OutdatedGem.new("haml", "4.0.4", "4.0.5") - mock_inspector = stub list: [outdated_gem], outdated: "outdated" - Gemdiff::BundleInspector.stubs new: mock_inspector - cli.stubs ask: "" - cli.expects(:puts).with(Gemdiff::CLI::CHECKING_FOR_OUTDATED) - cli.expects(:puts).with("outdated") - cli.expects(:puts).with("haml: 4.0.5 > 4.0.4") - outdated_gem.expects(:compare).never - cli.each - end - end - - describe "#list" do - it "does nothing when nothing to update" do - mock_inspector = stub list: [], outdated: "" - Gemdiff::BundleInspector.stubs new: mock_inspector - cli.expects(:puts).with(Gemdiff::CLI::CHECKING_FOR_OUTDATED) - cli.expects(:puts).with("") - cli.expects(:puts).with("\n") - cli.list - end - - it "lists outdated gems" do - outdated_gem = Gemdiff::OutdatedGem.new("pundit", "1.0.0", "1.0.1") - mock_inspector = stub list: [outdated_gem], outdated: "outdated" - Gemdiff::BundleInspector.stubs new: mock_inspector - outdated_gem.expects(:compare_url) - .returns("https://github.com/varvet/pundit/compare/v1.0.0...v1.0.1") - cli.expects(:puts).with(Gemdiff::CLI::CHECKING_FOR_OUTDATED) - cli.expects(:puts).with("outdated") - cli.expects(:puts).with("\n").twice - cli.expects(:puts).with("pundit: 1.0.1 > 1.0.0") - cli.expects(:puts).with("https://github.com/varvet/pundit/compare/v1.0.0...v1.0.1") - cli.list - end - end - - describe "#update" do - before do - @mock_gem = stub clean?: true, diff: "le diff", show: "le show" - Gemdiff::GemUpdater.stubs new: @mock_gem - end - - it "updates the gem and returns with no response" do - cli.stubs ask: "" - cli.expects(:puts).with("Updating haml...") - @mock_gem.expects :update - cli.expects(:puts).with("le diff") - cli.update "haml" - end - - it "updates the gem and commits with responses of c" do - cli.stubs ask: "c" - cli.expects(:puts).with("Updating haml...") - @mock_gem.expects :update - cli.expects(:puts).with("le diff") - @mock_gem.expects :commit - cli.expects(:puts).with("\nle show") - cli.update "haml" - end - - it "updates the gem and resets with responses of r" do - cli.stubs ask: "r" - cli.expects(:puts).with("Updating haml...") - @mock_gem.expects :update - cli.expects(:puts).with("le diff") - @mock_gem.expects(:reset).returns("le reset") - cli.expects(:puts).with("le reset") - cli.update "haml" - end - end - - private - - def mock_gem(name) - outdated_gem = stub repo?: true, repo: "http://github.com/#{name}/#{name}" - Gemdiff::OutdatedGem.stubs new: outdated_gem - outdated_gem - end - - def mock_missing_gem - outdated_gem = stub repo?: false - Gemdiff::OutdatedGem.stubs new: outdated_gem - outdated_gem +def cli + @cli ||= Gemdiff::CLI.new +end + +describe "#find" do + it "finds" do + mock_gem "haml" + cli.expects(:puts).with("http://github.com/haml/haml") + cli.find "haml" + end + + it "does not find" do + mock_missing_gem + cli.expects(:puts).with("Could not find github repository for notfound.") + cli.find "notfound" + end +end + +describe "#open" do + it "opens repo" do + outdated_gem = mock_gem("haml") + cli.expects(:puts).with("http://github.com/haml/haml") + outdated_gem.expects :open + cli.open "haml" + end +end + +describe "#releases" do + it "opens releases page" do + outdated_gem = mock_gem("haml") + cli.expects(:puts).with("http://github.com/haml/haml") + outdated_gem.expects :releases + cli.releases "haml" + end +end + +describe "#main" do + it "opens commits page" do + outdated_gem = mock_gem("haml") + cli.expects(:puts).with("http://github.com/haml/haml") + outdated_gem.expects :main + cli.main "haml" + end +end + +describe "#compare" do + it "opens compare view using bundle" do + outdated_gem = mock_gem("haml") + cli.expects(:puts).with("http://github.com/haml/haml") + outdated_gem.expects(:set_versions).with(nil, nil) + outdated_gem.expects(:missing_versions?).returns(true) + cli.expects(:puts).with(Gemdiff::CLI::CHECKING_FOR_OUTDATED) + outdated_gem.expects(:load_bundle_versions).returns(true) + outdated_gem.expects(:compare_message).returns("compare message") + cli.expects(:puts).with("compare message") + outdated_gem.expects :compare + cli.compare "haml" + end + + it "opens compare view with versions" do + outdated_gem = mock_gem("haml") + cli.expects(:puts).with("http://github.com/haml/haml") + outdated_gem.expects(:set_versions).with("4.0.4", "4.0.5") + outdated_gem.expects(:missing_versions?).returns(false) + outdated_gem.expects(:compare_message).returns("compare message") + cli.expects(:puts).with("compare message") + outdated_gem.expects :compare + cli.compare "haml", "4.0.4", "4.0.5" + end + + it "returns when the gem is not found" do + mock_missing_gem + cli.expects(:puts).with("Could not find github repository for notfound.") + cli.compare "notfound" + end +end + +describe "#each" do + it "does nothing when nothing to update" do + mock_inspector = stub list: [], outdated: "" + Gemdiff::BundleInspector.stubs new: mock_inspector + cli.expects(:puts).with(Gemdiff::CLI::CHECKING_FOR_OUTDATED) + cli.expects(:puts).with("") + cli.each + end + + it "compares outdated gems with responses of y" do + outdated_gem = Gemdiff::OutdatedGem.new("haml", "4.0.4", "4.0.5") + mock_inspector = stub list: [outdated_gem], outdated: "outdated" + Gemdiff::BundleInspector.stubs new: mock_inspector + cli.stubs ask: "y" + cli.expects(:puts).with(Gemdiff::CLI::CHECKING_FOR_OUTDATED) + cli.expects(:puts).with("outdated") + cli.expects(:puts).with("haml: 4.0.5 > 4.0.4") + outdated_gem.expects :compare + cli.each + end + + it "show compare urls of outdated gems with responses of s" do + outdated_gem = Gemdiff::OutdatedGem.new("haml", "4.0.4", "4.0.5") + mock_inspector = stub list: [outdated_gem], outdated: "outdated" + Gemdiff::BundleInspector.stubs new: mock_inspector + cli.stubs ask: "s" + cli.expects(:puts).with(Gemdiff::CLI::CHECKING_FOR_OUTDATED) + cli.expects(:puts).with("outdated") + cli.expects(:puts).with("haml: 4.0.5 > 4.0.4") + outdated_gem.expects(:compare_url).returns("https://github.com/haml/haml/compare/4.0.4...4.0.5") + cli.expects(:puts).with("https://github.com/haml/haml/compare/4.0.4...4.0.5") + cli.each + end + + it "skips outdated gems without responses of y" do + outdated_gem = Gemdiff::OutdatedGem.new("haml", "4.0.4", "4.0.5") + mock_inspector = stub list: [outdated_gem], outdated: "outdated" + Gemdiff::BundleInspector.stubs new: mock_inspector + cli.stubs ask: "" + cli.expects(:puts).with(Gemdiff::CLI::CHECKING_FOR_OUTDATED) + cli.expects(:puts).with("outdated") + cli.expects(:puts).with("haml: 4.0.5 > 4.0.4") + outdated_gem.expects(:compare).never + cli.each + end +end + +describe "#list" do + it "does nothing when nothing to update" do + mock_inspector = stub list: [], outdated: "" + Gemdiff::BundleInspector.stubs new: mock_inspector + cli.expects(:puts).with(Gemdiff::CLI::CHECKING_FOR_OUTDATED) + cli.expects(:puts).with("") + cli.expects(:puts).with("\n") + cli.list + end + + it "lists outdated gems" do + outdated_gem = Gemdiff::OutdatedGem.new("pundit", "1.0.0", "1.0.1") + mock_inspector = stub list: [outdated_gem], outdated: "outdated" + Gemdiff::BundleInspector.stubs new: mock_inspector + outdated_gem.expects(:compare_url) + .returns("https://github.com/varvet/pundit/compare/v1.0.0...v1.0.1") + cli.expects(:puts).with(Gemdiff::CLI::CHECKING_FOR_OUTDATED) + cli.expects(:puts).with("outdated") + cli.expects(:puts).with("\n").twice + cli.expects(:puts).with("pundit: 1.0.1 > 1.0.0") + cli.expects(:puts).with("https://github.com/varvet/pundit/compare/v1.0.0...v1.0.1") + cli.list + end +end + +describe "#update" do + before do + @mock_gem = stub clean?: true, diff: "le diff", show: "le show" + Gemdiff::GemUpdater.stubs new: @mock_gem + end + + it "updates the gem and returns with no response" do + cli.stubs ask: "" + cli.expects(:puts).with("Updating haml...") + @mock_gem.expects :update + cli.expects(:puts).with("le diff") + cli.update "haml" + end + + it "updates the gem and commits with responses of c" do + cli.stubs ask: "c" + cli.expects(:puts).with("Updating haml...") + @mock_gem.expects :update + cli.expects(:puts).with("le diff") + @mock_gem.expects :commit + cli.expects(:puts).with("\nle show") + cli.update "haml" + end + + it "updates the gem and resets with responses of r" do + cli.stubs ask: "r" + cli.expects(:puts).with("Updating haml...") + @mock_gem.expects :update + cli.expects(:puts).with("le diff") + @mock_gem.expects(:reset).returns("le reset") + cli.expects(:puts).with("le reset") + cli.update "haml" end end + +private + +def mock_gem(name) + outdated_gem = stub repo?: true, repo: "http://github.com/#{name}/#{name}" + Gemdiff::OutdatedGem.stubs new: outdated_gem + outdated_gem +end + +def mock_missing_gem + outdated_gem = stub repo?: false + Gemdiff::OutdatedGem.stubs new: outdated_gem + outdated_gem +end diff --git a/test/gem_updater_test.rb b/test/gem_updater_test.rb index 16f76a9..054d6e0 100644 --- a/test/gem_updater_test.rb +++ b/test/gem_updater_test.rb @@ -2,83 +2,82 @@ require "test_helper" -class GemUpdaterTest < MiniTest::Spec - describe "#update" do - it "updates the gem" do - updater = Gemdiff::GemUpdater.new("x") - updater.expects :bundle_update - updater.update - end +describe "#update" do + it "updates the gem" do + updater = Gemdiff::GemUpdater.new("x") + updater.expects :bundle_update + updater.update end +end - describe "#commit" do - it "adds a git commit for a gem update" do - updater = Gemdiff::GemUpdater.new("json") - updater.stubs git_removed_line: "- json (1.8.0)" - updater.stubs git_added_line: "+ json (1.8.1)" - assert_equal "Update json to 1.8.1\n\nhttps://github.com/flori/json/compare/v1.8.0...v1.8.1", - updater.send(:commit_message) - updater.expects :git_add_and_commit_lockfile - assert updater.commit - end +describe "#commit" do + it "adds a git commit for a gem update" do + updater = Gemdiff::GemUpdater.new("json") + updater.stubs git_removed_line: "- json (1.8.0)" + updater.stubs git_added_line: "+ json (1.8.1)" + assert_equal "Update json to 1.8.1\n\nhttps://github.com/flori/json/compare/v1.8.0...v1.8.1", + updater.send(:commit_message) + updater.expects :git_add_and_commit_lockfile + assert updater.commit + end - it "adds a git commit for an update from a specific ref" do - updater = Gemdiff::GemUpdater.new("ffi") - updater.stubs git_removed_line: "- ffi (1.2.3)" - updater.stubs git_added_line: "+ ffi (1.2.4)\n+ ffi" - assert_equal "Update ffi to 1.2.4\n\nhttps://github.com/ffi/ffi/compare/1.2.3...1.2.4", - updater.send(:commit_message) - updater.expects :git_add_and_commit_lockfile - assert updater.commit - end + it "adds a git commit for an update from a specific ref" do + updater = Gemdiff::GemUpdater.new("ffi") + updater.stubs git_removed_line: "- ffi (1.2.3)" + updater.stubs git_added_line: "+ ffi (1.2.4)\n+ ffi" + assert_equal "Update ffi to 1.2.4\n\nhttps://github.com/ffi/ffi/compare/1.2.3...1.2.4", + updater.send(:commit_message) + updater.expects :git_add_and_commit_lockfile + assert updater.commit + end - it "adds a git commit for an update with dependencies" do - updater = Gemdiff::GemUpdater.new("activejob") - updater.stubs git_removed_line: "- activejob (4.2.2)" - updater.stubs git_added_line: \ - "+ activejob (= 4.2.3)\n+ activejob (4.2.3)\n+ activejob (= 4.2.3)" - assert_equal "Update activejob to 4.2.3\n\nhttps://github.com/rails/rails/compare/v4.2.2...v4.2.3", - updater.send(:commit_message) - updater.expects :git_add_and_commit_lockfile - assert updater.commit - end + it "adds a git commit for an update with dependencies" do + updater = Gemdiff::GemUpdater.new("activejob") + updater.stubs git_removed_line: "- activejob (4.2.2)" + updater.stubs git_added_line: \ + "+ activejob (= 4.2.3)\n+ activejob (4.2.3)\n+ activejob (= 4.2.3)" + assert_equal "Update activejob to 4.2.3\n\nhttps://github.com/rails/rails/compare/v4.2.2...v4.2.3", + updater.send(:commit_message) + updater.expects :git_add_and_commit_lockfile + assert updater.commit end +end - describe "#reset" do - it "resets Gemfile.lock" do - updater = Gemdiff::GemUpdater.new("x") - updater.expects :git_reset - updater.reset - end +describe "#reset" do + it "resets Gemfile.lock" do + updater = Gemdiff::GemUpdater.new("x") + updater.expects :git_reset + updater.reset end +end - describe "#diff" do - it "returns git diff" do - updater = Gemdiff::GemUpdater.new("x") - updater.expects :git_diff - updater.diff - end +describe "#diff" do + it "returns git diff" do + updater = Gemdiff::GemUpdater.new("x") + updater.expects :git_diff + updater.diff end +end - describe "#show" do - it "returns git show" do - updater = Gemdiff::GemUpdater.new("x") - updater.expects :git_show - updater.show - end +describe "#show" do + it "returns git show" do + updater = Gemdiff::GemUpdater.new("x") + updater.expects :git_show + updater.show end +end - describe "#clean?" do - it "returns true for empty diff" do - updater = Gemdiff::GemUpdater.new("x") - updater.stubs git_diff: "" - assert updater.clean? - end +describe "#clean?" do + it "returns true for empty diff" do + updater = Gemdiff::GemUpdater.new("x") + updater.stubs git_diff: "" + assert updater.clean? + end - it "returns false for non-empty diff" do - updater = Gemdiff::GemUpdater.new("x") - updater.stubs git_diff: "something" - refute updater.clean? - end + it "returns false for non-empty diff" do + updater = Gemdiff::GemUpdater.new("x") + updater.stubs git_diff: "something" + refute updater.clean? end end + diff --git a/test/outdated_gem_test.rb b/test/outdated_gem_test.rb index 606a082..8b35bd7 100644 --- a/test/outdated_gem_test.rb +++ b/test/outdated_gem_test.rb @@ -2,159 +2,158 @@ require "test_helper" -class OutdatedGemTest < MiniTest::Spec - describe "#initialize" do - it "sets name" do - assert_equal "x", Gemdiff::OutdatedGem.new("x").name - end - - it "sets name to current directory when ." do - assert_equal "gemdiff", Gemdiff::OutdatedGem.new(".").name - end - end - - describe "#missing_versions?" do - it "returns true" do - assert Gemdiff::OutdatedGem.new("x").missing_versions? - end - - it "returns false" do - refute Gemdiff::OutdatedGem.new("x", "1", "2").missing_versions? - end - end - - describe "#compare_url" do - it "returns compare url" do - outdated_gem = Gemdiff::OutdatedGem.new("x", "1.0", "2.0") - outdated_gem.stubs repo: "http://github.com/x/x/" - assert_equal "http://github.com/x/x/compare/v1.0...v2.0", outdated_gem.compare_url - end - - it "returns compare url with no v for exceptions" do - outdated_gem = Gemdiff::OutdatedGem.new("ffi", "1.9.17", "1.9.18") - outdated_gem.stubs repo: "http://github.com/ffi/ffi" - assert_equal "http://github.com/ffi/ffi/compare/1.9.17...1.9.18", outdated_gem.compare_url - end - - it "returns compare url with branch name for new version" do - outdated_gem = Gemdiff::OutdatedGem.new("x", "4.0.0", "main") - outdated_gem.stubs repo: "http://github.com/x/x" - assert_equal "http://github.com/x/x/compare/v4.0.0...main", outdated_gem.compare_url - end - end - - describe "#releases_url" do - it "returns releases url" do - outdated_gem = Gemdiff::OutdatedGem.new("x") - outdated_gem.stubs repo: "http://github.com/x/x" - assert_equal "http://github.com/x/x/releases", outdated_gem.releases_url - end - end - - describe "#commits_url" do - it "returns commits url" do - outdated_gem = Gemdiff::OutdatedGem.new("x") - outdated_gem.stubs repo: "http://github.com/x/x" - assert_equal "http://github.com/x/x/commits/main", outdated_gem.commits_url - end - end - - describe "#compare_message" do - it "returns compare message" do - outdated_gem = Gemdiff::OutdatedGem.new("x", "1", "2") - outdated_gem.stubs repo: "http://github.com/x/x" - assert_equal "x: 2 > 1", outdated_gem.compare_message - end - end - - describe "#load_bundle_versions" do - it "returns false if not found" do - mock_inspector = stub(get: nil) - Gemdiff::BundleInspector.stubs new: mock_inspector - refute Gemdiff::OutdatedGem.new("x").load_bundle_versions - end - - it "sets versions from gem in bundle" do - mock_outdated_gem = Gemdiff::OutdatedGem.new("y", "1.2.3", "2.3.4") - mock_inspector = stub get: mock_outdated_gem - Gemdiff::BundleInspector.stubs new: mock_inspector - outdated_gem = Gemdiff::OutdatedGem.new("y") - assert outdated_gem.load_bundle_versions - assert_equal "1.2.3", outdated_gem.old_version - assert_equal "2.3.4", outdated_gem.new_version - end - end - - describe "#set_versions" do - it "sets nil versions" do - outdated_gem = Gemdiff::OutdatedGem.new("x", "1", "2") - outdated_gem.set_versions nil, nil - assert_nil outdated_gem.old_version - assert_nil outdated_gem.new_version - end - - it "sets old, new versions" do - outdated_gem = Gemdiff::OutdatedGem.new("x") - outdated_gem.set_versions "1.2.34", "2.34.56" - assert_equal "1.2.34", outdated_gem.old_version - assert_equal "2.34.56", outdated_gem.new_version - end - - it "swaps versions in the wrong order" do - outdated_gem = Gemdiff::OutdatedGem.new("x") - outdated_gem.set_versions "2.34.56", "1.2.34" - assert_equal "1.2.34", outdated_gem.old_version - assert_equal "2.34.56", outdated_gem.new_version - end - - it "swaps versions over 10 in the wrong order" do - outdated_gem = Gemdiff::OutdatedGem.new("x") - outdated_gem.set_versions "1.10.0", "1.9.3" - assert_equal "1.9.3", outdated_gem.old_version - assert_equal "1.10.0", outdated_gem.new_version - end - - it "swaps versions with main" do - outdated_gem = Gemdiff::OutdatedGem.new("x") - outdated_gem.set_versions "main", "1.9.3" - assert_equal "1.9.3", outdated_gem.old_version - assert_equal "main", outdated_gem.new_version - end - end - - describe "#main" do - it "opens main commits url" do - outdated_gem = Gemdiff::OutdatedGem.new("x") - outdated_gem.stubs repo: "http://github.com/x/x" - outdated_gem.expects(:open_url).with("http://github.com/x/x/commits/main") - outdated_gem.main - end - end - - describe "#releases" do - it "opens releases url" do - outdated_gem = Gemdiff::OutdatedGem.new("x") - outdated_gem.stubs repo: "http://github.com/x/x" - outdated_gem.expects(:open_url).with("http://github.com/x/x/releases") - outdated_gem.releases - end - end - - describe "#compare" do - it "opens compare url" do - outdated_gem = Gemdiff::OutdatedGem.new("x", "1.2.3", "2.3.4") - outdated_gem.stubs repo: "http://github.com/x/x" - outdated_gem.expects(:open_url).with("http://github.com/x/x/compare/v1.2.3...v2.3.4") - outdated_gem.compare - end - end - - describe "#open" do - it "opens repo url" do - outdated_gem = Gemdiff::OutdatedGem.new("x") - outdated_gem.stubs repo: "http://github.com/x/x" - outdated_gem.expects(:open_url).with("http://github.com/x/x") - outdated_gem.open - end +describe "#initialize" do + it "sets name" do + assert_equal "x", Gemdiff::OutdatedGem.new("x").name + end + + it "sets name to current directory when ." do + assert_equal "gemdiff", Gemdiff::OutdatedGem.new(".").name + end +end + +describe "#missing_versions?" do + it "returns true" do + assert Gemdiff::OutdatedGem.new("x").missing_versions? + end + + it "returns false" do + refute Gemdiff::OutdatedGem.new("x", "1", "2").missing_versions? + end +end + +describe "#compare_url" do + it "returns compare url" do + outdated_gem = Gemdiff::OutdatedGem.new("x", "1.0", "2.0") + outdated_gem.stubs repo: "http://github.com/x/x/" + assert_equal "http://github.com/x/x/compare/v1.0...v2.0", outdated_gem.compare_url + end + + it "returns compare url with no v for exceptions" do + outdated_gem = Gemdiff::OutdatedGem.new("ffi", "1.9.17", "1.9.18") + outdated_gem.stubs repo: "http://github.com/ffi/ffi" + assert_equal "http://github.com/ffi/ffi/compare/1.9.17...1.9.18", outdated_gem.compare_url + end + + it "returns compare url with branch name for new version" do + outdated_gem = Gemdiff::OutdatedGem.new("x", "4.0.0", "main") + outdated_gem.stubs repo: "http://github.com/x/x" + assert_equal "http://github.com/x/x/compare/v4.0.0...main", outdated_gem.compare_url + end +end + +describe "#releases_url" do + it "returns releases url" do + outdated_gem = Gemdiff::OutdatedGem.new("x") + outdated_gem.stubs repo: "http://github.com/x/x" + assert_equal "http://github.com/x/x/releases", outdated_gem.releases_url + end +end + +describe "#commits_url" do + it "returns commits url" do + outdated_gem = Gemdiff::OutdatedGem.new("x") + outdated_gem.stubs repo: "http://github.com/x/x" + assert_equal "http://github.com/x/x/commits/main", outdated_gem.commits_url + end +end + +describe "#compare_message" do + it "returns compare message" do + outdated_gem = Gemdiff::OutdatedGem.new("x", "1", "2") + outdated_gem.stubs repo: "http://github.com/x/x" + assert_equal "x: 2 > 1", outdated_gem.compare_message + end +end + +describe "#load_bundle_versions" do + it "returns false if not found" do + mock_inspector = stub(get: nil) + Gemdiff::BundleInspector.stubs new: mock_inspector + refute Gemdiff::OutdatedGem.new("x").load_bundle_versions + end + + it "sets versions from gem in bundle" do + mock_outdated_gem = Gemdiff::OutdatedGem.new("y", "1.2.3", "2.3.4") + mock_inspector = stub get: mock_outdated_gem + Gemdiff::BundleInspector.stubs new: mock_inspector + outdated_gem = Gemdiff::OutdatedGem.new("y") + assert outdated_gem.load_bundle_versions + assert_equal "1.2.3", outdated_gem.old_version + assert_equal "2.3.4", outdated_gem.new_version + end +end + +describe "#set_versions" do + it "sets nil versions" do + outdated_gem = Gemdiff::OutdatedGem.new("x", "1", "2") + outdated_gem.set_versions nil, nil + assert_nil outdated_gem.old_version + assert_nil outdated_gem.new_version + end + + it "sets old, new versions" do + outdated_gem = Gemdiff::OutdatedGem.new("x") + outdated_gem.set_versions "1.2.34", "2.34.56" + assert_equal "1.2.34", outdated_gem.old_version + assert_equal "2.34.56", outdated_gem.new_version + end + + it "swaps versions in the wrong order" do + outdated_gem = Gemdiff::OutdatedGem.new("x") + outdated_gem.set_versions "2.34.56", "1.2.34" + assert_equal "1.2.34", outdated_gem.old_version + assert_equal "2.34.56", outdated_gem.new_version + end + + it "swaps versions over 10 in the wrong order" do + outdated_gem = Gemdiff::OutdatedGem.new("x") + outdated_gem.set_versions "1.10.0", "1.9.3" + assert_equal "1.9.3", outdated_gem.old_version + assert_equal "1.10.0", outdated_gem.new_version + end + + it "swaps versions with main" do + outdated_gem = Gemdiff::OutdatedGem.new("x") + outdated_gem.set_versions "main", "1.9.3" + assert_equal "1.9.3", outdated_gem.old_version + assert_equal "main", outdated_gem.new_version end end + +describe "#main" do + it "opens main commits url" do + outdated_gem = Gemdiff::OutdatedGem.new("x") + outdated_gem.stubs repo: "http://github.com/x/x" + outdated_gem.expects(:open_url).with("http://github.com/x/x/commits/main") + outdated_gem.main + end +end + +describe "#releases" do + it "opens releases url" do + outdated_gem = Gemdiff::OutdatedGem.new("x") + outdated_gem.stubs repo: "http://github.com/x/x" + outdated_gem.expects(:open_url).with("http://github.com/x/x/releases") + outdated_gem.releases + end +end + +describe "#compare" do + it "opens compare url" do + outdated_gem = Gemdiff::OutdatedGem.new("x", "1.2.3", "2.3.4") + outdated_gem.stubs repo: "http://github.com/x/x" + outdated_gem.expects(:open_url).with("http://github.com/x/x/compare/v1.2.3...v2.3.4") + outdated_gem.compare + end +end + +describe "#open" do + it "opens repo url" do + outdated_gem = Gemdiff::OutdatedGem.new("x") + outdated_gem.stubs repo: "http://github.com/x/x" + outdated_gem.expects(:open_url).with("http://github.com/x/x") + outdated_gem.open + end +end + diff --git a/test/repo_finder_test.rb b/test/repo_finder_test.rb index aee5965..c009fbb 100644 --- a/test/repo_finder_test.rb +++ b/test/repo_finder_test.rb @@ -2,108 +2,106 @@ require "test_helper" -class RepoFinderTest < MiniTest::Spec - describe ".github_url" do - it "returns github url from local gemspec" do - Gemdiff::RepoFinder.stubs find_local_gemspec: fake_gemspec("homepage: http://github.com/rails/arel") - assert_equal "https://github.com/rails/arel", Gemdiff::RepoFinder.github_url("arel") - end - - it "strips anchors from urls" do - Gemdiff::RepoFinder.stubs \ - find_local_gemspec: fake_gemspec("homepage: https://github.com/rubysec/bundler-audit#readme") - assert_equal "https://github.com/rubysec/bundler-audit", - Gemdiff::RepoFinder.github_url("bundler-audit") - end - - it "returns github url from remote gemspec" do - Gemdiff::RepoFinder.stubs find_local_gemspec: "" - Gemdiff::RepoFinder.stubs find_remote_gemspec: fake_gemspec("homepage: http://github.com/rails/arel") - assert_equal "https://github.com/rails/arel", Gemdiff::RepoFinder.github_url("arel") - end - - it "returns nil when gem does not exist and not found in search" do - Gemdiff::RepoFinder.stubs octokit_client: mock_octokit(nil) - Gemdiff::RepoFinder.stubs gemspec: "" - assert_nil Gemdiff::RepoFinder.github_url("nope") - end - - it "returns url from github search when gem does not exist and found in search" do - Gemdiff::RepoFinder.stubs octokit_client: mock_octokit("x/x") - Gemdiff::RepoFinder.stubs gemspec: "" - assert_equal "https://github.com/x/x", Gemdiff::RepoFinder.github_url("x") - end - - it "returns url from github search when not in gemspec" do - Gemdiff::RepoFinder.stubs octokit_client: mock_octokit("y/y") - Gemdiff::RepoFinder.stubs gemspec: fake_gemspec - assert_equal "https://github.com/y/y", Gemdiff::RepoFinder.github_url("y") - end - - it "returns nil when not in gemspec and not found" do - Gemdiff::RepoFinder.stubs octokit_client: mock_octokit(nil) - Gemdiff::RepoFinder.stubs gemspec: fake_gemspec - assert_nil Gemdiff::RepoFinder.github_url("not_found") - end - - it "returns exception url" do - assert_equal "https://github.com/rails/rails", Gemdiff::RepoFinder.github_url("activerecord") - end - - it "returns nil for gemspec with no homepage and no description" do - Gemdiff::RepoFinder.stubs octokit_client: mock_octokit(nil) - Gemdiff::RepoFinder.stubs gemspec: NO_DESCRIPTION_GEMSPEC - assert_nil Gemdiff::RepoFinder.github_url("none") - end - - it "returns url when # is present in description" do - Gemdiff::RepoFinder.stubs find_local_gemspec: ANCHOR_DESCRIPTION_GEMSPEC - assert_equal "https://github.com/nicksieger/multipart-post", - Gemdiff::RepoFinder.github_url("multipart-post") - end +describe ".github_url" do + it "returns github url from local gemspec" do + Gemdiff::RepoFinder.stubs find_local_gemspec: fake_gemspec("homepage: http://github.com/rails/arel") + assert_equal "https://github.com/rails/arel", Gemdiff::RepoFinder.github_url("arel") end - private + it "strips anchors from urls" do + Gemdiff::RepoFinder.stubs \ + find_local_gemspec: fake_gemspec("homepage: https://github.com/rubysec/bundler-audit#readme") + assert_equal "https://github.com/rubysec/bundler-audit", + Gemdiff::RepoFinder.github_url("bundler-audit") + end + + it "returns github url from remote gemspec" do + Gemdiff::RepoFinder.stubs find_local_gemspec: "" + Gemdiff::RepoFinder.stubs find_remote_gemspec: fake_gemspec("homepage: http://github.com/rails/arel") + assert_equal "https://github.com/rails/arel", Gemdiff::RepoFinder.github_url("arel") + end + + it "returns nil when gem does not exist and not found in search" do + Gemdiff::RepoFinder.stubs octokit_client: mock_octokit(nil) + Gemdiff::RepoFinder.stubs gemspec: "" + assert_nil Gemdiff::RepoFinder.github_url("nope") + end + + it "returns url from github search when gem does not exist and found in search" do + Gemdiff::RepoFinder.stubs octokit_client: mock_octokit("x/x") + Gemdiff::RepoFinder.stubs gemspec: "" + assert_equal "https://github.com/x/x", Gemdiff::RepoFinder.github_url("x") + end + + it "returns url from github search when not in gemspec" do + Gemdiff::RepoFinder.stubs octokit_client: mock_octokit("y/y") + Gemdiff::RepoFinder.stubs gemspec: fake_gemspec + assert_equal "https://github.com/y/y", Gemdiff::RepoFinder.github_url("y") + end - def mock_octokit(full_name) - mock_items = if full_name.nil? - stub items: [] - else - stub items: [stub(full_name: full_name)] - end - stub search_repositories: mock_items + it "returns nil when not in gemspec and not found" do + Gemdiff::RepoFinder.stubs octokit_client: mock_octokit(nil) + Gemdiff::RepoFinder.stubs gemspec: fake_gemspec + assert_nil Gemdiff::RepoFinder.github_url("not_found") end - FAKE_GEMSPEC = <<~SPEC - --- !ruby/object:Gem::Specification - name: fake - version: !ruby/object:Gem::Version - version: 1.2.3 - date: 2021-01-06 00:00:00.000000000 Z - description: fake - SPEC - - NO_DESCRIPTION_GEMSPEC = <<~SPEC - --- !ruby/object:Gem::Specification - name: fake - version: !ruby/object:Gem::Version - version: 1.2.3 - description: - SPEC - - ANCHOR_DESCRIPTION_GEMSPEC = <<~SPEC - --- !ruby/object:Gem::Specification - name: multipart-post - version: !ruby/object:Gem::Version - version: 2.0.0 - description: 'IO values that have #content_type, #original_filename, - and #local_path will be posted as a binary file.' - homepage: https://github.com/nicksieger/multipart-post - licenses: - - MIT - SPEC - - def fake_gemspec(extra = "") - [FAKE_GEMSPEC, extra].compact.join("\n") + it "returns exception url" do + assert_equal "https://github.com/rails/rails", Gemdiff::RepoFinder.github_url("activerecord") + end + + it "returns nil for gemspec with no homepage and no description" do + Gemdiff::RepoFinder.stubs octokit_client: mock_octokit(nil) + Gemdiff::RepoFinder.stubs gemspec: NO_DESCRIPTION_GEMSPEC + assert_nil Gemdiff::RepoFinder.github_url("none") + end + + it "returns url when # is present in description" do + Gemdiff::RepoFinder.stubs find_local_gemspec: ANCHOR_DESCRIPTION_GEMSPEC + assert_equal "https://github.com/nicksieger/multipart-post", + Gemdiff::RepoFinder.github_url("multipart-post") end end + +private + +def mock_octokit(full_name) + mock_items = if full_name.nil? + stub items: [] + else + stub items: [stub(full_name: full_name)] + end + stub search_repositories: mock_items +end + +FAKE_GEMSPEC = <<~SPEC + --- !ruby/object:Gem::Specification + name: fake + version: !ruby/object:Gem::Version + version: 1.2.3 + date: 2021-01-06 00:00:00.000000000 Z + description: fake +SPEC + +NO_DESCRIPTION_GEMSPEC = <<~SPEC + --- !ruby/object:Gem::Specification + name: fake + version: !ruby/object:Gem::Version + version: 1.2.3 + description: +SPEC + +ANCHOR_DESCRIPTION_GEMSPEC = <<~SPEC + --- !ruby/object:Gem::Specification + name: multipart-post + version: !ruby/object:Gem::Version + version: 2.0.0 + description: 'IO values that have #content_type, #original_filename, + and #local_path will be posted as a binary file.' + homepage: https://github.com/nicksieger/multipart-post + licenses: + - MIT +SPEC + +def fake_gemspec(extra = "") + [FAKE_GEMSPEC, extra].compact.join("\n") +end \ No newline at end of file