Beginnings of specs

This commit is contained in:
Samuel Cochran 2014-03-21 11:58:44 +11:00
parent 8f5a5b59ce
commit 77212c3e98
6 changed files with 125 additions and 28 deletions

View File

@ -14,22 +14,18 @@ PATH
GEM
remote: https://rubygems.org/
specs:
activesupport (4.0.4)
i18n (~> 0.6, >= 0.6.9)
minitest (~> 4.2)
multi_json (~> 1.3)
thread_safe (~> 0.1)
tzinfo (~> 0.3.37)
atomic (1.1.15)
activesupport (3.2.17)
i18n (~> 0.6, >= 0.6.4)
multi_json (~> 1.0)
chunky_png (1.3.0)
coffee-script (2.2.0)
coffee-script-source
execjs
coffee-script-source (1.7.0)
compass (0.12.2)
compass (0.12.4)
chunky_png (~> 1.2)
fssm (>= 0.2.7)
sass (~> 3.1)
sass (~> 3.2.17)
daemons (1.1.9)
eventmachine (1.0.3)
execjs (2.0.2)
@ -43,8 +39,8 @@ GEM
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.25.1)
minitest (4.7.5)
multi_json (1.9.0)
minitest (5.3.1)
multi_json (1.9.2)
polyglot (0.3.4)
rack (1.5.2)
rack-protection (1.5.2)
@ -52,7 +48,7 @@ GEM
rake (10.1.1)
rdoc (4.1.1)
json (~> 1.4)
sass (3.2.14)
sass (3.2.17)
sinatra (1.4.4)
rack (~> 1.4)
rack-protection (~> 1.4)
@ -68,18 +64,15 @@ GEM
sprockets-sass (1.0.3)
sprockets (~> 2.0)
tilt (~> 1.1)
sqlite3 (1.3.8)
sqlite3 (1.3.9)
thin (1.5.1)
daemons (>= 1.0.9)
eventmachine (>= 0.12.6)
rack (>= 1.0.0)
thread_safe (0.2.0)
atomic (>= 1.1.7, < 2)
tilt (1.4.1)
treetop (1.4.15)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.39)
uglifier (2.5.0)
execjs (>= 0.3.0)
json (>= 1.8.0)
@ -91,6 +84,7 @@ DEPENDENCIES
coffee-script
compass
mailcatcher!
minitest (~> 5.0)
rake
rdoc
sass

View File

@ -1,20 +1,8 @@
require "fileutils"
require "rubygems"
require "rubygems/package"
require "mail_catcher/version"
spec_file = File.expand_path("../mailcatcher.gemspec", __FILE__)
spec = Gem::Specification.load(spec_file)
require "rdoc/task"
RDoc::Task.new(:rdoc => "doc",:clobber_rdoc => "doc:clean", :rerdoc => "doc:force") do |rdoc|
rdoc.title = "MailCatcher #{MailCatcher::VERSION}"
rdoc.rdoc_dir = "doc"
rdoc.main = "README.md"
rdoc.rdoc_files.include "lib/**/*.rb"
end
# XXX: Would prefer to use Rake::SprocketsTask but can't populate
# non-digest assets, and we don't want sprockets at runtime so
# can't use manifest directly. Perhaps index.html should be
@ -39,6 +27,12 @@ end
desc "Package as Gem"
task "package" => ["assets"] do
require "rubygems/package"
require "rubygems/specification"
spec_file = File.expand_path("../mailcatcher.gemspec", __FILE__)
spec = Gem::Specification.load(spec_file)
Gem::Package.build spec
end
@ -46,3 +40,18 @@ desc "Release Gem to RubyGems"
task "release" => ["package"] do
%x[gem push mailcatcher-#{MailCatcher::VERSION}.gem]
end
require "rdoc/task"
RDoc::Task.new(:rdoc => "doc",:clobber_rdoc => "doc:clean", :rerdoc => "doc:force") do |rdoc|
rdoc.title = "MailCatcher #{MailCatcher::VERSION}"
rdoc.rdoc_dir = "doc"
rdoc.main = "README.md"
rdoc.rdoc_files.include "lib/**/*.rb"
end
require "rake/testtask"
Rake::TestTask.new do |task|
task.pattern = "spec/*_spec.rb"
end

20
examples/attachmail Normal file
View File

@ -0,0 +1,20 @@
To: Blah <blah@blah.com>
From: Me <me@sj26.com>
Subject: Test Attachment Mail
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary=BOUNDARY--198849662
Header
--BOUNDARY--198849662
Content-Type: text/plain
Content-Disposition: attachment; filename=blah.txt
Plain text mail
--BOUNDARY--198849662
Content-Type: text/html
<html><body><em>HTML</em> mail</body></html>
--BOUNDARY--198849662--

6
examples/unknownmail Normal file
View File

@ -0,0 +1,6 @@
To: Blah <blah@blah.com>
From: Me <me@sj26.com>
Subject: Test mail
Content-Type: application/x-weird
Weird stuff~

View File

@ -41,6 +41,7 @@ Gem::Specification.new do |s|
s.add_development_dependency "coffee-script"
s.add_development_dependency "compass"
s.add_development_dependency "minitest", "~> 5.0"
s.add_development_dependency "rake"
s.add_development_dependency "rdoc"
s.add_development_dependency "sass"

67
spec/mailcatcher_spec.rb Normal file
View File

@ -0,0 +1,67 @@
require "minitest/autorun"
require "mail_catcher"
require "socket"
require "net/smtp"
SMTP_PORT = 10025
HTTP_PORT = 10080
# Start MailCatcher
MAILCATCHER_PID = spawn "bundle", "exec", "mailcatcher", "--foreground", "--smtp-port", SMTP_PORT.to_s, "--http-port", HTTP_PORT.to_s
# Make sure it will be stopped
MiniTest.after_run do
Process.kill("TERM", MAILCATCHER_PID) and Process.wait
end
# Wait for it to boot
begin
TCPSocket.new("127.0.0.1", SMTP_PORT).close
rescue Errno::ECONNREFUSED
retry
end
describe MailCatcher do
def deliver(message, options={})
options = {:from => "from@example.com", :to => "to@example.com"}.merge(options)
Net::SMTP.start('127.0.0.1', SMTP_PORT) do |smtp|
smtp.send_message message, options[:from], options[:to]
end
end
def read_example(name)
File.read(File.expand_path("../../examples/#{name}", __FILE__))
end
def deliver_example(name, options={})
deliver(read_example(name), options)
end
it "catches and displays a plain text message as plain text and source" do
deliver_example("plainmail")
end
it "catches and displays an html message as html and source" do
deliver_example("htmlmail")
end
it "catches and displays a multipart message as text, html and source" do
deliver_example("multipartmail")
end
it "catches and displays an unknown message as source" do
deliver_example("unknownmail")
end
it "catches and displays a message with multipart attachments" do
deliver_example("attachmail")
end
it "doesn't choke on messages containing dots" do
deliver_example("dotmail")
end
it "doesn't choke on messages containing quoted printables" do
deliver_example("quoted_printable_htmlmail")
end
end