Sha256: bf1d9daab2025f9a31812d006dbfb5362e5dc5d6492d45d984384ec1a178ed61

Contents?: true

Size: 1.8 KB

Versions: 1

Compression:

Stored size: 1.8 KB

Contents

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pricecut-0.0.3 spec/pricecut/elements/text_spec.rb