Sha256: 79243cbfdb1ce31e7d67118e4e8e4a83790c6190fdb7ec77a4bbe5555f539685
Contents?: true
Size: 1.87 KB
Versions: 3
Compression:
Stored size: 1.87 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) } Aitch::Request .should_receive(:new) .with(expected) .and_return(request) Aitch.get("URL", "DATA", "HEADERS", options) end it "performs request" do Aitch::Request.stub new: request request.should_receive(:perform) Aitch.get("URL") end end describe "#execute!" do it "returns response when successful" do response = double(error?: false) Aitch::Request.any_instance.stub perform: response expect(Aitch.get!("URL")).to eql(response) end it "raises when has errors" do response = double(error?: true, error: "ERROR") Aitch::Request.any_instance.stub perform: response expect { Aitch.get!("URL") }.to raise_error("ERROR") end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
aitch-0.3.0 | spec/aitch/aitch_spec.rb |
aitch-0.2.1 | spec/aitch/aitch_spec.rb |
aitch-0.2.0 | spec/aitch/aitch_spec.rb |