spec/pricecut/elements/text_spec.rb in pricecut-0.0.2 vs spec/pricecut/elements/text_spec.rb in pricecut-0.0.3
- old
+ new
@@ -1,20 +1,73 @@
require "spec_helper"
require "pricecut"
describe Pricecut::Elements::Text do
let(:visitor) { Pricecut::MarkdownVisitor.new }
+ let(:root) { parse %<\n This is \n text.\n > }
- let(:root) do
- parse %<\n\nText.\n\n>
- end
-
subject { described_class.new(visitor, root) }
describe "#output!" do
- it "appends the whitespace-stripped text to the output" do
- subject.output!
+ describe "with only whitespace" do
+ before { subject.stub(:whitespace_only?) { true } }
- visitor.output.should eq("Text.")
+ 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