Skip to content

Commit

Permalink
Merge pull request #60 from alphagov/handle-no-rubygem
Browse files Browse the repository at this point in the history
Catch exception when Rubygem does not exist
  • Loading branch information
MuriloDalRi authored Apr 22, 2024
2 parents 7474bb9 + cbb68cc commit b7e15f1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/change_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ def internal?
Net::HTTP.get(URI("https://rubygems.org/api/v1/gems/#{name}/owners.yaml"))
.then { |response| YAML.safe_load response }
.any? { |owner| owner["handle"] == "govuk" }
rescue NoMethodError
puts "This rubygem could not be found."
false
end
end

Expand Down
9 changes: 9 additions & 0 deletions spec/lib/change_set_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@

expect(Dependency.new("foo").internal?).to eq(false)
end

it "returns false if the dependency is not found in Rubygems" do
stub_request(:get, "https://rubygems.org/api/v1/gems/foo/owners.yaml")
.to_return(
body: "This rubygem could not be found.",
)

expect(Dependency.new("foo").internal?).to eq(false)
end
end
end

Expand Down

0 comments on commit b7e15f1

Please sign in to comment.