Sha256: a5f674da3c6c840bde55e24ed60dac24392b0a368c59edfd23956e8768ca7157

Contents?: true

Size: 899 Bytes

Versions: 20

Compression:

Stored size: 899 Bytes

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




end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
api_client-0.5.0 spec/api_client/base/parsing_spec.rb
api_client-0.4.3 spec/api_client/base/parsing_spec.rb
api_client-0.4.2 spec/api_client/base/parsing_spec.rb
api_client-0.4.1 spec/api_client/base/parsing_spec.rb
api_client-0.3.3 spec/api_client/base/parsing_spec.rb
api_client-0.4.0 spec/api_client/base/parsing_spec.rb
api_client-0.3.2 spec/api_client/base/parsing_spec.rb
api_client-0.3.1 spec/api_client/base/parsing_spec.rb
api_client-0.3.0 spec/api_client/base/parsing_spec.rb
api_client-0.2.0 spec/api_client/base/parsing_spec.rb
api_client-0.1.9 spec/api_client/base/parsing_spec.rb
api_client-0.1.8 spec/api_client/base/parsing_spec.rb
api_client-0.1.7 spec/api_client/base/parsing_spec.rb
api_client-0.1.6 spec/api_client/base/parsing_spec.rb
api_client-0.1.5 spec/api_client/base/parsing_spec.rb
api_client-0.1.4 spec/api_client/base/parsing_spec.rb
api_client-0.1.3 spec/api_client/base/parsing_spec.rb
api_client-0.1.2 spec/api_client/base/parsing_spec.rb
api_client-0.1.1 spec/api_client/base/parsing_spec.rb
api_client-0.1.0 spec/api_client/base/parsing_spec.rb