1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
require "rspec/rails/feature_check"
class ApplicationMailbox
class << self
attr_accessor :received
def receive(*)
self.received += 1
end
end
self.received = 0
end
module RSpec
module Rails
RSpec.describe MailboxExampleGroup, skip: !RSpec::Rails::FeatureCheck.has_action_mailbox? do
it_behaves_like "an rspec-rails example group mixin", :mailbox,
'./spec/mailboxes/', '.\\spec\\mailboxes\\'
def group_for(klass)
RSpec::Core::ExampleGroup.describe klass do
include MailboxExampleGroup
end
end
let(:group) { group_for(::ApplicationMailbox) }
let(:example) { group.new }
describe '#have_been_delivered' do
it 'raises on undelivered mail' do
expect {
expect(double('IncomingEmail', delivered?: false)).to example.have_been_delivered
}.to raise_error(/have been delivered/)
end
it 'does not raise otherwise' do
expect(double('IncomingEmail', delivered?: true)).to example.have_been_delivered
end
end
describe '#have_bounced' do
it 'raises on unbounced mail' do
expect {
expect(double('IncomingEmail', bounced?: false)).to example.have_bounced
}.to raise_error(/have bounced/)
end
it 'does not raise otherwise' do
expect(double('IncomingEmail', bounced?: true)).to example.have_bounced
end
end
describe '#have_failed' do
it 'raises on unfailed mail' do
expect {
expect(double('IncomingEmail', failed?: false)).to example.have_failed
}.to raise_error(/have failed/)
end
it 'does not raise otherwise' do
expect(double('IncomingEmail', failed?: true)).to example.have_failed
end
end
describe '#process' do
before do
allow(RSpec::Rails::MailboxExampleGroup).to receive(:create_inbound_email) do |attributes|
mail = double('Mail::Message', attributes)
double('InboundEmail', mail: mail)
end
end
it 'sends mail to the mailbox' do
expect {
example.process(to: ['test@example.com'])
}.to change(::ApplicationMailbox, :received).by(1)
end
end
end
end
end
|