rest_shifter 0.0.9 → 0.0.10
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +0 -2
- data/CHANGES +4 -0
- data/lib/rest_shifter/commands/create.rb +2 -0
- data/lib/rest_shifter/shifter.rb +29 -11
- data/lib/rest_shifter/version.rb +1 -1
- data/spec/flavors/notfound_get.flavor +5 -5
- data/spec/flavors/notfound_get_accept.flavor +8 -0
- data/spec/flavors/notfound_post.flavor +2 -2
- data/spec/flavors/sleep_get.flavor +2 -2
- data/spec/flavors/success_get.flavor +2 -2
- data/spec/flavors/success_post.flavor +2 -2
- data/spec/service_spec.rb +23 -6
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b5c41753cf4e00ae06f8b076c44991a74cb548a6
|
|
4
|
+
data.tar.gz: 6482d5ab7a1389cef63e47854538f88290f8307a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: be7c8c594ab04221c0f8e47131f0655960967d1dc4b4c264b34e03d1901e40f9d9368814725b00cf2e56815f33578b5204d92a08d488b33220ad39f81c18f232
|
|
7
|
+
data.tar.gz: e226bc6576fbd2a44cc3396e0f859a34e6d8b6c64f05deffe2b159b3ca848cc72b3602722e309404a39dc7c8517383307ae5a5a23c0d29ec6cc67ea329dd3abb
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/CHANGES
CHANGED
|
@@ -9,6 +9,8 @@ class RestShifter::Commands::Create
|
|
|
9
9
|
File.open(dirname + "/" + name, 'w') {|f| f.write(
|
|
10
10
|
'method_used = "get"
|
|
11
11
|
path = "/hello_world"
|
|
12
|
+
request_accept = ""
|
|
13
|
+
request_content_type = ""
|
|
12
14
|
response_sleep = 0
|
|
13
15
|
response_status = "200"
|
|
14
16
|
response_body = "{ \"hello_world\" : \"Your service is working fine. :D\" }"
|
data/lib/rest_shifter/shifter.rb
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
require 'sinatra/base'
|
|
2
|
-
require 'sinatra'
|
|
3
2
|
require 'icecream'
|
|
4
3
|
|
|
5
4
|
module RestShifter; end
|
|
@@ -23,21 +22,40 @@ class Shifter < Sinatra::Base
|
|
|
23
22
|
posts_paths = gets.map { |service| service.path }.uniq
|
|
24
23
|
|
|
25
24
|
gets.each do |service|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
if service.request_accept.to_s == ''
|
|
26
|
+
get service.path do
|
|
27
|
+
sleep service.response_sleep
|
|
28
|
+
status service.response_status
|
|
29
|
+
content_type service.response_content_type
|
|
30
|
+
service.response_body
|
|
31
|
+
end
|
|
32
|
+
else
|
|
33
|
+
get service.path, :provides => service.request_accept.to_s == '' ? "" : service.request_accept do
|
|
34
|
+
sleep service.response_sleep
|
|
35
|
+
status service.response_status
|
|
36
|
+
content_type service.response_content_type
|
|
37
|
+
service.response_body
|
|
38
|
+
end
|
|
31
39
|
end
|
|
32
40
|
end
|
|
33
41
|
|
|
34
42
|
posts.each do |service|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
43
|
+
if service.request_accept.to_s == ''
|
|
44
|
+
post service.path do
|
|
45
|
+
sleep service.response_sleep
|
|
46
|
+
status service.response_status
|
|
47
|
+
content_type service.response_content_type
|
|
48
|
+
service.response_body
|
|
49
|
+
end
|
|
50
|
+
else
|
|
51
|
+
post service.path, :provides => service.request_accept.to_s == '' ? "" : service.request_accept do
|
|
52
|
+
sleep service.response_sleep
|
|
53
|
+
status service.response_status
|
|
54
|
+
content_type service.response_content_type
|
|
55
|
+
service.response_body
|
|
56
|
+
end
|
|
40
57
|
end
|
|
41
58
|
end
|
|
42
59
|
|
|
60
|
+
|
|
43
61
|
end
|
data/lib/rest_shifter/version.rb
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
method_used = "get"
|
|
2
2
|
path = "/notfound"
|
|
3
|
-
request_accept =
|
|
4
|
-
request_content_type =
|
|
3
|
+
request_accept = "text/plain"
|
|
4
|
+
request_content_type = ""
|
|
5
5
|
response_sleep = 0
|
|
6
|
-
response_status = "
|
|
7
|
-
response_body = "
|
|
8
|
-
response_content_type = "
|
|
6
|
+
response_status = "201"
|
|
7
|
+
response_body = "This is just a text"
|
|
8
|
+
response_content_type = "text/plain"
|
data/spec/service_spec.rb
CHANGED
|
@@ -9,30 +9,47 @@ describe RestShifter do
|
|
|
9
9
|
|
|
10
10
|
describe Shifter do
|
|
11
11
|
describe "Get Operations" do
|
|
12
|
-
it "
|
|
12
|
+
it "Endpoint for get" do
|
|
13
13
|
get '/ok'
|
|
14
14
|
expect(last_response.status).to eq(200)
|
|
15
15
|
expect(last_response.body).to eq("success")
|
|
16
16
|
expect(last_response.headers['Content-Type']).to eq("application/json")
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
it "
|
|
19
|
+
it "Known bug: Return 400 when has no endpoint with specified accept" do
|
|
20
|
+
header 'Accept', 'application/xml'
|
|
20
21
|
get '/notfound'
|
|
21
22
|
expect(last_response.status).to eq(404)
|
|
22
|
-
expect(last_response.body).to eq("Not Found")
|
|
23
|
-
expect(last_response.headers['Content-Type']).to eq("
|
|
23
|
+
expect(last_response.body).to eq("<h1>Not Found</h1>")
|
|
24
|
+
expect(last_response.headers['Content-Type']).to eq("text/html;charset=utf-8")
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "Should choose right endpoint based on accept header - text" do
|
|
28
|
+
header 'Accept', 'text/plain'
|
|
29
|
+
get '/notfound'
|
|
30
|
+
expect(last_response.status).to eq(201)
|
|
31
|
+
expect(last_response.body).to eq("This is just a text")
|
|
32
|
+
expect(last_response.headers['Content-Type']).to eq("text/plain;charset=utf-8")
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "Should choose right endpoint based on accept header - json" do
|
|
36
|
+
header 'Accept', 'application/json'
|
|
37
|
+
get '/notfound'
|
|
38
|
+
expect(last_response.status).to eq(200)
|
|
39
|
+
expect(last_response.body).to eq("Found")
|
|
40
|
+
expect(last_response.headers['Content-Type']).to eq("application/json")
|
|
24
41
|
end
|
|
25
42
|
|
|
26
43
|
end
|
|
27
44
|
describe "Post operations" do
|
|
28
|
-
it "
|
|
45
|
+
it "Endpoint for post" do
|
|
29
46
|
post '/ok'
|
|
30
47
|
expect(last_response.status).to eq(200)
|
|
31
48
|
expect(last_response.body).to eq("success")
|
|
32
49
|
expect(last_response.headers['Content-Type']).to eq("application/json")
|
|
33
50
|
end
|
|
34
51
|
|
|
35
|
-
it "
|
|
52
|
+
it "Common endpoint with get should behave like post when using post" do
|
|
36
53
|
post '/notfound'
|
|
37
54
|
expect(last_response.status).to eq(404)
|
|
38
55
|
expect(last_response.body).to eq("Not Found")
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rest_shifter
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.10
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Camilo Ribeiro
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-02-
|
|
11
|
+
date: 2015-02-19 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: simplecov
|
|
@@ -193,6 +193,7 @@ files:
|
|
|
193
193
|
- lib/rest_shifter/version.rb
|
|
194
194
|
- rest_shifter.gemspec
|
|
195
195
|
- spec/flavors/notfound_get.flavor
|
|
196
|
+
- spec/flavors/notfound_get_accept.flavor
|
|
196
197
|
- spec/flavors/notfound_post.flavor
|
|
197
198
|
- spec/flavors/sleep_get.flavor
|
|
198
199
|
- spec/flavors/success_get.flavor
|
|
@@ -225,6 +226,7 @@ specification_version: 4
|
|
|
225
226
|
summary: Simple Rest Mock service
|
|
226
227
|
test_files:
|
|
227
228
|
- spec/flavors/notfound_get.flavor
|
|
229
|
+
- spec/flavors/notfound_get_accept.flavor
|
|
228
230
|
- spec/flavors/notfound_post.flavor
|
|
229
231
|
- spec/flavors/sleep_get.flavor
|
|
230
232
|
- spec/flavors/success_get.flavor
|