require File.join(File.dirname(__FILE__), 'spec_helper') describe Ruhl do before do @co = ContextObject.new end describe "basic.html" do before do @html = File.read html(:basic) end it "content of p should be content from data_from_method" do doc = create_doc doc.xpath('//h1').first.content.should == @co.generate_h1 end end describe "seo.html" do before do @html = File.read html(:seo) end it "meta keywords should be replaced" do doc = create_doc doc.xpath('//meta[@name="keywords"]').first['content']. should == @co.generate_keywords end it "meta title should be replaced" do doc = create_doc doc.xpath('//meta[@name="description"]').first['content']. should == @co.generate_description end end describe "medium.html" do before do @html = File.read html(:medium) @doc = create_doc end it "first data row should equal first user " do table = @doc.xpath('/html/body/table/tr//td') table.children[0].to_s.should == "Jane" table.children[1].to_s.should == "Doe" table.children[2].to_s.should == "jane@stonean.com" end it "last data row should equal last user " do table = @doc.xpath('/html/body/table/tr//td') table.children[9].to_s.should == "Paul" table.children[10].to_s.should == "Tin" table.children[11].to_s.should == "paul@stonean.com" end end describe "fragment.html" do before do @html = File.read html(:fragment) end it "will be injected into layout.html" do doc = create_doc( html(:layout) ) doc.xpath('//h1').should_not be_empty doc.xpath('//p').should_not be_empty end end describe "main_with_sidebar.html" do before do @html = File.read html(:main_with_sidebar) end it "should replace sidebar with partial contents" do doc = create_doc end end describe "if.html" do describe "no users" do before do class ContextObject def users?(tag = nil) false end end @html = File.read html(:if) @doc = create_doc end it "table should not render" do nodes = @doc.xpath('/html/body//*') nodes.children.length.should == 2 nodes.children[0].to_s.should == "This is the header template" end it "no user message should render" do nodes = @doc.xpath('/html/body//*') nodes.children[1].to_s.should == @co.no_users_message end end describe "has users" do before do class ContextObject def users?(tag = nil) true end end @html = File.read html(:if) @doc = create_doc end it "table should render" do nodes = @doc.xpath('/html/body//*') nodes.children.length.should > 1 table = @doc.xpath('/html/body/table/tr//td') table.children[12].to_s.should == "NoMail" table.children[13].to_s.should == "Man" end end end end