pry 0.9.8pre2 → 0.9.8pre3

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,7 +16,7 @@ describe Pry::InputCompleter do
16
16
  end
17
17
 
18
18
  # another jruby hack :((
19
- if !jruby?
19
+ if !Pry::Helpers::BaseHelpers.jruby?
20
20
  it "should not crash if there's a Module that has a symbolic name." do
21
21
  completer = Pry::InputCompleter.build_completion_proc(Pry.binding_for(Object.new))
22
22
  lambda{ completer.call "a.to_s." }.should.not.raise Exception
@@ -7,8 +7,7 @@ describe "Pry::Commands" do
7
7
  redirect_pry_io(InputTester.new("help ls", "exit-all"), str_output) do
8
8
  pry
9
9
  end
10
- str_output.string.each_line.count.should == 1
11
- str_output.string.should =~ /ls --help/
10
+ str_output.string.should =~ /Usage: ls/
12
11
  end
13
12
 
14
13
  it 'should display help for a regex command with a "listing"' do
@@ -53,7 +53,7 @@ describe "Pry::DefaultCommands::Introspection" do
53
53
 
54
54
  mock_pry("edit #{path}", "$rand").should =~ /#{@rand}/
55
55
 
56
- tf.close
56
+ tf.close(true)
57
57
  end
58
58
 
59
59
  it "should not reload the file if it is not a ruby file" do
@@ -62,7 +62,7 @@ describe "Pry::DefaultCommands::Introspection" do
62
62
 
63
63
  mock_pry("edit #{path}", "$rand").should.not =~ /#{@rand}/
64
64
 
65
- tf.close
65
+ tf.close(true)
66
66
  end
67
67
 
68
68
  it "should not reload a ruby file if -n is given" do
@@ -71,7 +71,7 @@ describe "Pry::DefaultCommands::Introspection" do
71
71
 
72
72
  mock_pry("edit -n #{path}", "$rand").should.not =~ /#{@rand}/
73
73
 
74
- tf.close
74
+ tf.close(true)
75
75
  end
76
76
 
77
77
  it "should reload a non-ruby file if -r is given" do
@@ -80,7 +80,7 @@ describe "Pry::DefaultCommands::Introspection" do
80
80
 
81
81
  mock_pry("edit -r #{path}", "$rand").should =~ /#{@rand}/
82
82
 
83
- tf.close
83
+ tf.close(true)
84
84
  end
85
85
  end
86
86
  end
@@ -93,7 +93,7 @@ describe "Pry::DefaultCommands::Introspection" do
93
93
  @tf.flush
94
94
  end
95
95
  after do
96
- @tf.close
96
+ @tf.close(true)
97
97
  File.unlink("#{@path}c") if File.exists?("#{@path}c") #rbx
98
98
  end
99
99
  it "should open the correct file" do
@@ -455,7 +455,7 @@ describe "Pry::DefaultCommands::Introspection" do
455
455
  end
456
456
 
457
457
  after do
458
- @tempfile.close
458
+ @tempfile.close(true)
459
459
  end
460
460
 
461
461
  describe 'without -p' do
@@ -92,7 +92,7 @@ describe "ls" do
92
92
  describe "when no arguments given" do
93
93
  describe "when at the top-level" do
94
94
  # rubinius has a bug that means local_variables of "main" aren't reported inside eval()
95
- unless defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /rbx/
95
+ unless Pry::Helpers::BaseHelpers.rbx?
96
96
  it "should show local variables" do
97
97
  mock_pry("ls").should =~ /_pry_/
98
98
  mock_pry("arbitrar = 1", "ls").should =~ /arbitrar/
@@ -47,7 +47,7 @@ describe "Pry::DefaultCommands::Shell" do
47
47
  # this doesnt work so well on rbx due to differences in backtrace
48
48
  # so we currently skip rbx until we figure out a workaround
49
49
  describe "with --ex" do
50
- if !rbx?
50
+ if !Pry::Helpers::BaseHelpers.rbx?
51
51
  it 'cat --ex should correctly display code that generated exception even if raised in repl' do
52
52
  mock_pry("this raises error", "cat --ex").should =~ /\d+:(\s*) this raises error/
53
53
  end
@@ -140,7 +140,9 @@ describe "Pry::DefaultCommands::Shell" do
140
140
  pry_instance.rep(self)
141
141
  str_output.string.should =~ /bt number 0/
142
142
 
143
- temp_files.each(&:close)
143
+ temp_files.each do |file|
144
+ file.close(true)
145
+ end
144
146
  end
145
147
 
146
148
  end
@@ -172,4 +172,20 @@ describe Pry::Hooks do
172
172
  @hooks.exec_hook(:test_hook).should == 3
173
173
  end
174
174
  end
175
+
176
+ describe "integration tests" do
177
+ describe "when_started hook" do
178
+ it 'should yield options to the hook' do
179
+ options = nil
180
+ Pry.config.hooks.add_hook(:when_started, :test_hook) { |_, opt, _| options = opt }
181
+
182
+ redirect_pry_io(StringIO.new("exit"), out=StringIO.new) do
183
+ Pry.start binding, :hello => :baby
184
+ end
185
+ options[:hello].should == :baby
186
+
187
+ Pry.config.hooks.delete_hook(:when_started, :test_hook)
188
+ end
189
+ end
190
+ end
175
191
  end
@@ -74,6 +74,56 @@ describe Pry::Method do
74
74
  end
75
75
  end
76
76
 
77
+ describe '.from_binding' do
78
+ it 'should be able to pick a method out of a binding' do
79
+ Pry::Method.from_binding(Class.new{ def self.foo; binding; end }.foo).name.should == "foo"
80
+ end
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
+ it 'should NOT find a method from the toplevel binding' do
87
+ Pry::Method.from_binding(TOPLEVEL_BINDING).should == nil
88
+ end
89
+
90
+ it "should find methods that have been undef'd" do
91
+ m = Pry::Method.from_binding(Class.new do
92
+ def self.bar
93
+ class << self; undef bar; end
94
+ binding
95
+ end
96
+ end.bar)
97
+ m.name.should == "bar"
98
+ end
99
+
100
+ # Our source_location trick doesn't work, due to https://github.com/rubinius/rubinius/issues/953
101
+ unless Pry::Helpers::BaseHelpers.rbx?
102
+ it 'should find the super method correctly' do
103
+ a = Class.new{ def gag; binding; end; def self.line; __LINE__; end }
104
+ b = Class.new(a){ def gag; super; end }
105
+
106
+ g = b.new.gag
107
+ m = Pry::Method.from_binding(g)
108
+
109
+ m.owner.should == a
110
+ m.source_line.should == a.line
111
+ m.name.should == "gag"
112
+ end
113
+ end
114
+
115
+ it 'should find the right method if a super method exists' do
116
+ a = Class.new{ def gag; binding; end; }
117
+ b = Class.new(a){ def gag; super; binding; end; def self.line; __LINE__; end }
118
+
119
+ m = Pry::Method.from_binding(b.new.gag)
120
+
121
+ m.owner.should == b
122
+ m.source_line.should == b.line
123
+ m.name.should == "gag"
124
+ end
125
+ end
126
+
77
127
  describe 'all_from_class' do
78
128
  def should_find_method(name)
79
129
  Pry::Method.all_from_class(@class).map(&:name).should.include(name)
@@ -2,16 +2,6 @@ require 'helper'
2
2
 
3
3
  describe Pry do
4
4
 
5
- # if RUBY_PLATFORM !~ /mingw/ && RUBY_PLATFORM !~ /mswin/ && RUBY_PLATFORM != 'java'
6
- # describe 'warning emissions' do
7
- # it 'should emit no warnings' do
8
- # Open4.popen4 'ruby -I lib -rubygems -r"pry" -W -e "exit"' do |pid, stdin, stdout, stderr|
9
- # stderr.read.empty?.should == true
10
- # end
11
- # end
12
- # end
13
- # end
14
-
15
5
  if RUBY_VERSION =~ /1.9/
16
6
  describe "Exotic object support" do
17
7
  # regression test for exotic object support
@@ -53,7 +43,7 @@ describe Pry do
53
43
 
54
44
  # bug fix for https://github.com/banister/pry/issues/93
55
45
  it 'should not leak pry constants into Object namespace' do
56
- input_string = "CommandContext"
46
+ input_string = "Command"
57
47
  str_output = StringIO.new
58
48
  o = Object.new
59
49
  pry_tester = Pry.new(:input => StringIO.new(input_string),
@@ -792,7 +782,7 @@ describe Pry do
792
782
  str_output = StringIO.new
793
783
  Pry.new(:input => StringIO.new("hello\n"), :output => str_output, :commands => klass).rep
794
784
  str_output.string.should =~ /nil/
795
- str_output.string.should =~ /=>/
785
+ str_output.string.should =~ /=>/
796
786
  end
797
787
 
798
788
  it 'should define a command that keeps its return value but does not return when value is void' do
@@ -806,7 +796,7 @@ describe Pry do
806
796
  str_output.string.empty?.should == true
807
797
  end
808
798
 
809
- it 'a command (with :keep_retval => false) that replaces eval_string with a valid expression should not have the expression value suppressed' do
799
+ it 'a command (with :keep_retval => false) that replaces eval_string with a valid expression should not have the expression value suppressed' do
810
800
  klass = Pry::CommandSet.new do
811
801
  command "hello", "" do
812
802
  eval_string.replace("6")
@@ -818,45 +808,45 @@ describe Pry do
818
808
  end
819
809
 
820
810
 
821
- it 'a command (with :keep_retval => true) that replaces eval_string with a valid expression should overwrite the eval_string with the return value' do
822
- klass = Pry::CommandSet.new do
823
- command "hello", "", :keep_retval => true do
811
+ it 'a command (with :keep_retval => true) that replaces eval_string with a valid expression should overwrite the eval_string with the return value' do
812
+ klass = Pry::CommandSet.new do
813
+ command "hello", "", :keep_retval => true do
824
814
  eval_string.replace("6")
825
815
  7
816
+ end
826
817
  end
827
- end
828
- str_output = StringIO.new
829
- Pry.new(:input => StringIO.new("def yo\nhello\n"), :output => str_output, :commands => klass).rep
818
+ str_output = StringIO.new
819
+ Pry.new(:input => StringIO.new("def yo\nhello\n"), :output => str_output, :commands => klass).rep
830
820
  str_output.string.should =~ /7/
831
821
  str_output.string.should.not =~ /6/
832
822
  end
833
823
 
834
- it 'a command that return a value in a multi-line expression should clear the expression and return the value' do
835
- klass = Pry::CommandSet.new do
836
- command "hello", "", :keep_retval => true do
837
- 5
824
+ it 'a command that return a value in a multi-line expression should clear the expression and return the value' do
825
+ klass = Pry::CommandSet.new do
826
+ command "hello", "", :keep_retval => true do
827
+ 5
828
+ end
838
829
  end
830
+ str_output = StringIO.new
831
+ Pry.new(:input => StringIO.new("def yo\nhello\n"), :output => str_output, :commands => klass).rep
832
+ str_output.string.should =~ /5/
839
833
  end
840
- str_output = StringIO.new
841
- Pry.new(:input => StringIO.new("def yo\nhello\n"), :output => str_output, :commands => klass).rep
842
- str_output.string.should =~ /5/
843
- end
844
834
 
845
835
 
846
- it 'should set the commands default, and the default should be overridable' do
847
- klass = Pry::CommandSet.new do
848
- command "hello" do
849
- output.puts "hello world"
836
+ it 'should set the commands default, and the default should be overridable' do
837
+ klass = Pry::CommandSet.new do
838
+ command "hello" do
839
+ output.puts "hello world"
840
+ end
850
841
  end
851
- end
852
842
 
853
- Pry.commands = klass
843
+ Pry.commands = klass
854
844
 
855
- str_output = StringIO.new
856
- Pry.new(:input => InputTester.new("hello"), :output => str_output).rep
857
- str_output.string.should =~ /hello world/
845
+ str_output = StringIO.new
846
+ Pry.new(:input => InputTester.new("hello"), :output => str_output).rep
847
+ str_output.string.should =~ /hello world/
858
848
 
859
- other_klass = Pry::CommandSet.new do
849
+ other_klass = Pry::CommandSet.new do
860
850
  command "goodbye", "" do
861
851
  output.puts "goodbye world"
862
852
  end
@@ -1312,7 +1302,7 @@ describe Pry do
1312
1302
  str_output = StringIO.new
1313
1303
  Pry.new(:output => str_output,
1314
1304
  :hooks => Pry::Hooks.new.
1315
- add_hook(:before_session, :my_name) { |out,_,_| out.puts "OPEN" }
1305
+ add_hook(:before_session, :my_name) { |out,_,_| out.puts "OPEN" }
1316
1306
  ).repl
1317
1307
 
1318
1308
  str_output.string.should =~ /OPEN/
@@ -1321,7 +1311,7 @@ describe Pry do
1321
1311
  str_output = StringIO.new
1322
1312
  Pry.new(:output => str_output,
1323
1313
  :hooks => Pry::Hooks.new.
1324
- add_hook(:after_session, :my_name) { |out,_,_| out.puts "CLOSE" }
1314
+ add_hook(:after_session, :my_name) { |out,_,_| out.puts "CLOSE" }
1325
1315
  ).repl
1326
1316
 
1327
1317
  str_output.string.should =~ /CLOSE/
@@ -1332,4 +1322,12 @@ describe Pry do
1332
1322
  end
1333
1323
  end
1334
1324
  end
1325
+
1326
+ describe 'setting custom options' do
1327
+ it 'should not raise for unrecognized options' do
1328
+ should.not.raise?(NoMethodError) {
1329
+ instance = Pry.new(:custom_option => 'custom value')
1330
+ }
1331
+ end
1332
+ end
1335
1333
  end
@@ -26,7 +26,7 @@ describe Pry do
26
26
  ["1 1"],
27
27
  ["puts :"],
28
28
  # in this case the syntax error is "expecting ')'".
29
- ((defined? RUBY_ENGINE && RUBY_ENGINE == "rbx") ? nil : ["def", "method(1"])
29
+ (Pry::Helpers::BaseHelpers.rbx? ? nil : ["def", "method(1"])
30
30
  ].compact.each do |foo|
31
31
  it "should raise an error on invalid syntax like #{foo.inspect}" do
32
32
  output = StringIO.new
metadata CHANGED
@@ -1,92 +1,95 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: pry
3
- version: !ruby/object:Gem::Version
4
- version: 0.9.8pre2
3
+ version: !ruby/object:Gem::Version
5
4
  prerelease: 5
5
+ version: 0.9.8pre3
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - John Mair (banisterfiend)
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-21 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
12
+
13
+ date: 2012-01-05 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
15
16
  name: coderay
16
- requirement: &70272200153380 !ruby/object:Gem::Requirement
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
17
19
  none: false
18
- requirements:
20
+ requirements:
19
21
  - - ~>
20
- - !ruby/object:Gem::Version
21
- version: '0.9'
22
+ - !ruby/object:Gem::Version
23
+ version: 1.0.5
22
24
  type: :runtime
23
- prerelease: false
24
- version_requirements: *70272200153380
25
- - !ruby/object:Gem::Dependency
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
26
27
  name: slop
27
- requirement: &70272200152100 !ruby/object:Gem::Requirement
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
28
30
  none: false
29
- requirements:
30
- - - ! '>='
31
- - !ruby/object:Gem::Version
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
32
34
  version: 2.4.1
33
35
  - - <
34
- - !ruby/object:Gem::Version
35
- version: '3'
36
+ - !ruby/object:Gem::Version
37
+ version: "3"
36
38
  type: :runtime
37
- prerelease: false
38
- version_requirements: *70272200152100
39
- - !ruby/object:Gem::Dependency
39
+ version_requirements: *id002
40
+ - !ruby/object:Gem::Dependency
40
41
  name: method_source
41
- requirement: &70272200150660 !ruby/object:Gem::Requirement
42
+ prerelease: false
43
+ requirement: &id003 !ruby/object:Gem::Requirement
42
44
  none: false
43
- requirements:
45
+ requirements:
44
46
  - - ~>
45
- - !ruby/object:Gem::Version
46
- version: '0.6'
47
+ - !ruby/object:Gem::Version
48
+ version: "0.7"
47
49
  type: :runtime
48
- prerelease: false
49
- version_requirements: *70272200150660
50
- - !ruby/object:Gem::Dependency
50
+ version_requirements: *id003
51
+ - !ruby/object:Gem::Dependency
51
52
  name: bacon
52
- requirement: &70272200147760 !ruby/object:Gem::Requirement
53
+ prerelease: false
54
+ requirement: &id004 !ruby/object:Gem::Requirement
53
55
  none: false
54
- requirements:
56
+ requirements:
55
57
  - - ~>
56
- - !ruby/object:Gem::Version
57
- version: '1.1'
58
+ - !ruby/object:Gem::Version
59
+ version: "1.1"
58
60
  type: :development
59
- prerelease: false
60
- version_requirements: *70272200147760
61
- - !ruby/object:Gem::Dependency
61
+ version_requirements: *id004
62
+ - !ruby/object:Gem::Dependency
62
63
  name: open4
63
- requirement: &70272200138920 !ruby/object:Gem::Requirement
64
+ prerelease: false
65
+ requirement: &id005 !ruby/object:Gem::Requirement
64
66
  none: false
65
- requirements:
67
+ requirements:
66
68
  - - ~>
67
- - !ruby/object:Gem::Version
68
- version: '1.3'
69
+ - !ruby/object:Gem::Version
70
+ version: "1.3"
69
71
  type: :development
70
- prerelease: false
71
- version_requirements: *70272200138920
72
- - !ruby/object:Gem::Dependency
72
+ version_requirements: *id005
73
+ - !ruby/object:Gem::Dependency
73
74
  name: rake
74
- requirement: &70272200136900 !ruby/object:Gem::Requirement
75
+ prerelease: false
76
+ requirement: &id006 !ruby/object:Gem::Requirement
75
77
  none: false
76
- requirements:
78
+ requirements:
77
79
  - - ~>
78
- - !ruby/object:Gem::Version
79
- version: '0.9'
80
+ - !ruby/object:Gem::Version
81
+ version: "0.9"
80
82
  type: :development
81
- prerelease: false
82
- version_requirements: *70272200136900
83
+ version_requirements: *id006
83
84
  description: An IRB alternative and runtime developer console
84
85
  email: jrmair@gmail.com
85
- executables:
86
+ executables:
86
87
  - pry
87
88
  extensions: []
89
+
88
90
  extra_rdoc_files: []
89
- files:
91
+
92
+ files:
90
93
  - .document
91
94
  - .gemtest
92
95
  - .gitignore
@@ -113,8 +116,7 @@ files:
113
116
  - examples/helper.rb
114
117
  - lib/pry.rb
115
118
  - lib/pry/cli.rb
116
- - lib/pry/command_context.rb
117
- - lib/pry/command_processor.rb
119
+ - lib/pry/command.rb
118
120
  - lib/pry/command_set.rb
119
121
  - lib/pry/commands.rb
120
122
  - lib/pry/completion.rb
@@ -155,8 +157,8 @@ files:
155
157
  - pry.gemspec
156
158
  - test/helper.rb
157
159
  - test/test_cli.rb
160
+ - test/test_command.rb
158
161
  - test/test_command_helpers.rb
159
- - test/test_command_processor.rb
160
162
  - test/test_command_set.rb
161
163
  - test/test_completion.rb
162
164
  - test/test_default_commands.rb
@@ -185,33 +187,36 @@ files:
185
187
  - wiki/Home.md
186
188
  homepage: http://pry.github.com
187
189
  licenses: []
190
+
188
191
  post_install_message:
189
192
  rdoc_options: []
190
- require_paths:
193
+
194
+ require_paths:
191
195
  - lib
192
- required_ruby_version: !ruby/object:Gem::Requirement
196
+ required_ruby_version: !ruby/object:Gem::Requirement
193
197
  none: false
194
- requirements:
195
- - - ! '>='
196
- - !ruby/object:Gem::Version
197
- version: '0'
198
- required_rubygems_version: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: "0"
202
+ required_rubygems_version: !ruby/object:Gem::Requirement
199
203
  none: false
200
- requirements:
201
- - - ! '>'
202
- - !ruby/object:Gem::Version
204
+ requirements:
205
+ - - ">"
206
+ - !ruby/object:Gem::Version
203
207
  version: 1.3.1
204
208
  requirements: []
209
+
205
210
  rubyforge_project:
206
- rubygems_version: 1.8.10
211
+ rubygems_version: 1.8.11
207
212
  signing_key:
208
213
  specification_version: 3
209
214
  summary: An IRB alternative and runtime developer console
210
- test_files:
215
+ test_files:
211
216
  - test/helper.rb
212
217
  - test/test_cli.rb
218
+ - test/test_command.rb
213
219
  - test/test_command_helpers.rb
214
- - test/test_command_processor.rb
215
220
  - test/test_command_set.rb
216
221
  - test/test_completion.rb
217
222
  - test/test_default_commands.rb