Sha256: 341deff79866ea75a6d94c1f5c629558c589f3d31774672e249ba39570ecd95f

Contents?: true

Size: 1.11 KB

Versions: 27

Compression:

Stored size: 1.11 KB

Contents

require "spec_helper"

require "multi_xml"

describe ApiClient::Base do

  it "parses json if json is set as format" do
    ApiClient::Base.stub(:format).and_return(:json)
    parsed = ApiClient::Base.parse('{"a":"1"}')
    parsed.should == {"a"=> "1"}
  end

  it "parses xml if xml is set as format" do
    ApiClient::Base.stub(:format).and_return(:xml)
    parsed = ApiClient::Base.parse('<a>1</a>')
    parsed.should == {"a"=> "1"}
  end

  it "returns the string if parser is not found" do
    ApiClient::Base.stub(:format).and_return(:unknown)
    parsed = ApiClient::Base.parse('a:1')
    parsed.should == "a:1"
  end

  it "extracts the body of a Faraday::Response if it is provided" do
    response = Faraday::Response.new(:body => '{"a": "1"}')
    ApiClient::Base.stub(:format).and_return(:json)
    parsed = ApiClient::Base.parse(response)
    parsed.should == {"a"=> "1"}
  end

  it "returns nil if the response is 204" do
    response = Faraday::Response.new(:body => nil, :status => 204)
    ApiClient::Base.stub(:format).and_return(:json)
    parsed = ApiClient::Base.parse(response)
    parsed.should == nil
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
api_client-0.5.7 spec/api_client/base/parsing_spec.rb
api_client-0.5.6 spec/api_client/base/parsing_spec.rb
api_client-0.5.5 spec/api_client/base/parsing_spec.rb
api_client-0.5.4 spec/api_client/base/parsing_spec.rb
api_client-0.5.3 spec/api_client/base/parsing_spec.rb
api_client-0.5.2 spec/api_client/base/parsing_spec.rb
api_client-0.5.1 spec/api_client/base/parsing_spec.rb