module WebMock::API
Public Instance Methods
a_request(method, uri)
click to toggle source
# File lib/webmock/api.rb, line 12 def a_request(method, uri) WebMock::RequestPattern.new(method, uri) end
assert_not_requested(*args, &block)
click to toggle source
# File lib/webmock/api.rb, line 29 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, &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)
click to toggle source
# File lib/webmock/api.rb, line 20 def assert_requested(*args, &block) if not args[0].is_a?(WebMock::RequestStub) args = convert_uri_method_and_options_to_request_and_options(*args, &block) elsif block raise ArgumentError, "assert_requested with a stub object, doesn't accept blocks" end assert_request_requested(*args) end
hash_including(*args)
click to toggle source
Similar to RSpec::Mocks::ArgumentMatchers#hash_including()
Matches a hash that includes the specified key(s) or key/value pairs. Ignores any additional keys.
@example
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))
Calls superclass method
# File lib/webmock/api.rb, line 48 def hash_including(*args) if defined?(super) super else WebMock::Matchers::HashIncludingMatcher.new(anythingize_lonely_keys(*args)) end end
remove_request_stub(stub)
click to toggle source
# File lib/webmock/api.rb, line 56 def remove_request_stub(stub) WebMock::StubRegistry.instance.remove_request_stub(stub) end
stub_request(method, uri)
click to toggle source
# File lib/webmock/api.rb, line 5 def stub_request(method, uri) WebMock::StubRegistry.instance. register_request_stub(WebMock::RequestStub.new(method, uri)) end
Also aliased as: stub_http_request
Private Instance Methods
anythingize_lonely_keys(*args)
click to toggle source
this is a based on RSpec::Mocks::ArgumentMatchers#anythingize_lonely_keys
# File lib/webmock/api.rb, line 78 def anythingize_lonely_keys(*args) hash = args.last.class == Hash ? args.delete_at(-1) : {} args.each { | arg | hash[arg] = WebMock::Matchers::AnyArgMatcher.new(nil) } hash end
assert_request_not_requested(request, options = {})
click to toggle source
# File lib/webmock/api.rb, line 72 def assert_request_not_requested(request, options = {}) verifier = WebMock::RequestExecutionVerifier.new(request, options.delete(:times)) WebMock::AssertionFailure.failure(verifier.negative_failure_message) unless verifier.does_not_match? end
assert_request_requested(request, options = {})
click to toggle source
# File lib/webmock/api.rb, line 67 def assert_request_requested(request, options = {}) verifier = WebMock::RequestExecutionVerifier.new(request, options.delete(:times) || 1) WebMock::AssertionFailure.failure(verifier.failure_message) unless verifier.matches? end
convert_uri_method_and_options_to_request_and_options(*args, &block)
click to toggle source
# File lib/webmock/api.rb, line 62 def convert_uri_method_and_options_to_request_and_options(*args, &block) request = WebMock::RequestPattern.new(*args).with(&block) [request, args[2] || {}] end