Sha256: 29e9a16efd7a01b33cf8961c7ef37737778587792ec73f48f03c40db7cdfc69b

Contents?: true

Size: 1.99 KB

Versions: 2

Compression:

Stored size: 1.99 KB

Contents

# encoding: utf-8
require 'spec_helper'

describe ActiveCleaner::MarkdownCleaner do

  let(:cleaner) { ActiveCleaner::MarkdownCleaner.new(:body) }

  describe "#clean_value" do

    it "doesn't touch legit value" do
      body = ""
      body << "= Title =\n"
      body << "\n"
      body << "A first paragraph.\n"
      body << "\n"
      body << "A **second** one, with a\n"
      body << "line break.\n"
      body << "\n"
      body << " * first item\n"
      body << " * second item\n"
      body << "\n"
      body << "    <div id=\"test\">\n"
      body << "      <p>Text</p>\n"
      body << "    </div>\n"
      body << "\n"
      body << "A third paragraph."

      expect(cleaner.clean_value(body)).to eq(body)
    end

    it "empties string full of spaces" do
      [
        "",
        " ",
        "\t",
        "\n",
        " \t\n \t\n \t\n \t\n",
      ].each do |title|
        expect(cleaner.clean_value(title)).to eq("")
      end
    end

    it "cleans repeted spaces" do
      expect(cleaner.clean_value("Lorem   ipsum   \ndolor   sit   amet.")).to eq("Lorem ipsum\ndolor sit amet.")
      expect(cleaner.clean_value("Lorem \t ipsum \t \ndolor \t sit \t amet.")).to eq("Lorem ipsum\ndolor sit amet.")
    end

    context "considering the spaces in the beggining of lines" do
      it "preserves them" do
        expect(cleaner.clean_value("Lorem ipsum\n   dolor sit amet.")).to eq("Lorem ipsum\n   dolor sit amet.")
      end
      it "clears line full of spaces" do
        expect(cleaner.clean_value("Lorem ipsum   \n   \n   dolor sit amet.")).to eq("Lorem ipsum\n\n   dolor sit amet.")
      end
    end

    it "keeps two max succeeding new line" do
      expect(cleaner.clean_value("Lorem ipsum\n\n\ndolor sit amet.")).to eq("Lorem ipsum\n\ndolor sit amet.")
      expect(cleaner.clean_value("Lorem ipsum\n\n\n\ndolor sit amet.")).to eq("Lorem ipsum\n\ndolor sit amet.")
      expect(cleaner.clean_value("Lorem ipsum\n  \n  \n  \ndolor sit amet.")).to eq("Lorem ipsum\n\ndolor sit amet.")
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
activecleaner-0.3.0 spec/lib/active_cleaner/markdown_cleaner_spec.rb
activecleaner-0.2.0 spec/lib/active_cleaner/markdown_cleaner_spec.rb