Sha256: 64b7404188181ab5118b29eabeba104199d109a5f652d1fce0ded32ee82d3c6c

Contents?: true

Size: 1.85 KB

Versions: 1

Compression:

Stored size: 1.85 KB

Contents

# -*- coding: utf-8 -*-
require "sixarm_ruby_ramp_test"
require "sixarm_ruby_ramp/class"

class ClassTest < Minitest::Test

  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

1 entries across 1 versions & 1 rubygems

Version Path
sixarm_ruby_ramp-4.2.4 test/sixarm_ruby_ramp_test/class_test.rb