Sha256: 824189c061c028df0ea8134b2a1a3fdc46db44cb20058c5edd5350a1a3c0d8e4

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

# encoding: utf-8

require_relative '../spec_helper'

describe "Api" do
  subject { Riksteatern::Api.new(config) }

  let(:config) {
    Riksteatern::Config.new.tap do |c|
      c.base_url    = base_url
      c.http_client = BounceURI

      c.username = 'foo'
      c.password = 'bar'
    end
  }

  let(:base_url) { 'https://api.test:1234/api' }

  describe "get" do
    it "should raise an exception if the username is blank" do
      config.username = nil

      -> { Riksteatern::Api.new(config).get('foo') }.
        must_raise Riksteatern::UnauthorizedUser
    end
  end

  describe "get_json" do
    it "returns parsed JSON" do
      expected_venue_name = 'Finlandsinstitutet, Sibeliussalen'

      subject.stub(:http_get, fixture('lokal/0180126')) do
        subject.get_json(:lokal)['venueName'].must_equal expected_venue_name
      end
    end

    it "loads a blank JSON document if the GET request returns nil" do
      subject.stub(:get, nil) do
        subject.get_json(:unknown).must_equal({})
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
riksteatern-0.0.1 spec/riksteatern/api_spec.rb