spec/ruhl_spec.rb in ruhl-0.9.7 vs spec/ruhl_spec.rb in ruhl-0.10.0

- old
+ new

@@ -80,56 +80,102 @@ doc.xpath('/html/body/div/div/div/ul/li//a')[0].inner_html. should == "Real Link 1" end end + shared_examples_for "if with no users" do + 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 + + shared_examples_for "if with users" do + 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 + describe "if.html" do - describe "no users" do + describe "users? is false" do before do class ContextObject - def users?(tag = nil) + def users? 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 + it_should_behave_like "if with no users" end - describe "has users" do + describe "users? is true" do before do class ContextObject - def users?(tag = nil) + def users? 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 + it_should_behave_like "if with users" + end + end - table = @doc.xpath('/html/body/table/tr//td') - table.children[12].to_s.should == "NoMail" - table.children[13].to_s.should == "Man" + describe "if_on_collection.html" do + describe "user_list is empty" do + before do + class ContextObject + def user_list + [] + end + end + + @html = File.read html(:if_on_collection) + @doc = create_doc end + + it_should_behave_like "if with no users" end + + describe "user_list is not empty" do + before do + class ContextObject + def user_list + [ + TestUser.new('Jane', 'Doe', 'jane@stonean.com'), + TestUser.new('John', 'Joe', 'john@stonean.com'), + TestUser.new('Jake', 'Smo', 'jake@stonean.com'), + TestUser.new('Paul', 'Tin', 'paul@stonean.com'), + TestUser.new('NoMail', 'Man') + ] + end + end + + @html = File.read html(:if_on_collection) + @doc = create_doc + end + + it_should_behave_like "if with users" + end end describe "loop.html" do before do @html = File.read html(:loop) @@ -175,16 +221,11 @@ nodes[3]['value'].should == 'tin' nodes[4]['value'].should == 'man' end end - describe "use.html" do - before do - @html = File.read html(:use) - @doc = create_doc - end - + shared_examples_for "if with user" do it "first name will be set" do @doc.xpath('/html/body/div//input')[0]['value'].should == "Jane" end it "last name will be set" do @@ -192,9 +233,27 @@ end it "email will be set" do @doc.xpath('/html/body/div//input')[2]['value'].should == "jane@stonean.com" end + end + + describe "use.html" do + before do + @html = File.read html(:use) + @doc = create_doc + end + + it_should_behave_like "if with user" + end + + describe "use_if.html" do + before do + @html = File.read html(:use_if) + @doc = create_doc + end + + it_should_behave_like "if with user" end describe "collection_of_strings.html" do before do @html = File.read html(:collection_of_strings)