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

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,27 @@
1
+ require 'helper'
2
+
3
+ describe "exit-all" do
4
+ before { @pry = Pry.new }
5
+
6
+ it "should break out of the repl and return nil" do
7
+ @pry.eval("exit-all").should.be.false
8
+ @pry.exit_value.should.be.nil
9
+ end
10
+
11
+ it "should break out of the repl wth a user specified value" do
12
+ @pry.eval("exit-all 'message'").should.be.false
13
+ @pry.exit_value.should == "message"
14
+ end
15
+
16
+ it "should break out of the repl even if multiple bindings still on stack" do
17
+ ["cd 1", "cd 2"].each { |line| @pry.eval(line).should.be.true }
18
+ @pry.eval("exit-all 'message'").should.be.false
19
+ @pry.exit_value.should == "message"
20
+ end
21
+
22
+ it "should have empty binding_stack after breaking out of the repl" do
23
+ ["cd 1", "cd 2"].each { |line| @pry.eval(line).should.be.true }
24
+ @pry.eval("exit-all").should.be.false
25
+ @pry.binding_stack.should.be.empty
26
+ end
27
+ end
@@ -0,0 +1,19 @@
1
+ require 'helper'
2
+
3
+ describe "exit-program" do
4
+ it 'should raise SystemExit' do
5
+ proc {
6
+ pry_eval('exit-program')
7
+ }.should.raise SystemExit
8
+ end
9
+
10
+ it 'should exit the program with the provided value' do
11
+ begin
12
+ pry_eval 'exit-program 66'
13
+ rescue SystemExit => e
14
+ e.status.should == 66
15
+ else
16
+ raise "Failed to raise SystemExit"
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,28 @@
1
+ require 'helper'
2
+
3
+ describe "exit" do
4
+ before { @pry = Pry.new(:target => :outer, :output => StringIO.new) }
5
+
6
+ it "should pop a binding" do
7
+ @pry.eval "cd :inner"
8
+ @pry.evaluate_ruby("self").should == :inner
9
+ @pry.eval "exit"
10
+ @pry.evaluate_ruby("self").should == :outer
11
+ end
12
+
13
+ it "should break out of the repl when binding_stack has only one binding" do
14
+ @pry.eval("exit").should.be.false
15
+ @pry.exit_value.should.be.nil
16
+ end
17
+
18
+ it "should break out of the repl and return user-given value" do
19
+ @pry.eval("exit :john").should.be.false
20
+ @pry.exit_value.should == :john
21
+ end
22
+
23
+ it "should break out of the repl even after an exception" do
24
+ @pry.eval "exit = 42"
25
+ @pry.output.string.should =~ /^SyntaxError/
26
+ @pry.eval("exit").should.be.false
27
+ end
28
+ end
@@ -0,0 +1,70 @@
1
+ require 'helper'
2
+
3
+ # we turn off the test for MRI 1.8 because our source_location hack
4
+ # for C methods actually runs the methods - and since it runs ALL
5
+ # methods (in an attempt to find a match) it runs 'exit' and aborts
6
+ # the test, causing a failure. We should fix this in the future by
7
+ # blacklisting certain methods for 1.8 MRI (such as exit, fork, and so on)
8
+ unless Pry::Helpers::BaseHelpers.mri_18?
9
+ MyKlass = Class.new do
10
+ def hello
11
+ "timothy"
12
+ end
13
+ def goodbye
14
+ "jenny"
15
+ end
16
+ def tea_tim?
17
+ "timothy"
18
+ end
19
+ def tea_time?
20
+ "polly"
21
+ end
22
+ end
23
+
24
+ describe "find-method" do
25
+ describe "find matching methods by name regex (-n option)" do
26
+ it "should find a method by regex" do
27
+ pry_eval("find-method hell MyKlass").should =~
28
+ /MyKlass.*?hello/m
29
+ end
30
+
31
+ it "should NOT match a method that does not match the regex" do
32
+ pry_eval("find-method hell MyKlass").should.not =~
33
+ /MyKlass.*?goodbye/m
34
+ end
35
+ end
36
+
37
+ describe "find matching methods by content regex (-c option)" do
38
+ it "should find a method by regex" do
39
+ pry_eval("find-method -c timothy MyKlass").should =~
40
+ /MyKlass.*?hello/m
41
+ end
42
+
43
+ it "should NOT match a method that does not match the regex" do
44
+ pry_eval("find-method timothy MyKlass").should.not =~
45
+ /MyKlass.*?goodbye/m
46
+ end
47
+ end
48
+
49
+ it "should work with badly behaved constants" do
50
+ MyKlass::X = Object.new
51
+ def (MyKlass::X).hash
52
+ raise "mooo"
53
+ end
54
+
55
+ pry_eval("find-method -c timothy MyKlass").should =~
56
+ /MyKlass.*?hello/m
57
+ end
58
+
59
+ it "should escape regexes correctly" do
60
+ good = /tea_time\?/
61
+ bad = /tea_tim\?/
62
+ pry_eval('find-method tea_time? MyKlass').should =~ good
63
+ pry_eval('find-method tea_time? MyKlass').should =~ good
64
+ pry_eval('find-method tea_time\? MyKlass').should.not =~ bad
65
+ pry_eval('find-method tea_time\? MyKlass').should =~ good
66
+ end
67
+ end
68
+
69
+ Object.remove_const(:MyKlass)
70
+ end
@@ -0,0 +1,26 @@
1
+ require 'helper'
2
+
3
+ describe "gem-list" do
4
+ # fixing bug for 1.8 compat
5
+ it 'should not raise when invoked' do
6
+ proc {
7
+ pry_eval(self, 'gem-list')
8
+ }.should.not.raise
9
+ end
10
+
11
+ it 'should work arglessly' do
12
+ list = pry_eval('gem-list')
13
+ list.should =~ /slop \(/
14
+ list.should =~ /bacon \(/
15
+ end
16
+
17
+ it 'should find arg' do
18
+ prylist = pry_eval('gem-list slop')
19
+ prylist.should =~ /slop \(/
20
+ prylist.should.not =~ /bacon/
21
+ end
22
+
23
+ it 'should return non-results as silence' do
24
+ pry_eval('gem-list aoeuoueouaou').should.empty?
25
+ end
26
+ end
@@ -0,0 +1,79 @@
1
+ # These tests are out of date.
2
+ # THey need to be updated for the new 'gist' API, but im too sleepy to
3
+ # do that now.
4
+
5
+ require 'helper'
6
+
7
+ describe 'gist' do
8
+ it 'has a dependency on the jist gem' do
9
+ Pry::Command::Gist.command_options[:requires_gem].should == "jist"
10
+ end
11
+ end
12
+
13
+ # before do
14
+ # Pad.jist_calls = {}
15
+ # end
16
+
17
+ # # In absence of normal mocking, just monkeysmash these with no undoing after.
18
+ # module Jist
19
+ # class << self
20
+ # def login!; Pad.jist_calls[:login!] = true end
21
+ # def gist(*args)
22
+ # Pad.jist_calls[:gist_args] = args
23
+ # {'html_url' => 'http://gist.blahblah'}
24
+ # end
25
+ # def copy(content); Pad.jist_calls[:copy_args] = content end
26
+ # end
27
+ # end
28
+
29
+ # module Pry::Gist
30
+ # # a) The actual require fails for jruby for some odd reason.
31
+ # # b) 100% of jist should be stubbed by the above, so this ensures that.
32
+ # def self.require_jist; 'nope' end
33
+ # end
34
+
35
+ # it 'nominally logs in' do
36
+ # pry_eval 'gist --login'
37
+ # Pad.jist_calls[:login!].should.not.be.nil
38
+ # end
39
+
40
+ # EXAMPLE_REPL_METHOD = <<-EOT
41
+ # # docdoc
42
+ # def my_method
43
+ # # line 1
44
+ # 'line 2'
45
+ # line 3
46
+ # Line.four
47
+ # end
48
+ # EOT
49
+
50
+ # RANDOM_COUPLE_OF_LINES = %w(a=1 b=2)
51
+ # run_case = proc do |sym|
52
+ # actual_command = Pry::Gist.example_code(sym)
53
+ # pry_eval EXAMPLE_REPL_METHOD, RANDOM_COUPLE_OF_LINES, actual_command
54
+ # end
55
+
56
+ # it 'deduces filenames' do
57
+ # Pry::Gist::INVOCATIONS.keys.each do |e|
58
+ # run_case.call(e)
59
+ # if Pad.jist_calls[:gist_args]
60
+ # text, args = Pad.jist_calls[:gist_args]
61
+ # args[:filename].should.not == '(pry)'
62
+ # end
63
+ # Pad.jist_calls[:copy_args].should.not.be.nil
64
+ # end
65
+ # end
66
+
67
+ # it 'equates aliae' do
68
+ # run_case.call(:clipit).should == run_case.call(:cliponly)
69
+ # run_case.call(:jist).should == run_case.call(:class)
70
+ # end
71
+
72
+ # it 'has a reasonable --help' do
73
+ # help = pry_eval('gist --help')
74
+ # Pry::Gist::INVOCATIONS.keys.each do |e|
75
+ # help.should.include? Pry::Gist.example_code(e)
76
+ # help.should.include? Pry::Gist.example_description(e)
77
+ # end
78
+ # end
79
+ # end
@@ -0,0 +1,56 @@
1
+ require 'helper'
2
+
3
+ describe "help" do
4
+ before do
5
+ @oldset = Pry.config.commands
6
+ @set = Pry.config.commands = Pry::CommandSet.new do
7
+ import Pry::Commands
8
+ end
9
+ end
10
+
11
+ after do
12
+ Pry.config.commands = @oldset
13
+ end
14
+
15
+ it 'should display help for a specific command' do
16
+ pry_eval('help ls').should =~ /Usage: ls/
17
+ end
18
+
19
+ it 'should display help for a regex command with a "listing"' do
20
+ @set.command /bar(.*)/, "Test listing", :listing => "foo" do; end
21
+ pry_eval('help foo').should =~ /Test listing/
22
+ end
23
+
24
+ it 'should display help for a command with a spaces in its name' do
25
+ @set.command "cmd with spaces", "desc of a cmd with spaces" do; end
26
+ pry_eval('help "cmd with spaces"').should =~ /desc of a cmd with spaces/
27
+ end
28
+
29
+ it 'should display help for all commands with a description' do
30
+ @set.command /bar(.*)/, "Test listing", :listing => "foo" do; end
31
+ @set.command "b", "description for b", :listing => "foo" do; end
32
+ @set.command "c" do;end
33
+ @set.command "d", "" do;end
34
+
35
+ output = pry_eval('help')
36
+ output.should =~ /Test listing/
37
+ output.should =~ /description for b/
38
+ output.should =~ /No description/
39
+ end
40
+
41
+ it "should sort the output of the 'help' command" do
42
+ @set.command 'faa', "Fooerizes" do; end
43
+ @set.command 'gaa', "Gooerizes" do; end
44
+ @set.command 'maa', "Mooerizes" do; end
45
+ @set.command 'baa', "Booerizes" do; end
46
+
47
+ doc = pry_eval('help')
48
+
49
+ order = [doc.index("baa"),
50
+ doc.index("faa"),
51
+ doc.index("gaa"),
52
+ doc.index("maa")]
53
+
54
+ order.should == order.sort
55
+ end
56
+ end
@@ -0,0 +1,172 @@
1
+ require 'helper'
2
+
3
+ describe "hist" do
4
+ before do
5
+ Pry.history.clear
6
+ @hist = Pry.history
7
+
8
+ @str_output = StringIO.new
9
+ @t = pry_tester :history => @hist do
10
+ # For looking at what hist pushes into the input stack. The
11
+ # implementation of this helper will definitely have to change at some
12
+ # point.
13
+ def next_input
14
+ @pry.input.string
15
+ end
16
+ end
17
+ end
18
+
19
+ it 'should display the correct history' do
20
+ @hist.push "hello"
21
+ @hist.push "world"
22
+
23
+ @t.eval('hist').should =~ /hello\n.*world/
24
+ end
25
+
26
+ it 'should replay history correctly (single item)' do
27
+ o = Object.new
28
+ @hist.push "@x = 10"
29
+ @hist.push "@y = 20"
30
+ @hist.push "@z = 30"
31
+
32
+ @t.push_binding o
33
+ @t.eval 'hist --replay -1'
34
+
35
+ o.instance_variable_get(:@z).should == 30
36
+ end
37
+
38
+ it 'should replay a range of history correctly (range of items)' do
39
+ o = Object.new
40
+ @hist.push "@x = 10"
41
+ @hist.push "@y = 20"
42
+
43
+ @t.push_binding o
44
+ @t.eval 'hist --replay 0..2'
45
+ @t.eval('[@x, @y]').should == [10, 20]
46
+ end
47
+
48
+ # this is to prevent a regression where input redirection is
49
+ # replaced by just appending to `eval_string`
50
+ it 'should replay a range of history correctly (range of commands)' do
51
+ o = Object.new
52
+ @hist.push "cd 1"
53
+ @hist.push "cd 2"
54
+
55
+ @t.eval("hist --replay 0..2")
56
+ stack = @t.eval("Pad.stack = _pry_.binding_stack.dup")
57
+ stack.map{ |b| b.eval("self") }.should == [TOPLEVEL_BINDING.eval("self"), 1, 2]
58
+ end
59
+
60
+ it 'should grep for correct lines in history' do
61
+ @hist.push "abby"
62
+ @hist.push "box"
63
+ @hist.push "button"
64
+ @hist.push "pepper"
65
+ @hist.push "orange"
66
+ @hist.push "grape"
67
+ @hist.push "def blah 1"
68
+ @hist.push "def boink 2"
69
+ @hist.push "place holder"
70
+
71
+ @t.eval('hist --grep o').should =~ /\d:.*?box\n\d:.*?button\n\d:.*?orange/
72
+
73
+ # test more than one word in a regex match (def blah)
74
+ @t.eval('hist --grep def blah').should =~ /def blah 1/
75
+
76
+ # test more than one word with leading white space in a regex match (def boink)
77
+ @t.eval('hist --grep def boink').should =~ /def boink 2/
78
+ end
79
+
80
+ it 'should return last N lines in history with --tail switch' do
81
+ ("a".."z").each do |v|
82
+ @hist.push v
83
+ end
84
+
85
+ out = @t.eval 'hist --tail 3'
86
+ out.each_line.count.should == 3
87
+ out.should =~ /x\n\d+:.*y\n\d+:.*z/
88
+ end
89
+
90
+ it 'should apply --tail after --grep' do
91
+ @hist.push "print 1"
92
+ @hist.push "print 2"
93
+ @hist.push "puts 3"
94
+ @hist.push "print 4"
95
+ @hist.push "puts 5"
96
+
97
+ out = @t.eval 'hist --tail 2 --grep print'
98
+ out.each_line.count.should == 2
99
+ out.should =~ /\d:.*?print 2\n\d:.*?print 4/
100
+ end
101
+
102
+ it 'should apply --head after --grep' do
103
+ @hist.push "puts 1"
104
+ @hist.push "print 2"
105
+ @hist.push "puts 3"
106
+ @hist.push "print 4"
107
+ @hist.push "print 5"
108
+
109
+ out = @t.eval 'hist --head 2 --grep print'
110
+ out.each_line.count.should == 2
111
+ out.should =~ /\d:.*?print 2\n\d:.*?print 4/
112
+ end
113
+
114
+ # strangeness in this test is due to bug in Readline::HISTORY not
115
+ # always registering first line of input
116
+ it 'should return first N lines in history with --head switch' do
117
+ ("a".."z").each do |v|
118
+ @hist.push v
119
+ end
120
+
121
+ out = @t.eval 'hist --head 4'
122
+ out.each_line.count.should == 4
123
+ out.should =~ /a\n\d+:.*b\n\d+:.*c/
124
+ end
125
+
126
+ # strangeness in this test is due to bug in Readline::HISTORY not
127
+ # always registering first line of input
128
+ it 'should show lines between lines A and B with the --show switch' do
129
+ ("a".."z").each do |v|
130
+ @hist.push v
131
+ end
132
+
133
+ out = @t.eval 'hist --show 1..4'
134
+ out.each_line.count.should == 4
135
+ out.should =~ /b\n\d+:.*c\n\d+:.*d/
136
+ end
137
+
138
+ it "should store a call with `--replay` flag" do
139
+ @t.eval ":banzai"
140
+ @t.eval "hist --replay 1"
141
+ @t.eval("hist").should =~ /hist --replay 1/
142
+ end
143
+
144
+ it "should not contain lines produced by `--replay` flag" do
145
+ @t.eval ":banzai"
146
+ @t.eval ":geronimo"
147
+ @t.eval ":huzzah"
148
+ @t.eval("hist --replay 1..3")
149
+
150
+ output = @t.eval("hist")
151
+ output.should == "1: :banzai\n2: :geronimo\n3: :huzzah\n4: hist --replay 1..3\n"
152
+ end
153
+
154
+ it "should raise CommandError when index of `--replay` points out to another `hist --replay`" do
155
+ @t.eval ":banzai"
156
+ @t.eval "hist --replay 1"
157
+ lambda do
158
+ @t.eval "hist --replay 2"
159
+ end.should.raise(Pry::CommandError, /Replay index 4 points out to another replay call: `hist --replay 1`/)
160
+ end
161
+
162
+ it "should disallow execution of `--replay <i>` when CommandError raised" do
163
+ @t.eval "a = 0"
164
+ @t.eval "a += 1"
165
+ @t.eval "hist --replay 2"
166
+ lambda{
167
+ @t.eval "hist --replay 3"
168
+ }.should.raise(Pry::CommandError)
169
+ @t.eval("a").should == 2
170
+ @t.eval("hist").lines.to_a.size.should == 5
171
+ end
172
+ end