vcr_cable 0.2.3 → 0.3.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4914b147c7f4d7934be9b87366a4c731f1ee4870
4
+ data.tar.gz: ddf96eac16c7d512efa4c95f18e240a568c31dcb
5
+ SHA512:
6
+ metadata.gz: 904b5ffe6ebfecdcc1144c0ccd44a3ef8e25f3440fb14564fd98ea60fde7f56b82f7b76a39be1e1b15d8af1f461247eacaeaefe5e41fdd14ea665a36253357dd
7
+ data.tar.gz: d845a1376a8062f0f1ec9c922ac2055440042750a7cac0fd1a770f63659df016cec09e5a187525160709001a0647fbba0f5fd2b1bf5eca29df81372faf90afc4
data/README.md CHANGED
@@ -2,51 +2,53 @@
2
2
 
3
3
  [![Build Status](https://secure.travis-ci.org/spaghetticode/vcr_cable.png)](http://travis-ci.org/spaghetticode/vcr_cable)
4
4
 
5
- This gem allows to use VCR in development. This is quite handy when your app
5
+ This gem allows you to use VCR in development. This is quite handy when your app
6
6
  interacts frequently with external services and you're on a sloppy connection,
7
- or when you want to save bandwidth, or when you happent to have no connection
7
+ or when you want to save bandwidth, or when you happen to have no connection
8
8
  at all.
9
9
 
10
10
 
11
11
  ## Usage
12
12
 
13
- Add required gems to your Gemfile:
13
+ Add the required gem(s) to your Gemfile:
14
14
 
15
15
  ```ruby
16
16
  gem 'vcr_cable'
17
- gem 'webmock' # or fakeweb
17
+ gem 'fakeweb' # or webmock
18
18
  ```
19
- Now all external requests will hit the remote servers only one time, and the
20
- application will subsequently use the recorded data.
21
19
 
20
+ *Note: You can choose between the FakeWeb and WebMock gems for faking web requests. If one of those gems is already loaded by your application it will be used automatically.*
21
+
22
+ That's it! Now all external requests will hit the remote servers only one time, and the application will subsequently use the recorded data.
22
23
 
23
24
  ## Custom VCR Configuration
24
25
 
25
- The default VCR configuration values are (extracted from ```lib/vcr_cable.rb```):
26
+ The default VCR configuration is:
26
27
 
27
- ```ruby
28
- DEFAULT_CONFIG = {
29
- 'hook_into' => :fakeweb,
30
- 'cassette_library_dir' => 'development_cassettes',
31
- 'allow_http_connections_when_no_cassette' => true
32
- }
28
+ ```yaml
29
+ development:
30
+ hook_into: fakeweb
31
+ cassette_library_dir: development_cassettes
32
+ allow_http_connections_when_no_cassette: true
33
+ disable_vcr_cable: false
33
34
  ```
34
35
 
35
- If you want to override those values you can generate the vcr_cable.yml config
36
- file and edit its params:
36
+ If you want to override those values or configure vcr_cable to work in some
37
+ other environment you can generate the `vcr_cable.yml` config file and update it:
37
38
 
38
39
  ```bash
39
40
  bundle exec rails generate vcr_cable
40
41
  ```
41
42
 
42
- You will find the generated file in the ```config``` folder of your rails
43
- application.
43
+ The file will be located in the ```config``` folder of your rails application.
44
+
45
+ You can also disable vcr_cable by setting `DISABLE_VCR_CABLE=true` in your environment. This would allow each developer to opt into or out of vcr_cable on his/her own machine, for example.
44
46
 
45
47
  ## Contributing
46
48
 
47
49
  1. Fork it
48
50
  2. Create your feature branch (`git checkout -b my-new-feature`)
49
- 3. Add your feature tests to the rspec/cucumber test suite
51
+ 3. Add your feature tests to the test suite
50
52
  4. Commit your changes (`git commit -am 'Added some feature'`)
51
53
  5. Push to the branch (`git push origin my-new-feature`)
52
54
  6. Create new Pull Request
@@ -2,3 +2,4 @@ development:
2
2
  hook_into: fakeweb
3
3
  cassette_library_dir: development_cassettes
4
4
  allow_http_connections_when_no_cassette: true
5
+ disable_vcr_cable: false
data/lib/vcr_cable.rb CHANGED
@@ -2,12 +2,12 @@ require 'vcr'
2
2
  require 'vcr_cable/railtie' if defined? Rails
3
3
 
4
4
  module VcrCable
5
+ class InvalidMockingLibraryError < ArgumentError; end;
5
6
  extend self
6
7
 
7
8
  CONFIG_FILE = 'vcr_cable.yml'
8
9
  DEFAULT_CONFIG = {
9
10
  'development' => {
10
- 'hook_into' => :fakeweb,
11
11
  'cassette_library_dir' => 'development_cassettes',
12
12
  'allow_http_connections_when_no_cassette' => true
13
13
  }
@@ -22,30 +22,70 @@ module VcrCable
22
22
  end
23
23
 
24
24
  def config
25
- @config ||= global_config[env] || {}
25
+ @config ||= default_config.merge local_config
26
26
  end
27
27
 
28
28
  def enabled?
29
- config.present?
29
+ config.present? && !config['disable_vcr_cable']
30
+ end
31
+
32
+ def disabled_by_env?
33
+ %w(true 1).include?(ENV['DISABLE_VCR_CABLE'])
30
34
  end
31
35
 
32
36
  def reset_config
33
- %w[global_config env_config config_file config].each do |name|
37
+ %w[local_config config_file default_config config].each do |name|
34
38
  instance_variable_set "@#{name}", nil
35
39
  end
36
40
  end
37
41
 
38
- def global_config
39
- @global_config ||= File.file?(config_file) ? YAML.load_file(config_file) : DEFAULT_CONFIG
40
- end
41
-
42
42
  private
43
43
 
44
44
  def env
45
45
  Rails.env
46
46
  end
47
47
 
48
+ def local_config
49
+ @local_config ||= if File.file? config_file
50
+ YAML.load(ERB.new(config_file.read).result).fetch env, {}
51
+ else
52
+ {}
53
+ end
54
+ end
55
+
48
56
  def config_file
49
57
  @config_file ||= Rails.root.join 'config', CONFIG_FILE
50
58
  end
59
+
60
+ def default_config
61
+ @default_config ||= if DEFAULT_CONFIG.has_key? env
62
+ DEFAULT_CONFIG[env].merge({
63
+ 'hook_into' => select_default_mocking_library,
64
+ 'disable_vcr_cable' => disabled_by_env?
65
+ })
66
+ else
67
+ {}
68
+ end
69
+ end
70
+
71
+ def select_default_mocking_library
72
+ if gem_available? 'fakeweb'
73
+ :fakeweb
74
+ elsif gem_available? 'webmock'
75
+ :webmock
76
+ else
77
+ raise InvalidMockingLibraryError.new(
78
+ "A valid mocking framework was not supplied - Add FakeWeb or WebMock to Gemfile"
79
+ )
80
+ end
81
+ end
82
+
83
+ # http://stackoverflow.com/questions/1032114/check-for-ruby-gem-availability#answer-7455576
84
+ def gem_available?(name)
85
+ Gem::Specification.find_by_name(name)
86
+ rescue Gem::LoadError
87
+ false
88
+ rescue
89
+ Gem.available?(name)
90
+ end
51
91
  end
@@ -1,3 +1,3 @@
1
1
  module VcrCable
2
- VERSION = '0.2.3'
2
+ VERSION = '0.3.0'
3
3
  end
@@ -1,9 +1,2 @@
1
1
  development:
2
- hook_into: fakeweb
3
- cassette_library_dir: development_cassettes
4
- allow_http_connections_when_no_cassette: true
5
-
6
- test:
7
- hook_into: fakeweb
8
2
  cassette_library_dir: custom_named_cassettes
9
- allow_http_connections_when_no_cassette: false
@@ -1106,3 +1106,49 @@ Connecting to database specified by database.yml
1106
1106
   (0.1ms) rollback transaction
1107
1107
   (0.1ms) begin transaction
1108
1108
   (0.1ms) rollback transaction
1109
+ Connecting to database specified by database.yml
1110
+  (0.5ms) begin transaction
1111
+  (0.1ms) rollback transaction
1112
+  (0.0ms) begin transaction
1113
+  (0.0ms) rollback transaction
1114
+  (0.0ms) begin transaction
1115
+  (0.0ms) rollback transaction
1116
+  (0.0ms) begin transaction
1117
+  (0.0ms) rollback transaction
1118
+  (0.0ms) begin transaction
1119
+  (0.0ms) rollback transaction
1120
+  (0.0ms) begin transaction
1121
+  (0.0ms) rollback transaction
1122
+  (0.0ms) begin transaction
1123
+  (0.0ms) rollback transaction
1124
+  (0.0ms) begin transaction
1125
+  (0.0ms) rollback transaction
1126
+  (0.0ms) begin transaction
1127
+  (0.0ms) rollback transaction
1128
+  (0.0ms) begin transaction
1129
+  (0.0ms) rollback transaction
1130
+  (0.0ms) begin transaction
1131
+  (0.0ms) rollback transaction
1132
+ Connecting to database specified by database.yml
1133
+  (0.3ms) begin transaction
1134
+  (0.1ms) rollback transaction
1135
+  (0.0ms) begin transaction
1136
+  (0.0ms) rollback transaction
1137
+  (0.0ms) begin transaction
1138
+  (0.0ms) rollback transaction
1139
+  (0.0ms) begin transaction
1140
+  (0.0ms) rollback transaction
1141
+  (0.0ms) begin transaction
1142
+  (0.0ms) rollback transaction
1143
+  (0.0ms) begin transaction
1144
+  (0.0ms) rollback transaction
1145
+  (0.0ms) begin transaction
1146
+  (0.0ms) rollback transaction
1147
+  (0.0ms) begin transaction
1148
+  (0.0ms) rollback transaction
1149
+  (0.0ms) begin transaction
1150
+  (0.0ms) rollback transaction
1151
+  (0.0ms) begin transaction
1152
+  (0.0ms) rollback transaction
1153
+  (0.0ms) begin transaction
1154
+  (0.0ms) rollback transaction
@@ -13,36 +13,49 @@ class VcrCableTest < ActiveSupport::TestCase
13
13
  assert !VcrCable.enabled?
14
14
  end
15
15
 
16
- test 'loads the default config when current env has configuration' do
17
- File.stubs(:file?).returns(false)
16
+ test 'is not enabled when config disables it' do
17
+ VcrCable.stubs(:config).returns({'disable_vcr_cable' => true})
18
+ assert !VcrCable.enabled?
19
+ end
20
+
21
+ test 'is not enabled when DISABLE_VCR_CABLE is present in ENV' do
22
+ ENV.stubs(:[]).with('DISABLE_VCR_CABLE').returns(true)
23
+ assert !VcrCable.enabled?
24
+ end
25
+
26
+ test 'loads FakeWeb or WebMock based on which is installed' do
18
27
  VcrCable.stubs(:env).returns('development')
19
- VcrCable.configure_vcr
20
- assert_match /development_cassettes$/, VCR.configuration.cassette_library_dir
28
+ assert_equal :fakeweb, VcrCable.config['hook_into']
29
+ end
30
+
31
+ test 'raises an error when no mocking library is available' do
32
+ VcrCable.stubs(:env).returns('development')
33
+ VcrCable.stubs(:gem_available?).returns(false)
34
+ assert_raises(VcrCable::InvalidMockingLibraryError) { VcrCable.config['hook_into'] }
21
35
  end
22
36
 
23
37
  test 'has no config when the current env has no configuration' do
24
- VcrCable.stubs(:env).returns('without_vcr_cable')
25
38
  assert !VcrCable.config.present?
26
39
  end
27
40
 
28
- test 'config in config/vcr_cable.yml overwrites default values' do
41
+ test 'loads config from config/vcr_cable.yml over default values' do
42
+ VcrCable.stubs(:env).returns('development')
29
43
  VcrCable.configure_vcr
30
44
  assert_match /custom_named_cassettes$/, VCR.configuration.cassette_library_dir
31
45
  end
32
46
 
33
- test 'global_config contains all env specific configs' do
34
- %w[test development].each do |env_name|
35
- VcrCable.global_config.keys.include?(env_name)
36
- end
47
+ test 'loads default values when not specified in config/vcr_cable.yml' do
48
+ VcrCable.stubs(:env).returns('development')
49
+ VcrCable.configure_vcr
50
+ assert VcrCable.config['allow_http_connections_when_no_cassette']
37
51
  end
38
52
 
39
53
  test 'adds VCR::Middleware::Rack to the middleware stack' do
40
- assert Rails.configuration.middleware.any? {|name| name == 'VCR::Middleware::Rack'}
54
+ list = Dir.chdir(Rails.root) {`bundle exec rake middleware RAILS_ENV=development`}
55
+ assert_match /VCR::Middleware::Rack/, list
41
56
  end
42
57
 
43
58
  test 'it does not add VCR::Middleware::Rack to environments that are not enabled' do
44
- list = Dir.chdir(Rails.root) {`bundle exec rake middleware RAILS_ENV=no_vcr`}
45
- assert_not_match /VCR::Middleware::Rack/, list
59
+ assert !Rails.configuration.middleware.any? {|name| name == 'VCR::Middleware::Rack'}
46
60
  end
47
-
48
61
  end
metadata CHANGED
@@ -1,110 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vcr_cable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
5
- prerelease:
4
+ version: 0.3.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - andrea longhi
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-08-29 00:00:00.000000000 Z
11
+ date: 2014-07-04 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rails
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: vcr
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: fakeweb
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: sqlite3
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - '>='
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - '>='
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: guard-test
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - '>='
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - '>='
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: mocha
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
- - - ! '>='
87
+ - - '>='
100
88
  - !ruby/object:Gem::Version
101
89
  version: '0'
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
- - - ! '>='
94
+ - - '>='
108
95
  - !ruby/object:Gem::Version
109
96
  version: '0'
110
97
  description: use VCR in development (or whatever Rails environment you want)
@@ -164,33 +151,26 @@ files:
164
151
  - test/vcr_cable_test.rb
165
152
  homepage: https://github.com/spaghetticode/vcr_cable
166
153
  licenses: []
154
+ metadata: {}
167
155
  post_install_message:
168
156
  rdoc_options: []
169
157
  require_paths:
170
158
  - lib
171
159
  required_ruby_version: !ruby/object:Gem::Requirement
172
- none: false
173
160
  requirements:
174
- - - ! '>='
161
+ - - '>='
175
162
  - !ruby/object:Gem::Version
176
163
  version: '0'
177
- segments:
178
- - 0
179
- hash: -2234079835404851201
180
164
  required_rubygems_version: !ruby/object:Gem::Requirement
181
- none: false
182
165
  requirements:
183
- - - ! '>='
166
+ - - '>='
184
167
  - !ruby/object:Gem::Version
185
168
  version: '0'
186
- segments:
187
- - 0
188
- hash: -2234079835404851201
189
169
  requirements: []
190
170
  rubyforge_project:
191
- rubygems_version: 1.8.24
171
+ rubygems_version: 2.1.11
192
172
  signing_key:
193
- specification_version: 3
173
+ specification_version: 4
194
174
  summary: use VCR in development
195
175
  test_files:
196
176
  - test/dummy/app/assets/javascripts/application.js