RestShifter 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -0
- data/CHANGES +9 -0
- data/Gemfile.lock +2 -2
- data/README.md +58 -3
- data/Rakefile +1 -2
- data/lib/RestShifter/Shifter.rb +64 -3
- data/lib/RestShifter/version.rb +1 -1
- data/spec/flavors/notfound_get.flavor +7 -0
- data/spec/flavors/notfound_post.flavor +7 -0
- data/spec/flavors/notfoundwithaccept.flavor +7 -0
- data/spec/flavors/success_get.flavor +7 -0
- data/spec/flavors/success_post.flavor +7 -0
- data/spec/service_spec.rb +39 -9
- data/spec/spec_helper.rb +0 -1
- metadata +14 -6
- data/spec/flavors/notfound.flavor +0 -3
- data/spec/flavors/success.flavor +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1fb765d8483a9b57675e827f5115242bc1baf122
|
4
|
+
data.tar.gz: a3756a4371ee6590094446da878ad1ff79aa6dcf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4b42355791801d33629ff583f8d5f4722c9d5ee8b33381674e316f079687dd93d4bd301008948744012d34224a092264b02c485c488ffd4ef15add9a3f8d187
|
7
|
+
data.tar.gz: 0fcd151a47c280b443e98f207a1d0483b1cd831b6c764bde11bf9740f4a6b3f94fd76f15f29f8f54473c35e50c5a6c89073a3916463672f76b052bb5bcf016b0
|
data/.travis.yml
ADDED
data/CHANGES
ADDED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
RestShifter (0.0.
|
4
|
+
RestShifter (0.0.2)
|
5
5
|
icecream
|
6
6
|
sinatra
|
7
7
|
|
@@ -26,7 +26,7 @@ GEM
|
|
26
26
|
docile (1.1.5)
|
27
27
|
gherkin (2.12.2)
|
28
28
|
multi_json (~> 1.3)
|
29
|
-
icecream (0.0.
|
29
|
+
icecream (0.0.13)
|
30
30
|
method_source (0.8.2)
|
31
31
|
mime-types (2.4.3)
|
32
32
|
multi_json (1.10.1)
|
data/README.md
CHANGED
@@ -1,10 +1,65 @@
|
|
1
1
|
# RestShifter
|
2
2
|
|
3
|
-
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/RestShifter.png)](https://rubygems.org/gems/RestShifter)
|
4
|
+
[![Build Status](https://secure.travis-ci.org/camiloribeiro/RestShifter.png)](http://travis-ci.org/camiloribeiro/RestShifter)
|
5
|
+
[![endorse](https://api.coderwall.com/camiloribeiro/endorsecount.png)](https://coderwall.com/camiloribeiro)
|
4
6
|
|
5
|
-
This is a sinatra app, with no routs, responses or behaviour defined. It can be routed wherever you like. It uses a declarative file to define all your services.
|
6
7
|
|
7
|
-
|
8
|
+
/
|
9
|
+
__ // The rest api ShapeShifter!
|
10
|
+
-\= \=\ //
|
11
|
+
--=_\=---//=-- This is a Sinatra app with no predefined routes.
|
12
|
+
-_==/ \/ //\/-- This replaces mocks for integration level tests.
|
13
|
+
==/ /O O\==-- This can be used also to create tests for new feature
|
14
|
+
_ _ _ _ /_/ \ ] /-- before the dependent services are in place
|
15
|
+
/\ ( (- \ / ] ] ]==-
|
16
|
+
(\ _\_\_\-\__/ \ (,_,)--
|
17
|
+
(\_/ \ \- Some of the main features are:
|
18
|
+
\/ / ( ( \ ] /) - Easy to define rest paths with custom routes
|
19
|
+
/ ( \ \_ \./ ) - Easy to define rest paths with custom responses
|
20
|
+
( \ \ ) \ - Definition of response times and response codes
|
21
|
+
( /\_ _ _ _ /---/ /\_ \ - Suitable to any kind of tests that use Rest
|
22
|
+
\ / \ / ____/ / \ \
|
23
|
+
( / ) / / /__ ) ( )
|
24
|
+
( ) / __/ '---` / /
|
25
|
+
\ / \ \ _/ / This is still under development, so do not use it.
|
26
|
+
] ] )_\_ /__\/
|
27
|
+
/_\ ]___\
|
28
|
+
(___)
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
The Idea
|
33
|
+
=======
|
34
|
+
|
35
|
+
Are you tired of integrating with services that does not exist yet? Or that are expensive to spin up? Or just want to know what happens whan that service times out or return a ugly error? So you should know RestShifter :)
|
36
|
+
As simples is always better, I've put here a ridiculously easy to run app with no natural behaviour. You just have to create declarative files and start this app.
|
37
|
+
|
38
|
+
ASCII art: http://www.chris.com/ascii/index.php?art=creatures/unicorns
|
39
|
+
|
40
|
+
|
41
|
+
Instructions
|
42
|
+
==========
|
43
|
+
|
44
|
+
Developing
|
45
|
+
----------
|
46
|
+
To develop `RestShifter`, you are going to need [Bundler][1]
|
47
|
+
|
48
|
+
$ git git@github.com:camiloribeiro/RestShifter.git
|
49
|
+
$ cd RestShifter
|
50
|
+
$ bundle install
|
51
|
+
$ rake
|
52
|
+
|
53
|
+
The last step is launching the regression tests and all should be green.
|
54
|
+
|
55
|
+
If you have any problems, please let me know.
|
56
|
+
|
57
|
+
[1]: http://gembundler.com
|
58
|
+
|
59
|
+
Using
|
60
|
+
-----
|
61
|
+
|
62
|
+
Soon.
|
8
63
|
|
9
64
|
LICENSE
|
10
65
|
=======
|
data/Rakefile
CHANGED
@@ -3,8 +3,7 @@ require 'coveralls/rake/task'
|
|
3
3
|
|
4
4
|
Coveralls::RakeTask.new
|
5
5
|
|
6
|
-
task :default => [:spec]
|
7
|
-
# task :default => [:spec, 'coveralls:push']
|
6
|
+
task :default => [:spec, 'coveralls:push']
|
8
7
|
|
9
8
|
RSpec::Core::RakeTask .new(:spec) do |task|
|
10
9
|
task.rspec_opts = ["--format documentation"]
|
data/lib/RestShifter/Shifter.rb
CHANGED
@@ -12,8 +12,69 @@ end
|
|
12
12
|
|
13
13
|
@shapes.all.each do |shape|
|
14
14
|
service = @shapes.flavor shape.to_s.gsub!("@", "").to_sym
|
15
|
-
|
16
|
-
|
17
|
-
service.
|
15
|
+
|
16
|
+
if service.method_used == "get"
|
17
|
+
if (service.request_accept.length > 0 && service.request_content_type.length > 0)
|
18
|
+
get service.path, :provides => service.request_accept, :consumes => service.request_content_type do
|
19
|
+
status service.response_status
|
20
|
+
content_type service.response_content_type
|
21
|
+
service.response_body
|
22
|
+
end
|
23
|
+
|
24
|
+
elsif (service.request_accept.length == 0 && service.request_content_type.length > 0)
|
25
|
+
get service.path, :consumes => service.request_content_type do
|
26
|
+
status service.response_status
|
27
|
+
content_type service.response_content_type
|
28
|
+
service.response_body
|
29
|
+
end
|
30
|
+
|
31
|
+
elsif (service.request_accept.length > 0 && service.request_content_type.length == 0)
|
32
|
+
get service.path, :provides => service.request_accept do
|
33
|
+
binding.pry
|
34
|
+
status service.response_status
|
35
|
+
content_type service.response_content_type
|
36
|
+
service.response_body
|
37
|
+
end
|
38
|
+
|
39
|
+
elsif
|
40
|
+
get service.path do
|
41
|
+
status service.response_status
|
42
|
+
content_type service.response_content_type
|
43
|
+
service.response_body
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
if service.method_used == "post"
|
49
|
+
if (service.request_accept.length > 0 && service.request_content_type.length > 0)
|
50
|
+
post service.path, :provides => service.request_accept, :consumes => service.request_content_type do
|
51
|
+
status service.response_status
|
52
|
+
content_type service.response_content_type
|
53
|
+
service.response_body
|
54
|
+
end
|
55
|
+
|
56
|
+
elsif (service.request_accept.length == 0 && service.request_content_type.length > 0)
|
57
|
+
post service.path, :consumes => service.request_content_type do
|
58
|
+
status service.response_status
|
59
|
+
content_type service.response_content_type
|
60
|
+
service.response_body
|
61
|
+
end
|
62
|
+
|
63
|
+
elsif (service.request_accept.length > 0 && service.request_content_type.length == 0)
|
64
|
+
post service.path, :provides => service.request_accept do
|
65
|
+
binding.pry
|
66
|
+
status service.response_status
|
67
|
+
content_type service.response_content_type
|
68
|
+
service.response_body
|
69
|
+
end
|
70
|
+
|
71
|
+
elsif
|
72
|
+
post service.path do
|
73
|
+
status service.response_status
|
74
|
+
content_type service.response_content_type
|
75
|
+
service.response_body
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
18
79
|
end
|
19
80
|
end
|
data/lib/RestShifter/version.rb
CHANGED
data/spec/service_spec.rb
CHANGED
@@ -7,16 +7,46 @@ describe RestShifter do
|
|
7
7
|
Sinatra::Application
|
8
8
|
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
describe "Get Operations" do
|
11
|
+
# Get
|
12
|
+
it "Service should return 200 for get" do
|
13
|
+
get '/ok'
|
14
|
+
expect(last_response.status).to eq(200)
|
15
|
+
expect(last_response.body).to eq("success")
|
16
|
+
expect(last_response.headers['Content-Type']).to eq("application/json")
|
17
|
+
end
|
18
|
+
|
19
|
+
it "Service should return 404 without accept defining routing for get" do
|
20
|
+
get '/notfound'
|
21
|
+
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("application/foo.company.product.type-version+json")
|
24
|
+
end
|
15
25
|
|
16
|
-
it "Service should return 404" do
|
17
|
-
|
18
|
-
|
19
|
-
expect(last_response.
|
26
|
+
# it "Service should return 404 with accept defining routing" do
|
27
|
+
# header 'Accept', "application/foo.company.product.type-version2+json"
|
28
|
+
# get '/notfound'
|
29
|
+
# expect(last_response.status).to eq(404)
|
30
|
+
# expect(last_response.body).to eq("Not Found with accept")
|
31
|
+
# expect(last_response.headers['Content-Type']).to eq("application/foo.company.product.type-version2+json")
|
32
|
+
# end
|
20
33
|
end
|
34
|
+
describe "Post operations" do
|
35
|
+
|
36
|
+
# Post
|
37
|
+
it "Service should return 200 for post" do
|
38
|
+
post '/ok'
|
39
|
+
expect(last_response.status).to eq(200)
|
40
|
+
expect(last_response.body).to eq("success")
|
41
|
+
expect(last_response.headers['Content-Type']).to eq("application/json")
|
42
|
+
end
|
21
43
|
|
44
|
+
it "Service should return 404 without accept defining routing for post" do
|
45
|
+
post '/notfound'
|
46
|
+
expect(last_response.status).to eq(404)
|
47
|
+
expect(last_response.body).to eq("Not Found")
|
48
|
+
expect(last_response.headers['Content-Type']).to eq("application/foo.company.product.type-version+json")
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
22
52
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: RestShifter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
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-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: simplecov
|
@@ -174,6 +174,8 @@ extra_rdoc_files: []
|
|
174
174
|
files:
|
175
175
|
- .gitignore
|
176
176
|
- .ruby-version
|
177
|
+
- .travis.yml
|
178
|
+
- CHANGES
|
177
179
|
- Gemfile
|
178
180
|
- Gemfile.lock
|
179
181
|
- LICENSE
|
@@ -183,8 +185,11 @@ files:
|
|
183
185
|
- lib/RestShifter.rb
|
184
186
|
- lib/RestShifter/Shifter.rb
|
185
187
|
- lib/RestShifter/version.rb
|
186
|
-
- spec/flavors/
|
187
|
-
- spec/flavors/
|
188
|
+
- spec/flavors/notfound_get.flavor
|
189
|
+
- spec/flavors/notfound_post.flavor
|
190
|
+
- spec/flavors/notfoundwithaccept.flavor
|
191
|
+
- spec/flavors/success_get.flavor
|
192
|
+
- spec/flavors/success_post.flavor
|
188
193
|
- spec/service_spec.rb
|
189
194
|
- spec/spec_helper.rb
|
190
195
|
homepage: http://github.com/camiloribeiro/RestShifter
|
@@ -212,7 +217,10 @@ signing_key:
|
|
212
217
|
specification_version: 4
|
213
218
|
summary: Simple Rest Mock service
|
214
219
|
test_files:
|
215
|
-
- spec/flavors/
|
216
|
-
- spec/flavors/
|
220
|
+
- spec/flavors/notfound_get.flavor
|
221
|
+
- spec/flavors/notfound_post.flavor
|
222
|
+
- spec/flavors/notfoundwithaccept.flavor
|
223
|
+
- spec/flavors/success_get.flavor
|
224
|
+
- spec/flavors/success_post.flavor
|
217
225
|
- spec/service_spec.rb
|
218
226
|
- spec/spec_helper.rb
|
data/spec/flavors/success.flavor
DELETED