pry 0.10.pre.1-java → 0.10.0.pre2-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (214) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +702 -0
  3. data/LICENSE +2 -2
  4. data/{README.markdown → README.md} +41 -35
  5. data/lib/pry.rb +82 -139
  6. data/lib/pry/cli.rb +77 -30
  7. data/lib/pry/code.rb +126 -182
  8. data/lib/pry/code/code_file.rb +103 -0
  9. data/lib/pry/code/code_range.rb +71 -0
  10. data/lib/pry/code/loc.rb +92 -0
  11. data/lib/pry/code_object.rb +172 -0
  12. data/lib/pry/color_printer.rb +55 -0
  13. data/lib/pry/command.rb +184 -28
  14. data/lib/pry/command_set.rb +113 -59
  15. data/lib/pry/commands.rb +4 -27
  16. data/lib/pry/commands/amend_line.rb +99 -0
  17. data/lib/pry/commands/bang.rb +20 -0
  18. data/lib/pry/commands/bang_pry.rb +17 -0
  19. data/lib/pry/commands/cat.rb +62 -0
  20. data/lib/pry/commands/cat/abstract_formatter.rb +27 -0
  21. data/lib/pry/commands/cat/exception_formatter.rb +77 -0
  22. data/lib/pry/commands/cat/file_formatter.rb +67 -0
  23. data/lib/pry/commands/cat/input_expression_formatter.rb +43 -0
  24. data/lib/pry/commands/cd.rb +41 -0
  25. data/lib/pry/commands/change_inspector.rb +27 -0
  26. data/lib/pry/commands/change_prompt.rb +26 -0
  27. data/lib/pry/commands/code_collector.rb +165 -0
  28. data/lib/pry/commands/disable_pry.rb +27 -0
  29. data/lib/pry/commands/disabled_commands.rb +2 -0
  30. data/lib/pry/commands/easter_eggs.rb +112 -0
  31. data/lib/pry/commands/edit.rb +195 -0
  32. data/lib/pry/commands/edit/exception_patcher.rb +25 -0
  33. data/lib/pry/commands/edit/file_and_line_locator.rb +36 -0
  34. data/lib/pry/commands/exit.rb +42 -0
  35. data/lib/pry/commands/exit_all.rb +29 -0
  36. data/lib/pry/commands/exit_program.rb +23 -0
  37. data/lib/pry/commands/find_method.rb +193 -0
  38. data/lib/pry/commands/fix_indent.rb +19 -0
  39. data/lib/pry/commands/gem_cd.rb +26 -0
  40. data/lib/pry/commands/gem_install.rb +32 -0
  41. data/lib/pry/commands/gem_list.rb +33 -0
  42. data/lib/pry/commands/gem_open.rb +29 -0
  43. data/lib/pry/commands/gist.rb +101 -0
  44. data/lib/pry/commands/help.rb +164 -0
  45. data/lib/pry/commands/hist.rb +180 -0
  46. data/lib/pry/commands/import_set.rb +22 -0
  47. data/lib/pry/commands/install_command.rb +53 -0
  48. data/lib/pry/commands/jump_to.rb +29 -0
  49. data/lib/pry/commands/list_inspectors.rb +35 -0
  50. data/lib/pry/commands/list_prompts.rb +35 -0
  51. data/lib/pry/commands/ls.rb +114 -0
  52. data/lib/pry/commands/ls/constants.rb +47 -0
  53. data/lib/pry/commands/ls/formatter.rb +49 -0
  54. data/lib/pry/commands/ls/globals.rb +48 -0
  55. data/lib/pry/commands/ls/grep.rb +21 -0
  56. data/lib/pry/commands/ls/instance_vars.rb +39 -0
  57. data/lib/pry/commands/ls/interrogatable.rb +18 -0
  58. data/lib/pry/commands/ls/jruby_hacks.rb +49 -0
  59. data/lib/pry/commands/ls/local_names.rb +35 -0
  60. data/lib/pry/commands/ls/local_vars.rb +39 -0
  61. data/lib/pry/commands/ls/ls_entity.rb +70 -0
  62. data/lib/pry/commands/ls/methods.rb +57 -0
  63. data/lib/pry/commands/ls/methods_helper.rb +46 -0
  64. data/lib/pry/commands/ls/self_methods.rb +32 -0
  65. data/lib/pry/commands/nesting.rb +25 -0
  66. data/lib/pry/commands/play.rb +103 -0
  67. data/lib/pry/commands/pry_backtrace.rb +25 -0
  68. data/lib/pry/commands/pry_version.rb +17 -0
  69. data/lib/pry/commands/raise_up.rb +32 -0
  70. data/lib/pry/commands/reload_code.rb +62 -0
  71. data/lib/pry/commands/reset.rb +18 -0
  72. data/lib/pry/commands/ri.rb +60 -0
  73. data/lib/pry/commands/save_file.rb +61 -0
  74. data/lib/pry/commands/shell_command.rb +48 -0
  75. data/lib/pry/commands/shell_mode.rb +25 -0
  76. data/lib/pry/commands/show_doc.rb +83 -0
  77. data/lib/pry/commands/show_info.rb +195 -0
  78. data/lib/pry/commands/show_input.rb +17 -0
  79. data/lib/pry/commands/show_source.rb +50 -0
  80. data/lib/pry/commands/simple_prompt.rb +22 -0
  81. data/lib/pry/commands/stat.rb +40 -0
  82. data/lib/pry/commands/switch_to.rb +23 -0
  83. data/lib/pry/commands/toggle_color.rb +24 -0
  84. data/lib/pry/commands/watch_expression.rb +105 -0
  85. data/lib/pry/commands/watch_expression/expression.rb +38 -0
  86. data/lib/pry/commands/whereami.rb +190 -0
  87. data/lib/pry/commands/wtf.rb +57 -0
  88. data/lib/pry/config.rb +20 -229
  89. data/lib/pry/config/behavior.rb +139 -0
  90. data/lib/pry/config/convenience.rb +26 -0
  91. data/lib/pry/config/default.rb +165 -0
  92. data/lib/pry/core_extensions.rb +59 -38
  93. data/lib/pry/editor.rb +133 -0
  94. data/lib/pry/exceptions.rb +77 -0
  95. data/lib/pry/helpers.rb +1 -0
  96. data/lib/pry/helpers/base_helpers.rb +40 -154
  97. data/lib/pry/helpers/command_helpers.rb +19 -130
  98. data/lib/pry/helpers/documentation_helpers.rb +21 -11
  99. data/lib/pry/helpers/table.rb +109 -0
  100. data/lib/pry/helpers/text.rb +8 -9
  101. data/lib/pry/history.rb +61 -45
  102. data/lib/pry/history_array.rb +11 -1
  103. data/lib/pry/hooks.rb +10 -32
  104. data/lib/pry/indent.rb +110 -38
  105. data/lib/pry/input_completer.rb +242 -0
  106. data/lib/pry/input_lock.rb +132 -0
  107. data/lib/pry/inspector.rb +27 -0
  108. data/lib/pry/last_exception.rb +61 -0
  109. data/lib/pry/method.rb +199 -200
  110. data/lib/pry/method/disowned.rb +53 -0
  111. data/lib/pry/method/patcher.rb +125 -0
  112. data/lib/pry/method/weird_method_locator.rb +186 -0
  113. data/lib/pry/module_candidate.rb +39 -33
  114. data/lib/pry/object_path.rb +82 -0
  115. data/lib/pry/output.rb +50 -0
  116. data/lib/pry/pager.rb +234 -0
  117. data/lib/pry/plugins.rb +4 -3
  118. data/lib/pry/prompt.rb +26 -0
  119. data/lib/pry/pry_class.rb +199 -227
  120. data/lib/pry/pry_instance.rb +344 -403
  121. data/lib/pry/rbx_path.rb +1 -1
  122. data/lib/pry/repl.rb +202 -0
  123. data/lib/pry/repl_file_loader.rb +20 -26
  124. data/lib/pry/rubygem.rb +82 -0
  125. data/lib/pry/terminal.rb +79 -0
  126. data/lib/pry/test/helper.rb +170 -0
  127. data/lib/pry/version.rb +1 -1
  128. data/lib/pry/wrapped_module.rb +133 -48
  129. metadata +132 -197
  130. data/.document +0 -2
  131. data/.gemtest +0 -0
  132. data/.gitignore +0 -16
  133. data/.travis.yml +0 -17
  134. data/.yardopts +0 -1
  135. data/CHANGELOG +0 -387
  136. data/CONTRIBUTORS +0 -36
  137. data/Gemfile +0 -2
  138. data/Rakefile +0 -137
  139. data/TODO +0 -117
  140. data/examples/example_basic.rb +0 -15
  141. data/examples/example_command_override.rb +0 -32
  142. data/examples/example_commands.rb +0 -36
  143. data/examples/example_hooks.rb +0 -9
  144. data/examples/example_image_edit.rb +0 -67
  145. data/examples/example_input.rb +0 -7
  146. data/examples/example_input2.rb +0 -29
  147. data/examples/example_output.rb +0 -11
  148. data/examples/example_print.rb +0 -6
  149. data/examples/example_prompt.rb +0 -9
  150. data/examples/helper.rb +0 -6
  151. data/lib/pry/completion.rb +0 -221
  152. data/lib/pry/custom_completions.rb +0 -6
  153. data/lib/pry/default_commands/cd.rb +0 -81
  154. data/lib/pry/default_commands/commands.rb +0 -62
  155. data/lib/pry/default_commands/context.rb +0 -98
  156. data/lib/pry/default_commands/easter_eggs.rb +0 -95
  157. data/lib/pry/default_commands/editing.rb +0 -420
  158. data/lib/pry/default_commands/find_method.rb +0 -169
  159. data/lib/pry/default_commands/gems.rb +0 -84
  160. data/lib/pry/default_commands/gist.rb +0 -187
  161. data/lib/pry/default_commands/help.rb +0 -127
  162. data/lib/pry/default_commands/hist.rb +0 -120
  163. data/lib/pry/default_commands/input_and_output.rb +0 -306
  164. data/lib/pry/default_commands/introspection.rb +0 -410
  165. data/lib/pry/default_commands/ls.rb +0 -272
  166. data/lib/pry/default_commands/misc.rb +0 -38
  167. data/lib/pry/default_commands/navigating_pry.rb +0 -110
  168. data/lib/pry/default_commands/whereami.rb +0 -92
  169. data/lib/pry/extended_commands/experimental.rb +0 -7
  170. data/lib/pry/rbx_method.rb +0 -13
  171. data/man/pry.1 +0 -195
  172. data/man/pry.1.html +0 -204
  173. data/man/pry.1.ronn +0 -141
  174. data/pry.gemspec +0 -46
  175. data/test/candidate_helper1.rb +0 -11
  176. data/test/candidate_helper2.rb +0 -8
  177. data/test/helper.rb +0 -223
  178. data/test/test_cli.rb +0 -78
  179. data/test/test_code.rb +0 -201
  180. data/test/test_command.rb +0 -712
  181. data/test/test_command_helpers.rb +0 -9
  182. data/test/test_command_integration.rb +0 -668
  183. data/test/test_command_set.rb +0 -610
  184. data/test/test_completion.rb +0 -62
  185. data/test/test_control_d_handler.rb +0 -45
  186. data/test/test_default_commands/example.erb +0 -5
  187. data/test/test_default_commands/test_cd.rb +0 -318
  188. data/test/test_default_commands/test_context.rb +0 -280
  189. data/test/test_default_commands/test_documentation.rb +0 -314
  190. data/test/test_default_commands/test_find_method.rb +0 -50
  191. data/test/test_default_commands/test_gems.rb +0 -18
  192. data/test/test_default_commands/test_help.rb +0 -57
  193. data/test/test_default_commands/test_input.rb +0 -428
  194. data/test/test_default_commands/test_introspection.rb +0 -511
  195. data/test/test_default_commands/test_ls.rb +0 -151
  196. data/test/test_default_commands/test_shell.rb +0 -343
  197. data/test/test_default_commands/test_show_source.rb +0 -432
  198. data/test/test_exception_whitelist.rb +0 -21
  199. data/test/test_history_array.rb +0 -65
  200. data/test/test_hooks.rb +0 -521
  201. data/test/test_indent.rb +0 -277
  202. data/test/test_input_stack.rb +0 -86
  203. data/test/test_method.rb +0 -401
  204. data/test/test_pry.rb +0 -463
  205. data/test/test_pry_defaults.rb +0 -419
  206. data/test/test_pry_history.rb +0 -84
  207. data/test/test_pry_output.rb +0 -41
  208. data/test/test_sticky_locals.rb +0 -155
  209. data/test/test_syntax_checking.rb +0 -65
  210. data/test/test_wrapped_module.rb +0 -174
  211. data/test/testrc +0 -2
  212. data/test/testrcbad +0 -2
  213. data/wiki/Customizing-pry.md +0 -397
  214. data/wiki/Home.md +0 -4
@@ -1,151 +0,0 @@
1
- require 'helper'
2
-
3
- describe "ls" do
4
- describe "below ceiling" do
5
- it "should stop before Object by default" do
6
- mock_pry("cd Class.new{ def goo; end }.new", "ls").should.not =~ /Object/
7
- mock_pry("cd Class.new{ def goo; end }", "ls -M").should.not =~ /Object/
8
- end
9
-
10
- it "should include object if -v is given" do
11
- mock_pry("cd Class.new{ def goo; end }.new", "ls -m -v").should =~ /Object/
12
- mock_pry("cd Class.new{ def goo; end }", "ls -vM").should =~ /Object/
13
- end
14
-
15
- it "should include super-classes by default" do
16
- mock_pry("cd Class.new(Class.new{ def goo; end }).new", "ls").should =~ /goo/
17
- mock_pry("cd Class.new(Class.new{ def goo; end })", "ls -M").should =~ /goo/
18
- end
19
-
20
- it "should not include super-classes when -q is given" do
21
- mock_pry("cd Class.new(Class.new{ def goo; end }).new", "ls -q").should.not =~ /goo/
22
- mock_pry("cd Class.new(Class.new{ def goo; end })", "ls -M -q").should.not =~ /goo/
23
- end
24
- end
25
-
26
- describe "help" do
27
- it 'should show help with -h' do
28
- mock_pry("ls -h").should =~ /Usage: ls/
29
- end
30
- end
31
-
32
- describe "methods" do
33
- it "should show public methods by default" do
34
- mock_pry("ls Class.new{ def goo; end }.new").should =~ /methods: goo/
35
- end
36
-
37
- it "should not show protected/private by default" do
38
- mock_pry("ls -M Class.new{ def goo; end; private :goo }").should.not =~ /methods: goo/
39
- mock_pry("ls Class.new{ def goo; end; protected :goo }.new").should.not =~ /methods: goo/
40
- end
41
-
42
- it "should show public methods with -p" do
43
- mock_pry("ls -p Class.new{ def goo; end }.new").should =~ /methods: goo/
44
- end
45
-
46
- it "should show protected/private methods with -p" do
47
- mock_pry("ls -pM Class.new{ def goo; end; protected :goo }").should =~ /methods: goo/
48
- mock_pry("ls -p Class.new{ def goo; end; private :goo }.new").should =~ /methods: goo/
49
- end
50
-
51
- it "should work for objects with an overridden method method" do
52
- require 'net/http'
53
- # This doesn't actually touch the network, promise!
54
- mock_pry("ls Net::HTTP::Get.new('localhost')").should =~ /Net::HTTPGenericRequest#methods/
55
- end
56
- end
57
-
58
- describe "when inside Modules" do
59
- it "should still work" do
60
- mock_pry("cd Module.new{ def foobie; end }", "ls -M").should =~ /foobie/
61
- end
62
-
63
- it "should work for ivars" do
64
- mock_pry("module StigmaT1sm; def foobie; @@gharble = 456; end; end", "Object.new.tap{ |o| o.extend(StigmaT1sm) }.foobie", "cd StigmaT1sm", "ls -i").should =~ /@@gharble/
65
- end
66
-
67
- it "should include instance methods by default" do
68
- mock_pry("ls Module.new{ def shinanagarns; 4; end }").should =~ /shinanagarns/
69
- end
70
- end
71
-
72
- describe "constants" do
73
- it "should show constants defined on the current module" do
74
- mock_pry("class TempFoo1; BARGHL = 1; end", "ls TempFoo1").should =~ /BARGHL/
75
- end
76
-
77
- it "should not show constants defined on parent modules by default" do
78
- mock_pry("class TempFoo2; LHGRAB = 1; end; class TempFoo3 < TempFoo2; BARGHL = 1; end", "ls TempFoo3").should.not =~ /LHGRAB/
79
- end
80
-
81
- it "should show constants defined on ancestors with -v" do
82
- mock_pry("class TempFoo4; LHGRAB = 1; end; class TempFoo5 < TempFoo4; BARGHL = 1; end", "ls -v TempFoo5").should =~ /LHGRAB/
83
- end
84
-
85
- it "should not autoload constants!" do
86
- autoload :McflurgleTheThird, "/tmp/this-file-d000esnat-exist.rb"
87
- lambda{ mock_pry("ls -c") }.should.not.raise
88
- end
89
- end
90
-
91
- describe "grep" do
92
- it "should reduce the number of outputted things" do
93
- mock_pry("ls -c").should =~ /ArgumentError/
94
- mock_pry("ls -c --grep Run").should.not =~ /ArgumentError/
95
- end
96
-
97
- it "should still output matching things" do
98
- mock_pry("ls -c --grep Run").should =~ /RuntimeError/
99
- end
100
- end
101
-
102
- describe "when no arguments given" do
103
- describe "when at the top-level" do
104
- # rubinius has a bug that means local_variables of "main" aren't reported inside eval()
105
- unless Pry::Helpers::BaseHelpers.rbx?
106
- it "should show local variables" do
107
- mock_pry("ls").should =~ /_pry_/
108
- mock_pry("arbitrar = 1", "ls").should =~ /arbitrar/
109
- end
110
- end
111
- end
112
-
113
- describe "when in a class" do
114
- it "should show constants" do
115
- mock_pry("class GeFromulate1; FOOTIFICATE=1.3; end", "cd GeFromulate1", "ls").should =~ /FOOTIFICATE/
116
- end
117
-
118
- it "should show class variables" do
119
- mock_pry("class GeFromulate2; @@flurb=1.3; end", "cd GeFromulate2", "ls").should =~ /@@flurb/
120
- end
121
-
122
- it "should show methods" do
123
- mock_pry("class GeFromulate3; def self.mooflight; end ; end", "cd GeFromulate3", "ls").should =~ /mooflight/
124
- end
125
- end
126
-
127
- describe "when in an object" do
128
- it "should show methods" do
129
- mock_pry("cd Class.new{ def self.fooerise; end; self }", "ls").should =~ /fooerise/
130
- end
131
-
132
- it "should show instance variables" do
133
- mock_pry("cd Class.new", "@alphooent = 1", "ls").should =~ /@alphooent/
134
- end
135
- end
136
- end
137
-
138
- if Pry::Helpers::BaseHelpers.jruby?
139
- describe 'on java objects' do
140
- it 'should omit java-esque aliases by default' do
141
- mock_pry('ls java.lang.Thread.current_thread').should =~ / thread_group /
142
- mock_pry('ls java.lang.Thread.current_thread').should.not =~ / getThreadGroup /
143
- end
144
-
145
- it 'should include java-esque aliases if requested' do
146
- mock_pry('ls java.lang.Thread.current_thread -J').should =~ / thread_group /
147
- mock_pry('ls java.lang.Thread.current_thread -J').should =~ / getThreadGroup /
148
- end
149
- end
150
- end
151
- end
@@ -1,343 +0,0 @@
1
- require 'helper'
2
-
3
- describe "Pry::DefaultCommands::Shell" do
4
- describe "save-file" do
5
- before do
6
- @tf = Tempfile.new(["pry", ".py"])
7
- @path = @tf.path
8
- end
9
-
10
- after do
11
- @tf.close(true)
12
- end
13
-
14
- describe "-f" do
15
- it 'should save a file to a file' do
16
- f = Tempfile.new(["pry", ".py"])
17
- path = f.path
18
- f.write ":cute_horse"
19
-
20
- redirect_pry_io(InputTester.new("save-file -f #{path} #{@path}",
21
- "exit-all")) do
22
- Pry.start(@o)
23
- end
24
- File.read(@path).should == File.read(path)
25
-
26
- f.close(true)
27
- end
28
- end
29
-
30
- describe "-i" do
31
- it 'should save input expressions to a file (single expression)' do
32
- redirect_pry_io(InputTester.new(":horse_nostrils",
33
- "save-file -i 1 #{@path}",
34
- "exit-all")) do
35
- Pry.start(@o)
36
- end
37
- File.read(@path).should == ":horse_nostrils\n"
38
- end
39
-
40
- it 'should save input expressions to a file (range)' do
41
- redirect_pry_io(InputTester.new(":horse_nostrils",
42
- ":sucking_up_all_the_oxygen",
43
- "save-file -i 1..2 #{@path}",
44
- "exit-all")) do
45
- Pry.start(@o)
46
- end
47
- File.read(@path).should == ":horse_nostrils\n:sucking_up_all_the_oxygen\n"
48
- end
49
- end
50
-
51
- describe "-m" do
52
- before do
53
- @o = Object.new
54
- def @o.baby
55
- :baby
56
- end
57
- def @o.bang
58
- :bang
59
- end
60
- end
61
-
62
- describe "single method" do
63
- it 'should save a method to a file' do
64
- redirect_pry_io(InputTester.new("save-file #{@path} -m baby",
65
- "exit-all")) do
66
- Pry.start(@o)
67
- end
68
- File.read(@path).should == Pry::Method.from_obj(@o, :baby).source
69
- end
70
-
71
- it 'should save a method to a file truncated by --lines' do
72
- redirect_pry_io(InputTester.new("save-file #{@path} -m baby --lines 2..4",
73
- "exit-all")) do
74
- Pry.start(@o)
75
- end
76
-
77
- # must add 1 as first line of method is 1
78
- File.read(@path).should == Pry::Method.from_obj(@o, :baby).source.lines.to_a[1..5].join
79
- end
80
- end
81
-
82
- describe "multiple method" do
83
- it 'should save multiple methods to a file' do
84
- redirect_pry_io(InputTester.new("save-file #{@path} -m baby -m bang",
85
- "exit-all")) do
86
- Pry.start(@o)
87
- end
88
- File.read(@path).should == Pry::Method.from_obj(@o, :baby).source +
89
- Pry::Method.from_obj(@o, :bang).source
90
- end
91
-
92
- it 'should save multiple methods to a file trucated by --lines' do
93
- redirect_pry_io(InputTester.new("save-file #{@path} -m baby -m bang --lines 2..-2",
94
- "exit-all")) do
95
- Pry.start(@o)
96
- end
97
-
98
- # must add 1 as first line of method is 1
99
- File.read(@path).should == (Pry::Method.from_obj(@o, :baby).source +
100
- Pry::Method.from_obj(@o, :bang).source).lines.to_a[1..-2].join
101
- end
102
-
103
- it 'should save multiple methods to a file trucated by --lines 1 (single parameter, not range)' do
104
- redirect_pry_io(InputTester.new("save-file #{@path} -m baby -m bang --lines 1",
105
- "exit-all")) do
106
- Pry.start(@o)
107
- end
108
-
109
- # must add 1 as first line of method is 1
110
- File.read(@path).should == (Pry::Method.from_obj(@o, :baby).source +
111
- Pry::Method.from_obj(@o, :bang).source).lines.to_a[0]
112
- end
113
-
114
- end
115
-
116
- end
117
-
118
- describe "overwrite by default (no --append)" do
119
- it 'should overwrite specified file with new input' do
120
- redirect_pry_io(InputTester.new(":horse_nostrils",
121
- "save-file -i 1 #{@path}",
122
- "exit-all")) do
123
- Pry.start(@o)
124
- end
125
-
126
- redirect_pry_io(InputTester.new(":sucking_up_all_the_oxygen",
127
- "save-file -i 1 #{@path}",
128
- "exit-all")) do
129
- Pry.start(@o)
130
- end
131
-
132
- File.read(@path).should == ":sucking_up_all_the_oxygen\n"
133
- end
134
-
135
- end
136
-
137
- describe "--append" do
138
- it 'should append to end of specified file' do
139
- redirect_pry_io(InputTester.new(":horse_nostrils",
140
- "save-file -i 1 #{@path}",
141
- "exit-all")) do
142
- Pry.start(@o)
143
- end
144
-
145
- redirect_pry_io(InputTester.new(":sucking_up_all_the_oxygen",
146
- "save-file -i 1 #{@path} -a",
147
- "exit-all")) do
148
- Pry.start(@o)
149
- end
150
-
151
- File.read(@path).should == ":horse_nostrils\n:sucking_up_all_the_oxygen\n"
152
- end
153
- end
154
-
155
- describe "-c" do
156
- it 'should save a command to a file' do
157
- redirect_pry_io(InputTester.new("save-file #{@path} -k show-method",
158
- "exit-all")) do
159
- Pry.start(@o)
160
- end
161
- cmd = Pry::Method.new(Pry.commands.find_command("show-method").block)
162
- File.read(@path).should == Pry::Code.from_method(cmd).to_s
163
- end
164
- end
165
-
166
- describe "combined options" do
167
- before do
168
- @o = Object.new
169
- def @o.baby
170
- :baby
171
- end
172
- end
173
-
174
- it 'should save input cache and a method to a file (in that order)' do
175
- redirect_pry_io(InputTester.new(":horse_nostrils",
176
- "save-file -i 1 -m baby #{@path}",
177
- "exit-all")) do
178
- Pry.start(@o)
179
- end
180
- File.read(@path).should == ":horse_nostrils\n" + Pry::Method.from_obj(@o, :baby).source
181
- end
182
-
183
- it 'should select a portion to save using --lines' do
184
- redirect_pry_io(InputTester.new(":horse_nostrils",
185
- "save-file -i 1 -m baby #{@path} --lines 2..-2",
186
- "exit-all")) do
187
- Pry.start(@o)
188
- end
189
- File.read(@path).should == (":horse_nostrils\n" + Pry::Method.from_obj(@o, :baby).source).lines.to_a[1..-2].join
190
- end
191
- end
192
- end
193
-
194
- describe "cat" do
195
- before do
196
- @str_output = StringIO.new
197
- end
198
-
199
- describe "on receiving a file that does not exist" do
200
- it 'should display an error message' do
201
- mock_pry("cat supercalifragilicious66").should =~ /Cannot open/
202
- end
203
- end
204
-
205
- describe "with --in" do
206
- it 'should display the last few expressions with indices' do
207
- output = mock_pry("10", "20", "cat --in")
208
- output.should =~ /^1:/
209
- output.should =~ /^ 10/
210
- output.should =~ /^2:/
211
- output.should =~ /^ 20/
212
- end
213
- end
214
-
215
- describe "with --in 1" do
216
- it 'should display the first expression with no index' do
217
- output = mock_pry("10", "20", "cat --in 1")
218
- output.should.not =~ /^\d+:/
219
- output.should =~ /^10/
220
- end
221
- end
222
-
223
- describe "with --in -1" do
224
- it 'should display the last expression with no index' do
225
- output = mock_pry("10", "20", "cat --in -1")
226
- output.should.not =~ /^\d+:/
227
- output.should =~ /^20/
228
- end
229
- end
230
-
231
- describe "with --in 1..2" do
232
- it 'should display the given range with indices, omitting nils' do
233
- output = mock_pry("10", "20", "cat --ex", ":hello", "cat --in 1..4")
234
- output.should =~ /^1:/
235
- output.should.not =~ /^3:/
236
- output.should =~ /^ :hello/
237
- end
238
- end
239
-
240
- # this doesnt work so well on rbx due to differences in backtrace
241
- # so we currently skip rbx until we figure out a workaround
242
- describe "with --ex" do
243
- if !Pry::Helpers::BaseHelpers.rbx?
244
- it 'cat --ex should correctly display code that generated exception even if raised in repl' do
245
- mock_pry("this raises error", "cat --ex").should =~ /\d+:(\s*) this raises error/
246
- end
247
-
248
- it 'cat --ex should correctly display code that generated exception' do
249
- mock_pry("broken_method", "cat --ex").should =~ /this method is broken/
250
- end
251
- end
252
- end
253
-
254
- describe "with --ex N" do
255
- it 'should cat first level of backtrace when --ex used with no argument ' do
256
- pry_instance = Pry.new(:input => StringIO.new("cat --ex"), :output => @str_output)
257
-
258
- temp_file do |f|
259
- f << "bt number 1"
260
- f.flush
261
- pry_instance.last_exception = mock_exception("#{f.path}:1", "x", "x")
262
- pry_instance.rep(self)
263
- end
264
-
265
- @str_output.string.should =~ /bt number 1/
266
- end
267
-
268
- it 'should cat first level of backtrace when --ex 0 used ' do
269
- pry_instance = Pry.new(:input => StringIO.new("cat --ex 0"), :output => @str_output)
270
-
271
- temp_file do |f|
272
- f << "bt number 1"
273
- f.flush
274
- pry_instance.last_exception = mock_exception("#{f.path}:1", "x", "x")
275
- pry_instance.rep(self)
276
- end
277
-
278
- @str_output.string.should =~ /bt number 1/
279
- end
280
-
281
- it 'should cat second level of backtrace when --ex 1 used ' do
282
- pry_instance = Pry.new(:input => StringIO.new("cat --ex 1"), :output => @str_output)
283
-
284
- temp_file do |f|
285
- f << "bt number 2"
286
- f.flush
287
- pry_instance.last_exception = mock_exception("x", "#{f.path}:1", "x")
288
- pry_instance.rep(self)
289
- end
290
-
291
- @str_output.string.should =~ /bt number 2/
292
- end
293
-
294
- it 'should cat third level of backtrace when --ex 2 used' do
295
- pry_instance = Pry.new(:input => StringIO.new("cat --ex 2"), :output => @str_output)
296
-
297
- temp_file do |f|
298
- f << "bt number 3"
299
- f.flush
300
- pry_instance.last_exception = mock_exception("x", "x", "#{f.path}:1")
301
- pry_instance.rep(self)
302
- end
303
-
304
- @str_output.string.should =~ /bt number 3/
305
- end
306
-
307
- it 'should show error when backtrace level out of bounds' do
308
- pry_instance = Pry.new(:input => StringIO.new("cat --ex 3"), :output => @str_output)
309
- pry_instance.last_exception = mock_exception("x", "x", "x")
310
- pry_instance.rep(self)
311
- @str_output.string.should =~ /out of bounds/
312
- end
313
-
314
- it 'each successive cat --ex should show the next level of backtrace, and going past the final level should return to the first' do
315
- temp_files = []
316
- 3.times do |i|
317
- temp_files << Tempfile.new(['pry', '*.rb'])
318
- temp_files.last << "bt number #{i}"
319
- temp_files.last.flush
320
- end
321
-
322
- pry_instance = Pry.new(:input => StringIO.new("cat --ex\n" * 4),
323
- :output => @str_output)
324
-
325
- pry_instance.last_exception = mock_exception(*temp_files.map { |f| "#{f.path}:1" })
326
-
327
- 3.times do |i|
328
- pry_instance.rep(self)
329
- @str_output.string.should =~ /bt number #{i}/
330
- end
331
-
332
- @str_output.reopen
333
- pry_instance.rep(self)
334
- @str_output.string.should =~ /bt number 0/
335
-
336
- temp_files.each do |file|
337
- file.close(true)
338
- end
339
- end
340
-
341
- end
342
- end
343
- end