require 'helper' require 'fixtures/markup_app/app' class TestAssetTagHelpers < Test::Unit::TestCase include SinatraMore::AssetTagHelpers def app MarkupDemo.tap { |app| app.set :environment, :test } end def flash { :notice => "Demo notice" } end context 'for #flash_tag method' do should "display flash with no given attributes" do assert_equal '
Demo notice
', flash_tag(:notice) end should "display flash with given attributes" do flash_expected = '
Demo notice
' assert_equal flash_expected, flash_tag(:notice, :class => 'notice', :id => 'notice-area') end end context 'for #link_to method' do should "display link element with no given attributes" do assert_equal 'Sign up', link_to('Sign up', '/register') end should "display link element with given attributes" do link_expected = 'Sign up' assert_equal link_expected, link_to('Sign up', '/register', :class => 'first', :id => 'linky') end should "display link element with ruby block" do link_expected = 'Sign up' actual_link = link_to('/register', :class => 'first', :id => 'binky') do "Sign up" end assert_equal link_expected, actual_link end should "display link block element in haml" do visit '/haml/link_to' assert_have_selector :a, :content => "Test 1 No Block", :href => '/test1', :class => 'test', :id => 'test1' assert_have_selector :a, :content => "Test 2 With Block", :href => '/test2', :class => 'test', :id => 'test2' end should "display link block element in erb" do visit '/erb/link_to' assert_have_selector :a, :content => "Test 1 No Block", :href => '/test1', :class => 'test', :id => 'test1' #TODO fix this selector below in erb # assert_have_selector :a, :content => "Test 2 With Block", :href => '/test2', :class => 'test', :id => 'test2' end end context 'for #image_tag method' do should "display image tag absolute link with no options" do assert_equal '', image_tag('/absolute/pic.gif') end should "display image tag relative link with options" do assert_equal '', image_tag('relative/pic.gif', :class => 'photo') end should "display image tag relative link with incorrect space" do assert_equal '', image_tag(' relative/ pic.gif ', :class => 'photo') end end context 'for #stylesheet_link_tag method' do should "display stylesheet link item" do time = stop_time_for_test expected_style = %Q[] assert_equal expected_style, stylesheet_link_tag('style') end should "display stylesheet link items" do time = stop_time_for_test expected_style = %Q[\n] expected_style << %Q[\n] expected_style << %Q[] assert_equal expected_style, stylesheet_link_tag('style', 'layout.css', 'http://google.com/style.css') end end context 'for #javascript_include_tag method' do should "display javascript item" do time = stop_time_for_test expected_include = %Q[] assert_equal expected_include, javascript_include_tag('application') end should "display javascript items" do time = stop_time_for_test expected_include = %Q[\n] expected_include << %Q[\n] expected_include << %Q[] assert_equal expected_include, javascript_include_tag('application', 'base.js', 'http://google.com/lib.js') end end end