Skip to content

Commit

Permalink
Merge pull request #61 from yykamei/test
Browse files Browse the repository at this point in the history
Make tests compatible with Ruby 3.2
  • Loading branch information
rdp authored Nov 21, 2023
2 parents 0d8ef16 + dd99836 commit 16686d6
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 22 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: CI
on:
push:
branches: [master]
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
48 changes: 27 additions & 21 deletions spec/specific_install_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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
Expand All @@ -66,92 +67,97 @@ 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 [email protected]:bar/zoz.git foo})
subject.install_shorthand
subject.send(:install_shorthand)
end
end
end

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

describe "#determine_source_and_install" do
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, "[email protected]: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

Expand Down
2 changes: 1 addition & 1 deletion specific_install.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 16686d6

Please sign in to comment.