Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactoring tests: Closing tempfile in teardown and DRY the code.

  • Loading branch information...
commit 9c5e4b230311729357e0af51e816d87f966f0426 1 parent ec20e6a
janfri authored
14 test/helpers_for_test.rb
View
@@ -1,6 +1,8 @@
# -- encoding: utf-8 --
require 'mini_exiftool'
require 'test/unit'
+require 'fileutils'
+require 'tempfile'
begin
require 'turn'
rescue LoadError
@@ -12,3 +14,15 @@
end
include Test::Unit
+
+module TempfileTest
+ def setup
+ @temp_file = Tempfile.new('test')
+ @temp_filename = @temp_file.path
+ @data_dir = File.dirname(__FILE__) + '/data'
+ end
+
+ def teardown
+ @temp_file.close
+ end
+end
8 test/test_save.rb
View
@@ -6,11 +6,11 @@
class TestSave < TestCase
+ include TempfileTest
+
def setup
- @temp_file = Tempfile.new('test')
- @temp_file.close
- @temp_filename = @temp_file.path
- @org_filename = File.dirname(__FILE__) + '/data/test.jpg'
+ super
+ @org_filename = @data_dir + '/test.jpg'
FileUtils.cp(@org_filename, @temp_filename)
@mini_exiftool = MiniExiftool.new @temp_filename
@mini_exiftool_num = MiniExiftool.new @temp_filename, :numerical => true
13 test/test_special.rb
View
@@ -1,19 +1,16 @@
# -- encoding: utf-8 --
-require 'fileutils'
-require 'tempfile'
require 'helpers_for_test'
class TestSpecial < TestCase
+ include TempfileTest
+
CAPTION_ABSTRACT = 'Some text for caption abstract'
def setup
- data_dir = File.dirname(__FILE__) + '/data'
- temp_file = Tempfile.new('test')
- temp_file.close
- @temp_filename = temp_file.path
- org_filename = data_dir + '/Canon.jpg'
- FileUtils.cp org_filename, @temp_filename
+ super
+ @org_filename = @data_dir + '/Canon.jpg'
+ FileUtils.cp @org_filename, @temp_filename
@canon = MiniExiftool.new @temp_filename
end
15 test/test_special_dates.rb
View
@@ -1,18 +1,15 @@
# -- encoding: utf-8 --
require 'date'
-require 'fileutils'
-require 'tempfile'
require 'helpers_for_test'
class TestSpecialDates < TestCase
+ include TempfileTest
+
def setup
- data_dir = File.dirname(__FILE__) + '/data'
- temp_file = Tempfile.new('test')
- temp_file.close
- @temp_filename = temp_file.path
- org_filename = data_dir + '/test_special_dates.jpg'
- FileUtils.cp org_filename, @temp_filename
+ super
+ @org_filename = @data_dir + '/test_special_dates.jpg'
+ FileUtils.cp @org_filename, @temp_filename
@mini_exiftool = MiniExiftool.new @temp_filename
@mini_exiftool_datetime = MiniExiftool.new @temp_filename,
:timestamps => DateTime
@@ -21,7 +18,7 @@ def setup
# Catching bug [#16328] (1st part)
# Thanks to unknown
def test_datetime
- datetime_original = @mini_exiftool.datetime_original
+ datetime_original = @mini_exiftool.datetime_original
if datetime_original
assert_kind_of Time, datetime_original
else
Please sign in to comment.
Something went wrong with that request. Please try again.