Sha256: 2d696e8c34daf3ced5ee7c4c66969eb9716ff3279abd60e8efe14548cc668e61

Contents?: true

Size: 1013 Bytes

Versions: 3

Compression:

Stored size: 1013 Bytes

Contents

require 'spec_helper'

describe Zeppelin::Middleware::JsonParser do
  let(:json_body) { "{\"foo\":\"bar\"}" }

  let(:expected_parsed_body) { { 'foo' => 'bar' } }

  it 'parses a standard JSON content type' do
    process(json_body, 'application/json').body.should eq(expected_parsed_body)
  end

  it 'parses vendor JSON content type' do
    process(json_body, 'application/vnd.urbanairship+json').body.should eq(expected_parsed_body)
  end

  it 'does not change nil body' do
    process(nil).body.should be_nil
  end

  it 'does not parse non-JSON content types' do
    process('<hello>world</hello>', 'text/xml').body.should eq('<hello>world</hello>')
  end

  def process(body, content_type=nil, options={})
    env = { :body => body, :response_headers => Faraday::Utils::Headers.new }
    env[:response_headers]['content-type'] = content_type if content_type

    middleware = Zeppelin::Middleware::JsonParser.new(
      lambda { |env| Faraday::Response.new(env) }
    )

    middleware.call(env)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
zeppelin-0.8.1 spec/middleware/json_parser_spec.rb
zeppelin-0.7.0 spec/middleware/json_parser_spec.rb
zeppelin-0.6.0 spec/middleware/json_parser_spec.rb