/
spec_helper.rb
149 lines (118 loc) · 2.56 KB
/
spec_helper.rb
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# encoding: utf-8
unless defined?(MAIL_ROOT)
STDERR.puts("Running Specs under Ruby Version #{RUBY_VERSION}")
MAIL_ROOT = File.join(File.dirname(__FILE__), '../')
end
unless defined?(SPEC_ROOT)
SPEC_ROOT = File.join(File.dirname(__FILE__))
end
require 'rubygems'
require 'ruby-debug' if RUBY_VERSION < '1.9'
require 'spec'
require 'treetop'
$:.unshift "#{File.dirname(__FILE__)}/mail"
$:.unshift "#{File.dirname(__FILE__)}/../lib"
require File.join(File.dirname(__FILE__), 'matchers', 'break_down_to')
require 'mail'
Spec::Runner.configure do |config|
config.include(CustomMatchers)
end
def fixture(*name)
File.join(SPEC_ROOT, 'fixtures', name)
end
alias doing lambda
# Produces an array or printable ascii by default.
#
# We can assume if a, m and z and 1, 5, 0 work, then the rest
# of the letters and numbers work.
def ascii(from = 33, to = 126)
chars = []
from.upto(to) { |c| chars << ('' << c) }
boring = ('b'..'l').to_a + ('n'..'o').to_a +
('p'..'y').to_a + ('B'..'L').to_a + ('N'..'O').to_a +
('P'..'Y').to_a + ('1'..'4').to_a + ('6'..'8').to_a
chars - boring
end
# Original mockup from ActionMailer
class MockSMTP
def self.deliveries
@@deliveries
end
def initialize
@@deliveries = []
end
def sendmail(mail, from, to)
@@deliveries << [mail, from, to]
end
def start(*args)
yield self
end
# in the standard lib: net/smtp.rb line 577
# a TypeError is thrown unless this arg is a
# kind of OpenSSL::SSL::SSLContext
def enable_tls(context = nil)
if context && context.kind_of?(OpenSSL::SSL::SSLContext)
true
elsif context
raise TypeError,
"wrong argument (#{context.class})! "+
"(Expected kind of OpenSSL::SSL::SSLContext)"
end
end
def enable_starttls
true
end
end
class Net::SMTP
def self.new(*args)
MockSMTP.new
end
end
class MockPopMail
def initialize(rfc2822)
@rfc2822 = rfc2822
end
def pop
Mail.new(@rfc2822)
end
end
class MockPOP3
@@start = false
def initialize
@@popmails = [
MockPopMail.new('test1'),
MockPopMail.new('test2'),
]
end
def self.popmails
@@popmails
end
def each_mail(*args)
@@popmails.each do |popmail|
yield popmail
end
end
def start(*args)
@@start = true
block_given? ? yield(self) : self
end
def enable_ssl(*args)
true
end
def started?
@@start == true
end
def self.started?
@@start == true
end
def reset
end
def finish
@@start = false
end
end
class Net::POP3
def self.new(*args)
MockPOP3.new
end
end