mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
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.
This commit is contained in:
parent
9e78a80dfa
commit
6aacc8721d
6 changed files with 61 additions and 8 deletions
0
.gemtest
Normal file
0
.gemtest
Normal file
|
@ -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
|
||||
---------------------------------------
|
||||
|
||||
|
|
3
Rakefile
3
Rakefile
|
@ -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 @@ class Pry
|
|||
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__
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
class Pry
|
||||
VERSION = "0.4.0"
|
||||
VERSION = "0.4.1pre2"
|
||||
end
|
||||
|
|
41
test/test.rb
41
test/test.rb
|
@ -100,8 +100,45 @@ describe Pry do
|
|||
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 @@ describe Pry do
|
|||
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")
|
||||
|
|
Loading…
Add table
Reference in a new issue