$:.unshift File.dirname(__FILE__) + "/../../lib" require 'test/unit' require 'expected_result_set' class TestExpectedResultSet < Test::Unit::TestCase def setup @testee = ExpectedResultSet.new end def test_row_hashes_with_one_entry @testee.columns = ["firstColumn"] @testee.rows << [2] assert_equal( [{"firstColumn"=>2}], @testee.row_hashes ) end def test_columns_are_strings @testee.columns = ["firstColumn"] assert_equal ['firstColumn'], @testee.columns end def test_row_hash_with_one_row_and_one_column @testee.columns = ["firstColumn"] @testee.rows << [2] assert_equal( {"firstColumn"=>2}, @testee.row_hash( 0 ) ) end def test_row_hash_with_one_rows_and_two_columns @testee.columns = ["firstColumn", "secondColumn"] @testee.rows << [123, 456] assert_equal( {"firstColumn"=>123, "secondColumn"=>456}, @testee.row_hash( 0 ) ) end def test_row_hash_with_two_rows_and_two_columns @testee.columns = ["firstColumn", "secondColumn"] @testee.rows << [123, 234] @testee.rows << [345, 567] assert_equal( {"firstColumn"=>123, "secondColumn"=>234}, @testee.row_hash( 0 ) ) assert_equal( {"firstColumn"=>345, "secondColumn"=>567}, @testee.row_hash( 1 ) ) end def test_adding_row_as_hash @testee.with_row :first=>1, :second=>2 assert_equal({"first" => 1, "second"=>2}, @testee.row_hash(0)) end def test_adding_multiple_rows_as_hash @testee.with_row(:first=>1, :second=>2).with_row(:first=>10, :second=>20) assert_equal({"first" => 1, "second"=>2}, @testee.row_hash(0)) assert_equal({"first" => 10, "second"=>20}, @testee.row_hash(1)) end def test_adding_a_key_to_a_row_adds_that_to_previously_added_rows_with_nil_value @testee.with_row :first=>1 @testee.with_row :first=>10, :second=>20 assert_equal({"first" => 1, "second"=>nil}, @testee.row_hash(0)) assert_equal({"first" => 10, "second"=>20}, @testee.row_hash(1)) end def test_adding_a_fixture fixture_map = { "firstColumn" => "first", "secondColumn" => "last" } @testee.columns = [ "firstColumn", "secondColumn"] assert( @testee.rows.empty? ) @testee.add_fixture( fixture_map ) assert( !@testee.rows.empty? ) assert_equal( [ "first", "last" ], @testee.rows[0] ) end def test_adding_a_fixture_which_has_more_columns_than_expected_is_interested_in fixture_map = { "firstColumn" => "first", "secondColumn" => "last", "not very interesting column" => "value" } @testee.columns = [ "firstColumn", "secondColumn"] @testee.add_fixture( fixture_map ) assert_equal( [ "first", "last" ], @testee.rows[0] ) end def test_adding_a_fixture_which_has_less_columns_than_expected fixture_map = { "firstColumn" => "first" } @testee.columns = [ "firstColumn", "secondColumn"] @testee.add_fixture( fixture_map ) assert_equal( [ "first", nil ], @testee.rows[0] ) end def test_adding_two_fixtures_with_two_calls @testee.columns = [ :one, :two ] @testee.add_fixture( {:one => "first fixture first value", :two => "first fixture second value"} ) @testee.add_fixture( {:one => "second fixture first value", :two => "second fixture second value"} ) assert_equal( [ "first fixture first value", "first fixture second value" ], @testee.rows[0] ) assert_equal( [ "second fixture first value", "second fixture second value" ], @testee.rows[1] ) end def test_adding_two_fixtures_that_join @testee.columns = [ :parent_name, :child_name ] parent_fixture_map = {:parent_name => "I am the parent table record", :id_join => 5 } child_fixture_map = {:child_name => "I am the child table record", :id_join => 5 } @testee.add_fixture parent_fixture_map, child_fixture_map assert_equal( 1, @testee.rows.length ) assert_equal( [ "I am the parent table record", "I am the child table record" ], @testee.rows[0] ) end end