File: test_hoe_debug.rb

package info (click to toggle)
ruby-hoe 3.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 440 kB
  • sloc: ruby: 1,886; makefile: 2
file content (107 lines) | stat: -rw-r--r-- 1,910 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
require 'hoe'
require File.expand_path 'lib/hoe/debug.rb' # ugh. avoid dupe warnings
require 'tmpdir'
require 'tempfile'
require 'minitest/autorun'

class TestHoeDebug < MiniTest::Unit::TestCase

  include Hoe::Debug

  attr_accessor :generated_files

  def setup
    super

    @generated_files = []
  end

  def test_check_manifest
    in_tmpdir do
      manifest

      assert_silent do
        check_manifest
      end
    end
  end

  def test_check_manifest_generated
    in_tmpdir do
      manifest 'generated.rb'

      open 'generated.rb', 'w' do |io| io.puts 'generated = true' end

      assert_silent do
        check_manifest
      end
    end
  end

  def test_check_manifest_missing
    in_tmpdir do
      manifest

      open 'missing.rb', 'w' do |io| io.puts 'missing = true' end

      e = nil

      out = capture_STDOUT do
        e = assert_raises RuntimeError do
          check_manifest
        end
      end

      assert_match %r%^Command failed with status%, e.message

      assert_match %r%^\+missing.rb%, out
    end
  end

  def capture_STDOUT
    orig_STDOUT = STDOUT.dup

    Tempfile.open __name__ do |io|
      STDOUT.reopen io

      yield

      io.flush

      return File.read io.path
    end
  ensure
    STDOUT.reopen orig_STDOUT
  end

  def in_tmpdir
    old_LOAD_PATH = $LOAD_PATH.dup
    $LOAD_PATH.map! { |path| File.expand_path path }

    Dir.mktmpdir do |path|
      Dir.chdir path do
        yield
      end
    end
  ensure
    $LOAD_PATH.replace old_LOAD_PATH
  end

  def manifest extra = nil
    open 'Manifest.txt', 'w' do |io| # sorted
      io.puts 'History.txt'
      io.puts 'Manifest.txt'
      io.puts 'README.txt'
      io.puts extra if extra
    end

    open 'README.txt',  'w'  do |io| io.puts '= blah' end
    open 'History.txt', 'w'  do |io| io.puts '=== 1.0' end
  end

  def with_config
    yield({ 'exclude' => [] }, '~/.hoerc')
  end

end