Permalink
Browse files

Merge branch 'master' of github.com:soveran/cuba

  • Loading branch information...
2 parents f9442fa + e5dbd0a commit b34c4b7f0f8eabf05ae31110a7c5c53281116296 @soveran committed May 7, 2012
Showing with 38 additions and 1 deletion.
  1. +1 −1 README.md
  2. +37 −0 test/captures.rb
View
@@ -204,7 +204,7 @@ Captures
You may have noticed that some matchers yield a value to the block. The rules
for determining if a matcher will yield a value are simple:
-1. Regex captures: `"posts/(\d+)-(.*)"` will yield two values, corresponding to each capture.
+1. Regex captures: `"posts/(\\d+)-(.*)"` will yield two values, corresponding to each capture.
2. Placeholders: `"users/:id"` will yield the value in the position of :id.
3. Symbols: `:foobar` will yield if a segment is available.
4. File extensions: `extension("css")` will yield the basename of the matched file.
View
@@ -123,3 +123,40 @@
assert_response resp, ["foo/bar.css"]
end
+
+test "regex captures in string format" do
+ Cuba.define do
+ on get, "posts/(\\d+)-(.*)" do |id, slug|
+ res.write id
+ res.write slug
+ end
+ end
+
+
+ env = { "REQUEST_METHOD" => "GET",
+ "PATH_INFO" => "/posts/123-postal-service",
+ "SCRIPT_NAME" => "/" }
+
+ _, _, resp = Cuba.call(env)
+
+
+ assert_response resp, ["123", "postal-service"]
+end
+
+test "regex captures in regex format" do
+ Cuba.define do
+ on get, %r{posts/(\d+)-(.*)} do |id, slug|
+ res.write id
+ res.write slug
+ end
+ end
+
+ env = { "REQUEST_METHOD" => "GET",
+ "PATH_INFO" => "/posts/123-postal-service",
+ "SCRIPT_NAME" => "/" }
+
+ _, _, resp = Cuba.call(env)
+
+
+ assert_response resp, ["123", "postal-service"]
+end

0 comments on commit b34c4b7

Please sign in to comment.