@@ -3,7 +3,7 @@ require "../src/html/builder"
33
44describe HTML ::Builder do
55 it " builds html" do
6- str = HTML :: Builder .build do
6+ str = HTML .build do
77 doctype
88 html do
99 head do
@@ -20,8 +20,18 @@ describe HTML::Builder do
2020 str.should eq %( <!DOCTYPE html><html><head><title>Crystal Programming Language</title></head><body><a href="http://crystal-lang.org">Crystal rocks!</a><form method="POST"><input name="name"></form></body></html>)
2121 end
2222
23+ it " builds html to IO" do
24+ io = IO ::Memory .new
25+ HTML .build(io) do
26+ doctype
27+ html do
28+ end
29+ end
30+ io.to_s.should eq %( <!DOCTYPE html><html></html>)
31+ end
32+
2333 it " builds html with some tag attributes" do
24- str = HTML :: Builder .new .build do
34+ str = HTML .build do
2535 a(href: " http://crystal-lang.org" , class: " crystal" , id: " main" ) do
2636 text " Crystal rocks!"
2737 end
@@ -30,7 +40,7 @@ describe HTML::Builder do
3040 end
3141
3242 it " builds html with some tag attributes, using a hash" do
33- str = HTML :: Builder .new .build do
43+ str = HTML .build do
3444 a(href: " http://crystal-lang.org" , class: " crystal" , id: " main" ) do
3545 text " Crystal rocks!"
3646 end
@@ -39,7 +49,7 @@ describe HTML::Builder do
3949 end
4050
4151 it " builds html with some tag attributes, using a named tuple" do
42- str = HTML :: Builder .new .build do |builder |
52+ str = HTML .build do |builder |
4353 builder.a({href: " http://crystal-lang.org" , class: " crystal" , id: " main" }) do
4454 text " Crystal rocks!"
4555 end
@@ -48,28 +58,28 @@ describe HTML::Builder do
4858 end
4959
5060 it " builds html with an provided html string" do
51- str = HTML :: Builder .new .build do
61+ str = HTML .build do
5262 html " <section>Crystal rocks!</section>"
5363 end
5464 str.should eq %( <section>Crystal rocks!</section>)
5565 end
5666
5767 it " builds html with a custom tag with attributes" do
58- str = HTML :: Builder .new .build do
68+ str = HTML .build do
5969 tag(" section" , class: " crystal" ) { text " Crystal rocks!" }
6070 end
6171 str.should eq %( <section class="crystal">Crystal rocks!</section>)
6272 end
6373
6474 it " escapes attribute values" do
65- str = HTML :: Builder .new .build do
75+ str = HTML .build do
6676 a(href: " <>" ) { }
6777 end
6878 str.should eq %( <a href="<>"></a>)
6979 end
7080
7181 it " escapes text" do
72- str = HTML :: Builder .new .build do
82+ str = HTML .build do
7383 a { text " <>" }
7484 end
7585 str.should eq %( <a><></a>)
0 commit comments