vcr 1.11.3 → 2.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. data/.gitignore +2 -0
  2. data/.travis.yml +6 -2
  3. data/CHANGELOG.md +49 -1
  4. data/Gemfile +1 -5
  5. data/Guardfile +0 -5
  6. data/README.md +3 -2
  7. data/Rakefile +11 -16
  8. data/cucumber.yml +0 -4
  9. data/features/.nav +14 -2
  10. data/features/cassettes/automatic_re_recording.feature +4 -6
  11. data/features/cassettes/dynamic_erb.feature +6 -8
  12. data/features/cassettes/exclusive.feature +111 -0
  13. data/features/cassettes/format.feature +16 -14
  14. data/features/cassettes/naming.feature +4 -6
  15. data/features/cassettes/no_cassette.feature +25 -28
  16. data/features/cassettes/update_content_length_header.feature +9 -9
  17. data/features/configuration/allow_http_connections_when_no_cassette.feature +6 -8
  18. data/features/configuration/cassette_library_dir.feature +4 -6
  19. data/features/configuration/default_cassette_options.feature +12 -10
  20. data/features/configuration/filter_sensitive_data.feature +12 -17
  21. data/features/configuration/{stub_with.feature → hook_into.feature} +63 -62
  22. data/features/configuration/hooks.feature +23 -33
  23. data/features/configuration/ignore_hosts.feature +16 -17
  24. data/features/configuration/ignore_localhost.feature +33 -42
  25. data/features/http_libraries/em_http_request.feature +7 -8
  26. data/features/http_libraries/net_http.feature +26 -28
  27. data/features/middleware/faraday.feature +17 -56
  28. data/features/middleware/rack.feature +8 -11
  29. data/features/record_modes/all.feature +5 -7
  30. data/features/record_modes/new_episodes.feature +5 -7
  31. data/features/record_modes/none.feature +6 -6
  32. data/features/record_modes/once.feature +6 -8
  33. data/features/request_matching/README.md +28 -0
  34. data/features/request_matching/body.feature +81 -0
  35. data/features/request_matching/custom_matcher.feature +125 -0
  36. data/features/request_matching/headers.feature +85 -0
  37. data/features/request_matching/host.feature +85 -0
  38. data/features/request_matching/identical_request_sequence.feature +79 -0
  39. data/features/request_matching/method.feature +86 -0
  40. data/features/request_matching/path.feature +86 -0
  41. data/features/request_matching/playback_repeats.feature +87 -0
  42. data/features/request_matching/uri.feature +84 -0
  43. data/features/request_matching/uri_without_param.feature +85 -0
  44. data/features/step_definitions/cli_steps.rb +4 -28
  45. data/features/support/env.rb +11 -9
  46. data/features/support/http_lib_filters.rb +2 -11
  47. data/features/support/vcr_cucumber_helpers.rb +4 -5
  48. data/features/test_frameworks/cucumber.feature +17 -18
  49. data/features/test_frameworks/rspec.feature +8 -12
  50. data/features/test_frameworks/shoulda.feature +5 -8
  51. data/features/test_frameworks/test_unit.feature +5 -8
  52. data/lib/vcr.rb +38 -58
  53. data/lib/vcr/cassette.rb +41 -60
  54. data/lib/vcr/cassette/http_interaction_list.rb +56 -0
  55. data/lib/vcr/cassette/reader.rb +29 -31
  56. data/lib/vcr/configuration.rb +76 -0
  57. data/lib/vcr/deprecations.rb +39 -0
  58. data/lib/vcr/errors.rb +22 -0
  59. data/lib/vcr/library_hooks.rb +19 -0
  60. data/lib/vcr/library_hooks/excon.rb +136 -0
  61. data/lib/vcr/library_hooks/fakeweb.rb +110 -0
  62. data/lib/vcr/library_hooks/faraday.rb +3 -0
  63. data/lib/vcr/library_hooks/typhoeus.rb +98 -0
  64. data/lib/vcr/library_hooks/webmock.rb +100 -0
  65. data/lib/vcr/middleware/faraday.rb +43 -36
  66. data/lib/vcr/middleware/rack.rb +28 -4
  67. data/lib/vcr/request_handler.rb +43 -0
  68. data/lib/vcr/request_ignorer.rb +31 -0
  69. data/lib/vcr/request_matcher_registry.rb +86 -0
  70. data/lib/vcr/structs/http_interaction.rb +24 -18
  71. data/lib/vcr/structs/normalizers/body.rb +1 -1
  72. data/lib/vcr/structs/normalizers/header.rb +1 -1
  73. data/lib/vcr/structs/normalizers/status_message.rb +1 -1
  74. data/lib/vcr/structs/normalizers/uri.rb +1 -1
  75. data/lib/vcr/structs/request.rb +0 -13
  76. data/lib/vcr/structs/response.rb +2 -9
  77. data/lib/vcr/structs/response_status.rb +0 -4
  78. data/lib/vcr/test_frameworks/cucumber.rb +1 -1
  79. data/lib/vcr/test_frameworks/rspec.rb +1 -1
  80. data/lib/vcr/util/hooks.rb +28 -19
  81. data/lib/vcr/util/internet_connection.rb +29 -2
  82. data/lib/vcr/util/version_checker.rb +60 -0
  83. data/lib/vcr/version.rb +1 -1
  84. data/script/FullBuildRakeFile +0 -7
  85. data/script/full_build +1 -1
  86. data/spec/capture_warnings.rb +36 -31
  87. data/spec/fixtures/{1.9.1/cassette_spec → cassette_spec}/empty.yml +0 -0
  88. data/spec/fixtures/{not_1.9.1/cassette_spec → cassette_spec}/example.yml +0 -0
  89. data/spec/fixtures/{not_1.9.1/cassette_spec → cassette_spec}/with_localhost_requests.yml +0 -0
  90. data/spec/fixtures/{not_1.9.1/fake_example.com_responses.yml → fake_example.com_responses.yml} +0 -0
  91. data/spec/fixtures/{not_1.9.1/match_requests_on.yml → match_requests_on.yml} +0 -0
  92. data/spec/monkey_patches.rb +40 -11
  93. data/spec/spec_helper.rb +7 -43
  94. data/spec/support/http_library_adapters.rb +3 -13
  95. data/spec/support/shared_example_groups/{http_library.rb → hook_into_http_library.rb} +39 -111
  96. data/spec/support/shared_example_groups/version_checking.rb +9 -9
  97. data/spec/vcr/cassette/http_interaction_list_spec.rb +178 -0
  98. data/spec/vcr/cassette/reader_spec.rb +2 -2
  99. data/spec/vcr/cassette_spec.rb +121 -156
  100. data/spec/vcr/configuration_spec.rb +143 -0
  101. data/spec/vcr/deprecations_spec.rb +91 -0
  102. data/spec/vcr/{http_stubbing_adapters → library_hooks}/excon_spec.rb +6 -9
  103. data/spec/vcr/library_hooks/fakeweb_spec.rb +83 -0
  104. data/spec/vcr/{http_stubbing_adapters → library_hooks}/typhoeus_spec.rb +7 -11
  105. data/spec/vcr/library_hooks/webmock_spec.rb +17 -0
  106. data/spec/vcr/library_hooks_spec.rb +51 -0
  107. data/spec/vcr/middleware/faraday_spec.rb +17 -44
  108. data/spec/vcr/middleware/rack_spec.rb +94 -58
  109. data/spec/vcr/request_ignorer_spec.rb +54 -0
  110. data/spec/vcr/request_matcher_registry_spec.rb +223 -0
  111. data/spec/vcr/structs/request_spec.rb +0 -33
  112. data/spec/vcr/structs/response_spec.rb +0 -24
  113. data/spec/vcr/structs/response_status_spec.rb +0 -9
  114. data/spec/vcr/util/hooks_spec.rb +3 -5
  115. data/spec/vcr/version_spec.rb +1 -1
  116. data/spec/vcr_spec.rb +79 -91
  117. data/vcr.gemspec +1 -1
  118. metadata +83 -103
  119. data/features/cassettes/request_matching.feature +0 -383
  120. data/lib/vcr/config.rb +0 -84
  121. data/lib/vcr/deprecations/cassette.rb +0 -29
  122. data/lib/vcr/deprecations/config.rb +0 -18
  123. data/lib/vcr/deprecations/http_stubbing_adapters/common.rb +0 -9
  124. data/lib/vcr/deprecations/http_stubbing_adapters/fakeweb.rb +0 -11
  125. data/lib/vcr/extensions/net_http.rb +0 -32
  126. data/lib/vcr/http_stubbing_adapters/common.rb +0 -202
  127. data/lib/vcr/http_stubbing_adapters/excon.rb +0 -178
  128. data/lib/vcr/http_stubbing_adapters/fakeweb.rb +0 -107
  129. data/lib/vcr/http_stubbing_adapters/faraday.rb +0 -26
  130. data/lib/vcr/http_stubbing_adapters/multi_object_proxy.rb +0 -43
  131. data/lib/vcr/http_stubbing_adapters/typhoeus.rb +0 -115
  132. data/lib/vcr/http_stubbing_adapters/webmock.rb +0 -120
  133. data/lib/vcr/middleware/cassette_arguments.rb +0 -19
  134. data/lib/vcr/middleware/common.rb +0 -20
  135. data/lib/vcr/request_matcher.rb +0 -94
  136. data/lib/vcr/rspec.rb +0 -2
  137. data/lib/vcr/util/basic_object.rb +0 -43
  138. data/lib/vcr/util/ping.rb +0 -30
  139. data/lib/vcr/util/regexes.rb +0 -37
  140. data/spec/fixtures/1.9.1/0_3_1_cassette.yml +0 -29
  141. data/spec/fixtures/1.9.1/cassette_spec/example.yml +0 -110
  142. data/spec/fixtures/1.9.1/cassette_spec/with_localhost_requests.yml +0 -109
  143. data/spec/fixtures/1.9.1/example_net_http.yml +0 -14
  144. data/spec/fixtures/1.9.1/example_net_http_request.yml +0 -12
  145. data/spec/fixtures/1.9.1/example_net_http_response.yml +0 -25
  146. data/spec/fixtures/1.9.1/fake_example.com_responses.yml +0 -108
  147. data/spec/fixtures/1.9.1/match_requests_on.yml +0 -185
  148. data/spec/fixtures/not_1.9.1/0_3_1_cassette.yml +0 -29
  149. data/spec/fixtures/not_1.9.1/cassette_spec/empty.yml +0 -0
  150. data/spec/fixtures/not_1.9.1/example_net_http.yml +0 -14
  151. data/spec/fixtures/not_1.9.1/example_net_http_request.yml +0 -12
  152. data/spec/fixtures/not_1.9.1/example_net_http_response.yml +0 -25
  153. data/spec/support/shared_example_groups/http_stubbing_adapter.rb +0 -133
  154. data/spec/support/shared_example_groups/ignore_localhost_deprecation.rb +0 -28
  155. data/spec/vcr/config_spec.rb +0 -181
  156. data/spec/vcr/deprecations/cassette_spec.rb +0 -57
  157. data/spec/vcr/deprecations/config_spec.rb +0 -30
  158. data/spec/vcr/deprecations/http_stubbing_adapters/common_spec.rb +0 -7
  159. data/spec/vcr/deprecations/http_stubbing_adapters/fakeweb_spec.rb +0 -16
  160. data/spec/vcr/extensions/net_http_spec.rb +0 -80
  161. data/spec/vcr/http_stubbing_adapters/fakeweb_spec.rb +0 -19
  162. data/spec/vcr/http_stubbing_adapters/faraday_spec.rb +0 -76
  163. data/spec/vcr/http_stubbing_adapters/multi_object_proxy_spec.rb +0 -101
  164. data/spec/vcr/http_stubbing_adapters/webmock_spec.rb +0 -17
  165. data/spec/vcr/middleware/cassette_arguments_spec.rb +0 -32
  166. data/spec/vcr/request_matcher_spec.rb +0 -230
@@ -0,0 +1,84 @@
1
+ Feature: Matching on URI
2
+
3
+ Use the `:uri` request matcher to match requests on the request URI.
4
+
5
+ The `:uri` matcher is used (along with the `:method` matcher) by default
6
+ if you do not specify how requests should match.
7
+
8
+ Background:
9
+ Given a previously recorded cassette file "cassettes/example.yml" with:
10
+ """
11
+ ---
12
+ - !ruby/struct:VCR::HTTPInteraction
13
+ request: !ruby/struct:VCR::Request
14
+ method: :post
15
+ uri: http://example.com:80/foo
16
+ body:
17
+ headers:
18
+ response: !ruby/struct:VCR::Response
19
+ status: !ruby/struct:VCR::ResponseStatus
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ content-length:
24
+ - "12"
25
+ body: foo response
26
+ http_version: "1.1"
27
+ - !ruby/struct:VCR::HTTPInteraction
28
+ request: !ruby/struct:VCR::Request
29
+ method: :post
30
+ uri: http://example.com:80/bar
31
+ body:
32
+ headers:
33
+ response: !ruby/struct:VCR::Response
34
+ status: !ruby/struct:VCR::ResponseStatus
35
+ code: 200
36
+ message: OK
37
+ headers:
38
+ content-length:
39
+ - "12"
40
+ body: bar response
41
+ http_version: "1.1"
42
+ """
43
+
44
+ Scenario Outline: Replay interaction that matches the request URI
45
+ And a file named "uri_matching.rb" with:
46
+ """ruby
47
+ include_http_adapter_for("<http_lib>")
48
+
49
+ require 'vcr'
50
+
51
+ VCR.configure do |c|
52
+ <configuration>
53
+ c.cassette_library_dir = 'cassettes'
54
+ end
55
+
56
+ VCR.use_cassette('example', :match_requests_on => [:uri]) do
57
+ puts "Response for /bar: " + response_body_for(:get, "http://example.com/bar")
58
+ end
59
+
60
+ VCR.use_cassette('example', :match_requests_on => [:uri]) do
61
+ puts "Response for /foo: " + response_body_for(:get, "http://example.com/foo")
62
+ end
63
+ """
64
+ When I run `ruby uri_matching.rb`
65
+ Then it should pass with:
66
+ """
67
+ Response for /bar: bar response
68
+ Response for /foo: foo response
69
+ """
70
+
71
+ Examples:
72
+ | configuration | http_lib |
73
+ | c.hook_into :fakeweb | net/http |
74
+ | c.hook_into :webmock | net/http |
75
+ | c.hook_into :webmock | httpclient |
76
+ | c.hook_into :webmock | curb |
77
+ | c.hook_into :webmock | patron |
78
+ | c.hook_into :webmock | em-http-request |
79
+ | c.hook_into :webmock | typhoeus |
80
+ | c.hook_into :typhoeus | typhoeus |
81
+ | c.hook_into :excon | excon |
82
+ | | faraday (w/ net_http) |
83
+ | | faraday (w/ typhoeus) |
84
+
@@ -0,0 +1,85 @@
1
+ Feature: URI without param(s)
2
+
3
+ A common source of difficulty when using VCR with the default matchers
4
+ are non-deterministic URIs. If the URI changes on every test run (because
5
+ it includes a timestamp parameter, or whatever), the default URI matcher
6
+ will not work well for you.
7
+
8
+ You can write a custom matcher to match URIs however you want, but for the
9
+ common need to match on a URI and ignore particular query parameters, VCR
10
+ provides an easier way:
11
+
12
+ :match_requests_on => [:method, VCR.request_matchers.uri_without_param(:timestamp)]
13
+
14
+ `uri_without_param` also has a plural alias (i.e. `uri_without_params(:timestamp, :session)`)
15
+
16
+ Background:
17
+ Given a previously recorded cassette file "cassettes/example.yml" with:
18
+ """
19
+ ---
20
+ - !ruby/struct:VCR::HTTPInteraction
21
+ request: !ruby/struct:VCR::Request
22
+ method: :get
23
+ uri: http://example.com:80/search?q=foo&timestamp=1316920490
24
+ body:
25
+ headers:
26
+ response: !ruby/struct:VCR::Response
27
+ status: !ruby/struct:VCR::ResponseStatus
28
+ code: 200
29
+ message: OK
30
+ headers:
31
+ content-length:
32
+ - "12"
33
+ body: foo response
34
+ http_version: "1.1"
35
+ - !ruby/struct:VCR::HTTPInteraction
36
+ request: !ruby/struct:VCR::Request
37
+ method: :get
38
+ uri: http://example.com:80/search?q=bar&timestamp=1296723437
39
+ body:
40
+ headers:
41
+ response: !ruby/struct:VCR::Response
42
+ status: !ruby/struct:VCR::ResponseStatus
43
+ code: 200
44
+ message: OK
45
+ headers:
46
+ content-length:
47
+ - "12"
48
+ body: bar response
49
+ http_version: "1.1"
50
+ """
51
+
52
+ Scenario: Match the URI on all but the timestamp query parameter
53
+ And a file named "uri_without_param_matcher.rb" with:
54
+ """ruby
55
+ include_http_adapter_for("net/http")
56
+
57
+ require 'vcr'
58
+
59
+ VCR.configure do |c|
60
+ c.hook_into :fakeweb
61
+ c.cassette_library_dir = 'cassettes'
62
+ c.default_cassette_options = {
63
+ :match_requests_on => [:method, VCR.request_matchers.uri_without_param(:timestamp)]
64
+ }
65
+ end
66
+
67
+ def search_uri(q)
68
+ "http://example.com:80/search?q=#{q}&timestamp=#{Time.now.to_i}"
69
+ end
70
+
71
+ VCR.use_cassette('example') do
72
+ puts "Response for bar: " + response_body_for(:get, search_uri("bar"))
73
+ end
74
+
75
+ VCR.use_cassette('example') do
76
+ puts "Response for foo: " + response_body_for(:get, search_uri("foo"))
77
+ end
78
+ """
79
+ When I run `ruby uri_without_param_matcher.rb`
80
+ Then it should pass with:
81
+ """
82
+ Response for bar: bar response
83
+ Response for foo: foo response
84
+ """
85
+
@@ -1,32 +1,8 @@
1
1
  require 'vcr'
2
2
 
3
3
  module VCRHelpers
4
- YAML_REGEX_FOR_1_9_1 = Regexp.union(*[
5
- ' request',
6
- ' method',
7
- ' uri',
8
- ' body',
9
- ' headers',
10
- ' response',
11
- ' status',
12
- ' code',
13
- ' message',
14
- ' body',
15
- ' http_version'
16
- ].uniq)
17
-
18
- def normalize_cassette_yaml(content)
19
- return content unless RUBY_VERSION == '1.9.1'
20
-
21
- # Ruby 1.9.1 serializes YAML a bit different, so
22
- # we deal with that difference and add leading colons here.
23
- content = content.gsub(YAML_REGEX_FOR_1_9_1) do |match|
24
- match.sub(/^ +/, '\0:')
25
- end
26
- end
27
4
 
28
5
  def normalize_cassette_structs(content)
29
- content = normalize_cassette_yaml(content)
30
6
  structs = YAML.load(content)
31
7
 
32
8
  # Remove non-deterministic headers
@@ -34,9 +10,9 @@ module VCRHelpers
34
10
  s.response.headers.reject! { |k, v| %w[ server date ].include?(k) }
35
11
  end
36
12
 
37
- case $stubbing_lib_for_current_scenario
38
- when ':excon'
39
- # Excon does not expose the status message or http version,
13
+ case @stubbing_lib_for_current_scenario
14
+ when /excon|faraday/
15
+ # Excon/Faraday do not expose the status message or http version,
40
16
  # so we have no way to record these attributes.
41
17
  structs.each do |s|
42
18
  s.response.status.message = nil
@@ -69,7 +45,7 @@ Given /^the directory "([^"]*)" does not exist$/ do |dir|
69
45
  end
70
46
 
71
47
  Given /^a previously recorded cassette file "([^"]*)" with:$/ do |file_name, content|
72
- write_file(file_name, normalize_cassette_yaml(content))
48
+ write_file(file_name, content)
73
49
  end
74
50
 
75
51
  Given /^(\d+) days have passed since the cassette was recorded$/ do |day_count|
@@ -4,20 +4,22 @@ Bundler.setup
4
4
 
5
5
  require 'aruba/cucumber'
6
6
 
7
- Before do
8
- this_dir = File.dirname(__FILE__)
9
- in_current_dir do
10
- FileUtils.ln_s File.join(this_dir, 'vcr_cucumber_helpers.rb'), 'vcr_cucumber_helpers.rb'
11
- end
12
- end
13
-
7
+ cucumer_helpers_file = '../../features/support/vcr_cucumber_helpers'
14
8
  if RUBY_VERSION > '1.9.1'
15
9
  Before do
16
- set_env('RUBYOPT', '-I.:../../lib')
10
+ set_env('RUBYOPT', "-I.:../../lib -r#{cucumer_helpers_file}")
17
11
  end
18
12
  elsif RUBY_PLATFORM == 'java'
19
13
  Before do
20
- set_env('RUBYOPT', '-I../../lib -rubygems')
14
+ set_env('RUBYOPT', "-I../../lib -rubygems -r#{cucumer_helpers_file}")
15
+
16
+ # ideas taken from: http://blog.headius.com/2010/03/jruby-startup-time-tips.html
17
+ set_env('JRUBY_OPTS', '-X-C') # disable JIT since these processes are so short lived
18
+ set_env('JAVA_OPTS', '-d32') # force jRuby to use client JVM for faster startup times
19
+ end
20
+ else
21
+ Before do
22
+ set_env('RUBYOPT', "-rubygems -r#{cucumer_helpers_file}")
21
23
  end
22
24
  end
23
25
 
@@ -27,8 +27,6 @@ elsif RUBY_PLATFORM == 'java'
27
27
  # on JRuby. I'm not sure why, and there's little benefit to running
28
28
  # them on JRuby...so we just skip them. Excon seems to have the same issue :(.
29
29
  UNSUPPORTED_HTTP_LIBS = c_dependent_libs + %w[ httpclient excon ]
30
- elsif RUBY_VERSION == '1.8.6' && ENV['TRAVIS']
31
- UNSUPPORTED_HTTP_LIBS = %w[ em-http-request ]
32
30
  end
33
31
 
34
32
  if defined?(UNSUPPORTED_HTTP_LIBS)
@@ -42,19 +40,12 @@ if defined?(UNSUPPORTED_HTTP_LIBS)
42
40
  end
43
41
  end
44
42
 
45
- stubbing_libs = %w[ :fakeweb :webmock :typhoeus :faraday :excon ]
46
-
47
43
  # Set a global based on the current stubbing lib so we can put special-case
48
44
  # logic in our step definitions based on the http stubbing library.
49
45
  Before do |scenario|
50
46
  if scenario.respond_to?(:cell_values)
51
- stub_with = stubbing_libs & scenario.cell_values
52
- if stub_with.size == 1
53
- $stubbing_lib_for_current_scenario = stub_with.first
54
- else
55
- $stubbing_lib_for_current_scenario = nil
56
- end
47
+ @stubbing_lib_for_current_scenario = scenario.cell_values.find { |v| v =~ /fakeweb|webmock|typhoeus|faraday|excon/ }
57
48
  else
58
- $stubbing_lib_for_current_scenario = nil
49
+ @stubbing_lib_for_current_scenario = nil
59
50
  end
60
51
  end
@@ -1,11 +1,10 @@
1
1
  # This file gets symlinked into the tmp/aruba directory before
2
2
  # each scenario so that it is available to be required in them.
3
- $LOAD_PATH.unshift '../../spec' unless $LOAD_PATH.include?('../../spec')
3
+ $LOAD_PATH << '../../spec' unless $LOAD_PATH.include?('../../spec')
4
4
  $LOAD_PATH.unshift '../../lib' unless $LOAD_PATH.include?('../../lib')
5
5
 
6
- RUNNING_UNDER_ARUBA = File.dirname(__FILE__) == '.' || File.dirname(__FILE__) =~ /aruba/
7
-
8
- if RUNNING_UNDER_ARUBA
6
+ running_under_aruba = File.expand_path('.').include?('aruba')
7
+ if running_under_aruba
9
8
  require 'support/fixnum_extension'
10
9
  require 'vcr/util/internet_connection'
11
10
 
@@ -23,7 +22,7 @@ end
23
22
 
24
23
  def include_http_adapter_for(lib)
25
24
  require 'support/http_library_adapters'
26
- require lib
25
+ require (lib =~ /faraday/ ? 'faraday' : lib)
27
26
  include HTTP_LIBRARY_ADAPTERS[lib]
28
27
  end
29
28
 
@@ -8,13 +8,15 @@ Feature: Usage with Cucumber
8
8
 
9
9
  In a cucumber support file (e.g. features/support/vcr.rb), put code like this:
10
10
 
11
- VCR.cucumber_tags do |t|
12
- t.tag '@tag1'
13
- t.tags '@tag2', '@tag3'
11
+ ``` ruby
12
+ VCR.cucumber_tags do |t|
13
+ t.tag '@tag1'
14
+ t.tags '@tag2', '@tag3'
14
15
 
15
- t.tag '@tag3', :cassette => :options
16
- t.tags '@tag4, '@tag5', :cassette => :options
17
- end
16
+ t.tag '@tag3', :cassette => :options
17
+ t.tags '@tag4, '@tag5', :cassette => :options
18
+ end
19
+ ```
18
20
 
19
21
  VCR will use a cassette named "cucumber_tags/<tag_name>" for scenarios
20
22
  with each of these tags. The configured `default_cassette_options` will
@@ -23,9 +25,7 @@ Feature: Usage with Cucumber
23
25
 
24
26
  Scenario: Record HTTP interactions in a scenario by tagging it
25
27
  Given a file named "lib/server.rb" with:
26
- """
27
- require 'vcr_cucumber_helpers'
28
-
28
+ """ruby
29
29
  if ENV['WITH_SERVER'] == 'true'
30
30
  start_sinatra_app(:port => 7777) do
31
31
  get('/:path') { "Hello #{params[:path]}" }
@@ -34,14 +34,13 @@ Feature: Usage with Cucumber
34
34
  """
35
35
 
36
36
  Given a file named "features/support/vcr.rb" with:
37
- """
37
+ """ruby
38
38
  require "lib/server"
39
39
  require 'vcr'
40
40
 
41
- VCR.config do |c|
42
- c.stub_with :webmock
41
+ VCR.configure do |c|
42
+ c.hook_into :fakeweb
43
43
  c.cassette_library_dir = 'features/cassettes'
44
- c.default_cassette_options = { :record => :new_episodes }
45
44
  end
46
45
 
47
46
  VCR.cucumber_tags do |t|
@@ -50,7 +49,7 @@ Feature: Usage with Cucumber
50
49
  end
51
50
  """
52
51
  And a file named "features/step_definitions/steps.rb" with:
53
- """
52
+ """ruby
54
53
  require 'net/http'
55
54
 
56
55
  When /^a request is made to "([^"]*)"$/ do |url|
@@ -92,8 +91,8 @@ Feature: Usage with Cucumber
92
91
  When I run `cucumber WITH_SERVER=true features/vcr_example.feature`
93
92
  Then it should fail with "3 scenarios (2 failed, 1 passed)"
94
93
  And the output should contain each of the following:
95
- | Real HTTP connections are disabled. Unregistered request: GET http://localhost:7777/disallowed_1 |
96
- | Real HTTP connections are disabled. Unregistered request: GET http://localhost:7777/disallowed_2 |
94
+ | Real HTTP connections are disabled. Request: GET http://localhost:7777/disallowed_1 |
95
+ | Real HTTP connections are disabled. Request: GET http://localhost:7777/disallowed_2 |
97
96
  And the file "features/cassettes/cucumber_tags/localhost_request.yml" should contain "body: Hello localhost_request_1"
98
97
  And the file "features/cassettes/cucumber_tags/localhost_request.yml" should contain "body: Hello localhost_request_2"
99
98
  And the file "features/cassettes/nested_cassette.yml" should contain "body: Hello nested_cassette"
@@ -104,8 +103,8 @@ Feature: Usage with Cucumber
104
103
  When I run `cucumber features/vcr_example.feature`
105
104
  Then it should fail with "3 scenarios (2 failed, 1 passed)"
106
105
  And the output should contain each of the following:
107
- | Real HTTP connections are disabled. Unregistered request: GET http://localhost:7777/disallowed_1 |
108
- | Real HTTP connections are disabled. Unregistered request: GET http://localhost:7777/disallowed_2 |
106
+ | Real HTTP connections are disabled. Request: GET http://localhost:7777/disallowed_1 |
107
+ | Real HTTP connections are disabled. Request: GET http://localhost:7777/disallowed_2 |
109
108
  And the file "features/cassettes/cucumber_tags/localhost_request.yml" should contain "body: Hello localhost_request_1"
110
109
  And the file "features/cassettes/cucumber_tags/localhost_request.yml" should contain "body: Hello localhost_request_2"
111
110
  And the file "features/cassettes/nested_cassette.yml" should contain "body: Hello nested_cassette"
@@ -27,15 +27,13 @@ Feature: Usage with RSpec
27
27
  | spec/cassettes/VCR-RSpec_integration/without_an_explicit_cassette_name.yml |
28
28
  | spec/cassettes/net_http_example.yml |
29
29
  And a file named "spec/sinatra_app.rb" with:
30
- """
31
- require 'vcr_cucumber_helpers'
32
-
30
+ """ruby
33
31
  start_sinatra_app(:port => 7777) do
34
32
  get('/') { "Hello" }
35
33
  end
36
34
  """
37
35
  And a file named "spec/vcr_example_spec.rb" with:
38
- """
36
+ """ruby
39
37
  require 'spec_helper'
40
38
 
41
39
  describe "VCR-RSpec integration" do
@@ -63,14 +61,13 @@ Feature: Usage with RSpec
63
61
 
64
62
  Scenario: Use `use_vcr_cassette` macro with RSpec 2
65
63
  Given a file named "spec/spec_helper.rb" with:
66
- """
64
+ """ruby
67
65
  require 'sinatra_app'
68
66
  require 'vcr'
69
67
 
70
- VCR.config do |c|
68
+ VCR.configure do |c|
71
69
  c.cassette_library_dir = 'spec/cassettes'
72
- c.stub_with :fakeweb
73
- c.default_cassette_options = { :record => :new_episodes }
70
+ c.hook_into :fakeweb
74
71
  end
75
72
 
76
73
  RSpec.configure do |c|
@@ -84,7 +81,7 @@ Feature: Usage with RSpec
84
81
 
85
82
  Scenario: Use `use_vcr_cassette` macro with RSpec 1
86
83
  Given a file named "spec/spec_helper.rb" with:
87
- """
84
+ """ruby
88
85
  require 'sinatra_app'
89
86
  $LOAD_PATH.unshift(File.join(%w[ .. .. vendor rspec-1 lib ]))
90
87
 
@@ -93,10 +90,9 @@ Feature: Usage with RSpec
93
90
 
94
91
  require 'vcr'
95
92
 
96
- VCR.config do |c|
93
+ VCR.configure do |c|
97
94
  c.cassette_library_dir = 'spec/cassettes'
98
- c.stub_with :fakeweb
99
- c.default_cassette_options = { :record => :new_episodes }
95
+ c.hook_into :fakeweb
100
96
  end
101
97
 
102
98
  Spec::Runner.configure do |c|