vcr 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. data/CHANGELOG.md +62 -0
  2. data/README.md +224 -0
  3. data/Rakefile +12 -5
  4. data/VERSION +1 -1
  5. data/benchmarks/http_stubbing_libraries.rb +59 -0
  6. data/features/fixtures/vcr_cassettes/1.8.6/cucumber_tags/replay_cassette1.yml +25 -25
  7. data/features/fixtures/vcr_cassettes/1.8.6/cucumber_tags/replay_cassette2.yml +32 -30
  8. data/features/fixtures/vcr_cassettes/1.8.6/cucumber_tags/replay_cassette3.yml +40 -40
  9. data/features/fixtures/vcr_cassettes/1.8.6/nested_replay_cassette.yml +16 -15
  10. data/features/fixtures/vcr_cassettes/1.8.6/not_the_real_response.yml +25 -25
  11. data/features/fixtures/vcr_cassettes/1.8.7/cucumber_tags/replay_cassette1.yml +23 -23
  12. data/features/fixtures/vcr_cassettes/1.8.7/cucumber_tags/replay_cassette2.yml +24 -22
  13. data/features/fixtures/vcr_cassettes/1.8.7/cucumber_tags/replay_cassette3.yml +36 -36
  14. data/features/fixtures/vcr_cassettes/1.8.7/nested_replay_cassette.yml +12 -11
  15. data/features/fixtures/vcr_cassettes/1.8.7/not_the_real_response.yml +23 -23
  16. data/features/fixtures/vcr_cassettes/1.9.1/cucumber_tags/replay_cassette1.yml +24 -24
  17. data/features/fixtures/vcr_cassettes/1.9.1/cucumber_tags/replay_cassette2.yml +26 -24
  18. data/features/fixtures/vcr_cassettes/1.9.1/cucumber_tags/replay_cassette3.yml +38 -38
  19. data/features/fixtures/vcr_cassettes/1.9.1/nested_replay_cassette.yml +13 -12
  20. data/features/fixtures/vcr_cassettes/1.9.1/not_the_real_response.yml +24 -24
  21. data/features/record_response.feature +2 -2
  22. data/features/replay_recorded_response.feature +1 -1
  23. data/features/step_definitions/vcr_steps.rb +8 -8
  24. data/features/support/env.rb +6 -0
  25. data/lib/vcr.rb +16 -3
  26. data/lib/vcr/cassette.rb +49 -46
  27. data/lib/vcr/config.rb +8 -0
  28. data/lib/vcr/extensions/fake_web.rb +12 -26
  29. data/lib/vcr/extensions/net_http.rb +9 -26
  30. data/lib/vcr/http_stubbing_adapters/base.rb +34 -0
  31. data/lib/vcr/http_stubbing_adapters/fakeweb.rb +75 -0
  32. data/lib/vcr/http_stubbing_adapters/webmock.rb +80 -0
  33. data/lib/vcr/structs.rb +44 -0
  34. data/lib/vcr/task_runner.rb +47 -0
  35. data/lib/vcr/tasks/vcr.rake +9 -0
  36. data/spec/cassette_spec.rb +70 -71
  37. data/spec/config_spec.rb +27 -0
  38. data/spec/extensions/net_http_spec.rb +21 -17
  39. data/spec/fixtures/1.8.6/0_3_1_cassette.yml +29 -0
  40. data/spec/fixtures/1.8.6/cassette_spec/example.yml +110 -108
  41. data/spec/fixtures/1.8.6/example_net_http.yml +14 -0
  42. data/spec/fixtures/1.8.6/example_net_http_request.yml +12 -0
  43. data/spec/fixtures/1.8.6/example_net_http_response.yml +25 -0
  44. data/spec/fixtures/1.8.6/fake_example.com_responses.yml +90 -0
  45. data/spec/fixtures/1.8.7/0_3_1_cassette.yml +29 -0
  46. data/spec/fixtures/1.8.7/cassette_spec/example.yml +110 -108
  47. data/spec/fixtures/1.8.7/example_net_http.yml +14 -0
  48. data/spec/fixtures/1.8.7/example_net_http_request.yml +12 -0
  49. data/spec/fixtures/1.8.7/example_net_http_response.yml +25 -0
  50. data/spec/fixtures/1.8.7/fake_example.com_responses.yml +90 -0
  51. data/spec/fixtures/1.9.1/0_3_1_cassette.yml +29 -0
  52. data/spec/fixtures/1.9.1/cassette_spec/example.yml +62 -59
  53. data/spec/fixtures/1.9.1/example_net_http.yml +14 -0
  54. data/spec/fixtures/1.9.1/example_net_http_request.yml +12 -0
  55. data/spec/fixtures/1.9.1/example_net_http_response.yml +25 -0
  56. data/spec/fixtures/1.9.1/fake_example.com_responses.yml +90 -0
  57. data/spec/http_stubbing_adapters/fakeweb_spec.rb +24 -0
  58. data/spec/http_stubbing_adapters/webmock_spec.rb +23 -0
  59. data/spec/spec_helper.rb +5 -0
  60. data/spec/structs_spec.rb +95 -0
  61. data/spec/support/http_stubbing_adapter.rb +113 -0
  62. data/spec/task_runner_spec.rb +59 -0
  63. data/spec/vcr_spec.rb +37 -0
  64. data/vcr.gemspec +45 -15
  65. metadata +67 -26
  66. data/History.rdoc +0 -31
  67. data/README.rdoc +0 -222
  68. data/lib/vcr/recorded_response.rb +0 -4
  69. data/spec/extensions/fake_web_spec.rb +0 -63
  70. data/spec/recorded_response_spec.rb +0 -25
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 3
8
- - 1
9
- version: 0.3.1
7
+ - 4
8
+ - 0
9
+ version: 0.4.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Myron Marston
@@ -14,11 +14,11 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-10 00:00:00 -07:00
17
+ date: 2010-04-28 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: fakeweb
21
+ name: rspec
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
24
  requirements:
@@ -27,39 +27,53 @@ dependencies:
27
27
  segments:
28
28
  - 1
29
29
  - 2
30
- - 8
31
- version: 1.2.8
32
- type: :runtime
30
+ - 9
31
+ version: 1.2.9
32
+ type: :development
33
33
  version_requirements: *id001
34
34
  - !ruby/object:Gem::Dependency
35
- name: rspec
35
+ name: cucumber
36
36
  prerelease: false
37
37
  requirement: &id002 !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  segments:
42
+ - 0
43
+ - 6
42
44
  - 1
43
- - 2
44
- - 9
45
- version: 1.2.9
45
+ version: 0.6.1
46
46
  type: :development
47
47
  version_requirements: *id002
48
48
  - !ruby/object:Gem::Dependency
49
- name: cucumber
49
+ name: fakeweb
50
50
  prerelease: false
51
51
  requirement: &id003 !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - ">="
54
54
  - !ruby/object:Gem::Version
55
55
  segments:
56
- - 0
57
- - 6
58
56
  - 1
59
- version: 0.6.1
57
+ - 2
58
+ - 8
59
+ version: 1.2.8
60
60
  type: :development
61
61
  version_requirements: *id003
62
- description: VCR provides helpers to record HTTP requests for URIs that are not registered with fakeweb, and replay them later. It works with any ruby testing framework, and provides built-in support for cucumber.
62
+ - !ruby/object:Gem::Dependency
63
+ name: webmock
64
+ prerelease: false
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ segments:
70
+ - 1
71
+ - 1
72
+ - 0
73
+ version: 1.1.0
74
+ type: :development
75
+ version_requirements: *id004
76
+ description: VCR provides helpers to record your test suite's HTTP interactions and replay them during future test runs for fast, deterministic, accurate tests. It works with any ruby testing framework, and provides built-in support for cucumber.
63
77
  email: myron.marston@gmail.com
64
78
  executables: []
65
79
 
@@ -67,15 +81,16 @@ extensions: []
67
81
 
68
82
  extra_rdoc_files:
69
83
  - LICENSE
70
- - README.rdoc
84
+ - README.md
71
85
  files:
72
86
  - .document
73
87
  - .gitignore
74
- - History.rdoc
88
+ - CHANGELOG.md
75
89
  - LICENSE
76
- - README.rdoc
90
+ - README.md
77
91
  - Rakefile
78
92
  - VERSION
93
+ - benchmarks/http_stubbing_libraries.rb
79
94
  - features/fixtures/vcr_cassettes/1.8.6/cucumber_tags/replay_cassette1.yml
80
95
  - features/fixtures/vcr_cassettes/1.8.6/cucumber_tags/replay_cassette2.yml
81
96
  - features/fixtures/vcr_cassettes/1.8.6/cucumber_tags/replay_cassette3.yml
@@ -103,23 +118,46 @@ files:
103
118
  - lib/vcr/extensions/fake_web.rb
104
119
  - lib/vcr/extensions/net_http.rb
105
120
  - lib/vcr/extensions/net_read_adapter.rb
106
- - lib/vcr/recorded_response.rb
121
+ - lib/vcr/http_stubbing_adapters/base.rb
122
+ - lib/vcr/http_stubbing_adapters/fakeweb.rb
123
+ - lib/vcr/http_stubbing_adapters/webmock.rb
124
+ - lib/vcr/structs.rb
125
+ - lib/vcr/task_runner.rb
126
+ - lib/vcr/tasks/vcr.rake
107
127
  - spec/cassette_spec.rb
108
128
  - spec/config_spec.rb
109
129
  - spec/cucumber_tags_spec.rb
110
130
  - spec/deprecations_spec.rb
111
- - spec/extensions/fake_web_spec.rb
112
131
  - spec/extensions/net_http_spec.rb
113
132
  - spec/extensions/net_read_adapter_spec.rb
133
+ - spec/fixtures/1.8.6/0_3_1_cassette.yml
114
134
  - spec/fixtures/1.8.6/cassette_spec/example.yml
135
+ - spec/fixtures/1.8.6/example_net_http.yml
136
+ - spec/fixtures/1.8.6/example_net_http_request.yml
137
+ - spec/fixtures/1.8.6/example_net_http_response.yml
138
+ - spec/fixtures/1.8.6/fake_example.com_responses.yml
139
+ - spec/fixtures/1.8.7/0_3_1_cassette.yml
115
140
  - spec/fixtures/1.8.7/cassette_spec/example.yml
141
+ - spec/fixtures/1.8.7/example_net_http.yml
142
+ - spec/fixtures/1.8.7/example_net_http_request.yml
143
+ - spec/fixtures/1.8.7/example_net_http_response.yml
144
+ - spec/fixtures/1.8.7/fake_example.com_responses.yml
145
+ - spec/fixtures/1.9.1/0_3_1_cassette.yml
116
146
  - spec/fixtures/1.9.1/cassette_spec/example.yml
117
- - spec/recorded_response_spec.rb
147
+ - spec/fixtures/1.9.1/example_net_http.yml
148
+ - spec/fixtures/1.9.1/example_net_http_request.yml
149
+ - spec/fixtures/1.9.1/example_net_http_response.yml
150
+ - spec/fixtures/1.9.1/fake_example.com_responses.yml
151
+ - spec/http_stubbing_adapters/fakeweb_spec.rb
152
+ - spec/http_stubbing_adapters/webmock_spec.rb
118
153
  - spec/spec.opts
119
154
  - spec/spec_helper.rb
155
+ - spec/structs_spec.rb
120
156
  - spec/support/deprecated.rb
121
157
  - spec/support/disable_warnings.rb
158
+ - spec/support/http_stubbing_adapter.rb
122
159
  - spec/support/temp_cassette_library_dir.rb
160
+ - spec/task_runner_spec.rb
123
161
  - spec/vcr_spec.rb
124
162
  - vcr.gemspec
125
163
  has_rdoc: true
@@ -151,18 +189,21 @@ rubyforge_project:
151
189
  rubygems_version: 1.3.6
152
190
  signing_key:
153
191
  specification_version: 3
154
- summary: Use VCR to record HTTP responses and replay them using fakeweb.
192
+ summary: Record your test suite's HTTP interactions and replay them during future test runs for fast, deterministic, accurate tests.
155
193
  test_files:
156
194
  - spec/cassette_spec.rb
157
195
  - spec/config_spec.rb
158
196
  - spec/cucumber_tags_spec.rb
159
197
  - spec/deprecations_spec.rb
160
- - spec/extensions/fake_web_spec.rb
161
198
  - spec/extensions/net_http_spec.rb
162
199
  - spec/extensions/net_read_adapter_spec.rb
163
- - spec/recorded_response_spec.rb
200
+ - spec/http_stubbing_adapters/fakeweb_spec.rb
201
+ - spec/http_stubbing_adapters/webmock_spec.rb
164
202
  - spec/spec_helper.rb
203
+ - spec/structs_spec.rb
165
204
  - spec/support/deprecated.rb
166
205
  - spec/support/disable_warnings.rb
206
+ - spec/support/http_stubbing_adapter.rb
167
207
  - spec/support/temp_cassette_library_dir.rb
208
+ - spec/task_runner_spec.rb
168
209
  - spec/vcr_spec.rb
@@ -1,31 +0,0 @@
1
- == 0.3.1 April 10, 2010
2
- * Fixed a bug: when Net::HTTP#request was called with a block that had a return statement, the response was not being recorded.
3
-
4
- == 0.3.0 March 24, 2010
5
- * Renamed a bunch of methods, replacing them with method names that more clearly fit the VCR/cassette metaphor:
6
- * VCR.create_cassette! => VCR.insert_cassette
7
- * VCR.destroy_cassette! => VCR.eject_cassette
8
- * VCR.with_cassette => VCR.use_cassette
9
- * VCR::Cassette#destroy! => VCR::Cassette#eject
10
- * VCR::Cassette#cache_file => VCR::Cassette#file
11
- * VCR::Config.cache_dir => VCR::Config.cassette_library_dir
12
- * :unregistered record mode => :new_episodes record mode
13
- * All the old methods still work, but you'll get deprecation warnings.
14
-
15
- == 0.2.0 March 9, 2010
16
- * Added <tt>:allow_real_http</tt> cassette option, which allows VCR to work with capybara and a javascript driver.
17
- Bug reported by {Ben Hutton}[http://github.com/benhutton].
18
- * Deprecated the default_cassette_record_mode option. Use default_cassette_options instead.
19
-
20
- == 0.1.2 March 4, 2010
21
- * Added explanatory note about VCR to FakeWeb::NetConnectNotAllowedError#message.
22
- * Got things to work for when a cassette records multiple requests made to the same URL with the same HTTP verb,
23
- but different responses. We have to register an array of responses with fakeweb.
24
- * Fixed our Net::HTTP monkey patch so that it only stores a the recorded response once per request.
25
- Internally, Net::HTTP#request recursively calls itself (passing slightly different arguments) in certain circumstances.
26
-
27
- == 0.1.1 February 25, 2010
28
- * Handle asynchronous HTTP requests (such as for mechanize). Bug reported by {Thibaud Guillaume-Gentil}[http://github.com/thibaudgg].
29
-
30
- == 0.1.0 February 25, 2010
31
- * Initial release. Basic recording and replaying of responses works.
@@ -1,222 +0,0 @@
1
- = VCR
2
-
3
- VCR provides helpers to record HTTP requests for URIs that are not registered with fakeweb, and replay them later.
4
- It works with any ruby testing framework and provides built-in support for cucumber.
5
-
6
- == Installation
7
-
8
- gem install vcr
9
-
10
- == Background
11
-
12
- This README assumes you are familiar with FakeWeb; if not, please checkout the {README}[http://github.com/chrisk/fakeweb/blob/master/README.rdoc].
13
-
14
- VCR was inspired by {NetRecorder}[http://github.com/chrisyoung/netrecorder], but was designed from the ground up to support
15
- localized recording and replaying, rather than the global recording and replaying of NetRecorder. In general, I believe that
16
- tests should not rely upon anything global. You're coupling your test to something outside of it that may later change and
17
- break the test. It's far better to localize things to each test, as much as possible. VCR, in combination with FakeWeb,
18
- makes it easy to do this with the recording and replaying of HTTP responses.
19
-
20
- == Cassettes
21
-
22
- Cassettes are central to the way VCR works. They are a similar to VHS cassettes--your library of cassettes
23
- is your library of previously recorded responses that can be replayed. When you insert a cassette, it does
24
- the following:
25
-
26
- * It loads the previously recorded responses from the library file corresponding to the cassette name.
27
- * It register these responses with fakeweb (depending on the cassette's :record option--see below)
28
- * It sets the <tt>FakeWeb.allow_net_connect</tt> setting based on the cassette's :record option.
29
-
30
- While a cassette is active, any HTTP requests to a URL of a previously recorded response will use
31
- the recorded response. New HTTP requests (i.e. HTTP requests that have not been previously recorded)
32
- will be recorded to the same library file, depending on your :record option. When you eject a cassette,
33
- it does the following:
34
-
35
- * It saves all of the recorded responses (both old and new) to a yml library file corresponding to the cassette name.
36
- * It removes the registrations it made with fakeweb, to prevent "leakage" into other tests.
37
- * It reverts the <tt>FakeWeb.allow_net_connect</tt> back to whatever it was before the cassette was inserted.
38
-
39
- == Record modes
40
-
41
- VCR supports 3 record modes, which configure when it records new responses. You can set a default
42
- record mode in your configuration (see below) and a per-cassette record mode when creating a cassette. The record
43
- modes are:
44
-
45
- * <tt>:new_episodes</tt> - This will use the previously recorded responses, and record any new requests that are not registered with
46
- fakeweb. The previously recorded responses will be registered with fakeweb. <tt>FakeWeb.allow_net_connect</tt> will be
47
- set to true, so that VCR will record any new HTTP requests within the cassette. Use this when it's ok for external HTTP
48
- requests to be made without you explicitly allowing it. New requests will get saved to the cassette's yml library file, and
49
- automatically get used in the future.
50
- * <tt>:all</tt> - This will cause VCR to re-record all HTTP requests that occur.
51
- When the cassette is created, it will not register any of the cached responses with fakeweb.
52
- <tt>FakeWeb.allow_net_connect</tt> will be set to true, so it can record the requests. Use this
53
- when you want to re-record all of the HTTP requests for a cassette. Alternately, you can simply
54
- delete the corresponding library file and use the :new_episodes record mode, described above.
55
- * <tt>:none</tt> - This will prevent VCR from recording, or even allowing, any new HTTP requests.
56
- The previously recorded responses will be registered with fakeweb. <tt>FakeWeb.allow_net_connect</tt> will be set to
57
- false, so that no new HTTP connections are allowed. Use this when you want to guarantee that no external
58
- HTTP requests will be made while the given cassette is active. Fakeweb will raise an error in this case.
59
-
60
- == Configuration
61
-
62
- require 'vcr'
63
-
64
- # Set the default allow_net_connect option--usually you'll want this off.
65
- # You don't usually want your test suite to make HTTP connections, do you?
66
- FakeWeb.allow_net_connect = false
67
-
68
- VCR.config do |c|
69
- # the cassette_library_dir is where the cassette yml files will be saved.
70
- c.cassette_library_dir = File.join(Rails.root, 'features', 'fixtures', 'cassette_library')
71
-
72
- # these options will be used as defaults for your cassettes, but you can override them in each individual cassette.
73
- c.default_cassette_options = {
74
- :record => :none,
75
- :allow_real_http => :localhost
76
- }
77
- end
78
-
79
- This can go pretty much wherever, as long as this code is run before your tests, specs or scenarios. I tend
80
- to put it in spec/support/vcr.rb, test/support/vcr.rb or features/support/vcr.rb.
81
-
82
- == Usage with your favorite test/spec framework
83
-
84
- VCR can easily be used with any ruby test or spec framework. Usually, you'll want to use <tt>VCR.use_cassette</tt>:
85
-
86
- VCR.use_cassette('geocoding/Seattle, WA', :record => :new_episodes) do
87
- # do something that causes an HTTP request.
88
- end
89
-
90
- Alternately, you can insert and eject the cassette with individual method calls from setup/before and teardown/after:
91
-
92
- describe "Something that makes an HTTP request" do
93
- before(:each) do
94
- VCR.insert_cassette('geocoding/Seattle, WA', :record => :new_episodes)
95
- end
96
-
97
- it "should do something that makes an HTTP request"
98
-
99
- after(:each) do
100
- VCR.eject_cassette
101
- end
102
- end
103
-
104
- In both of these cases, VCR would use the file geocoding/Seattle_WA.yml within the configured
105
- cassette library dir. The :record setting is optional--if you leave it blank, your configured default will be used.
106
-
107
- Besides the :record option, cassettes also support the :allow_real_http option. You can use this to make the cassette
108
- allow some real HTTP requests. You can specify it with a lambda:
109
-
110
- VCR.use_cassette('my cassette', :allow_real_http => lambda { |uri| uri.host == 'google.com' }) do
111
- # do something that causes an HTTP request.
112
- end
113
-
114
- In this case, any google HTTP requests will be made for real, regardless of your <tt>FakeWeb.allow_net_connect</tt> setting,
115
- your current record mode, and whether or not you are recording or replaying this cassette. Non-google requests will do
116
- the appropriate recording/replaying as usual. You can also use the special <tt>:localhost</tt> option:
117
-
118
- VCR.use_cassette('my cassette', :allow_real_http => :localhost) do
119
- # do something that causes an HTTP request.
120
- end
121
-
122
- This is equivalent to using a lambda like:
123
-
124
- lambda { |uri| uri.host == 'localhost' }
125
-
126
- This is needed for using VCR with {capybara}[http://github.com/jnicklas/capybara] and any of the javascript drivers (see below for more info).
127
-
128
- == Usage with Cucumber
129
-
130
- VCR provides special support for cucumber. You can of course use <tt>VCR.use_cassette</tt> within a step definition,
131
- and that's the recommended way for any of your step definitions. But many times I find myself using generic step definitions
132
- provided by another library (such as the webrat/capybara web steps generated by cucumber-rails), and I don't want to modify
133
- these. VCR provides cucumber tagging support to help in these cases.
134
-
135
- First, tag your scenario with something descriptive:
136
-
137
- @facebook_http_request
138
- Scenario: Sign up with facebook connect
139
-
140
- Then let VCR know about this tag, in features/support/vcr.rb (or some similar support file):
141
-
142
- VCR.cucumber_tags do |t|
143
- t.tags '@facebook_http_request', '@twitter_status_update', :record => :none
144
- t.tags '@another_scenario_tag' # the default record mode will be used for this tag.
145
- end
146
-
147
- For each of the tags you specify in your cucumber_tags block, VCR will set up the appropriate
148
- {Before and After hooks}[http://wiki.github.com/aslakhellesoy/cucumber/hooks] to use a cassette
149
- for the entire scenario. The tag (minus the '@') will be used as the cassette name, and it'll
150
- go in the cucumber_tags subdirectory of the configured cassette library dir.
151
-
152
- == Usage with Capybara
153
-
154
- When you use any of the javascript-enabled drivers (selenium, celerity, culerity) with {capybara}[http://github.com/jnicklas/capybara],
155
- it'll need to ping the app running on localhost. You can use the <tt>:allow_real_http => :localhost</tt> option to allow this.
156
-
157
- == Suggested Workflow
158
-
159
- First, configure VCR and FakeWeb as I have above. I like setting <tt>FakeWeb.allow_net_connect</tt> to <tt>false</tt>
160
- and the default record mode to <tt>:none</tt> so that no new HTTP requests are made without me explicitly allowing it.
161
-
162
- When an HTTP request is made, you'll get an {error from FakeWeb}[http://github.com/chrisk/fakeweb/blob/fakeweb-1.2.8/lib/fake_web/ext/net_http.rb#L62-63],
163
- such as:
164
-
165
- FakeWeb::NetConnectNotAllowedError: Real HTTP connections are disabled. Unregistered request: get http://example.com
166
-
167
- Find the place that is making the HTTP request (the backtrace should help here). If you've already recorded this HTTP
168
- request to a cassette from a different test, you can simply re-use the cassette. Use <tt>VCR.use_cassette</tt>, as
169
- shown above. You may also want to refactor this into a helper method that sets up the VCR cassette and does whatever
170
- makes the HTTP request:
171
-
172
- def set_user_address(user, address, city, state)
173
- VCR.use_cassette("geocoding/#{address}, #{city}, #{state}", :record => :new_episodes) do
174
- user.address.update_attributes!(:address => address, :city => city, :state => state)
175
- end
176
- end
177
-
178
- In this case, I've used a dynamic cassette name based on the address being geocoded. That way, each separate address
179
- gets a different cassette, and tests that set the same user address will reuse the same cassette. I've also set
180
- the record mode to <tt>:new_episodes</tt> so that VCR will automatically record geocoding requests for a new address
181
- to a new cassette, without me having to do anything.
182
-
183
- If the HTTP request that triggered the error is new, you'll have to record it for the first time. Simply use <tt>VCR.use_cassette</tt>
184
- with the record mode set to <tt>:new_episodes</tt> or <tt>:all</tt>. Run the test again, and VCR will record the HTTP response. I usually
185
- remove the record mode at this point so that it uses the default of <tt>:none</tt> in the future. Future test runs will use the
186
- recorded response, and if your code changes so that it is making a new HTTP request, you'll get the same FakeWeb error as shown above.
187
-
188
- == Ruby Version Compatibility
189
-
190
- VCR works on ruby {1.8.6}[http://integrity186.heroku.com/vcr], {1.8.7}[http://integrity187.heroku.com/vcr] and {1.9.1}[http://integrity191.heroku.com/vcr].
191
-
192
- == Notes, etc.
193
-
194
- * The cassette name determines the name of the library file for the given cassette. Strings or symbols are fine,
195
- and you can include any characters, but spaces and invalid file name characters will be removed
196
- before the cassette reads or writes to its library file.
197
- * You can use a directory separator (i.e. '/') in your cassette names to cause it to use a subdirectory
198
- of the cassette_library_dir. The cucumber tagging support uses this.
199
- * VCR maintains a simple stack of cassettes. This allows you to nest them as deeply as you want.
200
- This is particularly useful when you have a cucumber step definition that uses a cassette, and
201
- you also want to use a cassette for the entire scenario using the tagging support.
202
-
203
- == Note on Patches/Pull Requests
204
-
205
- * Fork the project.
206
- * Make your feature addition or bug fix.
207
- * Add tests for it. This is important so I don't break it in a
208
- future version unintentionally.
209
- * Commit, do not mess with rakefile, version, or history.
210
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
211
- * Send me a pull request. Bonus points for topic branches.
212
-
213
- == Thanks
214
-
215
- * {Aslak Hellesøy}[http://github.com/aslakhellesoy] for {Cucumber}[http://github.com/aslakhellesoy/cucumber].
216
- * {Chris Kampmeier}[http://github.com/chrisk] for {FakeWeb}[http://github.com/chrisk/fakeweb].
217
- * {Chris Young}[http://github.com/chrisyoung] for {NetRecorder}[http://github.com/chrisyoung/netrecorder], the inspiration
218
- for VCR.
219
-
220
- == Copyright
221
-
222
- Copyright (c) 2010 Myron Marston. See LICENSE for details.
@@ -1,4 +0,0 @@
1
- module VCR
2
- class RecordedResponse < Struct.new(:method, :uri, :response)
3
- end
4
- end
@@ -1,63 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- describe "FakeWeb Extensions" do
4
- describe "#remove_from_registry with (:get, 'http://example.com')" do
5
- before(:each) do
6
- FakeWeb.register_uri(:get, 'http://example.com', :body => "Example dot com!")
7
- FakeWeb.register_uri(:post, 'http://example.com', :body => "Example dot com!")
8
- FakeWeb.register_uri(:get, 'http://google.com', :body => "Google dot com!")
9
- @remove_example_dot_com = lambda { FakeWeb.remove_from_registry(:get, 'http://example.com') }
10
- end
11
-
12
- it "removes the :get http://example.com registration" do
13
- @remove_example_dot_com.should change { FakeWeb.registered_uri?(:get, 'http://example.com') }.from(true).to(false)
14
- end
15
-
16
- it "does not remove the :post http://example.com registration" do
17
- FakeWeb.registered_uri?(:post, 'http://example.com').should be_true
18
- @remove_example_dot_com.should_not change { FakeWeb.registered_uri?(:post, 'http://example.com') }
19
- end
20
-
21
- it "does not affect other registered uris" do
22
- FakeWeb.registered_uri?(:get, 'http://google.com').should be_true
23
- @remove_example_dot_com.should_not change { FakeWeb.registered_uri?(:get, 'http://google.com') }
24
- end
25
- end
26
-
27
- describe 'FakeWeb::NetConnectNotAllowedError#message' do
28
- it 'includes a note about VCR' do
29
- FakeWeb::NetConnectNotAllowedError.new('The fakeweb error message').message.should ==
30
- 'The fakeweb error message. You can use VCR to automatically record this request and replay it later with fakeweb. For more details, see the VCR README at: http://github.com/myronmarston/vcr'
31
- end
32
- end
33
-
34
- describe "#with_allow_net_connect_set_to" do
35
- it 'sets allow_net_connect for the duration of the block to the provided value' do
36
- [true, false].each do |expected|
37
- yielded_value = :not_set
38
- FakeWeb.with_allow_net_connect_set_to(expected) { yielded_value = FakeWeb.allow_net_connect? }
39
- yielded_value.should == expected
40
- end
41
- end
42
-
43
- it 'returns the value returned by the block' do
44
- FakeWeb.with_allow_net_connect_set_to(true) { :return_value }.should == :return_value
45
- end
46
-
47
- it 'reverts allow_net_connect when the block completes' do
48
- [true, false].each do |expected|
49
- FakeWeb.allow_net_connect = expected
50
- FakeWeb.with_allow_net_connect_set_to(true) { }
51
- FakeWeb.allow_net_connect?.should == expected
52
- end
53
- end
54
-
55
- it 'reverts allow_net_connect when the block completes, even if an error is raised' do
56
- [true, false].each do |expected|
57
- FakeWeb.allow_net_connect = expected
58
- lambda { FakeWeb.with_allow_net_connect_set_to(true) { raise RuntimeError } }.should raise_error(RuntimeError)
59
- FakeWeb.allow_net_connect?.should == expected
60
- end
61
- end
62
- end
63
- end