$:.unshift File.dirname(__FILE__) + "/../../lib" require 'test/unit' require 'expected_result_set' require 'marjoree/result_set' require 'marjoree' class TestAssertResults < Test::Unit::TestCase include Marjoree class StubStatement def initialize( result_set_rows = []) @result_set_rows = result_set_rows end def each_hash @result_set_rows.each { |row| yield row } end def columns return {"first"=>"val", "second"=>"val", "third"=>"val" } end end def setup @expected = ExpectedResultSet.new end def test_assert_equals_fails_when_expected_columns_not_found @expected.columns = [:first, :beta] other = ResultSet.new StubStatement.new assert_raises(Test::Unit::AssertionFailedError) {assert_results @expected, other} end def test_assert_unxexpected_columns_in_actual_ignored @expected.columns = [:first] other = ResultSet.new StubStatement.new assert_results @expected, other end def test_assert_equals_passes_with_empty_rows_and_identical_columns @expected.columns = [:first, :second] other = ResultSet.new StubStatement.new assert_results @expected, other end def test_assert_equals_fails_when_expected_row_count_excedes_actual @expected.columns = [:first, :second] @expected.rows << [1, 10] other = ResultSet.new StubStatement.new([{"first"=>1, "second"=>2}]) assert_raises(Test::Unit::AssertionFailedError) {assert_results @expected, other} end def test_assert_equals_passes_when_actual_row_count_excedes_expected @expected.columns = [:first, :second] other = ResultSet.new StubStatement.new([{"first"=>1, "second"=>2}, {}]) assert_results @expected, other end def test_assert_equals_passes_when_row_value_are_equal @expected.columns = [:first, :second] @expected.rows << [1, 2] other = ResultSet.new StubStatement.new([{"first"=>1, "second"=>2}]) assert_results @expected, other end def test_assert_equals_fails_when_row_count_differs @expected.columns = [:first, :second] @expected.rows << [1, 2] @expected.rows << [] other = ResultSet.new StubStatement.new([{"first"=>1, "second"=>2}]) assert_raises(Test::Unit::AssertionFailedError) {assert_results @expected, other} end end