test/support/webmock.rb
def assert_request(method, path, options = {})
    if options[:to_return].is_a?(Array) && !options[:times]
      options = options.merge(times: options[:to_return].size)
    end
    request = stub_request(method, path)
    assertion_options = options.slice!(:to_timeout, :to_return, :with, :to_raise)

    request = options.each_with_object(request) do |(k, v), r|
      case v
      when Array then r.public_send(k, *v)
      when Proc then r.public_send(k, &v)
      else r.public_send(k, v)
      end
    end

    assert_args = [request, assertion_options]

    if block_given?
      result = yield
      assert_requested(*assert_args)
      remove_request_stub(request)
      result
    else
      raise "use assert_requests in the describe block" unless @assert_requests
      @assert_requests << assert_args
    end
  end
# TODO: does not work when asserting the same method/path twice in the same test but different blocks
does not work when asserting the same method/path twice in the same test but different blocks
does not work when asserting the same method / path twice in the same test but different blocks
def assert_request(method, path, options = {})
    if options[:to_return].is_a?(Array) && !options[:times]
      options = options.merge(times: options[:to_return].size)
    end
    request = stub_request(method, path)
    assertion_options = options.slice!(:to_timeout, :to_return, :with, :to_raise)
    request = options.each_with_object(request) do |(k, v), r|
      case v
      when Array then r.public_send(k, *v)
      when Proc then r.public_send(k, &v)
      else r.public_send(k, v)
      end
    end
    assert_args = [request, assertion_options]
    if block_given?
      result = yield
      assert_requested(*assert_args)
      remove_request_stub(request)
      result
    else
      raise "use assert_requests in the describe block" unless @assert_requests
      @assert_requests << assert_args
    end
  end
def assert_request ( method , path , options = { } ) if options [ :to_return ] . is_a? ( Array ) && ! options [ :times ] options = options . merge ( times : options [ :to_return ] . size ) end request = stub_request ( method , path ) assertion_options = options . slice! ( :to_timeout , :to_return , :with , :to_raise ) request = options . each_with_object ( request ) do | ( k , v ) , r | case v when Array then r . public_send ( k , * v ) when Proc then r . public_send ( k , & v ) else r . public_send ( k , v ) end end assert_args = [ request , assertion_options ] if block_given? result = yield assert_requested ( * assert_args ) remove_request_stub ( request ) result else raise "use assert_requests in the describe block" unless @assert_requests @assert_requests << assert_args end end
TODO: does not work when asserting the same method/path twice in the same test but different blocks
TODO : does not work when asserting the same method / path twice in the same test but different blocks
method
path
options