~ubuntu-branches/ubuntu/quantal/ruby1.9.1/quantal

« back to all changes in this revision

Viewing changes to test/rake/test_rake_extension.rb

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2011-09-24 19:16:17 UTC
  • mfrom: (1.1.8 upstream) (13.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20110924191617-o1qz4rcmqjot8zuy
Tags: 1.9.3~rc1-1
* New upstream release: 1.9.3 RC1.
  + Includes load.c fixes. Closes: #639959.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require File.expand_path('../helper', __FILE__)
 
2
require 'stringio'
 
3
 
 
4
class TestRakeExtension < Rake::TestCase
 
5
 
 
6
  module Redirect
 
7
    def error_redirect
 
8
      old_err = $stderr
 
9
      result = StringIO.new
 
10
      $stderr = result
 
11
      yield
 
12
      result
 
13
    ensure
 
14
      $stderr = old_err
 
15
    end
 
16
  end
 
17
 
 
18
  class Sample
 
19
    extend Redirect
 
20
 
 
21
    def duplicate_method
 
22
      :original
 
23
    end
 
24
 
 
25
    OK_ERRS = error_redirect do
 
26
      rake_extension("a") do
 
27
        def ok_method
 
28
        end
 
29
      end
 
30
    end
 
31
 
 
32
 
 
33
    DUP_ERRS = error_redirect do
 
34
      rake_extension("duplicate_method") do
 
35
        def duplicate_method
 
36
          :override
 
37
        end
 
38
      end
 
39
    end
 
40
  end
 
41
 
 
42
  def test_methods_actually_exist
 
43
    sample = Sample.new
 
44
    sample.ok_method
 
45
    sample.duplicate_method
 
46
  end
 
47
 
 
48
  def test_no_warning_when_defining_ok_method
 
49
    assert_equal "", Sample::OK_ERRS.string
 
50
  end
 
51
 
 
52
  def test_extension_complains_when_a_method_that_is_present
 
53
    assert_match(/warning:/i, Sample::DUP_ERRS.string)
 
54
    assert_match(/already exists/i, Sample::DUP_ERRS.string)
 
55
    assert_match(/duplicate_method/i, Sample::DUP_ERRS.string)
 
56
    assert_equal :original, Sample.new.duplicate_method
 
57
  end
 
58
 
 
59
end