Skip to content

Instantly share code, notes, and snippets.

@biot023
Created July 11, 2010 20:49
Show Gist options
  • Save biot023/471824 to your computer and use it in GitHub Desktop.
Save biot023/471824 to your computer and use it in GitHub Desktop.
require "spec_helper"
describe "tabs/show.html.haml", :type => :cell_view do
before( :each ) do
@tab_articles = [ Factory.stub( :tab_article, tab_title: "Home", url_title: "home" ),
Factory.stub( :tab_article, tab_title: "Title One", url_title: "title_one" ),
Factory.stub( :tab_article, tab_title: "Title Two", url_title: "title_two" ),
Factory.stub( :tab_article, tab_title: "Title Three", url_title: "title_three" ) ]
@selected_tab_title = "Title Two"
assign( :tab_articles, @tab_articles )
assign( :selected_tab_title, @selected_tab_title )
view.stub!( :li_for_tab_article ).and_return( "" )
end
def do_render
render_cell( :tabs, :show )
end
it "should render a ul with an id of tabs" do
do_render
rendered.should have_selector( "ul#tabs" )
end
context "within tabs ul" do
it "should render each tab in order inside the tabs ul with selected_tab_title" do
@tab_articles.each do |tab_article|
view.should_receive( :li_for_tab_article ).with( tab_article, @selected_tab_title )
.and_return( "<li id='#{ tab_article.url_title }'></li>" )
end
do_render
rendered.should have_xpath( "//ul[@id = 'tabs']" ) do |ul|
@tab_articles.each_with_index do |tab_article, i|
ul.should have_xpath( "//li[#{ i + 1 }][@id = '#{ tab_article.url_title }']" )
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment