diff --git a/iruby.gemspec b/iruby.gemspec
index 9fee5a0..cfebb8d 100644
--- a/iruby.gemspec
+++ b/iruby.gemspec
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
s.add_dependency 'bond', '~> 0.5'
s.add_dependency 'data_uri', '~> 0.1'
s.add_dependency 'ffi-rzmq'
- s.add_dependency 'mimemagic', '~> 0.3'
+ s.add_dependency 'mime-types', '>= 3.3.1'
s.add_dependency 'multi_json', '~> 1.11'
s.add_development_dependency 'pycall', '>= 1.2.1'
diff --git a/lib/iruby.rb b/lib/iruby.rb
index bd68b1a..480cf8c 100644
--- a/lib/iruby.rb
+++ b/lib/iruby.rb
@@ -1,4 +1,4 @@
-require 'mimemagic'
+require 'mime/types'
require 'multi_json'
require 'securerandom'
require 'openssl'
diff --git a/lib/iruby/display.rb b/lib/iruby/display.rb
index f312a55..340a437 100644
--- a/lib/iruby/display.rb
+++ b/lib/iruby/display.rb
@@ -44,7 +44,7 @@ def clear_output(wait = false)
private
def protect(mime, data)
- MimeMagic.new(mime).text? ? data.to_s : [data.to_s].pack('m0')
+ MIME::Type.new(mime).ascii? ? data.to_s : [data.to_s].pack('m0')
end
def render(data, obj, exact_mime, fuzzy_mime)
@@ -304,7 +304,7 @@ def format(mime = nil, &block)
match { |obj| obj.respond_to?(:path) && obj.method(:path).arity == 0 && File.readable?(obj.path) }
format do |obj|
- mime = MimeMagic.by_path(obj.path).to_s
+ mime = MIME::Types.of(obj.path).first.to_s
[mime, File.read(obj.path)] if SUPPORTED_MIMES.include?(mime)
end
diff --git a/test/iruby/mime_test.rb b/test/iruby/mime_test.rb
new file mode 100644
index 0000000..81a4419
--- /dev/null
+++ b/test/iruby/mime_test.rb
@@ -0,0 +1,32 @@
+class IRubyTest::MimeTest < IRubyTest::TestBase
+ sub_test_case("IRuby::Display") do
+ def test_display_with_mime_type
+ html = "Bold Text"
+
+ obj = Object.new
+ obj.define_singleton_method(:to_s) { html }
+
+ res = IRuby::Display.display(obj, mime: "text/html")
+ assert_equal({ plain: obj.inspect, html: html },
+ { plain: res["text/plain"], html: res["text/html"] })
+ end
+ end
+
+ sub_test_case("Rendering a file") do
+ def setup
+ @html = "Bold Text"
+ Dir.mktmpdir do |tmpdir|
+ @file = File.join(tmpdir, "test.html")
+ File.write(@file, @html)
+ yield
+ end
+ end
+
+ def test_display
+ File.open(@file, "rb") do |f|
+ res = IRuby::Display.display(f)
+ assert_equal(@html, res["text/html"])
+ end
+ end
+ end
+end