webvalve 0.12.0 → 1.0.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d632e36adb6db315896d3a144d02408dfcacdb7af5196874f4839d12b187499b
4
- data.tar.gz: 044a117bf8a6df2eba482f99b5234e39b393f906ef0b895b3819d76805e76e9d
3
+ metadata.gz: 5da39e3192b0ca68909782d930f60bbcb854b9f1d81f2f2e48ab5ce485d6758b
4
+ data.tar.gz: a5deb923fb76b3d4e1a084a012d671fc3689cdd61f24255f869217f2527e46a7
5
5
  SHA512:
6
- metadata.gz: e7c5ca72aa5ac1ee8417a15df0848f66f019655a4870152c32ff62231b1df91eef435524f072e548e4091e509be76d2ac5fd19391ecafd861193c2ef1b92617e
7
- data.tar.gz: b1a9d0d174ae5d65ca02fc62ecdb13b24f74489d13c6ab39995868cac56665015667632849a62477c087fc6fe4d0770d5945131ffd84914d61706e58e58b374e
6
+ metadata.gz: 406fca19f30cffb98fd401667ef41038dc1b45f7ee0ff255a9ecb01359dbbef1ac35209bd15b0202790072b8f9f09b82fa8069457d6fb777305719d797024032
7
+ data.tar.gz: 00e5633ca9ee5932dd0af9344e15c2e580f8d550e2ad8a6500a9a952f4f973892df349119bd36e2ebc5540f2e6445671471dd20bcefa9de18ac243bdad08c1f4
@@ -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/v0.12.0...HEAD
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
- [![Build Status](https://travis-ci.org/Betterment/webvalve.svg?branch=master)](https://travis-ci.org/Betterment/webvalve)
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
@@ -7,7 +7,7 @@ end
7
7
  Bundler::GemHelper.install_tasks
8
8
 
9
9
  task(:default).clear
10
- if ENV['APPRAISAL_INITIALIZED'] || ENV['TRAVIS']
10
+ if ENV['APPRAISAL_INITIALIZED'] || ENV['CI']
11
11
  require 'rspec/core'
12
12
  require 'rspec/core/rake_task'
13
13
  RSpec::Core::RakeTask.new(:spec)
@@ -23,6 +23,10 @@ module WebValve
23
23
  end
24
24
  end
25
25
 
26
+ def path_prefix
27
+ @path_prefix ||= URI::parse(service_url).path
28
+ end
29
+
26
30
  private
27
31
 
28
32
  attr_reader :custom_service_url
@@ -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(app_class_name)
5
- @app_class_name = app_class_name
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
- @app_class_name.constantize
16
+ @service_config.service_class_name.constantize
16
17
  end
17
18
  end
18
19
  end
@@ -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.service_class_name))
136
+ ).to_rack(FakeServiceWrapper.new(config))
136
137
  end
137
138
 
138
139
  def allowlist_service(config)
@@ -1,3 +1,3 @@
1
1
  module WebValve
2
- VERSION = "0.12.0"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -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
- it 'raise a useful error when an unmapped route is requested' do
30
- with_env 'DUMMY_API_URL' => 'http://dummy.dev' do
31
- WebValve.register subject.name
32
- WebValve.setup
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
- expect { Net::HTTP.get(URI('http://dummy.dev/foos')) }.to raise_error(RuntimeError, /route not defined for GET/)
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
- it 'returns the result from the fake when a mapped route is requested' do
39
- with_env 'DUMMY_API_URL' => 'http://dummy.dev' do
40
- WebValve.register subject.name
41
- WebValve.setup
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
- expect(Net::HTTP.get(URI('http://dummy.dev/widgets'))).to eq({ result: 'it works!' }.to_json)
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.12.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-02-22 00:00:00.000000000 Z
11
+ date: 2020-04-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport