webvalve 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +195 -0
  4. data/Rakefile +22 -0
  5. data/lib/generators/webvalve/fake_service_generator.rb +70 -0
  6. data/lib/generators/webvalve/install_generator.rb +33 -0
  7. data/lib/tasks/webvalve_tasks.rake +0 -0
  8. data/lib/webvalve.rb +40 -0
  9. data/lib/webvalve/engine.rb +26 -0
  10. data/lib/webvalve/fake_service.rb +22 -0
  11. data/lib/webvalve/fake_service_config.rb +53 -0
  12. data/lib/webvalve/fake_service_wrapper.rb +18 -0
  13. data/lib/webvalve/instrumentation.rb +4 -0
  14. data/lib/webvalve/instrumentation/log_subscriber.rb +16 -0
  15. data/lib/webvalve/instrumentation/middleware.rb +24 -0
  16. data/lib/webvalve/manager.rb +76 -0
  17. data/lib/webvalve/rspec.rb +8 -0
  18. data/lib/webvalve/version.rb +3 -0
  19. data/spec/dummy/README.rdoc +28 -0
  20. data/spec/dummy/Rakefile +6 -0
  21. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  22. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  23. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  24. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  25. data/spec/dummy/app/views/layouts/application.html.erb +13 -0
  26. data/spec/dummy/bin/bundle +3 -0
  27. data/spec/dummy/bin/rails +4 -0
  28. data/spec/dummy/bin/rake +4 -0
  29. data/spec/dummy/bin/setup +29 -0
  30. data/spec/dummy/config.ru +4 -0
  31. data/spec/dummy/config/application.rb +31 -0
  32. data/spec/dummy/config/boot.rb +5 -0
  33. data/spec/dummy/config/database.yml +25 -0
  34. data/spec/dummy/config/environment.rb +5 -0
  35. data/spec/dummy/config/environments/development.rb +41 -0
  36. data/spec/dummy/config/environments/production.rb +79 -0
  37. data/spec/dummy/config/environments/test.rb +42 -0
  38. data/spec/dummy/config/initializers/assets.rb +11 -0
  39. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  40. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  41. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  42. data/spec/dummy/config/initializers/inflections.rb +16 -0
  43. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  44. data/spec/dummy/config/initializers/session_store.rb +3 -0
  45. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  46. data/spec/dummy/config/locales/en.yml +23 -0
  47. data/spec/dummy/config/routes.rb +3 -0
  48. data/spec/dummy/config/secrets.yml +22 -0
  49. data/spec/dummy/db/test.sqlite3 +0 -0
  50. data/spec/dummy/log/development.log +0 -0
  51. data/spec/dummy/log/test.log +3938 -0
  52. data/spec/dummy/public/404.html +67 -0
  53. data/spec/dummy/public/422.html +67 -0
  54. data/spec/dummy/public/500.html +66 -0
  55. data/spec/dummy/public/favicon.ico +0 -0
  56. data/spec/examples.txt +30 -0
  57. data/spec/rails_helper.rb +14 -0
  58. data/spec/spec_helper.rb +22 -0
  59. data/spec/support/helpers.rb +24 -0
  60. data/spec/webvalve/fake_service_config_spec.rb +133 -0
  61. data/spec/webvalve/fake_service_spec.rb +47 -0
  62. data/spec/webvalve/manager_spec.rb +132 -0
  63. data/spec/webvalve_spec.rb +19 -0
  64. metadata +268 -0
@@ -0,0 +1,132 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe WebValve::Manager do
4
+
5
+ subject { described_class.send :new }
6
+
7
+ it 'is a singleton' do
8
+ described_class.is_a? Singleton
9
+ end
10
+
11
+ describe '#whitelist_url' do
12
+ it 'raises on duplicates' do
13
+ subject.whitelist_url "foo"
14
+ expect { subject.whitelist_url "foo" }.to raise_error /already registered/
15
+ expect(subject.whitelisted_urls.count).to eq 1
16
+ expect(subject.whitelisted_urls).to contain_exactly(/foo/)
17
+ end
18
+ end
19
+
20
+ describe '#register(fake_service)' do
21
+ it 'raises on duplicates' do
22
+ fake = class_double(WebValve::FakeService)
23
+
24
+ subject.register fake
25
+ expect { subject.register fake }.to raise_error /already registered/
26
+ expect(subject.fake_service_configs.count).to eq 1
27
+ expect(subject.fake_service_configs.first.service).to eq fake
28
+ end
29
+ end
30
+
31
+ describe '#register(fake_service, url:)' do
32
+ it 'stores the url' do
33
+ fake = class_double(WebValve::FakeService)
34
+
35
+ subject.register fake, url: 'http://manual.dev'
36
+ expect(subject.fake_service_configs.first.service_url).to eq 'http://manual.dev'
37
+ end
38
+ end
39
+
40
+ describe '#setup' do
41
+ it 'enables webmock' do
42
+ allow(WebMock).to receive(:enable!)
43
+
44
+ subject.setup
45
+
46
+ expect(WebMock).to have_received(:enable!)
47
+ end
48
+
49
+ it 'disables network connections' do
50
+ allow(WebMock).to receive(:disable_net_connect!)
51
+
52
+ subject.setup
53
+
54
+ expect(WebMock).to have_received(:disable_net_connect!)
55
+ end
56
+
57
+ it 'allows localhost connections' do
58
+ allow(WebMock).to receive(:disable_net_connect!)
59
+
60
+ subject.setup
61
+
62
+ expect(WebMock).to have_received(:disable_net_connect!).with(hash_including(allow_localhost: true))
63
+ end
64
+
65
+ context 'in test environment' do
66
+ around do |example|
67
+ with_rails_env 'test' do
68
+ example.run
69
+ end
70
+ end
71
+
72
+ it 'does not whitelist configured urls in webmock' do
73
+ allow(WebMock).to receive(:disable_net_connect!)
74
+ results = [%r{\Ahttp://foo\.dev}, %r{\Ahttp://bar\.dev}]
75
+
76
+ subject.whitelist_url 'http://foo.dev'
77
+ subject.whitelist_url 'http://bar.dev'
78
+
79
+ subject.setup
80
+
81
+ expect(WebMock).not_to have_received(:disable_net_connect!)
82
+ .with(hash_including(allow: results))
83
+ end
84
+ end
85
+
86
+ context 'in non-test environment' do
87
+ around do |example|
88
+ with_rails_env 'development' do
89
+ example.run
90
+ end
91
+ end
92
+
93
+ it 'whitelists configured urls in webmock' do
94
+ allow(WebMock).to receive(:disable_net_connect!)
95
+ results = [%r{\Ahttp://foo\.dev}, %r{\Ahttp://bar\.dev}]
96
+
97
+ subject.whitelist_url 'http://foo.dev'
98
+ subject.whitelist_url 'http://bar.dev'
99
+
100
+ subject.setup
101
+
102
+ expect(WebMock).to have_received(:disable_net_connect!)
103
+ .with(hash_including(allow: results))
104
+ end
105
+
106
+ it 'mocks registered fakes that are not enabled in ENV' do
107
+ disabled_service = class_double(WebValve::FakeService, name: 'FakeSomething')
108
+ web_mock_stubble = double(to_rack: true)
109
+ allow(WebMock).to receive(:stub_request).and_return(web_mock_stubble)
110
+
111
+ with_env 'SOMETHING_API_URL' => 'http://fake.dev' do
112
+ subject.register disabled_service
113
+ subject.setup
114
+ end
115
+
116
+ expect(WebMock).to have_received(:stub_request).with(:any, %r{\Ahttp://fake\.dev})
117
+ expect(web_mock_stubble).to have_received(:to_rack)
118
+ end
119
+
120
+ it 'whitelists registered fakes that are enabled in ENV' do
121
+ enabled_service = class_double(WebValve::FakeService, name: 'FakeSomething')
122
+
123
+ with_env 'SOMETHING_ENABLED' => '1', 'SOMETHING_API_URL' => 'http://real.dev' do
124
+ subject.register enabled_service
125
+ subject.setup
126
+ end
127
+
128
+ expect(subject.whitelisted_urls).to include 'http://real.dev'
129
+ end
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,19 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe WebValve do
4
+ it 'delegates .setup to manager' do
5
+ expect(described_class).to respond_to(:setup)
6
+ end
7
+
8
+ it 'delegates .register to manager' do
9
+ expect(described_class).to respond_to(:register)
10
+ end
11
+
12
+ it 'delegates .reset to manager' do
13
+ expect(described_class).to respond_to(:reset)
14
+ end
15
+
16
+ it 'delegates .whitelist_url to manager' do
17
+ expect(described_class).to respond_to(:whitelist_url)
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,268 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: webvalve
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ platform: ruby
6
+ authors:
7
+ - Sam Moore
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-02-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.2'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '6'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '4.2'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '6'
33
+ - !ruby/object:Gem::Dependency
34
+ name: sinatra
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.4'
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: 3.beta
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">"
48
+ - !ruby/object:Gem::Version
49
+ version: '1.4'
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: 3.beta
53
+ - !ruby/object:Gem::Dependency
54
+ name: sinatra-contrib
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">"
58
+ - !ruby/object:Gem::Version
59
+ version: '1.4'
60
+ - - "<"
61
+ - !ruby/object:Gem::Version
62
+ version: 3.beta
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">"
68
+ - !ruby/object:Gem::Version
69
+ version: '1.4'
70
+ - - "<"
71
+ - !ruby/object:Gem::Version
72
+ version: 3.beta
73
+ - !ruby/object:Gem::Dependency
74
+ name: webmock
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: '2.0'
80
+ type: :runtime
81
+ prerelease: false
82
+ version_requirements: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - "~>"
85
+ - !ruby/object:Gem::Version
86
+ version: '2.0'
87
+ - !ruby/object:Gem::Dependency
88
+ name: rspec-rails
89
+ requirement: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ type: :development
95
+ prerelease: false
96
+ version_requirements: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ - !ruby/object:Gem::Dependency
102
+ name: pry
103
+ requirement: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ type: :development
109
+ prerelease: false
110
+ version_requirements: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ - !ruby/object:Gem::Dependency
116
+ name: yard
117
+ requirement: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ type: :development
123
+ prerelease: false
124
+ version_requirements: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ description: Betterment's library for developing and testing service-oriented apps
130
+ in isolation with WebMock and Sinatra-based fakes.
131
+ email:
132
+ - sam@betterment.com
133
+ executables: []
134
+ extensions: []
135
+ extra_rdoc_files: []
136
+ files:
137
+ - LICENSE
138
+ - README.md
139
+ - Rakefile
140
+ - lib/generators/webvalve/fake_service_generator.rb
141
+ - lib/generators/webvalve/install_generator.rb
142
+ - lib/tasks/webvalve_tasks.rake
143
+ - lib/webvalve.rb
144
+ - lib/webvalve/engine.rb
145
+ - lib/webvalve/fake_service.rb
146
+ - lib/webvalve/fake_service_config.rb
147
+ - lib/webvalve/fake_service_wrapper.rb
148
+ - lib/webvalve/instrumentation.rb
149
+ - lib/webvalve/instrumentation/log_subscriber.rb
150
+ - lib/webvalve/instrumentation/middleware.rb
151
+ - lib/webvalve/manager.rb
152
+ - lib/webvalve/rspec.rb
153
+ - lib/webvalve/version.rb
154
+ - spec/dummy/README.rdoc
155
+ - spec/dummy/Rakefile
156
+ - spec/dummy/app/assets/javascripts/application.js
157
+ - spec/dummy/app/assets/stylesheets/application.css
158
+ - spec/dummy/app/controllers/application_controller.rb
159
+ - spec/dummy/app/helpers/application_helper.rb
160
+ - spec/dummy/app/views/layouts/application.html.erb
161
+ - spec/dummy/bin/bundle
162
+ - spec/dummy/bin/rails
163
+ - spec/dummy/bin/rake
164
+ - spec/dummy/bin/setup
165
+ - spec/dummy/config.ru
166
+ - spec/dummy/config/application.rb
167
+ - spec/dummy/config/boot.rb
168
+ - spec/dummy/config/database.yml
169
+ - spec/dummy/config/environment.rb
170
+ - spec/dummy/config/environments/development.rb
171
+ - spec/dummy/config/environments/production.rb
172
+ - spec/dummy/config/environments/test.rb
173
+ - spec/dummy/config/initializers/assets.rb
174
+ - spec/dummy/config/initializers/backtrace_silencers.rb
175
+ - spec/dummy/config/initializers/cookies_serializer.rb
176
+ - spec/dummy/config/initializers/filter_parameter_logging.rb
177
+ - spec/dummy/config/initializers/inflections.rb
178
+ - spec/dummy/config/initializers/mime_types.rb
179
+ - spec/dummy/config/initializers/session_store.rb
180
+ - spec/dummy/config/initializers/wrap_parameters.rb
181
+ - spec/dummy/config/locales/en.yml
182
+ - spec/dummy/config/routes.rb
183
+ - spec/dummy/config/secrets.yml
184
+ - spec/dummy/db/test.sqlite3
185
+ - spec/dummy/log/development.log
186
+ - spec/dummy/log/test.log
187
+ - spec/dummy/public/404.html
188
+ - spec/dummy/public/422.html
189
+ - spec/dummy/public/500.html
190
+ - spec/dummy/public/favicon.ico
191
+ - spec/examples.txt
192
+ - spec/rails_helper.rb
193
+ - spec/spec_helper.rb
194
+ - spec/support/helpers.rb
195
+ - spec/webvalve/fake_service_config_spec.rb
196
+ - spec/webvalve/fake_service_spec.rb
197
+ - spec/webvalve/manager_spec.rb
198
+ - spec/webvalve_spec.rb
199
+ homepage: https://github.com/Betterment/webvalve
200
+ licenses:
201
+ - MIT
202
+ metadata: {}
203
+ post_install_message:
204
+ rdoc_options: []
205
+ require_paths:
206
+ - lib
207
+ required_ruby_version: !ruby/object:Gem::Requirement
208
+ requirements:
209
+ - - ">="
210
+ - !ruby/object:Gem::Version
211
+ version: '2'
212
+ required_rubygems_version: !ruby/object:Gem::Requirement
213
+ requirements:
214
+ - - ">="
215
+ - !ruby/object:Gem::Version
216
+ version: '0'
217
+ requirements: []
218
+ rubyforge_project:
219
+ rubygems_version: 2.5.1
220
+ signing_key:
221
+ specification_version: 4
222
+ summary: A library for faking http service integrations in development and test
223
+ test_files:
224
+ - spec/dummy/app/assets/javascripts/application.js
225
+ - spec/dummy/app/assets/stylesheets/application.css
226
+ - spec/dummy/app/controllers/application_controller.rb
227
+ - spec/dummy/app/helpers/application_helper.rb
228
+ - spec/dummy/app/views/layouts/application.html.erb
229
+ - spec/dummy/bin/bundle
230
+ - spec/dummy/bin/rails
231
+ - spec/dummy/bin/rake
232
+ - spec/dummy/bin/setup
233
+ - spec/dummy/config/application.rb
234
+ - spec/dummy/config/boot.rb
235
+ - spec/dummy/config/database.yml
236
+ - spec/dummy/config/environment.rb
237
+ - spec/dummy/config/environments/development.rb
238
+ - spec/dummy/config/environments/production.rb
239
+ - spec/dummy/config/environments/test.rb
240
+ - spec/dummy/config/initializers/assets.rb
241
+ - spec/dummy/config/initializers/backtrace_silencers.rb
242
+ - spec/dummy/config/initializers/cookies_serializer.rb
243
+ - spec/dummy/config/initializers/filter_parameter_logging.rb
244
+ - spec/dummy/config/initializers/inflections.rb
245
+ - spec/dummy/config/initializers/mime_types.rb
246
+ - spec/dummy/config/initializers/session_store.rb
247
+ - spec/dummy/config/initializers/wrap_parameters.rb
248
+ - spec/dummy/config/locales/en.yml
249
+ - spec/dummy/config/routes.rb
250
+ - spec/dummy/config/secrets.yml
251
+ - spec/dummy/config.ru
252
+ - spec/dummy/db/test.sqlite3
253
+ - spec/dummy/log/development.log
254
+ - spec/dummy/log/test.log
255
+ - spec/dummy/public/404.html
256
+ - spec/dummy/public/422.html
257
+ - spec/dummy/public/500.html
258
+ - spec/dummy/public/favicon.ico
259
+ - spec/dummy/Rakefile
260
+ - spec/dummy/README.rdoc
261
+ - spec/examples.txt
262
+ - spec/rails_helper.rb
263
+ - spec/spec_helper.rb
264
+ - spec/support/helpers.rb
265
+ - spec/webvalve/fake_service_config_spec.rb
266
+ - spec/webvalve/fake_service_spec.rb
267
+ - spec/webvalve/manager_spec.rb
268
+ - spec/webvalve_spec.rb