test/gettext-test-utils.rb in gettext-2.3.0 vs test/gettext-test-utils.rb in gettext-2.3.1
- old
+ new
@@ -20,10 +20,14 @@
require "fileutils"
require "tmpdir"
require "tempfile"
require "time"
+unless String.method_defined?(:encode)
+ require "iconv"
+end
+
require "gettext"
module GetTextTestUtils
module_function
def fixture_path(*components)
@@ -38,7 +42,26 @@
@tmpdir = Dir.mktmpdir
end
def teardown_tmpdir
FileUtils.rm_rf(@tmpdir, :secure => true) if @tmpdir
+ end
+
+ def need_encoding
+ unless defined?(Encoding)
+ omit("This test needs encoding.")
+ end
+ end
+
+ def set_encoding(string, encoding)
+ return unless string.respond_to?(:force_encoding)
+ string.force_encoding(encoding)
+ end
+
+ def encode(string, encoding)
+ if string.respond_to?(:encode)
+ string.encode(encoding)
+ else
+ Iconv.iconv(encoding, "UTF-8", string).join("")
+ end
end
end