Class: BlitzSMTP::MockServer

Inherits:
Object
  • Object
show all
Defined in:
lib/blitz_smtp/mock_server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMockServer

Returns a new instance of MockServer.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/blitz_smtp/mock_server.rb', line 9

def initialize
  @esmtp = true
  @features = []
  @accepted_emails = []
  @server_socket = TCPServer.new(address, 0)
  @server_thread = Thread.start do
    loop do
      @client_socket = @server_socket.accept
      mock_smtp
    end
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, command, *_) ⇒ Object (protected)



100
101
102
103
# File 'lib/blitz_smtp/mock_server.rb', line 100

def method_missing(method, command, *_)
  puts "could not identify #{command} [##{method}]"
  send_command_unknown(command)
end

Instance Attribute Details

#accepted_emailsObject

Returns the value of attribute accepted_emails.



7
8
9
# File 'lib/blitz_smtp/mock_server.rb', line 7

def accepted_emails
  @accepted_emails
end

#esmtpObject

Returns the value of attribute esmtp.



7
8
9
# File 'lib/blitz_smtp/mock_server.rb', line 7

def esmtp
  @esmtp
end

#featuresObject

Returns the value of attribute features.



7
8
9
# File 'lib/blitz_smtp/mock_server.rb', line 7

def features
  @features
end

Instance Method Details

#addressObject



22
23
24
# File 'lib/blitz_smtp/mock_server.rb', line 22

def address
  "localhost"
end

#connected_to_client?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/blitz_smtp/mock_server.rb', line 30

def connected_to_client?
  not @client_socket.nil?
end

#portObject



26
27
28
# File 'lib/blitz_smtp/mock_server.rb', line 26

def port
  @server_socket.connect_address.ip_port
end

#shutdown!Object



34
35
36
37
38
# File 'lib/blitz_smtp/mock_server.rb', line 34

def shutdown!
  @server_thread.kill
  @client_socket.close if connected_to_client?
  @server_socket.close
end