pry 0.10.2-i386-mswin32 → 1.0.0.pre1-i386-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (189) hide show
  1. data/.document +2 -0
  2. data/.gitignore +16 -0
  3. data/.travis.yml +21 -0
  4. data/.yardopts +3 -0
  5. data/CHANGELOG +503 -0
  6. data/CONTRIBUTORS +55 -0
  7. data/Gemfile +9 -0
  8. data/Guardfile +62 -0
  9. data/LICENSE +2 -2
  10. data/{README.md → README.markdown} +31 -37
  11. data/Rakefile +144 -0
  12. data/TODO +117 -0
  13. data/lib/pry.rb +146 -33
  14. data/lib/pry/cli.rb +13 -35
  15. data/lib/pry/code.rb +63 -24
  16. data/lib/pry/code/loc.rb +2 -2
  17. data/lib/pry/code_object.rb +21 -40
  18. data/lib/pry/command.rb +6 -9
  19. data/lib/pry/command_set.rb +37 -80
  20. data/lib/pry/commands.rb +1 -1
  21. data/lib/pry/commands/amend_line.rb +1 -1
  22. data/lib/pry/commands/bang.rb +1 -1
  23. data/lib/pry/commands/cat.rb +2 -11
  24. data/lib/pry/commands/cat/abstract_formatter.rb +1 -1
  25. data/lib/pry/commands/cat/exception_formatter.rb +7 -6
  26. data/lib/pry/commands/cat/file_formatter.rb +32 -15
  27. data/lib/pry/commands/cat/input_expression_formatter.rb +1 -1
  28. data/lib/pry/commands/cd.rb +3 -14
  29. data/lib/pry/commands/code_collector.rb +4 -4
  30. data/lib/pry/commands/easter_eggs.rb +3 -3
  31. data/lib/pry/commands/edit.rb +22 -10
  32. data/lib/pry/commands/edit/exception_patcher.rb +1 -1
  33. data/lib/pry/commands/edit/file_and_line_locator.rb +2 -0
  34. data/lib/pry/{method/patcher.rb → commands/edit/method_patcher.rb} +37 -40
  35. data/lib/pry/commands/find_method.rb +22 -16
  36. data/lib/pry/commands/gem_install.rb +2 -5
  37. data/lib/pry/commands/gem_open.rb +1 -1
  38. data/lib/pry/commands/gist.rb +11 -10
  39. data/lib/pry/commands/help.rb +14 -14
  40. data/lib/pry/commands/hist.rb +5 -24
  41. data/lib/pry/commands/ls.rb +287 -56
  42. data/lib/pry/commands/play.rb +10 -44
  43. data/lib/pry/commands/pry_backtrace.rb +2 -1
  44. data/lib/pry/commands/raise_up.rb +1 -1
  45. data/lib/pry/commands/reload_code.rb +15 -31
  46. data/lib/pry/commands/ri.rb +3 -7
  47. data/lib/pry/commands/shell_command.rb +12 -17
  48. data/lib/pry/commands/shell_mode.rb +2 -2
  49. data/lib/pry/commands/show_doc.rb +0 -5
  50. data/lib/pry/commands/show_info.rb +10 -11
  51. data/lib/pry/commands/show_source.rb +3 -15
  52. data/lib/pry/commands/simple_prompt.rb +1 -1
  53. data/lib/pry/commands/toggle_color.rb +4 -8
  54. data/lib/pry/commands/whereami.rb +10 -18
  55. data/lib/pry/completion.rb +293 -0
  56. data/lib/pry/config.rb +233 -20
  57. data/lib/pry/core_extensions.rb +19 -29
  58. data/lib/pry/custom_completions.rb +6 -0
  59. data/lib/pry/editor.rb +103 -109
  60. data/lib/pry/helpers/base_helpers.rb +109 -22
  61. data/lib/pry/helpers/command_helpers.rb +8 -10
  62. data/lib/pry/helpers/documentation_helpers.rb +2 -1
  63. data/lib/pry/helpers/text.rb +5 -4
  64. data/lib/pry/history.rb +10 -21
  65. data/lib/pry/history_array.rb +0 -5
  66. data/lib/pry/hooks.rb +29 -9
  67. data/lib/pry/indent.rb +10 -5
  68. data/lib/pry/method.rb +86 -81
  69. data/lib/pry/method/weird_method_locator.rb +2 -4
  70. data/lib/pry/module_candidate.rb +14 -5
  71. data/lib/pry/pager.rb +48 -193
  72. data/lib/pry/plugins.rb +2 -2
  73. data/lib/pry/pry_class.rb +193 -104
  74. data/lib/pry/pry_instance.rb +154 -152
  75. data/lib/pry/rbx_method.rb +13 -0
  76. data/lib/pry/rbx_path.rb +1 -1
  77. data/lib/pry/repl.rb +14 -17
  78. data/lib/pry/repl_file_loader.rb +3 -8
  79. data/lib/pry/rubygem.rb +3 -3
  80. data/lib/pry/terminal.rb +3 -4
  81. data/lib/pry/test/helper.rb +11 -6
  82. data/lib/pry/version.rb +1 -1
  83. data/lib/pry/wrapped_module.rb +56 -49
  84. data/man/pry.1 +195 -0
  85. data/man/pry.1.html +204 -0
  86. data/man/pry.1.ronn +141 -0
  87. data/pry.gemspec +31 -0
  88. data/spec/Procfile +3 -0
  89. data/spec/cli_spec.rb +78 -0
  90. data/spec/code_object_spec.rb +277 -0
  91. data/spec/code_spec.rb +219 -0
  92. data/spec/command_helpers_spec.rb +29 -0
  93. data/spec/command_integration_spec.rb +562 -0
  94. data/spec/command_set_spec.rb +627 -0
  95. data/spec/command_spec.rb +821 -0
  96. data/spec/commands/amend_line_spec.rb +247 -0
  97. data/spec/commands/bang_spec.rb +18 -0
  98. data/spec/commands/cat_spec.rb +164 -0
  99. data/spec/commands/cd_spec.rb +250 -0
  100. data/spec/commands/disable_pry_spec.rb +25 -0
  101. data/spec/commands/edit_spec.rb +725 -0
  102. data/spec/commands/exit_all_spec.rb +27 -0
  103. data/spec/commands/exit_program_spec.rb +19 -0
  104. data/spec/commands/exit_spec.rb +28 -0
  105. data/spec/commands/find_method_spec.rb +70 -0
  106. data/spec/commands/gem_list_spec.rb +26 -0
  107. data/spec/commands/gist_spec.rb +79 -0
  108. data/spec/commands/help_spec.rb +56 -0
  109. data/spec/commands/hist_spec.rb +172 -0
  110. data/spec/commands/jump_to_spec.rb +15 -0
  111. data/spec/commands/ls_spec.rb +189 -0
  112. data/spec/commands/play_spec.rb +136 -0
  113. data/spec/commands/raise_up_spec.rb +56 -0
  114. data/spec/commands/save_file_spec.rb +177 -0
  115. data/spec/commands/show_doc_spec.rb +488 -0
  116. data/spec/commands/show_input_spec.rb +17 -0
  117. data/spec/commands/show_source_spec.rb +760 -0
  118. data/spec/commands/whereami_spec.rb +203 -0
  119. data/spec/completion_spec.rb +221 -0
  120. data/spec/control_d_handler_spec.rb +62 -0
  121. data/spec/documentation_helper_spec.rb +73 -0
  122. data/spec/editor_spec.rb +79 -0
  123. data/spec/exception_whitelist_spec.rb +21 -0
  124. data/spec/fixtures/candidate_helper1.rb +11 -0
  125. data/spec/fixtures/candidate_helper2.rb +8 -0
  126. data/spec/fixtures/example.erb +5 -0
  127. data/spec/fixtures/example_nesting.rb +33 -0
  128. data/spec/fixtures/show_source_doc_examples.rb +15 -0
  129. data/spec/fixtures/testlinkrc +2 -0
  130. data/spec/fixtures/testrc +2 -0
  131. data/spec/fixtures/testrcbad +2 -0
  132. data/spec/fixtures/whereami_helper.rb +6 -0
  133. data/spec/helper.rb +35 -0
  134. data/spec/helpers/bacon.rb +86 -0
  135. data/spec/helpers/mock_pry.rb +44 -0
  136. data/spec/helpers/repl_tester.rb +112 -0
  137. data/spec/helpers/table_spec.rb +105 -0
  138. data/spec/history_array_spec.rb +67 -0
  139. data/spec/hooks_spec.rb +522 -0
  140. data/spec/indent_spec.rb +301 -0
  141. data/spec/method_spec.rb +482 -0
  142. data/spec/prompt_spec.rb +61 -0
  143. data/spec/pry_defaults_spec.rb +420 -0
  144. data/spec/pry_history_spec.rb +69 -0
  145. data/spec/pry_output_spec.rb +95 -0
  146. data/spec/pry_repl_spec.rb +86 -0
  147. data/spec/pry_spec.rb +394 -0
  148. data/spec/pryrc_spec.rb +97 -0
  149. data/spec/run_command_spec.rb +25 -0
  150. data/spec/sticky_locals_spec.rb +147 -0
  151. data/spec/syntax_checking_spec.rb +81 -0
  152. data/spec/wrapped_module_spec.rb +261 -0
  153. data/wiki/Customizing-pry.md +397 -0
  154. data/wiki/Home.md +4 -0
  155. metadata +272 -61
  156. checksums.yaml +0 -7
  157. data/CHANGELOG.md +0 -714
  158. data/lib/pry/code/code_file.rb +0 -103
  159. data/lib/pry/color_printer.rb +0 -55
  160. data/lib/pry/commands/change_inspector.rb +0 -27
  161. data/lib/pry/commands/change_prompt.rb +0 -26
  162. data/lib/pry/commands/list_inspectors.rb +0 -35
  163. data/lib/pry/commands/list_prompts.rb +0 -35
  164. data/lib/pry/commands/ls/constants.rb +0 -47
  165. data/lib/pry/commands/ls/formatter.rb +0 -49
  166. data/lib/pry/commands/ls/globals.rb +0 -48
  167. data/lib/pry/commands/ls/grep.rb +0 -21
  168. data/lib/pry/commands/ls/instance_vars.rb +0 -39
  169. data/lib/pry/commands/ls/interrogatable.rb +0 -18
  170. data/lib/pry/commands/ls/jruby_hacks.rb +0 -49
  171. data/lib/pry/commands/ls/local_names.rb +0 -35
  172. data/lib/pry/commands/ls/local_vars.rb +0 -39
  173. data/lib/pry/commands/ls/ls_entity.rb +0 -70
  174. data/lib/pry/commands/ls/methods.rb +0 -57
  175. data/lib/pry/commands/ls/methods_helper.rb +0 -46
  176. data/lib/pry/commands/ls/self_methods.rb +0 -32
  177. data/lib/pry/commands/watch_expression.rb +0 -105
  178. data/lib/pry/commands/watch_expression/expression.rb +0 -38
  179. data/lib/pry/config/behavior.rb +0 -139
  180. data/lib/pry/config/convenience.rb +0 -25
  181. data/lib/pry/config/default.rb +0 -161
  182. data/lib/pry/exceptions.rb +0 -78
  183. data/lib/pry/input_completer.rb +0 -242
  184. data/lib/pry/input_lock.rb +0 -132
  185. data/lib/pry/inspector.rb +0 -27
  186. data/lib/pry/last_exception.rb +0 -61
  187. data/lib/pry/object_path.rb +0 -82
  188. data/lib/pry/output.rb +0 -50
  189. data/lib/pry/prompt.rb +0 -26
@@ -0,0 +1,203 @@
1
+ require 'helper'
2
+
3
+ describe "whereami" do
4
+ it 'should work with methods that have been undefined' do
5
+ class Cor
6
+ def blimey!
7
+ Cor.send :undef_method, :blimey!
8
+ Pad.binding = binding
9
+ end
10
+ end
11
+
12
+ Cor.new.blimey!
13
+
14
+ # using [.] so the regex doesn't match itself
15
+ pry_eval(Pad.binding, 'whereami').should =~ /self[.]blimey!/
16
+
17
+ Object.remove_const(:Cor)
18
+ end
19
+
20
+ it 'should work in objects with no method methods' do
21
+ class Cor
22
+ def blimey!
23
+ pry_eval(binding, 'whereami').should =~ /Cor[#]blimey!/
24
+ end
25
+
26
+ def method; "moo"; end
27
+ end
28
+ Cor.new.blimey!
29
+ Object.remove_const(:Cor)
30
+ end
31
+
32
+ it 'should properly set _file_, _line_ and _dir_' do
33
+ class Cor
34
+ def blimey!
35
+ pry_eval(binding, 'whereami', '_file_').
36
+ should == File.expand_path(__FILE__)
37
+ end
38
+ end
39
+
40
+ Cor.new.blimey!
41
+ Object.remove_const(:Cor)
42
+ end
43
+
44
+ if defined?(BasicObject)
45
+ it 'should work in BasicObjects' do
46
+ cor = Class.new(BasicObject) do
47
+ def blimey!
48
+ ::Kernel.binding # omnom
49
+ end
50
+ end.new.blimey!
51
+
52
+ pry_eval(cor, 'whereami').should =~ /::Kernel.binding [#] omnom/
53
+ end
54
+ end
55
+
56
+ it 'should show description and correct code when __LINE__ and __FILE__ are outside @method.source_location' do
57
+ class Cor
58
+ def blimey!
59
+ eval <<-END, binding, "spec/fixtures/example.erb", 1
60
+ pry_eval(binding, 'whereami')
61
+ END
62
+ end
63
+ end
64
+
65
+ Cor.instance_method(:blimey!).source.should =~ /pry_eval/
66
+ Cor.new.blimey!.should =~ /Cor#blimey!.*Look at me/m
67
+ Object.remove_const(:Cor)
68
+ end
69
+
70
+ it 'should show description and correct code when @method.source_location would raise an error' do
71
+ class Cor
72
+ eval <<-END, binding, "spec/fixtures/example.erb", 1
73
+ def blimey!
74
+ pry_eval(binding, 'whereami')
75
+ end
76
+ END
77
+ end
78
+
79
+ lambda{
80
+ Cor.instance_method(:blimey!).source
81
+ }.should.raise(MethodSource::SourceNotFoundError)
82
+
83
+ Cor.new.blimey!.should =~ /Cor#blimey!.*Look at me/m
84
+ Object.remove_const(:Cor)
85
+ end
86
+
87
+ # Now that we use stagger_output (paging output) we no longer get
88
+ # the "From: " line, as we output everything in one go (not separate output.puts)
89
+ # and so the user just gets a single `Error: Cannot open
90
+ # "not.found.file.erb" for reading.`
91
+ # which is good enough IMO. Unfortunately we can't test for it
92
+ # though, as we don't hook stdout.
93
+ #
94
+ # it 'should display a description and error if reading the file goes wrong' do
95
+ # class Cor
96
+ # def blimey!
97
+ # eval <<-END, binding, "not.found.file.erb", 7
98
+ # Pad.tester = pry_tester(binding)
99
+ # Pad.tester.eval('whereami')
100
+ # END
101
+ # end
102
+ # end
103
+
104
+ # proc { Cor.new.blimey! }.should.raise(MethodSource::SourceNotFoundError)
105
+
106
+ # Pad.tester.last_output.should =~
107
+ # /From: not.found.file.erb @ line 7 Cor#blimey!:/
108
+ # Object.remove_const(:Cor)
109
+ # end
110
+
111
+ it 'should show code window (not just method source) if parameter passed to whereami' do
112
+ class Cor
113
+ def blimey!
114
+ pry_eval(binding, 'whereami 3').should =~ /class Cor/
115
+ end
116
+ end
117
+ Cor.new.blimey!
118
+ Object.remove_const(:Cor)
119
+ end
120
+
121
+ it 'should show entire method when -m option used' do
122
+ old_size, Pry.config.default_window_size = Pry.config.default_window_size, 1
123
+ old_cutoff, Pry::Command::Whereami.method_size_cutoff = Pry::Command::Whereami.method_size_cutoff, 1
124
+ class Cor
125
+ def blimey!
126
+ 1
127
+ 2
128
+ pry_eval(binding, 'whereami -m').should =~ /def blimey/
129
+ end
130
+ end
131
+ Pry::Command::Whereami.method_size_cutoff, Pry.config.default_window_size = old_cutoff, old_size
132
+ Cor.new.blimey!
133
+ Object.remove_const(:Cor)
134
+ end
135
+
136
+ it 'should show entire file when -f option used' do
137
+ class Cor
138
+ def blimey!
139
+ 1
140
+ 2
141
+ pry_eval(binding, 'whereami -f').should =~ /show entire file when -f option used/
142
+ end
143
+ end
144
+ Cor.new.blimey!
145
+ Object.remove_const(:Cor)
146
+ end
147
+
148
+ it 'should show class when -c option used, and locate correct candidate' do
149
+ require 'fixtures/whereami_helper'
150
+ class Cor
151
+ def blimey!
152
+ 1
153
+ 2
154
+ out = pry_eval(binding, 'whereami -c')
155
+ out.should =~ /class Cor/
156
+ out.should =~ /blimey/
157
+ end
158
+ end
159
+ Cor.new.blimey!
160
+ Object.remove_const(:Cor)
161
+ end
162
+
163
+ it 'should not show line numbers or marker when -n switch is used' do
164
+ class Cor
165
+ def blimey!
166
+ out = pry_eval(binding, 'whereami -n')
167
+ out.should =~ /^\s*def/
168
+ out.should.not =~ /\=\>/
169
+ end
170
+ end
171
+ Cor.new.blimey!
172
+ Object.remove_const(:Cor)
173
+ end
174
+
175
+ it 'should use Pry.config.default_window_size for window size when outside a method context' do
176
+ old_size, Pry.config.default_window_size = Pry.config.default_window_size, 1
177
+ :litella
178
+ :pig
179
+ out = pry_eval(binding, 'whereami')
180
+ :punk
181
+ :sanders
182
+
183
+ out.should.not =~ /:litella/
184
+ out.should =~ /:pig/
185
+ out.should =~ /:punk/
186
+ out.should.not =~ /:sanders/
187
+
188
+ Pry.config.default_window_size = old_size
189
+ end
190
+
191
+ it "should work at the top level" do
192
+ pry_eval(Pry.toplevel_binding, 'whereami').should =~
193
+ /At the top level/
194
+ end
195
+
196
+ it "should work inside a class" do
197
+ pry_eval(Pry, 'whereami').should =~ /Inside Pry/
198
+ end
199
+
200
+ it "should work inside an object" do
201
+ pry_eval(Object.new, 'whereami').should =~ /Inside #<Object/
202
+ end
203
+ end
@@ -0,0 +1,221 @@
1
+ require 'helper'
2
+
3
+ def completer_test(bind, pry=nil, assert_flag=true)
4
+ test = proc {|symbol|
5
+ Pry::InputCompleter.call(symbol[0..-2], :target => Pry.binding_for(bind), :pry => pry).include?(symbol).should == assert_flag}
6
+ return proc {|*symbols| symbols.each(&test) }
7
+ end
8
+
9
+ if defined?(Bond) && Readline::VERSION !~ /editline/i
10
+ describe 'bond-based completion' do
11
+ it 'should pull in Bond by default' do
12
+ Pry.config.completer.should == Pry::BondCompleter
13
+ end
14
+ end
15
+ end
16
+
17
+ describe Pry::InputCompleter do
18
+
19
+ before do
20
+ # The AMQP gem has some classes like this:
21
+ # pry(main)> AMQP::Protocol::Test::ContentOk.name
22
+ # => :content_ok
23
+ module SymbolyName
24
+ def self.name; :symboly_name; end
25
+ end
26
+
27
+ $default_completer = Pry.config.completer
28
+ Pry.config.completer = Pry::InputCompleter
29
+ end
30
+
31
+ after do
32
+ Pry.config.completer = $default_completer
33
+ Object.remove_const :SymbolyName
34
+ end
35
+
36
+ # another jruby hack :((
37
+ if !Pry::Helpers::BaseHelpers.jruby?
38
+ it "should not crash if there's a Module that has a symbolic name." do
39
+ lambda{ Pry::InputCompleter.call "a.to_s.", :target => Pry.binding_for(Object.new) }.should.not.raise Exception
40
+ end
41
+ end
42
+
43
+ it 'should take parenthesis and other characters into account for symbols' do
44
+ lambda { Pry::InputCompleter.call(":class)", :target => Pry.binding_for(Object.new)) }.should.not.raise(RegexpError)
45
+ end
46
+
47
+ it 'should complete instance variables' do
48
+ object = Class.new.new
49
+
50
+ # set variables in appropriate scope
51
+ object.instance_variable_set(:'@name', 'Pry')
52
+ object.class.send(:class_variable_set, :'@@number', 10)
53
+
54
+ # check to see if variables are in scope
55
+ object.instance_variables.
56
+ map { |v| v.to_sym }.
57
+ include?(:'@name').should == true
58
+
59
+ object.class.class_variables.
60
+ map { |v| v.to_sym }.
61
+ include?(:'@@number').should == true
62
+
63
+ # Complete instance variables.
64
+ b = Pry.binding_for(object)
65
+ completer_test(b).call('@name', '@name.downcase')
66
+
67
+ # Complete class variables.
68
+ b = Pry.binding_for(object.class)
69
+ completer_test(b).call('@@number', '@@number.class')
70
+
71
+ end
72
+
73
+
74
+ it 'should complete for stdlib symbols' do
75
+
76
+ o = Object.new
77
+ # Regexp
78
+ completer_test(o).call('/foo/.extend')
79
+
80
+ # Array
81
+ completer_test(o).call('[1].push')
82
+
83
+ # Hash
84
+ completer_test(o).call('{"a" => "b"}.keys')
85
+
86
+ # Proc
87
+ completer_test(o).call('{2}.call')
88
+
89
+ # Symbol
90
+ completer_test(o).call(':symbol.to_s')
91
+
92
+ # Absolute Constant
93
+ completer_test(o).call('::IndexError')
94
+ end
95
+
96
+ it 'should complete for target symbols' do
97
+ o = Object.new
98
+
99
+ # Constant
100
+ module Mod
101
+ Con = 'Constant'
102
+ module Mod2
103
+ end
104
+ end
105
+
106
+ completer_test(Mod).call('Con')
107
+
108
+ # Constants or Class Methods
109
+ completer_test(o).call('Mod::Con')
110
+
111
+ # Symbol
112
+ foo = :symbol
113
+ completer_test(o).call(':symbol')
114
+
115
+ # Variables
116
+ class << o
117
+ attr_accessor :foo
118
+ end
119
+ o.foo = 'bar'
120
+ completer_test(binding).call('o.foo')
121
+
122
+ # trailing slash
123
+ Pry::InputCompleter.call('Mod2/', :target => Pry.binding_for(Mod)).include?('Mod2/').should == true
124
+ end
125
+
126
+ it 'should complete for arbitrary scopes' do
127
+ module Bar
128
+ @barvar = :bar
129
+ end
130
+
131
+ module Baz
132
+ @bar = Bar
133
+ @bazvar = :baz
134
+ Con = :constant
135
+ end
136
+
137
+ pry = Pry.new(:target => Baz)
138
+ pry.push_binding(Bar)
139
+
140
+ b = Pry.binding_for(Bar)
141
+ completer_test(b, pry).call("../@bazvar")
142
+ completer_test(b, pry).call('/Con')
143
+ end
144
+
145
+ it 'should complete for stdlib symbols' do
146
+
147
+ o = Object.new
148
+ # Regexp
149
+ completer_test(o).call('/foo/.extend')
150
+
151
+ # Array
152
+ completer_test(o).call('[1].push')
153
+
154
+ # Hash
155
+ completer_test(o).call('{"a" => "b"}.keys')
156
+
157
+ # Proc
158
+ completer_test(o).call('{2}.call')
159
+
160
+ # Symbol
161
+ completer_test(o).call(':symbol.to_s')
162
+
163
+ # Absolute Constant
164
+ completer_test(o).call('::IndexError')
165
+ end
166
+
167
+ it 'should complete for target symbols' do
168
+ o = Object.new
169
+
170
+ # Constant
171
+ module Mod
172
+ Con = 'Constant'
173
+ module Mod2
174
+ end
175
+ end
176
+
177
+ completer_test(Mod).call('Con')
178
+
179
+ # Constants or Class Methods
180
+ completer_test(o).call('Mod::Con')
181
+
182
+ # Symbol
183
+ foo = :symbol
184
+ completer_test(o).call(':symbol')
185
+
186
+ # Variables
187
+ class << o
188
+ attr_accessor :foo
189
+ end
190
+ o.foo = 'bar'
191
+ completer_test(binding).call('o.foo')
192
+
193
+ # trailing slash
194
+ Pry::InputCompleter.call('Mod2/', :target => Pry.binding_for(Mod)).include?('Mod2/').should == true
195
+
196
+ end
197
+
198
+ it 'should complete for arbitrary scopes' do
199
+ module Bar
200
+ @barvar = :bar
201
+ end
202
+
203
+ module Baz
204
+ @bar = Bar
205
+ @bazvar = :baz
206
+ Con = :constant
207
+ end
208
+
209
+ pry = Pry.new(:target => Baz)
210
+ pry.push_binding(Bar)
211
+
212
+ b = Pry.binding_for(Bar)
213
+ completer_test(b, pry).call("../@bazvar")
214
+ completer_test(b, pry).call('/Con')
215
+ end
216
+
217
+ it 'should not return nil in its output' do
218
+ pry = Pry.new
219
+ Pry::InputCompleter.call("pry.", :target => binding).should.not.include nil
220
+ end
221
+ end
@@ -0,0 +1,62 @@
1
+ require 'helper'
2
+
3
+ describe Pry::DEFAULT_CONTROL_D_HANDLER do
4
+
5
+ describe "control-d press" do
6
+
7
+ before do
8
+ # Simulates a ^D press.
9
+ @control_d = "Pry::DEFAULT_CONTROL_D_HANDLER.call('', _pry_)"
10
+ end
11
+
12
+ describe "in an expression" do
13
+ it "should clear out passed string" do
14
+ str = 'hello world'
15
+ Pry::DEFAULT_CONTROL_D_HANDLER.call(str, nil)
16
+ str.should == ''
17
+ end
18
+ end
19
+
20
+ describe 'at top-level session' do
21
+ it 'should break out of a REPL loop' do
22
+ instance = Pry.new
23
+ instance.binding_stack.should.not.be.empty
24
+ instance.eval(nil).should.be.false
25
+ instance.binding_stack.should.be.empty
26
+ end
27
+ end
28
+
29
+ describe 'in a nested session' do
30
+ it 'should pop last binding from the binding stack' do
31
+ t = pry_tester
32
+ t.eval "cd Object.new"
33
+ t.eval("_pry_.binding_stack.size").should == 2
34
+ t.eval("_pry_.eval(nil)").should.be.true
35
+ t.eval("_pry_.binding_stack.size").should == 1
36
+ end
37
+
38
+ it "breaks out of the parent session" do
39
+ ReplTester.start do
40
+ input 'Pry::REPL.new(_pry_, :target => 10).start'
41
+ output ''
42
+ prompt(/10.*> $/)
43
+
44
+ input 'self'
45
+ output '=> 10'
46
+
47
+ input nil # Ctrl-D
48
+ output ''
49
+
50
+ input 'self'
51
+ output '=> main'
52
+
53
+ input nil # Ctrl-D
54
+ output '=> nil' # Exit value of nested REPL.
55
+ assert_exited
56
+ end
57
+ end
58
+ end
59
+
60
+ end
61
+
62
+ end