Module: WebMock

Extended by:
API
Includes:
API
Defined in:
lib/webmock/util/json.rb,
lib/webmock/api.rb,
lib/webmock/errors.rb,
lib/webmock/config.rb,
lib/webmock/version.rb,
lib/webmock/webmock.rb,
lib/webmock/response.rb,
lib/webmock/util/uri.rb,
lib/webmock/deprecation.rb,
lib/webmock/request_stub.rb,
lib/webmock/util/headers.rb,
lib/webmock/rack_response.rb,
lib/webmock/stub_registry.rb,
lib/webmock/rspec/matchers.rb,
lib/webmock/request_pattern.rb,
lib/webmock/request_registry.rb,
lib/webmock/util/hash_counter.rb,
lib/webmock/assertion_failure.rb,
lib/webmock/request_signature.rb,
lib/webmock/callback_registry.rb,
lib/webmock/responses_sequence.rb,
lib/webmock/util/version_checker.rb,
lib/webmock/stub_request_snippet.rb,
lib/webmock/request_execution_verifier.rb,
lib/webmock/http_lib_adapters/net_http.rb,
lib/webmock/http_lib_adapters/net_http.rb,
lib/webmock/util/hash_keys_stringifier.rb,
lib/webmock/rspec/matchers/webmock_matcher.rb,
lib/webmock/http_lib_adapters/curb_adapter.rb,
lib/webmock/matchers/hash_including_matcher.rb,
lib/webmock/http_lib_adapters/excon_adapter.rb,
lib/webmock/http_lib_adapters/patron_adapter.rb,
lib/webmock/http_lib_adapters/http_lib_adapter.rb,
lib/webmock/http_lib_adapters/httpclient_adapter.rb,
lib/webmock/rspec/matchers/request_pattern_matcher.rb,
lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb,
lib/webmock/http_lib_adapters/http_lib_adapter_registry.rb,
lib/webmock/http_lib_adapters/em_http_request/em_http_request_1_x.rb,
lib/webmock/http_lib_adapters/em_http_request/em_http_request_0_x.rb

Overview

This code was created based on github.com/myronmarston/vcr/blob/master/lib/vcr/util/version_checker.rb Thanks to @myronmarston

Defined Under Namespace

Modules: API, HttpLibAdapters, Matchers, NetHTTPUtility, RSpecMatcherDetector, Util Classes: AssertionFailure, BodyPattern, CallbackRegistry, Config, Deprecation, DynamicResponse, HeadersPattern, HttpLibAdapter, HttpLibAdapterRegistry, MethodPattern, NetConnectNotAllowedError, RackResponse, RequestExecutionVerifier, RequestPattern, RequestPatternMatcher, RequestRegistry, RequestSignature, RequestStub, Response, ResponseFactory, ResponsesSequence, StubRegistry, StubRequestSnippet, URIPattern, URIRegexpPattern, URIStringPattern, VersionChecker, WebMockMatcher

Constant Summary

VERSION =
'1.9.0'

Class Method Summary (collapse)

Methods included from API

a_request, assert_not_requested, assert_requested, hash_including, stub_request

Class Method Details

+ (Object) after_request(options = {}, &block)



90
91
92
# File 'lib/webmock/webmock.rb', line 90

def self.after_request(options={}, &block)
  WebMock::CallbackRegistry.add_callback(options, block)
end

+ (Object) allow_net_connect!(options = {})



44
45
46
47
# 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

+ (Object) disable!(options = {})



28
29
30
31
32
33
34
# 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

+ (Object) disable_net_connect!(options = {})



49
50
51
52
53
54
# 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

+ (Object) enable!(options = {})



36
37
38
39
40
41
42
# 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

+ (Object) globally_stub_request(&block)



102
103
104
# File 'lib/webmock/webmock.rb', line 102

def self.globally_stub_request(&block)
  WebMock::StubRegistry.instance.register_global_stub(&block)
end

+ (Object) included(clazz)



3
4
5
6
7
8
9
10
11
12
13
14
15
# 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

+ (Boolean) net_connect_allowed?(uri = nil)



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# 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 && (
    (Config.instance.allow.kind_of?(Regexp) && uri.to_s =~ Config.instance.allow) ||
    (
      Config.instance.allow.respond_to?(:include?) &&
      (
        Config.instance.allow.include?(uri.host) ||
        Config.instance.allow.include?("#{uri.host}:#{uri.port}")
      )
    )
  )
end


98
99
100
# File 'lib/webmock/webmock.rb', line 98

def self.print_executed_requests
  puts WebMock::RequestExecutionVerifier.executed_requests_message
end

+ (Boolean) registered_request?(request_signature)



94
95
96
# File 'lib/webmock/webmock.rb', line 94

def self.registered_request?(request_signature)
  WebMock::StubRegistry.instance.registered_request?(request_signature)
end

+ (Object) reset!



76
77
78
79
# File 'lib/webmock/webmock.rb', line 76

def self.reset!
  WebMock::RequestRegistry.instance.reset!
  WebMock::StubRegistry.instance.reset!
end

+ (Object) reset_callbacks



86
87
88
# File 'lib/webmock/webmock.rb', line 86

def self.reset_callbacks
  WebMock::CallbackRegistry.reset
end

+ (Object) reset_webmock



81
82
83
84
# File 'lib/webmock/webmock.rb', line 81

def self.reset_webmock
  WebMock::Deprecation.warning("WebMock.reset_webmock is deprecated. Please use WebMock.reset! method instead")
  reset!
end

+ (Object) version



24
25
26
# File 'lib/webmock/webmock.rb', line 24

def self.version
  VERSION
end