diff --git a/ChangeLog b/ChangeLog index dff430c904..f669ca4733 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Sun Nov 9 09:50:22 2014 Tanaka Akira + + * test/webrick: Refine log tests. + Sun Nov 9 08:58:05 2014 Tanaka Akira * defs/known_errors.def (EHWPOISON): New errno symbol. diff --git a/test/webrick/test_httpauth.rb b/test/webrick/test_httpauth.rb index b0cb8a05bf..0d5288e2a2 100644 --- a/test/webrick/test_httpauth.rb +++ b/test/webrick/test_httpauth.rb @@ -61,11 +61,17 @@ class TestWEBrickHTTPAuth < Test::Unit::TestCase http.request(g){|res| assert_not_equal("hoge", res.body, log.call)} } } - pat = /ERROR Basic WEBrick's realm: webrick: password unmatch\./ - assert_match(pat, log); log.sub!(pat, '') - pat = /ERROR WEBrick::HTTPStatus::Unauthorized/ - assert_match(pat, log); log.sub!(pat, '') - assert_not_match(/ERROR/, log) + log = log.lines.to_a + log.reject! {|line| /\A\s*\z/ =~ line } + pats = [ + /ERROR Basic WEBrick's realm: webrick: password unmatch\./, + /ERROR WEBrick::HTTPStatus::Unauthorized/ + ] + pats.each {|pat| + assert_operator(log, :grep, pat) + log.reject! {|line| pat =~ line } + } + assert_equal([], log) end def test_basic_auth3 @@ -148,15 +154,18 @@ class TestWEBrickHTTPAuth < Test::Unit::TestCase end } } - pat = /ERROR Digest WEBrick's realm: no credentials in the request\./ - assert_match(pat, log); log.sub!(pat, '') - pat = /ERROR WEBrick::HTTPStatus::Unauthorized/ - assert_match(pat, log); log.sub!(pat, '') - pat = /ERROR Digest WEBrick's realm: webrick: digest unmatch\./ - assert_match(pat, log); log.sub!(pat, '') - pat = /ERROR WEBrick::HTTPStatus::Unauthorized/ - assert_match(pat, log); log.sub!(pat, '') - assert_not_match(/ERROR/, log) + log = log.lines.to_a + log.reject! {|line| /\A\s*\z/ =~ line } + pats = [ + /ERROR Digest WEBrick's realm: no credentials in the request\./, + /ERROR WEBrick::HTTPStatus::Unauthorized/, + /ERROR Digest WEBrick's realm: webrick: digest unmatch\./ + ] + pats.each {|pat| + assert_operator(log, :grep, pat) + log.reject! {|line| pat =~ line } + } + assert_equal([], log) end private diff --git a/test/webrick/utils.rb b/test/webrick/utils.rb index 667ae737bb..b15ef9a408 100644 --- a/test/webrick/utils.rb +++ b/test/webrick/utils.rb @@ -41,7 +41,7 @@ module TestWEBrick server = klass.new({ :BindAddress => "127.0.0.1", :Port => 0, :ServerType => Thread, - :Logger => WEBrick::Log.new(logger), + :Logger => WEBrick::Log.new(logger, WEBrick::BasicLog::WARN), :AccessLog => [[logger, ""]] }.update(config)) server_thread = server.start