Skip to content

Commit

Permalink
#495: add stdout-based postman
Browse files Browse the repository at this point in the history
Fixed #495
  • Loading branch information
dgroup committed Sep 29, 2021
1 parent 81b06ed commit 9679e67
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/lazylead/postman.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,24 @@ def make_email(opts)
mail
end
end

#
# A postman that sends emails to the std out.
#
class StdoutPostman
def initialize(log = Log.new)
@log = log
end

# Send an email.
# :opts :: the mail configuration like to, from, cc, subject, template.
def send(opts)
if opts.msg_to.empty?
p "Email can't be sent as 'to' is empty, more: '#{opts}'"
else
p "to=#{opts.msg_to}, from=#{opts.msg_from}, cc=#{opts.msg_cc}, " \
"subject=#{opts['subject']}, attachments=#{opts.msg_attachments}, body=#{opts.msg_body}"
end
end
end
end
16 changes: 16 additions & 0 deletions test/lazylead/postman_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,20 @@ class PostmanTest < Lazylead::Test
)
end
end

class StdoutPostmanTest < Lazylead::Test
# @todo #495/DEV Find way to capture the STDOUT in order to test the email sending.
# Right now its just visual verification.
test "send email to stdout" do
StdoutPostman.new.send(
Opts.new(
"to" => "to@email.com",
"from" => "from@email.com",
"attachments" => ["readme.md"],
"subject" => "[LL] Attachments",
"template" => "lib/messages/savepoint.erb"
)
)
end
end
end

0 comments on commit 9679e67

Please sign in to comment.