Skip to content

Commit

Permalink
Add some specs to get to 100% coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
azimux committed Nov 9, 2024
1 parent b482c6c commit d6f17ac
Show file tree
Hide file tree
Showing 3 changed files with 356 additions and 3 deletions.
74 changes: 71 additions & 3 deletions spec/foobara/http_api_command_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,73 @@
RSpec.describe Foobara::HttpApiCommand do
it "has a version number" do
expect(Foobara::HttpApiCommand::VERSION).to_not be_nil
RSpec.describe Foobara::HttpApiGetCommand do
describe "#run" do
context "when command hits rubygems search API" do
let(:command_class) do
mixin = described_class

stub_class(:Search, Foobara::Command) do
include mixin

inputs do
query :string, :required
end

result [Hash]

url "https://rubygems.org/api/v1/search.json"

def build_request_body
self.request_body = { query: }
end
end
end

let(:command) { command_class.new(inputs) }
let(:outcome) { command.run }
let(:result) { outcome.result }
let(:errors) { outcome.errors }
let(:errors_hash) { outcome.errors_hash }

let(:inputs) do
{ query: "foobara" }
end

it "is successful", vcr: { record: :none } do
expect(outcome).to be_success
expect(result).to be_an(Array)
end
end

context "when command hits rubygems versions API" do
let(:command_class) do
mixin = described_class

stub_class(:GetVersions, Foobara::Command) do
include mixin

inputs do
gem_name :string, :required
end

result [Hash]

url { "https://rubygems.org/api/v1/versions/#{gem_name}.json" }
end
end

let(:command) { command_class.new(inputs) }
let(:outcome) { command.run }
let(:result) { outcome.result }
let(:errors) { outcome.errors }
let(:errors_hash) { outcome.errors_hash }

let(:inputs) do
{ gem_name: "foobara" }
end

it "is successful", vcr: { record: :none } do
expect(outcome).to be_success
expect(result).to be_an(Array)
end
end
end
end
Loading

0 comments on commit d6f17ac

Please sign in to comment.