forked from mailman/mailman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spec_helper.rb
89 lines (70 loc) · 2.11 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
$LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'fileutils'
require 'mailman'
require 'rspec'
require 'maildir'
# Require all files in spec/support (Mocks, helpers, etc.)
Dir[File.join(File.dirname(__FILE__), "support", "**", "*.rb")].each do |f|
require File.expand_path(f)
end
unless defined?(SPEC_ROOT)
SPEC_ROOT = File.join(File.dirname(__FILE__))
end
unless defined?(THREAD_TIMING)
THREAD_TIMING = (ENV['THREAD_TIMING'] || (defined?(RUBY_ENGINE) && (RUBY_ENGINE == 'jruby' || RUBY_ENGINE == 'rbx') ? 2.5 : 2)).to_f
end
module Mailman::SpecHelpers
def regexp_matcher(pattern)
Mailman::Route::RegexpMatcher.new(pattern)
end
def string_matcher(pattern)
Mailman::Route::StringMatcher.new(pattern)
end
def basic_message
Mail.new("To: [email protected]\r\nFrom: [email protected]\r\nCC: [email protected]\r\nSubject: Hello!\r\n\r\nemail message\r\n")
end
def multipart_message
mail = Mail.new do
to '[email protected]'
from '[email protected]'
subject 'I am a multipart message'
text_part do
body 'This is plain text'
end
html_part do
content_type 'text/html; charset=UTF-8'
body '<h1>This is HTML</h1>'
end
end
end
def mailman_app(&block)
@app = Mailman::Application.new(&block)
end
def send_message(message)
@app.router.route Mail.new(message)
end
def config
Mailman.config
end
def fixture(*name)
File.open(File.join(SPEC_ROOT, 'fixtures', name) + '.eml').read
end
def setup_maildir
maildir_path = File.join(SPEC_ROOT, 'test-maildir')
FileUtils.rm_r(maildir_path) rescue nil
@maildir = Maildir.new(maildir_path)
message = File.new(File.join(maildir_path, 'new', 'message1'), 'w')
message.puts(fixture('example01'))
message.close
end
end
RSpec.configure do |config|
config.include Mailman::SpecHelpers
config.before do
Mailman.config.logger = Logger.new(File.join(SPEC_ROOT, 'mailman-log.log'))
end
config.after do
FileUtils.rm File.join(SPEC_ROOT, 'mailman-log.log') rescue nil
end
end