Sha256: 261e9a107cbc3cb19226582d4f13019167ee95a721295849f1c6268da9e43fed

Contents?: true

Size: 898 Bytes

Versions: 3

Compression:

Stored size: 898 Bytes

Contents

require "spec_helper"
require "espago/api_connection"
require "json"

class StubbedResponse < Struct.new(:body, :status); end

class Espago::ApiConnection::PathStubbed
  def initialize(connection); end

  def request(params = {})
    StubbedResponse.new("{\"data\":\"returned api data\"}", 200)
  end
end

class Espago::ApiConnection::PathUnauthorized
  def initialize(connection)
  end

  def request(params = {})
    StubbedResponse.new(nil, 401)
  end
end


describe Espago::ApiConnection do
  subject { Espago::ApiConnection.new("http://some.api.example.com",{'Accept' => "application/vnd.espago.v2+json"}) }

  context "#create" do
    it "returns response" do
      expect(subject.create(:path, :stubbed)).to be_a_kind_of Espago::Response
    end
    it "raises auth error" do
      expect { subject.create(:path, :unauthorized) }.to raise_error Espago::AuthenticationError
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
espago-0.1.11 spec/espago/api_connection_spec.rb
espago-0.1.10 spec/espago/api_connection_spec.rb
espago-0.1.9 spec/espago/api_connection_spec.rb