File: sender_field_spec.rb

package info (click to toggle)
ruby-mail 2.7.1%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 5,436 kB
  • sloc: ruby: 71,596; makefile: 3
file content (57 lines) | stat: -rw-r--r-- 1,956 bytes parent folder | download | duplicates (3)
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
# encoding: utf-8
# frozen_string_literal: true
require 'spec_helper'

describe Mail::SenderField do
  # sender          =       "Sender:" mailbox CRLF
  #

  describe "initialization" do

    it "should initialize" do
      expect { Mail::SenderField.new("Mikel") }.not_to raise_error
    end

    it "should mix in the CommonAddress module" do
      expect(Mail::SenderField.included_modules).to include(Mail::CommonAddress)
    end

    it "should accept a string without the field name" do
      t = Mail::SenderField.new('Mikel Lindsaar <mikel@test.lindsaar.net>')
      expect(t.name).to eq 'Sender'
      expect(t.value).to eq 'Mikel Lindsaar <mikel@test.lindsaar.net>'
    end

    it "should reject headers with multiple mailboxes" do
      pending 'Sender accepts an address list now, but should only accept a single address'
      expect { Mail::SenderField.new('Mikel Lindsaar <mikel@test.lindsaar.net>, "Bob Smith" <bob@me.com>') }.to raise_error(Mail::Field::ParseError)
    end
  end

  # Actual testing of CommonAddress methods oSenderurs in the address field spec file

  describe "instance methods" do
    it "should return an address" do
      t = Mail::SenderField.new('Mikel Lindsaar <mikel@test.lindsaar.net>')
      expect(t.formatted).to eq ['Mikel Lindsaar <mikel@test.lindsaar.net>']
    end

    it "should return two addresses" do
      t = Mail::SenderField.new('Mikel Lindsaar <mikel@test.lindsaar.net>')
      expect(t.address.to_s).to eq 'Mikel Lindsaar <mikel@test.lindsaar.net>'
    end

    it "should return the formatted line on to_s" do
      t = Mail::SenderField.new('Mikel Lindsaar <mikel@test.lindsaar.net>')
      expect(t.value).to eq 'Mikel Lindsaar <mikel@test.lindsaar.net>'
    end

    it "should return the encoded line" do
      t = Mail::SenderField.new('Mikel Lindsaar <mikel@test.lindsaar.net>')
      expect(t.encoded).to eq "Sender: Mikel Lindsaar <mikel@test.lindsaar.net>\r\n"
    end

  end


end