spec/unit/lib/mail_adapters/mailgun_spec.rb in howitzer-2.0.3 vs spec/unit/lib/mail_adapters/mailgun_spec.rb in howitzer-2.1.0
- old
+ new
@@ -3,10 +3,14 @@
require 'howitzer/log'
require 'howitzer/exceptions'
require 'howitzer/mailgun_api/connector'
RSpec.describe 'Mailgun Email Adapter' do
+ before do
+ allow(Howitzer).to receive(:mail_adapter) { 'mailgun' }
+ Howitzer::Email.adapter = 'mailgun'
+ end
let(:recipient) { 'first_tester@gmail.com' }
let(:message) do
{
'body-plain' => 'test body footer',
'stripped-html' => '<p> test body </p> <p> footer </p>',
@@ -25,12 +29,18 @@
before do
stub_const('Howitzer::Email::SUBJECT', message_subject)
end
describe '.find' do
- let(:mailgun_message) { double(to_h: message) }
- let(:events) { double(to_h: { 'items' => [event] }) }
+ let(:mailgun_message) { JSON.generate(message) }
+ let(:events) { JSON.generate('items' => [event]) }
+ before do
+ FakeWeb.register_uri(:any, 'https://api:mailgun_account_private_key@api.mailgun.net/v3/'\
+ 'mailgun@test.domain/events?event=stored', body: events.to_s)
+ FakeWeb.register_uri(:any, 'https://api:mailgun_account_private_key@si.api.mailgun.net/v3/'\
+ 'domains/mg.strongqa.com/messages/1234567890', body: mailgun_message.to_s)
+ end
subject { Howitzer::MailAdapters::Mailgun.find(recipient, message_subject, wait: 0.01) }
context 'when message is found' do
let(:event) do
{
@@ -44,19 +54,10 @@
'key' => '1234567890',
'url' => 'https://si.api.mailgun.net/v3/domains/mg.strongqa.com/messages/1234567890'
}
}
end
- before do
- allow(Howitzer::MailgunApi::Connector.instance.client).to receive(:get).with(
- 'mailgun@test.domain/events',
- params: { event: 'stored' }
- ) { events }
- allow(Howitzer::MailgunApi::Connector.instance.client).to receive(:get_url).with(
- 'https://si.api.mailgun.net/v3/domains/mg.strongqa.com/messages/1234567890'
- ) { mailgun_message }
- end
it do
expect(Howitzer::Email.adapter).to receive(:new).with(message).once
subject
end
end
@@ -74,16 +75,10 @@
'key' => '1234567890',
'url' => 'https://si.api.mailgun.net/v3/domains/mg.strongqa.com/messages/1234567890'
}
}
end
- before do
- allow(Howitzer::MailgunApi::Connector.instance.client).to receive(:get).with(
- 'mailgun@test.domain/events',
- params: { event: 'stored' }
- ) { events }
- end
it do
expect { subject }.to raise_error(
Howitzer::EmailNotFoundError,
"Message with subject '#{message_subject}' for recipient '#{recipient}' was not found."
)
@@ -154,10 +149,10 @@
it { is_expected.to eq(files) }
end
context 'when no attachments' do
it do
- expect { subject }.to raise_error(Howitzer::NoAttachmentsError, 'No attachments where found.')
+ expect { subject }.to raise_error(Howitzer::NoAttachmentsError, 'No attachments were found.')
end
end
end
end