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,97 @@
1
+ require 'helper'
2
+
3
+ describe Pry do
4
+ describe 'loading rc files' do
5
+ before do
6
+ Pry::HOME_RC_FILE.replace "spec/fixtures/testrc"
7
+ Pry::LOCAL_RC_FILE.replace "spec/fixtures/testrc/../testrc"
8
+ Pry.instance_variable_set(:@initial_session, true)
9
+ Pry.config.should_load_rc = true
10
+ Pry.config.should_load_local_rc = true
11
+ end
12
+
13
+ after do
14
+ Pry::HOME_RC_FILE.replace "~/.pryrc"
15
+ Pry::LOCAL_RC_FILE.replace "./.pryrc"
16
+ Pry.config.should_load_rc = false
17
+ Object.remove_const(:TEST_RC) if defined?(TEST_RC)
18
+ end
19
+
20
+ it "should never run the rc file twice" do
21
+ Pry.start(self, :input => StringIO.new("exit-all\n"), :output => StringIO.new)
22
+ TEST_RC.should == [0]
23
+
24
+ Pry.start(self, :input => StringIO.new("exit-all\n"), :output => StringIO.new)
25
+ TEST_RC.should == [0]
26
+ end
27
+
28
+ # Resolving symlinks doesn't work on jruby 1.9 [jruby issue #538]
29
+ unless Pry::Helpers::BaseHelpers.jruby_19?
30
+ it "should not load the rc file twice if it's symlinked differently" do
31
+ Pry::HOME_RC_FILE.replace "spec/fixtures/testrc"
32
+ Pry::LOCAL_RC_FILE.replace "spec/fixtures/testlinkrc"
33
+
34
+ Pry.start(self, :input => StringIO.new("exit-all\n"), :output => StringIO.new)
35
+
36
+ TEST_RC.should == [0]
37
+ end
38
+ end
39
+
40
+ it "should not load the pryrc if it cannot expand ENV[HOME]" do
41
+ old_home = ENV['HOME']
42
+ ENV['HOME'] = nil
43
+ Pry.config.should_load_rc = true
44
+ lambda { Pry.start(self, :input => StringIO.new("exit-all\n"), :output => StringIO.new) }.should.not.raise
45
+
46
+ ENV['HOME'] = old_home
47
+ end
48
+
49
+ it "should not run the rc file at all if Pry.config.should_load_rc is false" do
50
+ Pry.config.should_load_rc = false
51
+ Pry.config.should_load_local_rc = false
52
+ Pry.start(self, :input => StringIO.new("exit-all\n"), :output => StringIO.new)
53
+ Object.const_defined?(:TEST_RC).should == false
54
+ end
55
+
56
+ describe "that raise exceptions" do
57
+ before do
58
+ Pry::HOME_RC_FILE = "spec/fixtures/testrcbad"
59
+ Pry.config.should_load_local_rc = false
60
+
61
+ putsed = nil
62
+
63
+ # YUCK! horrible hack to get round the fact that output is not configured
64
+ # at the point this message is printed.
65
+ (class << Pry; self; end).send(:define_method, :puts) { |str|
66
+ putsed = str
67
+ }
68
+
69
+ @doing_it = lambda{
70
+ Pry.start(self, :input => StringIO.new("Object::TEST_AFTER_RAISE=1\nexit-all\n"), :output => StringIO.new)
71
+ putsed
72
+ }
73
+ end
74
+
75
+ after do
76
+ Object.remove_const(:TEST_BEFORE_RAISE)
77
+ Object.remove_const(:TEST_AFTER_RAISE)
78
+ (class << Pry; undef_method :puts; end)
79
+ end
80
+
81
+ it "should not raise exceptions" do
82
+ @doing_it.should.not.raise
83
+ end
84
+
85
+ it "should continue to run pry" do
86
+ @doing_it[]
87
+ Object.const_defined?(:TEST_BEFORE_RAISE).should == true
88
+ Object.const_defined?(:TEST_AFTER_RAISE).should == true
89
+ end
90
+
91
+ it "should output an error" do
92
+ @doing_it.call.split("\n").first.should =~
93
+ %r{Error loading .*spec/fixtures/testrcbad: messin with ya}
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,25 @@
1
+ require 'helper'
2
+
3
+ describe "Pry.run_command" do
4
+ before do
5
+ o = Object.new
6
+ def o.drum
7
+ "roken is dodelijk"
8
+ end
9
+ @context = Pry.binding_for(o)
10
+ end
11
+
12
+ it 'performs a simple ls' do
13
+ @context.eval("hokey_pokey = 10")
14
+ Pry.run_command "ls", :context => @context, :output => out = StringIO.new
15
+ out.string.should =~ /hokey_pokey/
16
+ end
17
+
18
+ if !PryTestHelpers.mri18_and_no_real_source_location?
19
+ # This is a regression test as 0.9.11 broke this behaviour
20
+ it 'can perform a show-source' do
21
+ Pry.run_command "show-source drum", :context => @context, :output => out = StringIO.new
22
+ out.string.should =~ /roken is dodelijk/
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,147 @@
1
+ require 'helper'
2
+
3
+ describe "Sticky locals (_file_ and friends)" do
4
+ it 'locals should all exist upon initialization' do
5
+ proc {
6
+ pry_eval '_file_', '_dir_', '_ex_', '_pry_', '_'
7
+ }.should.not.raise(NameError)
8
+ end
9
+
10
+ it 'locals should still exist after cd-ing into a new context' do
11
+ proc {
12
+ pry_eval 'cd 0', '_file_', '_dir_', '_ex_', '_pry_', '_'
13
+ }.should.not.raise(NameError)
14
+ end
15
+
16
+ it 'locals should keep value after cd-ing (_pry_)' do
17
+ pry_tester.tap do |t|
18
+ pry = t.eval '_pry_'
19
+ t.eval 'cd 0'
20
+ t.eval('_pry_').should == pry
21
+ end
22
+ end
23
+
24
+ # Using mock_pry here until we figure out exception handling
25
+ it 'locals should keep value after cd-ing (_ex_)' do
26
+ mock_pry("error blah;", "$x = _ex_;", "cd 0", "_ex_ == $x").should =~ /true/
27
+ end
28
+
29
+ it 'locals should keep value after cd-ing (_file_ and _dir_)' do
30
+ Pry.commands.command "file-and-dir-test" do
31
+ set_file_and_dir_locals("/blah/ostrich.rb")
32
+ end
33
+
34
+ pry_eval('file-and-dir-test', 'cd 0', '_file_').
35
+ should =~ /\/blah\/ostrich\.rb/
36
+
37
+ pry_eval('file-and-dir-test', 'cd 0', '_dir_').
38
+ should =~ /\/blah/
39
+
40
+ Pry.commands.delete "file-and-dir-test"
41
+ end
42
+
43
+ describe "User defined sticky locals" do
44
+ describe "setting as Pry.config option" do
45
+ it 'should define a new sticky local for the session (normal value)' do
46
+ Pry.config.extra_sticky_locals[:test_local] = :john
47
+
48
+ o = Object.new
49
+ redirect_pry_io(InputTester.new("@value = test_local",
50
+ "exit-all")) do
51
+ Pry.start(o)
52
+ end
53
+
54
+ o.instance_variable_get(:@value).should == :john
55
+ Pry.config.extra_sticky_locals = {}
56
+ end
57
+
58
+ it 'should define a new sticky local for the session (proc)' do
59
+ Pry.config.extra_sticky_locals[:test_local] = proc { :john }
60
+
61
+ o = Object.new
62
+ redirect_pry_io(InputTester.new("@value = test_local",
63
+ "exit-all")) do
64
+ Pry.start(o)
65
+ end
66
+
67
+ o.instance_variable_get(:@value).should == :john
68
+ Pry.config.extra_sticky_locals = {}
69
+ end
70
+
71
+ end
72
+
73
+ describe "passing in as hash option when creating pry instance" do
74
+ it 'should define a new sticky local for the session (normal value)' do
75
+ o = Object.new
76
+ redirect_pry_io(InputTester.new("@value = test_local",
77
+ "exit-all")) do
78
+ Pry.start(o, :extra_sticky_locals => { :test_local => :john } )
79
+ end
80
+
81
+ o.instance_variable_get(:@value).should == :john
82
+ end
83
+
84
+ it 'should define multiple sticky locals' do
85
+ o = Object.new
86
+ redirect_pry_io(InputTester.new("@value1 = test_local1",
87
+ "@value2 = test_local2",
88
+ "exit-all")) do
89
+ Pry.start(o, :extra_sticky_locals => { :test_local1 => :john ,
90
+ :test_local2 => :carl} )
91
+ end
92
+
93
+ o.instance_variable_get(:@value1).should == :john
94
+ o.instance_variable_get(:@value2).should == :carl
95
+ end
96
+
97
+
98
+ it 'should define a new sticky local for the session (as Proc)' do
99
+ o = Object.new
100
+ redirect_pry_io(InputTester.new("@value = test_local",
101
+ "exit-all")) do
102
+ Pry.start(o, :extra_sticky_locals => { :test_local => proc { :john }} )
103
+ end
104
+
105
+ o.instance_variable_get(:@value).should == :john
106
+ end
107
+ end
108
+
109
+ describe "hash option value should override config value" do
110
+ it 'should define a new sticky local for the session (normal value)' do
111
+ Pry.config.extra_sticky_locals[:test_local] = :john
112
+
113
+ o = Object.new
114
+ redirect_pry_io(InputTester.new("@value = test_local",
115
+ "exit-all")) do
116
+ Pry.start(o, :extra_sticky_locals => { :test_local => :carl })
117
+ end
118
+
119
+ o.instance_variable_get(:@value).should == :carl
120
+ Pry.config.extra_sticky_locals = {}
121
+ end
122
+ end
123
+
124
+ it 'should create a new sticky local' do
125
+ t = pry_tester
126
+ t.eval "_pry_.add_sticky_local(:test_local){ :test_value }"
127
+ t.eval("test_local").should == :test_value
128
+ end
129
+
130
+ it 'should still exist after cd-ing into new binding' do
131
+ t = pry_tester
132
+ t.eval "_pry_.add_sticky_local(:test_local){ :test_value }"
133
+ t.eval "cd Object.new"
134
+ t.eval("test_local").should == :test_value
135
+ end
136
+
137
+ it 'should provide different values for successive block invocations' do
138
+ pry = Pry.new
139
+ pry.push_binding binding
140
+ pry.add_sticky_local(:test_local) { rand }
141
+ value1 = pry.evaluate_ruby 'test_local'
142
+ value2 = pry.evaluate_ruby 'test_local'
143
+ value1.should.not == value2
144
+ end
145
+ end
146
+
147
+ end
@@ -0,0 +1,81 @@
1
+ require 'helper'
2
+
3
+ describe Pry do
4
+ before do
5
+ @str_output = StringIO.new
6
+ end
7
+
8
+ [
9
+ ["p = '", "'"],
10
+ ["def", "a", "(); end"],
11
+ ["p = <<FOO", "lots", "and", "lots of", "foo", "FOO"],
12
+ ["[", ":lets,", "'list',", "[/nested/", "], things ]"],
13
+ ["abc =~ /hello", "/"],
14
+ ["issue = %W/", "343/"],
15
+ ["pouts(<<HI, 'foo", "bar", "HI", "baz')"],
16
+ ].each do |foo|
17
+ it "should not raise an error on broken lines: #{foo.join("\\n")}" do
18
+ redirect_pry_io(InputTester.new(*foo), @str_output) do
19
+ Pry.start
20
+ end
21
+
22
+ @str_output.string.should.not =~ /SyntaxError/
23
+ end
24
+ end
25
+
26
+ [
27
+ ["end"],
28
+ ["puts )("],
29
+ ["1 1"],
30
+ ["puts :"]
31
+ ] + (Pry::Helpers::BaseHelpers.rbx? ? [] : [
32
+ ["def", "method(1"], # in this case the syntax error is "expecting ')'".
33
+ ["o = Object.new.tap{ def o.render;","'MEH'", "}"] # in this case the syntax error is "expecting keyword_end".
34
+ ]).compact.each do |foo|
35
+ it "should raise an error on invalid syntax like #{foo.inspect}" do
36
+ redirect_pry_io(InputTester.new(*foo), @str_output) do
37
+ Pry.start
38
+ end
39
+
40
+ @str_output.string.should =~ /SyntaxError/
41
+ end
42
+ end
43
+
44
+ it "should not intefere with syntax errors explicitly raised" do
45
+ redirect_pry_io(InputTester.new(%q{raise SyntaxError, "unexpected $end"}), @str_output) do
46
+ Pry.start
47
+ end
48
+
49
+ @str_output.string.should =~ /SyntaxError/
50
+ end
51
+
52
+ it "should allow trailing , to continue the line" do
53
+ pry = Pry.new
54
+ Pry::Code.complete_expression?("puts 1, 2,").should == false
55
+ end
56
+
57
+ it "should complete an expression that contains a line ending with a ," do
58
+ pry = Pry.new
59
+ Pry::Code.complete_expression?("puts 1, 2,\n3").should == true
60
+ end
61
+
62
+ it "should not suppress the error output if the line ends in ;" do
63
+ mock_pry("raise RuntimeError, 'foo';").should =~ /RuntimeError/
64
+ end
65
+
66
+ it "should not clobber _ex_ on a SyntaxError in the repl" do
67
+ mock_pry("raise RuntimeError, 'foo'", "puts foo)", "_ex_.is_a?(RuntimeError)").should =~ /^RuntimeError.*\nSyntaxError.*\n=> true/m
68
+ end
69
+
70
+ it "should allow whitespace delimeted strings" do
71
+ mock_pry('"%s" %% foo ').should =~ /"foo"/
72
+ end
73
+
74
+ it "should allow newline delimeted strings" do
75
+ mock_pry('"%s" %%','foo').should =~ /"foo"/
76
+ end
77
+
78
+ it "should allow whitespace delimeted strings ending on the first char of a line" do
79
+ mock_pry('"%s" %% ', ' #done!').should =~ /"\\n"/
80
+ end
81
+ end
@@ -0,0 +1,261 @@
1
+ require 'helper'
2
+
3
+ describe Pry::WrappedModule do
4
+
5
+ describe "#initialize" do
6
+ it "should raise an exception when a non-module is passed" do
7
+ lambda{ Pry::WrappedModule.new(nil) }.should.raise ArgumentError
8
+ end
9
+ end
10
+
11
+ describe "candidates" do
12
+ before do
13
+ class Host
14
+ %w(spec/fixtures/candidate_helper1.rb
15
+ spec/fixtures/candidate_helper2.rb).each do |file|
16
+ binding.eval File.read(file), file, 1
17
+ end
18
+
19
+ # rank 2
20
+ class CandidateTest
21
+ def test6
22
+ end
23
+ end
24
+
25
+ class ForeverAlone
26
+ class DoublyNested
27
+ # nested docs
28
+ class TriplyNested
29
+ def nested_method
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ describe "number_of_candidates" do
38
+ it 'should return the correct number of candidates' do
39
+ Pry::WrappedModule(Host::CandidateTest).number_of_candidates.should == 3
40
+ end
41
+
42
+ it 'should return 0 candidates for a class with no methods and no other definitions' do
43
+ Pry::WrappedModule(Host::ForeverAlone).number_of_candidates.should == 0
44
+ end
45
+ end
46
+
47
+ describe "ordering of candidates" do
48
+ it 'should return class with largest number of methods as primary candidate' do
49
+ Pry::WrappedModule(Host::CandidateTest).candidate(0).file.should =~ /helper1/
50
+ end
51
+
52
+ it 'should return class with second largest number of methods as second ranked candidate' do
53
+ Pry::WrappedModule(Host::CandidateTest).candidate(1).file.should =~ /helper2/
54
+ end
55
+
56
+ it 'should return class with third largest number of methods as third ranked candidate' do
57
+ Pry::WrappedModule(Host::CandidateTest).candidate(2).file.should =~ /#{__FILE__}/
58
+ end
59
+
60
+ it 'should raise when trying to access non-existent candidate' do
61
+ lambda { Pry::WrappedModule(Host::CandidateTest).candidate(3) }.should.raise Pry::CommandError
62
+ end
63
+ end
64
+
65
+ describe "source_location" do
66
+ it 'should return primary candidates source_location by default' do
67
+ wm = Pry::WrappedModule(Host::CandidateTest)
68
+ wm.source_location.should == wm.candidate(0).source_location
69
+ end
70
+
71
+ it 'should return nil if no source_location can be found' do
72
+ Pry::WrappedModule(Host::ForeverAlone).source_location.should == nil
73
+ end
74
+ end
75
+
76
+ describe "source" do
77
+ it 'should return primary candidates source by default' do
78
+ wm = Pry::WrappedModule(Host::CandidateTest)
79
+ wm.source.should == wm.candidate(0).source
80
+ end
81
+
82
+ it 'should return source for highest ranked candidate' do
83
+ Pry::WrappedModule(Host::CandidateTest).candidate(0).source.should =~ /test1/
84
+ end
85
+
86
+ it 'should return source for second ranked candidate' do
87
+ Pry::WrappedModule(Host::CandidateTest).candidate(1).source.should =~ /test4/
88
+ end
89
+
90
+ it 'should return source for third ranked candidate' do
91
+ Pry::WrappedModule(Host::CandidateTest).candidate(2).source.should =~ /test6/
92
+ end
93
+
94
+ it 'should return source for deeply nested class' do
95
+ Pry::WrappedModule(Host::ForeverAlone::DoublyNested::TriplyNested).source.should =~ /nested_method/
96
+ Pry::WrappedModule(Host::ForeverAlone::DoublyNested::TriplyNested).source.lines.count.should == 4
97
+ end
98
+ end
99
+
100
+ describe "doc" do
101
+ it 'should return primary candidates doc by default' do
102
+ wm = Pry::WrappedModule(Host::CandidateTest)
103
+ wm.doc.should == wm.candidate(0).doc
104
+ end
105
+
106
+ it 'should return doc for highest ranked candidate' do
107
+ Pry::WrappedModule(Host::CandidateTest).candidate(0).doc.should =~ /rank 0/
108
+ end
109
+
110
+ it 'should return doc for second ranked candidate' do
111
+ Pry::WrappedModule(Host::CandidateTest).candidate(1).doc.should =~ /rank 1/
112
+ end
113
+
114
+ it 'should return doc for third ranked candidate' do
115
+ Pry::WrappedModule(Host::CandidateTest).candidate(2).doc.should =~ /rank 2/
116
+ end
117
+
118
+ it 'should return docs for deeply nested class' do
119
+ Pry::WrappedModule(Host::ForeverAlone::DoublyNested::TriplyNested).doc.should =~ /nested docs/
120
+ end
121
+ end
122
+
123
+ after do
124
+ Object.remove_const(:Host)
125
+ end
126
+ end
127
+
128
+ describe ".method_prefix" do
129
+ before do
130
+ Foo = Class.new
131
+ @foo = Foo.new
132
+ end
133
+
134
+ after do
135
+ Object.remove_const(:Foo)
136
+ end
137
+
138
+ it "should return Foo# for normal classes" do
139
+ Pry::WrappedModule.new(Foo).method_prefix.should == "Foo#"
140
+ end
141
+
142
+ it "should return Bar# for modules" do
143
+ Pry::WrappedModule.new(Kernel).method_prefix.should == "Kernel#"
144
+ end
145
+
146
+ it "should return Foo. for singleton classes of classes" do
147
+ Pry::WrappedModule.new(class << Foo; self; end).method_prefix.should == "Foo."
148
+ end
149
+
150
+ describe "of singleton classes of objects" do
151
+ Pry::WrappedModule.new(class << @foo; self; end).method_prefix.should == "self."
152
+ end
153
+
154
+ describe "of anonymous classes should not be empty" do
155
+ Pry::WrappedModule.new(Class.new).method_prefix.should =~ /#<Class:.*>#/
156
+ end
157
+
158
+ describe "of singleton classes of anonymous classes should not be empty" do
159
+ Pry::WrappedModule.new(class << Class.new; self; end).method_prefix.should =~ /#<Class:.*>./
160
+ end
161
+ end
162
+
163
+ describe ".singleton_class?" do
164
+ it "should be true for singleton classes" do
165
+ Pry::WrappedModule.new(class << ""; self; end).singleton_class?.should == true
166
+ end
167
+
168
+ it "should be false for normal classes" do
169
+ Pry::WrappedModule.new(Class.new).singleton_class?.should == false
170
+ end
171
+
172
+ it "should be false for modules" do
173
+ Pry::WrappedModule.new(Module.new).singleton_class?.should == false
174
+ end
175
+ end
176
+
177
+ describe ".singleton_instance" do
178
+ it "should raise an exception when called on a non-singleton-class" do
179
+ lambda{ Pry::WrappedModule.new(Class).singleton_instance }.should.raise ArgumentError
180
+ end
181
+
182
+ it "should return the attached object" do
183
+ Pry::WrappedModule.new(class << "hi"; self; end).singleton_instance.should == "hi"
184
+ Pry::WrappedModule.new(class << Object; self; end).singleton_instance.should.equal?(Object)
185
+ end
186
+ end
187
+
188
+ describe ".super" do
189
+ describe "receiver is a class" do
190
+ before do
191
+ @a = Class.new
192
+ @m = Module.new
193
+ @b = Class.new(@a)
194
+ @b.send(:include, @m)
195
+ @c = Class.new(@b)
196
+ end
197
+
198
+ it 'should return superclass for a wrapped class' do
199
+ Pry::WrappedModule(@c).super.wrapped.should == @b
200
+ end
201
+
202
+ it 'should return nth superclass for a wrapped class' do
203
+ d = Class.new(@c)
204
+ Pry::WrappedModule(d).super(2).wrapped.should == @b
205
+ end
206
+
207
+ it 'should ignore modules when retrieving nth superclass' do
208
+ Pry::WrappedModule(@c).super(2).wrapped.should == @a
209
+ end
210
+
211
+ it 'should return nil when no nth superclass exists' do
212
+ Pry::WrappedModule(@c).super(10).should == nil
213
+ end
214
+
215
+ it 'should return self when .super(0) is used' do
216
+ c = Pry::WrappedModule(@c)
217
+ c.super(0).should == c
218
+ end
219
+ end
220
+
221
+ describe "receiver is a module" do
222
+ before do
223
+ @m1 = Module.new
224
+ @m2 = Module.new.tap { |v| v.send(:include, @m1) }
225
+ @m3 = Module.new.tap { |v| v.send(:include, @m2) }
226
+ end
227
+
228
+ it 'should not ignore modules when retrieving supers' do
229
+ Pry::WrappedModule(@m3).super.wrapped.should == @m2
230
+ end
231
+
232
+ it 'should retrieve nth super' do
233
+ Pry::WrappedModule(@m3).super(2).wrapped.should == @m1
234
+ end
235
+
236
+ it 'should return self when .super(0) is used' do
237
+ m = Pry::WrappedModule(@m1)
238
+ m.super(0).should == m
239
+ end
240
+ end
241
+ end
242
+
243
+ describe ".from_str" do
244
+ it 'should lookup a constant' do
245
+ m = Pry::WrappedModule.from_str("Host::CandidateTest", binding)
246
+ m.wrapped.should == Host::CandidateTest
247
+ end
248
+
249
+ it 'should lookup a local' do
250
+ local = Host::CandidateTest
251
+ m = Pry::WrappedModule.from_str("local", binding)
252
+ m.wrapped.should == Host::CandidateTest
253
+ end
254
+
255
+ it 'should lookup an ivar' do
256
+ @ivar = Host::CandidateTest
257
+ m = Pry::WrappedModule.from_str("@ivar", binding)
258
+ m.wrapped.should == Host::CandidateTest
259
+ end
260
+ end
261
+ end