pry 0.9.12.6-i386-mingw32 → 0.10.0-i386-mingw32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +702 -0
  3. data/LICENSE +2 -2
  4. data/{README.markdown → README.md} +37 -31
  5. data/lib/pry.rb +38 -151
  6. data/lib/pry/cli.rb +35 -17
  7. data/lib/pry/code.rb +19 -63
  8. data/lib/pry/code/code_file.rb +103 -0
  9. data/lib/pry/code/code_range.rb +2 -1
  10. data/lib/pry/code/loc.rb +2 -2
  11. data/lib/pry/code_object.rb +40 -21
  12. data/lib/pry/color_printer.rb +55 -0
  13. data/lib/pry/command.rb +12 -9
  14. data/lib/pry/command_set.rb +81 -38
  15. data/lib/pry/commands.rb +1 -1
  16. data/lib/pry/commands/amend_line.rb +2 -2
  17. data/lib/pry/commands/bang.rb +1 -1
  18. data/lib/pry/commands/cat.rb +11 -2
  19. data/lib/pry/commands/cat/exception_formatter.rb +6 -7
  20. data/lib/pry/commands/cat/file_formatter.rb +15 -32
  21. data/lib/pry/commands/cat/input_expression_formatter.rb +1 -1
  22. data/lib/pry/commands/cd.rb +14 -3
  23. data/lib/pry/commands/change_inspector.rb +27 -0
  24. data/lib/pry/commands/change_prompt.rb +26 -0
  25. data/lib/pry/commands/code_collector.rb +4 -4
  26. data/lib/pry/commands/easter_eggs.rb +3 -3
  27. data/lib/pry/commands/edit.rb +10 -22
  28. data/lib/pry/commands/edit/exception_patcher.rb +2 -2
  29. data/lib/pry/commands/edit/file_and_line_locator.rb +0 -2
  30. data/lib/pry/commands/exit_program.rb +0 -1
  31. data/lib/pry/commands/find_method.rb +16 -22
  32. data/lib/pry/commands/gem_install.rb +5 -2
  33. data/lib/pry/commands/gem_open.rb +1 -1
  34. data/lib/pry/commands/gist.rb +10 -11
  35. data/lib/pry/commands/help.rb +14 -14
  36. data/lib/pry/commands/hist.rb +27 -8
  37. data/lib/pry/commands/install_command.rb +14 -12
  38. data/lib/pry/commands/list_inspectors.rb +35 -0
  39. data/lib/pry/commands/list_prompts.rb +35 -0
  40. data/lib/pry/commands/ls.rb +72 -296
  41. data/lib/pry/commands/ls/constants.rb +47 -0
  42. data/lib/pry/commands/ls/formatter.rb +49 -0
  43. data/lib/pry/commands/ls/globals.rb +48 -0
  44. data/lib/pry/commands/ls/grep.rb +21 -0
  45. data/lib/pry/commands/ls/instance_vars.rb +39 -0
  46. data/lib/pry/commands/ls/interrogatable.rb +18 -0
  47. data/lib/pry/commands/ls/jruby_hacks.rb +49 -0
  48. data/lib/pry/commands/ls/local_names.rb +35 -0
  49. data/lib/pry/commands/ls/local_vars.rb +39 -0
  50. data/lib/pry/commands/ls/ls_entity.rb +70 -0
  51. data/lib/pry/commands/ls/methods.rb +57 -0
  52. data/lib/pry/commands/ls/methods_helper.rb +46 -0
  53. data/lib/pry/commands/ls/self_methods.rb +32 -0
  54. data/lib/pry/commands/play.rb +44 -10
  55. data/lib/pry/commands/pry_backtrace.rb +1 -2
  56. data/lib/pry/commands/raise_up.rb +2 -2
  57. data/lib/pry/commands/reload_code.rb +16 -19
  58. data/lib/pry/commands/ri.rb +7 -3
  59. data/lib/pry/commands/shell_command.rb +18 -13
  60. data/lib/pry/commands/shell_mode.rb +2 -4
  61. data/lib/pry/commands/show_doc.rb +5 -0
  62. data/lib/pry/commands/show_info.rb +8 -13
  63. data/lib/pry/commands/show_source.rb +15 -3
  64. data/lib/pry/commands/simple_prompt.rb +1 -1
  65. data/lib/pry/commands/toggle_color.rb +8 -4
  66. data/lib/pry/commands/watch_expression.rb +105 -0
  67. data/lib/pry/commands/watch_expression/expression.rb +38 -0
  68. data/lib/pry/commands/whereami.rb +18 -10
  69. data/lib/pry/commands/wtf.rb +3 -3
  70. data/lib/pry/config.rb +20 -254
  71. data/lib/pry/config/behavior.rb +139 -0
  72. data/lib/pry/config/convenience.rb +26 -0
  73. data/lib/pry/config/default.rb +165 -0
  74. data/lib/pry/core_extensions.rb +31 -21
  75. data/lib/pry/editor.rb +107 -103
  76. data/lib/pry/exceptions.rb +77 -0
  77. data/lib/pry/helpers/base_helpers.rb +22 -109
  78. data/lib/pry/helpers/command_helpers.rb +10 -8
  79. data/lib/pry/helpers/documentation_helpers.rb +1 -2
  80. data/lib/pry/helpers/text.rb +4 -5
  81. data/lib/pry/history.rb +46 -45
  82. data/lib/pry/history_array.rb +6 -1
  83. data/lib/pry/hooks.rb +9 -29
  84. data/lib/pry/indent.rb +6 -6
  85. data/lib/pry/input_completer.rb +242 -0
  86. data/lib/pry/input_lock.rb +132 -0
  87. data/lib/pry/inspector.rb +27 -0
  88. data/lib/pry/last_exception.rb +61 -0
  89. data/lib/pry/method.rb +82 -87
  90. data/lib/pry/{commands/edit/method_patcher.rb → method/patcher.rb} +41 -38
  91. data/lib/pry/module_candidate.rb +4 -14
  92. data/lib/pry/object_path.rb +82 -0
  93. data/lib/pry/output.rb +50 -0
  94. data/lib/pry/pager.rb +193 -48
  95. data/lib/pry/plugins.rb +1 -1
  96. data/lib/pry/prompt.rb +26 -0
  97. data/lib/pry/pry_class.rb +149 -230
  98. data/lib/pry/pry_instance.rb +302 -413
  99. data/lib/pry/rbx_path.rb +1 -1
  100. data/lib/pry/repl.rb +202 -0
  101. data/lib/pry/repl_file_loader.rb +20 -26
  102. data/lib/pry/rubygem.rb +13 -5
  103. data/lib/pry/terminal.rb +2 -1
  104. data/lib/pry/test/helper.rb +26 -41
  105. data/lib/pry/version.rb +1 -1
  106. data/lib/pry/wrapped_module.rb +45 -59
  107. metadata +62 -225
  108. data/.document +0 -2
  109. data/.gitignore +0 -16
  110. data/.travis.yml +0 -25
  111. data/.yardopts +0 -1
  112. data/CHANGELOG +0 -534
  113. data/CONTRIBUTORS +0 -55
  114. data/Gemfile +0 -12
  115. data/Rakefile +0 -140
  116. data/TODO +0 -117
  117. data/lib/pry/completion.rb +0 -321
  118. data/lib/pry/custom_completions.rb +0 -6
  119. data/lib/pry/rbx_method.rb +0 -13
  120. data/man/pry.1 +0 -195
  121. data/man/pry.1.html +0 -204
  122. data/man/pry.1.ronn +0 -141
  123. data/pry.gemspec +0 -29
  124. data/spec/Procfile +0 -3
  125. data/spec/cli_spec.rb +0 -78
  126. data/spec/code_object_spec.rb +0 -277
  127. data/spec/code_spec.rb +0 -219
  128. data/spec/command_helpers_spec.rb +0 -29
  129. data/spec/command_integration_spec.rb +0 -644
  130. data/spec/command_set_spec.rb +0 -627
  131. data/spec/command_spec.rb +0 -821
  132. data/spec/commands/amend_line_spec.rb +0 -247
  133. data/spec/commands/bang_spec.rb +0 -19
  134. data/spec/commands/cat_spec.rb +0 -164
  135. data/spec/commands/cd_spec.rb +0 -250
  136. data/spec/commands/disable_pry_spec.rb +0 -25
  137. data/spec/commands/edit_spec.rb +0 -727
  138. data/spec/commands/exit_all_spec.rb +0 -34
  139. data/spec/commands/exit_program_spec.rb +0 -19
  140. data/spec/commands/exit_spec.rb +0 -34
  141. data/spec/commands/find_method_spec.rb +0 -70
  142. data/spec/commands/gem_list_spec.rb +0 -26
  143. data/spec/commands/gist_spec.rb +0 -79
  144. data/spec/commands/help_spec.rb +0 -56
  145. data/spec/commands/hist_spec.rb +0 -181
  146. data/spec/commands/jump_to_spec.rb +0 -15
  147. data/spec/commands/ls_spec.rb +0 -181
  148. data/spec/commands/play_spec.rb +0 -140
  149. data/spec/commands/raise_up_spec.rb +0 -56
  150. data/spec/commands/save_file_spec.rb +0 -177
  151. data/spec/commands/show_doc_spec.rb +0 -510
  152. data/spec/commands/show_input_spec.rb +0 -17
  153. data/spec/commands/show_source_spec.rb +0 -782
  154. data/spec/commands/whereami_spec.rb +0 -203
  155. data/spec/completion_spec.rb +0 -241
  156. data/spec/control_d_handler_spec.rb +0 -58
  157. data/spec/documentation_helper_spec.rb +0 -73
  158. data/spec/editor_spec.rb +0 -79
  159. data/spec/exception_whitelist_spec.rb +0 -21
  160. data/spec/fixtures/candidate_helper1.rb +0 -11
  161. data/spec/fixtures/candidate_helper2.rb +0 -8
  162. data/spec/fixtures/example.erb +0 -5
  163. data/spec/fixtures/example_nesting.rb +0 -33
  164. data/spec/fixtures/show_source_doc_examples.rb +0 -15
  165. data/spec/fixtures/testrc +0 -2
  166. data/spec/fixtures/testrcbad +0 -2
  167. data/spec/fixtures/whereami_helper.rb +0 -6
  168. data/spec/helper.rb +0 -34
  169. data/spec/helpers/bacon.rb +0 -86
  170. data/spec/helpers/mock_pry.rb +0 -43
  171. data/spec/helpers/table_spec.rb +0 -105
  172. data/spec/history_array_spec.rb +0 -67
  173. data/spec/hooks_spec.rb +0 -522
  174. data/spec/indent_spec.rb +0 -301
  175. data/spec/input_stack_spec.rb +0 -90
  176. data/spec/method_spec.rb +0 -482
  177. data/spec/prompt_spec.rb +0 -60
  178. data/spec/pry_defaults_spec.rb +0 -419
  179. data/spec/pry_history_spec.rb +0 -99
  180. data/spec/pry_output_spec.rb +0 -95
  181. data/spec/pry_spec.rb +0 -515
  182. data/spec/run_command_spec.rb +0 -25
  183. data/spec/sticky_locals_spec.rb +0 -157
  184. data/spec/syntax_checking_spec.rb +0 -81
  185. data/spec/wrapped_module_spec.rb +0 -261
  186. data/wiki/Customizing-pry.md +0 -397
  187. data/wiki/Home.md +0 -4
@@ -1,99 +0,0 @@
1
- require 'helper'
2
- require 'tempfile'
3
-
4
- describe Pry do
5
- before do
6
- Pry.history.clear
7
-
8
- @saved_history = "1\n2\n3\n"
9
-
10
- Pry.history.loader = proc do |&blk|
11
- @saved_history.lines.each { |l| blk.call(l) }
12
- end
13
-
14
- Pry.history.saver = proc do |lines|
15
- @saved_history << lines.map { |l| "#{l}\n" }.join
16
- end
17
-
18
- Pry.load_history
19
- end
20
-
21
- after do
22
- Pry.history.clear
23
- Pry.history.restore_default_behavior
24
- end
25
-
26
- describe '#push' do
27
- it "should not record duplicated lines" do
28
- Pry.history << '3'
29
- Pry.history << '_ += 1'
30
- Pry.history << '_ += 1'
31
- Pry.history.to_a.grep('_ += 1').count.should == 1
32
- end
33
-
34
- it "should not record empty lines" do
35
- c = Pry.history.to_a.count
36
- Pry.history << ''
37
- Pry.history.to_a.count.should == c
38
- end
39
- end
40
-
41
- describe ".load_history" do
42
- it "should read the contents of the file" do
43
- Pry.history.to_a[-2..-1].should == %w(2 3)
44
- end
45
- end
46
-
47
- describe ".save_history" do
48
- it "should include a trailing newline" do
49
- Pry.history << "4"
50
- Pry.save_history
51
- @saved_history.should =~ /4\n\z/
52
- end
53
-
54
- it "should not change anything if history is not changed" do
55
- @saved_history = "4\n5\n6\n"
56
- Pry.save_history
57
- @saved_history.should == "4\n5\n6\n"
58
- end
59
-
60
- it "should append new lines to the file" do
61
- Pry.history << "4"
62
- Pry.save_history
63
- @saved_history.should == "1\n2\n3\n4\n"
64
- end
65
-
66
- it "should not clobber lines written by other Pry's in the meantime" do
67
- Pry.history << "5"
68
- @saved_history << "4\n"
69
- Pry.save_history
70
-
71
- Pry.history.to_a[-3..-1].should == ["2", "3", "5"]
72
- @saved_history.should == "1\n2\n3\n4\n5\n"
73
- end
74
-
75
- it "should not delete lines from the file if this session's history was cleared" do
76
- Pry.history.clear
77
- Pry.save_history
78
- @saved_history.should == "1\n2\n3\n"
79
- end
80
-
81
- it "should save new lines that are added after the history was cleared" do
82
- Pry.history.clear
83
- Pry.history << "4"
84
- Pry.save_history
85
- @saved_history.should =~ /1\n2\n3\n4\n/
86
- end
87
-
88
- it "should only append new lines the second time it is saved" do
89
- Pry.history << "4"
90
- Pry.save_history
91
- @saved_history << "5\n"
92
- Pry.history << "6"
93
- Pry.save_history
94
-
95
- Pry.history.to_a[-4..-1].should == ["2", "3", "4", "6"]
96
- @saved_history.should == "1\n2\n3\n4\n5\n6\n"
97
- end
98
- end
99
- end
@@ -1,95 +0,0 @@
1
- require 'helper'
2
-
3
- describe Pry do
4
- describe "output failsafe" do
5
- after do
6
- Pry.config.print = Pry::DEFAULT_PRINT
7
- end
8
-
9
- it "should catch serialization exceptions" do
10
- Pry.config.print = lambda { |*a| raise "catch-22" }
11
-
12
- lambda {
13
- mock_pry("1")
14
- }.should.not.raise
15
- end
16
-
17
- it "should display serialization exceptions" do
18
- Pry.config.print = lambda { |*a| raise "catch-22" }
19
-
20
- mock_pry("1").should =~ /\(pry\) output error: #<RuntimeError: catch-22>/
21
- end
22
-
23
- it "should catch errors serializing exceptions" do
24
- Pry.config.print = lambda do |*a|
25
- raise Exception.new("catch-22").tap{ |e| class << e; def inspect; raise e; end; end }
26
- end
27
-
28
- mock_pry("1").should =~ /\(pry\) output error: failed to show result/
29
- end
30
- end
31
-
32
- describe "DEFAULT_PRINT" do
33
- it "should output the right thing" do
34
- mock_pry("[1]").should =~ /^=> \[1\]/
35
- end
36
-
37
- it "should include the =>" do
38
- accumulator = StringIO.new
39
- Pry.config.print.call(accumulator, [1])
40
- accumulator.string.should == "=> \[1\]\n"
41
- end
42
-
43
- it "should not be phased by un-inspectable things" do
44
- mock_pry("class NastyClass; undef pretty_inspect; end", "NastyClass.new").should =~ /#<.*NastyClass:0x.*?>/
45
- end
46
- end
47
-
48
- describe "color" do
49
- before do
50
- Pry.color = true
51
- end
52
-
53
- after do
54
- Pry.color = false
55
- end
56
-
57
- it "should colorize strings as though they were ruby" do
58
- accumulator = StringIO.new
59
- Pry.config.print.call(accumulator, [1])
60
- accumulator.string.should == "=> [\e[1;34m1\e[0m]\e[0m\n"
61
- end
62
-
63
- it "should not colorize strings that already include color" do
64
- f = Object.new
65
- def f.inspect
66
- "\e[1;31mFoo\e[0m"
67
- end
68
- accumulator = StringIO.new
69
- Pry.config.print.call(accumulator, f)
70
- # We add an extra \e[0m to prevent color leak
71
- accumulator.string.should == "=> \e[1;31mFoo\e[0m\e[0m\n"
72
- end
73
- end
74
-
75
- describe "output suppression" do
76
- before do
77
- @t = pry_tester
78
- end
79
- it "should normally output the result" do
80
- mock_pry("1 + 2").should == "=> 3\n\n"
81
- end
82
-
83
- it "should not output anything if the input ends with a semicolon" do
84
- mock_pry("1 + 2;").should == "\n"
85
- end
86
-
87
- it "should output something if the input ends with a comment" do
88
- mock_pry("1 + 2 # basic addition").should == "=> 3\n\n"
89
- end
90
-
91
- it "should not output something if the input is only a comment" do
92
- mock_pry("# basic addition").should == "\n"
93
- end
94
- end
95
- end
@@ -1,515 +0,0 @@
1
- require 'helper'
2
-
3
- describe Pry do
4
- before do
5
- @str_output = StringIO.new
6
- end
7
-
8
- if RUBY_VERSION =~ /1.9/
9
- describe "Exotic object support" do
10
- # regression test for exotic object support
11
- it "Should not error when return value is a BasicObject instance" do
12
-
13
- lambda do
14
- redirect_pry_io(InputTester.new("BasicObject.new", "exit-all"), StringIO.new) do
15
- Pry.start
16
- end
17
- end.should.not.raise NoMethodError
18
-
19
- end
20
- end
21
- end
22
-
23
- describe 'DISABLE_PRY' do
24
- before do
25
- ENV['DISABLE_PRY'] = 'true'
26
- end
27
-
28
- after do
29
- ENV.delete 'DISABLE_PRY'
30
- end
31
-
32
- it 'should not binding.pry' do
33
- binding.pry.should == nil
34
- end
35
-
36
- it 'should not Pry.start' do
37
- Pry.start.should == nil
38
- end
39
- end
40
-
41
- describe "Pry.critical_section" do
42
- it "should prevent Pry being called" do
43
- output = StringIO.new
44
- Pry.output = output
45
- Pry.critical_section do
46
- Pry.start
47
- end
48
- output.string.should =~ /Pry started inside Pry/
49
- end
50
- end
51
-
52
- describe "Pry.binding_for" do
53
-
54
- # regression test for burg's bug (see git history)
55
- it "Should not error when object doesn't have a valid == method" do
56
- o = Object.new
57
- def o.==(other)
58
- raise
59
- end
60
-
61
- lambda { Pry.binding_for(o) }.should.not.raise Exception
62
- end
63
-
64
- it "should not leak local variables" do
65
- [Object.new, Array, 3].each do |obj|
66
- Pry.binding_for(obj).eval("local_variables").should.be.empty
67
- end
68
- end
69
- end
70
-
71
- describe "open a Pry session on an object" do
72
- describe "rep" do
73
- before do
74
- class Hello
75
- end
76
- end
77
-
78
- after do
79
- Object.send(:remove_const, :Hello)
80
- end
81
-
82
- # bug fix for https://github.com/banister/pry/issues/93
83
- it 'should not leak pry constants into Object namespace' do
84
- input_string = "Command"
85
- o = Object.new
86
- pry_tester = Pry.new(:input => StringIO.new(input_string),
87
- :output => @str_output,
88
- :exception_handler => proc { |_, exception, _pry_| @excep = exception },
89
- :print => proc {}
90
- ).rep(o)
91
-
92
- @excep.is_a?(NameError).should == true
93
- end
94
-
95
- if defined?(BasicObject)
96
- it 'should be able to operate inside the BasicObject class' do
97
- redirect_pry_io(InputTester.new(":foo", "Pad.obj = _", "exit-all")) do
98
- BasicObject.pry
99
- end
100
-
101
- Pad.obj.should == :foo
102
- end
103
- end
104
-
105
- it 'should set an ivar on an object' do
106
- input_string = "@x = 10"
107
- input = InputTester.new(input_string)
108
- o = Object.new
109
-
110
- pry_tester = Pry.new(:input => input, :output => StringIO.new)
111
- pry_tester.rep(o)
112
- o.instance_variable_get(:@x).should == 10
113
- end
114
-
115
- it 'should display error if Pry instance runs out of input' do
116
- redirect_pry_io(StringIO.new, @str_output) do
117
- Pry.new.repl
118
- end
119
- @str_output.string.should =~ /Error: Pry ran out of things to read/
120
- end
121
-
122
- it 'should make self evaluate to the receiver of the rep session' do
123
- o = :john
124
-
125
- pry_tester = Pry.new(:input => InputTester.new("self"), :output => @str_output)
126
- pry_tester.rep(o)
127
- @str_output.string.should =~ /:john/
128
- end
129
-
130
- it 'should work with multi-line input' do
131
- o = Object.new
132
-
133
- pry_tester = Pry.new(:input => InputTester.new("x = ", "1 + 4"), :output => @str_output)
134
- pry_tester.rep(o)
135
- @str_output.string.should =~ /5/
136
- end
137
-
138
- it 'should define a nested class under Hello and not on top-level or Pry' do
139
- pry_tester = Pry.new(:input => InputTester.new("class Nested", "end"), :output => StringIO.new)
140
- pry_tester.rep(Hello)
141
- Hello.const_defined?(:Nested).should == true
142
- end
143
-
144
- it 'should suppress output if input ends in a ";" and is an Exception object (single line)' do
145
- o = Object.new
146
-
147
- pry_tester = Pry.new(:input => InputTester.new("Exception.new;"), :output => @str_output)
148
- pry_tester.rep(o)
149
- @str_output.string.should == ""
150
- end
151
-
152
- it 'should suppress output if input ends in a ";" (single line)' do
153
- o = Object.new
154
-
155
- pry_tester = Pry.new(:input => InputTester.new("x = 5;"), :output => @str_output)
156
- pry_tester.rep(o)
157
- @str_output.string.should == ""
158
- end
159
-
160
- it 'should suppress output if input ends in a ";" (multi-line)' do
161
- o = Object.new
162
-
163
- pry_tester = Pry.new(:input => InputTester.new("def self.blah", ":test", "end;"), :output => @str_output)
164
- pry_tester.rep(o)
165
- @str_output.string.should == ""
166
- end
167
-
168
- it 'should be able to evaluate exceptions normally' do
169
- o = Exception.new
170
-
171
- was_called = false
172
- pry_tester = Pry.new(:input => InputTester.new("self"),
173
- :output => @str_output,
174
- :exception_handler => proc { was_called = true })
175
-
176
- pry_tester.rep(o)
177
- was_called.should == false
178
- end
179
-
180
- it 'should notice when exceptions are raised' do
181
- o = Exception.new
182
-
183
- was_called = false
184
- pry_tester = Pry.new(:input => InputTester.new("raise self"),
185
- :output => @str_output,
186
- :exception_handler => proc { was_called = true })
187
-
188
- pry_tester.rep(o)
189
- was_called.should == true
190
- end
191
-
192
- it 'should not try to catch intended exceptions' do
193
- lambda { mock_pry("raise SystemExit") }.should.raise SystemExit
194
- # SIGTERM
195
- lambda { mock_pry("raise SignalException.new(15)") }.should.raise SignalException
196
- end
197
- end
198
-
199
- describe "repl" do
200
- describe "basic functionality" do
201
- it 'should set an ivar on an object and exit the repl' do
202
- input_strings = ["@x = 10", "exit-all"]
203
- input = InputTester.new(*input_strings)
204
-
205
- o = Object.new
206
-
207
- pry_tester = Pry.start(o, :input => input, :output => StringIO.new)
208
-
209
- o.instance_variable_get(:@x).should == 10
210
- end
211
-
212
- it 'should preserve newlines correctly with multi-line input' do
213
- input_strings = ['@s = <<-END', '1', '', '', '2', 'END']
214
- input = InputTester.new(*input_strings)
215
-
216
- o = Object.new
217
-
218
- pry_tester = Pry.start(o, :input => input, :output => StringIO.new)
219
-
220
- o.instance_variable_get(:@s).should == "1\n\n\n2\n"
221
- end
222
- end
223
-
224
- describe "complete_expression?" do
225
- it "should not mutate the input!" do
226
- clean = "puts <<-FOO\nhi\nFOO\n"
227
- a = clean.dup
228
- Pry::Code.complete_expression?(a)
229
- a.should == clean
230
- end
231
- end
232
-
233
- describe "history arrays" do
234
- it 'sets _ to the last result' do
235
- res = []
236
- input = InputTester.new *[":foo", "self << _", "42", "self << _"]
237
- pry = Pry.new(:input => input, :output => StringIO.new)
238
- pry.repl(res)
239
-
240
- res.should == [:foo, 42]
241
- end
242
-
243
- it 'sets out to an array with the result' do
244
- res = {}
245
- input = InputTester.new *[":foo", "42", "self[:res] = _out_"]
246
- pry = Pry.new(:input => input, :output => StringIO.new)
247
- pry.repl(res)
248
-
249
- res[:res].should.be.kind_of Pry::HistoryArray
250
- res[:res][1..2].should == [:foo, 42]
251
- end
252
-
253
- it 'sets _in_ to an array with the entered lines' do
254
- res = {}
255
- input = InputTester.new *[":foo", "42", "self[:res] = _in_"]
256
- pry = Pry.new(:input => input, :output => StringIO.new)
257
- pry.repl(res)
258
-
259
- res[:res].should.be.kind_of Pry::HistoryArray
260
- res[:res][1..2].should == [":foo\n", "42\n"]
261
- end
262
-
263
- it 'uses 100 as the size of _in_ and _out_' do
264
- res = []
265
- input = InputTester.new *["self << _out_.max_size << _in_.max_size"]
266
- pry = Pry.new(:input => input, :output => StringIO.new)
267
- pry.repl(res)
268
-
269
- res.should == [100, 100]
270
- end
271
-
272
- it 'can change the size of the history arrays' do
273
- res = []
274
- input = InputTester.new *["self << _out_.max_size << _in_.max_size"]
275
- pry = Pry.new(:input => input, :output => StringIO.new,
276
- :memory_size => 1000)
277
- pry.repl(res)
278
-
279
- res.should == [1000, 1000]
280
- end
281
-
282
- it 'store exceptions' do
283
- res = []
284
- input = InputTester.new *["foo!","self << _in_[-1] << _out_[-1]"]
285
- pry = Pry.new(:input => input, :output => StringIO.new,
286
- :memory_size => 1000)
287
- pry.repl(res)
288
-
289
- res.first.should == "foo!\n"
290
- res.last.should.be.kind_of NoMethodError
291
- end
292
- end
293
-
294
- describe "last_result" do
295
- it "should be set to the most recent value" do
296
- pry_eval("2", "_ + 82").should == 84
297
- end
298
-
299
- # This test needs mock_pry because the command retvals work by
300
- # replacing the eval_string, so _ won't be modified without Pry doing
301
- # a REPL loop.
302
- it "should be set to the result of a command with :keep_retval" do
303
- Pry::Commands.block_command '++', '', :keep_retval => true do |a|
304
- a.to_i + 1
305
- end
306
-
307
- mock_pry('++ 86', '++ #{_}').should =~ /88/
308
- end
309
-
310
- it "should be preserved over an empty line" do
311
- pry_eval("2 + 2", " ", "\t", " ", "_ + 92").should == 96
312
- end
313
-
314
- it "should be preserved when evalling a command without :keep_retval" do
315
- pry_eval("2 + 2", "ls -l", "_ + 96").should == 100
316
- end
317
- end
318
-
319
- describe "test loading rc files" do
320
- before do
321
- Pry::HOME_RC_FILE.replace "spec/fixtures/testrc"
322
- Pry::LOCAL_RC_FILE.replace "spec/fixtures/testrc/../testrc"
323
- Pry.instance_variable_set(:@initial_session, true)
324
- end
325
-
326
- after do
327
- Pry::HOME_RC_FILE.replace "~/.pryrc"
328
- Pry::LOCAL_RC_FILE.replace "./.pryrc"
329
- Pry.config.should_load_rc = false
330
- Object.remove_const(:TEST_RC) if defined?(TEST_RC)
331
- end
332
-
333
- it "should never run the rc file twice" do
334
- Pry.config.should_load_rc = true
335
-
336
- Pry.start(self, :input => StringIO.new("exit-all\n"), :output => StringIO.new)
337
- TEST_RC.should == [0]
338
-
339
- Pry.start(self, :input => StringIO.new("exit-all\n"), :output => StringIO.new)
340
- TEST_RC.should == [0]
341
- end
342
-
343
- it "should not load the pryrc if it cannot expand ENV[HOME]" do
344
- old_home = ENV['HOME']
345
- old_rc = Pry.config.should_load_rc
346
- ENV['HOME'] = nil
347
- Pry.config.should_load_rc = true
348
- lambda { Pry.start(self, :input => StringIO.new("exit-all\n"), :output => StringIO.new) }.should.not.raise
349
-
350
- ENV['HOME'] = old_home
351
- Pry.config.should_load_rc = old_rc
352
- end
353
-
354
- it "should not run the rc file at all if Pry.config.should_load_rc is false" do
355
- Pry.config.should_load_rc = false
356
- Pry.start(self, :input => StringIO.new("exit-all\n"), :output => StringIO.new)
357
- Object.const_defined?(:TEST_RC).should == false
358
- end
359
-
360
- it "should not load the rc file if #repl method invoked" do
361
- Pry.config.should_load_rc = true
362
- Pry.new(:input => StringIO.new("exit-all\n"), :output => StringIO.new).repl(self)
363
- Object.const_defined?(:TEST_RC).should == false
364
- Pry.config.should_load_rc = false
365
- end
366
-
367
- describe "that raise exceptions" do
368
- before do
369
- Pry::HOME_RC_FILE = "spec/fixtures/testrcbad"
370
- Pry.config.should_load_rc = true
371
- Pry.config.should_load_local_rc = false
372
-
373
- putsed = nil
374
-
375
- # YUCK! horrible hack to get round the fact that output is not configured
376
- # at the point this message is printed.
377
- (class << Pry; self; end).send(:define_method, :puts) { |str|
378
- putsed = str
379
- }
380
-
381
- @doing_it = lambda{
382
- Pry.start(self, :input => StringIO.new("Object::TEST_AFTER_RAISE=1\nexit-all\n"), :output => StringIO.new)
383
- putsed
384
- }
385
- end
386
-
387
- after do
388
- Object.remove_const(:TEST_BEFORE_RAISE)
389
- Object.remove_const(:TEST_AFTER_RAISE)
390
- (class << Pry; undef_method :puts; end)
391
- end
392
-
393
- it "should not raise exceptions" do
394
- @doing_it.should.not.raise
395
- end
396
-
397
- it "should continue to run pry" do
398
- @doing_it[]
399
- Object.const_defined?(:TEST_BEFORE_RAISE).should == true
400
- Object.const_defined?(:TEST_AFTER_RAISE).should == true
401
- end
402
-
403
- it "should output an error" do
404
- @doing_it.call.split("\n").first.should ==
405
- "Error loading spec/fixtures/testrcbad: messin with ya"
406
- end
407
- end
408
- end
409
-
410
- describe "nesting" do
411
- after do
412
- Pry.reset_defaults
413
- Pry.color = false
414
- end
415
-
416
- it 'should nest properly' do
417
- Pry.input = InputTester.new("cd 1", "cd 2", "cd 3", "\"nest:\#\{(_pry_.binding_stack.size - 1)\}\"", "exit-all")
418
-
419
- Pry.output = @str_output
420
-
421
- o = Object.new
422
-
423
- pry_tester = o.pry
424
- @str_output.string.should =~ /nest:3/
425
- end
426
- end
427
-
428
- describe "defining methods" do
429
- it 'should define a method on the singleton class of an object when performing "def meth;end" inside the object' do
430
- [Object.new, {}, []].each do |val|
431
- str_input = StringIO.new("def hello;end")
432
- Pry.new(:input => str_input, :output => StringIO.new).rep(val)
433
-
434
- val.methods(false).map(&:to_sym).include?(:hello).should == true
435
- end
436
- end
437
-
438
- it 'should define an instance method on the module when performing "def meth;end" inside the module' do
439
- str_input = StringIO.new("def hello;end")
440
- hello = Module.new
441
- Pry.new(:input => str_input, :output => StringIO.new).rep(hello)
442
- hello.instance_methods(false).map(&:to_sym).include?(:hello).should == true
443
- end
444
-
445
- it 'should define an instance method on the class when performing "def meth;end" inside the class' do
446
- str_input = StringIO.new("def hello;end")
447
- hello = Class.new
448
- Pry.new(:input => str_input, :output => StringIO.new).rep(hello)
449
- hello.instance_methods(false).map(&:to_sym).include?(:hello).should == true
450
- end
451
-
452
- it 'should define a method on the class of an object when performing "def meth;end" inside an immediate value or Numeric' do
453
- # should include float in here, but test fails for some reason
454
- # on 1.8.7, no idea why!
455
- [:test, 0, true, false, nil].each do |val|
456
- str_input = StringIO.new("def hello;end")
457
- Pry.new(:input => str_input, :output => StringIO.new).rep(val)
458
- val.class.instance_methods(false).map(&:to_sym).include?(:hello).should == true
459
- end
460
- end
461
- end
462
-
463
- describe "Object#pry" do
464
-
465
- after do
466
- Pry.reset_defaults
467
- Pry.color = false
468
- end
469
-
470
- it "should start a pry session on the receiver (first form)" do
471
- Pry.input = InputTester.new("self", "exit-all")
472
-
473
- str_output = StringIO.new
474
- Pry.output = str_output
475
-
476
- 20.pry
477
-
478
- str_output.string.should =~ /20/
479
- end
480
-
481
- it "should start a pry session on the receiver (second form)" do
482
- Pry.input = InputTester.new("self", "exit-all")
483
-
484
- str_output = StringIO.new
485
- Pry.output = str_output
486
-
487
- pry 20
488
-
489
- str_output.string.should =~ /20/
490
- end
491
-
492
- it "should raise if more than two arguments are passed to Object#pry" do
493
- lambda { pry(20, :quiet, :input => Readline) }.should.raise ArgumentError
494
- end
495
- end
496
-
497
- describe "Pry.binding_for" do
498
- it 'should return TOPLEVEL_BINDING if parameter self is main' do
499
- _main_ = lambda { TOPLEVEL_BINDING.eval('self') }
500
- Pry.binding_for(_main_.call).is_a?(Binding).should == true
501
- Pry.binding_for(_main_.call).should == TOPLEVEL_BINDING
502
- Pry.binding_for(_main_.call).should == Pry.binding_for(_main_.call)
503
- end
504
- end
505
- end
506
- end
507
-
508
- describe 'setting custom options' do
509
- it 'should not raise for unrecognized options' do
510
- should.not.raise?(NoMethodError) {
511
- instance = Pry.new(:custom_option => 'custom value')
512
- }
513
- end
514
- end
515
- end