lib/fake_smtp/server.rb in fake_smtp-0.0.1 vs lib/fake_smtp/server.rb in fake_smtp-0.0.2
- old
+ new
@@ -34,16 +34,16 @@
end
def run
log("New session: #{@socket}")
- handlers[:start].call if handlers[:start]
+ instance_eval &handlers[:start] if handlers[:start]
until done
break unless cmd = read_line
handle_command cmd
end
- handlers[:end].call if handlers[:end]
+ instance_eval &handlers[:end] if handlers[:end]
@socket.close
log("Session finished: #{@socket}")
end
@@ -61,10 +61,11 @@
def log(*args)
puts args.join(' ')
end
def respond_with(msg)
+ log "Response: #{msg}"
@socket.puts msg
end
def read_line
line = @socket.gets
@@ -73,12 +74,15 @@
line
end
end
class SmtpSession < Session
+ on :start do
+ respond_with '220 smtp.example.com SMTP FakeSmtp'
+ end
on /^HELO|^EHLO/ do
words = cmd.split(' ')
- respond_with "Hello #{words[1]} I am glad to meet you"
+ respond_with "250: Hello #{words[1]} I am glad to meet you"
end
on /^QUIT/ do
respond_with('221 Bye')
self.done = true