Permalink
Browse files

Add test coverage for Curb support.

  • Loading branch information...
myronmarston committed Oct 5, 2010
1 parent a736ec6 commit ea777b9328f97e7ed090630183a9639e2d008abb
Showing with 41 additions and 5 deletions.
  1. +2 −0 CHANGELOG.md
  2. +1 −0 README.md
  3. +2 −2 Rakefile
  4. +1 −1 spec/http_stubbing_adapters/webmock_spec.rb
  5. +6 −2 spec/spec_helper.rb
  6. +29 −0 spec/support/http_library_adapters.rb
View
@@ -12,6 +12,8 @@
WebMock is used, and relies upon WebMock's after_request callback to record Net::HTTP instead. This
fixes [a bug](http://github.com/myronmarston/vcr/issues/14) when using WebMock and Open URI.
* Consider 0.0.0.0 to be a localhost alias (previously only "localhost" and 127.0.0.1 were considered).
+* Added spec and feature coverage for Curb integration. Works out of the box with no changes required
+ to VCR due to [Pete Higgins](http://github.com/phiggins) great work to add Curb support to WebMock.
## 1.1.2 (September 9, 2010)
View
@@ -45,6 +45,7 @@ maintenance) and accurate (the response from example.com will contain the same h
is easy to implement for any future libraries.
* Supports multiple HTTP libraries: [Net::HTTP](http://www.ruby-doc.org/stdlib/libdoc/net/http/rdoc/index.html)
(all HTTP stubbing libraries), [Patron](http://github.com/toland/patron) (WebMock only),
+ [Curb](http://github.com/taf2/curb) (WebMock only),
[HTTPClient](http://github.com/nahi/httpclient) (WebMock only) and
[em-http-request](http://github.com/igrigorik/em-http-request) (WebMock only).
* Request matching is configurable based on HTTP method, URI, host, path, body and headers.
View
@@ -21,7 +21,7 @@ end
permutations = {
'fakeweb' => %w( net/http ),
- 'webmock' => %w( net/http httpclient patron em-http-request )
+ 'webmock' => %w( net/http httpclient patron em-http-request curb )
}
require 'cucumber/rake/task'
@@ -31,7 +31,7 @@ namespace :features do
namespace http_stubbing_adapter do
http_libraries.each do |http_lib|
- next if RUBY_PLATFORM =~ /java/ && %w( patron em-http-request ).include?(http_lib)
+ next if RUBY_PLATFORM == 'java' && %w( patron em-http-request curb ).include?(http_lib)
sanitized_http_lib = http_lib.gsub('/', '_')
features_subtasks << "features:#{http_stubbing_adapter}:#{sanitized_http_lib}"
@@ -4,7 +4,7 @@
without_monkey_patches :vcr
it_should_behave_like 'an http stubbing adapter',
- %w[net/http patron httpclient em-http-request],
+ %w[net/http patron httpclient em-http-request curb],
[:method, :uri, :host, :path, :body, :headers]
describe '#check_version!' do
View
@@ -4,9 +4,13 @@
require 'monkey_patches'
-require 'patron' unless RUBY_PLATFORM =~ /java/
require 'httpclient'
-require 'em-http-request' unless RUBY_PLATFORM =~ /java/
+unless RUBY_PLATFORM == 'java'
+ require 'patron'
+ require 'em-http-request'
+ require 'curb'
+end
+
require 'vcr'
require 'vcr/http_stubbing_adapters/webmock'
require 'vcr/http_stubbing_adapters/fakeweb'
@@ -67,6 +67,35 @@ def make_http_request(method, url, body = nil, headers = {})
end
end
+HTTP_LIBRARY_ADAPTERS['curb'] = Module.new do
+ def self.http_library_name; "Curb"; end
+
+ def get_body_string(response)
+ response.body_str
+ end
+
+ def get_header(header_key, response)
+ headers = response.header_str.split("\r\n")[1..-1]
+ headers.each do |h|
+ if h =~ /^#{Regexp.escape(header_key)}: (.*)$/
+ return $1.split(', ')
+ end
+ end
+ end
+
+ def make_http_request(method, url, body = nil, headers = {})
+ Curl::Easy.new(url) do |c|
+ c.headers = headers
+ case method
+ when :get then c.http_get
+ when :post then c.http_post(body)
+ when :put then c.http_put(body)
+ when :delete then c.http_delete
+ end
+ end
+ end
+end
+
NET_CONNECT_NOT_ALLOWED_ERROR = /You can use VCR to automatically record this request and replay it later/
module HttpLibrarySpecs

0 comments on commit ea777b9

Please sign in to comment.