Skip to content

Commit 1cedfa5

Browse files
committed
Break out specs
1 parent 75465bf commit 1cedfa5

File tree

3 files changed

+52
-3
lines changed

3 files changed

+52
-3
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ PATH
22
remote: .
33
specs:
44
supermail (0.1.0)
5-
actionmailer (~> 7.0)
5+
actionmailer (>= 7.0)
66

77
GEM
88
remote: https://rubygems.org/

lib/supermail.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
# frozen_string_literal: true
22

33
require_relative "supermail/version"
4-
require "action_mailer"
4+
require 'action_mailer'
55

66
module Supermail
77
class Error < StandardError; end
88

99
module Rails
1010
class Base
11-
delegate :deliver, :deliver_now, :deliver_later, to: :message
11+
delegate :deliver, :deliver_now, :deliver_later, to: :message_delivery
1212

1313
def to = nil
1414
def from = nil
1515
def subject = nil
1616
def body = ""
1717

1818
def message
19+
message_delivery.message
20+
end
21+
22+
def message_delivery
1923
ActionMailer::Base.mail(to:, from:, subject:, body:)
2024
end
2125
end

spec/supermail_spec.rb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# frozen_string_literal: true
2+
3+
require "spec_helper"
4+
5+
class ExampleMailer < Supermail::Rails::Base
6+
def initialize(to:, from:, subject:, body:)
7+
@to = to
8+
@from = from
9+
@subject = subject
10+
@body = body
11+
end
12+
13+
attr_reader :to, :from, :subject, :body
14+
end
15+
16+
RSpec.describe ExampleMailer do
17+
let(:email) { described_class.new(
18+
19+
20+
subject: "Hello",
21+
body: "Hi there")
22+
}
23+
let(:message) { email.message }
24+
subject { message }
25+
26+
it "builds a Mail::Message" do
27+
expect(subject).to be_a(Mail::Message)
28+
end
29+
30+
it "sets the to header" do
31+
expect(subject.to).to eq(["[email protected]"])
32+
end
33+
34+
it "sets the from header" do
35+
expect(subject.from).to eq(["[email protected]"])
36+
end
37+
38+
it "sets the subject header" do
39+
expect(subject.subject).to eq("Hello")
40+
end
41+
42+
it "sets the body" do
43+
expect(subject.body.to_s).to eq("Hi there")
44+
end
45+
end

0 commit comments

Comments
 (0)