vendor/plugins/paperclip/test/iostream_test.rb in spree-0.8.5 vs vendor/plugins/paperclip/test/iostream_test.rb in spree-0.9.0
- old
+ new
@@ -1,13 +1,7 @@
-require 'rubygems'
-require 'test/unit'
-require 'stringio'
-require 'tempfile'
-require 'shoulda'
+require 'test/helper'
-require File.join(File.dirname(__FILE__), '..', 'lib', 'paperclip', 'iostream.rb')
-
class IOStreamTest < Test::Unit::TestCase
context "IOStream" do
should "be included in IO, File, Tempfile, and StringIO" do
[IO, File, Tempfile, StringIO].each do |klass|
assert klass.included_modules.include?(IOStream), "Not in #{klass}"
@@ -15,32 +9,49 @@
end
end
context "A file" do
setup do
- @file = File.new(File.join(File.dirname(__FILE__), "fixtures", "5k.png"))
+ @file = File.new(File.join(File.dirname(__FILE__), "fixtures", "5k.png"), 'rb')
end
+ teardown { @file.close }
+
context "that is sent #stream_to" do
- [["/tmp/iostream.string.test", File],
- [Tempfile.new('iostream.test'), Tempfile]].each do |args|
+ context "and given a String" do
+ setup do
+ FileUtils.mkdir_p(File.join(ROOT, 'tmp'))
+ assert @result = @file.stream_to(File.join(ROOT, 'tmp', 'iostream.string.test'))
+ end
- context "and given a #{args[0].class.to_s}" do
- setup do
- assert @result = @file.stream_to(args[0])
- end
+ should "return a File" do
+ assert @result.is_a?(File)
+ end
- should "return a #{args[1].to_s}" do
- assert @result.is_a?(args[1])
- end
+ should "contain the same data as the original file" do
+ @file.rewind; @result.rewind
+ assert_equal @file.read, @result.read
+ end
+ end
- should "contain the same data as the original file" do
- @file.rewind; @result.rewind
- assert_equal @file.read, @result.read
- end
+ context "and given a Tempfile" do
+ setup do
+ tempfile = Tempfile.new('iostream.test')
+ tempfile.binmode
+ assert @result = @file.stream_to(tempfile)
end
+
+ should "return a Tempfile" do
+ assert @result.is_a?(Tempfile)
+ end
+
+ should "contain the same data as the original file" do
+ @file.rewind; @result.rewind
+ assert_equal @file.read, @result.read
+ end
end
+
end
context "that is sent #to_tempfile" do
setup do
assert @tempfile = @file.to_tempfile