Sha256: 3d04f50898ef25ab6b3be6453ae15188da9de1d8c6d44b645e28db2f89387ac9

Contents?: true

Size: 1.44 KB

Versions: 2

Compression:

Stored size: 1.44 KB

Contents

# encoding: UTF-8

require 'spec_helper'
require 'support/account'
require 'wakatime'
require 'webmock/rspec'

describe Wakatime::Session do
  before do

    @session = Wakatime::Session.new(
                                       api_key: 'Lame Key'
    )

    @client = Wakatime::Client.new(@session)

  end

  it 'raises a RequestError if a badly formed request detected by the server' do
    stub_request(:get, /.*\/summary.*/).to_return(status: 401, body: '{\n  \"errors\": [\n    \"UNAUTHORIZED\"\n  ]\n}', headers: {})
    expect { @client.summary }.to raise_error(Wakatime::AuthError)

    # make sure status and body is
    # set on error object.
    begin
      @client.summary
    rescue StandardError => e
      expect(e.body).to eq '{\n  \"errors\": [\n    \"UNAUTHORIZED\"\n  ]\n}'
      expect(e.status).to eq 401
    end
  end

  it 'raises a ServerError if the server raises a 500 error' do
    stub_request(:get, /.*\/summary.*/)
    .to_return(status: 503, body: '{"type": "error", "status": 503, "message": "We messed up!"}', headers: {})
    expect { @client.summary }.to raise_error(Wakatime::ServerError)

    # make sure status and body is
    # set on error object.
    begin
      @client.summary
    rescue StandardError => e
      expect(e.body).to eq '{"type": "error", "status": 503, "message": "We messed up!"}' # TODO establish what happens when wakatime returns a 500 or something else.
      expect(e.status).to eq 503
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
wakatime-0.1.0 spec/session_spec.rb
wakatime-0.0.2 spec/session_spec.rb