Skip to content

Commit

Permalink
Merge pull request #264 from mttkay/mk-fix-ruby3-deprecation-warning
Browse files Browse the repository at this point in the history
Fix warning: Kernel#open is deprecated
  • Loading branch information
tduffield authored Jul 15, 2021
2 parents 1886f1c + e61f685 commit c801d12
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/license_scout/license.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def license_content(license_id, contents_url)

begin
LicenseScout::Log.debug("[license] Pulling license content for #{license_id} from #{new_url}")
open(new_url).read
URI.open(new_url).read
rescue RuntimeError => e
if e.message =~ /redirection forbidden/
m = /redirection forbidden:\s+(.+)\s+->\s+(.+)/.match(e.message)
Expand Down
27 changes: 23 additions & 4 deletions spec/license_scout/license_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
let(:apache_license_content) { File.read(File.join(SPEC_FIXTURES_DIR, "empty_project", "LICENSE")) }
let(:record) { described_class::Record.new(spdx, source, apache_license_content) }

before do
allow(described_class::Record).to receive(:new).with(spdx, source, apache_license_content).and_return(record)
end

describe ".new" do
let(:subject) { described_class.new(dependency_path) }

before do
allow(described_class::Record).to receive(:new).with(spdx, source, apache_license_content).and_return(record)
end

context "when path is nil" do
let(:dependency_path) { nil }

Expand Down Expand Up @@ -91,4 +91,23 @@
it { is_expected.to be false }
end
end

describe "#add_license" do
let(:license_url) { "https://url/to/license" }
let(:options) { { a: 42 } }

subject { described_class.new(dependency_path) }

it "downloads license body and adds a new record" do
expect(URI).to receive(:open).with(license_url).and_return(StringIO.new(apache_license_content))

subject.add_license(spdx, source, license_url, options)

new_record = subject.records.last
expect(new_record).not_to be_nil
expect(new_record.id).to eq(spdx)
expect(new_record.source).to eq(source)
expect(new_record.content).to eq(apache_license_content)
end
end
end

0 comments on commit c801d12

Please sign in to comment.