[#34722] cgi.rb の form の挙動 — FUJIOKA Takeyuki <fujioka@...>

藤岡です。

18 messages 2002/04/02

[#34724] 「たのしい Ruby 」 — Shin-ichiro HARA <sinara@...>

原(信)です。

18 messages 2002/04/02
[#34728] Re: 「たのしい Ruby 」 — matz@... (Yukihiro Matsumoto) 2002/04/02

まつもと ゆきひろです

[#34746] Re: 「たのしい Ruby 」 — TAKAHASHI Masayoshi <maki@...> 2002/04/02

高橋征義です。

[#34752] Re: 「たのしい Ruby 」 — Shin-ichiro HARA <sinara@...> 2002/04/03

原(信)です。

[#34842] [ann] Web 家計簿(β版)リリース — 堀川 久 <vzw00011@...>

こんにちは。

18 messages 2002/04/07
[#34869] Re: [ann] Web 家計簿(β版)リリース — Nobuhide Kanagawa <nobuhide@...> 2002/04/11

こんばんわ!

[#34885] creating a scope / anonymous module — Takaaki Tateishi <ttate@...>

立石です.

38 messages 2002/04/13
[#34891] Re: creating a scope / anonymous module — nobu.nakada@... 2002/04/14

なかだです。

[#34892] Re: creating a scope / anonymous module — Takaaki Tateishi <ttate@...> 2002/04/14

At Sun, 14 Apr 2002 18:00:12 +0900,

[#34894] Re: creating a scope / anonymous module — nobu.nakada@... 2002/04/14

なかだです。

[#34896] Re: creating a scope / anonymous module — Takaaki Tateishi <ttate@...> 2002/04/14

At Sun, 14 Apr 2002 21:08:47 +0900,

[#34899] Re: creating a scope / anonymous module — matz@... (Yukihiro Matsumoto) 2002/04/15

まつもと ゆきひろです

[#34901] Re: creating a scope / anonymous module — Takaaki Tateishi <ttate@...> 2002/04/15

At Mon, 15 Apr 2002 09:51:05 +0900,

[#34902] Re: creating a scope / anonymous module — matz@... (Yukihiro Matsumoto) 2002/04/15

まつもと ゆきひろです

[#34903] Re: creating a scope / anonymous module — Takaaki Tateishi <ttate@...> 2002/04/15

At Mon, 15 Apr 2002 13:53:53 +0900,

[#34904] Re: creating a scope / anonymous module — matz@... (Yukihiro Matsumoto) 2002/04/15

まつもと ゆきひろです

[#34910] Re: creating a scope / anonymous module — Takaaki Tateishi <ttate@...> 2002/04/15

At Mon, 15 Apr 2002 15:07:57 +0900,

[#34958] windows 版 ruby でシステムコマンドが動かない — "jazzski _comp" <jazzski_comp@...>

はじめてrubyを使うのですが、windows版(cygwin版1.6.1)で下記のように

12 messages 2002/04/23

[ruby-list:34730] RubyUnit: I want to test a message of an exception with assert_exception(){}.

From: NISHIMATSU Takeshi <t-nissie@...>
Date: 2002-04-02 08:37:57 UTC
List: ruby-list #34730
西松と申します.

Ruby, RubyUnitを便利に使っています. ありがとうございます.
assert_exception(){}で例外のメッセージもチェックしたくなりました.
最後にパッチを添付しました.
今までのテストスクリプトもそのまま使えるように書いたつもりです.
どうでしょうか.
それとも, じつは, はじめからちゃんとチェックできるのでしょうか...

= test-a.rb ===================================
require 'rubyunit'
def a(i)
  if (i==1)
    raise(ArgumentError, "Boom!")
  elsif (i==2)
    raise(ArgumentError, "Boom!Boom!")
  else
    i
  end
end

print "Version of Ruby: #{VERSION}\n"
print "Version of RubyUnit: #{RUNIT::VERSION}\n"

class Test_a < RUNIT::TestCase
  def test_a
    assert_equal(3, a(3))
  end
  def test_a_exception
    assert_exception(ArgumentError){                      # いままでの使い方 
      a(1)
    }
    assert_exception(ArgumentError.exception("Boom!")){   # messageもテストしたい!
      a(1)
    }
    assert_exception(ArgumentError.exception("Boom!")){   # messageが間違っていたら...
      a(2)
    }
  end
  def test_a_exception_fail
    assert_exception(ArgumentError){                      # いままでの使い方.
      a(0)
    }
  end
end
==========================================

実行すると:
% ruby test-a.rb
Version of Ruby: 1.6.6
Version of RubyUnit: 0.5.4

Test_a#test_a .
Test_a#test_a_exception E.
Test_a#test_a_exception_fail F.
Time: 0.044682
FAILURES!!!
Test Results:
 Run: 3/3(4 asserts) Failures: 1 Errors: 1
Failures: 1
test-a.rb:31:in `test_a_exception_fail'(Test_a): expected:<ArgumentError> but was:<NO EXCEPTION RAISED> (RUNIT::AssertionFailedError)
        from test-a.rb:30
Errors: 1
test-a.rb:23:in `test_a_exception'(Test_a): class or module required (TypeError)
        from test-a.rb:30
% 


添付のパッチをあててから実行すると:
% ruby test-a.rb
Version of Ruby: 1.6.6
Version of RubyUnit: 0.5.4

Test_a#test_a .
Test_a#test_a_exception F.
Test_a#test_a_exception_fail F.
Time: 0.004309
FAILURES!!!
Test Results:
 Run: 3/3(5 asserts) Failures: 2 Errors: 0
Failures: 2
test-a.rb:26:in `test_a_exception'(Test_a): expected mesage:"Boom!" but was:"Boom!Boom!" (RUNIT::AssertionFailedError)
        from test-a.rb:30
test-a.rb:31:in `test_a_exception_fail'(Test_a): expected:<ArgumentError> but was:<NO EXCEPTION RAISED> (RUNIT::AssertionFailedError)
        from test-a.rb:30
% 


パッチ:
--- assert.rb.original  Fri Mar 29 11:30:47 2002
+++ assert.rb   Tue Apr  2 16:55:41 2002
@@ -221,7 +221,14 @@
 
     def assert_exception(exception, message="")
       setup_assert
+      if exception.kind_of?(Exception)
+       expected_message = exception.message
+       exception = exception.class
+      else
+       expected_message = false
+      end
       exception_raised = true
+      message_was_correct = true
       err = ""
       ret = nil
       begin
@@ -231,7 +238,12 @@
       rescue Exception
        if $!.instance_of?(exception)
          exception_raised = true
-         ret = $!
+         if (expected_message && $!.message != expected_message)
+           message_was_correct = false
+           err = $!.message
+         else
+           ret = $!
+         end
        else
          exception_raised = false
          err = $!.type
@@ -240,6 +252,12 @@
       if !exception_raised
        msg = build_message(message, exception, err) {|arg1, arg2|
          "expected:<#{arg1}> but was:<#{arg2}>"
+       }
+       raise_assertion_error(msg)
+      end
+      if !message_was_correct
+       msg = build_message(message, expected_message, err) {|arg1, arg2|
+         "expected mesage:\"#{arg1}\" but was:\"#{arg2}\""
        }
        raise_assertion_error(msg)
       end

In This Thread

Prev Next