Commit 4d036e1

mokha <mokha@cisco.com>
2019-03-18 20:17:49
pass parameters to create_mail method.
1 parent 4645809
Changed files (2)
lib
minbox
spec
lib/minbox/cli.rb
@@ -18,12 +18,7 @@ module Minbox
       method_option :body, type: :string, default: "#{Time.now} This is a test message."
       desc 'send <HOST> <PORT>', 'Send mail to SMTP server'
       def send(host = 'localhost', port = 25)
-        mail = create_mail do |x|
-          x.to = options[:to]
-          x.from = options[:from]
-          x.subject = options[:subject]
-          x.body = (STDIN.tty?) ? options[:body] : $stdin.read
-        end
+        mail = create_mail(options[:to], options[:from], options[:subject], STDIN.tty? ? options[:body] : $stdin.read)
         Net::SMTP.start(host, port) do |smtp|
           smtp.debug_output = Minbox.logger
           smtp.send_message(mail.to_s, options[:from], options[:to])
@@ -48,9 +43,12 @@ module Minbox
 
       private
 
-      def create_mail
+      def create_mail(to, from, subject, body)
         Mail.new do |x|
-          yield x if block_given?
+          x.to = to
+          x.from = from
+          x.subject = subject
+          x.body = body
         end
       end
     end
spec/minbox/server_spec.rb
@@ -105,14 +105,14 @@ RSpec.describe Minbox::Server do
         specify { expect(result).to include('250 OK') }
       end
 
-      context "when sending multiple emails from multiple threads" do
+      context 'when sending multiple emails from multiple threads' do
         let!(:email) { Faker::Internet.email }
         let!(:mail) { create_mail }
-        let!(:mail_string) { mail.to_s  }
+        let!(:mail_string) { mail.to_s }
 
         specify do
           threads = []
-          10.times do |n|
+          10.times do |_n|
             threads << Thread.new do
               i = rand(10)
               result = Net::SMTP.start(host, port) do |smtp|