Permalink
Browse files

Moved all WebMock instance methods to WebMock::API module and depreca…

…ted inclusion of WebMock module.
  • Loading branch information...
bblimke committed Oct 10, 2010
1 parent 4cdf18c commit 08d6cce4da41443d4cc5630214d873939724abec
Showing with 51 additions and 33 deletions.
  1. +4 −4 README.md
  2. +1 −0 lib/webmock.rb
  3. +32 −0 lib/webmock/api.rb
  4. +12 −27 lib/webmock/webmock.rb
  5. +1 −1 spec/spec_helper.rb
  6. +1 −1 test/test_helper.rb
View
@@ -34,7 +34,7 @@ Add the following code to `test/test_helper.rb`
require 'webmock/test_unit'
class Test::Unit::TestCase
- include WebMock
+ include WebMock::API
end
### RSpec
@@ -44,7 +44,7 @@ Add the following code to `spec/spec_helper`:
require 'webmock/rspec'
Spec::Runner.configure do |config|
- config.include WebMock
+ config.include WebMock::API
end
### RSpec 2
@@ -54,7 +54,7 @@ Add the following code to `spec/spec_helper`:
require 'webmock/rspec'
RSpec.configure do |config|
- config.include WebMock
+ config.include WebMock::API
end
### Cucumber
@@ -67,7 +67,7 @@ Add the following code to `features/support/env.rb`
You can also use WebMock outside a test framework:
require 'webmock'
- include WebMock
+ include WebMock::API
include WebMock::Matchers
## Examples
View
@@ -26,4 +26,5 @@
require 'webmock/config'
require 'webmock/callback_registry'
require 'webmock/request_registry'
+require 'webmock/api'
require 'webmock/webmock'
View
@@ -0,0 +1,32 @@
+module WebMock
+ module API
+ extend self
+
+ def stub_request(method, uri)
+ WebMock::RequestRegistry.instance.register_request_stub(WebMock::RequestStub.new(method, uri))
+ end
+
+ alias_method :stub_http_request, :stub_request
+
+ def a_request(method, uri)
+ WebMock::RequestPattern.new(method, uri)
+ end
+
+ class << self
+ alias :request :a_request
+ end
+
+ def assert_requested(method, uri, options = {}, &block)
+ expected_times_executed = options.delete(:times) || 1
+ request = WebMock::RequestPattern.new(method, uri, options).with(&block)
+ verifier = WebMock::RequestExecutionVerifier.new(request, expected_times_executed)
+ WebMock::AssertionFailure.failure(verifier.failure_message) unless verifier.matches?
+ end
+
+ def assert_not_requested(method, uri, options = {}, &block)
+ request = WebMock::RequestPattern.new(method, uri, options).with(&block)
+ verifier = WebMock::RequestExecutionVerifier.new(request, options.delete(:times))
+ WebMock::AssertionFailure.failure(verifier.negative_failure_message) unless verifier.does_not_match?
+ end
+ end
+end
View
@@ -1,37 +1,22 @@
module WebMock
- extend self
-
- def self.version
- open(File.join(File.dirname(__FILE__), '../../VERSION')) { |f|
- f.read.strip
- }
- end
-
- def stub_request(method, uri)
- RequestRegistry.instance.register_request_stub(RequestStub.new(method, uri))
+
+ def self.included(clazz)
+ $stderr.puts "include WebMock is deprecated. Please include WebMock::API instead"
end
+
+ extend self
- alias_method :stub_http_request, :stub_request
-
- def a_request(method, uri)
- RequestPattern.new(method, uri)
- end
+ include WebMock::API
+ extend WebMock::API
class << self
alias :request :a_request
end
-
- def assert_requested(method, uri, options = {}, &block)
- expected_times_executed = options.delete(:times) || 1
- request = RequestPattern.new(method, uri, options).with(&block)
- verifier = RequestExecutionVerifier.new(request, expected_times_executed)
- WebMock::AssertionFailure.failure(verifier.failure_message) unless verifier.matches?
- end
-
- def assert_not_requested(method, uri, options = {}, &block)
- request = RequestPattern.new(method, uri, options).with(&block)
- verifier = RequestExecutionVerifier.new(request, options.delete(:times))
- WebMock::AssertionFailure.failure(verifier.negative_failure_message) unless verifier.does_not_match?
+
+ def self.version
+ open(File.join(File.dirname(__FILE__), '../../VERSION')) { |f|
+ f.read.strip
+ }
end
def self.allow_net_connect!
View
@@ -16,7 +16,7 @@
require 'json'
Spec::Runner.configure do |config|
- config.include WebMock
+ config.include WebMock::API
end
def fail()
View
@@ -7,7 +7,7 @@
require 'test/unit'
class Test::Unit::TestCase
- include WebMock
+ include WebMock::API
AssertionFailedError = Test::Unit::AssertionFailedError rescue MiniTest::Assertion
def assert_fail(message, &block)
e = assert_raise(AssertionFailedError, &block)

0 comments on commit 08d6cce

Please sign in to comment.