require "spec_helper" require "pricecut" describe Pricecut::Elements::Text do let(:visitor) { Pricecut::MarkdownVisitor.new } let(:root) { parse %<\n This is \n text.\n > } subject { described_class.new(visitor, root) } describe "#output!" do describe "with only whitespace" do before { subject.stub(:whitespace_only?) { true } } it "does not append anything to the output" do subject.output! visitor.output.should be_empty end end describe "with ample whitespace" do before do subject.stub(:previous_sibling?) { false } subject.stub(:next_sibling?) { false } end it "removes insignificant whitespace and appends to the output" do subject.output! visitor.output.should eq("This is text.") end end describe "preceded by an HTML tag" do before do subject.stub(:previous_sibling?) { true } subject.stub(:next_sibling?) { false } end it "removes the subsequent whitespace and appends to the output" do subject.output! visitor.output.should eq(" This is text.") end end describe "succeeded by an HTML tag" do before do subject.stub(:previous_sibling?) { false } subject.stub(:next_sibling?) { true } end it "removes the preceding whitespace and appends to the output" do subject.output! visitor.output.should eq("This is text. ") end end describe "succeeded and preceded by an HTML tag" do before do subject.stub(:previous_sibling?) { true } subject.stub(:next_sibling?) { true } end it "leaves all whitespace and appends to the output" do subject.output! visitor.output.should eq(" This is text. ") end end end end