Sha256: 714801ecc80c9fa62fb1021a14d0b73cb8a5e3bcfd83641c57af1c2e201ed805

Contents?: true

Size: 1.68 KB

Versions: 1

Compression:

Stored size: 1.68 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!) }
  end

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

    it "delegates to Request" do
      Aitch::Request
        .should_receive(:new)
        .with("METHOD", "URL", "ARGS", "HEADERS", "OPTIONS")
        .and_return(request)

      Aitch.execute("METHOD", "URL", "ARGS", "HEADERS", "OPTIONS")
    end

    it "performs request" do
      Aitch::Request.stub new: request
      request.should_receive(:perform)

      Aitch.execute("METHOD", "URL")
    end
  end

  describe "#execute!" do
    it "returns response when successful" do
      response = stub(error?: false)
      Aitch::Request.any_instance.stub perform: response

      expect(Aitch.execute!("METHOD", "URL")).to eql(response)
    end

    it "raises when has errors" do
      response = stub(error?: true, error: "ERROR")
      Aitch::Request.any_instance.stub perform: response

      expect {
        Aitch.execute!("METHOD", "URL")
      }.to raise_error("ERROR")
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
aitch-0.1.0 spec/aitch/aitch_spec.rb