require 'spec_helper' describe String do describe "#camelize" do it "to be ExampleString" do expect("example_string".camelize).to eq("ExampleString") end it "to be exampleString" do expect("example_string".camelize(:lower)).to eq("exampleString") end end describe "#ends_with?" do it "to be true" do expect("".ends_with?("")).to eq(true) expect(" ".ends_with?(" ")).to eq(true) expect(" ".ends_with?("")).to eq(true) expect("example string".ends_with?("g")).to eq(true) expect("example string".ends_with?("ng")).to eq(true) end it "to be false" do expect("".ends_with?(" ")).to eq(false) expect("e ".ends_with?("e")).to eq(false) expect("example string".ends_with?("x")).to eq(false) end end describe "#humanize" do it "to be Example string test" do expect("example_string_test".humanize).to eq("Example string test") expect("exampleStringTest".humanize).to eq("Example string test") expect("ExampleStringTest".humanize).to eq("Example string test") end end describe "#starts_with?" do it "to be true" do expect("".starts_with?("")).to eq(true) expect(" ".starts_with?(" ")).to eq(true) expect(" ".starts_with?("")).to eq(true) expect("example string".starts_with?("e")).to eq(true) expect("example string".starts_with?("ex")).to eq(true) end it "to be false" do expect("".starts_with?(" ")).to eq(false) expect(" e".starts_with?("e")).to eq(false) expect("example string".starts_with?("x")).to eq(false) end end describe "#titleize" do it "to be Example String Test" do expect("example string test".titleize).to eq("Example String Test") expect("Example string Test".titleize).to eq("Example String Test") expect("ExampleStringTest".titleize).to eq("Example String Test") expect("Example_string_test".titleize).to eq("Example String Test") end end describe "#underscore" do it "to be example_string" do expect("ExampleString".underscore).to eq("example_string") expect("exampleString".underscore).to eq("example_string") expect("example_string".underscore).to eq("example_string") expect("example_String".underscore).to eq("example_string") end end describe "#domain" do it "to be test" do expect("".domain).to eq("") expect(" ".domain).to eq(" ") expect("example string".domain).to eq("example string") expect("http://www.example.com".domain).to eq("www.example.com") expect("http://www.example.com/fake-page".domain).to eq("www.example.com") end end describe "#downcase?" do it "to be true" do expect("downcase".downcase?).to eq(true) expect("downcase string".downcase?).to eq(true) end it "to be false" do expect("Mixedcase".downcase?).to eq(false) expect("UPCASE".downcase?).to eq(false) expect("Mixedcase string".downcase?).to eq(false) end end describe "#ellipsize" do it "to be example string" do expect("example string".ellipsize).to eq("example string") end it "to be 0123...WXYZ" do expect("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".ellipsize).to eq("0123...WXYZ") end it "to be 012...XYZ" do expect("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".ellipsize(length: 50)).to eq("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ") end it "to be 012...XYZ" do expect("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".ellipsize(offset: 3)).to eq("012...XYZ") end it "to be 0123+++WXYZ" do expect("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".ellipsize(separator: "+++")).to eq("0123+++WXYZ") end end describe "#gnix" do it "to be this that " do expect("this thing that thing".gnix("thing")).to eq("this that ") end end describe "#mixedcase?" do it "to be true" do expect("Mixedcase".mixedcase?).to eq(true) expect("Mixedcase STRING type".mixedcase?).to eq(true) end it "to be false" do expect("downcase".mixedcase?).to eq(false) expect("UPCASE".mixedcase?).to eq(false) end end describe "#nix" do it "to be this that thing" do expect("this thing that thing".nix("thing")).to eq("this that thing") end end describe "#pollute" do it "to be t^--^--^e^--^--^s^--^--^t^--^--^" do expect("test".pollute).to eq("t^--^--^e^--^--^s^--^--^t^--^--^") end it "to be t-e-s-t-" do expect("test".pollute("-")).to eq("t-e-s-t-") end end describe "#unpollute" do it "to be test" do expect("test".unpollute).to eq("test") end it "to be test" do expect("t-e-s-t-".unpollute("-")).to eq("test") end end describe "#pollute then #unpollute" do it "to be test" do expect("test".pollute.unpollute).to eq("test") end it "to be test" do expect("t-e-s-t-".pollute("-").unpollute("-")).to eq("test") end end describe "#slugify" do it "to be example" do expect("example".slugify).to eq("example") end it "to be example-string" do expect("example string".slugify).to eq("example-string") end it "to be example-string-test" do expect("Example string @@@ test!".slugify).to eq("example-string-test") end it "to be a-real-doozie" do expect(" A REal Doozi\"e? \' ".slugify).to eq("a-real-doozie") end end describe "#strip_tags" do it "to be example" do expect("example".strip_tags).to eq("example") end it "to be click" do expect("click".strip_tags).to eq("click") end it "to be this is bold and emphatic" do expect("this is bold and emphatic".strip_tags).to eq("this is bold and emphatic") end end describe "#strip_tags" do it "to be example" do expect("example string test".strip_whitespace).to eq("example string test") expect(" this \t is also a test ".strip_whitespace).to eq("this is also a test") end end describe "#truncate_preserving_words" do it "to be example string" do expect("example string".truncate_preserving_words).to eq("example string") expect("example string".truncate_preserving_words(max_words: 10)).to eq("example string") expect("example string".truncate_preserving_words(:max_chars => 15, :end_string => "..")).to eq("example string") end it "to be example string" do expect("example string test another1 another2 another3".truncate_preserving_words).to eq("example string test another1 ...") expect("example string test".truncate_preserving_words(max_words: 2)).to eq("example string ...") expect("example string test".truncate_preserving_words(max_chars: 10, separator: "+++")).to eq("example +++") end end describe "#upcase?" do it "to be true" do expect("UPCASE".upcase?).to eq(true) expect("UPCASE STRING".upcase?).to eq(true) end it "to be false" do expect("downcase".upcase?).to eq(false) expect("Mixedcase".upcase?).to eq(false) expect("Mixedcase string".upcase?).to eq(false) end end end