WebMock の Ruby 2.6 で CI をまわしている分が落ちていて、原因を調べるのに結構時間が掛かって、さらにどう直そうかと難儀しかかっていたところ、ふと浮かんだのが TracePoint
だった。パッチの前に手元で素振ったのが以下。
class Foo def foo tmp = 'hello' puts tmp end end class Bar < Foo def foo trace = TracePoint.trace(:line) do |tp| if tp.binding.local_variable_defined?(:tmp) tp.binding.local_variable_set(:tmp, 'hi') end end super trace.disable end end Bar.new.foo # => hi
ここ最近、世間が空前の TracePoint
のようでご多分にもれず思考に影響を受けていて、あれ?これで解決できるじゃんとなった。送ったパッチは以下となる。もともとホワイトボックスでの実装に依存した設計だったのでこんなところだろうという見解。