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

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,73 @@
1
+ require 'helper'
2
+
3
+ describe Pry::Helpers::DocumentationHelpers do
4
+ before do
5
+ @helper = Pry::Helpers::DocumentationHelpers
6
+ end
7
+
8
+ describe "get_comment_content" do
9
+ it "should strip off the hash and unindent" do
10
+ @helper.get_comment_content(" # hello\n # world\n").should == "hello\nworld\n"
11
+ end
12
+
13
+ it "should strip out leading lines of hashes" do
14
+ @helper.get_comment_content("###############\n#hello\n#world\n").should == "hello\nworld\n"
15
+ end
16
+
17
+ it "should remove shebangs" do
18
+ @helper.get_comment_content("#!/usr/bin/env ruby\n# This is a program\n").should == "This is a program\n"
19
+ end
20
+
21
+ it "should unindent past separators" do
22
+ @helper.get_comment_content(" # Copyright Me <me@cirw.in>\n #--\n # So there.\n").should == "Copyright Me <me@cirw.in>\n--\nSo there.\n"
23
+ end
24
+ end
25
+
26
+ describe "process_rdoc" do
27
+ before do
28
+ Pry.color = true
29
+ end
30
+
31
+ after do
32
+ Pry.color = false
33
+ end
34
+
35
+ it "should syntax highlight indented code" do
36
+ @helper.process_rdoc(" 4 + 4\n").should.not == " 4 + 4\n"
37
+ end
38
+
39
+ it "should highlight words surrounded by +s" do
40
+ @helper.process_rdoc("the +parameter+").should =~ /the \e.*parameter\e.*/
41
+ end
42
+
43
+ it "should syntax highlight things in backticks" do
44
+ @helper.process_rdoc("for `Example`").should =~ /for `\e.*Example\e.*`/
45
+ end
46
+
47
+ it "should emphasise em tags" do
48
+ @helper.process_rdoc("for <em>science</em>").should == "for \e[1mscience\e[0m"
49
+ end
50
+
51
+ it "should emphasise italic tags" do
52
+ @helper.process_rdoc("for <i>science</i>").should == "for \e[1mscience\e[0m"
53
+ end
54
+
55
+ it "should syntax highlight code in <code>" do
56
+ @helper.process_rdoc("for <code>Example</code>").should =~ /for \e.*Example\e.*/
57
+ end
58
+
59
+ it "should not double-highlight backticks inside indented code" do
60
+ @helper.process_rdoc(" `echo 5`").should =~ /echo 5/
61
+ end
62
+
63
+ it "should not remove ++" do
64
+ @helper.process_rdoc("--\n comment in a bubble\n++").should =~ /\+\+/
65
+ end
66
+
67
+ it "should do nothing if Pry.color is false" do
68
+ Pry.color = false
69
+ @helper.process_rdoc(" 4 + 4\n").should == " 4 + 4\n"
70
+ end
71
+ end
72
+
73
+ end
@@ -0,0 +1,79 @@
1
+ require 'pathname'
2
+ require 'helper'
3
+
4
+ describe Pry::Editor do
5
+ class << Pry::Editor
6
+ public :build_editor_invocation_string
7
+ end
8
+
9
+ before do
10
+ # OS-specific tempdir name. For GNU/Linux it's "tmp", for Windows it's
11
+ # something "Temp".
12
+ @tf_dir =
13
+ if Pry::Helpers::BaseHelpers.mri_19?
14
+ Pathname.new(Dir::Tmpname.tmpdir)
15
+ else
16
+ Pathname.new(Dir.tmpdir)
17
+ end
18
+
19
+ @tf_path = File.join(@tf_dir.to_s, 'hello world.rb')
20
+ end
21
+
22
+ unless Pry::Helpers::BaseHelpers.windows?
23
+ describe "build_editor_invocation_string" do
24
+ before do
25
+ class << Pry::Editor
26
+ public :build_editor_invocation_string
27
+ end
28
+ end
29
+
30
+ it 'should shell-escape files' do
31
+ invocation_str = Pry::Editor.build_editor_invocation_string(@tf_path, 5, true)
32
+ invocation_str.should =~ /#@tf_dir.+hello\\ world\.rb/
33
+ end
34
+ end
35
+ end
36
+
37
+ describe "build_editor_invocation_string on windows" do
38
+ before do
39
+ class << Pry::Editor
40
+ def windows?; true; end
41
+ end
42
+ end
43
+
44
+ after do
45
+ class << Pry::Editor
46
+ undef windows?
47
+ end
48
+ end
49
+
50
+ it "should replace / by \\" do
51
+ invocation_str = Pry::Editor.build_editor_invocation_string(@tf_path, 5, true)
52
+ invocation_str.should =~ %r(\\#{@tf_dir.basename}\\)
53
+ end
54
+
55
+ it "should not shell-escape files" do
56
+ invocation_str = Pry::Editor.build_editor_invocation_string(@tf_path, 5, true)
57
+ invocation_str.should =~ /hello world\.rb/
58
+ end
59
+ end
60
+
61
+ describe 'invoke_editor with a proc' do
62
+ before do
63
+ @old_editor = Pry.config.editor
64
+ Pry.config.editor = proc{ |file, line, blocking|
65
+ @file = file
66
+ nil
67
+ }
68
+ end
69
+
70
+ after do
71
+ Pry.config.editor = @old_editor
72
+ end
73
+
74
+ it 'should not shell-escape files' do
75
+ Pry::Editor.invoke_editor(@tf_path, 10, true)
76
+ @file.should == @tf_path
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,21 @@
1
+ require 'helper'
2
+
3
+ describe "Pry.config.exception_whitelist" do
4
+ before do
5
+ @str_output = StringIO.new
6
+ end
7
+
8
+ it 'should rescue all exceptions NOT specified on whitelist' do
9
+ Pry.config.exception_whitelist.include?(NameError).should == false
10
+ lambda { Pry.start(self, :input => StringIO.new("raise NameError\nexit"), :output => @str_output) }.should.not.raise NameError
11
+ end
12
+
13
+ it 'should NOT rescue exceptions specified on whitelist' do
14
+ old_whitelist = Pry.config.exception_whitelist
15
+ Pry.config.exception_whitelist = [NameError]
16
+ lambda { Pry.start(self, :input => StringIO.new("raise NameError"), :output => @str_output) }.should.raise NameError
17
+ Pry.config.exception_whitelist = old_whitelist
18
+ end
19
+ end
20
+
21
+
@@ -0,0 +1,11 @@
1
+ # rank 0
2
+ class CandidateTest
3
+ def test1
4
+ end
5
+
6
+ def test2
7
+ end
8
+
9
+ def test3
10
+ end
11
+ end
@@ -0,0 +1,8 @@
1
+ # rank 1
2
+ class CandidateTest
3
+ def test4
4
+ end
5
+
6
+ def test5
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ <html>
2
+
3
+ Look at me, testing my erb!
4
+
5
+ </html>
@@ -0,0 +1,33 @@
1
+ # []
2
+ class A # ["class A"]
3
+ def a; end # ["class A"]
4
+ class B; def b; end; end # ["class A", "class B"]
5
+ end # []
6
+ # []
7
+ class << A # ["class << A"]
8
+ class B # ["class << A", "class B"]
9
+ def c; end # ["class << A", "class B"]
10
+ end # ["class << A"]
11
+ # ["class << A"]
12
+ module F::B # ["class << A", "module F::B"]
13
+ def foo; end # ["class << A", "module F::B"]
14
+ end # ["class << A"]
15
+ end # []
16
+ # []
17
+ module (:symbol.class)::Exciting #
18
+ def foo; end #
19
+ class B #
20
+ def goo; end #
21
+ end #
22
+ end # []
23
+ # []
24
+ module C # ["module C"]
25
+ class D # ["module C", "class D"]
26
+ def guh; foo.end; end # ["module C", "class D"]
27
+ end # ["module C"]
28
+ def bar; :end; end # ["module C"]
29
+ class << new.bar; end # ["module C"]
30
+ class << new.bar; def f; end; end #
31
+ # ["module C"]
32
+ class << self; def mug; end; end # ["module C", "class << self"]
33
+ end # []
@@ -0,0 +1,15 @@
1
+ # used by test_show_source.rb and test_documentation.rb
2
+ class TestClassForShowSource
3
+ def alpha
4
+ end
5
+ end
6
+
7
+ class TestClassForShowSourceClassEval
8
+ def alpha
9
+ end
10
+ end
11
+
12
+ class TestClassForShowSourceInstanceEval
13
+ def alpha
14
+ end
15
+ end
@@ -0,0 +1,2 @@
1
+ TEST_RC = [] if !Object.const_defined?(:TEST_RC)
2
+ TEST_RC << 0
@@ -0,0 +1,2 @@
1
+ TEST_RC = [] if !Object.const_defined?(:TEST_RC)
2
+ TEST_RC << 0
@@ -0,0 +1,2 @@
1
+ TEST_BEFORE_RAISE = 1
2
+ raise "messin with ya"
@@ -0,0 +1,6 @@
1
+ class Cor
2
+ def a; end
3
+ def b; end
4
+ def c; end
5
+ def d; end
6
+ end
@@ -0,0 +1,35 @@
1
+ unless Object.const_defined? 'Pry'
2
+ $:.unshift File.expand_path '../../lib', __FILE__
3
+ require 'pry'
4
+ end
5
+
6
+ require 'mocha/api'
7
+
8
+ require 'pry/test/helper'
9
+ require 'helpers/bacon'
10
+ require 'helpers/mock_pry'
11
+ require 'helpers/repl_tester'
12
+
13
+ class Module
14
+ public :remove_const
15
+ public :remove_method
16
+ end
17
+
18
+ # turn warnings off (esp for Pry::Hooks which will generate warnings
19
+ # in tests)
20
+ $VERBOSE = nil
21
+
22
+ Pad = OpenStruct.new
23
+ def Pad.clear
24
+ @table = {}
25
+ end
26
+
27
+ # to help with tracking down bugs that cause an infinite loop in the test suite
28
+ if ENV["SET_TRACE_FUNC"]
29
+ require 'set_trace' if Pry::Helpers::BaseHelpers.rbx?
30
+ set_trace_func proc { |event, file, line, id, binding, classname|
31
+ STDERR.printf "%8s %s:%-2d %10s %8s\n", event, file, line, id, classname
32
+ }
33
+ end
34
+
35
+ puts "Ruby v#{RUBY_VERSION} (#{defined?(RUBY_ENGINE) ? RUBY_ENGINE : "ruby"}), Pry v#{Pry::VERSION}, method_source v#{MethodSource::VERSION}, CodeRay v#{CodeRay::VERSION}, Slop v#{Slop::VERSION}"
@@ -0,0 +1,86 @@
1
+ # Colorize output (based on greeneggs (c) 2009 Michael Fleet)
2
+ # TODO: Make own gem (assigned to rking)
3
+ module Bacon
4
+ class Context
5
+ include PryTestHelpers
6
+ end
7
+
8
+ COLORS = {'F' => 31, 'E' => 35, 'M' => 33, '.' => 32}
9
+ USE_COLOR = !(ENV['NO_PRY_COLORED_BACON'] == 'true') && Pry::Helpers::BaseHelpers.use_ansi_codes?
10
+
11
+ module TestUnitOutput
12
+ def handle_requirement(description)
13
+ error = yield
14
+
15
+ if error.empty?
16
+ print colorize_string('.')
17
+ else
18
+ print colorize_string(error[0..0])
19
+ end
20
+ end
21
+
22
+ def handle_summary
23
+ puts
24
+ puts ErrorLog if Backtraces
25
+
26
+ out = "%d tests, %d assertions, %d failures, %d errors" %
27
+ Counter.values_at(:specifications, :requirements, :failed, :errors)
28
+
29
+ if Counter.values_at(:failed, :errors).inject(:+) > 0
30
+ puts colorize_string(out, 'F')
31
+ else
32
+ puts colorize_string(out, '.')
33
+ end
34
+ end
35
+
36
+ def colorize_string(text, color = nil)
37
+ if USE_COLOR
38
+ "\e[#{ COLORS[color || text] }m#{ text }\e[0m"
39
+ else
40
+ text
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ # Reset top-level binding at the beginning of each test case.
47
+ module Bacon
48
+ class Context
49
+ def it_with_reset_binding(description, &block)
50
+ Pry.toplevel_binding = nil
51
+ it_without_reset_binding(description, &block)
52
+ end
53
+ alias it_without_reset_binding it
54
+ alias it it_with_reset_binding
55
+ end
56
+ end
57
+
58
+ # Support mocha
59
+ # mocha-on-bacon (c) Copyright (C) 2011, Eloy Durán <eloy.de.enige@gmail.com>
60
+ module Bacon
61
+ module MochaRequirementsCounter
62
+ def self.increment
63
+ Counter[:requirements] += 1
64
+ end
65
+ end
66
+
67
+ class Context
68
+ include Mocha::API
69
+
70
+ def it_with_mocha(description, &block)
71
+ it_without_mocha(description) do
72
+ begin
73
+ mocha_setup
74
+ block.call
75
+ mocha_verify(MochaRequirementsCounter)
76
+ rescue Mocha::ExpectationError => e
77
+ raise Error.new(:failed, e.message)
78
+ ensure
79
+ mocha_teardown
80
+ end
81
+ end
82
+ end
83
+ alias it_without_mocha it
84
+ alias it it_with_mocha
85
+ end
86
+ end
@@ -0,0 +1,44 @@
1
+ def mock_pry(*args)
2
+ args.flatten!
3
+ binding = args.first.is_a?(Binding) ? args.shift : binding()
4
+ options = args.last.is_a?(Hash) ? args.pop : {}
5
+
6
+ input = InputTester.new(*args)
7
+ output = StringIO.new
8
+
9
+ redirect_pry_io(input, output) do
10
+ binding.pry(options)
11
+ end
12
+
13
+ output.string
14
+ end
15
+
16
+ # Set I/O streams. Out defaults to an anonymous StringIO.
17
+ def redirect_pry_io(new_in, new_out = StringIO.new)
18
+ old_in = Pry.input
19
+ old_out = Pry.output
20
+
21
+ Pry.input = new_in
22
+ Pry.output = new_out
23
+ begin
24
+ yield
25
+ ensure
26
+ Pry.input = old_in
27
+ Pry.output = old_out
28
+ end
29
+ end
30
+
31
+ class InputTester
32
+ def initialize(*actions)
33
+ @orig_actions = actions.dup
34
+ @actions = actions
35
+ end
36
+
37
+ def readline(*)
38
+ @actions.shift
39
+ end
40
+
41
+ def rewind
42
+ @actions = @orig_actions.dup
43
+ end
44
+ end
@@ -0,0 +1,112 @@
1
+ # This is for super-high-level integration testing.
2
+
3
+ require 'thread'
4
+ require 'delegate'
5
+
6
+ class ReplTester
7
+ class Input
8
+ def initialize(tester_mailbox)
9
+ @tester_mailbox = tester_mailbox
10
+ end
11
+
12
+ def readline(prompt)
13
+ @tester_mailbox.push prompt
14
+ mailbox.pop
15
+ end
16
+
17
+ def mailbox
18
+ Thread.current[:mailbox]
19
+ end
20
+ end
21
+
22
+ class Output < SimpleDelegator
23
+ def clear
24
+ __setobj__(StringIO.new)
25
+ end
26
+ end
27
+
28
+ def self.start(options = {}, &block)
29
+ Thread.current[:mailbox] = Queue.new
30
+ instance = nil
31
+ input = Input.new(Thread.current[:mailbox])
32
+ output = Output.new(StringIO.new)
33
+
34
+ redirect_pry_io input, output do
35
+ instance = new(options)
36
+ instance.instance_eval(&block)
37
+ instance.ensure_exit
38
+ end
39
+ ensure
40
+ if instance && instance.thread && instance.thread.alive?
41
+ instance.thread.kill
42
+ end
43
+ end
44
+
45
+ attr_accessor :thread, :mailbox, :last_prompt
46
+
47
+ def initialize(options = {})
48
+ @pry = Pry.new(options)
49
+ @repl = Pry::REPL.new(@pry)
50
+ @mailbox = Thread.current[:mailbox]
51
+
52
+ @thread = Thread.new do
53
+ begin
54
+ Thread.current[:mailbox] = Queue.new
55
+ @repl.start
56
+ ensure
57
+ Thread.current[:session_ended] = true
58
+ mailbox.push nil
59
+ end
60
+ end
61
+
62
+ wait # wait until the instance reaches its first readline
63
+ end
64
+
65
+ # Accept a line of input, as if entered by a user.
66
+ def input(input)
67
+ reset_output
68
+ repl_mailbox.push input
69
+ wait
70
+ Pry.output.string
71
+ end
72
+
73
+ # Assert that the current prompt matches the given string or regex.
74
+ def prompt(match)
75
+ match.should === last_prompt
76
+ end
77
+
78
+ # Assert that the most recent output (since the last time input was called)
79
+ # matches the given string or regex.
80
+ def output(match)
81
+ match.should === Pry.output.string.chomp
82
+ end
83
+
84
+ # Assert that the Pry session ended naturally after the last input.
85
+ def assert_exited
86
+ @should_exit_naturally = true
87
+ end
88
+
89
+ # @private
90
+ def ensure_exit
91
+ if @should_exit_naturally
92
+ @thread[:session_ended].should.be.true
93
+ else
94
+ input "exit-all"
95
+ raise "REPL didn't die" unless @thread[:session_ended]
96
+ end
97
+ end
98
+
99
+ private
100
+
101
+ def reset_output
102
+ Pry.output.clear
103
+ end
104
+
105
+ def repl_mailbox
106
+ @thread[:mailbox]
107
+ end
108
+
109
+ def wait
110
+ @last_prompt = mailbox.pop
111
+ end
112
+ end