summaryrefslogtreecommitdiff
path: root/jni/ruby/test/rake/test_rake_extension.rb
blob: 18d55f19f9cbff672955ad00d45292219ca2bc36 (plain)
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
require File.expand_path('../helper', __FILE__)
require 'stringio'

class TestRakeExtension < Rake::TestCase

  module Redirect
    def error_redirect
      old_err = $stderr
      result = StringIO.new
      $stderr = result
      yield
      result
    ensure
      $stderr = old_err
    end
  end

  class Sample
    extend Redirect

    def duplicate_method
      :original
    end

    OK_ERRS = error_redirect do
      rake_extension("a") do
        def ok_method
        end
      end
    end


    DUP_ERRS = error_redirect do
      rake_extension("duplicate_method") do
        def duplicate_method
          :override
        end
      end
    end
  end

  def test_methods_actually_exist
    sample = Sample.new
    sample.ok_method
    sample.duplicate_method
  end

  def test_no_warning_when_defining_ok_method
    assert_equal "", Sample::OK_ERRS.string
  end

  def test_extension_complains_when_a_method_that_is_present
    assert_match(/warning:/i, Sample::DUP_ERRS.string)
    assert_match(/already exists/i, Sample::DUP_ERRS.string)
    assert_match(/duplicate_method/i, Sample::DUP_ERRS.string)
    assert_equal :original, Sample.new.duplicate_method
  end

end