0
@@ -6,15 +6,18 @@ describe "In a mapping's path-matcher" do
0
describe "the HTTP method" do
0
handle( Waves::Dispatchers::NotFoundError ) { response.status = 404 }
0
it "is specified with a hash key" do
0
- mapping.response( :get => [ 'somewhere' ] ) { "GET method" }
0
- mapping.response( :put => [ 'somewhere' ] ) { "PUT method" }
0
- mapping.response( :post => [ 'somewhere' ] ) { "POST method" }
0
- mapping.response( :delete => [ 'somewhere' ] ) { "DELETE method" }
0
+ on( :get => [ 'somewhere' ] ) { "GET method" }
0
+ on( :put => [ 'somewhere' ] ) { "PUT method" }
0
+ on( :post => [ 'somewhere' ] ) { "POST method" }
0
+ on( :delete => [ 'somewhere' ] ) { "DELETE method" }
0
mock_request.get("/somewhere").body.should == "GET method"
0
mock_request.put("/somewhere").body.should == "PUT method"
0
@@ -25,72 +28,102 @@ describe "In a mapping's path-matcher" do
0
describe "the request path pattern" do
0
- handle( Waves::Dispatchers::NotFoundError ) { response.status = 404 }
0
- it "is an array given as the value of the HTTP method key" do
0
- mapping.response( :get => [ 'foo' ] ) { 'The Foo' }
0
- mapping.response( :get => [ 'bar', 'baz' ] ) { 'The Bar' }
0
- mock_request.get('/foo').body.should == 'The Foo'
0
- mock_request.get('/bar/baz').body.should == 'The Bar'
0
+ handle( Waves::Dispatchers::NotFoundError ) { response.status = 404 }
0
- it "may be omitted to allow matching all paths" do
0
- mapping.response( {} ) { "pathless" }
0
+ it "is an array given as the value of the HTTP method key" do
0
+ on( :get => [ 'foo' ] ) { 'The Foo' }
0
+ on( :get => [ 'bar', 'baz' ] ) { 'The Bar' }
0
+ mock_request.get('/foo').body.should == 'The Foo'
0
+ mock_request.get('/bar/baz').body.should == 'The Bar'
0
- mock_request.get('/bogus').body.should == 'pathless'
0
- it "may match string literals" do
0
- mapping.response( :get => [ 'kilroy', 'was', 'here'] ) { 'Hello from Kilroy' }
0
+ it "may be omitted to allow matching all paths" do
0
+ on( {} ) { "pathless" }
0
+ mock_request.get('/bogus').body.should == 'pathless'
0
- mock_request.get('/kilroy/was/here').body.should == 'Hello from Kilroy'
0
+ it "may use true to match all paths, while specifying a method" do
0
+ on( :get => [ true ] ) { "pathless" }
0
+ mock_request.get('/bogus').body.should == 'pathless'
0
- # doesn't work for partial matches.
0
- mock_request.get('/kilroy/was').status.should == 404
0
- it "may use symbols as placeholders for a default regex" do
0
- mapping.response( :get => [ :critter, :name ]) { "hi" }
0
+ it "may use true as the last element, to match all remaining components" do
0
+ on( :get => [ "first", true ] ) { "Yes" }
0
+ mock_request.get('/first/second/third').body.should == "Yes"
0
+ mock_request.get('/uno/dos/tres').status.should == 404
0
- mock_request.get('/smurf/papa_smurf').status.should == 200
0
+ it "may match string literals" do
0
+ on( :get => [ 'kilroy', 'was', 'here'] ) { 'Hello from Kilroy' }
0
+ mock_request.get('/kilroy/was/here').body.should == 'Hello from Kilroy'
0
+ # doesn't work for partial matches.
0
+ mock_request.get('/kilroy/was').status.should == 404
0
- # The default regex accepts word characters, hyphens, and underscores only.
0
- mock_request.get('/smurf/moo+cow').status.should == 404
0
- # it "may use hashes to specify placeholders with custom regexes" do
0
- # mapping.response( :get => [ :prisoner, { :prisoner_id => /9430|24601/ } ] ) { "I am Jean Valjean!" }
0
- # mock_request.get("/prisoner/9430").body.should == "I am Jean Valjean!"
0
- # mock_request.get("/prisoner/9431").status.should == 404
0
- it "saves placeholder matches as params" do
0
- mapping.response( :get => [ :critter, :name ]) { "#{params['critter']}, #{params['name']}" }
0
+ it "may use symbols as placeholders for a default regex" do
0
+ on( :get => [ :critter, :name ] ) { "hi" }
0
+ mock_request.get('/smurf/papa_smurf').status.should == 200
0
- mock_request.get('/dwarf/tyrion').body.should == "dwarf, tyrion"
0
- it "may use regexes instead of strings or placeholders, but the matches are not saved" do
0
- # extremely bad example. Don't ever really use this for authentication. If somebody thinks up a
0
- # better use case for pattern components that throw away the matches, please fix this spec.
0
- mapping.response( :get => [ "user", /matthew|mark/, "password", /wehttam|kram/ ]) { "you were able to get logged in!!!!"}
0
+ # it "may use hashes to specify placeholders with custom regexes" do
0
+ # mapping.on( :get => [ :prisoner, { :prisoner_id => /9430|24601/ } ] ) { "I am Jean Valjean!" }
0
+ # mock_request.get("/prisoner/9430").body.should == "I am Jean Valjean!"
0
+ # mock_request.get("/prisoner/9431").status.should == 404
0
- mock_request.get('/user/matthew/password/wehttam').status.should == 200
0
- mock_request.get('/user/matthew/password/nimda').status.should == 404
0
- it "can apparently also use hashes to set default values" do
0
- mapping.response( :get => [ "view", { :mode => 'show' } ] ) { "mode: #{params['mode']}" }
0
+ it "saves placeholder matches as params" do
0
+ on( :get => [ :critter, :name ]) { "#{params['critter']}, #{params['name']}" }
0
+ mock_request.get('/dwarf/tyrion').body.should == "dwarf, tyrion"
0
+ it "may use regexes instead of strings or placeholders, but the matches are not saved" do
0
+ # extremely bad example. Don't ever really use this for authentication. If somebody thinks up a
0
+ # better use case for pattern components that throw away the matches, please fix this spec.
0
+ on( :get => [ "user", /matthew|mark/, "password", /wehttam|kram/ ]) { "you been let in"}
0
+ mock_request.get('/user/matthew/password/wehttam').status.should == 200
0
+ mock_request.get('/user/matthew/password/nimda').status.should == 404
0
+ it "can apparently also use hashes to set default values" do
0
+ on( :get => [ "thingy", { :mode => 'show' } ] ) { "mode: #{params['mode']}" }
0
+ mock_request.get("/thingy").body.should == "mode: show"
0
+ mock_request.get("/thingy/edit").body.should == "mode: edit"
0
- mock_request.get("/view").body.should == "mode: show"
Comments
No one has commented yet.