Sha256: d15f9ee446a5e6c828e5a88ef0a28b1c67fd90ed4dc20c654b920cf0c3b2bfe0

Contents?: true

Size: 1.32 KB

Versions: 10

Compression:

Stored size: 1.32 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
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

10 entries across 10 versions & 1 rubygems

Version Path
cuba-3.0.0.rc2 test/path.rb
cuba-3.0.0.rc1 test/path.rb
cuba-2.2.1 test/path.rb
cuba-2.2.0 test/path.rb
cuba-2.2.0.rc1 test/path.rb
cuba-2.1.0 test/path.rb
cuba-2.1.0.rc1 test/path.rb
cuba-2.0.1 test/path.rb
cuba-2.0.0 test/path.rb
cuba-2.0.0.rc3 test/path.rb