speclog = Logger.new('log/rspec.log')
rspec 統合テストの 1 つにカスタム ロガーがあり、 before(:each) ... end
andit ... end
ブロック内から呼び出すと正常に動作します。
ただし、共通の「すべてを表示」ルーチンを独自のメソッドに移動していくつかのテストを DRY すると、そのメソッドで speclog を呼び出すとエラーがスローされますundefined local variable or method 'speclog'
#testit_spec.rb
require 'integration_spec_helper'
speclog = Logger.new('log/rspec.log')
describe FooController do
before(:each) do ... end
it "test1" do ... end # speclog directly inside here works fine
it "test2" do ... end # but calling log_it_all throws error
def log_it_all
speclog.debug "common messages" # SPECLOG is 'undefined' HERE?
end
end
上記のような一般的な方法で speclog にアクセスする場合、前に Rspec::Something を付ける必要がありますか? もしそうなら、なぜですか?