Skip to content

Commit c2049e2

Browse files
committed
Be more specific in specs, use JSON output.
1 parent 8daeb59 commit c2049e2

File tree

7 files changed

+255
-127
lines changed

7 files changed

+255
-127
lines changed

lib/grape-swagger.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def self.setup(options)
6767
routes_array = routes.keys.map do |local_route|
6868
{ :path => "#{parse_path(route.route_path.gsub('(.:format)', ''),route.route_version)}/#{local_route}#{@@hide_format ? '' : '.{format}'}" }
6969
end
70+
7071
{
7172
apiVersion: api_version,
7273
swaggerVersion: "1.1",
@@ -174,7 +175,7 @@ def parse_path(path, version)
174175
def parse_http_codes codes
175176
codes ||= {}
176177
codes.collect do |k, v|
177-
{:code => k, :reason => v}
178+
{ code: k, reason: v }
178179
end
179180
end
180181

spec/default_api_spec.rb

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
describe "Default API" do
44

5-
before(:all) do
5+
before :all do
66
class NotAMountedApi < Grape::API
7-
desc 'this gets something'
7+
format :json
8+
desc 'This gets something.'
89
get '/something' do
9-
{:bla => 'something'}
10+
{ bla: 'something' }
1011
end
1112
add_swagger_documentation
1213
end
@@ -16,7 +17,16 @@ def app; NotAMountedApi; end
1617

1718
it "should document something" do
1819
get '/swagger_doc'
19-
last_response.body.should == "{:apiVersion=>\"0.1\", :swaggerVersion=>\"1.1\", :basePath=>\"http://example.org\", :operations=>[], :apis=>[{:path=>\"/swagger_doc/something.{format}\"}, {:path=>\"/swagger_doc/swagger_doc.{format}\"}]}"
20+
JSON.parse(last_response.body).should == {
21+
"apiVersion" => "0.1",
22+
"swaggerVersion" => "1.1",
23+
"basePath" => "http://example.org",
24+
"operations" => [],
25+
"apis" => [
26+
{ "path" => "/swagger_doc/something.{format}" },
27+
{ "path" => "/swagger_doc/swagger_doc.{format}" }
28+
]
29+
}
2030
end
2131

2232
end

spec/grape-swagger-helper_spec.rb

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,85 +2,86 @@
22

33
describe "helpers" do
44

5-
before(:all) do
5+
before :all do
66
class HelperTestAPI < Grape::API
77
add_swagger_documentation
88
end
9+
end
910

11+
before :each do
1012
@api = Object.new
13+
1114
# after injecting grape-swagger into the Test API we get the helper methods
1215
# back from the first endpoint's class (the API mounted by grape-swagger
1316
# to serve the swagger_doc
14-
@api.extend HelperTestAPI.endpoints.first.options[:app].helpers
1517

18+
@api.extend HelperTestAPI.endpoints.first.options[:app].helpers
1619
end
1720

1821
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
2023
params = {
21-
name: {type: 'String', :desc => "A name", required: true },
24+
name: { type: 'String', desc: "A name", required: true },
2225
level: 'max'
2326
}
2427
path = "/coolness"
2528
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 }
3032
]
3133
end
3234

33-
it "should parse params as form for a POST" do
35+
it "parses params as form for a POST" do
3436
params = {
35-
name: {type: 'String', :desc =>"A name", required: true },
37+
name: { type: 'String', :desc => "A name", required: true },
3638
level: 'max'
3739
}
3840
path = "/coolness"
3941
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 }
4445
]
4546
end
4647
end
4748

4849
context "parsing the path" do
49-
it "should parse the path" do
50+
it "parses the path" do
5051
path = ":abc/def(.:format)"
5152
@api.parse_path(path, nil).should == "{abc}/def.{format}"
5253
end
5354

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
5556
path = "abc/:def_g(.:format)"
5657
@api.parse_path(path, nil).should == "abc/{def_g}.{format}"
57-
5858
end
5959

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
6161
path = "abc/:sha1(.:format)"
6262
@api.parse_path(path, nil).should == "abc/{sha1}.{format}"
6363
end
6464

65-
it "should parse a path that has multiple variables" do
65+
it "parses a path that has multiple variables" do
6666
path1 = "abc/:def/:geh(.:format)"
6767
path2 = "abc/:def:geh(.:format)"
6868
@api.parse_path(path1, nil).should == "abc/{def}/{geh}.{format}"
6969
@api.parse_path(path2, nil).should == "abc/{def}{geh}.{format}"
7070
end
7171

72-
it "should parse the path with a specified version" do
72+
it "parses the path with a specified version" do
7373
path = ":abc/{version}/def(.:format)"
7474
@api.parse_path(path, 'v1').should == "{abc}/v1/def.{format}"
7575
end
7676
end
7777

7878
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 }
8485
]
8586
end
8687
end

spec/grape-swagger_spec.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,4 @@
1010
Grape::API.should respond_to :add_swagger_documentation
1111
end
1212

13-
14-
1513
end

0 commit comments

Comments
 (0)