require File.dirname(__FILE__) + '/spec_helper.rb' describe "excesselt" do describe "When a developer wants to transform their hello world xml" do before do module TestHelper def error_text_in_parent error("Text is not allowed within a parent node!") unless (text.strip == '') end def uppercase_text add text.upcase end def text self.to_xml end end @stylesheet = Class.new(Excesselt::Stylesheet) do def rules render('parent > child') { builder.p(:style => "child_content" ) { child_content } } render('parent') { builder.p(:style => "parent_content") { child_content } } helper TestHelper do render('parent.explode > text()', :with => :a_method_that_doesnt_exist) render('parent > text()', :with => :error_text_in_parent) render('text()', :with => :uppercase_text) end end end end it "should transform a hello world document according to a stylesheet" do xml = <<-XML Hello World XML expected = <<-EXPECTED

HELLO WORLD

EXPECTED @stylesheet.transform(xml).should match_the_dom_of(expected) end it "should transform a goodbye document according to a stylesheet" do xml = <<-XML Goodbye XML expected = <<-EXPECTED

GOODBYE

EXPECTED @stylesheet.transform(xml).should match_the_dom_of(expected) end describe "error handling" do it "should record errors encountered during processing" do xml = <<-XML foo XML @instance = @stylesheet.new @instance.transform(xml) @instance.errors.should == ["Text is not allowed within a parent node!"] end it "should record errors encountered during processing" do xml = <<-XML foo XML @instance = @stylesheet.new lambda { @instance.transform(xml) }.should raise_exception {|e| e.message.should =~ /With Included Modules: \[TestHelper\]/} end end end end