File: test_case.rb

package info (click to toggle)
ruby-compass 1.0.1~dfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 8,152 kB
  • ctags: 1,795
  • sloc: ruby: 12,901; makefile: 127; perl: 43; xml: 14; sh: 4
file content (62 lines) | stat: -rw-r--r-- 1,402 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
module Compass
  module TestCaseHelper
    def absolutize(path)
      if Compass::Util.blank?(path)
        File.expand_path('../../', __FILE__)
      elsif path[0] == ?/
        File.join(File.expand_path('../', __FILE__), path)
      else
        File.join(File.expand_path('../../', __FILE__), path)
      end
    end

    # compile a Sass string in the context of a project in the current working directory.
    def compile_for_project(contents, options = {})
      Compass.add_project_configuration
      options[:syntax] ||= :scss
      Sass::Engine.new(contents, Compass.configuration.to_sass_engine_options.merge(options)).render
    end

    def assert_correct(before, after)
      if before == after
        assert(true)
      else
        assert false, diff_as_string(before.inspect, after.inspect)
      end
    end
    
    module ClassMethods

      def let(method, &block)
        define_method method, &block
      end

      def it(name, &block)
        test(name, &block)
      end

      def test(name, &block)
        define_method "test_#{underscore(name)}".to_sym, &block
      end

      def setup(&block)
        define_method :setup do
          yield
        end
      end

      def after(&block)
        define_method :teardown do
          yield
        end
      end

      private 

      def underscore(string)
        string.gsub(' ', '_')
      end

    end
  end
end