|
2 | 2 |
|
3 | 3 | describe "helpers" do |
4 | 4 |
|
5 | | - before(:all) do |
| 5 | + before :all do |
6 | 6 | class HelperTestAPI < Grape::API |
7 | 7 | add_swagger_documentation |
8 | 8 | end |
| 9 | + end |
9 | 10 |
|
| 11 | + before :each do |
10 | 12 | @api = Object.new |
| 13 | + |
11 | 14 | # after injecting grape-swagger into the Test API we get the helper methods |
12 | 15 | # back from the first endpoint's class (the API mounted by grape-swagger |
13 | 16 | # to serve the swagger_doc |
14 | | - @api.extend HelperTestAPI.endpoints.first.options[:app].helpers |
15 | 17 |
|
| 18 | + @api.extend HelperTestAPI.endpoints.first.options[:app].helpers |
16 | 19 | end |
17 | 20 |
|
18 | 21 | context "parsing parameters" do |
19 | | - it "should parse params as query strings for a GET" do |
| 22 | + it "parses params as query strings for a GET" do |
20 | 23 | params = { |
21 | | - name: {type: 'String', :desc => "A name", required: true }, |
| 24 | + name: { type: 'String', desc: "A name", required: true }, |
22 | 25 | level: 'max' |
23 | 26 | } |
24 | 27 | path = "/coolness" |
25 | 28 | method = "GET" |
26 | | - @api.parse_params(params, path, method).should == |
27 | | - [ |
28 | | - {paramType: "query", name: :name, description:"A name", dataType: "String", required: true}, |
29 | | - {paramType: "query", name: :level, description:"", dataType: "String", required: false} |
| 29 | + @api.parse_params(params, path, method).should == [ |
| 30 | + { paramType: "query", name: :name, description: "A name", dataType: "String", required: true }, |
| 31 | + { paramType: "query", name: :level, description: "", dataType: "String", required: false } |
30 | 32 | ] |
31 | 33 | end |
32 | 34 |
|
33 | | - it "should parse params as form for a POST" do |
| 35 | + it "parses params as form for a POST" do |
34 | 36 | params = { |
35 | | - name: {type: 'String', :desc =>"A name", required: true }, |
| 37 | + name: { type: 'String', :desc => "A name", required: true }, |
36 | 38 | level: 'max' |
37 | 39 | } |
38 | 40 | path = "/coolness" |
39 | 41 | method = "POST" |
40 | | - @api.parse_params(params, path, method).should == |
41 | | - [ |
42 | | - {paramType: "form", name: :name, description:"A name", dataType: "String", required: true}, |
43 | | - {paramType: "form", name: :level, description:"", dataType: "String", required: false} |
| 42 | + @api.parse_params(params, path, method).should == [ |
| 43 | + { paramType: "form", name: :name, description: "A name", dataType: "String", required: true }, |
| 44 | + { paramType: "form", name: :level, description: "", dataType: "String", required: false } |
44 | 45 | ] |
45 | 46 | end |
46 | 47 | end |
47 | 48 |
|
48 | 49 | context "parsing the path" do |
49 | | - it "should parse the path" do |
| 50 | + it "parses the path" do |
50 | 51 | path = ":abc/def(.:format)" |
51 | 52 | @api.parse_path(path, nil).should == "{abc}/def.{format}" |
52 | 53 | end |
53 | 54 |
|
54 | | - it "should parse a path that has vars with underscores in the name" do |
| 55 | + it "parses a path that has vars with underscores in the name" do |
55 | 56 | path = "abc/:def_g(.:format)" |
56 | 57 | @api.parse_path(path, nil).should == "abc/{def_g}.{format}" |
57 | | - |
58 | 58 | end |
59 | 59 |
|
60 | | - it "should parse a path that has vars with numbers in the name" do |
| 60 | + it "parses a path that has vars with numbers in the name" do |
61 | 61 | path = "abc/:sha1(.:format)" |
62 | 62 | @api.parse_path(path, nil).should == "abc/{sha1}.{format}" |
63 | 63 | end |
64 | 64 |
|
65 | | - it "should parse a path that has multiple variables" do |
| 65 | + it "parses a path that has multiple variables" do |
66 | 66 | path1 = "abc/:def/:geh(.:format)" |
67 | 67 | path2 = "abc/:def:geh(.:format)" |
68 | 68 | @api.parse_path(path1, nil).should == "abc/{def}/{geh}.{format}" |
69 | 69 | @api.parse_path(path2, nil).should == "abc/{def}{geh}.{format}" |
70 | 70 | end |
71 | 71 |
|
72 | | - it "should parse the path with a specified version" do |
| 72 | + it "parses the path with a specified version" do |
73 | 73 | path = ":abc/{version}/def(.:format)" |
74 | 74 | @api.parse_path(path, 'v1').should == "{abc}/v1/def.{format}" |
75 | 75 | end |
76 | 76 | end |
77 | 77 |
|
78 | 78 | context "parsing header parameters" do |
79 | | - it "should parse params for the header" do |
80 | | - params = {"XAuthToken" => { description: "A required header.", required: true}} |
81 | | - @api.parse_header_params(params).should == |
82 | | - [ |
83 | | - {paramType: "header", name: "XAuthToken", description:"A required header.", dataType: "String", required: true} |
| 79 | + it "parses params for the header" do |
| 80 | + params = { |
| 81 | + "XAuthToken" => { description: "A required header.", required: true } |
| 82 | + } |
| 83 | + @api.parse_header_params(params).should == [ |
| 84 | + { paramType: "header", name: "XAuthToken", description: "A required header.", dataType: "String", required: true } |
84 | 85 | ] |
85 | 86 | end |
86 | 87 | end |
|
0 commit comments