Commit cdf85a20 by Prem Sichanugrist

Add test helper for assert file existence

parent 3275f690
...@@ -28,15 +28,15 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -28,15 +28,15 @@ class AttachmentTest < Test::Unit::TestCase
dummy.avatar = file dummy.avatar = file
dummy.save dummy.save
assert File.exists?(dummy.avatar.path(:small)) assert_file_exists(dummy.avatar.path(:small))
assert File.exists?(dummy.avatar.path(:large)) assert_file_exists(dummy.avatar.path(:large))
assert File.exists?(dummy.avatar.path(:original)) assert_file_exists(dummy.avatar.path(:original))
dummy.avatar.reprocess!(:small) dummy.avatar.reprocess!(:small)
assert File.exists?(dummy.avatar.path(:small)) assert_file_exists(dummy.avatar.path(:small))
assert File.exists?(dummy.avatar.path(:large)) assert_file_exists(dummy.avatar.path(:large))
assert File.exists?(dummy.avatar.path(:original)) assert_file_exists(dummy.avatar.path(:original))
end end
should "handle a boolean second argument to #url" do should "handle a boolean second argument to #url" do
...@@ -957,7 +957,7 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -957,7 +957,7 @@ class AttachmentTest < Test::Unit::TestCase
should "commit the files to disk" do should "commit the files to disk" do
[:large, :medium, :small].each do |style| [:large, :medium, :small].each do |style|
assert File.exists?(@attachment.path(style)) assert_file_exists(@attachment.path(style))
end end
end end
...@@ -989,7 +989,7 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -989,7 +989,7 @@ class AttachmentTest < Test::Unit::TestCase
@attachment.expects(:instance_write).with(:updated_at, nil) @attachment.expects(:instance_write).with(:updated_at, nil)
@attachment.assign nil @attachment.assign nil
@attachment.save @attachment.save
@existing_names.each{|f| assert ! File.exists?(f) } @existing_names.each{|f| assert_file_not_exists(f) }
end end
should "delete the files when you call #clear and #save" do should "delete the files when you call #clear and #save" do
...@@ -1000,7 +1000,7 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -1000,7 +1000,7 @@ class AttachmentTest < Test::Unit::TestCase
@attachment.expects(:instance_write).with(:updated_at, nil) @attachment.expects(:instance_write).with(:updated_at, nil)
@attachment.clear @attachment.clear
@attachment.save @attachment.save
@existing_names.each{|f| assert ! File.exists?(f) } @existing_names.each{|f| assert_file_not_exists(f) }
end end
should "delete the files when you call #delete" do should "delete the files when you call #delete" do
...@@ -1010,7 +1010,7 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -1010,7 +1010,7 @@ class AttachmentTest < Test::Unit::TestCase
@attachment.expects(:instance_write).with(:fingerprint, nil) @attachment.expects(:instance_write).with(:fingerprint, nil)
@attachment.expects(:instance_write).with(:updated_at, nil) @attachment.expects(:instance_write).with(:updated_at, nil)
@attachment.destroy @attachment.destroy
@existing_names.each{|f| assert ! File.exists?(f) } @existing_names.each{|f| assert_file_not_exists(f) }
end end
context "when keeping old files" do context "when keeping old files" do
...@@ -1026,7 +1026,7 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -1026,7 +1026,7 @@ class AttachmentTest < Test::Unit::TestCase
@attachment.expects(:instance_write).with(:updated_at, nil) @attachment.expects(:instance_write).with(:updated_at, nil)
@attachment.assign nil @attachment.assign nil
@attachment.save @attachment.save
@existing_names.each{|f| assert File.exists?(f) } @existing_names.each{|f| assert_file_exists(f) }
end end
should "keep the files when you call #clear and #save" do should "keep the files when you call #clear and #save" do
...@@ -1037,7 +1037,7 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -1037,7 +1037,7 @@ class AttachmentTest < Test::Unit::TestCase
@attachment.expects(:instance_write).with(:updated_at, nil) @attachment.expects(:instance_write).with(:updated_at, nil)
@attachment.clear @attachment.clear
@attachment.save @attachment.save
@existing_names.each{|f| assert File.exists?(f) } @existing_names.each{|f| assert_file_exists(f) }
end end
should "keep the files when you call #delete" do should "keep the files when you call #delete" do
...@@ -1047,7 +1047,7 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -1047,7 +1047,7 @@ class AttachmentTest < Test::Unit::TestCase
@attachment.expects(:instance_write).with(:fingerprint, nil) @attachment.expects(:instance_write).with(:fingerprint, nil)
@attachment.expects(:instance_write).with(:updated_at, nil) @attachment.expects(:instance_write).with(:updated_at, nil)
@attachment.destroy @attachment.destroy
@existing_names.each{|f| assert File.exists?(f) } @existing_names.each{|f| assert_file_exists(f) }
end end
end end
end end
...@@ -1206,12 +1206,12 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -1206,12 +1206,12 @@ class AttachmentTest < Test::Unit::TestCase
should "not delete the files from storage when attachment is destroyed" do should "not delete the files from storage when attachment is destroyed" do
@attachment.destroy @attachment.destroy
assert File.exists?(@path) assert_file_exists(@path)
end end
should "not delete the file when model is destroyed" do should "not delete the file when model is destroyed" do
@dummy.destroy @dummy.destroy
assert File.exists?(@path) assert_file_exists(@path)
end end
end end
...@@ -1235,12 +1235,12 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -1235,12 +1235,12 @@ class AttachmentTest < Test::Unit::TestCase
@dummy.destroy @dummy.destroy
end end
assert File.exists?(@path), "#{@path} does not exist." assert_file_exists(@path)
end end
should "be deleted when the model is destroyed" do should "be deleted when the model is destroyed" do
@dummy.destroy @dummy.destroy
assert ! File.exists?(@path), "#{@path} does not exist." assert_file_not_exists(@path)
end end
end end
......
...@@ -177,3 +177,11 @@ def assert_not_found_response(url) ...@@ -177,3 +177,11 @@ def assert_not_found_response(url)
"Expected HTTP response code 404, got #{response.code}" "Expected HTTP response code 404, got #{response.code}"
end end
end end
def assert_file_exists(path)
assert File.exists?(path), %(Expect "#{path}" to be exists.)
end
def assert_file_not_exists(path)
assert !File.exists?(path), %(Expect "#{path}" to not exists.)
end
...@@ -96,14 +96,14 @@ class IntegrationTest < Test::Unit::TestCase ...@@ -96,14 +96,14 @@ class IntegrationTest < Test::Unit::TestCase
@dummy.avatar.post_processing = false @dummy.avatar.post_processing = false
@dummy.avatar = @file @dummy.avatar = @file
assert @dummy.save assert @dummy.save
assert !File.exists?(@thumb_path) assert_file_not_exists @thumb_path
end end
should "create the thumbnails upon saving when post_processing is enabled" do should "create the thumbnails upon saving when post_processing is enabled" do
@dummy.avatar.post_processing = true @dummy.avatar.post_processing = true
@dummy.avatar = @file @dummy.avatar = @file
assert @dummy.save assert @dummy.save
assert File.exists?(@thumb_path) assert_file_exists @thumb_path
end end
end end
...@@ -126,25 +126,25 @@ class IntegrationTest < Test::Unit::TestCase ...@@ -126,25 +126,25 @@ class IntegrationTest < Test::Unit::TestCase
teardown { @file.close } teardown { @file.close }
should "allow us to create all thumbnails in one go" do should "allow us to create all thumbnails in one go" do
assert !File.exists?(@thumb_small_path) assert_file_not_exists(@thumb_small_path)
assert !File.exists?(@thumb_large_path) assert_file_not_exists(@thumb_large_path)
@dummy.avatar.reprocess! @dummy.avatar.reprocess!
assert File.exists?(@thumb_small_path) assert_file_exists(@thumb_small_path)
assert File.exists?(@thumb_large_path) assert_file_exists(@thumb_large_path)
end end
should "allow us to selectively create each thumbnail" do should "allow us to selectively create each thumbnail" do
assert !File.exists?(@thumb_small_path) assert_file_not_exists(@thumb_small_path)
assert !File.exists?(@thumb_large_path) assert_file_not_exists(@thumb_large_path)
@dummy.avatar.reprocess! :thumb_small @dummy.avatar.reprocess! :thumb_small
assert File.exists?(@thumb_small_path) assert_file_exists(@thumb_small_path)
assert !File.exists?(@thumb_large_path) assert_file_not_exists(@thumb_large_path)
@dummy.avatar.reprocess! :thumb_large @dummy.avatar.reprocess! :thumb_large
assert File.exists?(@thumb_large_path) assert_file_exists(@thumb_large_path)
end end
end end
...@@ -182,7 +182,7 @@ class IntegrationTest < Test::Unit::TestCase ...@@ -182,7 +182,7 @@ class IntegrationTest < Test::Unit::TestCase
end end
should "have a large file in the right place" do should "have a large file in the right place" do
assert File.exists?(@dummy.avatar.path(:large)) assert_file_exists(@dummy.avatar.path(:large))
end end
context "and deleted" do context "and deleted" do
...@@ -192,12 +192,12 @@ class IntegrationTest < Test::Unit::TestCase ...@@ -192,12 +192,12 @@ class IntegrationTest < Test::Unit::TestCase
end end
should "not have a large file in the right place anymore" do should "not have a large file in the right place anymore" do
assert ! File.exists?(@saved_path) assert_file_not_exists(@saved_path)
end end
should "not have its next two parent directories" do should "not have its next two parent directories" do
assert ! File.exists?(File.dirname(@saved_path)) assert_file_not_exists(File.dirname(@saved_path))
assert ! File.exists?(File.dirname(File.dirname(@saved_path))) assert_file_not_exists(File.dirname(File.dirname(@saved_path)))
end end
before_should "not die if an unexpected SystemCallError happens" do before_should "not die if an unexpected SystemCallError happens" do
...@@ -334,7 +334,7 @@ class IntegrationTest < Test::Unit::TestCase ...@@ -334,7 +334,7 @@ class IntegrationTest < Test::Unit::TestCase
assert @dummy.save assert @dummy.save
saved_paths.each do |p| saved_paths.each do |p|
assert File.exists?(p) assert_file_exists(p)
end end
@dummy.avatar.clear @dummy.avatar.clear
...@@ -343,7 +343,7 @@ class IntegrationTest < Test::Unit::TestCase ...@@ -343,7 +343,7 @@ class IntegrationTest < Test::Unit::TestCase
assert @dummy.save assert @dummy.save
saved_paths.each do |p| saved_paths.each do |p|
assert ! File.exists?(p) assert_file_not_exists(p)
end end
@d2 = Dummy.find(@dummy.id) @d2 = Dummy.find(@dummy.id)
...@@ -364,7 +364,7 @@ class IntegrationTest < Test::Unit::TestCase ...@@ -364,7 +364,7 @@ class IntegrationTest < Test::Unit::TestCase
assert @d2.save assert @d2.save
saved_paths.each do |p| saved_paths.each do |p|
assert ! File.exists?(p) assert_file_not_exists(p)
end end
end end
...@@ -457,8 +457,8 @@ class IntegrationTest < Test::Unit::TestCase ...@@ -457,8 +457,8 @@ class IntegrationTest < Test::Unit::TestCase
end end
should "be accessible" do should "be accessible" do
assert File.exists?(@dummy.avatar.path(:original)) assert_file_exists(@dummy.avatar.path(:original))
assert File.exists?(@dummy.avatar.path(:thumb)) assert_file_exists(@dummy.avatar.path(:thumb))
end end
context "when new style is added" do context "when new style is added" do
...@@ -469,9 +469,9 @@ class IntegrationTest < Test::Unit::TestCase ...@@ -469,9 +469,9 @@ class IntegrationTest < Test::Unit::TestCase
end end
should "make all the styles accessible" do should "make all the styles accessible" do
assert File.exists?(@dummy.avatar.path(:original)) assert_file_exists(@dummy.avatar.path(:original))
assert File.exists?(@dummy.avatar.path(:thumb)) assert_file_exists(@dummy.avatar.path(:thumb))
assert File.exists?(@dummy.avatar.path(:mini)) assert_file_exists(@dummy.avatar.path(:mini))
end end
end end
end end
......
...@@ -19,12 +19,12 @@ class FileSystemTest < Test::Unit::TestCase ...@@ -19,12 +19,12 @@ class FileSystemTest < Test::Unit::TestCase
should "store the original" do should "store the original" do
@dummy.save @dummy.save
assert File.exists?(@dummy.avatar.path) assert_file_exists(@dummy.avatar.path)
end end
should "store the thumbnail" do should "store the thumbnail" do
@dummy.save @dummy.save
assert File.exists?(@dummy.avatar.path(:thumbnail)) assert_file_exists(@dummy.avatar.path(:thumbnail))
end end
end end
...@@ -41,7 +41,7 @@ class FileSystemTest < Test::Unit::TestCase ...@@ -41,7 +41,7 @@ class FileSystemTest < Test::Unit::TestCase
teardown { @file.close } teardown { @file.close }
should "store the file" do should "store the file" do
assert File.exists?(@dummy.avatar.path) assert_file_exists(@dummy.avatar.path)
end end
should "return a replaced version for path" do should "return a replaced version for path" do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment