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

Version Path
tracksperanto-3.5.9 test/test_block_init.rb
tracksperanto-3.5.8 test/test_block_init.rb
tracksperanto-3.5.7 test/test_block_init.rb
tracksperanto-3.5.6 test/test_block_init.rb
tracksperanto-3.5.5 test/test_block_init.rb
tracksperanto-3.5.4 test/test_block_init.rb
tracksperanto-3.5.2 test/test_block_init.rb
tracksperanto-3.5.1 test/test_block_init.rb
tracksperanto-3.5.0 test/test_block_init.rb
tracksperanto-3.4.1 test/test_block_init.rb
tracksperanto-3.4.0 test/test_block_init.rb
tracksperanto-3.3.13 test/test_block_init.rb
tracksperanto-3.3.12 test/test_block_init.rb
tracksperanto-3.3.11 test/test_block_init.rb
tracksperanto-3.3.10 test/test_block_init.rb
tracksperanto-3.3.9 test/test_block_init.rb
tracksperanto-3.3.8 test/test_block_init.rb
tracksperanto-3.3.7 test/test_block_init.rb