vcr 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. data/.document +5 -0
  2. data/.gitignore +27 -0
  3. data/CHANGELOG.md +13 -0
  4. data/Gemfile +24 -0
  5. data/Gemfile.lock +119 -0
  6. data/README.md +3 -6
  7. data/Rakefile +70 -0
  8. data/benchmarks/http_stubbing_libraries.rb +59 -0
  9. data/features/fixtures/vcr_cassettes/1.9.1/cucumber_tags/regex_cassette.yml +43 -0
  10. data/features/fixtures/vcr_cassettes/1.9.1/cucumber_tags/replay_cassette1.yml +43 -0
  11. data/features/fixtures/vcr_cassettes/1.9.1/cucumber_tags/replay_cassette2.yml +63 -0
  12. data/features/fixtures/vcr_cassettes/1.9.1/cucumber_tags/replay_cassette3.yml +85 -0
  13. data/features/fixtures/vcr_cassettes/1.9.1/erb_cassette.yml +36 -0
  14. data/features/fixtures/vcr_cassettes/1.9.1/match_requests_on.yml +35 -0
  15. data/features/fixtures/vcr_cassettes/1.9.1/nested_replay_cassette.yml +32 -0
  16. data/features/fixtures/vcr_cassettes/1.9.1/not_the_real_response.yml +43 -0
  17. data/features/fixtures/vcr_cassettes/1.9.1/replay_localhost_cassette.yml +32 -0
  18. data/features/fixtures/vcr_cassettes/not_1.9.1/cucumber_tags/regex_cassette.yml +43 -0
  19. data/features/fixtures/vcr_cassettes/not_1.9.1/cucumber_tags/replay_cassette1.yml +43 -0
  20. data/features/fixtures/vcr_cassettes/not_1.9.1/cucumber_tags/replay_cassette2.yml +47 -0
  21. data/features/fixtures/vcr_cassettes/not_1.9.1/cucumber_tags/replay_cassette3.yml +85 -0
  22. data/features/fixtures/vcr_cassettes/not_1.9.1/erb_cassette.yml +36 -0
  23. data/features/fixtures/vcr_cassettes/not_1.9.1/match_requests_on.yml +35 -0
  24. data/features/fixtures/vcr_cassettes/not_1.9.1/nested_replay_cassette.yml +24 -0
  25. data/features/fixtures/vcr_cassettes/not_1.9.1/not_the_real_response.yml +43 -0
  26. data/features/fixtures/vcr_cassettes/not_1.9.1/replay_localhost_cassette.yml +32 -0
  27. data/features/http_client.feature +16 -0
  28. data/features/net_http.feature +27 -0
  29. data/features/record_response.feature +66 -0
  30. data/features/replay_recorded_response.feature +96 -0
  31. data/features/step_definitions/http_client_steps.rb +7 -0
  32. data/features/step_definitions/net_http_steps.rb +37 -0
  33. data/features/step_definitions/vcr_steps.rb +240 -0
  34. data/features/support/env.rb +104 -0
  35. data/features/webmock.feature +26 -0
  36. data/lib/vcr.rb +2 -2
  37. data/lib/vcr/extensions/net_http.rb +0 -8
  38. data/lib/vcr/http_stubbing_adapters/common.rb +39 -0
  39. data/lib/vcr/http_stubbing_adapters/fakeweb.rb +74 -70
  40. data/lib/vcr/http_stubbing_adapters/webmock.rb +61 -62
  41. data/lib/vcr/version.rb +1 -1
  42. data/spec/cassette_spec.rb +280 -0
  43. data/spec/config_spec.rb +76 -0
  44. data/spec/cucumber_tags_spec.rb +55 -0
  45. data/spec/deprecations_spec.rb +52 -0
  46. data/spec/extensions/net_http_response_spec.rb +85 -0
  47. data/spec/extensions/net_http_spec.rb +77 -0
  48. data/spec/fixtures/1.9.1/0_3_1_cassette.yml +29 -0
  49. data/spec/fixtures/1.9.1/cassette_spec/erb_with_no_vars.yml +32 -0
  50. data/spec/fixtures/1.9.1/cassette_spec/erb_with_vars.yml +32 -0
  51. data/spec/fixtures/1.9.1/cassette_spec/example.yml +110 -0
  52. data/spec/fixtures/1.9.1/cassette_spec/with_localhost_requests.yml +86 -0
  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 +106 -0
  57. data/spec/fixtures/1.9.1/match_requests_on.yml +185 -0
  58. data/spec/fixtures/not_1.9.1/0_3_1_cassette.yml +29 -0
  59. data/spec/fixtures/not_1.9.1/cassette_spec/erb_with_no_vars.yml +32 -0
  60. data/spec/fixtures/not_1.9.1/cassette_spec/erb_with_vars.yml +32 -0
  61. data/spec/fixtures/not_1.9.1/cassette_spec/example.yml +110 -0
  62. data/spec/fixtures/not_1.9.1/cassette_spec/with_localhost_requests.yml +86 -0
  63. data/spec/fixtures/not_1.9.1/example_net_http.yml +14 -0
  64. data/spec/fixtures/not_1.9.1/example_net_http_request.yml +12 -0
  65. data/spec/fixtures/not_1.9.1/example_net_http_response.yml +25 -0
  66. data/spec/fixtures/not_1.9.1/fake_example.com_responses.yml +106 -0
  67. data/spec/fixtures/not_1.9.1/match_requests_on.yml +185 -0
  68. data/spec/http_stubbing_adapters/fakeweb_spec.rb +35 -0
  69. data/spec/http_stubbing_adapters/webmock_spec.rb +35 -0
  70. data/spec/request_matcher_spec.rb +194 -0
  71. data/spec/spec_helper.rb +40 -0
  72. data/spec/structs_spec.rb +121 -0
  73. data/spec/support/disable_warnings.rb +12 -0
  74. data/spec/support/http_library_adapters.rb +272 -0
  75. data/spec/support/http_stubbing_adapter.rb +100 -0
  76. data/spec/support/pending_on_heroku.rb +14 -0
  77. data/spec/support/temp_cassette_library_dir.rb +16 -0
  78. data/spec/support/vcr_localhost_server.rb +53 -0
  79. data/spec/vcr_spec.rb +198 -0
  80. data/spec/version_spec.rb +11 -0
  81. data/vcr.gemspec +43 -0
  82. metadata +134 -73
  83. data/lib/vcr/http_stubbing_adapters/base.rb +0 -36
  84. data/lib/vcr/version.rbc +0 -572
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,27 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+ tags
16
+
17
+ ## PROJECT::GENERAL
18
+ coverage
19
+ coverage.data
20
+ rdoc
21
+ pkg
22
+
23
+ ## PROJECT::SPECIFIC
24
+ features/fixtures/vcr_cassettes/**/temp/
25
+ *.rbc
26
+ .bundle
27
+
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  #Changelog
2
2
 
3
+ ## 1.1.1 (August 26, 2010)
4
+
5
+ * Updated to use and require FakeWeb 1.3.0. It includes a fix for a bug related to multiple values for the
6
+ same response header.
7
+ * Use new `FakeWeb::Utility.request_uri_as_string` method rather than our own logic to construct a request uri.
8
+ * Use new `FakeWeb.allow_net_connect = /url regex/` feature to power the `ignore_localhost` VCR option rather
9
+ then toggling `FakeWeb.allow_net_connect` in our Net::HTTP extension.
10
+ * Optimized `VCR.http_stubbing_adapter.stub_requests` a bit.
11
+ * Changed the http stubbing adapters to be modules rather than classes. They should never be instantiated and
12
+ don't really hold state, so a module is more appropriate.
13
+ * Warn when FakeWeb or WebMock are a minor or major version number ahead of the required version, as the new
14
+ version isn't known to work with VCR.
15
+
3
16
  ## 1.1.0 (August 22, 2010)
4
17
 
5
18
  * Added `:match_requests_on` cassette option, which determines how VCR matches requests.
data/Gemfile ADDED
@@ -0,0 +1,24 @@
1
+ source :rubygems
2
+ gemspec
3
+
4
+ group :development do
5
+ # Our specs rely on something in rspec-core master that hasn't been released yet.
6
+ gem 'rspec-core', :git => 'git://github.com/rspec/rspec-core.git'
7
+ end
8
+
9
+ # Additional gems that are useful, but not required for development.
10
+ group :extras do
11
+ platforms :mri, :jruby do
12
+ gem 'rcov'
13
+ end
14
+
15
+ platforms :mri_18 do
16
+ gem 'ruby-debug'
17
+ end
18
+
19
+ platforms :mri_19 do
20
+ gem 'ruby-debug19'
21
+ gem 'ruby-debug-base19', '0.11.23'
22
+ end
23
+ end
24
+
data/Gemfile.lock ADDED
@@ -0,0 +1,119 @@
1
+ GIT
2
+ remote: git://github.com/rspec/rspec-core.git
3
+ revision: 6258abe
4
+ specs:
5
+ rspec-core (2.0.0.beta.20)
6
+
7
+ PATH
8
+ remote: .
9
+ specs:
10
+ vcr (1.1.1)
11
+
12
+ GEM
13
+ remote: http://rubygems.org/
14
+ specs:
15
+ addressable (2.2.0)
16
+ archive-tar-minitar (0.5.2)
17
+ builder (2.1.2)
18
+ capybara (0.3.9)
19
+ culerity (>= 0.2.4)
20
+ mime-types (>= 1.16)
21
+ nokogiri (>= 1.3.3)
22
+ rack (>= 1.0.0)
23
+ rack-test (>= 0.5.4)
24
+ selenium-webdriver (>= 0.0.3)
25
+ columnize (0.3.1)
26
+ crack (0.1.8)
27
+ cucumber (0.8.5)
28
+ builder (~> 2.1.2)
29
+ diff-lcs (~> 1.1.2)
30
+ gherkin (~> 2.1.4)
31
+ json_pure (~> 1.4.3)
32
+ term-ansicolor (~> 1.0.4)
33
+ culerity (0.2.12)
34
+ diff-lcs (1.1.2)
35
+ em-http-request (0.2.11)
36
+ addressable (>= 2.0.0)
37
+ eventmachine (>= 0.12.9)
38
+ eventmachine (0.12.10)
39
+ eventmachine (0.12.10-java)
40
+ fakeweb (1.3.0)
41
+ ffi (0.6.3)
42
+ rake (>= 0.8.7)
43
+ ffi (0.6.3-java)
44
+ gherkin (2.1.5)
45
+ trollop (~> 1.16.2)
46
+ gherkin (2.1.5-java)
47
+ trollop (~> 1.16.2)
48
+ httpclient (2.1.5.2)
49
+ json_pure (1.4.6)
50
+ linecache (0.43)
51
+ linecache19 (0.5.11)
52
+ ruby_core_source (>= 0.1.4)
53
+ mime-types (1.16)
54
+ nokogiri (1.4.3.1)
55
+ nokogiri (1.4.3.1-java)
56
+ weakling (>= 0.0.3)
57
+ patron (0.4.6)
58
+ rack (1.2.0)
59
+ rack-test (0.5.4)
60
+ rack (>= 1.0)
61
+ rake (0.8.7)
62
+ rcov (0.9.8)
63
+ rcov (0.9.8-java)
64
+ rspec (2.0.0.beta.20)
65
+ rspec-core (= 2.0.0.beta.20)
66
+ rspec-expectations (= 2.0.0.beta.20)
67
+ rspec-mocks (= 2.0.0.beta.20)
68
+ rspec-expectations (2.0.0.beta.20)
69
+ diff-lcs (>= 1.1.2)
70
+ rspec-mocks (2.0.0.beta.20)
71
+ ruby-debug (0.10.3)
72
+ columnize (>= 0.1)
73
+ ruby-debug-base (~> 0.10.3.0)
74
+ ruby-debug-base (0.10.3)
75
+ linecache (>= 0.3)
76
+ ruby-debug-base19 (0.11.23)
77
+ columnize (>= 0.3.1)
78
+ linecache19 (>= 0.5.11)
79
+ ruby_core_source (>= 0.1.4)
80
+ ruby-debug19 (0.11.6)
81
+ columnize (>= 0.3.1)
82
+ linecache19 (>= 0.5.11)
83
+ ruby-debug-base19 (>= 0.11.19)
84
+ ruby_core_source (0.1.4)
85
+ archive-tar-minitar (>= 0.5.2)
86
+ rubyzip (0.9.4)
87
+ selenium-webdriver (0.0.28)
88
+ ffi (>= 0.6.1)
89
+ json_pure
90
+ rubyzip
91
+ term-ansicolor (1.0.5)
92
+ trollop (1.16.2)
93
+ weakling (0.0.4-java)
94
+ webmock (1.3.3)
95
+ addressable (>= 2.1.1)
96
+ crack (>= 0.1.7)
97
+
98
+ PLATFORMS
99
+ java
100
+ ruby
101
+
102
+ DEPENDENCIES
103
+ bundler (~> 1.0.0.rc6)
104
+ capybara (~> 0.3.9)
105
+ cucumber (~> 0.8.5)
106
+ em-http-request (~> 0.2.7)
107
+ fakeweb (~> 1.3.0)
108
+ httpclient (~> 2.1.5.2)
109
+ patron (~> 0.4.6)
110
+ rack (= 1.2.0)
111
+ rake (~> 0.8.7)
112
+ rcov
113
+ rspec (~> 2.0.0.beta.20)
114
+ rspec-core!
115
+ ruby-debug
116
+ ruby-debug-base19 (= 0.11.23)
117
+ ruby-debug19
118
+ vcr!
119
+ webmock (= 1.3.3)
data/README.md CHANGED
@@ -55,7 +55,7 @@ maintenance) and accurate (the response from example.com will contain the same h
55
55
  * Simple cucumber integration is provided using tags.
56
56
  * Known to work well with many popular ruby libraries including RSpec, Cucumber, Test::Unit, Capybara, Mechanize and
57
57
  Rest-Client.
58
- * Extensively tested on 5 different ruby interpretters.
58
+ * Extensively tested on 6 different ruby interpretters.
59
59
 
60
60
  ## Development
61
61
 
@@ -283,10 +283,6 @@ additional features. You can see the
283
283
  [benchmarks](http://github.com/myronmarston/vcr/blob/master/benchmarks/http_stubbing_libraries.rb) for
284
284
  more details.
285
285
 
286
- Note that FakeWeb also currently has a bug that prevents it from properly dealing with multiple values
287
- for the same response header. See [this FakeWeb issue](http://github.com/chrisk/fakeweb/issues/17) for
288
- more info.
289
-
290
286
  You should not need to directly interact with either FakeWeb or WebMock. VCR will take care of disallowing
291
287
  http connections when no cassette is inserted, and it will clean up all stubs/registrations when a cassette
292
288
  is ejected. If you ever decide to switch HTTP stubbing libraries, you'll just have to update the VCR config
@@ -334,7 +330,8 @@ VCR has been tested on the following ruby interpreters:
334
330
  * MRI 1.8.6-p399
335
331
  * MRI 1.8.7-p302
336
332
  * MRI 1.9.1-p378
337
- * MRI 1.9.2
333
+ * MRI 1.9.2-p0
334
+ * REE 1.8.7-2010.02
338
335
  * JRuby 1.5.1
339
336
 
340
337
  ## Notes, etc.
data/Rakefile ADDED
@@ -0,0 +1,70 @@
1
+ require 'bundler'
2
+ require 'bundler/setup'
3
+ Bundler::GemHelper.install_tasks
4
+
5
+ require 'rake'
6
+ require "rspec/core/rake_task"
7
+
8
+ RSpec::Core::RakeTask.new(:spec) do |t|
9
+ #t.spec_opts = %w[--format documentation]
10
+ end
11
+
12
+ desc "Run all examples using rcov"
13
+ RSpec::Core::RakeTask.new :rcov => :cleanup_rcov_files do |t|
14
+ t.rcov = true
15
+ t.rcov_opts = %[-Ilib -Ispec --exclude "spec/*,gems/*" --text-report --sort coverage --aggregate coverage.data]
16
+ end
17
+
18
+ task :cleanup_rcov_files do
19
+ rm_rf 'coverage.data'
20
+ end
21
+
22
+ begin
23
+ permutations = {
24
+ 'fakeweb' => %w( net/http ),
25
+ 'webmock' => %w( net/http httpclient patron em-http-request )
26
+ }
27
+
28
+ require 'cucumber/rake/task'
29
+ namespace :features do
30
+ permutations.each do |http_stubbing_adapter, http_libraries|
31
+ features_subtasks = []
32
+
33
+ namespace http_stubbing_adapter do
34
+ http_libraries.each do |http_lib|
35
+ next if RUBY_PLATFORM =~ /java/ && %w( patron em-http-request ).include?(http_lib)
36
+
37
+ sanitized_http_lib = http_lib.gsub('/', '_')
38
+ features_subtasks << "features:#{http_stubbing_adapter}:#{sanitized_http_lib}"
39
+
40
+ task "#{sanitized_http_lib}_prep" do
41
+ ENV['HTTP_STUBBING_ADAPTER'] = http_stubbing_adapter
42
+ ENV['HTTP_LIB'] = http_lib
43
+ end
44
+
45
+ Cucumber::Rake::Task.new(
46
+ { sanitized_http_lib => "#{features_subtasks.last}_prep" },
47
+ "Run the features using #{http_stubbing_adapter} and #{http_lib}") do |t|
48
+ t.cucumber_opts = ['--format', 'progress', '--tags', "@#{http_stubbing_adapter},@all_http_libs,@#{sanitized_http_lib}"]
49
+
50
+ # disable scenarios on heroku that can't pass due to heroku's restrictions
51
+ t.cucumber_opts += ['--tags', '~@spawns_localhost_server'] if ENV.keys.include?('HEROKU_SLUG')
52
+ end
53
+ end
54
+ end
55
+
56
+ desc "Run the features using #{http_stubbing_adapter} and each of #{http_stubbing_adapter}'s supported http libraries"
57
+ task http_stubbing_adapter => features_subtasks
58
+ end
59
+ end
60
+
61
+ desc "Run the features using each supported permutation of http stubbing library and http library."
62
+ task :features => permutations.keys.map { |a| "features:#{a}" }
63
+ rescue LoadError
64
+ task :features do
65
+ abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
66
+ end
67
+ end
68
+
69
+ task :default => [:spec, :features]
70
+
@@ -0,0 +1,59 @@
1
+ require 'rubygems'
2
+ require 'benchmark'
3
+ require 'net/http'
4
+
5
+ def http_request
6
+ res = Net::HTTP.get_response(URI.parse('http://example.com'))
7
+ raise "Body should be 'Hello'" unless res.body == 'Hello'
8
+ end
9
+
10
+ def fakeweb
11
+ FakeWeb.register_uri(:get, 'http://example.com', :body => 'Hello')
12
+ yield
13
+ ensure
14
+ FakeWeb.clean_registry
15
+ end
16
+
17
+ def webmock
18
+ WebMock.stub_request(:get, 'http://example.com').to_return(:body => 'Hello')
19
+ yield
20
+ ensure
21
+ WebMock.reset_webmock
22
+ end
23
+
24
+ def perform_benchmark(name)
25
+ puts "\n\nBenchmarking #{name}:"
26
+ Benchmark.benchmark do |b|
27
+ %w(webmock fakeweb).each do |type|
28
+ b.report(type) do
29
+ # this is a bit convoluted, but we want to ensure that each benchmark runs without the other library loaded,
30
+ # so we fork off a sub-process before requiring the libraries.
31
+ Process.fork do
32
+ require type
33
+ yield type
34
+ end
35
+ Process.wait
36
+ end
37
+ end
38
+ end
39
+ end
40
+
41
+ n = 5000
42
+ perform_benchmark("Single setup/teardown") do |type|
43
+ send(type) { n.times { http_request } }
44
+ end
45
+
46
+ perform_benchmark("Setup/teardown for each http request") do |type|
47
+ n.times { send(type) { http_request } }
48
+ end
49
+
50
+ # Output on my machine:
51
+ #
52
+ # Benchmarking Single setup/teardown:
53
+ # webmock 0.000000 0.000000 5.870000 ( 6.211840)
54
+ # fakeweb 0.000000 0.000000 1.840000 ( 1.940935)
55
+ #
56
+ #
57
+ # Benchmarking Setup/teardown for each http request:
58
+ # webmock 0.000000 0.000000 7.710000 ( 7.776178)
59
+ # fakeweb 0.000000 0.000000 2.410000 ( 2.420550)
@@ -0,0 +1,43 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ :request: !ruby/struct:VCR::Request
4
+ :method: :get
5
+ :uri: !ruby/regexp /example\.com\/reg/
6
+ :body:
7
+ :headers:
8
+ :response: !ruby/struct:VCR::Response
9
+ :status: !ruby/struct:VCR::ResponseStatus
10
+ :code: 200
11
+ :message: OK
12
+ :headers:
13
+ server:
14
+ - Apache/2.2.3 (Red Hat)
15
+ last-modified:
16
+ - Tue, 15 Nov 2005 13:24:10 GMT
17
+ etag:
18
+ - "\"b300b4-1b6-4059a80bfd280\""
19
+ accept-ranges:
20
+ - bytes
21
+ content-type:
22
+ - text/html; charset=UTF-8
23
+ connection:
24
+ - Keep-Alive
25
+ date:
26
+ - Thu, 28 Jan 2010 07:14:48 GMT
27
+ age:
28
+ - "1696"
29
+ content-length:
30
+ - "438"
31
+ :body: |
32
+ <HTML>
33
+ <HEAD>
34
+ <TITLE>Example Web Page</TITLE>
35
+ </HEAD>
36
+ <body>
37
+ <p>
38
+ This is the response from the regex cassette
39
+ </p>
40
+ </BODY>
41
+ </HTML>
42
+
43
+ :http_version: "1.1"
@@ -0,0 +1,43 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ :request: !ruby/struct:VCR::Request
4
+ :method: :get
5
+ :uri: http://example.com:80/
6
+ :body:
7
+ :headers:
8
+ :response: !ruby/struct:VCR::Response
9
+ :status: !ruby/struct:VCR::ResponseStatus
10
+ :code: 200
11
+ :message: OK
12
+ :headers:
13
+ server:
14
+ - Apache/2.2.3 (Red Hat)
15
+ last-modified:
16
+ - Tue, 15 Nov 2005 13:24:10 GMT
17
+ etag:
18
+ - "\"b300b4-1b6-4059a80bfd280\""
19
+ accept-ranges:
20
+ - bytes
21
+ content-type:
22
+ - text/html; charset=UTF-8
23
+ connection:
24
+ - Keep-Alive
25
+ date:
26
+ - Thu, 28 Jan 2010 07:14:48 GMT
27
+ age:
28
+ - "1696"
29
+ content-length:
30
+ - "438"
31
+ :body: |
32
+ <HTML>
33
+ <HEAD>
34
+ <TITLE>Example Web Page</TITLE>
35
+ </HEAD>
36
+ <body>
37
+ <p>
38
+ This is not the real response from example.com
39
+ </p>
40
+ </BODY>
41
+ </HTML>
42
+
43
+ :http_version: "1.1"