Sha256: ab7cfbc6c1d5036ef86983efcedfc70d7d0b0b57cfac3168be4d42017b29ec19

Contents?: true

Size: 1.45 KB

Versions: 2

Compression:

Stored size: 1.45 KB

Contents

require 'spec_helper'

describe Balanced::Error, '#response' do
  it "sets the response in the initializer" do
    response = {:status => 200}
    Balanced::Error.new(response).response.should == response
  end
end

describe Balanced::Error, '#body' do
  it 'is constructed from the response[:body]' do
    response = {:body => {}}
    error = Balanced::Error.new(response)
    error.body.should == response[:body]
  end

  it "defaults to an empty hash when no body is passed" do
    Balanced::Error.new({}).body.should == {}
  end

  describe "generating methods from response keys"  do
    before do
      response = {:body => {:foo => 'bar'}}
      @error = Balanced::Error.new(response)
    end

    it 'generates a getter for each key' do
      @error.foo.should == 'bar'
    end

    it 'generates a predicate method' do
      @error.foo?.should be_true
    end
  end
end

describe Balanced::StandardError do
  subject { Balanced::StandardError.new('ohnoe!') }

  its(:message) { should == 'ohnoe!' }
  its(:error_message) { should == 'ohnoe!' }
  its(:to_s) { should == 'ohnoe!' }
  its(:inspect) { should == '#<Balanced::StandardError: ohnoe!>' }
end

describe Balanced::UnassociatedCardError do
  let(:card) { Balanced::Card.new(:uri => '/v1/marketplaces/123/cards/235') }

  subject do
    Balanced::UnassociatedCardError.new(card)
  end

  its(:message) do
    should == "The Balanced::Card with uri=#{card.attributes['uri']} is not associated to an account"
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
balanced-0.8.2 spec/balanced/error_spec.rb
balanced-0.8.1 spec/balanced/error_spec.rb