http-mock-server 0.1.5 → 0.1.6
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 +26 -2
- data/lib/http-mock-server.rb +9 -8
- data/spec/responses_spec.rb +18 -0
- data/spec/spec_helper.rb +27 -0
- data/spec/test.yml +63 -0
- metadata +37 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06a392357e0c8018686eba0fc851bf1472a8b320
|
4
|
+
data.tar.gz: 34e9170a145e5f9c4633c5d20533ee2ab8baeae9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de5f55bd853117c05fd6a33dad38fc3b17f00580f5e3a67ebbc03c36f3268af2d14e2ae39a4a5a0aca395a466cd56581a9ea58df7b9ec87c738ed521a704ba00
|
7
|
+
data.tar.gz: 79fe46b1195541f57d8a41beee647dcc38447030197d18ed67ce88afce15a0ebe4c2bad9ea5f869999903dc453077184f9a4f1cf0e0db74141e9c57169e0dbe8
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,15 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
http-mock-server (0.1.6)
|
5
|
+
pry (~> 0.11)
|
6
|
+
sinatra (~> 2.0)
|
7
|
+
|
1
8
|
GEM
|
2
9
|
remote: https://rubygems.org/
|
3
10
|
specs:
|
4
11
|
coderay (1.1.2)
|
12
|
+
diff-lcs (1.3)
|
5
13
|
method_source (0.9.0)
|
6
14
|
mustermann (1.0.2)
|
7
15
|
pry (0.11.3)
|
@@ -10,6 +18,21 @@ GEM
|
|
10
18
|
rack (2.0.4)
|
11
19
|
rack-protection (2.0.1)
|
12
20
|
rack
|
21
|
+
rack-test (1.0.0)
|
22
|
+
rack (>= 1.0, < 3)
|
23
|
+
rspec (3.7.0)
|
24
|
+
rspec-core (~> 3.7.0)
|
25
|
+
rspec-expectations (~> 3.7.0)
|
26
|
+
rspec-mocks (~> 3.7.0)
|
27
|
+
rspec-core (3.7.1)
|
28
|
+
rspec-support (~> 3.7.0)
|
29
|
+
rspec-expectations (3.7.0)
|
30
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
31
|
+
rspec-support (~> 3.7.0)
|
32
|
+
rspec-mocks (3.7.0)
|
33
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
+
rspec-support (~> 3.7.0)
|
35
|
+
rspec-support (3.7.1)
|
13
36
|
sinatra (2.0.1)
|
14
37
|
mustermann (~> 1.0)
|
15
38
|
rack (~> 2.0)
|
@@ -21,8 +44,9 @@ PLATFORMS
|
|
21
44
|
ruby
|
22
45
|
|
23
46
|
DEPENDENCIES
|
24
|
-
|
25
|
-
|
47
|
+
http-mock-server!
|
48
|
+
rack-test (~> 1.0)
|
49
|
+
rspec (~> 3.7)
|
26
50
|
|
27
51
|
BUNDLED WITH
|
28
52
|
1.16.1
|
data/lib/http-mock-server.rb
CHANGED
@@ -3,9 +3,7 @@ require 'pry'
|
|
3
3
|
require 'sinatra/base'
|
4
4
|
require 'yaml'
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
$config_file = 'mock.yml'
|
6
|
+
$config_file = ENV['MOCK_CONFIG']
|
9
7
|
if ARGV.length > 0
|
10
8
|
case ARGV[0]
|
11
9
|
when '-h'
|
@@ -18,6 +16,7 @@ if ARGV.length > 0
|
|
18
16
|
end
|
19
17
|
end
|
20
18
|
end
|
19
|
+
$config_file ||= 'mock.yml'
|
21
20
|
|
22
21
|
$config = YAML.load File.read($config_file) rescue begin
|
23
22
|
puts "Config file not found: #{$config_file}"
|
@@ -28,6 +27,12 @@ $config['config']['namespace'] ||= ''
|
|
28
27
|
$config['routes'] ||= []
|
29
28
|
|
30
29
|
class HttpMockServer < Sinatra::Base
|
30
|
+
MIME_JSON = ['application/json']
|
31
|
+
CORS_HEADERS = {
|
32
|
+
'Access-Control-Allow-Origin' => '*',
|
33
|
+
'Access-Control-Allow-Methods' => 'POST, GET, PUT, DELETE, OPTIONS',
|
34
|
+
'Access-Control-Allow-Headers' => 'Origin, Content-Type, Accept, Authorization, Token',
|
35
|
+
}
|
31
36
|
METHODS = %w(connect delete get head options patch post put trace)
|
32
37
|
|
33
38
|
# set :environment, :development
|
@@ -40,11 +45,7 @@ class HttpMockServer < Sinatra::Base
|
|
40
45
|
before do
|
41
46
|
content_type :json
|
42
47
|
unless $config['config']['no_cors']
|
43
|
-
headers
|
44
|
-
'Access-Control-Allow-Origin' => '*',
|
45
|
-
'Access-Control-Allow-Methods' => 'POST, GET, PUT, DELETE, OPTIONS',
|
46
|
-
'Access-Control-Allow-Headers' => 'Origin, Content-Type, Accept, Authorization, Token',
|
47
|
-
)
|
48
|
+
headers CORS_HEADERS
|
48
49
|
end
|
49
50
|
end
|
50
51
|
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.expand_path '../spec_helper.rb', __FILE__
|
2
|
+
|
3
|
+
RSpec.describe HttpMockServer do
|
4
|
+
it 'returns not found' do
|
5
|
+
get '/'
|
6
|
+
conf = $config['not_found']
|
7
|
+
expect(last_response.body).to eq conf['body'].to_json
|
8
|
+
expect(last_response.status).to eq (conf['status'] || 404)
|
9
|
+
unless $config['config']['no_cors']
|
10
|
+
expect(HttpMockServer::CORS_HEADERS.to_a - last_response.headers.to_a).to be_empty
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'returns a message' do
|
15
|
+
get '/api/v1/posts'
|
16
|
+
expect(last_response.body).to eq({ message: 'List of posts' }.to_json)
|
17
|
+
end
|
18
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'rack/test'
|
2
|
+
require 'rspec'
|
3
|
+
|
4
|
+
ENV['RACK_ENV'] = 'test'
|
5
|
+
ENV['MOCK_CONFIG'] = File.expand_path '../test.yml', __FILE__
|
6
|
+
|
7
|
+
require_relative File.expand_path '../../lib/http-mock-server.rb', __FILE__
|
8
|
+
|
9
|
+
module RSpecMixin
|
10
|
+
include Rack::Test::Methods
|
11
|
+
def app() HttpMockServer end
|
12
|
+
end
|
13
|
+
|
14
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
15
|
+
RSpec.configure do |config|
|
16
|
+
config.expect_with :rspec do |expectations|
|
17
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
18
|
+
end
|
19
|
+
|
20
|
+
config.mock_with :rspec do |mocks|
|
21
|
+
mocks.verify_partial_doubles = true
|
22
|
+
end
|
23
|
+
|
24
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
25
|
+
|
26
|
+
config.include RSpecMixin
|
27
|
+
end
|
data/spec/test.yml
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
---
|
2
|
+
config:
|
3
|
+
namespace: '/api/v1' # prepend to every route
|
4
|
+
# no_cors: true # don't send CORS headers
|
5
|
+
port: 8080 # server port
|
6
|
+
# timeout: 10 # response timeout
|
7
|
+
verbose: true # shows request params
|
8
|
+
not_found:
|
9
|
+
body:
|
10
|
+
message: This is not the path you are looking for...
|
11
|
+
routes:
|
12
|
+
-
|
13
|
+
get: '/posts'
|
14
|
+
headers:
|
15
|
+
'A-Random-Header': Something
|
16
|
+
body:
|
17
|
+
message: List of posts
|
18
|
+
-
|
19
|
+
get: '/posts/:id'
|
20
|
+
body:
|
21
|
+
content: A random number {rand} !
|
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}'
|
45
|
+
-
|
46
|
+
post: '/posts'
|
47
|
+
status: 201
|
48
|
+
body:
|
49
|
+
code: 201
|
50
|
+
result: Ok
|
51
|
+
-
|
52
|
+
delete: '*'
|
53
|
+
status: 405
|
54
|
+
body:
|
55
|
+
message: Please don't do it
|
56
|
+
-
|
57
|
+
options: '*'
|
58
|
+
status: 200
|
59
|
+
headers:
|
60
|
+
'Access-Control-Allow-Origin': '*'
|
61
|
+
'Access-Control-Allow-Methods': 'HEAD,GET,PUT,DELETE,OPTIONS'
|
62
|
+
'Access-Control-Allow-Headers': 'X-Requested-With, X-HTTP-Method-Override, Content-Type, Cache-Control, Accept'
|
63
|
+
'Access-Control-Expose-Headers': 'X-Total-Count'
|
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.1.
|
4
|
+
version: 0.1.6
|
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-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|
@@ -38,6 +38,34 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rack-test
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.7'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.7'
|
41
69
|
description: A Ruby HTTP Mock Server based on Sinatra
|
42
70
|
email: mat@blocknot.es
|
43
71
|
executables:
|
@@ -51,6 +79,9 @@ files:
|
|
51
79
|
- README.md
|
52
80
|
- bin/http-mock-server
|
53
81
|
- lib/http-mock-server.rb
|
82
|
+
- spec/responses_spec.rb
|
83
|
+
- spec/spec_helper.rb
|
84
|
+
- spec/test.yml
|
54
85
|
homepage: https://github.com/blocknotes/http-mock-server
|
55
86
|
licenses:
|
56
87
|
- MIT
|
@@ -75,4 +106,7 @@ rubygems_version: 2.6.14
|
|
75
106
|
signing_key:
|
76
107
|
specification_version: 4
|
77
108
|
summary: HTTP Mock Server
|
78
|
-
test_files:
|
109
|
+
test_files:
|
110
|
+
- spec/responses_spec.rb
|
111
|
+
- spec/spec_helper.rb
|
112
|
+
- spec/test.yml
|