This repository has been archived by the owner on Nov 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 143
/
spec_helper.rb
71 lines (56 loc) · 1.73 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
$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'] || (RUBY_ENGINE == 'jruby' ? 2.5 : 0.5)).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: test@example.com\r\nFrom: chunky@bacon.com\r\nCC: testing@example.com\r\nSubject: Hello!\r\n\r\nemail message\r\n")
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