module WebMock

This is a copy of github.com/jnunemaker/crack/blob/master/lib/crack/json.rb with date parsing removed Copyright © 2004-2008 David Heinemeier Hansson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Constants

VERSION

Public Class Methods

after_request(options={}, &block) click to toggle source
# File lib/webmock/webmock.rb, line 104
def self.after_request(options={}, &block)
  WebMock::CallbackRegistry.add_callback(options, block)
end
allow_net_connect!(options = {}) click to toggle source
# File lib/webmock/webmock.rb, line 44
def self.allow_net_connect!(options = {})
  Config.instance.allow_net_connect = true
  Config.instance.net_http_connect_on_start = options[:net_http_connect_on_start]
end
disable!(options = {}) click to toggle source
# File lib/webmock/webmock.rb, line 28
def self.disable!(options = {})
  except = [options[:except]].flatten.compact
  HttpLibAdapterRegistry.instance.each_adapter do |name, adapter|
    adapter.enable!
    adapter.disable! unless except.include?(name)
  end
end
disable_net_connect!(options = {}) click to toggle source
# File lib/webmock/webmock.rb, line 49
def self.disable_net_connect!(options = {})
  Config.instance.allow_net_connect = false
  Config.instance.allow_localhost = options[:allow_localhost]
  Config.instance.allow = options[:allow]
  Config.instance.net_http_connect_on_start = options[:net_http_connect_on_start]
end
enable!(options = {}) click to toggle source
# File lib/webmock/webmock.rb, line 36
def self.enable!(options = {})
  except = [options[:except]].flatten.compact
  HttpLibAdapterRegistry.instance.each_adapter do |name, adapter|
    adapter.disable!
    adapter.enable! unless except.include?(name)
  end
end
globally_stub_request(&block) click to toggle source
# File lib/webmock/webmock.rb, line 116
def self.globally_stub_request(&block)
  WebMock::StubRegistry.instance.register_global_stub(&block)
end
hide_stubbing_instructions!() click to toggle source
# File lib/webmock/webmock.rb, line 78
def self.hide_stubbing_instructions!
  Config.instance.show_stubbing_instructions = false
end
included(clazz) click to toggle source
# File lib/webmock/webmock.rb, line 3
def self.included(clazz)
  WebMock::Deprecation.warning("include WebMock is deprecated. Please include WebMock::API instead")
  if clazz.instance_methods.map(&:to_s).include?('request')
    warn "WebMock#request was not included in #{clazz} to avoid name collision"
  else
    clazz.class_eval do
      def request(method, uri)
        WebMock::Deprecation.warning("WebMock#request is deprecated. Please use WebMock::API#a_request method instead")
        WebMock.a_request(method, uri)
      end
    end
  end
end
net_connect_allowed?(uri = nil) click to toggle source
# File lib/webmock/webmock.rb, line 56
def self.net_connect_allowed?(uri = nil)
  if uri.is_a?(String)
    uri = WebMock::Util::URI.normalize_uri(uri)
  end

  Config.instance.allow_net_connect ||
  ( Config.instance.allow_localhost && WebMock::Util::URI.is_uri_localhost?(uri) ||
    Config.instance.allow && net_connect_explicit_allowed?(Config.instance.allow, uri) )
end
net_connect_explicit_allowed?(allowed, uri=nil) click to toggle source
# File lib/webmock/webmock.rb, line 66
def self.net_connect_explicit_allowed?(allowed, uri=nil)
  case allowed
  when Array
    allowed.any? { |allowed_item| net_connect_explicit_allowed?(allowed_item, uri) }
  when Regexp
    uri.to_s =~ allowed
  when String
    allowed == uri.host ||
    allowed == "#{uri.host}:#{uri.port}"
  end
end
print_executed_requests() click to toggle source
registered_request?(request_signature) click to toggle source
# File lib/webmock/webmock.rb, line 108
def self.registered_request?(request_signature)
  WebMock::StubRegistry.instance.registered_request?(request_signature)
end
reset!() click to toggle source
# File lib/webmock/webmock.rb, line 90
def self.reset!
  WebMock::RequestRegistry.instance.reset!
  WebMock::StubRegistry.instance.reset!
end
reset_callbacks() click to toggle source
# File lib/webmock/webmock.rb, line 100
def self.reset_callbacks
  WebMock::CallbackRegistry.reset
end
reset_webmock() click to toggle source
# File lib/webmock/webmock.rb, line 95
def self.reset_webmock
  WebMock::Deprecation.warning("WebMock.reset_webmock is deprecated. Please use WebMock.reset! method instead")
  reset!
end
show_stubbing_instructions!() click to toggle source
# File lib/webmock/webmock.rb, line 82
def self.show_stubbing_instructions!
  Config.instance.show_stubbing_instructions = true
end
show_stubbing_instructions?() click to toggle source
# File lib/webmock/webmock.rb, line 86
def self.show_stubbing_instructions?
  Config.instance.show_stubbing_instructions
end
version() click to toggle source
# File lib/webmock/webmock.rb, line 24
def self.version
  VERSION
end

Public Instance Methods

request(method, uri) click to toggle source
# File lib/webmock/webmock.rb, line 9
def request(method, uri)
  WebMock::Deprecation.warning("WebMock#request is deprecated. Please use WebMock::API#a_request method instead")
  WebMock.a_request(method, uri)
end