Sha256: f9b2894d868cf899ee13a692dc940be9e51235773eeb6011269917a4fba319d2

Contents?: true

Size: 1.68 KB

Versions: 2

Compression:

Stored size: 1.68 KB

Contents

# encoding: utf-8
require 'spec_helper'

describe ActiveCleaner::TextCleaner do

  let(:cleaner) { ActiveCleaner::TextCleaner.new(:text) }

  describe "#clean_value" do

    it "doesn't touch legit value" do
      [
        "Lorem ipsum dolor sit amet.",
        "Lorem ipsum\ndolor sit amet.",
        "Lorem ipsum\n\ndolor sit amet.",
      ].each do |text|
        expect(cleaner.clean_value(text)).to eq(text)
      end
    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 leading and trailing spaces" do
      expect(cleaner.clean_value(" Lorem ipsum\ndolor sit amet. ")).to eq("Lorem ipsum\ndolor sit amet.")
    end
    it "cleans leading and trailing tabs" do
      expect(cleaner.clean_value("\tLorem ipsum\ndolor sit amet.\t")).to eq("Lorem ipsum\ndolor sit amet.")
    end
    it "cleans leading and trailing lines" do
      expect(cleaner.clean_value("\nLorem ipsum\ndolor sit amet.\n")).to eq("Lorem ipsum\ndolor sit amet.")
    end

    it "cleans repeted spaces" do
      expect(cleaner.clean_value("Lorem   ipsum   \n   dolor   sit   amet.")).to eq("Lorem ipsum\ndolor sit amet.")
      expect(cleaner.clean_value("Lorem \t ipsum \t \n   dolor \t sit \t amet.")).to eq("Lorem ipsum\ndolor sit amet.")
    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.")
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

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