Skip to content

Commit a65838f

Browse files
Merge pull request #45 from dblock/specific-json-specs
Be more specific in specs, use JSON output.
2 parents 997b4c4 + 12d66e4 commit a65838f

11 files changed

+270
-137
lines changed

.rspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--format documentation
2+
--color

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
rvm:
22
- 1.9.3
3+
- 2.0.0
4+

Gemfile.lock

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ GEM
44
activesupport (3.2.13)
55
i18n (= 0.6.1)
66
multi_json (~> 1.0)
7-
backports (2.6.7)
8-
builder (3.2.0)
7+
backports (3.3.2)
8+
builder (3.2.2)
99
coderay (1.0.7)
1010
descendants_tracker (0.0.1)
1111
diff-lcs (1.1.3)
1212
git (1.2.5)
13-
grape (0.4.0)
13+
grape (0.5.0)
1414
activesupport
1515
builder
1616
hashie (>= 1.2.0)
@@ -20,7 +20,7 @@ GEM
2020
rack-accept
2121
rack-mount
2222
virtus
23-
hashie (2.0.3)
23+
hashie (2.0.5)
2424
i18n (0.6.1)
2525
jeweler (1.8.4)
2626
bundler (~> 1.0)
@@ -30,8 +30,8 @@ GEM
3030
json (1.7.3)
3131
kramdown (0.13.7)
3232
method_source (0.8)
33-
multi_json (1.7.2)
34-
multi_xml (0.5.3)
33+
multi_json (1.7.7)
34+
multi_xml (0.5.4)
3535
pry (0.9.10)
3636
coderay (~> 1.0.5)
3737
method_source (~> 0.8)
@@ -61,8 +61,8 @@ GEM
6161
shoulda-matchers (1.2.0)
6262
activesupport (>= 3.0.0)
6363
slop (3.3.2)
64-
virtus (0.5.4)
65-
backports (~> 2.6.1)
64+
virtus (0.5.5)
65+
backports (~> 3.3)
6666
descendants_tracker (~> 0.0.1)
6767

6868
PLATFORMS

grape-swagger.gemspec

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
99

1010
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
1111
s.authors = ["Tim Vandecasteele"]
12-
s.date = "2013-06-19"
12+
s.date = "2013-06-23"
1313
s.description = "A simple way to add proper auto generated documentation - that can be displayed with swagger - to your inline described grape API"
1414
s.email = "[email protected]"
1515
s.extra_rdoc_files = [
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
1818
]
1919
s.files = [
2020
".document",
21+
".rspec",
2122
".rvmrc",
2223
".travis.yml",
2324
"CHANGELOG.markdown",
@@ -30,7 +31,7 @@ Gem::Specification.new do |s|
3031
"grape-swagger.gemspec",
3132
"lib/grape-swagger.rb",
3233
"spec/default_api_spec.rb",
33-
"spec/grape-swagger-helper_spec.rb",
34+
"spec/grape-swagger_helper_spec.rb",
3435
"spec/grape-swagger_spec.rb",
3536
"spec/non_default_api_spec.rb",
3637
"spec/simple_mounted_api_spec.rb",

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 renamed to 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)