From 3b85f8764c14847ef43b7859494689e5ca8e1572 Mon Sep 17 00:00:00 2001 From: Yutaka Kamei Date: Tue, 21 Nov 2023 15:06:32 +0900 Subject: [PATCH 1/2] Make tests compatible with Ruby 3.2 Previously, tests with Ruby version 3.2 didn't pass because the Bundler version was not compatible with the latest Ruby. Therefore, I made changes to remove the version constraint for `bundler` in gemspec. Even though I loosened the version constraint, the tests still didn't pass. Upon reviewing the test code, I found some issues: * Test cases are accessing private methods without using `#send`. * One test case assumes that the `*.gem` file exists. With this patch, I aim to ensure that specific_install_spec can be tested with ease. Additionally, I want to suggest adding a GitHub workflow to ensure tests are run whenever pull requests are submitted. --- .github/workflows/ci.yml | 21 +++++++++++++++ spec/specific_install_spec.rb | 48 ++++++++++++++++++++--------------- specific_install.gemspec | 2 +- 3 files changed, 49 insertions(+), 22 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..f0be658 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,21 @@ +name: CI +on: + push: + branches: [main] + pull_request: + workflow_dispatch: +jobs: + test: + name: Test on Ruby ${{ matrix.ruby }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + ruby: ['2.7', '3.0', '3.1', '3.2'] + steps: + - uses: actions/checkout@v4 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + - run: bundle exec rspec diff --git a/spec/specific_install_spec.rb b/spec/specific_install_spec.rb index fd7aa77..6901be3 100644 --- a/spec/specific_install_spec.rb +++ b/spec/specific_install_spec.rb @@ -1,7 +1,8 @@ require 'rubygems' -require './spec_helper' +require_relative './spec_helper' require 'stringio' require 'open3' +require 'tmpdir' describe Gem::Commands::SpecificInstallCommand do before do @@ -28,7 +29,7 @@ module Kernel describe "#gem_name" do it "sets gem_name from location" do subject.instance_variable_set(:@loc, "stuff/foo/bar") - expect(subject.gem_name).to eq("bar") + expect(subject.send(:gem_name)).to eq("bar") end end @@ -47,7 +48,7 @@ def install_from_git(dir) end it "sends correct command to system" do subject.should_receive(:system).with(/git clone bar foo/) - subject.install_git + subject.send(:install_git) end end @@ -56,8 +57,8 @@ def install_from_git(dir) Dir.mktmpdir do |tmpdir| url = "https://rubygems.org/downloads/specific_install-0.2.7.gem" output_name = "specific_install.gem" - subject.download(url, output_name) - expect(File.exist?(output_name)).to be_true + subject.send(:download, url, output_name) + expect(File.exist?(output_name)).to be true end end end @@ -66,7 +67,7 @@ def install_from_git(dir) it "formats the shorthand into a git repo" do subject.instance_variable_set(:@loc, "bar/zoz") subject.should_receive(:system).with(%r{git clone git@github.com:bar/zoz.git foo}) - subject.install_shorthand + subject.send(:install_shorthand) end end end @@ -74,34 +75,39 @@ def install_from_git(dir) describe "#success_message" do it "returns correct message" do subject.output.should_receive(:puts).with('Successfully installed') - subject.success_message + subject.send(:success_message) end end describe "#install_gemspec" do context "when no gemspec or gem" do xit "returns false" do - expect( subject.install_gemspec ).to eq(false) + expect( subject.send(:install_gemspec) ).to eq(false) end end end describe "#gemspec_exists?" do it "response true to when exists" do - expect( subject.gemspec_exists? ).to be_true + expect( subject.send(:gemspec_exists?) ).to be true end it "responds false when not present" do - expect( subject.gemspec_exists?("*.gemNOTPRESENT") ).to be_false + expect( subject.send(:gemspec_exists?, "*.gemNOTPRESENT") ).to be false end end describe "#gemfile" do it "response false when not existing" do - expect( subject.gemfile("*.gemNOTPRESENT") ).to be_false + expect( subject.send(:gemfile, "*.gemNOTPRESENT") ).to be false end it "response true to when exists" do - expect( subject.gemfile("**/*.gem") ).to be_true + Dir.mktmpdir do |dir| + Dir.chdir(dir) do + Pathname("foo.gem").write('foo') + expect(subject.send(:gemfile, "**/*.gem")).to be_truthy + end + end end end @@ -109,49 +115,49 @@ def install_from_git(dir) it "executes http gem requests" do subject.instance_variable_set(:@loc, "http://example.com/rad.gem") subject.should_receive(:install_gem) - subject.determine_source_and_install + subject.send(:determine_source_and_install) end it "executes https gem requests" do subject.instance_variable_set(:@loc, "https://example.com/rad.gem") subject.should_receive(:install_gem) - subject.determine_source_and_install + subject.send(:determine_source_and_install) end it "executes https git install requests" do subject.instance_variable_set(:@loc, "https://example.com/rad.git") subject.should_receive(:install_git) - subject.determine_source_and_install + subject.send(:determine_source_and_install) end it "executes git url git install requests" do subject.instance_variable_set(:@loc, "git@github.com:example/rad.git") subject.should_receive(:install_git) - subject.determine_source_and_install + subject.send(:determine_source_and_install) end it "executes shorthand github install requests" do subject.instance_variable_set(:@loc, "example/rad") subject.should_receive(:install_shorthand) - subject.determine_source_and_install + subject.send(:determine_source_and_install) end it "executes shorthand github install requests" do subject.instance_variable_set(:@loc, "example") subject.should_receive(:warn) - subject.determine_source_and_install + subject.send(:determine_source_and_install) end end describe "#set_location" do it "sets from options[location]" do subject.options[:location] = "example" - expect( subject.set_location ).to eq("example") + expect( subject.send(:set_location) ).to eq("example") end it "sets from options[args]" do subject.options[:location] = nil subject.options[:args] = ["args"] - expect( subject.set_location ).to eq("args") + expect( subject.send(:set_location) ).to eq("args") end it "sets neither and results in nil" do subject.options[:location] = nil subject.options[:args] = [] - expect( subject.set_location ).to be_nil + expect( subject.send(:set_location) ).to be_nil end end diff --git a/specific_install.gemspec b/specific_install.gemspec index 09c8073..b4b7dcd 100644 --- a/specific_install.gemspec +++ b/specific_install.gemspec @@ -22,7 +22,7 @@ Gem::Specification.new do |s| s.add_development_dependency 'rspec' s.add_development_dependency 'sane' - s.add_development_dependency "bundler", "~> 1.3" + s.add_development_dependency "bundler" s.add_development_dependency "rake" s.add_development_dependency "simplecov" s.add_development_dependency "simplecov-vim" From dd998367b8dc10ed120044ba9632f2fdabecd632 Mon Sep 17 00:00:00 2001 From: Yutaka Kamei Date: Tue, 21 Nov 2023 15:28:16 +0900 Subject: [PATCH 2/2] Fix the target branch for push event --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f0be658..66c774a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,7 +1,7 @@ name: CI on: push: - branches: [main] + branches: [master] pull_request: workflow_dispatch: jobs: