[Groonga-commit] groonga/groonga-query-log [master] test: use data driven style

Zurück zum Archiv-Index

Haruka Yoshihara null+****@clear*****
Thu Dec 13 15:46:07 JST 2012


Haruka Yoshihara	2012-12-13 15:46:07 +0900 (Thu, 13 Dec 2012)

  New Revision: 820390c7a6bd94bc8988a930f1201888b4682ed2
  https://github.com/groonga/groonga-query-log/commit/820390c7a6bd94bc8988a930f1201888b4682ed2

  Log:
    test: use data driven style

  Modified files:
    test/test-analyzer.rb

  Modified: test/test-analyzer.rb (+11 -18)
===================================================================
--- test/test-analyzer.rb    2012-12-13 15:43:52 +0900 (cda3591)
+++ test/test-analyzer.rb    2012-12-13 15:46:07 +0900 (f0d1c63)
@@ -43,26 +43,13 @@ class AnalyzerTest < Test::Unit::TestCase
     $stdout = @original_stdout
   end
 
-  def test_to_console
-    actual_result = run_analyzer("--reporter", "console", @query_log_path)
-    expected_result = expected_analyzed_query("console.expected")
-    assert_equal(expected_result, actual_result)
-  end
 
-  def test_to_html
-    actual_result = run_analyzer("--reporter", "html", @query_log_path)
-    expected_result = expected_analyzed_query("html.expected")
-    assert_equal(expected_result, actual_result)
-  end
+  data(:console => "console", :html => "html", :json => "json")
+  def test_output(output_type)
+    actual_result = run_analyzer("--reporter", output_type, @query_log_path)
+    actual_result = normalize_time(actual_result) if output_type == "json"
 
-  def test_to_json
-    actual_result = run_analyzer("--reporter", "json", @query_log_path)
-
-    actual_result = actual_result.gsub(/(\"start_time\"):\d+/,
-                                       "\\1:START_TIME")
-    actual_result = actual_result.gsub(/(\"last_time\"):\d+/,
-                                       "\\1:LAST_TIME")
-    expected_result = expected_analyzed_query("json.expected")
+    expected_result = expected_analyzed_query("#{output_type}.expected")
     assert_equal(expected_result, actual_result)
   end
 
@@ -72,6 +59,12 @@ class AnalyzerTest < Test::Unit::TestCase
     @output.string
   end
 
+  def normalize_time(json_string)
+    json_string = json_string.gsub(/(\"start_time\"):(\d+)/,
+                                     "\\1:START_TIME")
+    json_string.gsub(/(\"last_time\"):(\d+)/, "\\1:LAST_TIME")
+  end
+
   def expected_analyzed_query(file_name)
     File.read(File.join(@fixture_path, file_name))
   end
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Zurück zum Archiv-Index