File: envelope_from_element_spec.rb

package info (click to toggle)
ruby-mail 2.6.4%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,256 kB
  • ctags: 1,327
  • sloc: ruby: 44,678; makefile: 3
file content (48 lines) | stat: -rw-r--r-- 1,803 bytes parent folder | download | duplicates (5)
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
# frozen_string_literal: true
require 'spec_helper'

describe Mail::EnvelopeFromElement do
  
  describe "parsing a from envelope string" do
    it "should parse a full field" do
      expect { Mail::EnvelopeFromElement.new("mikel@test.lindsaar.net  Mon Aug  7 00:39:21 2009") }.not_to raise_error
    end

    it "should parse a full field with a double digit day" do
      expect { Mail::EnvelopeFromElement.new("mikel@test.lindsaar.net  Mon Aug 17 00:39:21 2009") }.not_to raise_error
    end

    it "should parse a full field with a single space day" do
      expect { Mail::EnvelopeFromElement.new("mikel@test.lindsaar.net Mon Aug 17 00:39:21 2009") }.not_to raise_error
    end

    it "should parse a null sender, when specified as <>" do
      expect { Mail::EnvelopeFromElement.new("<>  Mon Aug 17 00:39:21 2009") }.not_to raise_error
    end

    it "should parse a null sender, with a single space day" do
      expect { Mail::EnvelopeFromElement.new("<> Mon Aug 17 00:39:21 2009") }.not_to raise_error
    end
  end

  describe "accessor methods" do
    it "should return the address" do
      envelope = Mail::EnvelopeFromElement.new("mikel@test.lindsaar.net Mon Aug 17 00:39:21 2009")
      expect(envelope.address).to eq "mikel@test.lindsaar.net"
    end

    it "should return the date_time" do
      envelope = Mail::EnvelopeFromElement.new("mikel@test.lindsaar.net Mon Aug 17 00:39:21 2009")
      expect(envelope.date_time).to eq ::DateTime.parse("Mon Aug 17 00:39:21 2009")
    end
  end

  describe 'formatting' do
    it 'should format delivery date using UNIX ctime style' do
      time = Time.now
      envelope = Mail::EnvelopeFromElement.new("mikel@test.lindsaar.net #{time.ctime}")
      expect(envelope.to_s).to eq "mikel@test.lindsaar.net #{time.ctime}"
    end
  end

end