http-mock-server 0.2.0 → 0.2.1
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/Gemfile.lock +1 -1
- data/lib/http-mock-server.rb +16 -6
- data/lib/version.rb +1 -1
- data/spec/interpolations_spec.rb +19 -0
- data/spec/responses_spec.rb +27 -2
- data/spec/test.yml +19 -24
- 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: fd35b26b58347d86f5e9d6be1cf594cebe2489a5
|
4
|
+
data.tar.gz: 687b95c61d7b92fae47a22f4ef9aa209a1429349
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32e912c46637ff1a43daf02fe38fed05e56729818e7764bb0e8c20ecd2ff264605a5b5745b8eb95c4345c76e92ddcc80af4595f042770d8a17cf272c7b3f2158
|
7
|
+
data.tar.gz: c4dbac2988dc42875246a1e144f822a55d37418c505b2b1d1afdf2f5543ea2d80d2adbb38b702e59a3a4bfab8aa510dc85e45b664c4304357f7f258f4c5b7b30
|
data/Gemfile.lock
CHANGED
data/lib/http-mock-server.rb
CHANGED
@@ -122,13 +122,23 @@ class HttpMockServer < Sinatra::Base
|
|
122
122
|
config['routes'][route_id]
|
123
123
|
end
|
124
124
|
|
125
|
-
def traverse!(
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
elsif v
|
130
|
-
hash[k] = interpolate v
|
125
|
+
def traverse!(node)
|
126
|
+
if node.is_a?(Hash)
|
127
|
+
node.each do |k, v|
|
128
|
+
traverse_node(node, k, v)
|
131
129
|
end
|
130
|
+
elsif node.is_a?(Array)
|
131
|
+
node.each_with_index do |v, i|
|
132
|
+
traverse_node(node, i, v)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def traverse_node(node, k, v)
|
138
|
+
if v.is_a?(Hash) || v.is_a?(Array)
|
139
|
+
traverse! v
|
140
|
+
elsif v
|
141
|
+
node[k] = interpolate v
|
132
142
|
end
|
133
143
|
end
|
134
144
|
|
data/lib/version.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
MOCK_SERVER_VERSION = '0.2.
|
1
|
+
MOCK_SERVER_VERSION = '0.2.1'.freeze
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.expand_path '../spec_helper.rb', __FILE__
|
2
|
+
|
3
|
+
RSpec.describe HttpMockServer do
|
4
|
+
it 'returns the authors' do
|
5
|
+
get '/api/v1/authors'
|
6
|
+
expect(last_response.status).to eq 200
|
7
|
+
expect(last_response.body).to eq({ path: '/api/v1/authors' }.to_json)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'returns an author' do
|
11
|
+
id = rand 100
|
12
|
+
get "/api/v1/authors/#{id}"
|
13
|
+
expect(last_response.status).to eq 200
|
14
|
+
json = JSON.parse last_response.body
|
15
|
+
expect(json['var']).to eq(id.to_s)
|
16
|
+
expect(json['hash']).to eq('key1' => 'Just a key 4')
|
17
|
+
expect(json['array']).to eq([{ 'name' => 'Item 2' }, { 'name' => 'Item 4' }, { 'name' => 'Item 6' }])
|
18
|
+
end
|
19
|
+
end
|
data/spec/responses_spec.rb
CHANGED
@@ -5,14 +5,39 @@ RSpec.describe HttpMockServer do
|
|
5
5
|
get '/'
|
6
6
|
conf = $config['not_found']
|
7
7
|
expect(last_response.body).to eq conf['body'].to_json
|
8
|
-
expect(last_response.status).to eq
|
8
|
+
expect(last_response.status).to eq 404
|
9
9
|
unless $config['config']['no_cors']
|
10
10
|
expect(HttpMockServer::CORS_HEADERS.to_a - last_response.headers.to_a).to be_empty
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
it 'returns
|
14
|
+
it 'returns the list of posts' do
|
15
15
|
get '/api/v1/posts'
|
16
|
+
expect(last_response.status).to eq 200
|
16
17
|
expect(last_response.body).to eq({ message: 'List of posts' }.to_json)
|
17
18
|
end
|
19
|
+
|
20
|
+
it 'returns a post' do
|
21
|
+
get '/api/v1/posts/1'
|
22
|
+
expect(last_response.status).to eq 200
|
23
|
+
expect(last_response.body).to eq({ post: 'Post #1' }.to_json)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'returns another post' do
|
27
|
+
get '/api/v1/posts/123'
|
28
|
+
expect(last_response.status).to eq 200
|
29
|
+
expect(last_response.body).to eq({ post: 'Post #123' }.to_json)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'creates a post' do
|
33
|
+
post '/api/v1/posts'
|
34
|
+
expect(last_response.status).to eq 201
|
35
|
+
expect(last_response.body).to eq({ code: '201', result: 'Ok' }.to_json)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'deletes something' do
|
39
|
+
delete '/api/v1/something'
|
40
|
+
expect(last_response.status).to eq 405
|
41
|
+
expect(last_response.body).to eq({ message: 'Please don\'t do it' }.to_json)
|
42
|
+
end
|
18
43
|
end
|
data/spec/test.yml
CHANGED
@@ -18,30 +18,7 @@ routes:
|
|
18
18
|
-
|
19
19
|
get: '/posts/:id'
|
20
20
|
body:
|
21
|
-
|
22
|
-
extra:
|
23
|
-
today: 'Today is #{DateTime.now}'
|
24
|
-
request: 'Post id #{params[:id]} - request path #{request.path}'
|
25
|
-
more:
|
26
|
-
is_first: "conditional check #{params[:id] == '1' ? 'first' : 'other'}"
|
27
|
-
an_array:
|
28
|
-
- me
|
29
|
-
- myself
|
30
|
-
- I
|
31
|
-
an_array2:
|
32
|
-
-
|
33
|
-
name: me
|
34
|
-
age: 20
|
35
|
-
-
|
36
|
-
name: myself
|
37
|
-
age: 30
|
38
|
-
-
|
39
|
-
name: I
|
40
|
-
age: 40
|
41
|
-
-
|
42
|
-
get: '/pry'
|
43
|
-
body:
|
44
|
-
message: '#{binding.pry}'
|
21
|
+
post: 'Post ##{params[:id]}'
|
45
22
|
-
|
46
23
|
post: '/posts'
|
47
24
|
status: 201
|
@@ -61,3 +38,21 @@ routes:
|
|
61
38
|
'Access-Control-Allow-Methods': 'HEAD,GET,PUT,DELETE,OPTIONS'
|
62
39
|
'Access-Control-Allow-Headers': 'X-Requested-With, X-HTTP-Method-Override, Content-Type, Cache-Control, Accept'
|
63
40
|
'Access-Control-Expose-Headers': 'X-Total-Count'
|
41
|
+
|
42
|
+
-
|
43
|
+
get: '/authors'
|
44
|
+
body:
|
45
|
+
path: '#{request.path}'
|
46
|
+
-
|
47
|
+
get: '/authors/:id'
|
48
|
+
body:
|
49
|
+
var: '#{params[:id]}'
|
50
|
+
hash:
|
51
|
+
key1: 'Just a key #{2*2}'
|
52
|
+
array:
|
53
|
+
-
|
54
|
+
name: 'Item #{1+1}'
|
55
|
+
-
|
56
|
+
name: 'Item #{2+2}'
|
57
|
+
-
|
58
|
+
name: 'Item #{3+3}'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http-mock-server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mattia Roccoberton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-04-
|
11
|
+
date: 2018-04-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|
@@ -95,6 +95,7 @@ files:
|
|
95
95
|
- bin/http-mock-server
|
96
96
|
- lib/http-mock-server.rb
|
97
97
|
- lib/version.rb
|
98
|
+
- spec/interpolations_spec.rb
|
98
99
|
- spec/responses_spec.rb
|
99
100
|
- spec/spec_helper.rb
|
100
101
|
- spec/test.yml
|
@@ -123,6 +124,7 @@ signing_key:
|
|
123
124
|
specification_version: 4
|
124
125
|
summary: HTTP Mock Server
|
125
126
|
test_files:
|
127
|
+
- spec/interpolations_spec.rb
|
126
128
|
- spec/responses_spec.rb
|
127
129
|
- spec/spec_helper.rb
|
128
130
|
- spec/test.yml
|