PageRenderTime 48ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/gems/facets-2.4.5/test/core/kernel/test_populate.rb

https://bitbucket.org/mediashelf/fedora-migrator
Ruby | 46 lines | 29 code | 8 blank | 9 comment | 0 complexity | 658172caa6a69dc144b00d91d8a7931b MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0, IPL-1.0, AGPL-1.0, LGPL-3.0
  1. require 'facets/kernel/populate.rb'
  2. require 'test/unit'
  3. class TestKernelPopulate < Test::Unit::TestCase
  4. Customer = Struct.new( "Customer", :name, :address, :zip )
  5. # def test_assign_from
  6. # o = Object.new
  7. # o.instance_eval{ @z=0; @a=1; @b=2 } #; @@a=3 }
  8. # assign_from( o, "z", "@a", "@b" ) #, "@@a" )
  9. # assert_equal( 1, @a )
  10. # assert_equal( 2, @b )
  11. # #assert_equal( 3, @@a )
  12. # end
  13. def test_set_from
  14. bob = Customer.new("Bob Sawyer", "123 Maple, Anytown NC", 12345)
  15. joe = Customer.new("Joe Pitare")
  16. joe.set_from(bob, :address, :zip)
  17. assert_equal("Joe Pitare", joe.name)
  18. assert_equal("123 Maple, Anytown NC", joe.address)
  19. assert_equal(12345, joe.zip)
  20. end
  21. #Customer = Struct.new( "Customer", :name, :address, :zip )
  22. def test_populate_with_hash
  23. bob = Customer.new()
  24. x = { :name => "Bob Sawyer", :address => "123 Maple, Anytown NC", :zip => 12345 }
  25. bob.populate(x)
  26. assert_equal(x[:name], bob.name)
  27. assert_equal(x[:address], bob.address)
  28. assert_equal(x[:zip], bob.zip)
  29. end
  30. def test_populate_with_block
  31. bob = Customer.new()
  32. x = lambda {|s| s.name = "Bob Sawyer"; s.address = "123 Maple, Anytown NC"; s.zip = 12345 }
  33. bob.populate(&x)
  34. assert_equal("Bob Sawyer", bob.name)
  35. assert_equal("123 Maple, Anytown NC", bob.address)
  36. assert_equal(12345, bob.zip)
  37. end
  38. end