describe "Fortitude other outputting methods", :type => :system do def r(&block) render(widget_class_with_content(&block)) end def should_render_to(value, &block) expect(r(&block)).to eq(value) end describe "comments" do it "should render a simple comment" do should_render_to("") { comment "foo" } end it "should escape anything potentially comment-ending in a comment" do [ "fo --> oo", "fo -- oo", "fo --", "--", "-----", "---", " -- ", "-- ", " --", "- -", ">", " > ", ">>", "-->" ].each do |string| text = render(widget_class_with_content { comment string }) if text =~ /^$/ contents = $1 else raise "Not a comment?!? #{text.inspect}" end # From http://www.w3.org/TR/html5/syntax.html#comments: # # Comments must start with the four character sequence U+003C LESS-THAN SIGN, U+0021 EXCLAMATION MARK, # U+002D HYPHEN-MINUS, U+002D HYPHEN-MINUS (). expect(contents).not_to match(/\-\-/) expect(contents).not_to match(/^\s*>/) expect(contents).not_to match(/^\s*\->/) expect(contents).not_to match(/>$/) end end it "should not escape standard HTML escape characters inside a comment" do expect(render(widget_class_with_content { comment 'mind your "p"s & "q"s' })).to eq('') expect(render(widget_class_with_content { comment 'is 3 < 4, or is 4 > 3?' })).to eq('') end it "should not allow passing a block" do expect { render { comment { text "hi" } } }.to raise_error(ArgumentError) end it "should put comments on their own lines if we're formatting output, and indent them properly" do wc = widget_class do format_output true def content div do text "this is really cool" comment "isn't it?" text "man?" end end end expect(render(wc)).to eq(%{