Loading...

WellRailed@googlegroups.com

[Prev] Thread [Next]  |  [Prev] Date [Next]

Re: [WellRailed] Loops in tests - best practice ? Richard Hulse Thu Jun 17 08:00:14 2010

The 26 times was because I have a string of chars, and the test has to
walk through the string:

def test_is_ctype_alpha
        @parser.css     = "aBcDeFgHiJkLmNoPqRsTuVwXyZ"
        (0..25).each do |index|
                @parser.index   = index
                assert @parser.is_ctype?(:alpha)
        end
end

if chars b and L fail it only reports one failure, and you cannot tell
which one.

The other use case is reading in a directory of test files and looping
through some tests:

def test_yui_css
        test_files = Dir.glob(File.join(File.dirname(__FILE__), 'yuicss/*.css'))
        test_files.each do |file|
    test_css                    = File.read(file)
    expected_css        = File.read(file + '.min')

        test_name = File.basename(file, ".css")
                assert_block "Test failed - #{test_name}" do
                        expected_css == @yui.compress(test_css) #    
do_the_thing
                end
        end     
end

(And in case you ask, this is for a Ruby port of the yui css compressor).


cheers,

Richard

-- 
You received this message because you are subscribed to the Google Groups 
"WellRailed" group.
To post to this group, send email to [EMAIL PROTECTED]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/wellrailed?hl=en.