require "spec_helper" describe Goethe::Utils do describe ".remove_html_tags" do it "should replace html tags with space" do str = "

我爱你

" expect(Goethe::Utils.remove_html_tags(str)).to eq(" 我爱你 ") end it "should replace html char with space" do str = "

hello 

" expect(Goethe::Utils.remove_html_tags(str)).to eq(" hello ") end it "should replace html elements with given charater" do str = "

hello 

" expect(Goethe::Utils.remove_html_tags(str, :replacement => "**")).to eq("**hello****") end end describe ".remove_markdown_symbols" do it "should remove headers" do str = "#abc\n" expect(Goethe::Utils.remove_markdown_symbols(str)).to eq("abc\n") str = " #### abc\n" expect(Goethe::Utils.remove_markdown_symbols(str)).to eq("abc\n") str = "cba #### abc\n" expect(Goethe::Utils.remove_markdown_symbols(str)).to eq("cba #### abc\n") str = "abc\n===" expect(Goethe::Utils.remove_markdown_symbols(str)).to eq("abc\n") str = "abc\n---" expect(Goethe::Utils.remove_markdown_symbols(str)).to eq("abc\n") end context "Emphasis" do it "should remove 1 * emphasis" do str = "*abc*" expect(Goethe::Utils.remove_markdown_symbols(str)).to eq("abc") end it "should remove 2 * emphasis" do str = "**abc**" expect(Goethe::Utils.remove_markdown_symbols(str)).to eq("abc") end it "should remove 3 * emphasis" do str = "***abc***" expect(Goethe::Utils.remove_markdown_symbols(str)).to eq("abc") end it "should remove _ emphasis" do str = "_abc_" expect(Goethe::Utils.remove_markdown_symbols(str)).to eq("abc") str = "__abc__" expect(Goethe::Utils.remove_markdown_symbols(str)).to eq("abc") str = "___abc___" expect(Goethe::Utils.remove_markdown_symbols(str)).to eq("abc") end it "should remove uneven emphasis" do str = "***abc**" expect(Goethe::Utils.remove_markdown_symbols(str)).to eq("*abc") str = "__abc___" expect(Goethe::Utils.remove_markdown_symbols(str)).to eq("abc_") end end it "should remove blockquotes" do str = "> abc\n" expect(Goethe::Utils.remove_markdown_symbols(str)).to eq("abc\n") end it "should remove lists" do str = "* abc\n* bbc" expect(Goethe::Utils.remove_markdown_symbols(str)).to eq("abc\nbbc") end context "hrulers" do it "should remove hrulers" do str = "abc\n* * *\nbbc\n***\ncbc\n*****\ndbc\n- - -\nebc\n___" expect(Goethe::Utils.remove_markdown_symbols(str)).to eq("abc\n\nbbc\n\ncbc\n\ndbc\n\nebc\n") end end context "links" do it "should remove links correctly" do str = "please go to google: [Google](http://www.google.com)" expect(Goethe::Utils.remove_markdown_symbols(str)).to eq("please go to google: Google") end end context "images" do it "should remove images correctly" do str = "This is ![Alt text](/path/to/img.jpg 'Optional title') an image." expect(Goethe::Utils.remove_markdown_symbols(str)).to eq("This is an image.") end end context "copyright" do it "should remove the copyright sign" do str = "Here is our © brand" expect(Goethe::Utils.remove_markdown_symbols(str)).to eq("Here is our brand") end end end describe "auto_link" do it "should parse correctly" do str = "hellohttp://www.google.com/google" expect(Goethe::Utils.auto_link(str)).to eq(%Q{hellohttp://www.google.com/google}) str = "hellohttp://www.google.com/ google" expect(Goethe::Utils.auto_link(str)).to eq(%Q{hellohttp://www.google.com/ google}) end it "should allow params" do str = "hellohttp://www.google.com:8080/?search=google&keyword=google" expect(Goethe::Utils.auto_link(str)).to eq(%Q{hellohttp://www.google.com:8080/?search=google&keyword=google}) end end end