File: test_helper.rb

package info (click to toggle)
ruby-marcel 1.0.4%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 13,236 kB
  • sloc: xml: 7,071; ruby: 601; makefile: 7; javascript: 3
file content (50 lines) | stat: -rw-r--r-- 1,237 bytes parent folder | download
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
require 'minitest/autorun'
require 'marcel'
require 'pathname'

class Marcel::TestCase < Minitest::Test
  class << self
    def setup(&block)
      define_method(:setup, &block)
    end

    def teardown(&block)
      define_method(:teardown, &block)
    end

    def test(name, &block)
      test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
      defined = instance_method(test_name) rescue false
      raise "#{test_name} is already defined in #{self}" if defined
      define_method(test_name, &block)
    end

    def fixture_path(name)
      File.expand_path("../fixtures/#{name}", __FILE__)
    end

    def files(name)
      Pathname.new fixture_path(name)
    end

    def each_content_type_fixture(folder)
      FileUtils.chdir fixture_path(folder) do
        Dir["**/*.*"].map do |name|
          if File.file?(name)
            _, content_type, extra, _ = *name.match(/\A([^\/]+\/[^\/]*)\/?(.*)\.(\w+)\Z/)
            extra = nil if content_type[-content_type.size..-1] == extra
            yield files("#{folder}/#{name}"), name, content_type
          end
        end
      end
    end
  end

  def files(name)
    Pathname.new fixture_path(name)
  end

  def fixture_path(name)
    self.class.fixture_path(name)
  end
end