diff --git a/lib/slacker/application.rb b/lib/slacker/application.rb index 2675f63..4160700 100644 --- a/lib/slacker/application.rb +++ b/lib/slacker/application.rb @@ -85,6 +85,8 @@ def configure configure_db_odbc when TINYTDS_DRIVER configure_db_tiny_tds + else + raise RuntimeError, "Unknown driver \"#{@configuration.db_driver}\" used in database configuration; Supported drivers: \"odbc\", \"tiny_tds\"." end configure_rspec configure_misc diff --git a/lib/slacker/query_result_matcher.rb b/lib/slacker/query_result_matcher.rb index 1c8a4ce..50ef154 100644 --- a/lib/slacker/query_result_matcher.rb +++ b/lib/slacker/query_result_matcher.rb @@ -1,9 +1,8 @@ require 'csv' +require 'time' module Slacker - DATE_FORMAT = "%m/%d/%Y" - DATETIME_FORMAT = '%Y-%m-%dT%H:%M:%S' - + class QueryResultMatcher def initialize(golden_master) @golden_master = golden_master @@ -100,13 +99,16 @@ def match_values?(master_val, subject_val) elsif master_val.kind_of?(String) case subject_val when ODBC::TimeStamp - (!!Time.strptime(master_val, DATE_FORMAT) rescue false) && Time.strptime(master_val, DATE_FORMAT) == ODBC::to_time(subject_val) + # Convert master string value to date-time and compare. + ((subject_val_time = Time.parse(master_val)) rescue false) && subject_val_time == ODBC::to_time(subject_val) + # Time is the class returned by tiny_tds when the resultset includes datetime or time. + when Time + # Convert master string value to date-time and compare. + ((subject_val_time = Time.parse(master_val)) rescue false) && subject_val_time == subject_val when Float (!!Float(master_val) rescue false) && Float(master_val) == subject_val when BigDecimal (!!BigDecimal(master_val) rescue false) && BigDecimal(master_val) == BigDecimal(subject_val) - when Time - (!!DateTime.strptime(DateTime.parse(master_val).to_s, DATETIME_FORMAT) rescue false) && DateTime.strptime(DateTime.parse(master_val).to_s, DATETIME_FORMAT) == DateTime.strptime(DateTime.parse(subject_val.to_s).to_s, DATETIME_FORMAT) else subject_val.to_s == master_val.to_s end diff --git a/lib/slacker/version.rb b/lib/slacker/version.rb index 6a5332f..8318600 100644 --- a/lib/slacker/version.rb +++ b/lib/slacker/version.rb @@ -1,3 +1,3 @@ module Slacker - VERSION = "1.0.21" + VERSION = "1.0.22" end diff --git a/spec/test_files/matcher/test_1.csv b/spec/test_files/matcher/test_1.csv index 6b5c3f1..a456a71 100644 --- a/spec/test_files/matcher/test_1.csv +++ b/spec/test_files/matcher/test_1.csv @@ -1,3 +1,3 @@ "Field 1","Field_2","b" 12,,"" -"test string",01/30/2011,8.9 +"test string",2011-01-30,8.9