File: core_extensions_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 (99 lines) | stat: -rw-r--r-- 2,876 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# encoding: utf-8
require 'spec_helper'

describe Object do

  describe "blank method" do
    it "should say nil is blank" do
      nil.should be_blank
    end

    it "should say false is blank" do
      false.should be_blank
    end

    it "should say true is not blank" do
      true.should_not be_blank
    end

    it "should say an empty array is blank" do
      [].should be_blank
    end

    it "should say an empty hash is blank" do
      {}.should be_blank
    end

    it "should say an empty string is blank" do
      ''.should be_blank
      " ".should be_blank
      a = ''; 1000.times { a << ' ' }
      a.should be_blank
      "\t \n\n".should be_blank
    end
  end

  describe "not blank method" do
    it "should say a number is not blank" do
      1.should_not be_blank
    end
    
    it "should say a valueless hash is not blank" do
      {:one => nil, :two => nil}.should_not be_blank
    end
    
    it "should say a hash containing an empty hash is not blank" do
      {:key => {}}.should_not be_blank
    end
  end

  describe "to_lf method on String" do
    it "should leave lf as lf" do
      "\n".to_lf.should eq "\n"
    end

    it "should clean just cr to lf" do
      "\r".to_lf.should eq "\n"
    end

    it "should leave crlf as lf" do
      "\r\n".to_lf.should eq "\n"
    end
    
    it "should handle japanese characters" do
      string = "\343\201\202\343\201\210\343\201\206\343\201\210\343\201\212\r\n\r\n\343\201\213\343\201\215\343\201\217\343\201\221\343\201\223\r\n\r\n\343\201\225\343\201\227\343\201\244\343\201\233\343\201\235\r\n\r\n"
      string.to_lf.should eq "\343\201\202\343\201\210\343\201\206\343\201\210\343\201\212\n\n\343\201\213\343\201\215\343\201\217\343\201\221\343\201\223\n\n\343\201\225\343\201\227\343\201\244\343\201\233\343\201\235\n\n"
    end
  end

  describe "to_crlf method on String" do
    it "should clean just lf to crlf" do
      "\n".to_crlf.should eq "\r\n"
    end

    it "should clean just cr to crlf" do
      "\r".to_crlf.should eq "\r\n"
    end

    it "should leave crlf as crlf" do
      "\r\n".to_crlf.should eq "\r\n"
    end

    it "should handle japanese characters" do
      string = "\343\201\202\343\201\210\343\201\206\343\201\210\343\201\212\r\n\r\n\343\201\213\343\201\215\343\201\217\343\201\221\343\201\223\r\n\r\n\343\201\225\343\201\227\343\201\244\343\201\233\343\201\235\r\n\r\n"
      string.to_crlf.should eq "\343\201\202\343\201\210\343\201\206\343\201\210\343\201\212\r\n\r\n\343\201\213\343\201\215\343\201\217\343\201\221\343\201\223\r\n\r\n\343\201\225\343\201\227\343\201\244\343\201\233\343\201\235\r\n\r\n"
    end
    
  end

  describe "methods on NilClass" do
    it "should return empty string on to_crlf" do
      nil.to_crlf.should eq ''
    end

    it "should return empty string on to_lf" do
      nil.to_lf.should eq ''
    end
  end

end