Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

WebMock module has to be included manually and is not included by RSp…

…ec or Test::Unit adapters (this time correctly)
  • Loading branch information...
commit 3ca443e887b77b41a850f25ca9ef2b25725ad9b3 1 parent 95e8298
Bartosz Blimke authored
View
5 README.md
@@ -32,6 +32,11 @@ or if you use RSpec add these lines to `spec/spec_helper`:
include WebMock
+And add these lines if you want to use WebMock without RSpec or Test::Unit support:
+
+ require 'webmock'
+
+ include WebMock
## Examples
View
2  lib/webmock.rb
@@ -1,6 +1,5 @@
require 'singleton'
-require 'rubygems'
require 'addressable/uri'
require 'webmock/http_lib_adapters/net_http'
@@ -17,7 +16,6 @@
require 'webmock/response'
require 'webmock/request_execution_verifier'
-require 'webmock/utility'
require 'webmock/config'
require 'webmock/request_registry'
require 'webmock/webmock'
View
3  lib/webmock/adapters/test_unit.rb
@@ -2,10 +2,9 @@
require 'webmock'
class Test::Unit::TestCase
- include WebMock
alias setup_without_webmock setup
def setup
- reset_webmock
+ WebMock.reset_webmock
@original_allow_net_connect = WebMock.net_connect_allowed?
WebMock.disable_net_connect!
end
View
2  lib/webmock/request_stub.rb
@@ -10,7 +10,7 @@ def initialize(method, uri)
def with(params)
@request_profile.body = params[:body]
- @request_profile.headers = Utility.normalize_headers(params[:headers])
+ @request_profile.headers = Util::Headers.normalize_headers(params[:headers])
self
end
View
2  lib/webmock/response.rb
@@ -6,7 +6,7 @@ def initialize(options = {})
end
def headers
- Utility.normalize_headers(@options[:headers])
+ Util::Headers.normalize_headers(@options[:headers])
end
def body
View
11 lib/webmock/webmock.rb
@@ -1,4 +1,5 @@
module WebMock
+ extend self
def stub_request(method, uri)
RequestRegistry.instance.register_request_stub(RequestStub.new(method, uri))
@@ -23,23 +24,23 @@ def assert_not_requested(method, uri, options = {})
assertion_failure(verifier.negative_failure_message) unless verifier.does_not_match?
end
- def self.allow_net_connect!
+ def allow_net_connect!
Config.instance.allow_net_connect = true
end
- def self.disable_net_connect!
+ def disable_net_connect!
Config.instance.allow_net_connect = false
end
- def self.net_connect_allowed?
+ def net_connect_allowed?
Config.instance.allow_net_connect
end
- def self.registered_request?(request_signature)
+ def registered_request?(request_signature)
RequestRegistry.instance.registered_request?(request_signature)
end
- def self.response_for_request(request_signature, &block)
+ def response_for_request(request_signature, &block)
RequestRegistry.instance.response_for_request(request_signature, &block)
end
View
2  spec/net_http_spec.rb
@@ -2,8 +2,6 @@
require 'webmock_spec'
require 'ostruct'
-include WebMock
-
def http_request(method, uri, options = {})
begin
uri = URI.parse(uri)
View
4 spec/other_net_http_libs_spec.rb
@@ -3,7 +3,9 @@
describe "loading other Net::HTTP based libraries" do
def capture_output_from_requiring(libs, additional_code = "")
- requires = libs.map { |lib| "require '#{lib}'" }.join("; ")
+ requires = libs.map { |lib| "require '#{lib}'" }
+ requires << " require 'addressable/uri'"
+ requires = requires.join("; ")
webmock_dir = "#{File.dirname(__FILE__)}/../lib"
vendor_dirs = Dir["#{File.dirname(__FILE__)}/vendor/*/lib"]
load_path_opts = vendor_dirs.unshift(webmock_dir).map { |dir| "-I#{dir}" }.join(" ")
View
2  spec/request_stub_spec.rb
@@ -23,7 +23,7 @@
end
it "should assign normalized headers to request profile" do
- Utility.should_receive(:normalize_headers).with('A' => 'a').and_return('B' => 'b')
+ Util::Headers.should_receive(:normalize_headers).with('A' => 'a').and_return('B' => 'b')
@request_stub.with(:headers => {'A' => 'a'})
@request_stub.request_profile.headers.should == {'B' => 'b'}
end
View
2  spec/response_spec.rb
@@ -6,7 +6,7 @@
end
it "should report normalized headers" do
- Utility.should_receive(:normalize_headers).with('A' => 'a').and_return('B' => 'b')
+ Util::Headers.should_receive(:normalize_headers).with('A' => 'a').and_return('B' => 'b')
@response.headers.should == {'B' => 'b'}
end
View
3  spec/spec_helper.rb
@@ -1,9 +1,8 @@
$LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
-require 'webmock'
require 'spec'
require 'spec/autorun'
-require 'addressable/uri'
+require 'rubygems'
require 'webmock/rspec'
View
8 spec/vendor/addressable/lib/addressable/uri.rb
@@ -0,0 +1,8 @@
+module Addressable
+ class URI
+ module CharacterClasses
+ UNRESERVED = "123"
+ SUB_DELIMS = "123"
+ end
+ end
+end
View
0  spec/vendor/addressable/lib/uri.rb
No changes.
View
2  spec/webmock_spec.rb
@@ -1,7 +1,5 @@
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
-include WebMock
-
SAMPLE_HEADERS = { "Content-Length" => "8888" }
ESCAPED_PARAMS = "x=ab%2Bc&z=%27Stop%21%27%20said%20Fred"
NOT_ESCAPED_PARAMS = "z='Stop!' said Fred&x=ab c"
View
4 test/test_helper.rb
@@ -1,7 +1,11 @@
+require 'rubygems'
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
+
require 'webmock/test_unit'
require 'test/unit'
+include WebMock
def assert_fail(message, &block)
e = assert_raise(Test::Unit::AssertionFailedError, &block)
Please sign in to comment.
Something went wrong with that request. Please try again.