File: keywords_field_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 (73 lines) | stat: -rw-r--r-- 3,564 bytes parent folder | download
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
# encoding: utf-8
# frozen_string_literal: true
require 'spec_helper'

describe Mail::KeywordsField do

  describe "initializing" do
    
    it "should initialize" do
      expect { Mail::KeywordsField.new("this, is, email") }.not_to raise_error
    end
    
    it "should accept a string with the field name" do
      k = Mail::KeywordsField.new('Keywords: these are keywords, so there')
      expect(k.name).to eq 'Keywords'
      expect(k.value).to eq 'these are keywords, so there'
    end
    
    it "should accept a string with the field name" do
      k = Mail::KeywordsField.new('these are keywords, so there')
      expect(k.name).to eq 'Keywords'
      expect(k.value).to eq 'these are keywords, so there'
    end
    
  end
  
  describe "giving a list of keywords" do
    it "should return a list of keywords" do
      k = Mail::KeywordsField.new('these are keywords, so there')
      expect(k.keywords).to eq ['these are keywords', 'so there']
    end
    
    it "should handle phrases" do
      k = Mail::KeywordsField.new('"these, are keywords", so there')
      expect(k.keywords).to eq ['these, are keywords', 'so there']
    end
    
    it "should handle comments" do
      k = Mail::KeywordsField.new('"these, are keywords", so there (This is an irrelevant comment)')
      expect(k.keywords).to eq ['these, are keywords', 'so there (This is an irrelevant comment)']
    end
    
    it "should handle comments" do
      k = Mail::KeywordsField.new('"these, are keywords", so there (This is an irrelevant comment)')
      expect(k.keywords).to eq ['these, are keywords', 'so there (This is an irrelevant comment)']
    end
    
    it "should handle comments in quotes" do
      k = Mail::KeywordsField.new('"these, are keywords (another comment to be ignored)", so there (This is an irrelevant comment)')
      expect(k.keywords).to eq ['these, are keywords (another comment to be ignored)', 'so there (This is an irrelevant comment)']
    end
    
  end
  
  describe "encoding and decoding" do
    it "should encode" do
      k = Mail::KeywordsField.new('these are keywords, so there')
      expect(k.encoded).to eq "Keywords: these are keywords,\r\n so there\r\n"
    end

    it "should decode" do
      k = Mail::KeywordsField.new('these are keywords, so there')
      expect(k.decoded).to eq "these are keywords, so there"
    end
  end

  it "should output lines shorter than 998 chars" do
    k = Mail::KeywordsField.new('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed placerat euismod velit nec convallis. Cras bibendum mattis arcu a tincidunt. Nullam ac orci vitae massa elementum ultricies ultricies nec quam. Praesent eleifend viverra semper. Sed id ultricies ipsum. Pellentesque sed nunc mauris, at varius sem. Curabitur pretium pellentesque velit, eget pellentesque dolor interdum eget. Duis ac lectus nec arcu pharetra lobortis. Integer risus felis, convallis ut feugiat quis, imperdiet ut sapien. Nullam imperdiet leo nec lectus imperdiet mollis. Proin nec lectus id erat pellentesque pretium vitae sit amet massa. Proin interdum pellentesque mi, at tristique sem facilisis ut. Donec enim mauris, viverra ut lacinia pharetra, elementum nec mi. Ut at interdum massa. Integer placerat tortor at tellus lobortis a mattis massa ultricies. Vivamus nec dolor at justo fringilla laoreet rhoncus fermentum lectus. Praesent tincidunt congue mauris vitae aliquam. Mauris arcu mauris, faucibus sed turpis duis.')
    lines = k.encoded.split("\r\n\s")
    lines.each { |line| expect(line.length).to be < 998 }
  end

end