Sha256: bb9d2b7fc3caf11610c59af4660580d283258224124b0e2db93b8224a743e6cb
Contents?: true
Size: 1.79 KB
Versions: 7
Compression:
Stored size: 1.79 KB
Contents
require "spec_helper" module SocialNetworking RSpec.describe Notification do let(:participant) { instance_double(Participant) } let(:recipient) { instance_double(Participant) } let(:mailer) { double("mailer") } def notification(attributes = {}) Notification.new({ current_participant: participant, mailer: mailer, recipient: recipient, message_body: "foo", subject: "bar" }.merge(attributes)) end describe ".notify" do describe "when recipient is the current_participant" do it "returns nil" do new_notification = notification(recipient: participant) expect(new_notification.notify).to be_nil end end describe "when recipient is not the current_participant" do describe "when recipient would prefer to receive emails" do it "sends an email" do allow(recipient) .to receive(:contact_preference) { "email" } expect_any_instance_of(Notification) .to receive(:send_email) notification.notify end end describe "when recipient would prefer to receive sms" do it "sends an sms" do allow(recipient) .to receive(:contact_preference) { "sms" } expect_any_instance_of(Notification) .to receive(:send_sms) notification.notify end it "handles a Twilio SMS exception" do allow(recipient) .to receive(:contact_preference) { "sms" } expect_any_instance_of(Notification) .to receive(:send_sms) .and_raise(Twilio::REST::RequestError.new("SMS error.")) notification.notify end end end end end end
Version data entries
7 entries across 7 versions & 1 rubygems