Sha256: 4bcff49829dbd5c8debb4eab1bc0d050a2a42a0150ba88967862121b103be655
Contents?: true
Size: 1.12 KB
Versions: 18
Compression:
Stored size: 1.12 KB
Contents
# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__)) + '/helper' class TestBlockInit < Test::Unit::TestCase class Settable include Tracksperanto::BlockInit attr_accessor :foo, :bar private def privatized=(something) end end def test_block_init_with_hash s = Settable.new(:foo => "x", :bar => "y") assert_equal "x", s.foo assert_equal "y", s.bar end def test_block_init_with_hash_raises_on_unknown_attribute assert_raise(NoMethodError) { Settable.new(:nonexistent => true) } end def test_block_init_with_block_yields_the_object within_blk = nil s = Settable.new do | f | within_blk = f f.foo = "x" end assert_equal s, within_blk, "Should have yielded the object to the blk" assert_equal "x", s.foo end def test_block_init_attributes_overwrite_hash_attributes s = Settable.new(:foo => "bar") { |f| f.foo = "x" } assert_equal "x", s.foo end if RUBY_VERSION > '1.9' def test_block_init_uses_public_send assert_raise(NoMethodError) { Settable.new(:privatized => true) } end end end
Version data entries
18 entries across 18 versions & 1 rubygems