Sha256: 21287feebec2954f053029a2c4af6eee54206e0c403605d73cdc56b1ef985b04

Contents?: true

Size: 1.39 KB

Versions: 2

Compression:

Stored size: 1.39 KB

Contents

require File.expand_path("helper", File.dirname(__FILE__))

setup do
  { "SCRIPT_NAME" => "/", "PATH_INFO" => "/about" }
end

test "one level path" do |env|
  Cuba.define do
    on "about" do
      res.write "About"
    end
  end

  _, _, resp = Cuba.call(env)

  assert_equal ["About"], resp.body
  assert_equal({ "SCRIPT_NAME" => "/", "PATH_INFO" => "/about" }, env)
end

test "two level nested paths" do |env|
  Cuba.define do
    on "about" do
      on "1" do
        res.write "+1"
      end

      on "2" do
        res.write "+2"
      end
    end
  end

  env["PATH_INFO"] = "/about/1"

  _, _, resp = Cuba.call(env)

  assert_equal ["+1"], resp.body

  env["PATH_INFO"] = "/about/2"

  _, _, resp = Cuba.call(env)

  assert_equal ["+2"], resp.body
end

test "two level inlined paths" do |env|
  Cuba.define do
    on "a/b" do
      res.write "a"
      res.write "b"
    end
  end

  env["PATH_INFO"] = "/a/b"

  _, _, resp = Cuba.call(env)

  assert_equal ["a", "b"], resp.body
end

test "a path with some regex captures" do |env|
  Cuba.define do
    on "user(\\d+)" do |uid|
      res.write uid
    end
  end

  env["PATH_INFO"] = "/user123"

  _, _, resp = Cuba.call(env)

  assert_equal ["123"], resp.body
end

test "matching the root" do |env|
  Cuba.define do
    on "" do
      res.write "Home"
    end
  end

  env["PATH_INFO"] = "/"

  _, _, resp = Cuba.call(env)

  assert_equal ["Home"], resp.body
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cuba-2.0.0.rc2 test/path.rb
cuba-2.0.0.rc1 test/path.rb