A global space for storing temporary state during tests.
# File lib/pry/test/helper.rb, line 38 def constant_scope(*names) names.each do |name| Object.remove_const name if Object.const_defined?(name) end yield ensure names.each do |name| Object.remove_const name if Object.const_defined?(name) end end
inject a variable into a binding
# File lib/pry/test/helper.rb, line 31 def inject_var(name, value, b) Pry.current[:pry_local] = value b.eval("#{name} = ::Pry.current[:pry_local]") ensure Pry.current[:pry_local] = nil end
# File lib/pry/test/helper.rb, line 68 def mock_command(cmd, args=[], opts={}) output = StringIO.new ret = cmd.new(opts.merge(:output => output)).call_safely(*args) Struct.new(:output, :return).new(output.string, ret) end
# File lib/pry/test/helper.rb, line 74 def mock_exception(*mock_backtrace) e = StandardError.new("mock exception") (class << e; self; end).class_eval do define_method(:backtrace) { mock_backtrace } end e end
# File lib/pry/test/helper.rb, line 50 def mri18_and_no_real_source_location? Pry::Helpers::BaseHelpers.mri_18? && !(Method.instance_method(:source_location).owner == Method) end
Open a temp file and yield it to the block, closing it after @return [String] The path of the temp file
# File lib/pry/test/helper.rb, line 56 def temp_file(ext='.rb') file = Tempfile.new(['pry', ext]) yield file ensure file.close(true) if file File.unlink("#{file.path}c") if File.exists?("#{file.path}c") # rbx end
# File lib/pry/test/helper.rb, line 64 def unindent(*args) Pry::Helpers::CommandHelpers.unindent(*args) end