<commit_before>require File.dirname(__FILE__) + '/spec_helper.rb'
require 'yaml'

describe 'Doodle', 'block initialization of scalar attributes' do
  temporary_constant :Foo, :Bar, :Farm, :Barn, :Animal do
    before :each do
      class ::Animal < Doodle
        has :species
      end
      class Barn < Doodle
        has :animals, :collect => Animal
      end
      class Farm < Doodle
        has Barn
      end
      class Foo < Doodle
        has :ivar1, :kind => String
      end
      class Bar < Doodle
        has :block, :kind => Proc
      end
    end
    
    it 'should initialize an scalar attribute from a block' do
      farm = Farm do
        barn do
          animal "pig"
        end
      end
      farm.to_hash.should_be( {:barn=>{:animals=>[{:species=>"pig"}]}} )
      farm.to_string_hash.should_be( {"barn"=>{"animals"=>[{"species"=>"pig"}]}} )
    end

    it 'should do something sensible with Proc-valued attributes' do
      pending
      source_block = proc { puts "hello" }
      b = Bar do
        block &source_block
      end
      b.to_hash.should_be( { :block => source_block } )
    end
    
  end
end

<commit_msg>fixed block parameter to avoid warning<commit_after>require File.dirname(__FILE__) + '/spec_helper.rb'
require 'yaml'

describe 'Doodle', 'block initialization of scalar attributes' do
  temporary_constant :Foo, :Bar, :Farm, :Barn, :Animal do
    before :each do
      class ::Animal < Doodle
        has :species
      end
      class Barn < Doodle
        has :animals, :collect => Animal
      end
      class Farm < Doodle
        has Barn
      end
      class Foo < Doodle
        has :ivar1, :kind => String
      end
      class Bar < Doodle
        has :block, :kind => Proc
      end
    end

    it 'should initialize an scalar attribute from a block' do
      farm = Farm do
        barn do
          animal "pig"
        end
      end
      farm.to_hash.should_be( {:barn=>{:animals=>[{:species=>"pig"}]}} )
      farm.to_string_hash.should_be( {"barn"=>{"animals"=>[{"species"=>"pig"}]}} )
    end

    it 'should do something sensible with Proc-valued attributes' do
      pending
      source_block = proc { puts "hello" }
      b = Bar do
        block(&source_block)
      end
      b.to_hash.should_be( { :block => source_block } )
    end

  end
end


{'fraction_non_alphanumeric': 0.10757314974182444, 'fraction_numerical': 0.0008605851979345956, 'mean_word_length': 2.163265306122449, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '471333', 'n_tokens_mistral': 759, 'n_tokens_neox': 729, 'n_words': 224}