pry 0.9.9.6pre2-i386-mswin32 → 0.9.10-i386-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. data/CHANGELOG +41 -0
  2. data/CONTRIBUTORS +27 -26
  3. data/README.markdown +4 -4
  4. data/Rakefile +2 -2
  5. data/lib/pry.rb +25 -19
  6. data/lib/pry/cli.rb +31 -10
  7. data/lib/pry/code.rb +41 -83
  8. data/lib/pry/command.rb +87 -76
  9. data/lib/pry/command_set.rb +13 -20
  10. data/lib/pry/completion.rb +139 -121
  11. data/lib/pry/config.rb +4 -0
  12. data/lib/pry/core_extensions.rb +88 -31
  13. data/lib/pry/default_commands/cd.rb +31 -8
  14. data/lib/pry/default_commands/context.rb +4 -58
  15. data/lib/pry/default_commands/easter_eggs.rb +1 -1
  16. data/lib/pry/default_commands/editing.rb +21 -14
  17. data/lib/pry/default_commands/find_method.rb +5 -7
  18. data/lib/pry/default_commands/gist.rb +187 -0
  19. data/lib/pry/default_commands/hist.rb +6 -6
  20. data/lib/pry/default_commands/input_and_output.rb +73 -129
  21. data/lib/pry/default_commands/introspection.rb +107 -52
  22. data/lib/pry/default_commands/ls.rb +1 -1
  23. data/lib/pry/default_commands/misc.rb +0 -5
  24. data/lib/pry/default_commands/whereami.rb +92 -0
  25. data/lib/pry/helpers/base_helpers.rb +6 -1
  26. data/lib/pry/helpers/command_helpers.rb +30 -9
  27. data/lib/pry/helpers/documentation_helpers.rb +7 -7
  28. data/lib/pry/helpers/options_helpers.rb +1 -1
  29. data/lib/pry/helpers/text.rb +7 -9
  30. data/lib/pry/history.rb +15 -2
  31. data/lib/pry/hooks.rb +1 -1
  32. data/lib/pry/indent.rb +17 -10
  33. data/lib/pry/method.rb +35 -19
  34. data/lib/pry/module_candidate.rb +130 -0
  35. data/lib/pry/pry_class.rb +54 -22
  36. data/lib/pry/pry_instance.rb +71 -14
  37. data/lib/pry/repl_file_loader.rb +80 -0
  38. data/lib/pry/version.rb +1 -1
  39. data/lib/pry/wrapped_module.rb +121 -142
  40. data/pry.gemspec +13 -13
  41. data/test/candidate_helper1.rb +11 -0
  42. data/test/candidate_helper2.rb +8 -0
  43. data/test/helper.rb +16 -0
  44. data/test/test_code.rb +1 -1
  45. data/test/test_command.rb +364 -270
  46. data/test/test_command_integration.rb +235 -267
  47. data/test/test_completion.rb +36 -0
  48. data/test/test_control_d_handler.rb +45 -0
  49. data/test/test_default_commands/example.erb +5 -0
  50. data/test/test_default_commands/test_cd.rb +316 -11
  51. data/test/test_default_commands/test_context.rb +143 -192
  52. data/test/test_default_commands/test_documentation.rb +81 -14
  53. data/test/test_default_commands/test_find_method.rb +10 -2
  54. data/test/test_default_commands/test_input.rb +102 -111
  55. data/test/test_default_commands/test_introspection.rb +17 -12
  56. data/test/test_default_commands/test_ls.rb +8 -6
  57. data/test/test_default_commands/test_shell.rb +18 -15
  58. data/test/test_default_commands/test_show_source.rb +170 -44
  59. data/test/test_exception_whitelist.rb +6 -2
  60. data/test/test_hooks.rb +32 -0
  61. data/test/test_input_stack.rb +19 -16
  62. data/test/test_method.rb +0 -4
  63. data/test/test_prompt.rb +60 -0
  64. data/test/test_pry.rb +23 -31
  65. data/test/test_pry_defaults.rb +75 -57
  66. data/test/test_syntax_checking.rb +12 -11
  67. data/test/test_wrapped_module.rb +103 -0
  68. metadata +72 -26
@@ -1,15 +1,19 @@
1
1
  require 'helper'
2
2
 
3
3
  describe "Pry.config.exception_whitelist" do
4
+ before do
5
+ @str_output = StringIO.new
6
+ end
7
+
4
8
  it 'should rescue all exceptions NOT specified on whitelist' do
5
9
  Pry.config.exception_whitelist.include?(NameError).should == false
6
- lambda { Pry.start(self, :input => StringIO.new("raise NameError\nexit"), :output => StringIO.new) }.should.not.raise NameError
10
+ lambda { Pry.start(self, :input => StringIO.new("raise NameError\nexit"), :output => @str_output) }.should.not.raise NameError
7
11
  end
8
12
 
9
13
  it 'should NOT rescue exceptions specified on whitelist' do
10
14
  old_whitelist = Pry.config.exception_whitelist
11
15
  Pry.config.exception_whitelist = [NameError]
12
- lambda { Pry.start(self, :input => StringIO.new("raise NameError"), :output => StringIO.new) }.should.raise NameError
16
+ lambda { Pry.start(self, :input => StringIO.new("raise NameError"), :output => @str_output) }.should.raise NameError
13
17
  Pry.config.exception_whitelist = old_whitelist
14
18
  end
15
19
  end
data/test/test_hooks.rb CHANGED
@@ -316,6 +316,7 @@ describe Pry::Hooks do
316
316
  redirect_pry_io(StringIO.new("exit"), out=StringIO.new) do
317
317
  Pry.start binding, :hello => :baby
318
318
  end
319
+
319
320
  options[:hello].should == :baby
320
321
 
321
322
  Pry.config.hooks.delete_hook(:when_started, :test_hook)
@@ -394,6 +395,37 @@ describe Pry::Hooks do
394
395
  Pry.config.exception_whitelist = old_ew
395
396
  end
396
397
 
398
+ describe "before_eval hook" do
399
+ describe "modifying input code" do
400
+ it 'should replace input code with code determined by hook' do
401
+ hooks = Pry::Hooks.new.add_hook(:before_eval, :quirk) { |code, pry| code.replace(":little_duck") }
402
+ redirect_pry_io(InputTester.new(":jemima", "exit-all"), out = StringIO.new) do
403
+ Pry.start(self, :hooks => hooks)
404
+ end
405
+ out.string.should =~ /little_duck/
406
+ out.string.should.not =~ /jemima/
407
+ end
408
+
409
+ it 'should not interfere with command processing when replacing input code' do
410
+ commands = Pry::CommandSet.new do
411
+ import_from Pry::Commands, "exit-all"
412
+
413
+ command "how-do-you-like-your-blue-eyed-boy-now-mister-death" do
414
+ output.puts "in hours of bitterness i imagine balls of sapphire, of metal"
415
+ end
416
+ end
417
+
418
+ hooks = Pry::Hooks.new.add_hook(:before_eval, :quirk) { |code, pry| code.replace(":little_duck") }
419
+ redirect_pry_io(InputTester.new("how-do-you-like-your-blue-eyed-boy-now-mister-death", "exit-all"), out = StringIO.new) do
420
+ Pry.start(self, :hooks => hooks, :commands => commands)
421
+ end
422
+ out.string.should =~ /in hours of bitterness i imagine balls of sapphire, of metal/
423
+ out.string.should.not =~ /little_duck/
424
+ end
425
+ end
426
+
427
+ end
428
+
397
429
  describe "exceptions" do
398
430
  before do
399
431
  Pry.config.hooks.add_hook(:after_eval, :baddums){ raise "Baddums" }
@@ -2,6 +2,10 @@
2
2
  require 'helper'
3
3
 
4
4
  describe "Pry#input_stack" do
5
+ before do
6
+ @str_output = StringIO.new
7
+ end
8
+
5
9
  it 'should accept :input_stack as a config option' do
6
10
  stack = [StringIO.new("test")]
7
11
  Pry.new(:input_stack => stack).input_stack.should == stack
@@ -16,30 +20,30 @@ describe "Pry#input_stack" do
16
20
  it 'should read from all input objects on stack and exit session (usingn repl)' do
17
21
  stack = [b = StringIO.new(":cloister\nexit\n"), c = StringIO.new(":baron\n")]
18
22
  instance = Pry.new(:input => StringIO.new(":alex\n"),
19
- :output => str_output = StringIO.new,
23
+ :output => @str_output,
20
24
  :input_stack => stack)
21
25
 
22
26
  instance.repl
23
- str_output.string.should =~ /:alex/
24
- str_output.string.should =~ /:baron/
25
- str_output.string.should =~ /:cloister/
27
+ @str_output.string.should =~ /:alex/
28
+ @str_output.string.should =~ /:baron/
29
+ @str_output.string.should =~ /:cloister/
26
30
  end
27
31
 
28
32
  it 'input objects should be popped off stack as they are used up' do
29
33
  stack = [StringIO.new(":cloister\n"), StringIO.new(":baron\n")]
30
34
  instance = Pry.new(:input => StringIO.new(":alex\n"),
31
- :output => str_output = StringIO.new,
35
+ :output => @str_output,
32
36
  :input_stack => stack)
33
37
 
34
38
  stack.size.should == 2
35
39
 
36
40
  instance.rep
37
- str_output.string.should =~ /:alex/
41
+ @str_output.string.should =~ /:alex/
38
42
  instance.rep
39
- str_output.string.should =~ /:baron/
43
+ @str_output.string.should =~ /:baron/
40
44
  stack.size.should == 1
41
45
  instance.rep
42
- str_output.string.should =~ /:cloister/
46
+ @str_output.string.should =~ /:cloister/
43
47
  stack.size.should == 0
44
48
  end
45
49
 
@@ -47,25 +51,24 @@ describe "Pry#input_stack" do
47
51
  redirect_pry_io(StringIO.new(":rimbaud\nexit\n"), StringIO.new) do
48
52
  stack = [StringIO.new(":cloister\n"), StringIO.new(":baron\n")]
49
53
  instance = Pry.new(:input => StringIO.new(":alex\n"),
50
- :output => str_output = StringIO.new,
54
+ :output => @str_output,
51
55
  :input_stack => stack)
52
56
 
53
57
  instance.repl
54
- str_output.string.should =~ /:alex/
55
- str_output.string.should =~ /:baron/
56
- str_output.string.should =~ /:cloister/
57
- str_output.string.should =~ /:rimbaud/
58
+ @str_output.string.should =~ /:alex/
59
+ @str_output.string.should =~ /:baron/
60
+ @str_output.string.should =~ /:cloister/
61
+ @str_output.string.should =~ /:rimbaud/
58
62
  end
59
63
  end
60
64
 
61
65
  it 'should display error and throw(:breakout) if at end of input after using up input_stack objects' do
62
- str_output = StringIO.new
63
66
  catch(:breakout) do
64
- redirect_pry_io(StringIO.new(":rimbaud\n"), str_output) do
67
+ redirect_pry_io(StringIO.new(":rimbaud\n"), @str_output) do
65
68
  Pry.new(:input_stack => [StringIO.new(":a\n"), StringIO.new(":b\n")]).repl
66
69
  end
67
70
  end
68
- str_output.string.should =~ /Error: Pry ran out of things to read/
71
+ @str_output.string.should =~ /Error: Pry ran out of things to read/
69
72
  end
70
73
 
71
74
  if "".respond_to?(:encoding)
data/test/test_method.rb CHANGED
@@ -79,10 +79,6 @@ describe Pry::Method do
79
79
  Pry::Method.from_binding(Class.new{ def self.foo; binding; end }.foo).name.should == "foo"
80
80
  end
81
81
 
82
- it 'should NOT find a method from the special pry bindings' do
83
- Pry::Method.from_binding(5.__binding__).should == nil
84
- end
85
-
86
82
  it 'should NOT find a method from the toplevel binding' do
87
83
  Pry::Method.from_binding(TOPLEVEL_BINDING).should == nil
88
84
  end
@@ -0,0 +1,60 @@
1
+ require 'helper'
2
+
3
+ describe "Prompts" do
4
+ describe "one-parameter prompt proc" do
5
+ it 'should get full config object' do
6
+ config = nil
7
+ redirect_pry_io(InputTester.new("exit-all")) do
8
+ Pry.start(self, :prompt => proc { |v| config = v })
9
+ end
10
+ config.is_a?(OpenStruct).should == true
11
+ end
12
+
13
+ it 'should get full config object, when using a proc array' do
14
+ config1 = nil
15
+ redirect_pry_io(InputTester.new("exit-all")) do
16
+ Pry.start(self, :prompt => [proc { |v| config1 = v }, proc { |v| config2 = v }])
17
+ end
18
+ config1.is_a?(OpenStruct).should == true
19
+ end
20
+
21
+ it 'should receive correct data in the config object' do
22
+ config = nil
23
+ redirect_pry_io(InputTester.new("def hello", "exit-all")) do
24
+ Pry.start(self, :prompt => proc { |v| config = v })
25
+ end
26
+ config.eval_string.should =~ /def hello/
27
+ config.nesting_level.should == 0
28
+ config.expr_number.should == 1
29
+ config.cont.should == true
30
+ config._pry_.is_a?(Pry).should == true
31
+ config.object.should == self
32
+ end
33
+ end
34
+
35
+ describe "BACKWARDS COMPATIBILITY: 3 parameter prompt proc" do
36
+ it 'should get 3 parameters' do
37
+ o = n = p = nil
38
+ redirect_pry_io(InputTester.new("exit-all")) do
39
+ Pry.start(:test, :prompt => proc { |obj, nesting, _pry_|
40
+ o, n, p = obj, nesting, _pry_ })
41
+ end
42
+ o.should == :test
43
+ n.should == 0
44
+ p.is_a?(Pry).should == true
45
+ end
46
+
47
+ it 'should get 3 parameters, when using proc array' do
48
+ o1 = n1 = p1 = nil
49
+ redirect_pry_io(InputTester.new("exit-all")) do
50
+ Pry.start(:test, :prompt => [proc { |obj, nesting, _pry_|
51
+ o1, n1, p1 = obj, nesting, _pry_ },
52
+ proc { |obj, nesting, _pry_|
53
+ o2, n2, p2 = obj, nesting, _pry_ }])
54
+ end
55
+ o1.should == :test
56
+ n1.should == 0
57
+ p1.is_a?(Pry).should == true
58
+ end
59
+ end
60
+ end
data/test/test_pry.rb CHANGED
@@ -1,6 +1,9 @@
1
1
  require 'helper'
2
2
 
3
3
  describe Pry do
4
+ before do
5
+ @str_output = StringIO.new
6
+ end
4
7
 
5
8
  if RUBY_VERSION =~ /1.9/
6
9
  describe "Exotic object support" do
@@ -44,10 +47,9 @@ describe Pry do
44
47
  # bug fix for https://github.com/banister/pry/issues/93
45
48
  it 'should not leak pry constants into Object namespace' do
46
49
  input_string = "Command"
47
- str_output = StringIO.new
48
50
  o = Object.new
49
51
  pry_tester = Pry.new(:input => StringIO.new(input_string),
50
- :output => str_output,
52
+ :output => @str_output,
51
53
  :exception_handler => proc { |_, exception, _pry_| @excep = exception },
52
54
  :print => proc {}
53
55
  ).rep(o)
@@ -57,12 +59,11 @@ describe Pry do
57
59
 
58
60
  if defined?(BasicObject)
59
61
  it 'should be able to operate inside the BasicObject class' do
60
- $obj = nil
61
- redirect_pry_io(InputTester.new(":foo", "$obj = _", "exit-all"), StringIO.new) do
62
+ redirect_pry_io(InputTester.new(":foo", "Pad.obj = _", "exit-all")) do
62
63
  BasicObject.pry
63
64
  end
64
- $obj.should == :foo
65
- $obj = nil
65
+
66
+ Pad.obj.should == :foo
66
67
  end
67
68
  end
68
69
 
@@ -77,31 +78,28 @@ describe Pry do
77
78
  end
78
79
 
79
80
  it 'should display error and throw(:breakout) if Pry instance runs out of input' do
80
- str_output = StringIO.new
81
81
  catch(:breakout) do
82
- redirect_pry_io(StringIO.new(":nothing\n"), str_output) do
82
+ redirect_pry_io(StringIO.new(":nothing\n"), @str_output) do
83
83
  Pry.new.repl
84
84
  end
85
85
  end
86
- str_output.string.should =~ /Error: Pry ran out of things to read/
86
+ @str_output.string.should =~ /Error: Pry ran out of things to read/
87
87
  end
88
88
 
89
89
  it 'should make self evaluate to the receiver of the rep session' do
90
90
  o = :john
91
- str_output = StringIO.new
92
91
 
93
- pry_tester = Pry.new(:input => InputTester.new("self"), :output => str_output)
92
+ pry_tester = Pry.new(:input => InputTester.new("self"), :output => @str_output)
94
93
  pry_tester.rep(o)
95
- str_output.string.should =~ /:john/
94
+ @str_output.string.should =~ /:john/
96
95
  end
97
96
 
98
97
  it 'should work with multi-line input' do
99
98
  o = Object.new
100
- str_output = StringIO.new
101
99
 
102
- pry_tester = Pry.new(:input => InputTester.new("x = ", "1 + 4"), :output => str_output)
100
+ pry_tester = Pry.new(:input => InputTester.new("x = ", "1 + 4"), :output => @str_output)
103
101
  pry_tester.rep(o)
104
- str_output.string.should =~ /5/
102
+ @str_output.string.should =~ /5/
105
103
  end
106
104
 
107
105
  it 'should define a nested class under Hello and not on top-level or Pry' do
@@ -112,38 +110,34 @@ describe Pry do
112
110
 
113
111
  it 'should suppress output if input ends in a ";" and is an Exception object (single line)' do
114
112
  o = Object.new
115
- str_output = StringIO.new
116
113
 
117
- pry_tester = Pry.new(:input => InputTester.new("Exception.new;"), :output => str_output)
114
+ pry_tester = Pry.new(:input => InputTester.new("Exception.new;"), :output => @str_output)
118
115
  pry_tester.rep(o)
119
- str_output.string.should == ""
116
+ @str_output.string.should == ""
120
117
  end
121
118
 
122
119
  it 'should suppress output if input ends in a ";" (single line)' do
123
120
  o = Object.new
124
- str_output = StringIO.new
125
121
 
126
- pry_tester = Pry.new(:input => InputTester.new("x = 5;"), :output => str_output)
122
+ pry_tester = Pry.new(:input => InputTester.new("x = 5;"), :output => @str_output)
127
123
  pry_tester.rep(o)
128
- str_output.string.should == ""
124
+ @str_output.string.should == ""
129
125
  end
130
126
 
131
127
  it 'should suppress output if input ends in a ";" (multi-line)' do
132
128
  o = Object.new
133
- str_output = StringIO.new
134
129
 
135
- pry_tester = Pry.new(:input => InputTester.new("def self.blah", ":test", "end;"), :output => str_output)
130
+ pry_tester = Pry.new(:input => InputTester.new("def self.blah", ":test", "end;"), :output => @str_output)
136
131
  pry_tester.rep(o)
137
- str_output.string.should == ""
132
+ @str_output.string.should == ""
138
133
  end
139
134
 
140
135
  it 'should be able to evaluate exceptions normally' do
141
136
  o = Exception.new
142
- str_output = StringIO.new
143
137
 
144
138
  was_called = false
145
139
  pry_tester = Pry.new(:input => InputTester.new("self"),
146
- :output => str_output,
140
+ :output => @str_output,
147
141
  :exception_handler => proc { was_called = true })
148
142
 
149
143
  pry_tester.rep(o)
@@ -152,11 +146,10 @@ describe Pry do
152
146
 
153
147
  it 'should notice when exceptions are raised' do
154
148
  o = Exception.new
155
- str_output = StringIO.new
156
149
 
157
150
  was_called = false
158
151
  pry_tester = Pry.new(:input => InputTester.new("raise self"),
159
- :output => str_output,
152
+ :output => @str_output,
160
153
  :exception_handler => proc { was_called = true })
161
154
 
162
155
  pry_tester.rep(o)
@@ -370,13 +363,12 @@ describe Pry do
370
363
  it 'should nest properly' do
371
364
  Pry.input = InputTester.new("cd 1", "cd 2", "cd 3", "\"nest:\#\{(_pry_.binding_stack.size - 1)\}\"", "exit-all")
372
365
 
373
- str_output = StringIO.new
374
- Pry.output = str_output
366
+ Pry.output = @str_output
375
367
 
376
368
  o = Object.new
377
369
 
378
370
  pry_tester = o.pry
379
- str_output.string.should =~ /nest:3/
371
+ @str_output.string.should =~ /nest:3/
380
372
  end
381
373
  end
382
374
 
@@ -1,5 +1,11 @@
1
1
  require 'helper'
2
+
3
+ version = 1
4
+
2
5
  describe "test Pry defaults" do
6
+ before do
7
+ @str_output = StringIO.new
8
+ end
3
9
 
4
10
  after do
5
11
  Pry.reset_defaults
@@ -7,7 +13,6 @@ describe "test Pry defaults" do
7
13
  end
8
14
 
9
15
  describe "input" do
10
-
11
16
  after do
12
17
  Pry.reset_defaults
13
18
  Pry.color = false
@@ -16,13 +21,12 @@ describe "test Pry defaults" do
16
21
  it 'should set the input default, and the default should be overridable' do
17
22
  Pry.input = InputTester.new("5")
18
23
 
19
- str_output = StringIO.new
20
- Pry.output = str_output
24
+ Pry.output = @str_output
21
25
  Pry.new.rep
22
- str_output.string.should =~ /5/
26
+ @str_output.string.should =~ /5/
23
27
 
24
28
  Pry.new(:input => InputTester.new("6")).rep
25
- str_output.string.should =~ /6/
29
+ @str_output.string.should =~ /6/
26
30
  end
27
31
 
28
32
  it 'should pass in the prompt if readline arity is 1' do
@@ -73,19 +77,18 @@ describe "test Pry defaults" do
73
77
  it 'should set the output default, and the default should be overridable' do
74
78
  Pry.input = InputTester.new("5", "6", "7")
75
79
 
76
- str_output = StringIO.new
77
- Pry.output = str_output
80
+ Pry.output = @str_output
78
81
 
79
82
  Pry.new.rep
80
- str_output.string.should =~ /5/
83
+ @str_output.string.should =~ /5/
81
84
 
82
85
  Pry.new.rep
83
- str_output.string.should =~ /5\n.*6/
86
+ @str_output.string.should =~ /5\n.*6/
84
87
 
85
- str_output2 = StringIO.new
86
- Pry.new(:output => str_output2).rep
87
- str_output2.string.should.not =~ /5\n.*6/
88
- str_output2.string.should =~ /7/
88
+ @str_output = StringIO.new
89
+ Pry.new(:output => @str_output).rep
90
+ @str_output.string.should.not =~ /5\n.*6/
91
+ @str_output.string.should =~ /7/
89
92
  end
90
93
 
91
94
  it "should set the print default, and the default should be overridable" do
@@ -93,19 +96,18 @@ describe "test Pry defaults" do
93
96
  Pry.print = new_print
94
97
 
95
98
  Pry.new.print.should == Pry.print
96
- str_output = StringIO.new
97
- Pry.new(:input => InputTester.new("\"test\""), :output => str_output).rep
98
- str_output.string.should == "test\n"
99
+ Pry.new(:input => InputTester.new("\"test\""), :output => @str_output).rep
100
+ @str_output.string.should == "test\n"
99
101
 
100
- str_output = StringIO.new
101
- Pry.new(:input => InputTester.new("\"test\""), :output => str_output,
102
+ @str_output = StringIO.new
103
+ Pry.new(:input => InputTester.new("\"test\""), :output => @str_output,
102
104
  :print => proc { |out, value| out.puts value.reverse }).rep
103
- str_output.string.should == "tset\n"
105
+ @str_output.string.should == "tset\n"
104
106
 
105
107
  Pry.new.print.should == Pry.print
106
- str_output = StringIO.new
107
- Pry.new(:input => InputTester.new("\"test\""), :output => str_output).rep
108
- str_output.string.should == "test\n"
108
+ @str_output = StringIO.new
109
+ Pry.new(:input => InputTester.new("\"test\""), :output => @str_output).rep
110
+ @str_output.string.should == "test\n"
109
111
  end
110
112
 
111
113
  describe "pry return values" do
@@ -332,70 +334,86 @@ describe "test Pry defaults" do
332
334
 
333
335
  end
334
336
 
337
+ describe 'quiet' do
338
+ it 'should show whereami by default' do
339
+ Pry.start(binding, :input => InputTester.new("1", "exit-all"),
340
+ :output => @str_output,
341
+ :hooks => Pry::DEFAULT_HOOKS)
342
+
343
+ @str_output.string.should =~ /[w]hereami by default/
344
+ end
345
+
346
+ it 'should hide whereami if quiet is set' do
347
+ Pry.new(:input => InputTester.new("exit-all"),
348
+ :output => @str_output,
349
+ :quiet => true,
350
+ :hooks => Pry::DEFAULT_HOOKS)
351
+
352
+ @str_output.string.should == ""
353
+ end
354
+ end
355
+
356
+ describe 'toplevel_binding' do
357
+ it 'should be devoid of local variables' do
358
+ mock_pry(Pry.toplevel_binding, "ls -l").should.not =~ /version/
359
+ end
360
+
361
+ it 'should have self the same as TOPLEVEL_BINDING' do
362
+ mock_pry(Pry.toplevel_binding, "self.equal? TOPLEVEL_BINDING.eval('self')").should =~ /=> true/
363
+ end
364
+
365
+ # https://github.com/rubinius/rubinius/issues/1779
366
+ unless Pry::Helpers::BaseHelpers.rbx?
367
+ it 'should define private methods on Object' do
368
+ mock_pry(TOPLEVEL_BINDING, "def gooey_fooey; end")
369
+ method(:gooey_fooey).owner.should == Object
370
+ Pry::Method(method(:gooey_fooey)).visibility.should == :private
371
+ end
372
+ end
373
+ end
374
+
335
375
  it 'should set the hooks default, and the default should be overridable' do
336
376
  Pry.input = InputTester.new("exit-all")
337
377
  Pry.hooks = Pry::Hooks.new.
338
378
  add_hook(:before_session, :my_name) { |out,_,_| out.puts "HELLO" }.
339
379
  add_hook(:after_session, :my_name) { |out,_,_| out.puts "BYE" }
340
380
 
341
- str_output = StringIO.new
342
- Pry.new(:output => str_output).repl
343
- str_output.string.should =~ /HELLO/
344
- str_output.string.should =~ /BYE/
381
+ Pry.new(:output => @str_output).repl
382
+ @str_output.string.should =~ /HELLO/
383
+ @str_output.string.should =~ /BYE/
345
384
 
346
385
  Pry.input.rewind
347
386
 
348
- str_output = StringIO.new
349
- Pry.new(:output => str_output,
387
+ @str_output = StringIO.new
388
+ Pry.new(:output => @str_output,
350
389
  :hooks => Pry::Hooks.new.
351
390
  add_hook( :before_session, :my_name) { |out,_,_| out.puts "MORNING" }.
352
391
  add_hook(:after_session, :my_name) { |out,_,_| out.puts "EVENING" }
353
392
  ).repl
354
393
 
355
- str_output.string.should =~ /MORNING/
356
- str_output.string.should =~ /EVENING/
394
+ @str_output.string.should =~ /MORNING/
395
+ @str_output.string.should =~ /EVENING/
357
396
 
358
397
  # try below with just defining one hook
359
398
  Pry.input.rewind
360
- str_output = StringIO.new
361
- Pry.new(:output => str_output,
399
+ @str_output = StringIO.new
400
+ Pry.new(:output => @str_output,
362
401
  :hooks => Pry::Hooks.new.
363
402
  add_hook(:before_session, :my_name) { |out,_,_| out.puts "OPEN" }
364
403
  ).repl
365
404
 
366
- str_output.string.should =~ /OPEN/
405
+ @str_output.string.should =~ /OPEN/
367
406
 
368
407
  Pry.input.rewind
369
- str_output = StringIO.new
370
- Pry.new(:output => str_output,
408
+ @str_output = StringIO.new
409
+ Pry.new(:output => @str_output,
371
410
  :hooks => Pry::Hooks.new.
372
411
  add_hook(:after_session, :my_name) { |out,_,_| out.puts "CLOSE" }
373
412
  ).repl
374
413
 
375
- str_output.string.should =~ /CLOSE/
414
+ @str_output.string.should =~ /CLOSE/
376
415
 
377
416
  Pry.reset_defaults
378
417
  Pry.color = false
379
418
  end
380
-
381
- describe 'quiet' do
382
- it 'should show whereami by default' do
383
- output = StringIO.new
384
- Pry.start(binding, :input => InputTester.new("1", "exit-all"),
385
- :output => output,
386
- :hooks => Pry::DEFAULT_HOOKS)
387
-
388
- output.string.should =~ /[w]hereami by default/
389
- end
390
-
391
- it 'should hide whereami if quiet is set' do
392
- output = StringIO.new
393
- Pry.new(:input => InputTester.new("exit-all"),
394
- :output => output,
395
- :quiet => true,
396
- :hooks => Pry::DEFAULT_HOOKS)
397
-
398
- output.string.should == ""
399
- end
400
- end
401
419
  end