test/all.rb in syro-0.0.8 vs test/all.rb in syro-1.0.0
- old
+ new
@@ -9,16 +9,24 @@
res[Rack::CONTENT_TYPE] = "text/plain"
res.write(str)
end
end
+class DefaultHeaders < Syro::Deck
+ def default_headers
+ { Rack::CONTENT_TYPE => "text/html" }
+ end
+end
+
textual = Syro.new(TextualDeck) {
get {
text("GET /textual")
}
}
+default_headers = Syro.new(DefaultHeaders) { }
+
admin = Syro.new {
get {
res.write("GET /admin")
}
}
@@ -104,10 +112,16 @@
on(:id) {
res.write(sprintf("GET /users/%s", inbox[:id]))
}
}
+ on("articles") {
+ on(:id) { |id|
+ res.write(sprintf("GET /articles/%s", id))
+ }
+ }
+
on("posts") {
@path = path.prev
on(:post_id) {
on("comments") {
@@ -135,10 +149,14 @@
}
on("textual") {
run(textual)
}
+
+ on("headers") {
+ run(default_headers)
+ }
}
setup do
Driver.new(app)
end
@@ -197,10 +215,14 @@
test "captures" do |f|
f.get("/users/42")
assert_equal "GET /users/42", f.last_response.body
assert_equal 200, f.last_response.status
+
+ f.get("/articles/23")
+ assert_equal "GET /articles/23", f.last_response.body
+ assert_equal 200, f.last_response.status
end
test "post values" do |f|
f.post("/", "user" => { "username" => "foo" })
assert_equal "POST / (user)", f.last_response.body
@@ -239,6 +261,12 @@
test "custom deck" do |f|
f.get("/textual")
assert_equal "GET /textual", f.last_response.body
assert_equal "text/plain", f.last_response.headers["Content-Type"]
assert_equal 200, f.last_response.status
+end
+
+test "default headers" do |f|
+ f.get("/headers")
+
+ assert_equal "text/html", f.last_response.headers["Content-Type"]
end