pry 0.9.12.6-java → 0.10.0-java

Sign up to get free protection for your applications and to get access to all the features.
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,25 +0,0 @@
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
@@ -1,157 +0,0 @@
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
- o = Object.new
126
- pi = Pry.new
127
- pi.add_sticky_local(:test_local) { :test_value }
128
- pi.input, pi.output = InputTester.new("@value = test_local", "exit-all"), StringIO.new
129
- pi.repl(o)
130
-
131
- o.instance_variable_get(:@value).should == :test_value
132
- end
133
-
134
- it 'should still exist after cd-ing into new binding' do
135
- o = Object.new
136
- o2 = Object.new
137
- o.instance_variable_set(:@o2, o2)
138
- pi = Pry.new
139
- pi.add_sticky_local(:test_local) { :test_value }
140
- pi.input = InputTester.new("cd @o2\n",
141
- "@value = test_local", "exit-all")
142
- pi.output = StringIO.new
143
- pi.repl(o)
144
-
145
- o2.instance_variable_get(:@value).should == :test_value
146
- end
147
-
148
- it 'should provide different values for successive block invocations' do
149
- pry = Pry.new
150
- pry.add_sticky_local(:test_local) { rand }
151
- value1 = pry.evaluate_ruby 'test_local'
152
- value2 = pry.evaluate_ruby 'test_local'
153
- value1.should.not == value2
154
- end
155
- end
156
-
157
- end
@@ -1,81 +0,0 @@
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
@@ -1,261 +0,0 @@
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