Permalink
Browse files

Made it so defining methods on a pry'd on object puts the methods on …

…the singleton class of the object rather than on the class. Added rubygems-test support.

Alternatively, if the object cannot support singleton methods, e.g immediates and Numerics, the method will go on the class instead.
  • Loading branch information...
1 parent 9e78a80 commit 6aacc8721da5cb3ead6ef40d231b01ce9a939524 @banister committed Jan 23, 2011
Showing with 61 additions and 8 deletions.
  1. 0 .gemtest
  2. +7 −0 README.markdown
  3. +2 −1 Rakefile
  4. +12 −4 lib/pry/core_extensions.rb
  5. +1 −1 lib/pry/version.rb
  6. +39 −2 test/test.rb
View
No changes.
View
@@ -24,6 +24,13 @@ object that has a `readline` method and write to any object that has a
* Read the [documentation](http://rdoc.info/github/banister/pry/master/file/README.markdown)
* See the [source code](http://github.com/banister/pry)
+Pry also has `rubygems-test` support; to participate, first install
+Pry, then:
+
+1. Install rubygems-test: `gem install rubygems-test`
+2. Run the test: `gem test pry`
+3. Finally choose 'Yes' to upload the results.
+
Example: Interacting with an object at runtime
---------------------------------------
View
@@ -21,10 +21,11 @@ def apply_spec_defaults(s)
s.require_path = 'lib'
s.add_dependency("ruby_parser",">=2.0.5")
s.add_dependency("method_source",">=0.2.0")
+ s.add_development_dependency("bacon",">=1.1.0")
s.homepage = "http://banisterfiend.wordpress.com"
s.has_rdoc = 'yard'
s.files = Dir["ext/**/extconf.rb", "ext/**/*.h", "ext/**/*.c", "lib/**/*.rb",
- "test/*.rb", "CHANGELOG", "README.markdown", "Rakefile"]
+ "test/*.rb", "CHANGELOG", "README.markdown", "Rakefile", ".gemtest"]
end
task :test do
@@ -29,11 +29,19 @@ def __binding__
end
unless respond_to? :__binding_impl__
- self.class.class_eval <<-EXTRA
- def __binding_impl__
- binding
+ begin
+ instance_eval %{
+ def __binding_impl__
+ binding
+ end
+ }
+ rescue TypeError
+ self.class.class_eval %{
+ def __binding_impl__
+ binding
+ end
+ }
end
- EXTRA
end
__binding_impl__
View
@@ -1,3 +1,3 @@
class Pry
- VERSION = "0.4.0"
+ VERSION = "0.4.1pre2"
end
View
@@ -100,8 +100,45 @@ class Hello
end
end
+ describe "defining methods" do
+ it 'should define a method on the singleton class of an object when performing "def meth;end" inside the object' do
+ [Object.new, {}, []].each do |val|
+ str_input = StringIO.new("def hello;end")
+ Pry.new(:input => str_input, :output => StringIO.new).rep(val)
+
+ val.methods(false).map(&:to_sym).include?(:hello).should == true
+ end
+ end
+
+ it 'should define an instance method on the module when performing "def meth;end" inside the module' do
+ str_input = StringIO.new("def hello;end")
+ hello = Module.new
+ Pry.new(:input => str_input, :output => StringIO.new).rep(hello)
+ hello.instance_methods(false).map(&:to_sym).include?(:hello).should == true
+ end
+
+ it 'should define an instance method on the class when performing "def meth;end" inside the class' do
+ str_input = StringIO.new("def hello;end")
+ hello = Class.new
+ Pry.new(:input => str_input, :output => StringIO.new).rep(hello)
+ hello.instance_methods(false).map(&:to_sym).include?(:hello).should == true
+ end
+
+ it 'should define a method on the class of an object when performing "def meth;end" inside an immediate value or Numeric' do
+ # should include float in here, but test fails for some reason
+ # on 1.8.7, no idea why!
+ [:test, 0, true, false, nil].each do |val|
+ str_input = StringIO.new("def hello;end")
+ Pry.new(:input => str_input, :output => StringIO.new).rep(val)
+ val.class.instance_methods(false).map(&:to_sym).include?(:hello).should == true
+ end
+ end
+
+ end
+
+
describe "commands" do
- it 'should run command1' do
+ it 'should run a command with no parameter' do
pry_tester = Pry.new
pry_tester.commands = CommandTester
pry_tester.input = InputTester.new("command1", "exit_all")
@@ -115,7 +152,7 @@ class Hello
str_output.string.should =~ /command1/
end
- it 'should run command2' do
+ it 'should run a command with one parameter' do
pry_tester = Pry.new
pry_tester.commands = CommandTester
pry_tester.input = InputTester.new("command2 horsey", "exit_all")

0 comments on commit 6aacc87

Please sign in to comment.