rack-spec 0.0.5 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,36 +0,0 @@
1
- meta:
2
- baseUri: http://api.example.com/
3
- endpoints:
4
- /recipes:
5
- GET:
6
- parameters:
7
- page:
8
- type: integer
9
- minimum: 1
10
- maximum: 10
11
- private:
12
- type: boolean
13
- rank:
14
- type: float
15
- time:
16
- type: iso8601
17
- kind:
18
- type: string
19
- only:
20
- - mono
21
- - di
22
- - tri
23
- POST:
24
- parameters:
25
- title:
26
- type: string
27
- minimumLength: 3
28
- maximumLength: 10
29
- required: true
30
- /recipes/{id}:
31
- GET:
32
- description: Get the recipe
33
- PUT:
34
- description: Update the recipe
35
- DELETE:
36
- description: Delete the recipe
@@ -1,221 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Rack::Spec do
4
- include Rack::Test::Methods
5
-
6
- before do
7
- stub_const(
8
- "Recipe",
9
- Class.new do
10
- class << self
11
- def get(params)
12
- if params["id"]
13
- { name: "test#{params["id"]}"}
14
- else
15
- [
16
- { name: "test" }
17
- ]
18
- end
19
- end
20
-
21
- def post(params)
22
- { name: "test" }
23
- end
24
-
25
- def put(params)
26
- end
27
-
28
- def delete(params)
29
- end
30
- end
31
- end
32
- )
33
- end
34
-
35
- let(:app) do
36
- Rack::Builder.app do
37
- use Rack::Spec, spec: YAML.load_file("spec/fixtures/spec.yml")
38
- run ->(env) do
39
- [200, {}, ["OK"]]
40
- end
41
- end
42
- end
43
-
44
- let(:path) do
45
- "/recipes"
46
- end
47
-
48
- let(:params) do
49
- {}
50
- end
51
-
52
- let(:env) do
53
- {}
54
- end
55
-
56
- let(:response) do
57
- last_response
58
- end
59
-
60
- subject do
61
- send verb, path, params, env
62
- last_response.status
63
- end
64
-
65
- describe "Validation on GET" do
66
- let(:verb) do
67
- :get
68
- end
69
-
70
- context "with valid request" do
71
- before do
72
- params[:page] = 5
73
- params[:private] = "false"
74
- params[:rank] = 2.0
75
- params[:time] = "2000-01-01T00:00:00+00:00"
76
- params[:kind] = "mono"
77
- end
78
- it { should == 200 }
79
- end
80
-
81
- context "with query parameter invalid on integer" do
82
- before do
83
- params[:page] = "1.0"
84
- end
85
- it { should == 400 }
86
- end
87
-
88
- context "with query parameter invalid on float" do
89
- before do
90
- params[:rank] = "x"
91
- end
92
- it { should == 400 }
93
- end
94
-
95
- context "with query parameter invalid on boolean" do
96
- before do
97
- params[:private] = 1
98
- end
99
- it { should == 400 }
100
- end
101
-
102
- context "with query parameter invalid on iso8601" do
103
- before do
104
- params[:time] = "2000-01-01 00:00:00 +0000"
105
- end
106
- it { should == 400 }
107
- end
108
-
109
- context "with query parameter invalid on minimum" do
110
- before do
111
- params[:page] = 0
112
- end
113
- it { should == 400 }
114
- end
115
-
116
- context "with query parameter invalid on maximum" do
117
- before do
118
- params[:page] = 11
119
- end
120
- it { should == 400 }
121
- end
122
-
123
- context "with query parameter invalid on only" do
124
- before do
125
- params[:kind] = "tetra"
126
- end
127
- it { should == 400 }
128
- end
129
- end
130
-
131
- describe "Validation on POST" do
132
- before do
133
- params[:title] = "test"
134
- end
135
-
136
- let(:verb) do
137
- :post
138
- end
139
-
140
- context "with valid request" do
141
- it { should == 201 }
142
- end
143
-
144
- context "with request body parameter invalid on minimumLength" do
145
- before do
146
- params[:title] = "te"
147
- end
148
- it { should == 400 }
149
- end
150
-
151
- context "with request body parameter invalid on maximumLength" do
152
- before do
153
- params[:title] = "toooooolong"
154
- end
155
- it { should == 400 }
156
- end
157
-
158
- context "with request body parameter invalid on required" do
159
- before do
160
- params.delete(:title)
161
- end
162
- it { should == 400 }
163
- end
164
- end
165
-
166
- describe "Restful" do
167
- context "with GET /recipes" do
168
- it "calls Recipe.index(params)" do
169
- get "/recipes"
170
- response.status.should == 200
171
- response.body.should be_json_as(
172
- [
173
- { name: "test" },
174
- ]
175
- )
176
- end
177
- end
178
-
179
- context "with GET /recipes/{id}" do
180
- it "calls Recipe.get(params)" do
181
- get "/recipes/1"
182
- response.status.should == 200
183
- response.body.should be_json_as(name: "test1")
184
- end
185
- end
186
-
187
- context "with POST /recipes" do
188
- before do
189
- params[:title] = "test"
190
- end
191
-
192
- it "calls Recipe.post(params)" do
193
- post "/recipes", params
194
- response.status.should == 201
195
- response.body.should be_json_as(name: "test")
196
- end
197
- end
198
-
199
- context "with PUT /recipes/{id}" do
200
- it "calls Recipe.put(params)" do
201
- put "/recipes/1"
202
- response.status.should == 204
203
- end
204
- end
205
-
206
- context "with DELETE /recipes/{id}" do
207
- it "calls Recipe.delete(params)" do
208
- delete "/recipes/1"
209
- response.status.should == 204
210
- end
211
- end
212
-
213
- context "with undefined endpoint" do
214
- it "falls back to the inner rack app" do
215
- get "/undefined"
216
- response.status.should == 200
217
- response.body.should == "OK"
218
- end
219
- end
220
- end
221
- end