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.6.0-java spec/api_client/base/parsing_spec.rb
api_client-0.6.0 spec/api_client/base/parsing_spec.rb
api_client-0.5.26-java spec/api_client/base/parsing_spec.rb
api_client-0.5.26 spec/api_client/base/parsing_spec.rb
api_client-0.5.25-java spec/api_client/base/parsing_spec.rb
api_client-0.5.25 spec/api_client/base/parsing_spec.rb
api_client-0.5.24 spec/api_client/base/parsing_spec.rb
api_client-0.5.22 spec/api_client/base/parsing_spec.rb
api_client-0.5.21 spec/api_client/base/parsing_spec.rb
api_client-0.5.20 spec/api_client/base/parsing_spec.rb
api_client-0.5.19 spec/api_client/base/parsing_spec.rb
api_client-0.5.18 spec/api_client/base/parsing_spec.rb
api_client-0.5.17 spec/api_client/base/parsing_spec.rb
api_client-0.5.16 spec/api_client/base/parsing_spec.rb
api_client-0.5.15 spec/api_client/base/parsing_spec.rb
api_client-0.5.14 spec/api_client/base/parsing_spec.rb
api_client-0.5.13 spec/api_client/base/parsing_spec.rb
api_client-0.5.12 spec/api_client/base/parsing_spec.rb
api_client-0.5.11 spec/api_client/base/parsing_spec.rb
api_client-0.5.9 spec/api_client/base/parsing_spec.rb