Sha256: 1e0d55364c499672495847f71e56f883315ad5a1fc9574449f3739e0d5081fe4

Contents?: true

Size: 1.1 KB

Versions: 7

Compression:

Stored size: 1.1 KB

Contents

class Shrimp
  def initialize(app)
    @app = app
  end

  def call(env)
    status, headers, body = @app.call(env)

    return [status, headers, body.reverse]
  end
end

test "middleware in main application" do
  Tynn.use(Shrimp)

  Tynn.define do
    get do
      res.write("1")
      res.write("2")
    end
  end

  app = Tynn::Test.new
  app.get("/")

  assert_equal 200, app.res.status
  assert_equal "21", app.res.body
end

test "middleware with composition" do
  Tynn.use(Shrimp)

  Tynn.define do
    on "api" do
      run(API)
    end
  end

  class API < Tynn
  end

  API.define do
    get do
      res.write("1")
      res.write("2")
    end
  end

  app = Tynn::Test.new
  app.get("/api")

  assert_equal 200, app.res.status
  assert_equal "21", app.res.body
end

test "middleware only in child application" do
  class API < Tynn
    use(Shrimp)
  end

  Tynn.define do
    on "api" do
      run(API)
    end
  end

  API.define do
    get do
      res.write("1")
      res.write("2")
    end
  end

  app = Tynn::Test.new
  app.get("/api")

  assert_equal 200, app.res.status
  assert_equal "21", app.res.body
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
tynn-1.4.0 test/middleware_test.rb
tynn-1.3.0 test/middleware_test.rb
tynn-1.2.0 test/middleware_test.rb
tynn-1.1.0 test/middleware_test.rb
tynn-1.0.0 test/middleware_test.rb
tynn-1.0.0.rc3 test/middleware_test.rb
tynn-1.0.0.rc2 test/middleware_test.rb