Sha256: 4b1e20b6fc32f944c36dc8416cb18b6eab52e890ecd48a1f6d39d18dcdefaca4

Contents?: true

Size: 1.82 KB

Versions: 7

Compression:

Stored size: 1.82 KB

Contents

require File.join(File.dirname(__FILE__), "../spec_helper")

module Emailer
  describe ToFileSmtpFacade do
    
    FILE_DIR = '/tmp/emails/'
    
    TOFILE_OPTIONS = {
      :file_dir => FILE_DIR,
      :use => nil
    }
    
    describe :init do 
      it 'Should accept all valid options' do
        ToFileSmtpFacade.new TOFILE_OPTIONS
      end
      
      it 'Should only accept valid options' do
        lambda do 
          ToFileSmtpFacade.new :file_dir => FILE_DIR, :foo => 'foo'
        end.should raise_error
      end
      
      it 'Should demand that :file_dir option is supplied' do
        lambda do 
          ToFileSmtpFacade.new
        end.should raise_error
      end
    end
    
    describe :send_mail do
      it 'Should create a new file with the name of from and to addresses' do
        smtp = ToFileSmtpFacade.new :file_dir => FILE_DIR     
        smtp.open do
          smtp.send_mail(
            :to => 'test@bits2life.com',
            :from => 'test2@bits2life.com',
            :subject => 'a test subject',
            :body => 'A test message'
          )
        end
        
        found = false
        Dir.entries(FILE_DIR).each do |entry|
          found = true if entry.include? 'test@bits2life.com'
        end
        
        found.should == true
      end
      
      it 'Should send an email using the supplied facade' do
        mockSmtp = MockSmtpFacade.new
        smtp = ToFileSmtpFacade.new :file_dir => FILE_DIR, :use => mockSmtp
        smtp.open do 
          smtp.send_mail(
            :to => "emma@bits2life.com",
            :from => "bjorn@bits2life.com",
            :subject => 'A test email to emma',
            :body => '<html><head></head><body><h1>This is a test</h1></body></html>'
          )
        end
        
        mockSmtp.sent.count.should == 1
      end
      
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
bjornblomqvist-emailer-0.1.11 spec/emailer/tofile_smtp_facade_spec.rb
bjornblomqvist-emailer-0.1.12 spec/emailer/tofile_smtp_facade_spec.rb
bjornblomqvist-emailer-0.1.13 spec/emailer/tofile_smtp_facade_spec.rb
bjornblomqvist-emailer-0.1.15 spec/emailer/tofile_smtp_facade_spec.rb
bjornblomqvist-emailer-0.1.6 spec/emailer/tofile_smtp_facade_spec.rb
bjornblomqvist-emailer-0.1.7 spec/emailer/tofile_smtp_facade_spec.rb
bjornblomqvist-emailer-0.1.9 spec/emailer/tofile_smtp_facade_spec.rb