File: configuration_spec.rb

package info (click to toggle)
ruby-mail 2.6.1%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 4,092 kB
  • ctags: 1,281
  • sloc: ruby: 43,919; makefile: 2
file content (61 lines) | stat: -rw-r--r-- 2,247 bytes parent folder | download | duplicates (2)
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
require 'spec_helper'

class MyTestDeliveryMethod
  attr_accessor :settings

  def initialize(values)
    self.settings = {}.merge!(values)
  end
end

describe Mail::Configuration do

  describe "network configurations" do

    it "defaults delivery_method to smtp" do
      # Need to clear out any prior configuration, as setting nil on the config
      # will not clear it.
      Mail::Configuration.instance.send(:initialize)
      Mail.defaults { delivery_method nil, { :address => 'some.host' } }
      Mail.delivery_method.settings[:address].should eq 'some.host'
    end

    it "should be available from the Mail.defaults method" do
      Mail.defaults { delivery_method :smtp, { :address => 'some.host' } }
      Mail.delivery_method.settings[:address].should eq 'some.host'
    end

    it "should configure sendmail" do
      Mail.defaults { delivery_method :sendmail, :location => "/usr/bin/sendmail" }
      Mail.delivery_method.class.should eq Mail::Sendmail
      Mail.delivery_method.settings[:location].should eq "/usr/bin/sendmail"
    end

    it "should configure sendmail using a string" do
      Mail.defaults { delivery_method 'sendmail', :location => "/usr/bin/sendmail" }
      Mail.delivery_method.class.should eq Mail::Sendmail
      Mail.delivery_method.settings[:location].should eq "/usr/bin/sendmail"
    end

    it "should configure exim" do
      Mail.defaults { delivery_method :exim, :location => "/usr/bin/exim" }
      Mail.delivery_method.class.should eq Mail::Exim
      Mail.delivery_method.settings[:location].should eq "/usr/bin/exim"
    end

    it "should configure an open SMTP connection" do
      smtp = Net::SMTP.start('127.0.0.1', 25)
      Mail.defaults { delivery_method :smtp_connection, {:connection => smtp} }
      Mail.delivery_method.class.should eq Mail::SMTPConnection
      Mail.delivery_method.smtp.should eq smtp
    end

    it "should accept a plug-in delivery method" do
      Mail.defaults { delivery_method MyTestDeliveryMethod, { :option1 => "one", :option2 => "two" }}
      Mail.delivery_method.class.should eq MyTestDeliveryMethod
      Mail.delivery_method.settings[:option1].should eq "one"
      Mail.delivery_method.settings[:option2].should eq "two"
    end

  end
end