Skip to content

Commit

Permalink
Add a test helper to undefine a constant in a block
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrmurach committed Nov 26, 2023
1 parent f1534f3 commit 64ac303
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,28 @@ def replace_standard_streams(output)
ensure
$stdin, $stdout, $stderr = *original_streams
end

# Undefine a constant
#
# @example
# undefine_const(:Readline) do
# ...
# end
#
# @param [String, Symbol] name
# the constant name
#
# @return [void]
#
# @api public
def undefine_const(name)
if Object.const_defined?(name)
const = Object.send(:remove_const, name)
end
yield
ensure
Object.const_set(name, const) if const
end
end

require "tty-screen"
Expand Down

0 comments on commit 64ac303

Please sign in to comment.