Method: Object#stub_const

Defined in:
lib/minitest/stub_const.rb

#stub_const(name, val = nil, &block) ⇒ Object

Replace the value of constant name for the duration of a block. This is especially useful when testing that the expected class methods are being called on a Module or Class instance.

Example:

module Foo
  BAR = :original
end

Foo.stub_const(:BAR, :stubbed) do
  Foo::BAR
end
# => :stubbed

Foo::BAR
# => :original


19
20
21
# File 'lib/minitest/stub_const.rb', line 19

def stub_const(name, val = nil, &block)
  stub_consts(name => val, &block)
end