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,277 @@
1
+ require 'helper'
2
+
3
+ describe Pry::CodeObject do
4
+ describe "basic lookups" do
5
+ before do
6
+ @obj = Object.new
7
+ def @obj.ziggy
8
+ "a flight of scarlet pigeons thunders round my thoughts"
9
+ end
10
+
11
+ class ClassyWassy
12
+ def piggy
13
+ binding
14
+ end
15
+ end
16
+
17
+ @p = Pry.new
18
+ @p.binding_stack = [binding]
19
+ end
20
+
21
+ after do
22
+ Object.remove_const(:ClassyWassy)
23
+ end
24
+
25
+ it 'should lookup methods' do
26
+ m = Pry::CodeObject.lookup("@obj.ziggy", @p)
27
+ m.is_a?(Pry::Method).should == true
28
+ m.name.to_sym.should == :ziggy
29
+ end
30
+
31
+ it 'should lookup modules' do
32
+ m = Pry::CodeObject.lookup("ClassyWassy", @p)
33
+ m.is_a?(Pry::WrappedModule).should == true
34
+ m.source.should =~ /piggy/
35
+ end
36
+
37
+ it 'should lookup procs' do
38
+ my_proc = proc { :hello }
39
+ @p.binding_stack = [binding]
40
+ m = Pry::CodeObject.lookup("my_proc", @p)
41
+ m.is_a?(Pry::Method).should == true
42
+ m.source.should =~ /hello/
43
+ end
44
+
45
+ describe 'commands lookup' do
46
+ before do
47
+ @p = Pry.new
48
+ @p.binding_stack = [binding]
49
+ end
50
+
51
+ it 'should return command class' do
52
+ @p.commands.command "jeremy-jones" do
53
+ "lobster"
54
+ end
55
+ m = Pry::CodeObject.lookup("jeremy-jones", @p)
56
+ (m <= Pry::Command).should == true
57
+ m.source.should =~ /lobster/
58
+ end
59
+
60
+ describe "class commands" do
61
+ before do
62
+ class LobsterLady < Pry::ClassCommand
63
+ match "lobster-lady"
64
+ description "nada."
65
+ def process
66
+ "lobster"
67
+ end
68
+ end
69
+ end
70
+
71
+ after do
72
+ Object.remove_const(:LobsterLady)
73
+ end
74
+
75
+ it 'should return Pry::ClassCommand class when looking up class command' do
76
+ Pry.commands.add_command(LobsterLady)
77
+ m = Pry::CodeObject.lookup("lobster-lady", @p)
78
+ (m <= Pry::ClassCommand).should == true
79
+ m.source.should =~ /class LobsterLady/
80
+ Pry.commands.delete("lobster-lady")
81
+ end
82
+
83
+ it 'should return Pry::WrappedModule when looking up command class directly (as a class, not as a command)' do
84
+ Pry.commands.add_command(LobsterLady)
85
+ m = Pry::CodeObject.lookup("LobsterLady", @p)
86
+ m.is_a?(Pry::WrappedModule).should == true
87
+ m.source.should =~ /class LobsterLady/
88
+ Pry.commands.delete("lobster-lady")
89
+ end
90
+ end
91
+
92
+ it 'looks up commands by :listing name as well' do
93
+ @p.commands.command /jeremy-.*/, "", :listing => "jeremy-baby" do
94
+ "lobster"
95
+ end
96
+ m = Pry::CodeObject.lookup("jeremy-baby", @p)
97
+ (m <= Pry::Command).should == true
98
+ m.source.should =~ /lobster/
99
+ end
100
+
101
+ it 'finds nothing when passing nil as the first argument' do
102
+ Pry::CodeObject.lookup(nil, @p).should == nil
103
+ end
104
+
105
+ end
106
+
107
+ it 'should lookup instance methods defined on classes accessed via local variable' do
108
+ o = Class.new do
109
+ def princess_bubblegum
110
+ "mathematic!"
111
+ end
112
+ end
113
+
114
+ @p.binding_stack = [binding]
115
+ m = Pry::CodeObject.lookup("o#princess_bubblegum", @p)
116
+ m.is_a?(Pry::Method).should == true
117
+ m.source.should =~ /mathematic!/
118
+ end
119
+
120
+ it 'should lookup class methods defined on classes accessed via local variable' do
121
+ o = Class.new do
122
+ def self.finn
123
+ "4 realzies"
124
+ end
125
+ end
126
+ @p.binding_stack = [binding]
127
+ m = Pry::CodeObject.lookup("o.finn", @p)
128
+ m.is_a?(Pry::Method).should == true
129
+ m.source.should =~ /4 realzies/
130
+ end
131
+
132
+ it 'should lookup the class of an object (when given a variable)' do
133
+ moddy = ClassyWassy.new
134
+ @p.binding_stack = [binding]
135
+ m = Pry::CodeObject.lookup("moddy", @p)
136
+ m.is_a?(Pry::WrappedModule).should == true
137
+ m.source.should =~ /piggy/
138
+ end
139
+
140
+ describe "inferring object from binding when lookup str is empty/nil" do
141
+ before do
142
+ @b1 = Pry.binding_for(ClassyWassy)
143
+ @b2 = Pry.binding_for(ClassyWassy.new)
144
+ end
145
+
146
+ describe "infer module objects" do
147
+ it 'should infer module object when binding self is a module' do
148
+ ["", nil].each do |v|
149
+ @p.binding_stack = [@b1]
150
+ m = Pry::CodeObject.lookup(v, @p)
151
+ m.is_a?(Pry::WrappedModule).should == true
152
+ m.name.should =~ /ClassyWassy/
153
+ end
154
+ end
155
+
156
+ it 'should infer module object when binding self is an instance' do
157
+ ["", nil].each do |v|
158
+ @p.binding_stack = [@b2]
159
+ m = Pry::CodeObject.lookup(v, @p)
160
+ m.is_a?(Pry::WrappedModule).should == true
161
+ m.name.should =~ /ClassyWassy/
162
+ end
163
+ end
164
+ end
165
+
166
+ describe "infer method objects" do
167
+ it 'should infer method object from binding when inside method context' do
168
+ b = ClassyWassy.new.piggy
169
+
170
+ ["", nil].each do |v|
171
+ @p.binding_stack = [b]
172
+ m = Pry::CodeObject.lookup(v, @p)
173
+ m.is_a?(Pry::Method).should == true
174
+ m.name.should =~ /piggy/
175
+ end
176
+ end
177
+ end
178
+ end
179
+ end
180
+
181
+ describe "lookups with :super" do
182
+ before do
183
+ class MyClassyWassy; end
184
+ class CuteSubclass < MyClassyWassy; end
185
+ @p = Pry.new
186
+ @p.binding_stack = [binding]
187
+ end
188
+
189
+ after do
190
+ Object.remove_const(:MyClassyWassy)
191
+ Object.remove_const(:CuteSubclass)
192
+ end
193
+
194
+ it 'should lookup original class with :super => 0' do
195
+ m = Pry::CodeObject.lookup("CuteSubclass", @p, :super => 0)
196
+ m.is_a?(Pry::WrappedModule).should == true
197
+ m.wrapped.should == CuteSubclass
198
+ end
199
+
200
+ it 'should lookup immediate super class with :super => 1' do
201
+ m = Pry::CodeObject.lookup("CuteSubclass", @p, :super => 1)
202
+ m.is_a?(Pry::WrappedModule).should == true
203
+ m.wrapped.should == MyClassyWassy
204
+ end
205
+
206
+ it 'should ignore :super parameter for commands' do
207
+ p = Pry.new
208
+ p.commands.command "jeremy-jones" do
209
+ "lobster"
210
+ end
211
+ p.binding_stack = [binding]
212
+ m = Pry::CodeObject.lookup("jeremy-jones", p, :super => 10)
213
+ m.source.should =~ /lobster/
214
+ end
215
+ end
216
+
217
+ describe "precedence" do
218
+ before do
219
+ class ClassyWassy
220
+ class Puff
221
+ def tiggy
222
+ end
223
+ end
224
+
225
+ def Puff
226
+ end
227
+
228
+ def piggy
229
+ end
230
+ end
231
+
232
+ Object.class_eval do
233
+ def ClassyWassy
234
+ :ducky
235
+ end
236
+ end
237
+
238
+ @p = Pry.new
239
+ @p.binding_stack = [binding]
240
+ end
241
+
242
+ after do
243
+ Object.remove_const(:ClassyWassy)
244
+ Object.remove_method(:ClassyWassy)
245
+ end
246
+
247
+ it 'should look up methods before classes (at top-level)' do
248
+ m = Pry::CodeObject.lookup("ClassyWassy", @p)
249
+ m.is_a?(Pry::Method).should == true
250
+ m.source.should =~ /ducky/
251
+ end
252
+
253
+ it 'should look up classes before methods when namespaced' do
254
+ m = Pry::CodeObject.lookup("ClassyWassy::Puff", @p)
255
+ m.is_a?(Pry::WrappedModule).should == true
256
+ m.source.should =~ /tiggy/
257
+ end
258
+
259
+ it 'should look up locals before methods' do
260
+ b = Pry.binding_for(ClassyWassy)
261
+ b.eval("piggy = Puff.new")
262
+ @p.binding_stack = [b]
263
+ o = Pry::CodeObject.lookup("piggy", @p)
264
+ o.is_a?(Pry::WrappedModule).should == true
265
+ end
266
+
267
+ # actually locals are never looked up (via co.default_lookup) when they're classes, it
268
+ # just falls through to co.method_or_class
269
+ it 'should look up classes before locals' do
270
+ c = ClassyWassy
271
+ @p.binding_stack = [binding]
272
+ o = Pry::CodeObject.lookup("c", @p)
273
+ o.is_a?(Pry::WrappedModule).should == true
274
+ o.wrapped.should == ClassyWassy
275
+ end
276
+ end
277
+ end
@@ -0,0 +1,219 @@
1
+ require 'helper'
2
+
3
+ describe Pry::Code do
4
+ describe '.from_file' do
5
+ should 'read lines from a file on disk' do
6
+ Pry::Code.from_file('lib/pry.rb').length.should > 0
7
+ end
8
+
9
+ should 'read lines from Pry\'s line buffer' do
10
+ pry_eval ':hay_guys'
11
+ Pry::Code.from_file('(pry)').grep(/:hay_guys/).length.should == 1
12
+ end
13
+
14
+ should 'default to Ruby' do
15
+ temp_file('') do |f|
16
+ Pry::Code.from_file(f.path).code_type.should == :ruby
17
+ end
18
+ end
19
+
20
+ should 'check the extension' do
21
+ temp_file('.c') do |f|
22
+ Pry::Code.from_file(f.path).code_type.should == :c
23
+ end
24
+ end
25
+
26
+ should 'use the provided extension' do
27
+ temp_file('.c') do |f|
28
+ Pry::Code.from_file(f.path, :ruby).code_type.should == :ruby
29
+ end
30
+ end
31
+
32
+ should 'raise an error if the file doesn\'t exist' do
33
+ proc do
34
+ Pry::Code.from_file('/knalkjsdnalsd/alkjdlkq')
35
+ end.should.raise(MethodSource::SourceNotFoundError)
36
+ end
37
+
38
+ should 'check for files relative to origin pwd' do
39
+ Dir.chdir('spec') do |f|
40
+ Pry::Code.from_file('spec/' + File.basename(__FILE__)).code_type.should == :ruby
41
+ end
42
+ end
43
+
44
+ should 'find files that are relative to the current working directory' do
45
+ Dir.chdir('spec') do |f|
46
+ Pry::Code.from_file(File.basename(__FILE__)).code_type.should == :ruby
47
+ end
48
+ end
49
+ end
50
+
51
+ describe '.from_method' do
52
+ should 'read lines from a method\'s definition' do
53
+ m = Pry::Method.from_obj(Pry, :load_history)
54
+ Pry::Code.from_method(m).length.should > 0
55
+ end
56
+ end
57
+
58
+ describe '#initialize' do
59
+ before do
60
+ @str = Pry::Helpers::CommandHelpers.unindent <<-CODE
61
+ def hay
62
+ :guys
63
+ end
64
+ CODE
65
+
66
+ @array = ['def hay', ' :guys', 'end']
67
+ end
68
+
69
+ should 'break a string into lines' do
70
+ Pry::Code.new(@str).length.should == 3
71
+ end
72
+
73
+ should 'accept an array' do
74
+ Pry::Code.new(@array).length.should == 3
75
+ end
76
+
77
+ it 'an array or string should produce an equivalent object' do
78
+ Pry::Code.new(@str).should == Pry::Code.new(@array)
79
+ end
80
+ end
81
+
82
+ describe 'filters and formatters' do
83
+ before do
84
+ @code = Pry::Code(Pry::Helpers::CommandHelpers.unindent <<-STR)
85
+ class MyProgram
86
+ def self.main
87
+ puts 'Hello, world!'
88
+ end
89
+ end
90
+ STR
91
+ end
92
+
93
+ describe 'filters' do
94
+ describe '#between' do
95
+ should 'work with an inclusive range' do
96
+ @code = @code.between(1..3)
97
+ @code.length.should == 3
98
+ @code.should =~ /\Aclass MyProgram/
99
+ @code.should =~ /world!'\Z/
100
+ end
101
+
102
+ should 'default to an inclusive range' do
103
+ @code = @code.between(3, 5)
104
+ @code.length.should == 3
105
+ end
106
+
107
+ should 'work with an exclusive range' do
108
+ @code = @code.between(2...4)
109
+ @code.length.should == 2
110
+ @code.should =~ /\A def self/
111
+ @code.should =~ /world!'\Z/
112
+ end
113
+
114
+ should 'use real line numbers for positive indices' do
115
+ @code = @code.after(3, 3)
116
+ @code = @code.between(4, 4)
117
+ @code.length.should == 1
118
+ @code.should =~ /\A end\Z/
119
+ end
120
+ end
121
+
122
+ describe '#before' do
123
+ should 'work' do
124
+ @code = @code.before(3, 1)
125
+ @code.should =~ /\A def self\.main\Z/
126
+ end
127
+ end
128
+
129
+ describe '#around' do
130
+ should 'work' do
131
+ @code = @code.around(3, 1)
132
+ @code.length.should == 3
133
+ @code.should =~ /\A def self/
134
+ @code.should =~ / end\Z/
135
+ end
136
+ end
137
+
138
+ describe '#after' do
139
+ should 'work' do
140
+ @code = @code.after(3, 1)
141
+ @code.should =~ /\A end\Z/
142
+ end
143
+ end
144
+
145
+ describe '#grep' do
146
+ should 'work' do
147
+ @code = @code.grep(/end/)
148
+ @code.length.should == 2
149
+ end
150
+ end
151
+ end
152
+
153
+ describe 'formatters' do
154
+ describe '#with_line_numbers' do
155
+ should 'show line numbers' do
156
+ @code = @code.with_line_numbers
157
+ @code.should =~ /1:/
158
+ end
159
+
160
+ should 'disable line numbers when falsy' do
161
+ @code = @code.with_line_numbers
162
+ @code = @code.with_line_numbers(false)
163
+ @code.should.not =~ /1:/
164
+ end
165
+ end
166
+
167
+ describe '#with_marker' do
168
+ should 'show a marker in the right place' do
169
+ @code = @code.with_marker(2)
170
+ @code.should =~ /^ => def self/
171
+ end
172
+
173
+ should 'disable the marker when falsy' do
174
+ @code = @code.with_marker(2)
175
+ @code = @code.with_marker(false)
176
+ @code.should =~ /^ def self/
177
+ end
178
+ end
179
+
180
+ describe '#with_indentation' do
181
+ should 'indent the text' do
182
+ @code = @code.with_indentation(2)
183
+ @code.should =~ /^ def self/
184
+ end
185
+
186
+ should 'disable the indentation when falsy' do
187
+ @code = @code.with_indentation(2)
188
+ @code = @code.with_indentation(false)
189
+ @code.should =~ /^ def self/
190
+ end
191
+ end
192
+ end
193
+
194
+ describe 'composition' do
195
+ describe 'grep and with_line_numbers' do
196
+ should 'work' do
197
+ @code = @code.grep(/end/).with_line_numbers
198
+ @code.should =~ /\A4: end/
199
+ @code.should =~ /5: end\Z/
200
+ end
201
+ end
202
+
203
+ describe 'grep and before and with_line_numbers' do
204
+ should 'work' do
205
+ @code = @code.grep(/e/).before(5, 5).with_line_numbers
206
+ @code.should =~ /\A2: def self.main\n3:/
207
+ @code.should =~ /4: end\Z/
208
+ end
209
+ end
210
+
211
+ describe 'before and after' do
212
+ should 'work' do
213
+ @code = @code.before(4, 2).after(2)
214
+ @code.should == " puts 'Hello, world!'"
215
+ end
216
+ end
217
+ end
218
+ end
219
+ end