/vendor/gems/facets-2.4.5/test/core/binding/test_caller.rb

https://bitbucket.org/mediashelf/fedora-migrator · Ruby · 44 lines · 32 code · 10 blank · 2 comment · 0 complexity · 6a239adf41f3e4fd2a6bb3b464c707d7 MD5 · raw file

  1. require 'facets/binding/caller.rb'
  2. require 'test/unit'
  3. class TestBindingCallStack < Test::Unit::TestCase
  4. def setup
  5. a = 1
  6. b = 2
  7. x = "hello"
  8. # the line number must be updated if it moves
  9. @bind = binding; @this_line_no = __LINE__
  10. @this_file_name = File.basename( __FILE__ ) # why does it equal basename only?
  11. end
  12. def test___LINE__
  13. assert_equal( @this_line_no, @bind.__LINE__ )
  14. end
  15. def test___FILE__
  16. assert_equal( @this_file_name, File.basename( @bind.__FILE__ ) )
  17. end
  18. def test___DIR__
  19. assert_equal( File.dirname( @bind.__FILE__ ), @bind.__DIR__ )
  20. end
  21. def test_callstack
  22. assert_instance_of( Array, @bind.callstack )
  23. end
  24. def test_caller
  25. # how to test?
  26. assert_nothing_raised{ @bind.caller }
  27. end
  28. def test_callee
  29. assert_equal( :setup, @bind.__callee__ )
  30. end
  31. def test_method
  32. assert_equal( 'setup', @bind.__method__ )
  33. end
  34. end