Skip to content

Commit ff36f17

Browse files
committed
Add a test case to examine mime type handling
1 parent 5bd57ec commit ff36f17

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

test/iruby/mime_test.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
class IRubyTest::MimeTest < IRubyTest::TestBase
2+
sub_test_case("IRuby::Display") do
3+
def test_display_with_mime_type
4+
html = "<b>Bold Text</b>"
5+
6+
obj = Object.new
7+
obj.define_singleton_method(:to_s) { html }
8+
9+
res = IRuby::Display.display(obj, mime: "text/html")
10+
assert_equal({ plain: obj.inspect, html: html },
11+
{ plain: res["text/plain"], html: res["text/html"] })
12+
end
13+
end
14+
15+
sub_test_case("Rendering a file") do
16+
def setup
17+
@html = "<b>Bold Text</b>"
18+
Dir.mktmpdir do |tmpdir|
19+
@file = File.join(tmpdir, "test.html")
20+
File.write(@file, @html)
21+
yield
22+
end
23+
end
24+
25+
def test_display
26+
File.open(@file, "rb") do |f|
27+
res = IRuby::Display.display(f)
28+
assert_equal(@html, res["text/html"])
29+
end
30+
end
31+
end
32+
end

0 commit comments

Comments
 (0)