Sha256: 049f266bc7cadd9391ac82604e6850416c760ae1d2d3a70d21dc628db170b571

Contents?: true

Size: 1.43 KB

Versions: 10

Compression:

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

10 entries across 10 versions & 1 rubygems

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