diff --git a/spec/components/pretty_text_spec.rb b/spec/components/pretty_text_spec.rb index 0d72813647b..6d9b5697749 100644 --- a/spec/components/pretty_text_spec.rb +++ b/spec/components/pretty_text_spec.rb @@ -7,7 +7,7 @@ describe PrettyText do it "should support github style code blocks" do PrettyText.cook("``` test -```").should == "
test  \n
" +```").should match_html "
test  \n
" end it "should support quoting [] " do @@ -15,64 +15,64 @@ test end it "produces a quote even with new lines in it" do - PrettyText.cook("[quote=\"EvilTrout, post:123, topic:456, full:true\"]ddd\n[/quote]").should == "

" + PrettyText.cook("[quote=\"EvilTrout, post:123, topic:456, full:true\"]ddd\n[/quote]").should match_html "

" end it "should produce a quote" do - PrettyText.cook("[quote=\"EvilTrout, post:123, topic:456, full:true\"]ddd[/quote]").should == "

" + PrettyText.cook("[quote=\"EvilTrout, post:123, topic:456, full:true\"]ddd[/quote]").should match_html "

" end it "trims spaces on quote params" do - PrettyText.cook("[quote=\"EvilTrout, post:555, topic: 666\"]ddd[/quote]").should == "

" + PrettyText.cook("[quote=\"EvilTrout, post:555, topic: 666\"]ddd[/quote]").should match_html "

" end it "should handle 3 mentions in a row" do - PrettyText.cook('@hello @hello @hello').should == "

@hello @hello @hello

" + PrettyText.cook('@hello @hello @hello').should match_html "

@hello @hello @hello

" end it "should not do weird @ mention stuff inside a pre block" do PrettyText.cook("``` a @test -```").should == "
a @test  \n
" +```").should match_html "
a @test  \n
" end it "should sanitize the html" do - PrettyText.cook("").should == "alert(42)" + PrettyText.cook("").should match_html "alert(42)" end it "should escape html within the code block" do PrettyText.cook("```text
hello
-```").should == "
<header>hello</header>  \n
" +```").should match_html "
<header>hello</header>  \n
" end it "should support language choices" do PrettyText.cook("```ruby test -```").should == "
test  \n
" +```").should match_html "
test  \n
" end it 'should decorate @mentions' do - PrettyText.cook("Hello @eviltrout").should == "

Hello @eviltrout

" + PrettyText.cook("Hello @eviltrout").should match_html "

Hello @eviltrout

" end it 'should allow for @mentions to have punctuation' do - PrettyText.cook("hello @bob's @bob,@bob; @bob\"").should == - "

hello @bob's @bob,@bob; @bob\"

" + PrettyText.cook("hello @bob's @bob,@bob; @bob\"").should + match_html "

hello @bob's @bob,@bob; @bob\"

" end it 'should add spoiler tags' do - PrettyText.cook("[spoiler]hello[/spoiler]").should == "

hello

" + PrettyText.cook("[spoiler]hello[/spoiler]").should match_html "

hello

" end it "should only detect ``` at the begining of lines" do PrettyText.cook(" ```\n hello\n ```") - .should == "
```\nhello\n```\n
" + .should match_html "
```\nhello\n```\n
" end end diff --git a/spec/support/match_html_matcher.rb b/spec/support/match_html_matcher.rb new file mode 100644 index 00000000000..dde6376f6c5 --- /dev/null +++ b/spec/support/match_html_matcher.rb @@ -0,0 +1,21 @@ +require 'nokogiri/xml/parse_options' +RSpec::Matchers.define :match_html do |expected| + match do |actual| + a = make_canonical_html expected + b = make_canonical_html actual + a.to_html == b.to_html + end + + failure_message_for_should do |actual| + "after sanitizing for extra white space and compactness, expected #{actual} to match #{expected}" + end + + failure_message_for_should_not do |actual| + "after sanitizing for extra white space and compactness, expected #{actual} not to match #{expected}" + end + + def make_canonical_html(html) + Nokogiri::HTML(html) { |config| config.options = Nokogiri::XML::ParseOptions::NOBLANKS | Nokogiri::XML::ParseOptions::COMPACT } + end + +end