webvalve 0.9.3 → 0.9.4

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
  SHA1:
3
- metadata.gz: 3c7d7e47d1e476165ad4a624652f8f739a89f88b
4
- data.tar.gz: 9b52e6fe109b4e32d904ae4757369db755623a13
3
+ metadata.gz: 5e60a2b347e2feeac25e77f2f00ea08bd47a21ac
4
+ data.tar.gz: f24d8a35e41dcb5bb9ddf34c5bc6462a2a0ac2d0
5
5
  SHA512:
6
- metadata.gz: 20b8faa5fac8de89d4c512d852e1e9e8dede7552ad0ca5d82d7041b472c537064f1f9a2b64be0238317fbe6209e2f9fe5a184d38219cdfe4c7c18b2bedcf6bd1
7
- data.tar.gz: c21e6dcb440acd1c8ea4e04a990891876f6975bb86a962e1c3d4a8a8f096ebac6ae13d711c624f1f3b9d2903b58cd354d3bd5463b7d19889d01d31cc98f73151
6
+ metadata.gz: 1e683adde8772005f7128f32cc5bed08477acf771bece27ebd18248eddbd90137e2ff18e9a38363ab84b51611d2da5ecde1f7cb3321944bae770e3af99e5df76
7
+ data.tar.gz: 6398326ced19332fd63ba9d1eac2dd69de6a3f1970c2186690f46479ad1d4f3a4735a357a34c5aaae89670c87b287af7c7ec086fa48561306fd65308327a849d
data/README.md CHANGED
@@ -18,7 +18,8 @@ Check out [the Rails at Scale talk](https://www.youtube.com/watch?v=Nd9hnffxCP8)
18
18
 
19
19
  ## Getting Started
20
20
 
21
- WebValve is designed to work with Rails 4+.
21
+ WebValve is designed to work with Rails 4+, but it also should work with
22
+ non-Rails apps and gems.
22
23
 
23
24
  ### Installation
24
25
 
@@ -75,6 +76,8 @@ This will drop a new file in your config directory.
75
76
  # WebValve.whitelist_url 'https://example.com'
76
77
  ```
77
78
 
79
+ If you're not using Rails, you can create this file for yourself.
80
+
78
81
  ### Registering a service
79
82
 
80
83
  Next, you will want create a `FakeService` and register
@@ -113,6 +116,9 @@ And it will automatically register it in `config/webvalve.rb`
113
116
  WebValve.register FakeBank
114
117
  ```
115
118
 
119
+ Again, if you're not using Rails, you'll have to create this file
120
+ yourself and update the config file manually.
121
+
116
122
  You'll also want to define an environment variable for the base url of
117
123
  your service.
118
124
 
@@ -141,7 +147,7 @@ have to configure WebValve at the beginning of each test. For RSpec, there
141
147
  is a configuration provided.
142
148
 
143
149
  ```ruby
144
- # spec/rails_helper.rb
150
+ # spec/spec_helper.rb
145
151
  require 'webvalve/rspec'
146
152
  ```
147
153
 
@@ -202,6 +208,13 @@ environments; however, it can be enabled in other environments by
202
208
  setting `WEBVALVE_ENABLED=true`. This can be useful for spinning up
203
209
  cheap, one-off environments for user-testing or demos.
204
210
 
211
+ > Can I use WebValve without Rails?
212
+
213
+ Yep! If you're not using Rails, you'll have to load the config file
214
+ yourself. You will want to explicitly `require` each of your fake
215
+ services in your `config/webvalve.rb`, `require` your config file, and
216
+ call `WebValve.setup` during your app's boot-up process.
217
+
205
218
  ## How to Contribute
206
219
 
207
220
  We would love for you to contribute! Anything that benefits the majority
data/Rakefile CHANGED
@@ -4,25 +4,18 @@ rescue LoadError
4
4
  puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
5
  end
6
6
 
7
- APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
8
- load 'rails/tasks/engine.rake'
9
-
10
7
  Bundler::GemHelper.install_tasks
11
8
 
12
- if Rails.env.development? || Rails.env.test?
13
- if defined? Dummy
14
- task(:default).clear
15
- if ENV['APPRAISAL_INITIALIZED'] || ENV['TRAVIS']
16
- require 'rspec/core'
17
- require 'rspec/core/rake_task'
18
- RSpec::Core::RakeTask.new(:spec)
19
- task default: :spec
20
- else
21
- require 'appraisal'
22
- Appraisal::Task.new
23
- task default: :appraisal
24
- end
25
- end
9
+ task(:default).clear
10
+ if ENV['APPRAISAL_INITIALIZED'] || ENV['TRAVIS']
11
+ require 'rspec/core'
12
+ require 'rspec/core/rake_task'
13
+ RSpec::Core::RakeTask.new(:spec)
14
+ task default: :spec
15
+ else
16
+ require 'appraisal'
17
+ Appraisal::Task.new
18
+ task default: :appraisal
26
19
  end
27
20
 
28
21
  require 'yard'
@@ -1,4 +1,6 @@
1
1
  require 'set'
2
+ require 'active_support'
3
+ require 'active_support/core_ext'
2
4
 
3
5
  module WebValve
4
6
  ALWAYS_ENABLED_ENVS = %w(development test).freeze
@@ -16,9 +18,9 @@ module WebValve
16
18
  delegate :setup, :register, :whitelist_url, :reset, to: :manager
17
19
 
18
20
  def enabled?
19
- if Rails.env.in?(ALWAYS_ENABLED_ENVS)
21
+ if env.in?(ALWAYS_ENABLED_ENVS)
20
22
  if ENV.key? 'WEBVALVE_ENABLED'
21
- Rails.logger.warn(<<~MESSAGE)
23
+ logger.warn(<<~MESSAGE)
22
24
  WARNING: Ignoring WEBVALVE_ENABLED environment variable setting (#{ENV['WEBVALVE_ENABLED']})
23
25
  WebValve is always enabled in development and test environments.
24
26
  MESSAGE
@@ -33,7 +35,27 @@ module WebValve
33
35
  @config_paths ||= Set.new
34
36
  end
35
37
 
36
- private
38
+ if defined?(::Rails)
39
+ delegate :env, :env=, :logger, :logger=, to: ::Rails
40
+ else
41
+ def env
42
+ @env ||= (ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development').inquiry
43
+ end
44
+
45
+ def env=(env)
46
+ @env = env&.inquiry
47
+ end
48
+
49
+ def logger
50
+ @logger ||= ActiveSupport::Logger.new(STDOUT).tap do |l|
51
+ l.formatter = ::Logger::Formatter.new
52
+ end
53
+ end
54
+
55
+ def logger=(logger)
56
+ @logger = logger
57
+ end
58
+ end
37
59
 
38
60
  def manager
39
61
  WebValve::Manager.instance
@@ -41,8 +63,8 @@ module WebValve
41
63
  end
42
64
  end
43
65
 
66
+ require 'webvalve/railtie' if defined?(::Rails)
44
67
  require 'webvalve/instrumentation'
45
- require 'webvalve/engine'
46
68
  require 'webvalve/fake_service'
47
69
  require 'webvalve/fake_service_wrapper'
48
70
  require 'webvalve/fake_service_config'
@@ -8,7 +8,7 @@ module WebValve
8
8
  end
9
9
 
10
10
  def should_intercept?
11
- Rails.env.test? || # always intercept in test
11
+ WebValve.env.test? || # always intercept in test
12
12
  (WebValve.enabled? && !service_enabled_in_env?)
13
13
  end
14
14
 
@@ -1,3 +1,5 @@
1
+ require 'active_support/log_subscriber'
2
+
1
3
  module WebValve
2
4
  module Instrumentation
3
5
  class LogSubscriber < ActiveSupport::LogSubscriber
@@ -1,3 +1,5 @@
1
+ require 'active_support/notifications'
2
+
1
3
  module WebValve
2
4
  module Instrumentation
3
5
  class Middleware
@@ -50,7 +50,7 @@ module WebValve
50
50
 
51
51
  def webmock_disable_options
52
52
  { allow_localhost: true }.tap do |opts|
53
- opts[:allow] = whitelisted_url_regexps unless Rails.env.test?
53
+ opts[:allow] = whitelisted_url_regexps unless WebValve.env.test?
54
54
  end
55
55
  end
56
56
 
@@ -1,9 +1,7 @@
1
1
  module WebValve
2
- class Engine < ::Rails::Engine
3
- isolate_namespace WebValve
4
-
2
+ class Railtie < ::Rails::Railtie
5
3
  if WebValve.enabled?
6
- initializer "webvalve.set_autoload_paths", before: :set_autoload_paths do |app|
4
+ initializer 'webvalve.set_autoload_paths', before: :set_autoload_paths do |app|
7
5
  WebValve.config_paths << app.root
8
6
 
9
7
  WebValve.config_paths.each do |root|
@@ -11,7 +9,7 @@ module WebValve
11
9
  end
12
10
  end
13
11
 
14
- initializer "webvalve.setup" do
12
+ initializer 'webvalve.setup' do
15
13
  WebValve.config_paths.each do |root|
16
14
  path = root.join('config', 'webvalve.rb').to_s
17
15
  load path if File.exist?(path)
@@ -1,3 +1,3 @@
1
1
  module WebValve
2
- VERSION = "0.9.3"
2
+ VERSION = "0.9.4"
3
3
  end
@@ -1,3 +1,2 @@
1
1
  Rails.application.routes.draw do
2
- mount WebValve::Engine => "/webvalve"
3
2
  end
@@ -0,0 +1,36 @@
1
+ WebValve Request Captured (0.4ms) dummy.dev GET /foos []
2
+ WebValve Request Captured (4.8ms) dummy.dev GET /widgets [200]
3
+ WebValve Request Captured (3.0ms) dummy.dev GET /widgets [200]
4
+ WebValve Request Captured (0.8ms) dummy.dev GET /foos []
5
+ WebValve Request Captured (3.9ms) dummy.dev GET /widgets [200]
6
+ WebValve Request Captured (0.4ms) dummy.dev GET /foos []
7
+ WebValve Request Captured (2.6ms) dummy.dev GET /widgets [200]
8
+ WebValve Request Captured (0.5ms) dummy.dev GET /foos []
9
+ WebValve Request Captured (0.4ms) dummy.dev GET /foos []
10
+ WebValve Request Captured (2.2ms) dummy.dev GET /widgets [200]
11
+ WebValve Request Captured (0.5ms) dummy.dev GET /foos []
12
+ WebValve Request Captured (3.9ms) dummy.dev GET /widgets [200]
13
+ WebValve Request Captured (2.1ms) dummy.dev GET /widgets [200]
14
+ WebValve Request Captured (0.3ms) dummy.dev GET /foos []
15
+ WebValve Request Captured (2.9ms) dummy.dev GET /widgets [200]
16
+ WebValve Request Captured (0.4ms) dummy.dev GET /foos []
17
+ WebValve Request Captured (0.4ms) dummy.dev GET /foos []
18
+ WebValve Request Captured (4.9ms) dummy.dev GET /widgets [200]
19
+ WebValve Request Captured (2.1ms) dummy.dev GET /widgets [200]
20
+ WebValve Request Captured (0.4ms) dummy.dev GET /foos []
21
+ WebValve Request Captured (0.5ms) dummy.dev GET /foos []
22
+ WebValve Request Captured (2.2ms) dummy.dev GET /widgets [200]
23
+ WebValve Request Captured (0.5ms) dummy.dev GET /foos []
24
+ WebValve Request Captured (2.6ms) dummy.dev GET /widgets [200]
25
+ WebValve Request Captured (6.6ms) dummy.dev GET /widgets [200]
26
+ WebValve Request Captured (0.4ms) dummy.dev GET /foos []
27
+ WebValve Request Captured (0.5ms) dummy.dev GET /foos []
28
+ WebValve Request Captured (2.5ms) dummy.dev GET /widgets [200]
29
+ WebValve Request Captured (0.4ms) dummy.dev GET /foos []
30
+ WebValve Request Captured (2.2ms) dummy.dev GET /widgets [200]
31
+ WebValve Request Captured (2.1ms) dummy.dev GET /widgets [200]
32
+ WebValve Request Captured (0.3ms) dummy.dev GET /foos []
33
+ WebValve Request Captured (2.4ms) dummy.dev GET /widgets [200]
34
+ WebValve Request Captured (0.3ms) dummy.dev GET /foos []
35
+ WebValve Request Captured (0.4ms) dummy.dev GET /foos []
36
+ WebValve Request Captured (2.2ms) dummy.dev GET /widgets [200]
@@ -0,0 +1,32 @@
1
+ example_id | status | run_time |
2
+ ------------------------------------------------------ | ------ | --------------- |
3
+ ./spec/webvalve/fake_service_config_spec.rb[1:1:1:1] | passed | 0.00015 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.00019 seconds |
6
+ ./spec/webvalve/fake_service_config_spec.rb[1:1:2:2] | passed | 0.00026 seconds |
7
+ ./spec/webvalve/fake_service_config_spec.rb[1:1:2:3] | passed | 0.00024 seconds |
8
+ ./spec/webvalve/fake_service_config_spec.rb[1:1:3:1] | passed | 0.00016 seconds |
9
+ ./spec/webvalve/fake_service_config_spec.rb[1:1:3:2] | passed | 0.00021 seconds |
10
+ ./spec/webvalve/fake_service_config_spec.rb[1:1:3:3:1] | passed | 0.00019 seconds |
11
+ ./spec/webvalve/fake_service_config_spec.rb[1:1:3:3:2] | passed | 0.00027 seconds |
12
+ ./spec/webvalve/fake_service_config_spec.rb[1:2:1] | passed | 0.0002 seconds |
13
+ ./spec/webvalve/fake_service_config_spec.rb[1:2:2] | passed | 0.0002 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.00236 seconds |
16
+ ./spec/webvalve/fake_service_spec.rb[1:2:1] | passed | 0.00387 seconds |
17
+ ./spec/webvalve/fake_service_spec.rb[1:2:2] | passed | 0.02133 seconds |
18
+ ./spec/webvalve/manager_spec.rb[1:1] | passed | 0.00005 seconds |
19
+ ./spec/webvalve/manager_spec.rb[1:2:1] | passed | 0.00213 seconds |
20
+ ./spec/webvalve/manager_spec.rb[1:3:1] | passed | 0.00019 seconds |
21
+ ./spec/webvalve/manager_spec.rb[1:4:1] | passed | 0.00011 seconds |
22
+ ./spec/webvalve/manager_spec.rb[1:5:1] | passed | 0.00024 seconds |
23
+ ./spec/webvalve/manager_spec.rb[1:5:2] | passed | 0.0084 seconds |
24
+ ./spec/webvalve/manager_spec.rb[1:5:3] | passed | 0.00052 seconds |
25
+ ./spec/webvalve/manager_spec.rb[1:5:4:1] | passed | 0.00049 seconds |
26
+ ./spec/webvalve/manager_spec.rb[1:5:5:1] | passed | 0.0006 seconds |
27
+ ./spec/webvalve/manager_spec.rb[1:5:5:2] | passed | 0.00079 seconds |
28
+ ./spec/webvalve/manager_spec.rb[1:5:5:3] | passed | 0.0019 seconds |
29
+ ./spec/webvalve_spec.rb[1:1] | passed | 0.00012 seconds |
30
+ ./spec/webvalve_spec.rb[1:2] | passed | 0.00006 seconds |
31
+ ./spec/webvalve_spec.rb[1:3] | passed | 0.00006 seconds |
32
+ ./spec/webvalve_spec.rb[1:4] | passed | 0.00107 seconds |
@@ -1,3 +1,11 @@
1
+ ENV['RAILS_ENV'] ||= 'test'
2
+ require File.expand_path('dummy/config/environment', __dir__) if ENV['BUNDLE_GEMFILE'] =~ /rails/
3
+ require 'rspec'
4
+ require 'pry'
5
+ require 'webvalve'
6
+
7
+ Dir[File.join(__dir__, 'support/**/*.rb')].each { |f| require f }
8
+
1
9
  RSpec.configure do |config|
2
10
  config.expect_with :rspec do |expectations|
3
11
  expectations.include_chain_clauses_in_custom_matcher_descriptions = true
@@ -18,5 +26,7 @@ RSpec.configure do |config|
18
26
  config.order = :random
19
27
  Kernel.srand config.seed
20
28
 
21
- # config.profile_examples = 10
29
+ config.profile_examples = 10
30
+
31
+ config.include Helpers
22
32
  end
@@ -15,10 +15,10 @@ module Helpers
15
15
  end
16
16
 
17
17
  def with_rails_env(env)
18
- initial_env = Rails.env
19
- Rails.env = env
18
+ initial_env = WebValve.env
19
+ WebValve.env = env
20
20
  yield
21
21
  ensure
22
- Rails.env = initial_env
22
+ WebValve.env = initial_env
23
23
  end
24
24
  end
@@ -1,4 +1,4 @@
1
- require 'rails_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  RSpec.describe WebValve::FakeServiceConfig do
4
4
  let(:fake_service) do
@@ -1,4 +1,4 @@
1
- require 'rails_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  RSpec.describe WebValve::FakeService do
4
4
  subject do
@@ -1,4 +1,4 @@
1
- require 'rails_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  RSpec.describe WebValve::Manager do
4
4
 
@@ -1,4 +1,4 @@
1
- require 'rails_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  RSpec.describe WebValve do
4
4
  it 'delegates .setup to manager' do
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webvalve
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Moore
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-26 00:00:00.000000000 Z
11
+ date: 2018-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rails
14
+ name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -93,7 +93,7 @@ dependencies:
93
93
  - !ruby/object:Gem::Version
94
94
  version: 2.2.0
95
95
  - !ruby/object:Gem::Dependency
96
- name: rspec-rails
96
+ name: rspec
97
97
  requirement: !ruby/object:Gem::Requirement
98
98
  requirements:
99
99
  - - ">="
@@ -147,9 +147,7 @@ files:
147
147
  - Rakefile
148
148
  - lib/generators/webvalve/fake_service_generator.rb
149
149
  - lib/generators/webvalve/install_generator.rb
150
- - lib/tasks/webvalve_tasks.rake
151
150
  - lib/webvalve.rb
152
- - lib/webvalve/engine.rb
153
151
  - lib/webvalve/fake_service.rb
154
152
  - lib/webvalve/fake_service_config.rb
155
153
  - lib/webvalve/fake_service_wrapper.rb
@@ -157,6 +155,7 @@ files:
157
155
  - lib/webvalve/instrumentation/log_subscriber.rb
158
156
  - lib/webvalve/instrumentation/middleware.rb
159
157
  - lib/webvalve/manager.rb
158
+ - lib/webvalve/railtie.rb
160
159
  - lib/webvalve/rspec.rb
161
160
  - lib/webvalve/version.rb
162
161
  - spec/dummy/README.rdoc
@@ -189,11 +188,12 @@ files:
189
188
  - spec/dummy/config/locales/en.yml
190
189
  - spec/dummy/config/routes.rb
191
190
  - spec/dummy/config/secrets.yml
191
+ - spec/dummy/log/test.log
192
192
  - spec/dummy/public/404.html
193
193
  - spec/dummy/public/422.html
194
194
  - spec/dummy/public/500.html
195
195
  - spec/dummy/public/favicon.ico
196
- - spec/rails_helper.rb
196
+ - spec/examples.txt
197
197
  - spec/spec_helper.rb
198
198
  - spec/support/helpers.rb
199
199
  - spec/webvalve/fake_service_config_spec.rb
@@ -259,10 +259,11 @@ test_files:
259
259
  - spec/dummy/public/422.html
260
260
  - spec/dummy/public/500.html
261
261
  - spec/dummy/public/404.html
262
+ - spec/dummy/log/test.log
262
263
  - spec/dummy/README.rdoc
264
+ - spec/examples.txt
263
265
  - spec/webvalve/fake_service_spec.rb
264
266
  - spec/webvalve/fake_service_config_spec.rb
265
267
  - spec/webvalve/manager_spec.rb
266
268
  - spec/webvalve_spec.rb
267
269
  - spec/support/helpers.rb
268
- - spec/rails_helper.rb
File without changes
@@ -1,14 +0,0 @@
1
- ENV['RAILS_ENV'] ||= 'test'
2
- require File.expand_path('../dummy/config/environment', __FILE__)
3
- abort("The Rails environment is running in production mode!") if Rails.env.production?
4
- require 'spec_helper'
5
- require 'rspec/rails'
6
- require 'pry'
7
- Dir[Rails.root.join("#{WebValve::Engine.root}/spec/support/**/*.rb")].each { |f| require f }
8
-
9
- RSpec.configure do |config|
10
- config.use_transactional_fixtures = true
11
- config.infer_spec_type_from_file_location!
12
- config.filter_rails_from_backtrace!
13
- config.include Helpers
14
- end