mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
4391aa863e
* add Pry::Testable, and friends. This commit replaces lib/pry/test/helper.rb by using category modules. There's now: * Pry::Testable: * Pry::Testable::Evalable * Pry::Testable::Mockable * Pry::Testable::Utility * Pry::Testable::PryTester 'include Pry::Testable' includes all of the above. For the pry test suite it worked out best to include 'Pry::Testable' at the top-level. In plugins I've written though this hasn't been the case, and I only normally need: Pry::Testable::Evalable. So it reduces pollution for the third-party cases, which this code is intended for since it lives within lib/ of the project. What do you think? * breaking change: add set_testenv_variables and unset_testenv_variables * breaking change: add Pry::Testable::Variables, and rename constant_scope() to temporary_constants(). * breaking change: rename inject_var as insert_variable, and move its definition to Pry::Testable::Variables. * include Pry::Testable::Evalable & include Pry::Testable::Variables into the top-level, but keep the other two modules spec-local. * document third argument of insert_variable. * update CHANGELOG.md * note changelog entry is a breaking change * update documentation
70 lines
1.8 KiB
Ruby
70 lines
1.8 KiB
Ruby
# good idea ???
|
|
# if you're testing pry plugin you should require pry by yourself, no?
|
|
require 'pry' if not defined?(Pry)
|
|
|
|
module Pry::Testable
|
|
extend self
|
|
require_relative "testable/pry_tester"
|
|
require_relative "testable/evalable"
|
|
require_relative "testable/mockable"
|
|
require_relative "testable/variables"
|
|
require_relative "testable/utility"
|
|
|
|
#
|
|
# When {Pry::Testable} is included into another module or class,
|
|
# the following modules are also included: {Pry::Testable::Mockable},
|
|
# {Pry::Testable::Evalable}, {Pry::Testable::Variables}, and
|
|
# {Pry::Testable::Utility}.
|
|
#
|
|
# @note
|
|
# Each of the included modules mentioned above may also be used
|
|
# standalone or in a pick-and-mix fashion.
|
|
#
|
|
# @param [Module] mod
|
|
# A class or module.
|
|
#
|
|
# @return [void]
|
|
#
|
|
def self.included(mod)
|
|
mod.module_eval do
|
|
include Pry::Testable::Mockable
|
|
include Pry::Testable::Evalable
|
|
include Pry::Testable::Variables
|
|
include Pry::Testable::Utility
|
|
end
|
|
end
|
|
|
|
TEST_DEFAULTS = {
|
|
color: false,
|
|
pager: false,
|
|
should_load_rc: false,
|
|
should_load_local_rc: false,
|
|
correct_indent: false,
|
|
collison_warning: false,
|
|
history: {
|
|
should_load: false,
|
|
should_save: false
|
|
}
|
|
}
|
|
private_constant :TEST_DEFAULTS
|
|
|
|
#
|
|
# Sets various configuration options that make Pry optimal for a test
|
|
# environment, see source code for complete details.
|
|
#
|
|
# @return [void]
|
|
#
|
|
def self.set_testenv_variables
|
|
Pry.config = Pry::Config.from_hash(TEST_DEFAULTS, Pry::Config::Default.new)
|
|
Pry.config.hooks = Pry::Hooks.new
|
|
end
|
|
|
|
#
|
|
# Reset the Pry configuration to their default values.
|
|
#
|
|
# @return [void]
|
|
#
|
|
def self.unset_testenv_variables
|
|
Pry.config = Pry::Config.from_hash({}, Pry::Config::Default.new)
|
|
end
|
|
end
|