Sha256: 955da4b27a4a3f3b19bad9d80fe74539fb496fccd7c262aa0c7f44a85372bdf4

Contents?: true

Size: 1.33 KB

Versions: 21

Compression:

Stored size: 1.33 KB

Contents

require 'rest-core/test'

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

    would 'do nothing' do
      env = {RC::RESPONSE_BODY => []}
      app.call(env) do |res|
        res.should.eq(env)
        res[RC::RESPONSE_BODY].should.kind_of?(Array)
      end
    end

    would 'smash' do
      app.call(RC::RESPONSE_BODY => {}) do |res|
        body = res[RC::RESPONSE_BODY]
        body.should.kind_of?(RC::Smash)
        body.should.empty?
        body[0].should.eq(nil)
        body[0, 0].should.eq(nil)
      end
    end

    describe 'client' do
      body = {0 => {1 => 2}}
      client = RC::Builder.client do
        use RC::SmashResponse, true
        run Class.new{
          define_method(:call) do |env, &block|
            block.call(env.merge(RC::RESPONSE_BODY => body))
          end
        }
      end

      would 'do nothing' do
        b = client.new(:smash_response => false).get(''){ |res|
          res.should.eq(body)
          res.should.kind_of?(Hash)
        }.get('')
        b.should.eq(body)
        b.should.kind_of?(Hash)
      end

      would 'clash' do
        b = client.new.get(''){ |res|
          res.should.eq(body)
          res.should.kind_of?(RC::Smash)
        }.get('')
        b.should.eq(body)
        b.should.kind_of?(RC::Smash)
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
rest-core-4.0.1 test/test_smash_response.rb
rest-core-4.0.0 test/test_smash_response.rb
rest-core-3.6.0 test/test_smash_response.rb
rest-core-3.5.92 test/test_smash_response.rb
rest-core-3.5.91 test/test_smash_response.rb
rest-core-3.5.9 test/test_smash_response.rb
rest-core-3.5.8 test/test_smash_response.rb
rest-core-3.5.7 test/test_smash_response.rb
rest-core-3.5.6 test/test_smash_response.rb
rest-core-3.5.5 test/test_smash_response.rb
rest-core-3.5.4 test/test_smash_response.rb
rest-core-3.5.3 test/test_smash_response.rb
rest-core-3.5.2 test/test_smash_response.rb
rest-core-3.5.1 test/test_smash_response.rb
rest-core-3.5.0 test/test_smash_response.rb
rest-core-3.4.1 test/test_smash_response.rb
rest-core-3.4.0 test/test_smash_response.rb
rest-core-3.3.3 test/test_smash_response.rb
rest-core-3.3.2 test/test_smash_response.rb
rest-core-3.3.1 test/test_smash_response.rb