Created
October 13, 2011 15:43
-
-
Save tobynet/1284570 to your computer and use it in GitHub Desktop.
test for multiple logger
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| # -*- encoding: utf-8 -*- | |
| # 複数のIOに出力したいテスト | |
| # テストだけ書いた | |
| # Rubyist Magazine - 標準添付ライブラリ紹介 【第 6 回】 委譲 http://jp.rubyist.net/magazine/?0012-BundledLibraries | |
| # instance method Forwardable#def_delegators http://doc.ruby-lang.org/ja/1.9.2/method/Forwardable/i/def_delegators.html | |
| require 'minitest/unit' | |
| require 'minitest/autorun' # 実行したらテストも実行する | |
| require 'forwardable' | |
| require 'logger' | |
| class Object | |
| def foobar(x) | |
| self * x # do something!!!!!! | |
| end | |
| end | |
| class TestMultipleForwardable < MiniTest::Unit::TestCase | |
| CORRECT = [2048, -200, "abcabc"] | |
| def setup | |
| @a = [1024, -100, "abc"] | |
| end | |
| # map経由でメソッドを呼出 | |
| def test_call_by_map | |
| assert_equal CORRECT, @a.map{|x| x.foobar(2) } | |
| end | |
| # mapなしで、呼び出す | |
| def test_call_directly | |
| assert_equal CORRECT, @a.foobar(2) | |
| end | |
| end | |
| #logger = MultiLogger.new(STDOUT,STDERR) | |
| #logger.info "infooooooo1!!!!!!" | |
| #logger.debug "debuggggggggggeeeerr!!" | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ ruby multilogger-test.rb | |
| Loaded suite multilogger-test | |
| Started | |
| .F | |
| Finished in 0.000000 seconds. | |
| 1) Failure: | |
| test_call_directly(TestMultipleForwardable) [multilogger-test.rb:34]: | |
| Expected [2048, -200, "abcabc"], not [1024, -100, "abc", 1024, -100, "abc"]. | |
| 2 tests, 2 assertions, 1 failures, 0 errors, 0 skips | |
| Test run options: --seed 46579 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment