Permalink
Browse files

raise exception if location option is not present when setting up del…

…ivery
  • Loading branch information...
1 parent 11d5293 commit fccbf2f569212fed95be7665a9fdd7c0b83335ec @ryanb committed Oct 1, 2012
Showing with 12 additions and 4 deletions.
  1. +1 −1 README.rdoc
  2. +6 −3 lib/letter_opener/delivery_method.rb
  3. +5 −0 spec/letter_opener/delivery_method_spec.rb
View
@@ -22,7 +22,7 @@ If you aren't using Rails, this can be easily set up with the Mail gem. Just set
require "letter_opener"
Mail.defaults do
- delivery_method LetterOpener::DeliveryMethod, :location => "tmp/letter_opener"
+ delivery_method LetterOpener::DeliveryMethod, :location => File.expand_path('../tmp/letter_opener', __FILE__)
end
@@ -1,11 +1,14 @@
module LetterOpener
class DeliveryMethod
- def initialize(options = {})
- self.settings = {:location => './letter_opener'}.merge!(options)
- end
+ class InvalidOption < StandardError; end
attr_accessor :settings
+ def initialize(options = {})
+ raise InvalidOption, "A location option is required when using the Letter Opener delivery method" if options[:location].nil?
+ self.settings = options
+ end
+
def deliver!(mail)
location = File.join(settings[:location], "#{Time.now.to_i}_#{Digest::SHA1.hexdigest(mail.encoded)[0..6]}")
messages = Message.rendered_messages(location, mail)
@@ -13,6 +13,11 @@
end
end
+ it 'raises an exception if no location passed' do
+ lambda { LetterOpener::DeliveryMethod.new }.should raise_exception(LetterOpener::DeliveryMethod::InvalidOption)
+ lambda { LetterOpener::DeliveryMethod.new(location: "foo") }.should_not raise_exception
+ end
+
context 'content' do
let(:plain_file) { Dir["#{location}/*/plain.html"].first }
let(:plain) { File.read(plain_file) }

0 comments on commit fccbf2f

Please sign in to comment.