Sha256: d3e842870de30b587f315d8c9c8bc1ab4eaf870f98d280a1d8765c72dac3c85b

Contents?: true

Size: 1.82 KB

Versions: 6

Compression:

Stored size: 1.82 KB

Contents

require 'test/unit'
require 'webget_ruby_ramp'

class ClassTest < Test::Unit::TestCase

  
  METHOD_REGEXP = /^[abc]\W*$/
  def test_publicize_methods

    # Before we test the block, ensure our setup is correct
    assert_equal(["a","a!","a=","a?"],My.private_instance_methods.grep_sort_to_s(METHOD_REGEXP),'private methods before block')
    assert_equal(["b","b!","b=","b?"],My.protected_instance_methods.grep_sort_to_s(METHOD_REGEXP),'protected methods before block')
    assert_equal(["c","c!","c=","c?"],My.public_instance_methods.grep_sort_to_s(METHOD_REGEXP),'public methods before block')

    # Now we test inside the block
    My.publicize_methods{
      assert_equal([],My.private_instance_methods.grep_sort_to_s(METHOD_REGEXP),'private methods inside block')
      assert_equal([],My.protected_instance_methods.grep_sort_to_s(METHOD_REGEXP),'protected methods inside block')
      assert_equal(["a","a!","a=","a?","b","b!","b=","b?","c","c!","c=","c?"],My.public_instance_methods.grep_sort_to_s(METHOD_REGEXP),'public methods inside block')
    }

    # After we test the block, ensure our setup is restored
    assert_equal(["a","a!","a=","a?"],My.private_instance_methods.grep_sort_to_s(METHOD_REGEXP),'private methods before block')
    assert_equal(["b","b!","b=","b?"],My.protected_instance_methods.grep_sort_to_s(METHOD_REGEXP),'protected methods before block')
    assert_equal(["c","c!","c=","c?"],My.public_instance_methods.grep_sort_to_s(METHOD_REGEXP),'public methods before block')

  end

  protected

end


class Array
  def grep_sort_to_s(regexp)
    grep(regexp).sort.map{|x| x.to_s}
  end
end


class My

  private

  def a
  end

  def a!
  end

  def a=
  end

  def a?
  end

  protected

  def b
  end

  def b!
  end

  def b=
  end

  def b?
  end

  public

  def c
  end

  def c!
  end

  def c=
  end

  def c?
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
webget_ruby_ramp-1.8.2 test/webget_ruby_ramp/class_test.rb
webget_ruby_ramp-1.8.0 test/webget_ruby_ramp/class_test.rb
webget_ruby_ramp-1.7.8 test/webget_ruby_ramp/class_test.rb
webget_ruby_ramp-1.7.7 test/webget_ruby_ramp/class_test.rb
webget_ruby_ramp-1.7.6 test/webget_ruby_ramp/class_test.rb
webget_ruby_ramp-1.7.5 test/webget_ruby_ramp/class_test.rb