fake_server 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +22 -0
- data/README.md +12 -0
- data/Rakefile +1 -0
- data/bin/fake_server +2 -0
- data/fake_server.gemspec +28 -0
- data/lib/fake_server.rb +3 -0
- data/lib/fake_server/cli.rb +28 -0
- data/lib/fake_server/remote_api.rb +16 -0
- data/lib/fake_server/server.rb +27 -0
- data/lib/fake_server/version.rb +3 -0
- metadata +158 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 75641cd05fb4b53ab7b5f61338f87899d7e253b8
|
4
|
+
data.tar.gz: 9362eda450908023d7d83a298d0679f51f16a39a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 62d3bb0d3c07a2b930469da75317fcd3ed4f1aa6e5bf10d65203e8ed6d2ad2eea2d171adabc1ad6aed541a0bdd235381d71aad69631815efedea452af972d1ea
|
7
|
+
data.tar.gz: 7b80371786e401faff2f9b1da55cfde39f9914b71083d730a2ce4e301a67c8406adfb7d83dc27b2d37ebe30e9ff50333b8a07388e523f75fe2173560a48e8ade
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Mark Evans
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# FakeServer
|
2
|
+
FakeServer proxies web requests to another host but records GET requests and plays them back, which is useful for running tests which make external requests without actually hitting the server after the first time.
|
3
|
+
|
4
|
+
$ gem install "fake_server"
|
5
|
+
|
6
|
+
$ fake_server start 'http://some.other.place.com'
|
7
|
+
|
8
|
+
It defaults to running on port 5555, and records GET requests in the directory `cassettes`.
|
9
|
+
|
10
|
+
For all options, use
|
11
|
+
|
12
|
+
$ fake_server help start
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/fake_server
ADDED
data/fake_server.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'fake_server/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "fake_server"
|
8
|
+
spec.version = FakeServer::VERSION
|
9
|
+
spec.authors = ["Mark Evans"]
|
10
|
+
spec.email = ["mark@new-bamboo.co.uk"]
|
11
|
+
spec.description = %q{Command line proxy server that records requests, useful for caching external requests in tests}
|
12
|
+
spec.summary = spec.description
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_runtime_dependency "httparty"
|
24
|
+
spec.add_runtime_dependency "puma"
|
25
|
+
spec.add_runtime_dependency "thor"
|
26
|
+
spec.add_runtime_dependency "vcr"
|
27
|
+
spec.add_runtime_dependency "webmock"
|
28
|
+
end
|
data/lib/fake_server.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'vcr'
|
3
|
+
require 'rack/handler/puma'
|
4
|
+
require 'fake_server/server'
|
5
|
+
|
6
|
+
module FakeServer
|
7
|
+
class CLI < Thor
|
8
|
+
|
9
|
+
desc "start HOST", "start the server, proxying to HOST"
|
10
|
+
option :port, type: :numeric, default: 5555
|
11
|
+
option :min_threads, type: :numeric, default: 0
|
12
|
+
option :max_threads, type: :numeric, default: 16
|
13
|
+
option :cassette_dir, default: 'cassettes'
|
14
|
+
option :log_file
|
15
|
+
def start(remote_host)
|
16
|
+
VCR.configure do |c|
|
17
|
+
c.cassette_library_dir = options[:cassette_dir]
|
18
|
+
c.hook_into :webmock
|
19
|
+
end
|
20
|
+
|
21
|
+
Rack::Handler::Puma.run(Server.new(remote_host, options[:log_file]), {
|
22
|
+
Port: options[:port],
|
23
|
+
Threads: "#{options[:min_threads]}:#{options[:max_threads]}"
|
24
|
+
})
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
module FakeServer
|
4
|
+
class RemoteAPI
|
5
|
+
def initialize(host)
|
6
|
+
@host = host
|
7
|
+
end
|
8
|
+
|
9
|
+
attr_reader :host
|
10
|
+
|
11
|
+
def request(method, relative_url)
|
12
|
+
response = HTTParty.public_send(method.downcase, "#{host}#{relative_url}")
|
13
|
+
[response.code, response.headers, [response.body]]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'fake_server/remote_api'
|
2
|
+
require 'logger'
|
3
|
+
|
4
|
+
module FakeServer
|
5
|
+
class Server
|
6
|
+
|
7
|
+
def initialize(host, log_file=nil)
|
8
|
+
@remote_api = RemoteAPI.new(host)
|
9
|
+
@logger = Logger.new(log_file || STDOUT)
|
10
|
+
end
|
11
|
+
|
12
|
+
attr_reader :remote_api, :logger
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
url = env["REQUEST_URI"]
|
16
|
+
method = env["REQUEST_METHOD"]
|
17
|
+
|
18
|
+
logger.info("#{method} #{url}")
|
19
|
+
if method == "GET"
|
20
|
+
VCR.use_cassette(url) { remote_api.request(method, url) }
|
21
|
+
else
|
22
|
+
remote_api.request(method, url)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fake_server
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mark Evans
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: httparty
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: puma
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: thor
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: vcr
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: webmock
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Command line proxy server that records requests, useful for caching external
|
112
|
+
requests in tests
|
113
|
+
email:
|
114
|
+
- mark@new-bamboo.co.uk
|
115
|
+
executables:
|
116
|
+
- fake_server
|
117
|
+
extensions: []
|
118
|
+
extra_rdoc_files: []
|
119
|
+
files:
|
120
|
+
- .gitignore
|
121
|
+
- Gemfile
|
122
|
+
- LICENSE.txt
|
123
|
+
- README.md
|
124
|
+
- Rakefile
|
125
|
+
- bin/fake_server
|
126
|
+
- fake_server.gemspec
|
127
|
+
- lib/fake_server.rb
|
128
|
+
- lib/fake_server/cli.rb
|
129
|
+
- lib/fake_server/remote_api.rb
|
130
|
+
- lib/fake_server/server.rb
|
131
|
+
- lib/fake_server/version.rb
|
132
|
+
homepage: ''
|
133
|
+
licenses:
|
134
|
+
- MIT
|
135
|
+
metadata: {}
|
136
|
+
post_install_message:
|
137
|
+
rdoc_options: []
|
138
|
+
require_paths:
|
139
|
+
- lib
|
140
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - '>='
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
|
+
requirements:
|
147
|
+
- - '>='
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
requirements: []
|
151
|
+
rubyforge_project:
|
152
|
+
rubygems_version: 2.0.0
|
153
|
+
signing_key:
|
154
|
+
specification_version: 4
|
155
|
+
summary: Command line proxy server that records requests, useful for caching external
|
156
|
+
requests in tests
|
157
|
+
test_files: []
|
158
|
+
has_rdoc:
|