Sha256: 15e0da064f24916e50ecd4a2d8b8a1e70bdeeadeaf0ca7dc632459b525440a7a

Contents?: true

Size: 1.22 KB

Versions: 5

Compression:

Stored size: 1.22 KB

Contents

require 'rest-core/test'

describe RC::JsonResponse do
  describe 'app' do
    def app
      @app ||= RC::JsonResponse.new(RC::Dry.new, true)
    end

    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
    def client
      @client ||= RC::Builder.client do
        use RC::JsonResponse, true
        run Class.new{
          def call env
            yield(env.merge(RC::RESPONSE_BODY => '{}'))
          end
        }
      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

5 entries across 5 versions & 1 rubygems

Version Path
rest-core-2.0.4 test/test_json_response.rb
rest-core-2.0.3 test/test_json_response.rb
rest-core-2.0.2 test/test_json_response.rb
rest-core-2.0.1 test/test_json_response.rb
rest-core-2.0.0 test/test_json_response.rb