$:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib') require 'test/unit' require 'buildmaster/tree_to_object' module BuildMaster class TreeToObjectTest < Test::Unit::TestCase def test_should_populate_string_fields content = < error assert_equal(true, error.message.include?('not_field')) assert_equal(true, error.message.include?('string')) end end def test_should_raise_error_if_sub_property_not_found content = < error assert_equal(true, error.message.include?('not_sub_property')) assert_equal(true, error.message.include?('sub property')) end end def test_should_raise_error_if_array_property_not_found content = < error assert_equal(true, error.message.include?('not_array_property')) assert_equal(true, error.message.include?('array')) end end def test_empty_content object = TreeToObject.from_yaml('', SampleObject.new) assert_equal(nil, object.field_one) end end class SampleObject attr_reader :field_one, :field_two, :object_two, :array_field attr_writer :field_one, :field_two def initialize @object_two = SampleTwo.new @array_field = Array.new end def add_to_array_field item = SampleTwo.new @array_field.push(item) return item end end class SampleTwo attr_reader :field, :index attr_writer :field, :index end end