Module: WebMock::API

Extended by:
API
Included in:
Test::Unit::TestCase, WebMock, WebMock, API
Defined in:
lib/webmock/api.rb

Instance Method Summary collapse

Instance Method Details

#a_request(method, uri) ⇒ Object



14
15
16
# File 'lib/webmock/api.rb', line 14

def a_request(method, uri)
  WebMock::RequestPattern.new(method, uri)
end

#assert_not_requested(*args, &block) ⇒ Object Also known as: refute_requested



31
32
33
34
35
36
37
38
# File 'lib/webmock/api.rb', line 31

def assert_not_requested(*args, &block)
  if not args[0].is_a?(WebMock::RequestStub)
    args = convert_uri_method_and_options_to_request_and_options(args[0], args[1], args[2], &block)
  elsif block
    raise ArgumentError, "assert_not_requested with a stub object, doesn't accept blocks"
  end
  assert_request_not_requested(*args)
end

#assert_requested(*args, &block) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/webmock/api.rb', line 22

def assert_requested(*args, &block)
  if not args[0].is_a?(WebMock::RequestStub)
    args = convert_uri_method_and_options_to_request_and_options(args[0], args[1], args[2], &block)
  elsif block
    raise ArgumentError, "assert_requested with a stub object, doesn't accept blocks"
  end
  assert_request_requested(*args)
end

#hash_excluding(*args) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/webmock/api.rb', line 59

def hash_excluding(*args)
  if defined?(super)
    super
  else
    WebMock::Matchers::HashExcludingMatcher.new(anythingize_lonely_keys(*args))
  end
end

#hash_including(*args) ⇒ Object

Similar to RSpec::Mocks::ArgumentMatchers#hash_including()

Matches a hash that includes the specified key(s) or key/value pairs. Ignores any additional keys.

Examples:


object.should_receive(:message).with(hash_including(:key => val))
object.should_receive(:message).with(hash_including(:key))
object.should_receive(:message).with(hash_including(:key, :key2 => val2))


51
52
53
54
55
56
57
# File 'lib/webmock/api.rb', line 51

def hash_including(*args)
  if defined?(super)
    super
  else
    WebMock::Matchers::HashIncludingMatcher.new(anythingize_lonely_keys(*args))
  end
end

#remove_request_stub(stub) ⇒ Object



67
68
69
# File 'lib/webmock/api.rb', line 67

def remove_request_stub(stub)
  WebMock::StubRegistry.instance.remove_request_stub(stub)
end

#reset_executed_requests!Object



71
72
73
# File 'lib/webmock/api.rb', line 71

def reset_executed_requests!
  WebMock::RequestRegistry.instance.reset!
end

#stub_request(method, uri) ⇒ Object Also known as: stub_http_request



7
8
9
10
# File 'lib/webmock/api.rb', line 7

def stub_request(method, uri)
  WebMock::StubRegistry.instance.
    register_request_stub(WebMock::RequestStub.new(method, uri))
end