LoginSignup
0
0

More than 5 years have passed since last update.

テスト対象のメソッドにnilのブロックを渡す

Posted at

概要

テストのために、ブロックを受け取るメソッドに対して、nilとなるブロックを渡す方法について記載する。


メソッドの形式

下記のようなメソッドがあった時、raise 'main_block is necessary.'部分をテストするために、ブロックとしてnilを渡さなくてはいけない。

def handle_exception(&main_block)
  raise 'main_block is necessary.' unless (main_block)
  return true
end

解決策

下記のように実体のないブロックを渡してやればOK

@handler_stub.__send__('handle_exception',&nil_block)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0