Sha256: e137205defafd74ee45df71446d68aacf969f4a660a4a4ee0409fa2b31b41215

Contents?: true

Size: 1.44 KB

Versions: 2

Compression:

Stored size: 1.44 KB

Contents

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

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

test "text-book example" do |env|
  Cuba.define do
    on "posts/:id" do |id|
      res.write id
    end
  end

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

  assert_equal ["123"], resp.body
end

test "multi-param" do |env|
  Cuba.define do
    on "u/:uid/posts/:id" do |uid, id|
      res.write uid
      res.write id
    end
  end

  env["PATH_INFO"] = "/u/jdoe/posts/123"

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

  assert_equal ["jdoe", "123"], resp.body
end

test "regex nesting" do |env|
  Cuba.define do
    on(/u\/(\w+)/) do |uid|
      res.write uid

      on(/posts\/(\d+)/) do |id|
        res.write id
      end
    end
  end

  env["PATH_INFO"] = "/u/jdoe/posts/123"

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

  assert_equal ["jdoe", "123"], resp.body
end

test "regex nesting colon param style" do |env|
  Cuba.define do
    on(/u:(\w+)/) do |uid|
      res.write uid

      on(/posts:(\d+)/) do |id|
        res.write id
      end
    end
  end

  env["PATH_INFO"] = "/u:jdoe/posts:123"

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

  assert_equal ["jdoe", "123"], resp.body
end

test "symbol matching" do |env|
  Cuba.define do
    on "user", :id do |uid|
      res.write uid

      on "posts", :pid do |id|
        res.write id
      end
    end
  end

  env["PATH_INFO"] = "/user/jdoe/posts/123"

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

  assert_equal ["jdoe", "123"], resp.body
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cuba-3.0.0.rc2 test/match.rb
cuba-3.0.0.rc1 test/match.rb