Sha256: 10acdc32a5e96d9da6ad22a055bff450b1a3d943f60ebb83df6c3b89966ac37d

Contents?: true

Size: 1.57 KB

Versions: 1

Compression:

Stored size: 1.57 KB

Contents

require 'spec_helper'
require 'espago/client'
require "helpers/fake_response"

class StubbedApiConnection
  def initialize(enviroment,headers); end
  def authenticate(app_id, app_password); end
  def create(path, method, params= {})
    'returned api data'
  end
end

describe Espago::Client do
  subject { Espago::Client.new( app_id: 'app_id_test', app_password: 'secret', connection: stubbed_api_connection, api_version: 2) }
  let(:stubbed_api_connection) { StubbedApiConnection }
  let(:response) { FakeResponse.new(200, {id: 1, status: "2012"}.to_json) }

  it { subject.should respond_to :app_id }
  it { subject.should respond_to :app_password }
  it { subject.should respond_to :public_key }
  it { subject.should respond_to :api_version }

  context "#send_request" do
    let(:method) { :get }
    let(:path) { :new_client }
    let(:params) { { name: "Jan Kowalski"} }

    it "should create an api request" do
      subject.send_request(path, method, params).should eq('returned api data')
    end

    context "with no credentials" do
      subject { Espago::Client.new }

      it "should raise error" do
        expect { subject.send_request(path, method, params)}.to raise_error(Espago::Client::NotAuthenticated)
      end
    end
  end

  context "#parse_response" do
    subject { Espago::Client.new }

    it "should delegate work to parser" do
      Espago::Response.should_receive(:new).with(response)
      subject.parse_response(response)
    end

    it "should parse response into object" do
      subject.parse_response(response).class.should eq(Espago::Response)
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
espago-0.1.2 spec/espago/client_spec.rb