File: test_plugin_referer.rb

package info (click to toggle)
hiki 1.0.0-0.2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,812 kB
  • ctags: 2,033
  • sloc: ruby: 14,572; lisp: 926; sh: 19; makefile: 16
file content (46 lines) | stat: -rw-r--r-- 1,105 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
# coding: utf-8

require 'test/unit'
require 'fileutils'
require 'tempfile'

class Plugin_Referer_Unit_Tests < Test::Unit::TestCase
  def setup
    define_dummy_methods
    @body_leave_proc = nil
    @cache_path = test_cache_path
    @options = {}
    @page = 'test page'

    plugin_file = File.expand_path(File.join(File.dirname(__FILE__), *%w{.. misc plugin referer.rb}))
    instance_eval(File.open(plugin_file).read)
  end

  def teardown
    FileUtils.rm_r(@test_cache_path) if File.exists?(@test_cache_path)
  end

  def test_body_leave_proc
    assert_nothing_raised do
      @body_leave_proc.call
    end
  end

  def add_body_leave_proc(p)
    @body_leave_proc = p
  end

  def define_dummy_methods
    instance_eval(%{def export_plugin_methods(*args); end})
  end

  def test_cache_path
    if ! defined?(@test_cache_path)
      tempfile = Tempfile.new(self.class.to_s)
      @test_cache_path = File.join(File.dirname(tempfile.path), self.class.to_s)
      FileUtils.mkdir(@test_cache_path) unless File.exists?(@test_cache_path)
      tempfile.close(true)
    end
    @test_cache_path
  end
end