[前][次][番号順一覧][スレッド一覧]

ruby-changes:36258

From: akr <ko1@a...>
Date: Sun, 9 Nov 2014 18:36:40 +0900 (JST)
Subject: [ruby-changes:36258] akr:r48339 (trunk): * test/xmlrpc: Refine log test.

akr	2014-11-09 18:36:33 +0900 (Sun, 09 Nov 2014)

  New Revision: 48339

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=48339

  Log:
    * test/xmlrpc: Refine log test.

  Modified files:
    trunk/ChangeLog
    trunk/test/xmlrpc/test_webrick_server.rb
    trunk/test/xmlrpc/webrick_testing.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 48338)
+++ ChangeLog	(revision 48339)
@@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Nov  9 18:35:36 2014  Tanaka Akira  <akr@f...>
+
+	* test/xmlrpc: Refine log test.
+
 Sun Nov  9 18:33:33 2014  Martin Duerst <duerst@i...>
 
 	* lib/unicode_normalize/normalize.rb: Replaced if-else by
Index: test/xmlrpc/webrick_testing.rb
===================================================================
--- test/xmlrpc/webrick_testing.rb	(revision 48338)
+++ test/xmlrpc/webrick_testing.rb	(revision 48339)
@@ -2,21 +2,14 @@ require 'timeout' https://github.com/ruby/ruby/blob/trunk/test/xmlrpc/webrick_testing.rb#L2
 
 module TestXMLRPC
 module WEBrick_Testing
-  empty_log = Object.new
-  def empty_log.<<(str)
-    assert_equal('', str)
-    self
-  end
-  NoLog = WEBrick::Log.new(empty_log, WEBrick::BasicLog::WARN)
-
-  def start_server(config={})
+  def start_server(logger, config={})
     raise "already started" if defined?(@__server) && @__server
     @__started = false
 
     @__server = WEBrick::HTTPServer.new(
       {
         :BindAddress => "localhost",
-        :Logger => NoLog,
+        :Logger => logger,
         :AccessLog => [],
       }.update(config))
     yield @__server
@@ -38,7 +31,12 @@ module WEBrick_Testing https://github.com/ruby/ruby/blob/trunk/test/xmlrpc/webrick_testing.rb#L31
   end
 
   def with_server(config, servlet)
-    addr = start_server(config) {|w| w.mount('/RPC2', create_servlet) }
+    log = []
+    logger = WEBrick::Log.new(log, WEBrick::BasicLog::WARN)
+    addr = start_server(logger, config) {|w|
+      servlet = servlet.call(w) if servlet.respond_to? :call
+      w.mount('/RPC2', servlet)
+    }
       client_thread = Thread.new {
         begin
           yield addr
@@ -49,6 +47,7 @@ module WEBrick_Testing https://github.com/ruby/ruby/blob/trunk/test/xmlrpc/webrick_testing.rb#L47
       server_thread = Thread.new {
         @__server_thread.join
         @__server = nil
+        assert_equal([], log)
       }
       assert_join_threads([client_thread, server_thread])
   end
Index: test/xmlrpc/test_webrick_server.rb
===================================================================
--- test/xmlrpc/test_webrick_server.rb	(revision 48338)
+++ test/xmlrpc/test_webrick_server.rb	(revision 48339)
@@ -11,19 +11,19 @@ module TestXMLRPC https://github.com/ruby/ruby/blob/trunk/test/xmlrpc/test_webrick_server.rb#L11
 class Test_Webrick < Test::Unit::TestCase
   include WEBrick_Testing
 
-  @@basic_auth = WEBrick::HTTPAuth::BasicAuth.new(
-    :Realm => 'auth',
-    :UserDB => WEBrick::HTTPAuth::Htpasswd.new(File.expand_path('./htpasswd', File.dirname(__FILE__))),
-    :Logger => NoLog,
-  )
-
-  def create_servlet
+  def create_servlet(server)
     s = XMLRPC::WEBrickServlet.new
 
-    def s.service(req, res)
-      @@basic_auth.authenticate(req, res)
+    basic_auth = WEBrick::HTTPAuth::BasicAuth.new(
+      :Realm => 'auth',
+      :UserDB => WEBrick::HTTPAuth::Htpasswd.new(File.expand_path('./htpasswd', File.dirname(__FILE__))),
+      :Logger => server.logger,
+    )
+
+    class << s; self end.send(:define_method, :service) {|req, res|
+      basic_auth.authenticate(req, res)
       super(req, res)
-    end
+    }
 
     s.add_handler("test.add") do |a,b|
       a + b
@@ -68,7 +68,7 @@ class Test_Webrick < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/xmlrpc/test_webrick_server.rb#L68
     # NOTE: I don't enable SSL testing as this hangs
     [false].each do |use_ssl|
       option = setup_http_server_option(use_ssl)
-      with_server(option, create_servlet) {|addr|
+      with_server(option, method(:create_servlet)) {|addr|
         @s = XMLRPC::Client.new3(:host => addr.ip_address, :port => addr.ip_port, :use_ssl => use_ssl)
         @s.user = 'admin'
         @s.password = 'admin'

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]