Permalink
Browse files

Pony.mail, sends an email via net::smtp to localhost

  • Loading branch information...
adamwiggins committed Sep 23, 2008
0 parents commit fc9175ad9c2e2b78249c073904ad2cf0c267b402
Showing with 46 additions and 0 deletions.
  1. +23 −0 Rakefile
  2. +9 −0 lib/pony.rb
  3. +4 −0 spec/base.rb
  4. +10 −0 spec/pony_spec.rb
@@ -0,0 +1,23 @@
+require 'rake'
+require 'spec/rake/spectask'
+
+desc "Run all specs"
+Spec::Rake::SpecTask.new('spec') do |t|
+ t.spec_files = FileList['spec/*_spec.rb']
+end
+
+desc "Print specdocs"
+Spec::Rake::SpecTask.new(:doc) do |t|
+ t.spec_opts = ["--format", "specdoc", "--dry-run"]
+ t.spec_files = FileList['spec/*_spec.rb']
+end
+
+desc "Run all examples with RCov"
+Spec::Rake::SpecTask.new('rcov') do |t|
+ t.spec_files = FileList['spec/*_spec.rb']
+ t.rcov = true
+ t.rcov_opts = ['--exclude', 'examples']
+end
+
+task :default => :spec
+
@@ -0,0 +1,9 @@
+require 'net/smtp'
+
+module Pony
+ def self.mail(to, body)
+ Net::SMTP.start('localhost') do |smtp|
+ smtp.sendmail(body, 'pony@unknown', [ to ])
+ end
+ end
+end
@@ -0,0 +1,4 @@
+require 'rubygems'
+require 'spec'
+
+require File.dirname(__FILE__) + '/../lib/pony'
@@ -0,0 +1,10 @@
+require File.dirname(__FILE__) + '/base'
+
+describe Pony do
+ it "sends an email via Net::SMTP" do
+ smtp = mock('net::smtp object')
+ Net::SMTP.should_receive(:start).with('localhost').and_yield(smtp)
+ smtp.should_receive(:sendmail).with('Hello, Joe!', 'pony@unknown', [ 'joe@example.com' ])
+ Pony.mail('joe@example.com', 'Hello, Joe!')
+ end
+end

0 comments on commit fc9175a

Please sign in to comment.