webvalve 0.9.10 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e78700063483cd49d8ee34f059f807c6640a002e3380f8f255a742ae01aef042
4
- data.tar.gz: f7d1b324e129d5fbe368ef22bd98ddddf83ddf8a9252f8ed539142b3688ab6a9
3
+ metadata.gz: 3bf83f303a9549cb99552f7fc6810ac73ad574d551247d9b7b00f637290e34e8
4
+ data.tar.gz: 110b2a233b4abcf9a59a49f0354202b274dd6056561ed9aff9e985c9f8335a7a
5
5
  SHA512:
6
- metadata.gz: f1781dd8a0d8d64fe570164febfb328f60e3dabf757931fecf16c326bae36a87dd6d1b52dab62bfb588b5e07bb0f0795c61f92b395c5d2e9ea82b16266fd2f49
7
- data.tar.gz: 43a431a534c6dd790b05fd7767125b22359fa2d17e2d3fd87a1119bc9f242457ac4e355a069cdb172f5ba61cbe9e2e9225a6cf8072ee7e2c6b328f9d7e2a230c
6
+ metadata.gz: a62b2b9f6a2956445f9235b88eaa5abd425845da985952394bc0844d951308f556d54d13432df941f59a9047f62dd9ee4053a5b91d770bf6532a403297d0d8cc
7
+ data.tar.gz: ea441eb2ba4de0f1a84c8ab6648dd1a6c25c6858985b15ebd090bb277a3a9d637df8d439992934bf9671ea99c57625d9abce457d4f2b5a43a96de3b3af9ceb06
@@ -9,9 +9,13 @@ and this project aims to adhere to [Semantic Versioning](http://semver.org/spec/
9
9
  ### Added
10
10
  ### Removed
11
11
 
12
+ ## [0.10.0] - 2019-09-23
13
+ ### Changed
14
+ - `Webvalve.register` no longer accepts classes; you must provide class names as strings. Fixes a Rails 6 deprecation warning. (https://github.com/Betterment/webvalve/pull/35)
15
+
12
16
  ## [0.9.10] - 2019-09-09
13
17
  ### Changed
14
- - rename `whitelist_url` to `allow_url` (https://github.com/Betterment/retail/pull/4424)
18
+ - rename `whitelist_url` to `allow_url` (https://github.com/Betterment/webvalve/pull/33)
15
19
 
16
20
  ## [0.9.9] - 2019-05-24
17
21
  ### Changed
@@ -34,7 +38,8 @@ and this project aims to adhere to [Semantic Versioning](http://semver.org/spec/
34
38
  ### Changed
35
39
  - WebMock 3+ support from @messanjah (https://github.com/Betterment/webvalve/pull/22)
36
40
 
37
- [Unreleased]: https://github.com/Betterment/webvalve/compare/v0.9.9...HEAD
41
+ [Unreleased]: https://github.com/Betterment/webvalve/compare/v0.10.0...HEAD
42
+ [0.10.0]: https://github.com/Betterment/webvalve/compare/v0.9.10...v0.10.0
38
43
  [0.9.10]: https://github.com/Betterment/webvalve/compare/v0.9.9...v0.9.10
39
44
  [0.9.9]: https://github.com/Betterment/webvalve/compare/v0.9.8...v0.9.9
40
45
  [0.9.8]: https://github.com/Betterment/webvalve/compare/v0.9.7...v0.9.8
data/README.md CHANGED
@@ -40,13 +40,13 @@ is a warning that the requested URL was not mocked. This behavior comes
40
40
  straight outta WebMock.
41
41
 
42
42
  ```ruby
43
- irb(main):007:0> Net::HTTP.get(URI('http://bank.dev'))
43
+ irb(main):007:0> Net::HTTP.get(URI('http://bank.test'))
44
44
 
45
- WebMock::NetConnectNotAllowedError: Real HTTP connections are disabled. Unregistered request: GET http://bank.dev/ with headers {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}
45
+ WebMock::NetConnectNotAllowedError: Real HTTP connections are disabled. Unregistered request: GET http://bank.test/ with headers {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}
46
46
 
47
47
  You can stub this request with the following snippet:
48
48
 
49
- stub_request(:get, "http://bank.dev/").
49
+ stub_request(:get, "http://bank.test/").
50
50
  with(:headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
51
51
  to_return(:status => 200, :body => "", :headers => {})
52
52
 
@@ -68,12 +68,12 @@ This will drop a new file in your config directory.
68
68
 
69
69
  # # register services
70
70
  #
71
- # WebValve.register FakeBank
72
- # WebValve.register FakeExample, url: 'https://api.example.org'
71
+ # WebValve.register "FakeBank"
72
+ # WebValve.register "FakeExample", url: "https://api.example.org"
73
73
  #
74
74
  # # add urls to allowlist
75
75
  #
76
- # WebValve.allow_url 'https://example.com'
76
+ # WebValve.allow_url "https://example.com"
77
77
  ```
78
78
 
79
79
  If you're not using Rails, you can create this file for yourself.
@@ -113,7 +113,7 @@ And it will automatically register it in `config/webvalve.rb`
113
113
 
114
114
  ```ruby
115
115
  # config/webvalve.rb
116
- WebValve.register FakeBank
116
+ WebValve.register "FakeBank"
117
117
  ```
118
118
 
119
119
  Again, if you're not using Rails, you'll have to create this file
@@ -123,7 +123,7 @@ You'll also want to define an environment variable for the base url of
123
123
  your service.
124
124
 
125
125
  ```bash
126
- export BANK_API_URL='http://bank.dev'
126
+ export BANK_API_URL='http://bank.test'
127
127
  ```
128
128
 
129
129
  That's it. Now when you hit your service again, it will route your
@@ -189,10 +189,10 @@ endpoint in a test, we can just use WebMock™.
189
189
  # in an rspec test...
190
190
 
191
191
  it 'handles 404s by returning nil' do
192
- fake_req = stub_request('http://bank.dev/some/url/1234')
192
+ fake_req = stub_request('http://bank.test/some/url/1234')
193
193
  .to_return(status: 404, body: nil)
194
194
 
195
- response = Faraday.get 'http://bank.dev/some/url/1234'
195
+ response = Faraday.get 'http://bank.test/some/url/1234'
196
196
  expect(response.body).to be_nil
197
197
  expect(fake_req).to have_been_requested
198
198
  end
@@ -37,7 +37,7 @@ module Webvalve
37
37
 
38
38
  def register_fake_in_config
39
39
  append_to_file config_file_path do <<~RUBY
40
- WebValve.register #{fake_service_class_name}
40
+ WebValve.register "#{fake_service_class_name}"
41
41
  RUBY
42
42
  end
43
43
  end
@@ -16,12 +16,12 @@ module Webvalve
16
16
  create_file full_file_path, <<-FILE.strip_heredoc
17
17
  # # register services
18
18
  #
19
- # WebValve.register FakeThing
20
- # WebValve.register FakeExample, url: 'https://api.example.org'
19
+ # WebValve.register "FakeThing"
20
+ # WebValve.register "FakeExample", url: "https://api.example.org"
21
21
  #
22
22
  # # add urls to the allowlist
23
23
  #
24
- # WebValve.allow_url 'https://example.com'
24
+ # WebValve.allow_url "https://example.com"
25
25
  FILE
26
26
  end
27
27
 
@@ -1,9 +1,9 @@
1
1
  module WebValve
2
2
  class FakeServiceConfig
3
- attr_reader :service
3
+ attr_reader :service_class_name
4
4
 
5
- def initialize(service:, url: nil)
6
- @service = service
5
+ def initialize(service_class_name:, url: nil)
6
+ @service_class_name = service_class_name
7
7
  @custom_service_url = url
8
8
  end
9
9
 
@@ -26,9 +26,9 @@ module WebValve
26
26
 
27
27
  def missing_url_message
28
28
  <<~MESSAGE
29
- There is no URL defined for #{service.name}.
29
+ There is no URL defined for #{service_class_name}.
30
30
  Configure one by setting the ENV variable "#{service_name.to_s.upcase}_API_URL"
31
- or by using WebValve.register #{service.name}, url: "http://something.dev"
31
+ or by using WebValve.register "#{service_class_name}", url: "http://something.dev"
32
32
  MESSAGE
33
33
  end
34
34
 
@@ -45,7 +45,7 @@ module WebValve
45
45
  end
46
46
 
47
47
  def service_name
48
- @service_name ||= service.name.demodulize.underscore.sub 'fake_', ''
48
+ @service_name ||= service_class_name.demodulize.underscore.sub 'fake_', ''
49
49
  end
50
50
  end
51
51
  end
@@ -1,8 +1,8 @@
1
1
  module WebValve
2
2
  class FakeServiceWrapper
3
3
  # lazily resolve the app constant to leverage rails class reloading
4
- def initialize(app)
5
- @app_klass_name = app.name
4
+ def initialize(app_class_name)
5
+ @app_class_name = app_class_name
6
6
  end
7
7
 
8
8
  def call(env)
@@ -12,7 +12,7 @@ module WebValve
12
12
  private
13
13
 
14
14
  def app
15
- @app_klass_name.constantize
15
+ @app_class_name.constantize
16
16
  end
17
17
  end
18
18
  end
@@ -7,9 +7,10 @@ module WebValve
7
7
  class Manager
8
8
  include Singleton
9
9
 
10
- def register(fake_service, **args)
11
- raise "#{fake_service.inspect} already registered" if fake_service_configs.any? { |c| c.service == fake_service }
12
- fake_service_configs << FakeServiceConfig.new(service: fake_service, **args)
10
+ def register(fake_service_class_name, **args)
11
+ raise "register must be called with a string to comply with Rails autoloading" unless fake_service_class_name.is_a?(String)
12
+ raise "#{fake_service_class_name.inspect} already registered" if fake_service_configs.any? { |c| c.service_class_name == fake_service_class_name }
13
+ fake_service_configs << FakeServiceConfig.new(service_class_name: fake_service_class_name, **args)
13
14
  end
14
15
 
15
16
  def allow_url(url)
@@ -62,7 +63,7 @@ module WebValve
62
63
  WebMock.stub_request(
63
64
  :any,
64
65
  url_to_regexp(config.service_url)
65
- ).to_rack(FakeServiceWrapper.new(config.service))
66
+ ).to_rack(FakeServiceWrapper.new(config.service_class_name))
66
67
  end
67
68
 
68
69
  def allowlist_service(config)
@@ -1,3 +1,3 @@
1
1
  module WebValve
2
- VERSION = "0.9.10"
2
+ VERSION = "0.10.0"
3
3
  end
@@ -0,0 +1,8 @@
1
+ WebValve Request Captured (10.6ms) dummy.dev GET /widgets [200]
2
+ WebValve Request Captured (0.4ms) dummy.dev GET /foos []
3
+ WebValve Request Captured (0.8ms) dummy.dev GET /foos []
4
+ WebValve Request Captured (2.1ms) dummy.dev GET /widgets [200]
5
+ WebValve Request Captured (0.3ms) dummy.dev GET /foos []
6
+ WebValve Request Captured (19.5ms) dummy.dev GET /widgets [200]
7
+ WebValve Request Captured (0.4ms) dummy.dev GET /foos []
8
+ WebValve Request Captured (1.8ms) dummy.dev GET /widgets [200]
@@ -1,32 +1,32 @@
1
1
  example_id | status | run_time |
2
2
  ------------------------------------------------------ | ------ | --------------- |
3
- ./spec/webvalve/fake_service_config_spec.rb[1:1:1:1] | passed | 0.00013 seconds |
4
- ./spec/webvalve/fake_service_config_spec.rb[1:1:1:2] | passed | 0.00013 seconds |
5
- ./spec/webvalve/fake_service_config_spec.rb[1:1:2:1] | passed | 0.00013 seconds |
6
- ./spec/webvalve/fake_service_config_spec.rb[1:1:2:2] | passed | 0.00016 seconds |
7
- ./spec/webvalve/fake_service_config_spec.rb[1:1:2:3] | passed | 0.00017 seconds |
8
- ./spec/webvalve/fake_service_config_spec.rb[1:1:3:1] | passed | 0.00019 seconds |
9
- ./spec/webvalve/fake_service_config_spec.rb[1:1:3:2] | passed | 0.00014 seconds |
3
+ ./spec/webvalve/fake_service_config_spec.rb[1:1:1:1] | passed | 0.00011 seconds |
4
+ ./spec/webvalve/fake_service_config_spec.rb[1:1:1:2] | passed | 0.00014 seconds |
5
+ ./spec/webvalve/fake_service_config_spec.rb[1:1:2:1] | passed | 0.00012 seconds |
6
+ ./spec/webvalve/fake_service_config_spec.rb[1:1:2:2] | passed | 0.00014 seconds |
7
+ ./spec/webvalve/fake_service_config_spec.rb[1:1:2:3] | passed | 0.00015 seconds |
8
+ ./spec/webvalve/fake_service_config_spec.rb[1:1:3:1] | passed | 0.00012 seconds |
9
+ ./spec/webvalve/fake_service_config_spec.rb[1:1:3:2] | passed | 0.00011 seconds |
10
10
  ./spec/webvalve/fake_service_config_spec.rb[1:1:3:3:1] | passed | 0.00016 seconds |
11
- ./spec/webvalve/fake_service_config_spec.rb[1:1:3:3:2] | passed | 0.00016 seconds |
12
- ./spec/webvalve/fake_service_config_spec.rb[1:2:1] | passed | 0.00015 seconds |
13
- ./spec/webvalve/fake_service_config_spec.rb[1:2:2] | passed | 0.00013 seconds |
14
- ./spec/webvalve/fake_service_config_spec.rb[1:2:3] | passed | 0.00013 seconds |
15
- ./spec/webvalve/fake_service_spec.rb[1:1] | passed | 0.00273 seconds |
16
- ./spec/webvalve/fake_service_spec.rb[1:2:1] | passed | 0.0183 seconds |
17
- ./spec/webvalve/fake_service_spec.rb[1:2:2] | passed | 0.01809 seconds |
18
- ./spec/webvalve/manager_spec.rb[1:1] | passed | 0.00069 seconds |
19
- ./spec/webvalve/manager_spec.rb[1:2:1] | passed | 0.00233 seconds |
20
- ./spec/webvalve/manager_spec.rb[1:3:1] | passed | 0.00182 seconds |
21
- ./spec/webvalve/manager_spec.rb[1:4:1] | passed | 0.00134 seconds |
22
- ./spec/webvalve/manager_spec.rb[1:5:1] | passed | 0.03628 seconds |
23
- ./spec/webvalve/manager_spec.rb[1:5:2] | passed | 0.00118 seconds |
24
- ./spec/webvalve/manager_spec.rb[1:5:3] | passed | 0.00128 seconds |
25
- ./spec/webvalve/manager_spec.rb[1:5:4:1] | passed | 0.00141 seconds |
26
- ./spec/webvalve/manager_spec.rb[1:5:5:1] | passed | 0.00147 seconds |
27
- ./spec/webvalve/manager_spec.rb[1:5:5:2] | passed | 0.00148 seconds |
28
- ./spec/webvalve/manager_spec.rb[1:5:5:3] | passed | 0.00347 seconds |
29
- ./spec/webvalve_spec.rb[1:1] | passed | 0.00008 seconds |
30
- ./spec/webvalve_spec.rb[1:2] | passed | 0.00011 seconds |
31
- ./spec/webvalve_spec.rb[1:3] | passed | 0.00209 seconds |
11
+ ./spec/webvalve/fake_service_config_spec.rb[1:1:3:3:2] | passed | 0.00024 seconds |
12
+ ./spec/webvalve/fake_service_config_spec.rb[1:2:1] | passed | 0.00132 seconds |
13
+ ./spec/webvalve/fake_service_config_spec.rb[1:2:2] | passed | 0.00061 seconds |
14
+ ./spec/webvalve/fake_service_config_spec.rb[1:2:3] | passed | 0.00016 seconds |
15
+ ./spec/webvalve/fake_service_spec.rb[1:1] | passed | 0.0031 seconds |
16
+ ./spec/webvalve/fake_service_spec.rb[1:2:1] | passed | 0.00281 seconds |
17
+ ./spec/webvalve/fake_service_spec.rb[1:2:2] | passed | 0.02529 seconds |
18
+ ./spec/webvalve/manager_spec.rb[1:1] | passed | 0.00005 seconds |
19
+ ./spec/webvalve/manager_spec.rb[1:2:1] | passed | 0.00622 seconds |
20
+ ./spec/webvalve/manager_spec.rb[1:3:1] | passed | 0.00033 seconds |
21
+ ./spec/webvalve/manager_spec.rb[1:4:1] | passed | 0.00018 seconds |
22
+ ./spec/webvalve/manager_spec.rb[1:5:1] | passed | 0.02341 seconds |
23
+ ./spec/webvalve/manager_spec.rb[1:5:2] | passed | 0.00039 seconds |
24
+ ./spec/webvalve/manager_spec.rb[1:5:3] | passed | 0.00063 seconds |
25
+ ./spec/webvalve/manager_spec.rb[1:5:4:1] | passed | 0.00038 seconds |
26
+ ./spec/webvalve/manager_spec.rb[1:5:5:1] | passed | 0.00122 seconds |
27
+ ./spec/webvalve/manager_spec.rb[1:5:5:2] | passed | 0.00129 seconds |
28
+ ./spec/webvalve/manager_spec.rb[1:5:5:3] | passed | 0.00181 seconds |
29
+ ./spec/webvalve_spec.rb[1:1] | passed | 0.0001 seconds |
30
+ ./spec/webvalve_spec.rb[1:2] | passed | 0.00449 seconds |
31
+ ./spec/webvalve_spec.rb[1:3] | passed | 0.00014 seconds |
32
32
  ./spec/webvalve_spec.rb[1:4] | passed | 0.00009 seconds |
@@ -17,7 +17,7 @@ RSpec.describe WebValve::FakeServiceConfig do
17
17
  stub_const('FakeDummy', fake_service)
18
18
  end
19
19
 
20
- subject { described_class.new service: fake_service }
20
+ subject { described_class.new service_class_name: fake_service.name }
21
21
 
22
22
  describe '.should_intercept?' do
23
23
  context 'in test env' do
@@ -136,7 +136,7 @@ RSpec.describe WebValve::FakeServiceConfig do
136
136
  expect { subject.service_url }.to raise_error <<~MESSAGE
137
137
  There is no URL defined for FakeDummy.
138
138
  Configure one by setting the ENV variable "DUMMY_API_URL"
139
- or by using WebValve.register FakeDummy, url: "http://something.dev"
139
+ or by using WebValve.register "FakeDummy", url: "http://something.dev"
140
140
  MESSAGE
141
141
  end
142
142
 
@@ -28,7 +28,7 @@ RSpec.describe WebValve::FakeService do
28
28
 
29
29
  it 'raise a useful error when an unmapped route is requested' do
30
30
  with_env 'DUMMY_API_URL' => 'http://dummy.dev' do
31
- WebValve.register subject
31
+ WebValve.register subject.name
32
32
  WebValve.setup
33
33
 
34
34
  expect { Net::HTTP.get(URI('http://dummy.dev/foos')) }.to raise_error(RuntimeError, /route not defined for GET/)
@@ -37,7 +37,7 @@ RSpec.describe WebValve::FakeService do
37
37
 
38
38
  it 'returns the result from the fake when a mapped route is requested' do
39
39
  with_env 'DUMMY_API_URL' => 'http://dummy.dev' do
40
- WebValve.register subject
40
+ WebValve.register subject.name
41
41
  WebValve.setup
42
42
 
43
43
  expect(Net::HTTP.get(URI('http://dummy.dev/widgets'))).to eq({ result: 'it works!' }.to_json)
@@ -17,22 +17,22 @@ RSpec.describe WebValve::Manager do
17
17
  end
18
18
  end
19
19
 
20
- describe '#register(fake_service)' do
20
+ describe '#register(fake_service_class_name)' do
21
21
  it 'raises on duplicates' do
22
- fake = class_double(WebValve::FakeService)
22
+ fake = class_double(WebValve::FakeService, name: "FooService")
23
23
 
24
- subject.register fake
25
- expect { subject.register fake }.to raise_error(/already registered/)
24
+ subject.register fake.name
25
+ expect { subject.register fake.name }.to raise_error(/already registered/)
26
26
  expect(subject.fake_service_configs.count).to eq 1
27
- expect(subject.fake_service_configs.first.service).to eq fake
27
+ expect(subject.fake_service_configs.first.service_class_name).to eq fake.name
28
28
  end
29
29
  end
30
30
 
31
- describe '#register(fake_service, url:)' do
31
+ describe '#register(fake_service_class_name, url:)' do
32
32
  it 'stores the url' do
33
- fake = class_double(WebValve::FakeService)
33
+ fake = class_double(WebValve::FakeService, name: "FooService")
34
34
 
35
- subject.register fake, url: 'http://manual.dev'
35
+ subject.register fake.name, url: 'http://manual.dev'
36
36
  expect(subject.fake_service_configs.first.service_url).to eq 'http://manual.dev'
37
37
  end
38
38
  end
@@ -109,7 +109,7 @@ RSpec.describe WebValve::Manager do
109
109
  allow(WebMock).to receive(:stub_request).and_return(web_mock_stubble)
110
110
 
111
111
  with_env 'SOMETHING_API_URL' => 'http://fake.dev' do
112
- subject.register disabled_service
112
+ subject.register disabled_service.name
113
113
  subject.setup
114
114
  end
115
115
 
@@ -121,7 +121,7 @@ RSpec.describe WebValve::Manager do
121
121
  enabled_service = class_double(WebValve::FakeService, name: 'FakeSomething')
122
122
 
123
123
  with_env 'SOMETHING_ENABLED' => '1', 'SOMETHING_API_URL' => 'http://real.dev' do
124
- subject.register enabled_service
124
+ subject.register enabled_service.name
125
125
  subject.setup
126
126
  end
127
127
 
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.9.10
4
+ version: 0.10.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: 2019-09-09 00:00:00.000000000 Z
11
+ date: 2019-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -190,6 +190,7 @@ files:
190
190
  - spec/dummy/config/locales/en.yml
191
191
  - spec/dummy/config/routes.rb
192
192
  - spec/dummy/config/secrets.yml
193
+ - spec/dummy/log/test.log
193
194
  - spec/dummy/public/404.html
194
195
  - spec/dummy/public/422.html
195
196
  - spec/dummy/public/500.html
@@ -220,7 +221,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
220
221
  - !ruby/object:Gem::Version
221
222
  version: '0'
222
223
  requirements: []
223
- rubygems_version: 3.0.6
224
+ rubygems_version: 3.0.3
224
225
  signing_key:
225
226
  specification_version: 4
226
227
  summary: A library for faking http service integrations in development and test
@@ -259,6 +260,7 @@ test_files:
259
260
  - spec/dummy/public/422.html
260
261
  - spec/dummy/public/500.html
261
262
  - spec/dummy/public/404.html
263
+ - spec/dummy/log/test.log
262
264
  - spec/dummy/README.rdoc
263
265
  - spec/examples.txt
264
266
  - spec/webvalve/fake_service_spec.rb