Permalink
Browse files

Skip Rack::MailExceptions tests when tmail not installed

While here, modify other conditional tests to use the same
basic warning output.
  • Loading branch information...
1 parent 1e2134a commit daf75462c482e0e35786be25f6787440e5ed79e7 @rtomayko rtomayko committed Dec 9, 2008
Showing with 78 additions and 72 deletions.
  1. +77 −71 test/spec_rack_mailexceptions.rb
  2. +1 −1 test/spec_rack_post_body_content_type_parser.rb
View
148 test/spec_rack_mailexceptions.rb
@@ -1,90 +1,96 @@
require 'rack/mock'
-require 'rack/mailexceptions'
-require File.dirname(__FILE__) + '/mail_settings.rb'
+begin
+ require 'tmail'
+ require 'rack/mailexceptions'
-class TestError < RuntimeError
-end
-
-def test_exception
- raise TestError, 'Suffering Succotash!'
-rescue => boom
- return boom
-end
-
-context 'Rack::MailExceptions' do
+ require File.dirname(__FILE__) + '/mail_settings.rb'
- setup do
- @app = lambda { |env| raise TestError, 'Why, I say' }
- @env = Rack::MockRequest.env_for("/foo",
- 'FOO' => 'BAR',
- :method => 'GET',
- :input => 'THE BODY'
- )
- @smtp_settings = {
- :server => 'example.com',
- :domain => 'example.com',
- :port => 500,
- :authentication => :login,
- :user_name => 'joe',
- :password => 'secret'
- }
+ class TestError < RuntimeError
end
- specify 'yields a configuration object to the block when created' do
- called = false
- mailer =
- Rack::MailExceptions.new(@app) do |mail|
- called = true
- mail.to 'foo@example.org'
- mail.from 'bar@example.org'
- mail.subject '[ERROR] %s'
- mail.smtp @smtp_settings
- end
- called.should.be == true
+ def test_exception
+ raise TestError, 'Suffering Succotash!'
+ rescue => boom
+ return boom
end
- specify 'generates a TMail object with configured settings' do
- mailer =
- Rack::MailExceptions.new(@app) do |mail|
- mail.to 'foo@example.org'
- mail.from 'bar@example.org'
- mail.subject '[ERROR] %s'
- mail.smtp @smtp_settings
- end
+ context 'Rack::MailExceptions' do
- tmail = mailer.send(:generate_mail, test_exception, @env)
- tmail.to.should.equal ['foo@example.org']
- tmail.from.should.equal ['bar@example.org']
- tmail.subject.should.equal '[ERROR] Suffering Succotash!'
- tmail.body.should.not.be.nil
- tmail.body.should.be =~ /FOO:\s+"BAR"/
- tmail.body.should.be =~ /^\s*THE BODY\s*$/
- end
+ setup do
+ @app = lambda { |env| raise TestError, 'Why, I say' }
+ @env = Rack::MockRequest.env_for("/foo",
+ 'FOO' => 'BAR',
+ :method => 'GET',
+ :input => 'THE BODY'
+ )
+ @smtp_settings = {
+ :server => 'example.com',
+ :domain => 'example.com',
+ :port => 500,
+ :authentication => :login,
+ :user_name => 'joe',
+ :password => 'secret'
+ }
+ end
- specify 'catches exceptions raised from app, sends mail, and re-raises' do
- mailer =
- Rack::MailExceptions.new(@app) do |mail|
- mail.to 'foo@example.org'
- mail.from 'bar@example.org'
- mail.subject '[ERROR] %s'
- mail.smtp @smtp_settings
- end
- lambda { mailer.call(@env) }.should.raise(TestError)
- @env['mail.sent'].should.be == true
- end
+ specify 'yields a configuration object to the block when created' do
+ called = false
+ mailer =
+ Rack::MailExceptions.new(@app) do |mail|
+ called = true
+ mail.to 'foo@example.org'
+ mail.from 'bar@example.org'
+ mail.subject '[ERROR] %s'
+ mail.smtp @smtp_settings
+ end
+ called.should.be == true
+ end
+
+ specify 'generates a TMail object with configured settings' do
+ mailer =
+ Rack::MailExceptions.new(@app) do |mail|
+ mail.to 'foo@example.org'
+ mail.from 'bar@example.org'
+ mail.subject '[ERROR] %s'
+ mail.smtp @smtp_settings
+ end
+
+ tmail = mailer.send(:generate_mail, test_exception, @env)
+ tmail.to.should.equal ['foo@example.org']
+ tmail.from.should.equal ['bar@example.org']
+ tmail.subject.should.equal '[ERROR] Suffering Succotash!'
+ tmail.body.should.not.be.nil
+ tmail.body.should.be =~ /FOO:\s+"BAR"/
+ tmail.body.should.be =~ /^\s*THE BODY\s*$/
+ end
- if TEST_SMTP && ! TEST_SMTP.empty?
- specify 'sends mail' do
+ specify 'catches exceptions raised from app, sends mail, and re-raises' do
mailer =
Rack::MailExceptions.new(@app) do |mail|
- mail.config.merge! TEST_SMTP
+ mail.to 'foo@example.org'
+ mail.from 'bar@example.org'
+ mail.subject '[ERROR] %s'
+ mail.smtp @smtp_settings
end
lambda { mailer.call(@env) }.should.raise(TestError)
@env['mail.sent'].should.be == true
end
- else
- STDERR.puts 'skipping SMTP tests - edit test/mail_settings.rb to enable'
- end
+ if TEST_SMTP && ! TEST_SMTP.empty?
+ specify 'sends mail' do
+ mailer =
+ Rack::MailExceptions.new(@app) do |mail|
+ mail.config.merge! TEST_SMTP
+ end
+ lambda { mailer.call(@env) }.should.raise(TestError)
+ @env['mail.sent'].should.be == true
+ end
+ else
+ STDERR.puts 'WARN: Skipping SMTP tests (edit test/mail_settings.rb to enable)'
+ end
+
+ end
+rescue LoadError => boom
+ STDERR.puts "WARN: Skipping Rack::MailExceptions tests (tmail not installed)"
end
View
2 test/spec_rack_post_body_content_type_parser.rb
@@ -27,5 +27,5 @@ def env_for_post_with_headers(path, headers, body)
end
rescue LoadError => e
# Missing dependency JSON, skipping tests.
- STDERR.puts "skipping ostBodyContentTypeParser tests - install the JSON gem to enable"
+ STDERR.puts "WARN: Skipping Rack::PostBodyContentTypeParser tests (json not installed)"
end

0 comments on commit daf7546

Please sign in to comment.