webvalve 0.12.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -1
- data/README.md +1 -1
- data/Rakefile +1 -1
- data/lib/webvalve/fake_service_config.rb +4 -0
- data/lib/webvalve/fake_service_wrapper.rb +4 -3
- data/lib/webvalve/manager.rb +2 -1
- data/lib/webvalve/version.rb +1 -1
- data/spec/webvalve/fake_service_config_spec.rb +24 -0
- data/spec/webvalve/fake_service_spec.rb +33 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5da39e3192b0ca68909782d930f60bbcb854b9f1d81f2f2e48ab5ce485d6758b
|
4
|
+
data.tar.gz: a5deb923fb76b3d4e1a084a012d671fc3689cdd61f24255f869217f2527e46a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 406fca19f30cffb98fd401667ef41038dc1b45f7ee0ff255a9ecb01359dbbef1ac35209bd15b0202790072b8f9f09b82fa8069457d6fb777305719d797024032
|
7
|
+
data.tar.gz: 00e5633ca9ee5932dd0af9344e15c2e580f8d550e2ad8a6500a9a952f4f973892df349119bd36e2ebc5540f2e6445671471dd20bcefa9de18ac243bdad08c1f4
|
data/CHANGELOG.md
CHANGED
@@ -9,6 +9,11 @@ and this project aims to adhere to [Semantic Versioning](http://semver.org/spec/
|
|
9
9
|
### Added
|
10
10
|
### Removed
|
11
11
|
|
12
|
+
## [1.0.0] - 2020-04-22
|
13
|
+
### Changed
|
14
|
+
- Support API_URLs that include path
|
15
|
+
(https://github.com/Betterment/webvalve/pull/41)
|
16
|
+
|
12
17
|
## [0.12.0] - 2020-02-22
|
13
18
|
### Changed
|
14
19
|
- raise an error on setup when multiple services are registered to the
|
@@ -52,7 +57,8 @@ and this project aims to adhere to [Semantic Versioning](http://semver.org/spec/
|
|
52
57
|
### Changed
|
53
58
|
- WebMock 3+ support from @messanjah (https://github.com/Betterment/webvalve/pull/22)
|
54
59
|
|
55
|
-
[Unreleased]: https://github.com/Betterment/webvalve/compare/
|
60
|
+
[Unreleased]: https://github.com/Betterment/webvalve/compare/v1.0.0...HEAD
|
61
|
+
[1.0.0]: https://github.com/Betterment/webvalve/compare/v0.12.0...v1.0.0
|
56
62
|
[0.12.0]: https://github.com/Betterment/webvalve/compare/v0.11.0...v0.12.0
|
57
63
|
[0.11.0]: https://github.com/Betterment/webvalve/compare/v0.10.0...v0.11.0
|
58
64
|
[0.10.0]: https://github.com/Betterment/webvalve/compare/v0.9.10...v0.10.0
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
WebValve
|
2
2
|
========
|
3
3
|
|
4
|
-
|
4
|
+
![Build Status](https://github.com/Betterment/webvalve/workflows/CI/badge.svg)
|
5
5
|
[![Gem Status](https://img.shields.io/gem/v/webvalve.svg)](https://rubygems.org/gems/webvalve)
|
6
6
|
|
7
7
|
WebValve is a tool for defining and registering fake implementations of
|
data/Rakefile
CHANGED
@@ -1,18 +1,19 @@
|
|
1
1
|
module WebValve
|
2
2
|
class FakeServiceWrapper
|
3
3
|
# lazily resolve the app constant to leverage rails class reloading
|
4
|
-
def initialize(
|
5
|
-
@
|
4
|
+
def initialize(service_config)
|
5
|
+
@service_config = service_config
|
6
6
|
end
|
7
7
|
|
8
8
|
def call(env)
|
9
|
+
env['PATH_INFO'] = env['PATH_INFO'].gsub(/\A#{@service_config.path_prefix}/, '')
|
9
10
|
app.call(env)
|
10
11
|
end
|
11
12
|
|
12
13
|
private
|
13
14
|
|
14
15
|
def app
|
15
|
-
@
|
16
|
+
@service_config.service_class_name.constantize
|
16
17
|
end
|
17
18
|
end
|
18
19
|
end
|
data/lib/webvalve/manager.rb
CHANGED
@@ -70,6 +70,7 @@ module WebValve
|
|
70
70
|
allowlisted_urls.clear
|
71
71
|
fake_service_configs.clear
|
72
72
|
stubbed_urls.clear
|
73
|
+
WebMock.reset!
|
73
74
|
end
|
74
75
|
|
75
76
|
# @api private
|
@@ -132,7 +133,7 @@ module WebValve
|
|
132
133
|
WebMock.stub_request(
|
133
134
|
:any,
|
134
135
|
url_to_regexp(config.service_url)
|
135
|
-
).to_rack(FakeServiceWrapper.new(config
|
136
|
+
).to_rack(FakeServiceWrapper.new(config))
|
136
137
|
end
|
137
138
|
|
138
139
|
def allowlist_service(config)
|
data/lib/webvalve/version.rb
CHANGED
@@ -88,4 +88,28 @@ RSpec.describe WebValve::FakeServiceConfig do
|
|
88
88
|
end
|
89
89
|
end
|
90
90
|
end
|
91
|
+
|
92
|
+
describe '.path_prefix' do
|
93
|
+
it 'raises if the url is not present' do
|
94
|
+
expect { subject.path_prefix }.to raise_error(/There is no URL defined for FakeDummy/)
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'returns root when there is no path in the service URL' do
|
98
|
+
with_env 'DUMMY_API_URL' => 'http://bananas.test/' do
|
99
|
+
expect(subject.path_prefix).to eq '/'
|
100
|
+
end
|
101
|
+
with_env 'DUMMY_API_URL' => 'https://some:auth@bananas.test//' do
|
102
|
+
expect(subject.path_prefix).to eq '/' # Parses funkier URL
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'returns the path when there is one in the service URL' do
|
107
|
+
with_env 'DUMMY_API_URL' => 'http://zombo.com/welcome' do
|
108
|
+
expect(subject.path_prefix).to eq '/welcome'
|
109
|
+
end
|
110
|
+
with_env 'DUMMY_API_URL' => 'http://zombo.com/welcome/' do
|
111
|
+
expect(subject.path_prefix).to eq '/welcome' # Ignores trailing '/'
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
91
115
|
end
|
@@ -26,21 +26,44 @@ RSpec.describe WebValve::FakeService do
|
|
26
26
|
WebValve.reset
|
27
27
|
end
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
29
|
+
context 'when the service is at a root path' do
|
30
|
+
it 'raise a useful error when an unmapped route is requested' do
|
31
|
+
with_env 'DUMMY_API_URL' => 'http://dummy.dev' do
|
32
|
+
WebValve.register subject.name
|
33
|
+
WebValve.setup
|
33
34
|
|
34
|
-
|
35
|
+
expect { Net::HTTP.get(URI('http://dummy.dev/foos')) }.to raise_error(RuntimeError, /route not defined for GET/)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'returns the result from the fake when a mapped route is requested' do
|
40
|
+
with_env 'DUMMY_API_URL' => 'http://dummy.dev' do
|
41
|
+
WebValve.register subject.name
|
42
|
+
WebValve.setup
|
43
|
+
|
44
|
+
expect(Net::HTTP.get(URI('http://dummy.dev/widgets'))).to eq({ result: 'it works!' }.to_json)
|
45
|
+
end
|
35
46
|
end
|
36
47
|
end
|
37
48
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
49
|
+
context 'when the service lives at a non-root path' do
|
50
|
+
it 'raise a useful error when the route is requested at the root' do
|
51
|
+
with_env 'DUMMY_API_URL' => 'http://dummy.dev/gg' do
|
52
|
+
WebValve.register subject.name
|
53
|
+
WebValve.setup
|
54
|
+
|
55
|
+
expect { Net::HTTP.get(URI('http://dummy.dev/widgets')) }
|
56
|
+
.to raise_error(WebMock::NetConnectNotAllowedError, /Real HTTP connections are disabled/)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'returns the result from the fake when a mapped route is requested' do
|
61
|
+
with_env 'DUMMY_API_URL' => 'http://dummy.dev/gg' do
|
62
|
+
WebValve.register subject.name
|
63
|
+
WebValve.setup
|
42
64
|
|
43
|
-
|
65
|
+
expect(Net::HTTP.get(URI('http://dummy.dev/gg/widgets'))).to eq({ result: 'it works!' }.to_json)
|
66
|
+
end
|
44
67
|
end
|
45
68
|
end
|
46
69
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webvalve
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Moore
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|