require 'spec_helper'
describe DocxGenerator::DSL::Text do
describe "#new" do
it "should require some text" do
expect { DocxGenerator::DSL::Text.new }.to raise_error
end
context "with a block" do
it "should pass itself to a block" do
inner_text = nil
text = DocxGenerator::DSL::Text.new("") do |t|
inner_text = t
end
inner_text.should be(text)
end
end
end
describe "#generate" do
it "should return a new Run with text in it" do
text_fragment = DocxGenerator::DSL::Text.new("Title")
text_fragment.generate.to_s.should eq("Title")
end
context "with styles" do
it "should return a text in bold" do
DocxGenerator::DSL::Text.new("Text", bold: true).generate.to_s.should eq("Text")
(DocxGenerator::DSL::Text.new("Text") { |t| t.bold true }).generate.to_s.should eq("Text")
end
it "should return a text in italics" do
DocxGenerator::DSL::Text.new("Text", italics: true).generate.to_s.should eq("Text")
(DocxGenerator::DSL::Text.new("Text") { |t| t.italics true }).generate.to_s.should eq("Text")
end
it "should return an underlined text" do
DocxGenerator::DSL::Text.new("Text", underline: { style: "single" }).generate.to_s.should eq("Text")
(DocxGenerator::DSL::Text.new("Text") { |t| t.underline style: "single" }).generate.to_s.should eq("Text")
end
it "should return a text with a font size" do
DocxGenerator::DSL::Text.new("Text", size: 20).generate.to_s.should eq("Text")
(DocxGenerator::DSL::Text.new("Text") { |t| t.size 20 }).generate.to_s.should eq("Text")
end
it "should render a text in superscript" do
DocxGenerator::DSL::Text.new("Text", superscript: true).generate.to_s.should eq("Text")
(DocxGenerator::DSL::Text.new("Text") { |t| t.superscript true }).generate.to_s.should eq("Text")
end
it "should render a text in subscript" do
DocxGenerator::DSL::Text.new("Text", subscript: true).generate.to_s.should eq("Text")
(DocxGenerator::DSL::Text.new("Text") { |t| t.subscript true }).generate.to_s.should eq("Text")
end
it "shoud render a text as capital letters" do
DocxGenerator::DSL::Text.new("Text", caps: true).generate.to_s.should eq("Text")
(DocxGenerator::DSL::Text.new("Text") { |t| t.caps true }).generate.to_s.should eq("Text")
end
it "shoud render a text as small capital letters" do
DocxGenerator::DSL::Text.new("Text", small_caps: true).generate.to_s.should eq("Text")
(DocxGenerator::DSL::Text.new("Text") { |t| t.small_caps true }).generate.to_s.should eq("Text")
end
xit "shoud render a text with a single horizontal line through the center of the line" do
DocxGenerator::DSL::Text.new("Text", strike: true).generate.to_s.should eq("Text")
(DocxGenerator::DSL::Text.new("Text") { |t| t.strike true }).generate.to_s.should eq("Text")
end
xit "shoud render a text with two horizontal lines through the center of the line" do
DocxGenerator::DSL::Text.new("Text", dstrike: true).generate.to_s.should eq("Text")
(DocxGenerator::DSL::Text.new("Text") { |t| t.dstrike true }).generate.to_s.should eq("Text")
end
it "should render the name of the font" do
result = "Text"
DocxGenerator::DSL::Text.new("Text", font: "Arial").generate.to_s.should eq(result)
(DocxGenerator::DSL::Text.new("Text") { |t| t.font "Arial" }).generate.to_s.should eq(result)
end
end
end
describe "#to_s" do
it "should render the XML representation" do
text_fragment = DocxGenerator::DSL::Text.new("Title")
text_fragment.to_s.should eq("Title")
end
end
end