Sha256: f5f3887a661f73ffe9933131c237c98a12e5e3470148681c163e9fb8d30f8f15

Contents?: true

Size: 1.93 KB

Versions: 2

Compression:

Stored size: 1.93 KB

Contents

require "spec_helper"

describe Aitch do
  context "request methods" do
    it { should respond_to(:get) }
    it { should respond_to(:get!) }
    it { should respond_to(:post) }
    it { should respond_to(:post!) }
    it { should respond_to(:put) }
    it { should respond_to(:put!) }
    it { should respond_to(:patch) }
    it { should respond_to(:patch!) }
    it { should respond_to(:delete) }
    it { should respond_to(:delete!) }
    it { should respond_to(:head) }
    it { should respond_to(:head!) }
    it { should respond_to(:options) }
    it { should respond_to(:options!) }
    it { should respond_to(:trace) }
    it { should respond_to(:trace!) }
    it { should respond_to(:execute) }
    it { should respond_to(:execute!) }
    it { should respond_to(:config) }
    it { should respond_to(:configuration) }
  end

  describe "#execute" do
    let(:request) { double.as_null_object }

    it "delegates to Request" do
      options = {}

      expected = {
        request_method: "get",
        url: "URL",
        data: "DATA",
        headers: "HEADERS",
        options: options.merge(Aitch.config.to_h)
      }

      expect(Aitch::Request).to receive(:new).with(expected).and_return(request)

      Aitch.get("URL", "DATA", "HEADERS", options)
    end

    it "performs request" do
      allow(Aitch::Request).to receive(:new).and_return(request)
      expect(request).to receive(:perform)

      Aitch.get("URL")
    end
  end

  describe "#execute!" do
    it "returns response when successful" do
      response = double(error?: false)
      allow_any_instance_of(Aitch::Request).to receive(:perform).and_return(response)

      expect(Aitch.get!("URL")).to eql(response)
    end

    it "raises when has errors" do
      response = double(error?: true, error: "ERROR")
      allow_any_instance_of(Aitch::Request).to receive(:perform).and_return(response)

      expect {
        Aitch.get!("URL")
      }.to raise_error("ERROR")
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
aitch-0.4.1 spec/aitch/aitch_spec.rb
aitch-0.4.0 spec/aitch/aitch_spec.rb