spec_helpeRSpec.conf
を呼び出している場合、
以下のような警告が出てくることがあります。
1 ****************************************************** 2 DEPRECATION WARNING: you are using deprecated 3 behaviour that will be removed from RSpec 3. 4 5 You have set some configurat ion options after an 6 example group has already been defined. In RSpec 3, 7 this will not be allowed. All configurat ion should 8 happen before the first example group is defined. 9 The configurat ion is happening at: 10 11 /path/to/a pp/spec/sp ec_helper. rb:50 12 ******************************************************
これは spec_helpe
そもそも Ruby の require は一度しかファイルを読み込まないように なっていますが、読み込んだかどうか判定する基準となるのが 読み込み対象のファイルの絶対パスではなく、require に渡された引数であるため、同じファイルをrequireしてもパスの指定の仕方によって何度も読み込まれてしまうのです。
そこで、以下のように spec_helpe
1 $LOADED_FEATURES.push File.expand_pat h(__FILE__) 2 def require(path) 3 path = File.expand_pat h(path) if path =~ %r{^[./]} 4 super path 5 end
require を上書きして引数が "." か "/" で始まっている場合に expand_pat
posted by
genki
on Mon 30 May 2011
at 13:00