pry 0.11.2 → 0.11.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +46 -1
- data/lib/pry.rb +1 -0
- data/lib/pry/color_printer.rb +1 -1
- data/lib/pry/commands/whereami.rb +1 -1
- data/lib/pry/config/behavior.rb +1 -0
- data/lib/pry/config/default.rb +2 -2
- data/lib/pry/helpers/base_helpers.rb +59 -97
- data/lib/pry/helpers/text.rb +20 -5
- data/lib/pry/method/weird_method_locator.rb +16 -5
- data/lib/pry/platform.rb +93 -0
- data/lib/pry/testable.rb +70 -0
- data/lib/pry/testable/evalable.rb +15 -0
- data/lib/pry/testable/mockable.rb +14 -0
- data/lib/pry/testable/pry_tester.rb +73 -0
- data/lib/pry/testable/utility.rb +26 -0
- data/lib/pry/testable/variables.rb +46 -0
- data/lib/pry/version.rb +1 -1
- metadata +10 -4
- data/lib/pry/test/helper.rb +0 -179
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b64fffecceb1735b3224542dddf8210a4eea3ea
|
4
|
+
data.tar.gz: 00453f4390dc9d7d31a5a0215823f2f57929b097
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9fa428d4b7e63c0260dfd1082de23e978adc52461fb1123e415baed4101171a664ba7928511acbfe17d9aa034002f0e5f61645de6fa7cba036be1b87fd05525b
|
7
|
+
data.tar.gz: 91ca93bd5bd1948952ddb11bccc0ab03e1f792e7025f3ff77461c89801993f5141c1e5fbe85e123308b2d19c8ec86daf662c4e419b3bfef571d54f044e729758
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,49 @@
|
|
1
|
+
### HEAD
|
2
|
+
|
3
|
+
#### Features
|
4
|
+
|
5
|
+
* Add Pry::Testable, an improved modular replacement for PryTestHelpers.
|
6
|
+
**breaking change**.
|
7
|
+
|
8
|
+
See pull request [#1679](https://github.com/pry/pry/pull/1679).
|
9
|
+
|
10
|
+
* Add a new category module: "Pry::Platform". Loosely related to #1668 below.
|
11
|
+
|
12
|
+
See pull request [#1670](https://github.com/pry/pry/pull/1670)
|
13
|
+
|
14
|
+
* Add `mac_osx?` and `linux?` utility functions to Pry::Helpers::BaseHelpers.
|
15
|
+
|
16
|
+
See pull request [#1668](https://github.com/pry/pry/pull/1668).
|
17
|
+
|
18
|
+
* Add utility functions for drawing colorised text on a colorised background.
|
19
|
+
|
20
|
+
See pull request [#1673](https://github.com/pry/pry/pull/1673).
|
21
|
+
|
22
|
+
#### Bug fixes
|
23
|
+
|
24
|
+
* Fix a case of infinite recursion in `Pry::Method::WeirdMethodLocator#find_method_in_superclass`
|
25
|
+
that users of the [Hanami](http://hanamirb.org/) web framework experienced and
|
26
|
+
reported since 2015.
|
27
|
+
|
28
|
+
See pull request [#1639](https://github.com/pry/pry/pull/1689).
|
29
|
+
|
30
|
+
* Fix a bug where Method objects were not returned for setters inherited
|
31
|
+
from a default (Pry::Config::Default). Eg, this is no longer an error:
|
32
|
+
|
33
|
+
pry(main)> d = Pry::Config.from_hash({}, Pry::Config::Default.new)
|
34
|
+
pry(main)> d.method(:exception_whitelist=) # Error
|
35
|
+
|
36
|
+
See pull request [#1688](https://github.com/pry/pry/pull/1688).
|
37
|
+
|
38
|
+
* Do not capture unused Proc objects in Text helper methods `no_color` and `no_paging`,
|
39
|
+
for performance reasons. Improve the documentation of both methods.
|
40
|
+
|
41
|
+
See pull request [#1691](https://github.com/pry/pry/pull/1691).
|
42
|
+
|
43
|
+
* Fix `String#pp` output color.
|
44
|
+
|
45
|
+
See pull request [#1674](https://github.com/pry/pry/pull/1674).
|
46
|
+
|
1
47
|
### 0.11.0
|
2
48
|
|
3
49
|
* Add alias 'whereami[?!]+' for 'whereami' command. ([#1597](https://github.com/pry/pry/pull/1597))
|
@@ -47,7 +93,6 @@
|
|
47
93
|
* Move to rspec for testing (from bacon)
|
48
94
|
* Clean up ruby warnings
|
49
95
|
|
50
|
-
|
51
96
|
### 0.10.0
|
52
97
|
|
53
98
|
#### Features
|
data/lib/pry.rb
CHANGED
data/lib/pry/color_printer.rb
CHANGED
data/lib/pry/config/behavior.rb
CHANGED
data/lib/pry/config/default.rb
CHANGED
@@ -1,109 +1,71 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
# Acts like send but ignores any methods defined below Object or Class in the
|
19
|
-
# inheritance hierarchy.
|
20
|
-
# This is required to introspect methods on objects like Net::HTTP::Get that
|
21
|
-
# have overridden the `method` method.
|
22
|
-
def safe_send(obj, method, *args, &block)
|
23
|
-
(Module === obj ? Module : Object).instance_method(method).bind(obj).call(*args, &block)
|
24
|
-
end
|
25
|
-
public :safe_send
|
26
|
-
|
27
|
-
def find_command(name, set = Pry::Commands)
|
28
|
-
command_match = set.find do |_, command|
|
29
|
-
(listing = command.options[:listing]) == name && listing != nil
|
30
|
-
end
|
31
|
-
command_match.last if command_match
|
32
|
-
end
|
33
|
-
|
34
|
-
def not_a_real_file?(file)
|
35
|
-
file =~ /^(\(.*\))$|^<.*>$/ || file =~ /__unknown__/ || file == "" || file == "-e"
|
36
|
-
end
|
37
|
-
|
38
|
-
def command_dependencies_met?(options)
|
39
|
-
return true if !options[:requires_gem]
|
40
|
-
Array(options[:requires_gem]).all? do |g|
|
41
|
-
Rubygem.installed?(g)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def use_ansi_codes?
|
46
|
-
windows_ansi? || ENV['TERM'] && ENV['TERM'] != "dumb"
|
47
|
-
end
|
48
|
-
|
49
|
-
def colorize_code(code)
|
50
|
-
CodeRay.scan(code, :ruby).term
|
51
|
-
end
|
52
|
-
|
53
|
-
def highlight(string, regexp, highlight_color=:bright_yellow)
|
54
|
-
string.gsub(regexp) { |match| "<#{highlight_color}>#{match}</#{highlight_color}>" }
|
55
|
-
end
|
56
|
-
|
57
|
-
# formatting
|
58
|
-
def heading(text)
|
59
|
-
text = "#{text}\n--"
|
60
|
-
"\e[1m#{text}\e[0m"
|
61
|
-
end
|
1
|
+
module Pry::Helpers; end
|
2
|
+
module Pry::Helpers::BaseHelpers
|
3
|
+
include Pry::Platform
|
4
|
+
extend self
|
5
|
+
|
6
|
+
def silence_warnings
|
7
|
+
old_verbose = $VERBOSE
|
8
|
+
$VERBOSE = nil
|
9
|
+
begin
|
10
|
+
yield
|
11
|
+
ensure
|
12
|
+
$VERBOSE = old_verbose
|
13
|
+
end
|
14
|
+
end
|
62
15
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
16
|
+
# Acts like send but ignores any methods defined below Object or Class in the
|
17
|
+
# inheritance hierarchy.
|
18
|
+
# This is required to introspect methods on objects like Net::HTTP::Get that
|
19
|
+
# have overridden the `method` method.
|
20
|
+
def safe_send(obj, method, *args, &block)
|
21
|
+
(Module === obj ? Module : Object).instance_method(method).bind(obj).call(*args, &block)
|
22
|
+
end
|
23
|
+
public :safe_send
|
67
24
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
25
|
+
def find_command(name, set = Pry::Commands)
|
26
|
+
command_match = set.find do |_, command|
|
27
|
+
(listing = command.options[:listing]) == name && listing != nil
|
28
|
+
end
|
29
|
+
command_match.last if command_match
|
30
|
+
end
|
72
31
|
|
73
|
-
|
74
|
-
|
75
|
-
|
32
|
+
def not_a_real_file?(file)
|
33
|
+
file =~ /^(\(.*\))$|^<.*>$/ || file =~ /__unknown__/ || file == "" || file == "-e"
|
34
|
+
end
|
76
35
|
|
77
|
-
|
78
|
-
|
79
|
-
|
36
|
+
def command_dependencies_met?(options)
|
37
|
+
return true if !options[:requires_gem]
|
38
|
+
Array(options[:requires_gem]).all? do |g|
|
39
|
+
Pry::Rubygem.installed?(g)
|
40
|
+
end
|
41
|
+
end
|
80
42
|
|
81
|
-
|
82
|
-
|
83
|
-
|
43
|
+
def use_ansi_codes?
|
44
|
+
windows_ansi? || ENV['TERM'] && ENV['TERM'] != "dumb"
|
45
|
+
end
|
84
46
|
|
85
|
-
|
86
|
-
|
87
|
-
|
47
|
+
def colorize_code(code)
|
48
|
+
CodeRay.scan(code, :ruby).term
|
49
|
+
end
|
88
50
|
|
89
|
-
|
90
|
-
|
91
|
-
|
51
|
+
def highlight(string, regexp, highlight_color=:bright_yellow)
|
52
|
+
string.gsub(regexp) { |match| "<#{highlight_color}>#{match}</#{highlight_color}>" }
|
53
|
+
end
|
92
54
|
|
93
|
-
|
94
|
-
|
95
|
-
|
55
|
+
# formatting
|
56
|
+
def heading(text)
|
57
|
+
text = "#{text}\n--"
|
58
|
+
"\e[1m#{text}\e[0m"
|
59
|
+
end
|
96
60
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
end
|
106
|
-
end
|
61
|
+
# Send the given text through the best available pager (if Pry.config.pager is
|
62
|
+
# enabled). Infers where to send the output if used as a mixin.
|
63
|
+
# DEPRECATED.
|
64
|
+
def stagger_output(text, out = nil)
|
65
|
+
if defined?(_pry_) && _pry_
|
66
|
+
_pry_.pager.page text
|
67
|
+
else
|
68
|
+
Pry.new.pager.page text
|
107
69
|
end
|
108
70
|
end
|
109
71
|
end
|
data/lib/pry/helpers/text.rb
CHANGED
@@ -24,6 +24,16 @@ class Pry
|
|
24
24
|
define_method "bright_#{color}" do |text|
|
25
25
|
"\033[1;#{30+value}m#{text}\033[0m"
|
26
26
|
end
|
27
|
+
|
28
|
+
COLORS.each_pair do |bg_color, bg_value|
|
29
|
+
define_method "#{color}_on_#{bg_color}" do |text|
|
30
|
+
"\033[0;#{30 + value};#{40 + bg_value}m#{text}\033[0m"
|
31
|
+
end
|
32
|
+
|
33
|
+
define_method "bright_#{color}_on_#{bg_color}" do |text|
|
34
|
+
"\033[1;#{30 + value};#{40 + bg_value}m#{text}\033[0m"
|
35
|
+
end
|
36
|
+
end
|
27
37
|
end
|
28
38
|
|
29
39
|
# Remove any color codes from _text_.
|
@@ -52,10 +62,13 @@ class Pry
|
|
52
62
|
end
|
53
63
|
alias_method :bright_default, :bold
|
54
64
|
|
55
|
-
#
|
65
|
+
#
|
56
66
|
# @yield
|
67
|
+
# Yields a block with color turned off.
|
68
|
+
#
|
57
69
|
# @return [void]
|
58
|
-
|
70
|
+
#
|
71
|
+
def no_color
|
59
72
|
boolean = Pry.config.color
|
60
73
|
Pry.config.color = false
|
61
74
|
yield
|
@@ -63,10 +76,13 @@ class Pry
|
|
63
76
|
Pry.config.color = boolean
|
64
77
|
end
|
65
78
|
|
66
|
-
#
|
79
|
+
#
|
67
80
|
# @yield
|
81
|
+
# Yields a block with paging turned off.
|
82
|
+
#
|
68
83
|
# @return [void]
|
69
|
-
|
84
|
+
#
|
85
|
+
def no_pager
|
70
86
|
boolean = Pry.config.pager
|
71
87
|
Pry.config.pager = false
|
72
88
|
yield
|
@@ -98,4 +114,3 @@ class Pry
|
|
98
114
|
end
|
99
115
|
end
|
100
116
|
end
|
101
|
-
|
@@ -26,13 +26,17 @@ class Pry
|
|
26
26
|
# @param [Binding] b
|
27
27
|
# @return [Boolean]
|
28
28
|
def normal_method?(method, b)
|
29
|
-
method
|
30
|
-
|
31
|
-
|
29
|
+
if method and method.source_file and method.source_range
|
30
|
+
binding_file, binding_line = b.eval('__FILE__'), b.eval('__LINE__')
|
31
|
+
File.expand_path(method.source_file) == File.expand_path(binding_file) and
|
32
|
+
method.source_range.include?(binding_line)
|
33
|
+
end
|
34
|
+
rescue
|
35
|
+
false
|
32
36
|
end
|
33
37
|
|
34
38
|
def weird_method?(method, b)
|
35
|
-
|
39
|
+
not normal_method?(method, b)
|
36
40
|
end
|
37
41
|
end
|
38
42
|
|
@@ -61,6 +65,11 @@ class Pry
|
|
61
65
|
|
62
66
|
private
|
63
67
|
|
68
|
+
def skip_superclass_search?
|
69
|
+
target_mod = @target.eval('self').class
|
70
|
+
target_mod.ancestors.take_while {|mod| mod != target_mod }.any?
|
71
|
+
end
|
72
|
+
|
64
73
|
def normal_method?(method)
|
65
74
|
self.class.normal_method?(method, target)
|
66
75
|
end
|
@@ -98,7 +107,9 @@ class Pry
|
|
98
107
|
# superclass method.
|
99
108
|
def find_method_in_superclass
|
100
109
|
guess = method
|
101
|
-
|
110
|
+
if skip_superclass_search?
|
111
|
+
return guess
|
112
|
+
end
|
102
113
|
while guess
|
103
114
|
# needs rescue if this is a Disowned method or a C method or something...
|
104
115
|
# TODO: Fix up the exception handling so we don't need a bare rescue
|
data/lib/pry/platform.rb
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
module Pry::Platform
|
2
|
+
extend self
|
3
|
+
|
4
|
+
#
|
5
|
+
# @return [Boolean]
|
6
|
+
# Returns true if Pry is running on Mac OSX.
|
7
|
+
#
|
8
|
+
# @note
|
9
|
+
# Queries RbConfig::CONFIG['host_os'] with a best guess.
|
10
|
+
#
|
11
|
+
def mac_osx?
|
12
|
+
!!(RbConfig::CONFIG['host_os'] =~ /\Adarwin/i)
|
13
|
+
end
|
14
|
+
|
15
|
+
#
|
16
|
+
# @return [Boolean]
|
17
|
+
# Returns true if Pry is running on Linux.
|
18
|
+
#
|
19
|
+
# @note
|
20
|
+
# Queries RbConfig::CONFIG['host_os'] with a best guess.
|
21
|
+
#
|
22
|
+
def linux?
|
23
|
+
!!(RbConfig::CONFIG['host_os'] =~ /linux/i)
|
24
|
+
end
|
25
|
+
|
26
|
+
#
|
27
|
+
# @return [Boolean]
|
28
|
+
# Returns true if Pry is running on Windows.
|
29
|
+
#
|
30
|
+
# @note
|
31
|
+
# Queries RbConfig::CONFIG['host_os'] with a best guess.
|
32
|
+
#
|
33
|
+
def windows?
|
34
|
+
!!(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/)
|
35
|
+
end
|
36
|
+
|
37
|
+
#
|
38
|
+
# @return [Boolean]
|
39
|
+
# Returns true when Pry is running on Windows with ANSI support.
|
40
|
+
#
|
41
|
+
def windows_ansi?
|
42
|
+
return false if not windows?
|
43
|
+
!!(defined?(Win32::Console) or ENV['ANSICON'] or mri_2?)
|
44
|
+
end
|
45
|
+
|
46
|
+
#
|
47
|
+
# @return [Boolean]
|
48
|
+
# Returns true when Pry is being run from JRuby.
|
49
|
+
#
|
50
|
+
def jruby?
|
51
|
+
RbConfig::CONFIG['ruby_install_name'] == 'jruby'
|
52
|
+
end
|
53
|
+
|
54
|
+
#
|
55
|
+
# @return [Boolean]
|
56
|
+
# Returns true when Pry is being run from JRuby in 1.9 mode.
|
57
|
+
#
|
58
|
+
def jruby_19?
|
59
|
+
jruby? and RbConfig::CONFIG['ruby_version'] == '1.9'
|
60
|
+
end
|
61
|
+
|
62
|
+
#
|
63
|
+
# @return [Boolean]
|
64
|
+
# Returns true when Pry is being run from Rubinius.
|
65
|
+
#
|
66
|
+
def rbx?
|
67
|
+
RbConfig::CONFIG['ruby_install_name'] == 'rbx'
|
68
|
+
end
|
69
|
+
|
70
|
+
#
|
71
|
+
# @return [Boolean]
|
72
|
+
# Returns true when Pry is being run from MRI (CRuby).
|
73
|
+
#
|
74
|
+
def mri?
|
75
|
+
RbConfig::CONFIG['ruby_install_name'] == 'ruby'
|
76
|
+
end
|
77
|
+
|
78
|
+
#
|
79
|
+
# @return [Boolean]
|
80
|
+
# Returns true when Pry is being run from MRI v1.9+ (CRuby).
|
81
|
+
#
|
82
|
+
def mri_19?
|
83
|
+
!!(mri? and RUBY_VERSION =~ /\A1\.9/)
|
84
|
+
end
|
85
|
+
|
86
|
+
#
|
87
|
+
# @return [Boolean]
|
88
|
+
# Returns true when Pry is being run from MRI v2+ (CRuby).
|
89
|
+
#
|
90
|
+
def mri_2?
|
91
|
+
!!(mri? and RUBY_VERSION =~ /\A2/)
|
92
|
+
end
|
93
|
+
end
|
data/lib/pry/testable.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# good idea ???
|
2
|
+
# if you're testing pry plugin you should require pry by yourself, no?
|
3
|
+
require 'pry' if not defined?(Pry)
|
4
|
+
|
5
|
+
module Pry::Testable
|
6
|
+
extend self
|
7
|
+
require_relative "testable/pry_tester"
|
8
|
+
require_relative "testable/evalable"
|
9
|
+
require_relative "testable/mockable"
|
10
|
+
require_relative "testable/variables"
|
11
|
+
require_relative "testable/utility"
|
12
|
+
|
13
|
+
#
|
14
|
+
# When {Pry::Testable} is included into another module or class,
|
15
|
+
# the following modules are also included: {Pry::Testable::Mockable},
|
16
|
+
# {Pry::Testable::Evalable}, {Pry::Testable::Variables}, and
|
17
|
+
# {Pry::Testable::Utility}.
|
18
|
+
#
|
19
|
+
# @note
|
20
|
+
# Each of the included modules mentioned above may also be used
|
21
|
+
# standalone or in a pick-and-mix fashion.
|
22
|
+
#
|
23
|
+
# @param [Module] mod
|
24
|
+
# A class or module.
|
25
|
+
#
|
26
|
+
# @return [void]
|
27
|
+
#
|
28
|
+
def self.included(mod)
|
29
|
+
mod.module_eval do
|
30
|
+
include Pry::Testable::Mockable
|
31
|
+
include Pry::Testable::Evalable
|
32
|
+
include Pry::Testable::Variables
|
33
|
+
include Pry::Testable::Utility
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
TEST_DEFAULTS = {
|
38
|
+
color: false,
|
39
|
+
pager: false,
|
40
|
+
should_load_rc: false,
|
41
|
+
should_load_local_rc: false,
|
42
|
+
correct_indent: false,
|
43
|
+
collison_warning: false,
|
44
|
+
history: {
|
45
|
+
should_load: false,
|
46
|
+
should_save: false
|
47
|
+
}
|
48
|
+
}
|
49
|
+
private_constant :TEST_DEFAULTS
|
50
|
+
|
51
|
+
#
|
52
|
+
# Sets various configuration options that make Pry optimal for a test
|
53
|
+
# environment, see source code for complete details.
|
54
|
+
#
|
55
|
+
# @return [void]
|
56
|
+
#
|
57
|
+
def self.set_testenv_variables
|
58
|
+
Pry.config = Pry::Config.from_hash(TEST_DEFAULTS, Pry::Config::Default.new)
|
59
|
+
Pry.config.hooks = Pry::Hooks.new
|
60
|
+
end
|
61
|
+
|
62
|
+
#
|
63
|
+
# Reset the Pry configuration to their default values.
|
64
|
+
#
|
65
|
+
# @return [void]
|
66
|
+
#
|
67
|
+
def self.unset_testenv_variables
|
68
|
+
Pry.config = Pry::Config.from_hash({}, Pry::Config::Default.new)
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Pry::Testable::Evalable
|
2
|
+
def pry_tester(*args, &block)
|
3
|
+
if args.length == 0 || args[0].is_a?(Hash)
|
4
|
+
args.unshift(Pry.toplevel_binding)
|
5
|
+
end
|
6
|
+
Pry::Testable::PryTester.new(*args).tap do |t|
|
7
|
+
t.singleton_class.class_eval(&block) if block
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def pry_eval(*eval_strs)
|
12
|
+
b = String === eval_strs.first ? Pry.toplevel_binding : Pry.binding_for(eval_strs.shift)
|
13
|
+
pry_tester(b).eval(*eval_strs)
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Pry::Testable::Mockable
|
2
|
+
def mock_command(cmd, args=[], opts={})
|
3
|
+
output = StringIO.new
|
4
|
+
pry = Pry.new(output: output)
|
5
|
+
ret = cmd.new(opts.merge(pry_instance: pry, :output => output)).call_safely(*args)
|
6
|
+
Struct.new(:output, :return).new(output.string, ret)
|
7
|
+
end
|
8
|
+
|
9
|
+
def mock_exception(*mock_backtrace)
|
10
|
+
StandardError.new.tap do |e|
|
11
|
+
e.define_singleton_method(:backtrace) { mock_backtrace }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
class Pry::Testable::PryTester
|
2
|
+
extend Pry::Forwardable
|
3
|
+
attr_reader :pry, :out
|
4
|
+
def_delegators :@pry, :eval_string, :eval_string=
|
5
|
+
|
6
|
+
def initialize(target = TOPLEVEL_BINDING, options = {})
|
7
|
+
@pry = Pry.new(options.merge(:target => target))
|
8
|
+
@history = options[:history]
|
9
|
+
@pry.inject_sticky_locals!
|
10
|
+
reset_output
|
11
|
+
end
|
12
|
+
|
13
|
+
def eval(*strs)
|
14
|
+
reset_output
|
15
|
+
result = nil
|
16
|
+
|
17
|
+
strs.flatten.each do |str|
|
18
|
+
# Check for space prefix. See #1369.
|
19
|
+
if str !~ /^\s\S/
|
20
|
+
str = "#{str.strip}\n"
|
21
|
+
end
|
22
|
+
@history.push str if @history
|
23
|
+
|
24
|
+
if @pry.process_command(str)
|
25
|
+
result = last_command_result_or_output
|
26
|
+
else
|
27
|
+
result = @pry.evaluate_ruby(str)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
result
|
32
|
+
end
|
33
|
+
|
34
|
+
def push(*lines)
|
35
|
+
Array(lines).flatten.each do |line|
|
36
|
+
@pry.eval(line)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def push_binding(context)
|
41
|
+
@pry.push_binding context
|
42
|
+
end
|
43
|
+
|
44
|
+
def last_output
|
45
|
+
@out.string if @out
|
46
|
+
end
|
47
|
+
|
48
|
+
def process_command(command_str)
|
49
|
+
@pry.process_command(command_str) or raise "Not a valid command"
|
50
|
+
last_command_result_or_output
|
51
|
+
end
|
52
|
+
|
53
|
+
def last_command_result
|
54
|
+
result = Pry.current[:pry_cmd_result]
|
55
|
+
result.retval if result
|
56
|
+
end
|
57
|
+
|
58
|
+
protected
|
59
|
+
|
60
|
+
def last_command_result_or_output
|
61
|
+
result = last_command_result
|
62
|
+
if result != Pry::Command::VOID_VALUE
|
63
|
+
result
|
64
|
+
else
|
65
|
+
last_output
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def reset_output
|
70
|
+
@out = StringIO.new
|
71
|
+
@pry.output = @out
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Pry::Testable::Utility
|
2
|
+
#
|
3
|
+
# Creates a Tempfile then unlinks it after the block has yielded.
|
4
|
+
#
|
5
|
+
# @yieldparam [String] file
|
6
|
+
# The path of the temp file
|
7
|
+
#
|
8
|
+
# @return [void]
|
9
|
+
#
|
10
|
+
def temp_file(ext='.rb')
|
11
|
+
file = Tempfile.open(['pry', ext])
|
12
|
+
yield file
|
13
|
+
ensure
|
14
|
+
file.close(true) if file
|
15
|
+
end
|
16
|
+
|
17
|
+
def unindent(*args)
|
18
|
+
Pry::Helpers::CommandHelpers.unindent(*args)
|
19
|
+
end
|
20
|
+
|
21
|
+
def inner_scope
|
22
|
+
catch(:inner_scope) do
|
23
|
+
yield ->{ throw(:inner_scope, self) }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Pry::Testable::Variables
|
2
|
+
#
|
3
|
+
# @example
|
4
|
+
# temporary_constants(:Foo, :Bar) do
|
5
|
+
# Foo = Class.new(RuntimeError)
|
6
|
+
# Bar = Class.new(RuntimeError)
|
7
|
+
# end
|
8
|
+
# Foo # => NameError
|
9
|
+
# Bar # => NameError
|
10
|
+
#
|
11
|
+
# @param [Array<Symbol>] *names
|
12
|
+
# An array of constant names that be defined by a block,
|
13
|
+
# and removed by this method afterwards.
|
14
|
+
#
|
15
|
+
# @return [void]
|
16
|
+
#
|
17
|
+
def temporary_constants(*names)
|
18
|
+
names.each do |name|
|
19
|
+
Object.remove_const name if Object.const_defined?(name)
|
20
|
+
end
|
21
|
+
yield
|
22
|
+
ensure
|
23
|
+
names.each do |name|
|
24
|
+
Object.remove_const name if Object.const_defined?(name)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
#
|
29
|
+
# @param [String] name
|
30
|
+
# The name of a variable.
|
31
|
+
#
|
32
|
+
# @param [String] value
|
33
|
+
# Its value.
|
34
|
+
#
|
35
|
+
# @param [Binding] b
|
36
|
+
# The binding object to insert a variable into.
|
37
|
+
#
|
38
|
+
# @return [void]
|
39
|
+
#
|
40
|
+
def insert_variable(name, value, b)
|
41
|
+
Pry.current[:pry_local] = value
|
42
|
+
b.eval("#{name} = ::Pry.current[:pry_local]")
|
43
|
+
ensure
|
44
|
+
Pry.current[:pry_local] = nil
|
45
|
+
end
|
46
|
+
end
|
data/lib/pry/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.11.
|
4
|
+
version: 0.11.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Mair (banisterfiend)
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2017-
|
13
|
+
date: 2017-11-14 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: coderay
|
@@ -185,6 +185,7 @@ files:
|
|
185
185
|
- lib/pry/object_path.rb
|
186
186
|
- lib/pry/output.rb
|
187
187
|
- lib/pry/pager.rb
|
188
|
+
- lib/pry/platform.rb
|
188
189
|
- lib/pry/plugins.rb
|
189
190
|
- lib/pry/prompt.rb
|
190
191
|
- lib/pry/pry_class.rb
|
@@ -198,7 +199,12 @@ files:
|
|
198
199
|
- lib/pry/slop/commands.rb
|
199
200
|
- lib/pry/slop/option.rb
|
200
201
|
- lib/pry/terminal.rb
|
201
|
-
- lib/pry/
|
202
|
+
- lib/pry/testable.rb
|
203
|
+
- lib/pry/testable/evalable.rb
|
204
|
+
- lib/pry/testable/mockable.rb
|
205
|
+
- lib/pry/testable/pry_tester.rb
|
206
|
+
- lib/pry/testable/utility.rb
|
207
|
+
- lib/pry/testable/variables.rb
|
202
208
|
- lib/pry/version.rb
|
203
209
|
- lib/pry/wrapped_module.rb
|
204
210
|
- lib/pry/wrapped_module/candidate.rb
|
@@ -222,7 +228,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
222
228
|
version: '0'
|
223
229
|
requirements: []
|
224
230
|
rubyforge_project:
|
225
|
-
rubygems_version: 2.
|
231
|
+
rubygems_version: 2.6.13
|
226
232
|
signing_key:
|
227
233
|
specification_version: 4
|
228
234
|
summary: An IRB alternative and runtime developer console
|
data/lib/pry/test/helper.rb
DELETED
@@ -1,179 +0,0 @@
|
|
1
|
-
require 'pry'
|
2
|
-
|
3
|
-
# in case the tests call reset_defaults, ensure we reset them to
|
4
|
-
# amended (test friendly) values
|
5
|
-
class << Pry
|
6
|
-
alias_method :orig_reset_defaults, :reset_defaults
|
7
|
-
def reset_defaults
|
8
|
-
orig_reset_defaults
|
9
|
-
|
10
|
-
Pry.config.color = false
|
11
|
-
Pry.config.pager = false
|
12
|
-
Pry.config.should_load_rc = false
|
13
|
-
Pry.config.should_load_local_rc= false
|
14
|
-
Pry.config.should_load_plugins = false
|
15
|
-
Pry.config.history.should_load = false
|
16
|
-
Pry.config.history.should_save = false
|
17
|
-
Pry.config.correct_indent = false
|
18
|
-
Pry.config.hooks = Pry::Hooks.new
|
19
|
-
Pry.config.collision_warning = false
|
20
|
-
end
|
21
|
-
end
|
22
|
-
Pry.reset_defaults
|
23
|
-
|
24
|
-
# A global space for storing temporary state during tests.
|
25
|
-
|
26
|
-
module PryTestHelpers
|
27
|
-
|
28
|
-
module_function
|
29
|
-
|
30
|
-
# inject a variable into a binding
|
31
|
-
def inject_var(name, value, b)
|
32
|
-
Pry.current[:pry_local] = value
|
33
|
-
b.eval("#{name} = ::Pry.current[:pry_local]")
|
34
|
-
ensure
|
35
|
-
Pry.current[:pry_local] = nil
|
36
|
-
end
|
37
|
-
|
38
|
-
def constant_scope(*names)
|
39
|
-
names.each do |name|
|
40
|
-
Object.remove_const name if Object.const_defined?(name)
|
41
|
-
end
|
42
|
-
|
43
|
-
yield
|
44
|
-
ensure
|
45
|
-
names.each do |name|
|
46
|
-
Object.remove_const name if Object.const_defined?(name)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
# Open a temp file and yield it to the block, closing it after
|
51
|
-
# @return [String] The path of the temp file
|
52
|
-
def temp_file(ext='.rb')
|
53
|
-
file = Tempfile.new(['pry', ext])
|
54
|
-
yield file
|
55
|
-
ensure
|
56
|
-
file.close(true) if file
|
57
|
-
File.unlink("#{file.path}c") if File.exist?("#{file.path}c") # rbx
|
58
|
-
end
|
59
|
-
|
60
|
-
def unindent(*args)
|
61
|
-
Pry::Helpers::CommandHelpers.unindent(*args)
|
62
|
-
end
|
63
|
-
|
64
|
-
def mock_command(cmd, args=[], opts={})
|
65
|
-
output = StringIO.new
|
66
|
-
pry = Pry.new(output: output)
|
67
|
-
ret = cmd.new(opts.merge(pry_instance: pry, :output => output)).call_safely(*args)
|
68
|
-
Struct.new(:output, :return).new(output.string, ret)
|
69
|
-
end
|
70
|
-
|
71
|
-
def mock_exception(*mock_backtrace)
|
72
|
-
StandardError.new.tap do |e|
|
73
|
-
e.define_singleton_method(:backtrace) { mock_backtrace }
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def inner_scope
|
78
|
-
catch(:inner_scope) do
|
79
|
-
yield ->{ throw(:inner_scope, self) }
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
def pry_tester(*args, &block)
|
85
|
-
if args.length == 0 || args[0].is_a?(Hash)
|
86
|
-
args.unshift(Pry.toplevel_binding)
|
87
|
-
end
|
88
|
-
|
89
|
-
PryTester.new(*args).tap do |t|
|
90
|
-
(class << t; self; end).class_eval(&block) if block
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
def pry_eval(*eval_strs)
|
95
|
-
if eval_strs.first.is_a? String
|
96
|
-
binding = Pry.toplevel_binding
|
97
|
-
else
|
98
|
-
binding = Pry.binding_for(eval_strs.shift)
|
99
|
-
end
|
100
|
-
|
101
|
-
pry_tester(binding).eval(*eval_strs)
|
102
|
-
end
|
103
|
-
|
104
|
-
class PryTester
|
105
|
-
extend Pry::Forwardable
|
106
|
-
|
107
|
-
attr_reader :pry, :out
|
108
|
-
|
109
|
-
def_delegators :@pry, :eval_string, :eval_string=
|
110
|
-
|
111
|
-
def initialize(target = TOPLEVEL_BINDING, options = {})
|
112
|
-
@pry = Pry.new(options.merge(:target => target))
|
113
|
-
@history = options[:history]
|
114
|
-
|
115
|
-
@pry.inject_sticky_locals!
|
116
|
-
reset_output
|
117
|
-
end
|
118
|
-
|
119
|
-
def eval(*strs)
|
120
|
-
reset_output
|
121
|
-
result = nil
|
122
|
-
|
123
|
-
strs.flatten.each do |str|
|
124
|
-
# Check for space prefix. See #1369.
|
125
|
-
if str !~ /^\s\S/
|
126
|
-
str = "#{str.strip}\n"
|
127
|
-
end
|
128
|
-
@history.push str if @history
|
129
|
-
|
130
|
-
if @pry.process_command(str)
|
131
|
-
result = last_command_result_or_output
|
132
|
-
else
|
133
|
-
result = @pry.evaluate_ruby(str)
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
result
|
138
|
-
end
|
139
|
-
|
140
|
-
def push(*lines)
|
141
|
-
Array(lines).flatten.each do |line|
|
142
|
-
@pry.eval(line)
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
def push_binding(context)
|
147
|
-
@pry.push_binding context
|
148
|
-
end
|
149
|
-
|
150
|
-
def last_output
|
151
|
-
@out.string if @out
|
152
|
-
end
|
153
|
-
|
154
|
-
def process_command(command_str)
|
155
|
-
@pry.process_command(command_str) or raise "Not a valid command"
|
156
|
-
last_command_result_or_output
|
157
|
-
end
|
158
|
-
|
159
|
-
def last_command_result
|
160
|
-
result = Pry.current[:pry_cmd_result]
|
161
|
-
result.retval if result
|
162
|
-
end
|
163
|
-
|
164
|
-
protected
|
165
|
-
|
166
|
-
def last_command_result_or_output
|
167
|
-
result = last_command_result
|
168
|
-
if result != Pry::Command::VOID_VALUE
|
169
|
-
result
|
170
|
-
else
|
171
|
-
last_output
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
def reset_output
|
176
|
-
@out = StringIO.new
|
177
|
-
@pry.output = @out
|
178
|
-
end
|
179
|
-
end
|