Module: Minitest::Substitute::Substitute

Defined in:
lib/minitest/substitute/substitute.rb

Instance Method Summary collapse

Instance Method Details

#substitute(variable, substitute, on: self) { ... } ⇒ Object

Substitute the variable value for the duration of the given block

Parameters:

  • variable (String)

    instance or global variable name

  • substitute (Object)

    temporary substitution value

  • on (Object, nil) (defaults to: self)

    substitute in the context of this object

Yields:

  • block during which the substitution is made

Returns:

  • (Object)

    return value of the yielded block



14
15
16
17
18
19
20
# File 'lib/minitest/substitute/substitute.rb', line 14

def substitute(variable, substitute, on: self)
  substitutor = Minitest::Substitute::Substitutor.new(variable, on: on).substitute(substitute)
  substitutor.commit
  yield.tap do
    substitutor.rollback
  end
end