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
@@ -1,4 +1,10 @@
1
1
  require 'forwardable'
2
+ require 'vcr/structs/normalizers/body'
3
+ require 'vcr/structs/normalizers/header'
4
+ require 'vcr/structs/normalizers/status_message'
5
+ require 'vcr/structs/normalizers/uri'
6
+ require 'vcr/structs/request'
7
+ require 'vcr/structs/response'
2
8
 
3
9
  module VCR
4
10
  class HTTPInteraction < Struct.new(:request, :response)
@@ -25,28 +31,28 @@ module VCR
25
31
  filter_object!(self, text, replacement_text)
26
32
  end
27
33
 
28
- private
34
+ private
29
35
 
30
- def filter_object!(object, text, replacement_text)
31
- if object.respond_to?(:gsub)
32
- object.gsub!(text, replacement_text) if object.include?(text)
33
- elsif Hash === object
34
- filter_hash!(object, text, replacement_text)
35
- elsif object.respond_to?(:each)
36
- # This handles nested arrays and structs
37
- object.each { |o| filter_object!(o, text, replacement_text) }
38
- end
39
-
40
- object
36
+ def filter_object!(object, text, replacement_text)
37
+ if object.respond_to?(:gsub)
38
+ object.gsub!(text, replacement_text) if object.include?(text)
39
+ elsif Hash === object
40
+ filter_hash!(object, text, replacement_text)
41
+ elsif object.respond_to?(:each)
42
+ # This handles nested arrays and structs
43
+ object.each { |o| filter_object!(o, text, replacement_text) }
41
44
  end
42
45
 
43
- def filter_hash!(hash, text, replacement_text)
44
- filter_object!(hash.values, text, replacement_text)
46
+ object
47
+ end
48
+
49
+ def filter_hash!(hash, text, replacement_text)
50
+ filter_object!(hash.values, text, replacement_text)
45
51
 
46
- hash.keys.each do |k|
47
- new_key = filter_object!(k.dup, text, replacement_text)
48
- hash[new_key] = hash.delete(k) unless k == new_key
49
- end
52
+ hash.keys.each do |k|
53
+ new_key = filter_object!(k.dup, text, replacement_text)
54
+ hash[new_key] = hash.delete(k) unless k == new_key
50
55
  end
56
+ end
51
57
  end
52
58
  end
@@ -6,7 +6,7 @@ module VCR
6
6
  normalize_body
7
7
  end
8
8
 
9
- private
9
+ private
10
10
 
11
11
  def normalize_body
12
12
  # Ensure that the body is a raw string, in case the string instance
@@ -17,7 +17,7 @@ module VCR
17
17
  normalize_headers
18
18
  end
19
19
 
20
- private
20
+ private
21
21
 
22
22
  def important_header_values(k, values)
23
23
  skip_values = HEADERS_TO_SKIP[k] || []
@@ -6,7 +6,7 @@ module VCR
6
6
  normalize_status_message
7
7
  end
8
8
 
9
- private
9
+ private
10
10
 
11
11
  def normalize_status_message
12
12
  self.message = message.strip if message
@@ -11,7 +11,7 @@ module VCR
11
11
  normalize_uri
12
12
  end
13
13
 
14
- private
14
+ private
15
15
 
16
16
  def normalize_uri
17
17
  u = begin
@@ -4,23 +4,10 @@ module VCR
4
4
  include Normalizers::URI
5
5
  include Normalizers::Body
6
6
 
7
- def self.from_net_http_request(net_http, request)
8
- new(
9
- request.method.downcase.to_sym,
10
- VCR.http_stubbing_adapter.request_uri(net_http, request),
11
- request.body,
12
- request.to_hash
13
- )
14
- end
15
-
16
7
  @@object_method = Object.instance_method(:method)
17
8
  def method(*args)
18
9
  return super if args.empty?
19
10
  @@object_method.bind(self).call(*args)
20
11
  end
21
-
22
- def matcher(match_attributes)
23
- RequestMatcher.new(self, match_attributes)
24
- end
25
12
  end
26
13
  end
@@ -1,17 +1,10 @@
1
+ require 'vcr/structs/response_status'
2
+
1
3
  module VCR
2
4
  class Response < Struct.new(:status, :headers, :body, :http_version)
3
5
  include Normalizers::Header
4
6
  include Normalizers::Body
5
7
 
6
- def self.from_net_http_response(response)
7
- new(
8
- ResponseStatus.from_net_http_response(response),
9
- response.to_hash,
10
- response.body,
11
- response.http_version
12
- )
13
- end
14
-
15
8
  def update_content_length_header
16
9
  headers['content-length'] &&= [body ? body.length.to_s : '0']
17
10
  end
@@ -1,9 +1,5 @@
1
1
  module VCR
2
2
  class ResponseStatus < Struct.new(:code, :message)
3
3
  include Normalizers::StatusMessage
4
-
5
- def self.from_net_http_response(response)
6
- new(response.code.to_i, response.message)
7
- end
8
4
  end
9
5
  end
@@ -18,7 +18,7 @@ module VCR
18
18
  def tags(*tag_names)
19
19
  options = tag_names.last.is_a?(::Hash) ? tag_names.pop : {}
20
20
  tag_names.each do |tag_name|
21
- tag_name = "@#{tag_name}" unless tag_name =~ /^@/
21
+ tag_name = "@#{tag_name}" unless tag_name =~ /\A@/
22
22
  cassette_name = "cucumber_tags/#{tag_name.gsub(/\A@/, '')}"
23
23
 
24
24
  # It would be nice to use an Around hook here, but
@@ -14,7 +14,7 @@ module VCR
14
14
  end
15
15
  end
16
16
 
17
- private
17
+ private
18
18
 
19
19
  def infer_cassette_name
20
20
  # RSpec 1 exposes #description_parts; use that if its available
@@ -2,7 +2,11 @@ module VCR
2
2
  module Hooks
3
3
  include VariableArgsBlockCaller
4
4
 
5
- def invoke_hook(hook, tag, *args)
5
+ def self.included(klass)
6
+ klass.extend(ClassMethods)
7
+ end
8
+
9
+ def invoke_hook(hook, tag=nil, *args)
6
10
  hooks_for(hook, tag).each do |callback|
7
11
  call_block(callback, *args)
8
12
  end
@@ -12,31 +16,36 @@ module VCR
12
16
  hooks.clear
13
17
  end
14
18
 
15
- private
19
+ private
16
20
 
17
- def hooks
18
- @hooks ||= Hash.new do |hook_type_hash, hook_type|
19
- hook_type_hash[hook_type] = Hash.new do |tag_hash, tag|
20
- tag_hash[tag] = []
21
- end
21
+ def hooks
22
+ @hooks ||= Hash.new do |hook_type_hash, hook_type|
23
+ hook_type_hash[hook_type] = Hash.new do |tag_hash, tag|
24
+ tag_hash[tag] = []
22
25
  end
23
26
  end
27
+ end
24
28
 
29
+ def hooks_for(hook, tag)
30
+ for_hook = hooks[hook]
31
+ hooks = for_hook[tag] # matching tagged hooks
32
+ hooks += for_hook[nil] unless tag.nil? # untagged hooks
33
+ hooks
34
+ end
35
+
36
+ module ClassMethods
25
37
  def define_hook(hook)
26
- # We must use string eval so that the dynamically
27
- # defined method can accept a block.
28
- instance_eval <<-RUBY, __FILE__, __LINE__ + 1
29
- def #{hook}(tag = nil, &block)
30
- hooks[#{hook.inspect}][tag] << block
38
+ # We use splat args here because 1.8.7 doesn't allow default
39
+ # values for block arguments, so we have to fake it.
40
+ define_method hook do |*args, &block|
41
+ if args.size > 1
42
+ raise ArgumentError.new("wrong number of arguments (#{args.size} for 1)")
31
43
  end
32
- RUBY
33
- end
34
44
 
35
- def hooks_for(hook, tag)
36
- for_hook = hooks[hook]
37
- hooks = for_hook[tag] # matching tagged hooks
38
- hooks += for_hook[nil] unless tag.nil? # untagged hooks
39
- hooks
45
+ tag = args.first
46
+ hooks[hook][tag] << block
47
+ end
40
48
  end
49
+ end
41
50
  end
42
51
  end
@@ -1,6 +1,32 @@
1
- require 'vcr/util/ping'
2
-
3
1
  module VCR
2
+ # Ruby 1.8 provides Ping.pingecho, but it was removed in 1.9.
3
+ # So we try requiring it, and if that fails, define it ourselves.
4
+ begin
5
+ require 'ping'
6
+ Ping = ::Ping
7
+ rescue LoadError
8
+ # This is copied, verbatim, from Ruby 1.8.7's ping.rb.
9
+ require 'timeout'
10
+ require "socket"
11
+
12
+ module Ping
13
+ def pingecho(host, timeout=5, service="echo")
14
+ begin
15
+ timeout(timeout) do
16
+ s = TCPSocket.new(host, service)
17
+ s.close
18
+ end
19
+ rescue Errno::ECONNREFUSED
20
+ return true
21
+ rescue Timeout::Error, StandardError
22
+ return false
23
+ end
24
+ return true
25
+ end
26
+ module_function :pingecho
27
+ end
28
+ end
29
+
4
30
  module InternetConnection
5
31
  extend self
6
32
 
@@ -12,3 +38,4 @@ module VCR
12
38
  end
13
39
  end
14
40
  end
41
+
@@ -0,0 +1,60 @@
1
+ module VCR
2
+ class VersionChecker
3
+ def initialize(library_name, library_version, min_patch_level, max_minor_version)
4
+ @library_name, @library_version = library_name, library_version
5
+ @min_patch_level, @max_minor_version = min_patch_level, max_minor_version
6
+
7
+ @major, @minor, @patch = parse_version(library_version)
8
+ @min_major, @min_minor, @min_patch = parse_version(min_patch_level)
9
+ @max_major, @max_minor = parse_version(max_minor_version)
10
+
11
+ @comparison_result = compare_version
12
+ end
13
+
14
+ def check_version!
15
+ raise_too_low_error if too_low?
16
+ warn_about_too_high if too_high?
17
+ end
18
+
19
+ private
20
+
21
+ def too_low?
22
+ @comparison_result == :too_low
23
+ end
24
+
25
+ def too_high?
26
+ @comparison_result == :too_high
27
+ end
28
+
29
+ def raise_too_low_error
30
+ raise Errors::LibraryVersionTooLowError,
31
+ "You are using #{@library_name} #{@library_version}. " +
32
+ "VCR requires version #{version_requirement}."
33
+ end
34
+
35
+ def warn_about_too_high
36
+ Kernel.warn "You are using #{@library_name} #{@library_version}. " +
37
+ "VCR is known to work with #{@library_name} #{version_requirement}. " +
38
+ "It may not work with this version."
39
+ end
40
+
41
+ def compare_version
42
+ case
43
+ when @major < @min_major then :too_low
44
+ when @major > @max_major then :too_high
45
+ when @minor < @min_minor then :too_low
46
+ when @minor > @max_minor then :too_high
47
+ when @patch < @min_patch then :too_low
48
+ end
49
+ end
50
+
51
+ def version_requirement
52
+ ">= #{@min_patch_level}, < #{@max_major}.#{@max_minor + 1}"
53
+ end
54
+
55
+ def parse_version(version)
56
+ version.split('.').map { |v| v.to_i }
57
+ end
58
+ end
59
+ end
60
+
data/lib/vcr/version.rb CHANGED
@@ -3,7 +3,7 @@ module VCR
3
3
 
4
4
  def version
5
5
  @version ||= begin
6
- string = '1.11.3'
6
+ string = '2.0.0.beta1'
7
7
 
8
8
  def string.parts
9
9
  split('.').map { |p| p.to_i }
@@ -37,13 +37,6 @@ task :print_ruby_description do
37
37
  end
38
38
 
39
39
  task :bundle_install => :ensure_bundler_installed do
40
- # Unfortunately, there is no version of ruby-debug that installs cleanly on 1.9.1 and 1.9.2.
41
- # Our Gemfile specifies different versions using conditionals, but we still need to bundle update
42
- # to get bundler to use the different versions.
43
- if RUBY_VERSION =~ /^1\.9/
44
- sh "bundle update ruby-debug-base19"
45
- end
46
-
47
40
  sh "bundle install"
48
41
  end
49
42
 
data/script/full_build CHANGED
@@ -1 +1 @@
1
- rvm 1.8.6,1.8.7,1.9.1,1.9.2,ree,rbx rake -f script/FullBuildRakeFile build | tee tmp/full_build.out
1
+ rvm 1.8.7,1.9.2,ree,rbx rake -f script/FullBuildRakeFile build | tee tmp/full_build.out
@@ -3,40 +3,45 @@ stderr_file = Tempfile.new("vcr.stderr")
3
3
  $stderr.reopen(stderr_file.path)
4
4
  current_dir = Dir.pwd
5
5
 
6
- at_exit do
7
- stderr_file.rewind
8
- lines = stderr_file.read.split("\n").uniq
9
- stderr_file.close!
10
-
11
- vcr_warnings, other_warnings = lines.partition { |line| line.include?(current_dir) }
12
-
13
- # For some weird reason, JRuby is giving me some warnings about
14
- # `@proxy` not being initialized, and putting a vcr file/line number
15
- # in the warning, but it's really happening in excon.
16
- if RUBY_PLATFORM == 'java'
17
- vcr_warnings.reject! do |line|
18
- line.include?('@proxy not initialized') && line.include?('excon')
6
+ require 'rubygems' if RUBY_VERSION =~ /^1\.8/
7
+ require 'rspec/core'
8
+
9
+ RSpec.configure do |config|
10
+ config.after(:suite) do
11
+ stderr_file.rewind
12
+ lines = stderr_file.read.split("\n").uniq
13
+ stderr_file.close!
14
+
15
+ vcr_warnings, other_warnings = lines.partition { |line| line.include?(current_dir) }
16
+
17
+ # For some weird reason, JRuby is giving me some warnings about
18
+ # `@proxy` not being initialized, and putting a vcr file/line number
19
+ # in the warning, but it's really happening in excon.
20
+ if RUBY_PLATFORM == 'java'
21
+ vcr_warnings.reject! do |line|
22
+ line.include?('@proxy not initialized') && line.include?('excon')
23
+ end
19
24
  end
20
- end
21
25
 
22
- if vcr_warnings.any?
23
- puts
24
- puts "-" * 30 + " VCR Warnings: " + "-" * 30
25
- puts
26
- puts vcr_warnings.join("\n")
27
- puts
28
- puts "-" * 75
29
- puts
30
- end
26
+ if vcr_warnings.any?
27
+ puts
28
+ puts "-" * 30 + " VCR Warnings: " + "-" * 30
29
+ puts
30
+ puts vcr_warnings.join("\n")
31
+ puts
32
+ puts "-" * 75
33
+ puts
34
+ end
31
35
 
32
- if other_warnings.any?
33
- File.open('tmp/warnings.txt', 'w') { |f| f.write(other_warnings.join("\n")) }
34
- puts
35
- puts "Non-VCR warnings written to tmp/warnings.txt"
36
- puts
37
- end
36
+ if other_warnings.any?
37
+ File.open('tmp/warnings.txt', 'w') { |f| f.write(other_warnings.join("\n")) }
38
+ puts
39
+ puts "Non-VCR warnings written to tmp/warnings.txt"
40
+ puts
41
+ end
38
42
 
39
- # fail the build...
40
- exit(1) if vcr_warnings.any?
43
+ # fail the build...
44
+ raise "Failing build due to VCR warnings" if vcr_warnings.any?
45
+ end
41
46
  end
42
47