Browse files

Merge pull request #747 from zendesk/grosser/silence

silence warning
  • Loading branch information...
2 parents 08cd8f5 + 8ad1b8d commit 1fbb9486a73b1cbc2a79044d675eff3258659ab3 @bf4 bf4 committed Jul 22, 2014
Showing with 22 additions and 14 deletions.
  1. +13 −13 spec/mail/network/delivery_methods/file_delivery_spec.rb
  2. +9 −1 spec/spec_helper.rb
View
26 spec/mail/network/delivery_methods/file_delivery_spec.rb
@@ -15,47 +15,47 @@
:enable_starttls_auto => true }
end
end
-
+
after(:each) do
files = Dir.glob(File.join(Mail.delivery_method.settings[:location], '*'))
files.each do |file|
File.delete(file)
end
end
-
+
describe "general usage" do
tmpdir = File.expand_path('../../../../tmp/mail', __FILE__)
it "should send an email to a file" do
Mail.defaults do
delivery_method :file, :location => tmpdir
end
-
+
mail = Mail.deliver do
from 'roger@moore.com'
to 'marcel@amont.com'
subject 'invalid RFC2822'
end
-
+
delivery = File.join(Mail.delivery_method.settings[:location], 'marcel@amont.com')
-
+
expect(File.read(delivery)).to eq mail.encoded
end
it "should send multiple emails to multiple files" do
Mail.defaults do
delivery_method :file, :location => tmpdir
end
-
+
mail = Mail.deliver do
from 'roger@moore.com'
to 'marcel@amont.com, bob@me.com'
subject 'invalid RFC2822'
end
-
+
delivery_one = File.join(Mail.delivery_method.settings[:location], 'marcel@amont.com')
delivery_two = File.join(Mail.delivery_method.settings[:location], 'bob@me.com')
-
+
expect(File.read(delivery_one)).to eq mail.encoded
expect(File.read(delivery_two)).to eq mail.encoded
end
@@ -64,29 +64,29 @@
Mail.defaults do
delivery_method :file, :location => tmpdir
end
-
+
Mail.deliver do
from 'roger@moore.com'
to '"Long, stupid email address" <mikel@test.lindsaar.net>'
subject 'invalid RFC2822'
end
delivery = File.join(Mail.delivery_method.settings[:location], 'mikel@test.lindsaar.net')
- expect(File.exists?(delivery)).to be_truthy
+ expect(File.exist?(delivery)).to be_truthy
end
it "should use the base name of the file name to prevent file system traversal" do
Mail.defaults do
delivery_method :file, :location => tmpdir
end
-
+
Mail.deliver do
from 'roger@moore.com'
to '../../../../../../../../../../../tmp/pwn'
subject 'evil hacker'
end
delivery = File.join(Mail.delivery_method.settings[:location], 'pwn')
- expect(File.exists?(delivery)).to be_truthy
+ expect(File.exist?(delivery)).to be_truthy
end
it "should raise an error if no sender is defined" do
@@ -118,5 +118,5 @@
end
end
-
+
end
View
10 spec/spec_helper.rb
@@ -30,7 +30,15 @@
# NOTE: We set the KCODE manually here in 1.8.X because upgrading to rspec-2.8.0 caused it
# to default to "NONE" (Why!?).
$KCODE='UTF8' if RUBY_VERSION < '1.9'
-Encoding.default_external = 'utf-8' if defined?(Encoding) && Encoding.respond_to?(:default_external=)
+if defined?(Encoding) && Encoding.respond_to?(:default_external=)
+ begin
+ old, $VERBOSE = $VERBOSE, nil
+ Encoding.default_external = 'utf-8'
+ ensure
+ $VERBOSE = old
+ end
+end
+
def fixture(*name)
File.join(SPEC_ROOT, 'fixtures', name)

0 comments on commit 1fbb948

Please sign in to comment.