Sha256: 98f522aac2d39e044280e0309c2f95fc4e3c2bd8238ebf782b394742790fe97e

Contents?: true

Size: 1.1 KB

Versions: 24

Compression:

Stored size: 1.1 KB

Contents

require 'test/spec'
require 'rack/mock'

class Flame
  def call(env)
    env['flame'] = 'F Lifo..'
  end
end

class Pacify
  def initialize(with)
    @with = with
  end

  def call(env)
    env['peace'] = @with
  end
end

class Finale
  def call(response)
    status, headers, body = response

    headers['last'] = 'Finale'
    $old_status = status

    [201, headers, body]
  end
end

class TheEnd
  def call(response)
    status, headers, body = response

    headers['last'] = 'TheEnd'
    [201, headers, body]
  end
end

context "Rack::Callbacks" do
  specify "works for love and small stack trace" do
    callback_app = Rack::Callbacks.new do
      before Flame
      before Pacify, "with love"

      run lambda {|env| [200, {}, [env['flame'], env['peace']]] }

      after Finale
      after TheEnd
    end

    app = Rack::Builder.new do
      run callback_app
    end.to_app

    response = Rack::MockRequest.new(app).get("/")

    response.body.should.equal 'F Lifo..with love'

    $old_status.should.equal 200
    response.status.should.equal 201

    response.headers['last'].should.equal 'TheEnd'
  end
end

Version data entries

24 entries across 24 versions & 8 rubygems

Version Path
tricycle-rack-contrib-0.9.5 test/spec_rack_callbacks.rb
tricycle-rack-contrib-0.9.0 test/spec_rack_callbacks.rb
rack-contrib-with-working-jsonp-0.9.2.1 test/spec_rack_callbacks.rb
rack-contrib-0.9.2 test/spec_rack_callbacks.rb