require 'spec_helper' module Deface describe Parser do describe "#convert" do it "should parse html fragment" do Deface::Parser.convert("
test
") parsed.should be_an_instance_of(Nokogiri::HTML::Document) parsed = parsed.to_s.split("\n")[1..-1] parsed.should == "test
".split("\n") #ignore doctype added by noko end it "should convert <% ... %>" do Deface::Parser.convert("<% method_name %>").to_s.should == " method_name
"
end
it "should convert <%= ... %>" do
Deface::Parser.convert("<%= method_name %>").to_s.should == " method_name
"
end
it "should convert nested <% ... %>" do
Deface::Parser.convert("\">
").to_s.should == "" end it "should convert nested <%= ... %> including href attribute" do Deface::Parser.convert(%(">A Link)).to_s.should == "A Link" end it "should escape contents code tags" do Deface::Parser.convert("<% method_name(:key => 'value') %>").to_s.should == " method_name(:key => 'value')
"
end
end
describe "#undo_erb_markup" do
it "should revert " do
Deface::Parser.undo_erb_markup!(" method_name
").should == "<% method_name %>"
end
it "should revert " do
Deface::Parser.undo_erb_markup!(" method_name
").should == "<%= method_name %>"
end
it "should revert nested " do
Deface::Parser.undo_erb_markup!(" 1 </code>\">
").should == " 1 %>\">
"
end
it "should revert nested including href attribute" do
Deface::Parser.undo_erb_markup!("A Link").should == "\">A Link"
end
it "should revert nested " do
Deface::Parser.undo_erb_markup!("").should == "\">
"
end
it "should revert nested including href attribute" do
Deface::Parser.undo_erb_markup!("A Link").should == %(A Link)
Deface::Parser.undo_erb_markup!("A Link").should == %(">A Link)
end
it "should unescape contents of code tags" do
Deface::Parser.undo_erb_markup!("<% method(:key => 'value' %>").should == "<% method(:key => 'value' %>"
Deface::Parser.undo_erb_markup!("<% method(:key => 'value'\n %>").should == "<% method(:key => 'value'\n %>"
end
end
end
end