require 'test/unit' require 'lib/csses' module Test::Unit::Assertions def assert_include(item, obj, message = nil) assert_respond_to obj, :include? message ||= "#{obj.inspect}\ndoes not include\n#{item.inspect}." assert_block message do obj.include? item end end def deny_include(item, obj, message = nil) assert_respond_to obj, :include? message ||= "#{obj.inspect} includes #{item.inspect}." assert_block message do !obj.include? item end end # Thanks ZenTest! end class CSSesTest < Test::Unit::TestCase def setup files = Dir.glob('test/test_site/*') @css = CSSes.new(files) @css_unless = CSSes.new(['test/test_site/test_unless.html.erb']) @css_without_parens = CSSes.new(['test/test_site/test_no_parens.html.erb']) @css_without_anything = CSSes.new([]) end def test_000_no_unfashionable_elements CSSes::UNFASHIONABLE_ELEMENTS.each do |not_allowed| deny_include(not_allowed, @css.elements) end end def test_001_h1 assert_include('h1', @css.elements) end def test_002_h1_with_id assert_include('h1#h1_id', @css.elements, 'CSS should include entries for ids') end def test_003_h1_with_class assert_include('h1.h1_class', @css.elements, 'CSS should include entries for classes') end def test_004_link_to assert_include('a', @css.elements, 'CSS should know that link_to makes anchors') end def test_005_link_to_without_parens assert_include('a', @css_without_parens.elements, 'CSS should handle parenthesis-less helper calls') end def test_006_link_to_unless assert_include('a', @css_unless.elements, 'CSS should know that link_to_unless makes anchors') end def test_007_anchor_pseudo_class_visited assert_include('a:visited', @css.elements, 'CSS should create the visited pseudo-class for anchors') end def test_008_anchor_pseudo_class_hover assert_include('a:hover', @css.elements, 'CSS should create the hover pseudo-class for anchors') end def test_009_anchor_pseudo_class_active assert_include('a:active', @css.elements, 'CSS should create the active pseudo-class for anchors') end def test_010_anchor_pseudo_class_with_id assert_include('a#a_id:visited', @css.elements, 'CSS should handle ids with pseudoclasses') end def test_011_anchor_pseudo_class_with_class assert_include('a.a_class:hover', @css.elements, 'CSS should handle classes with pseudoclasses') end def test_012_image_tag assert_include('img', @css.elements, 'CSS should know that image_tag makes img tags') end def test_013_image_tag_with_id assert_include('img#img_id', @css.elements, 'CSS should handle image_tags with ids') end def test_014_image_tag_with_class assert_include('img.img_class', @css.elements, 'CSS should handle image_tags with classes') end def test_015_link_to_with_id assert_include('a#link_to_id', @css.elements, 'CSS should handle link_to with ids') end def test_016_link_to_with_class assert_include('a.link_to_class', @css.elements, 'CSS should handle link_to with classes') end def test_017_link_to_with_rails_id_not_html_id deny_include('a#not_an_html_id', @css.elements, "CSS shouldn't fall for rails ids in link_to calls") end def test_018_form_helpers assert_include('label#label_id', @css.elements, 'CSS should handle labels') end end