test_helper.rb 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. lib_dir = File.dirname(__FILE__) + '/../lib'
  2. require 'test/unit'
  3. require 'fileutils'
  4. $:.unshift lib_dir unless $:.include?(lib_dir)
  5. require 'sass'
  6. require 'mathn' if ENV['MATHN'] == 'true'
  7. Sass::RAILS_LOADED = true unless defined?(Sass::RAILS_LOADED)
  8. module Sass::Script::Functions
  9. def option(name)
  10. Sass::Script::String.new(@options[name.value.to_sym].to_s)
  11. end
  12. end
  13. class Test::Unit::TestCase
  14. def munge_filename(opts = {})
  15. return if opts.has_key?(:filename)
  16. opts[:filename] = filename_for_test(opts[:syntax] || :sass)
  17. end
  18. def filename_for_test(syntax = :sass)
  19. test_name = caller.
  20. map {|c| Sass::Util.caller_info(c)[2]}.
  21. compact.
  22. map {|c| c.sub(/^(block|rescue) in /, '')}.
  23. find {|c| c =~ /^test_/}
  24. "#{test_name}_inline.#{syntax}"
  25. end
  26. def clean_up_sassc
  27. path = File.dirname(__FILE__) + "/../.sass-cache"
  28. FileUtils.rm_r(path) if File.exist?(path)
  29. end
  30. def assert_warning(message)
  31. the_real_stderr, $stderr = $stderr, StringIO.new
  32. yield
  33. if message.is_a?(Regexp)
  34. assert_match message, $stderr.string.strip
  35. else
  36. assert_equal message.strip, $stderr.string.strip
  37. end
  38. ensure
  39. $stderr = the_real_stderr
  40. end
  41. def silence_warnings(&block)
  42. Sass::Util.silence_warnings(&block)
  43. end
  44. def assert_raise_message(klass, message)
  45. yield
  46. rescue Exception => e
  47. assert_instance_of(klass, e)
  48. assert_equal(message, e.message)
  49. else
  50. flunk "Expected exception #{klass}, none raised"
  51. end
  52. def assert_raise_line(line)
  53. yield
  54. rescue Sass::SyntaxError => e
  55. assert_equal(line, e.sass_line)
  56. else
  57. flunk "Expected exception on line #{line}, none raised"
  58. end
  59. end