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,143 @@
1
+ require 'spec_helper'
2
+
3
+ describe VCR::Configuration do
4
+ describe '#cassette_library_dir=' do
5
+ let(:tmp_dir) { VCR::SPEC_ROOT + '/../tmp/cassette_library_dir/new_dir' }
6
+ after(:each) { FileUtils.rm_rf tmp_dir }
7
+
8
+ it 'creates the directory if it does not exist' do
9
+ expect { subject.cassette_library_dir = tmp_dir }.to change { File.exist?(tmp_dir) }.from(false).to(true)
10
+ end
11
+
12
+ it 'does not raise an error if given nil' do
13
+ expect { subject.cassette_library_dir = nil }.to_not raise_error
14
+ end
15
+ end
16
+
17
+ describe '#default_cassette_options' do
18
+ it 'has a hash with some defaults' do
19
+ subject.default_cassette_options.should eq({
20
+ :match_requests_on => VCR::RequestMatcherRegistry::DEFAULT_MATCHERS,
21
+ :record => :once
22
+ })
23
+ end
24
+
25
+ it "returns #{VCR::RequestMatcherRegistry::DEFAULT_MATCHERS.inspect} for :match_requests_on when other defaults have been set" do
26
+ subject.default_cassette_options = { :record => :none }
27
+ subject.default_cassette_options.should include(:match_requests_on => VCR::RequestMatcherRegistry::DEFAULT_MATCHERS)
28
+ end
29
+
30
+ it "returns :once for :record when other defaults have been set" do
31
+ subject.default_cassette_options = { :erb => :true }
32
+ subject.default_cassette_options.should include(:record => :once)
33
+ end
34
+
35
+ it "allows defaults to be overriden" do
36
+ subject.default_cassette_options = { :record => :all }
37
+ subject.default_cassette_options.should include(:record => :all)
38
+ end
39
+
40
+ it "allows other keys to be set" do
41
+ subject.default_cassette_options = { :re_record_interval => 10 }
42
+ subject.default_cassette_options.should include(:re_record_interval => 10)
43
+ end
44
+ end
45
+
46
+ describe '#register_request_matcher' do
47
+ it 'registers the given request matcher' do
48
+ expect {
49
+ VCR.request_matchers[:custom]
50
+ }.to raise_error(VCR::UnregisteredMatcherError)
51
+
52
+ matcher_run = false
53
+ subject.register_request_matcher(:custom) { |r1, r2| matcher_run = true }
54
+ VCR.request_matchers[:custom].matches?(:r1, :r2)
55
+ matcher_run.should be_true
56
+ end
57
+ end
58
+
59
+ describe '#hook_into' do
60
+ it 'requires the named library hook' do
61
+ subject.should_receive(:require).with("vcr/library_hooks/fakeweb")
62
+ subject.should_receive(:require).with("vcr/library_hooks/excon")
63
+ subject.hook_into :fakeweb, :excon
64
+ end
65
+
66
+ it 'raises an error for unsupported stubbing libraries' do
67
+ expect {
68
+ subject.hook_into :unsupported_library
69
+ }.to raise_error(ArgumentError, /unsupported_library is not a supported VCR HTTP library hook/i)
70
+ end
71
+
72
+ it 'invokes the after_library_hooks_loaded hooks' do
73
+ called = false
74
+ subject.after_library_hooks_loaded { called = true }
75
+ subject.hook_into :fakeweb
76
+ called.should be_true
77
+ end
78
+ end
79
+
80
+ describe '#ignore_hosts' do
81
+ it 'delegates to the current request_ignorer instance' do
82
+ VCR.request_ignorer.should_receive(:ignore_hosts).with('example.com', 'example.net')
83
+ subject.ignore_hosts 'example.com', 'example.net'
84
+ end
85
+ end
86
+
87
+ describe '#ignore_localhost=' do
88
+ it 'delegates to the current request_ignorer instance' do
89
+ VCR.request_ignorer.should_receive(:ignore_localhost=).with(true)
90
+ subject.ignore_localhost = true
91
+ end
92
+ end
93
+
94
+ describe '#allow_http_connections_when_no_cassette=' do
95
+ [true, false].each do |val|
96
+ it "sets the allow_http_connections_when_no_cassette to #{val} when set to #{val}" do
97
+ subject.allow_http_connections_when_no_cassette = val
98
+ subject.allow_http_connections_when_no_cassette?.should eq(val)
99
+ end
100
+ end
101
+ end
102
+
103
+ describe '#filter_sensitive_data' do
104
+ let(:interaction) { mock('interaction') }
105
+ before(:each) { interaction.stub(:filter!) }
106
+
107
+ it 'adds a before_record hook that replaces the string returned by the block with the given string' do
108
+ subject.filter_sensitive_data('foo', &lambda { 'bar' })
109
+ interaction.should_receive(:filter!).with('bar', 'foo')
110
+ subject.invoke_hook(:before_record, nil, interaction)
111
+ end
112
+
113
+ it 'adds a before_playback hook that replaces the given string with the string returned by the block' do
114
+ subject.filter_sensitive_data('foo', &lambda { 'bar' })
115
+ interaction.should_receive(:filter!).with('foo', 'bar')
116
+ subject.invoke_hook(:before_playback, nil, interaction)
117
+ end
118
+
119
+ it 'tags the before_record hook when given a tag' do
120
+ subject.should_receive(:before_record).with(:my_tag)
121
+ subject.filter_sensitive_data('foo', :my_tag) { 'bar' }
122
+ end
123
+
124
+ it 'tags the before_playback hook when given a tag' do
125
+ subject.should_receive(:before_playback).with(:my_tag)
126
+ subject.filter_sensitive_data('foo', :my_tag) { 'bar' }
127
+ end
128
+
129
+ it 'yields the interaction to the block for the before_record hook' do
130
+ yielded_interaction = nil
131
+ subject.filter_sensitive_data('foo', &lambda { |i| yielded_interaction = i; 'bar' })
132
+ subject.invoke_hook(:before_record, nil, interaction)
133
+ yielded_interaction.should equal(interaction)
134
+ end
135
+
136
+ it 'yields the interaction to the block for the before_playback hook' do
137
+ yielded_interaction = nil
138
+ subject.filter_sensitive_data('foo', &lambda { |i| yielded_interaction = i; 'bar' })
139
+ subject.invoke_hook(:before_playback, nil, interaction)
140
+ yielded_interaction.should equal(interaction)
141
+ end
142
+ end
143
+ end
@@ -0,0 +1,91 @@
1
+ require 'spec_helper'
2
+
3
+ describe VCR, 'deprecations', :disable_warnings do
4
+ describe ".config" do
5
+ it 'delegates to VCR.configure' do
6
+ VCR.should_receive(:configure)
7
+ VCR.config { }
8
+ end
9
+
10
+ it 'yields the configuration object' do
11
+ config_object = nil
12
+ VCR.config { |c| config_object = c }
13
+ config_object.should be(VCR.configuration)
14
+ end
15
+
16
+ it 'prints a deprecation warning' do
17
+ VCR.should_receive(:warn).with \
18
+ "WARNING: `VCR.config` is deprecated. Use VCR.configure instead."
19
+
20
+ VCR.config { }
21
+ end
22
+ end
23
+
24
+ describe "Config" do
25
+ it 'returns the same object referenced by VCR.configuration' do
26
+ VCR::Config.should be(VCR.configuration)
27
+ end
28
+
29
+ it 'prints a deprecation warning' do
30
+ VCR.should_receive(:warn).with \
31
+ "WARNING: `VCR::Config` is deprecated. Use VCR.configuration instead."
32
+
33
+ VCR::Config
34
+ end
35
+
36
+ it 'preserves the normal undefined constant behavior' do
37
+ expect {
38
+ VCR::SomeUndefinedConstant
39
+ }.to raise_error(NameError)
40
+ end
41
+ end
42
+
43
+ describe "Cassette::MissingERBVariableError" do
44
+ it 'returns VCR::Errors::MissingERBVariableError' do
45
+ VCR::Cassette::MissingERBVariableError.should be(VCR::Errors::MissingERBVariableError)
46
+ end
47
+
48
+ it 'prints a deprecation warning' do
49
+ VCR::Cassette.should_receive(:warn).with \
50
+ "WARNING: `VCR::Cassette::MissingERBVariableError` is deprecated. Use `VCR::Errors::MissingERBVariableError` instead."
51
+
52
+ VCR::Cassette::MissingERBVariableError
53
+ end
54
+
55
+ it 'preserves the normal undefined constant behavior' do
56
+ expect {
57
+ VCR::Cassette::SomeUndefinedConstant
58
+ }.to raise_error(NameError)
59
+ end
60
+ end
61
+
62
+ describe "VCR.configure { |c| c.stub_with ... }" do
63
+ it 'delegates to #hook_into' do
64
+ VCR.configuration.should_receive(:hook_into).with(:fakeweb, :excon)
65
+ VCR.configure { |c| c.stub_with :fakeweb, :excon }
66
+ end
67
+
68
+ it 'prints a deprecation warning' do
69
+ VCR.configuration.should_receive(:warn).with \
70
+ "WARNING: `VCR.config { |c| c.stub_with ... }` is deprecated. Use `VCR.configure { |c| c.hook_into ... }` instead."
71
+
72
+ VCR.configure { |c| c.stub_with :fakeweb, :excon }
73
+ end
74
+ end
75
+
76
+ describe "VCR.configure { |c| c.stub_with :faraday }" do
77
+ it 'prints a descriptive warning' do
78
+ Kernel.should_receive(:warn).with(/Just use `VCR::Middleware::Faraday` in your faraday stack/)
79
+ # simulate the loading of the adapter (since it may have already been required)
80
+ load 'vcr/library_hooks/faraday.rb'
81
+ end
82
+ end
83
+
84
+ describe "VCR::Middleware::Faraday" do
85
+ it 'prints a deprecation warning when passed a block' do
86
+ Kernel.should_receive(:warn).with(/Passing a block .* is deprecated/)
87
+ VCR::Middleware::Faraday.new(stub) { }
88
+ end
89
+ end
90
+ end
91
+
@@ -1,12 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe VCR::HttpStubbingAdapters::Excon do
4
- it_behaves_like 'an http stubbing adapter',
5
- ['excon'],
6
- [:method, :uri, :host, :path, :body, :headers],
7
- :status_message_not_exposed
3
+ describe "Excon hook" do
4
+ it_behaves_like 'a hook into an HTTP library', 'excon', :status_message_not_exposed
8
5
 
9
- it_performs('version checking',
6
+ it_performs('version checking', 'Excon',
10
7
  :valid => %w[ 0.6.5 0.6.99 ],
11
8
  :too_low => %w[ 0.5.99 0.6.4 ],
12
9
  :too_high => %w[ 0.7.0 1.0.0 ]
@@ -24,7 +21,7 @@ describe VCR::HttpStubbingAdapters::Excon do
24
21
  let(:excon) { ::Excon.new("http://localhost:#{VCR::SinatraApp.port}/search") }
25
22
 
26
23
  it 'properly records and plays back the response' do
27
- described_class.http_connections_allowed = true
24
+ VCR.stub(:real_http_connections_allowed? => true)
28
25
  recorded, played_back = [1, 2].map do
29
26
  VCR.use_cassette('excon_query', :record => :once) do
30
27
  excon.request(:method => :get, :query => { :q => 'Tolkien' }).body
@@ -38,7 +35,7 @@ describe VCR::HttpStubbingAdapters::Excon do
38
35
 
39
36
  context "when Excon's streaming API is used" do
40
37
  it 'properly records and plays back the response' do
41
- described_class.http_connections_allowed = true
38
+ VCR.stub(:real_http_connections_allowed? => true)
42
39
  recorded, played_back = [1, 2].map do
43
40
  chunks = []
44
41
 
@@ -58,7 +55,7 @@ describe VCR::HttpStubbingAdapters::Excon do
58
55
 
59
56
  context 'when Excon raises an error due to an unexpected response status' do
60
57
  it 'still records properly' do
61
- described_class.http_connections_allowed = true
58
+ VCR.stub(:real_http_connections_allowed? => true)
62
59
 
63
60
  VCR.should_receive(:record_http_interaction) do |interaction|
64
61
  interaction.response.status.code.should eq(404)
@@ -0,0 +1,83 @@
1
+ require 'spec_helper'
2
+
3
+ describe "FakeWeb hook", :with_monkey_patches => :fakeweb do
4
+ it_behaves_like 'a hook into an HTTP library', 'net/http'
5
+
6
+ it_performs('version checking', 'FakeWeb',
7
+ :valid => %w[ 1.3.0 1.3.1 1.3.99 ],
8
+ :too_low => %w[ 1.2.8 1.1.30 0.30.30 ],
9
+ :too_high => %w[ 1.4.0 1.10.0 2.0.0 ]
10
+ ) do
11
+ before(:each) { @orig_version = FakeWeb::VERSION }
12
+ after(:each) { FakeWeb::VERSION = @orig_version }
13
+
14
+ # Cannot be regular method def as that raises a "dynamic constant assignment" error
15
+ define_method :stub_version do |version|
16
+ FakeWeb::VERSION = version
17
+ end
18
+ end
19
+
20
+ describe "some specific Net::HTTP edge cases" do
21
+ before(:each) do
22
+ VCR.stub(:real_http_connections_allowed? => true)
23
+ end
24
+
25
+ it "does not record headers for which Net::HTTP sets defaults near the end of the real request" do
26
+ VCR.should_receive(:record_http_interaction) do |interaction|
27
+ interaction.request.headers.should_not have_key('content-type')
28
+ interaction.request.headers.should_not have_key('host')
29
+ end
30
+ Net::HTTP.new('localhost', VCR::SinatraApp.port).send_request('POST', '/', '', { 'x-http-user' => 'me' })
31
+ end
32
+
33
+ it "records headers for which Net::HTTP usually sets defaults when the user manually sets their values" do
34
+ VCR.should_receive(:record_http_interaction) do |interaction|
35
+ interaction.request.headers['content-type'].should eq(['foo/bar'])
36
+ interaction.request.headers['host'].should eq(['my-example.com'])
37
+ end
38
+ Net::HTTP.new('localhost', VCR::SinatraApp.port).send_request('POST', '/', '', { 'Content-Type' => 'foo/bar', 'Host' => 'my-example.com' })
39
+ end
40
+
41
+ def perform_get_with_returning_block
42
+ Net::HTTP.new('localhost', VCR::SinatraApp.port).request(Net::HTTP::Get.new('/', {})) do |response|
43
+ return response
44
+ end
45
+ end
46
+
47
+ it 'records the interaction when Net::HTTP#request is called with a block with a return statement' do
48
+ VCR.should_receive(:record_http_interaction).once
49
+ perform_get_with_returning_block
50
+ end
51
+
52
+ it 'records the interaction only once, even when Net::HTTP internally recursively calls #request' do
53
+ VCR.should_receive(:record_http_interaction).once
54
+ Net::HTTP.new('localhost', VCR::SinatraApp.port).post('/', nil)
55
+ end
56
+ end
57
+
58
+ describe "VCR.configuration.after_library_hooks_loaded hook", :disable_warnings do
59
+ before(:each) do
60
+ load "vcr/library_hooks/fakeweb.rb" # to re-add the hook since it's cleared by each test
61
+ end
62
+
63
+ let(:run_hook) { VCR.configuration.invoke_hook(:after_library_hooks_loaded) }
64
+
65
+ context 'when WebMock has been loaded' do
66
+ before(:each) { defined?(WebMock).should be_true }
67
+
68
+ it 'raises an error since FakeWeb and WebMock cannot both be used simultaneously' do
69
+ expect { run_hook }.to raise_error(ArgumentError, /cannot use both/)
70
+ end
71
+ end
72
+
73
+ context 'when WebMock has not been loaded' do
74
+ let!(:orig_webmock_constant) { ::WebMock }
75
+ before(:each) { Object.send(:remove_const, :WebMock) }
76
+ after(:each) { ::WebMock = orig_webmock_constant }
77
+
78
+ it 'does not raise an error' do
79
+ run_hook # should not raise an error
80
+ end
81
+ end
82
+ end
83
+ end
@@ -1,14 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe VCR::HttpStubbingAdapters::Typhoeus do
4
- before(:each) do
5
- ::Typhoeus::Hydra.stubs = []
6
- ::Typhoeus::Hydra.allow_net_connect = true
7
- end
8
-
9
- it_behaves_like 'an http stubbing adapter', ['typhoeus'], [:method, :uri, :host, :path, :body, :headers]
3
+ describe "Typhoeus hook", :with_monkey_patches => :typhoeus do
4
+ it_behaves_like 'a hook into an HTTP library', 'typhoeus'
10
5
 
11
- it_performs('version checking',
6
+ it_performs('version checking', 'Typhoeus',
12
7
  :valid => %w[ 0.2.1 0.2.99 ],
13
8
  :too_low => %w[ 0.1.0 0.1.31 0.2.0 ],
14
9
  :too_high => %w[ 0.3.0 1.0.0 ]
@@ -22,10 +17,11 @@ describe VCR::HttpStubbingAdapters::Typhoeus do
22
17
  end
23
18
  end
24
19
 
25
- describe ".after_adapters_loaded" do
26
- it 'disables the webmock typhoeus adapter so it does not conflict with our typhoeus adapter' do
20
+ describe "VCR.configuration.after_library_hooks_loaded hook", :disable_warnings do
21
+ it 'disables the webmock typhoeus adapter so it does not conflict with our typhoeus hook' do
22
+ load "vcr/library_hooks/typhoeus.rb" # to re-add the hook since it's cleared by each test
27
23
  ::WebMock::HttpLibAdapters::TyphoeusAdapter.should_receive(:disable!)
28
- described_class.after_adapters_loaded
24
+ VCR.configuration.invoke_hook(:after_library_hooks_loaded)
29
25
  end
30
26
  end
31
27
  end unless RUBY_PLATFORM == 'java'
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe "WebMock hook", :with_monkey_patches => :webmock do
4
+ %w[net/http patron httpclient em-http-request curb typhoeus].each do |lib|
5
+ it_behaves_like 'a hook into an HTTP library', lib
6
+ end
7
+
8
+ it_performs('version checking', 'WebMock',
9
+ :valid => %w[ 1.7.0 1.7.99 ],
10
+ :too_low => %w[ 0.9.9 0.9.10 0.1.30 1.0.30 1.6.9 ],
11
+ :too_high => %w[ 1.8.0 1.10.0 2.0.0 ]
12
+ ) do
13
+ def stub_version(version)
14
+ WebMock.stub(:version).and_return(version)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,51 @@
1
+ require 'vcr/library_hooks'
2
+
3
+ module VCR
4
+ describe LibraryHooks do
5
+ describe '#disabled?' do
6
+ it 'returns false by default for any argument given' do
7
+ subject.disabled?(:foo).should be_false
8
+ subject.disabled?(:bar).should be_false
9
+ end
10
+
11
+ context 'when a library hook is exclusively enabled' do
12
+ it 'returns false for the exclusively enabled hook' do
13
+ faraday_disabled = nil
14
+
15
+ subject.exclusively_enabled :faraday do
16
+ faraday_disabled = subject.disabled?(:faraday)
17
+ end
18
+
19
+ faraday_disabled.should eq(false)
20
+ end
21
+
22
+ it 'returns true for every other argument given' do
23
+ foo_disabled = bar_disabled = nil
24
+
25
+ subject.exclusively_enabled :faraday do
26
+ foo_disabled = subject.disabled?(:foo)
27
+ bar_disabled = subject.disabled?(:bar)
28
+ end
29
+
30
+ foo_disabled.should be_true
31
+ bar_disabled.should be_true
32
+ end
33
+ end
34
+ end
35
+
36
+ describe '#exclusively_enabled' do
37
+ it 'restores all hook to being enabled when the block completes' do
38
+ subject.exclusively_enabled(:faraday) { }
39
+ subject.disabled?(:foo).should be_false
40
+ subject.disabled?(:faraday).should be_false
41
+ end
42
+
43
+ it 'restores all hooks to being enabled when the block completes, even if there is an error' do
44
+ subject.exclusively_enabled(:faraday) { raise "boom" } rescue
45
+ subject.disabled?(:foo).should be_false
46
+ subject.disabled?(:faraday).should be_false
47
+ end
48
+ end
49
+ end
50
+ end
51
+