Sha256: abd1a6f6750ead113544f86b3cd16f63bde5d4a8df8052924739d9591d062f77

Contents?: true

Size: 1.15 KB

Versions: 6

Compression:

Stored size: 1.15 KB

Contents

require 'rest-core/test'

describe RC::JsonResponse do
  describe 'app' do
    app = RC::JsonResponse.new(RC::Dry.new, true)

    should 'do nothing' do
      expected = {RC::RESPONSE_BODY => nil,
                  RC::REQUEST_HEADERS => {'Accept' => 'application/json'}}
      app.call({}){ |response| response.should.eq(expected) }
    end

    should 'decode' do
      expected = {RC::RESPONSE_BODY => {},
                  RC::REQUEST_HEADERS => {'Accept' => 'application/json'}}
      app.call(RC::RESPONSE_BODY => '{}'){ |response|
        response.should.eq(expected)
      }
    end
  end

  describe 'client' do
    client = RC::Builder.client do
      use RC::JsonResponse, true
      run Class.new{
        def call env
          yield(env.merge(RC::RESPONSE_BODY => '{}'))
        end
      }
    end

    should 'do nothing' do
      expected = '{}'
      client.new(:json_response => false).get(''){ |response|
        response.should.eq(expected)
      }.get('').should.eq(expected)
    end

    should 'decode' do
      expected = {}
      client.new.get(''){ |response|
        response.should.eq(expected)
      }.get('').should.eq(expected)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rest-core-3.1.1 test/test_json_response.rb
rest-core-3.1.0 test/test_json_response.rb
rest-core-3.0.0 test/test_json_response.rb
rest-core-2.1.2 test/test_json_response.rb
rest-core-2.1.1 test/test_json_response.rb
rest-core-2.1.0 test/test_json_response.rb