tcr.rb 959 B

1234567891011121314151617181920212223242526272829303132
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'tcr'
  3. TCR.configure do |config|
  4. config.cassette_library_dir = 'test/data/tcr_cassettes'
  5. config.hook_tcp_ports = [389] # LDAP
  6. config.format = 'yaml'
  7. end
  8. # TODO: tcr 0.22 does not seem to be compatible with Ruby 3, as it tries to perform a legacy call to
  9. # Socket.tcp(host, port, *socket_opts), where it should be **socket_opts. Work around this by omitting that part.
  10. class Socket
  11. class << self
  12. # def tcp(host, port, *socket_opts)
  13. # if TCR.configuration.hook_tcp_ports.include?(port)
  14. # TCR::RecordableTCPSocket.new(host, port, TCR.cassette)
  15. # else
  16. # real_tcp(host, port, *socket_opts)
  17. # end
  18. # end
  19. def tcp(host, port, ...)
  20. if TCR.configuration.hook_tcp_ports.include?(port)
  21. TCR::RecordableTCPSocket.new(host, port, TCR.cassette)
  22. else
  23. real_tcp(host, port, ...)
  24. end
  25. end
  26. end
  27. end