2010-10-30 16:50:48 -04:00
|
|
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
|
|
|
|
|
|
describe "Single method" do
|
2010-11-05 21:31:54 -04:00
|
|
|
after do
|
|
|
|
Object.instance_eval{ remove_const :Hello } if defined?(Hello)
|
|
|
|
end
|
|
|
|
|
2010-10-30 16:50:48 -04:00
|
|
|
it "plain: should handle a method with no arguments" do
|
|
|
|
method = ''.method(:upcase)
|
|
|
|
method.ai(:plain => true).should == 'String#upcase()'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "color: should handle a method with no arguments" do
|
|
|
|
method = ''.method(:upcase)
|
2010-11-06 18:40:20 -04:00
|
|
|
method.ai.should == "\e[1;33mString\e[0m#\e[0;35mupcase\e[0m\e[0;37m()\e[0m"
|
2010-10-30 16:50:48 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "plain: should handle a method with one argument" do
|
2010-11-01 01:34:50 -04:00
|
|
|
method = ''.method(:include?)
|
|
|
|
method.ai(:plain => true).should == 'String#include?(arg1)'
|
2010-10-30 16:50:48 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "color: should handle a method with one argument" do
|
2010-11-01 01:34:50 -04:00
|
|
|
method = ''.method(:include?)
|
2010-11-06 18:40:20 -04:00
|
|
|
method.ai.should == "\e[1;33mString\e[0m#\e[0;35minclude?\e[0m\e[0;37m(arg1)\e[0m"
|
2010-10-30 16:50:48 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "plain: should handle a method with two arguments" do
|
|
|
|
method = ''.method(:tr)
|
|
|
|
method.ai(:plain => true).should == 'String#tr(arg1, arg2)'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "color: should handle a method with two arguments" do
|
|
|
|
method = ''.method(:tr)
|
2010-11-06 18:40:20 -04:00
|
|
|
method.ai.should == "\e[1;33mString\e[0m#\e[0;35mtr\e[0m\e[0;37m(arg1, arg2)\e[0m"
|
2010-10-30 16:50:48 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "plain: should handle a method with multiple arguments" do
|
|
|
|
method = ''.method(:split)
|
2010-11-05 21:31:54 -04:00
|
|
|
method.ai(:plain => true).should == 'String#split(*arg1)'
|
2010-10-30 16:50:48 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "color: should handle a method with multiple arguments" do
|
|
|
|
method = ''.method(:split)
|
2010-11-06 18:40:20 -04:00
|
|
|
method.ai.should == "\e[1;33mString\e[0m#\e[0;35msplit\e[0m\e[0;37m(*arg1)\e[0m"
|
2010-10-30 16:50:48 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "plain: should handle a method defined in mixin" do
|
2010-11-01 01:34:50 -04:00
|
|
|
method = ''.method(:is_a?)
|
|
|
|
method.ai(:plain => true).should == 'String (Kernel)#is_a?(arg1)'
|
2010-10-30 16:50:48 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "color: should handle a method defined in mixin" do
|
2010-11-01 01:34:50 -04:00
|
|
|
method = ''.method(:is_a?)
|
2010-11-06 18:40:20 -04:00
|
|
|
method.ai.should == "\e[1;33mString (Kernel)\e[0m#\e[0;35mis_a?\e[0m\e[0;37m(arg1)\e[0m"
|
2010-10-31 18:02:12 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "plain: should handle an unbound method" do
|
|
|
|
class Hello
|
|
|
|
def world; end
|
|
|
|
end
|
|
|
|
method = Hello.instance_method(:world)
|
|
|
|
method.ai(:plain => true).should == 'Hello (unbound)#world()'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "color: should handle an unbound method" do
|
|
|
|
class Hello
|
|
|
|
def world(a,b); end
|
|
|
|
end
|
|
|
|
method = Hello.instance_method(:world)
|
2010-11-05 22:45:24 -04:00
|
|
|
if RUBY_VERSION < '1.9.2'
|
2010-11-06 18:40:20 -04:00
|
|
|
method.ai.should == "\e[1;33mHello (unbound)\e[0m#\e[0;35mworld\e[0m\e[0;37m(arg1, arg2)\e[0m"
|
2010-11-05 22:45:24 -04:00
|
|
|
else
|
2010-11-06 18:40:20 -04:00
|
|
|
method.ai.should == "\e[1;33mHello (unbound)\e[0m#\e[0;35mworld\e[0m\e[0;37m(a, b)\e[0m"
|
2010-11-05 22:45:24 -04:00
|
|
|
end
|
2010-10-30 16:50:48 -04:00
|
|
|
end
|
|
|
|
end
|
2010-10-31 18:02:12 -04:00
|
|
|
|
2010-11-05 21:31:54 -04:00
|
|
|
describe "Object methods" do
|
|
|
|
after do
|
|
|
|
Object.instance_eval{ remove_const :Hello } if defined?(Hello)
|
2010-10-31 18:02:12 -04:00
|
|
|
end
|
|
|
|
|
2010-11-05 21:31:54 -04:00
|
|
|
describe "object.methods" do
|
|
|
|
it "index: should handle object.methods" do
|
|
|
|
out = nil.methods.ai(:plain => true).split("\n").grep(/is_a\?/).first
|
|
|
|
out.should =~ /^\s+\[\s*\d+\]\s+is_a\?\(arg1\)\s+NilClass \(Kernel\)$/
|
|
|
|
end
|
|
|
|
|
|
|
|
it "no index: should handle object.methods" do
|
|
|
|
out = nil.methods.ai(:plain => true, :index => false).split("\n").grep(/is_a\?/).first
|
|
|
|
out.should =~ /^\s+is_a\?\(arg1\)\s+NilClass \(Kernel\)$/
|
|
|
|
end
|
2010-10-31 18:02:12 -04:00
|
|
|
end
|
|
|
|
|
2010-11-05 21:31:54 -04:00
|
|
|
describe "object.public_methods" do
|
|
|
|
it "index: should handle object.public_methods" do
|
|
|
|
out = nil.public_methods.ai(:plain => true).split("\n").grep(/is_a\?/).first
|
|
|
|
out.should =~ /^\s+\[\s*\d+\]\s+is_a\?\(arg1\)\s+NilClass \(Kernel\)$/
|
|
|
|
end
|
|
|
|
|
|
|
|
it "no index: should handle object.public_methods" do
|
|
|
|
out = nil.public_methods.ai(:plain => true, :index => false).split("\n").grep(/is_a\?/).first
|
|
|
|
out.should =~ /^\s+is_a\?\(arg1\)\s+NilClass \(Kernel\)$/
|
|
|
|
end
|
2010-10-31 18:02:12 -04:00
|
|
|
end
|
|
|
|
|
2010-11-05 21:31:54 -04:00
|
|
|
describe "object.private_methods" do
|
|
|
|
it "index: should handle object.private_methods" do
|
|
|
|
out = nil.private_methods.ai(:plain => true).split("\n").grep(/sleep/).first
|
|
|
|
out.should =~ /^\s+\[\s*\d+\]\s+sleep\(\*arg1\)\s+NilClass \(Kernel\)$/
|
|
|
|
end
|
|
|
|
|
|
|
|
it "no index: should handle object.private_methods" do
|
|
|
|
out = nil.private_methods.ai(:plain => true, :index => false).split("\n").grep(/sleep/).first
|
|
|
|
out.should =~ /^\s+sleep\(\*arg1\)\s+NilClass \(Kernel\)$/
|
|
|
|
end
|
2010-10-31 18:02:12 -04:00
|
|
|
end
|
|
|
|
|
2010-11-05 21:31:54 -04:00
|
|
|
describe "object.protected_methods" do
|
|
|
|
it "index: should handle object.protected_methods" do
|
|
|
|
class Hello
|
|
|
|
protected
|
|
|
|
def m1; end
|
|
|
|
def m2; end
|
|
|
|
end
|
|
|
|
Hello.new.protected_methods.ai(:plain => true).should == "[\n [0] m1() Hello\n [1] m2() Hello\n]"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "no index: should handle object.protected_methods" do
|
|
|
|
class Hello
|
|
|
|
protected
|
|
|
|
def m3(a,b); end
|
|
|
|
end
|
2010-11-05 22:45:24 -04:00
|
|
|
if RUBY_VERSION < '1.9.2'
|
|
|
|
Hello.new.protected_methods.ai(:plain => true, :index => false).should == "[\n m3(arg1, arg2) Hello\n]"
|
|
|
|
else
|
|
|
|
Hello.new.protected_methods.ai(:plain => true, :index => false).should == "[\n m3(a, b) Hello\n]"
|
|
|
|
end
|
2010-11-05 21:31:54 -04:00
|
|
|
end
|
2010-10-31 18:02:12 -04:00
|
|
|
end
|
|
|
|
|
2010-11-05 21:31:54 -04:00
|
|
|
describe "object.private_methods" do
|
|
|
|
it "index: should handle object.private_methods" do
|
|
|
|
class Hello
|
|
|
|
private
|
|
|
|
def m1; end
|
|
|
|
def m2; end
|
|
|
|
end
|
|
|
|
out = Hello.new.private_methods.ai(:plain => true).split("\n").grep(/m\d/)
|
|
|
|
out.first.should =~ /^\s+\[\d+\]\s+m1\(\)\s+Hello$/
|
|
|
|
out.last.should =~ /^\s+\[\d+\]\s+m2\(\)\s+Hello$/
|
|
|
|
end
|
|
|
|
|
|
|
|
it "no index: should handle object.private_methods" do
|
|
|
|
class Hello
|
|
|
|
private
|
|
|
|
def m3(a,b); end
|
|
|
|
end
|
|
|
|
out = Hello.new.private_methods.ai(:plain => true).split("\n").grep(/m\d/)
|
2010-11-05 22:45:24 -04:00
|
|
|
if RUBY_VERSION < '1.9.2'
|
|
|
|
out.first.should =~ /^\s+\[\d+\]\s+m3\(arg1, arg2\)\s+Hello$/
|
|
|
|
else
|
|
|
|
out.first.should =~ /^\s+\[\d+\]\s+m3\(a, b\)\s+Hello$/
|
|
|
|
end
|
2010-11-05 21:31:54 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "object.singleton_methods" do
|
|
|
|
it "index: should handle object.singleton_methods" do
|
|
|
|
class Hello
|
|
|
|
class << self
|
|
|
|
def m1; end
|
|
|
|
def m2; end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
out = Hello.singleton_methods.ai(:plain => true).split("\n").grep(/m\d/)
|
|
|
|
out.first.should =~ /^\s+\[\d+\]\s+m1\(\)\s+Hello$/
|
|
|
|
out.last.should =~ /^\s+\[\d+\]\s+m2\(\)\s+Hello$/
|
|
|
|
end
|
|
|
|
|
|
|
|
it "no index: should handle object.singleton_methods" do
|
|
|
|
class Hello
|
|
|
|
def self.m3(a,b); end
|
|
|
|
end
|
|
|
|
out = Hello.singleton_methods.ai(:plain => true, :index => false).split("\n").grep(/m\d/)
|
2010-11-05 22:45:24 -04:00
|
|
|
if RUBY_VERSION < '1.9.2'
|
|
|
|
out.first.should =~ /^\s+m3\(arg1, arg2\)\s+Hello$/
|
|
|
|
else
|
|
|
|
out.first.should =~ /^\s+m3\(a, b\)\s+Hello$/
|
|
|
|
end
|
2010-11-05 21:31:54 -04:00
|
|
|
end
|
2010-10-31 18:02:12 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-11-05 21:31:54 -04:00
|
|
|
describe "Class methods" do
|
|
|
|
after do
|
|
|
|
Object.instance_eval{ remove_const :Hello } if defined?(Hello)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "class.instance_methods" do
|
|
|
|
it "index: should handle unbound class.instance_methods" do
|
|
|
|
class Hello
|
|
|
|
def m1; end
|
|
|
|
def m2; end
|
|
|
|
end
|
|
|
|
out = Hello.instance_methods.ai(:plain => true).split("\n").grep(/m\d/)
|
|
|
|
out.first.should =~ /^\s+\[\s*\d+\]\s+m1\(\)\s+Hello\s\(unbound\)$/
|
|
|
|
out.last.should =~ /^\s+\[\s*\d+\]\s+m2\(\)\s+Hello\s\(unbound\)$/
|
|
|
|
end
|
|
|
|
|
|
|
|
it "no index: should handle unbound class.instance_methods" do
|
|
|
|
class Hello
|
|
|
|
def m3(a,b); end
|
|
|
|
end
|
|
|
|
out = Hello.instance_methods.ai(:plain => true, :index => false).split("\n").grep(/m\d/)
|
2010-11-05 22:45:24 -04:00
|
|
|
if RUBY_VERSION < '1.9.2'
|
|
|
|
out.first.should =~ /^\s+m3\(arg1, arg2\)\s+Hello\s\(unbound\)$/
|
|
|
|
else
|
|
|
|
out.first.should =~ /^\s+m3\(a, b\)\s+Hello\s\(unbound\)$/
|
|
|
|
end
|
2010-10-31 18:02:12 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-11-05 21:31:54 -04:00
|
|
|
describe "class.public_instance_methods" do
|
|
|
|
it "index: should handle class.public_instance_methods" do
|
|
|
|
class Hello
|
|
|
|
def m1; end
|
|
|
|
def m2; end
|
|
|
|
end
|
|
|
|
out = Hello.public_instance_methods.ai(:plain => true).split("\n").grep(/m\d/)
|
|
|
|
out.first.should =~ /^\s+\[\s*\d+\]\s+m1\(\)\s+Hello\s\(unbound\)$/
|
|
|
|
out.last.should =~ /^\s+\[\s*\d+\]\s+m2\(\)\s+Hello\s\(unbound\)$/
|
|
|
|
end
|
|
|
|
|
|
|
|
it "no index: should handle class.public_instance_methods" do
|
|
|
|
class Hello
|
|
|
|
def m3(a,b); end
|
|
|
|
end
|
|
|
|
out = Hello.public_instance_methods.ai(:plain => true, :index => false).split("\n").grep(/m\d/)
|
2010-11-05 22:45:24 -04:00
|
|
|
if RUBY_VERSION < '1.9.2'
|
|
|
|
out.first.should =~ /^\s+m3\(arg1, arg2\)\s+Hello\s\(unbound\)$/
|
|
|
|
else
|
|
|
|
out.first.should =~ /^\s+m3\(a, b\)\s+Hello\s\(unbound\)$/
|
|
|
|
end
|
2010-11-05 21:31:54 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "class.protected_instance_methods" do
|
|
|
|
it "index: should handle class.protected_instance_methods" do
|
|
|
|
class Hello
|
|
|
|
protected
|
|
|
|
def m1; end
|
|
|
|
def m2; end
|
|
|
|
end
|
|
|
|
out = Hello.protected_instance_methods.ai(:plain => true).split("\n").grep(/m\d/)
|
|
|
|
out.first.should =~ /^\s+\[\d+\]\s+m1\(\)\s+Hello\s\(unbound\)$/
|
|
|
|
out.last.should =~ /^\s+\[\d+\]\s+m2\(\)\s+Hello\s\(unbound\)$/
|
|
|
|
end
|
|
|
|
|
|
|
|
it "no index: should handle class.protected_instance_methods" do
|
|
|
|
class Hello
|
|
|
|
protected
|
|
|
|
def m3(a,b); end
|
|
|
|
end
|
|
|
|
out = Hello.protected_instance_methods.ai(:plain => true, :index => false).split("\n").grep(/m\d/)
|
2010-11-05 22:45:24 -04:00
|
|
|
if RUBY_VERSION < '1.9.2'
|
|
|
|
out.first.should =~ /^\s+m3\(arg1, arg2\)\s+Hello\s\(unbound\)$/
|
|
|
|
else
|
|
|
|
out.first.should =~ /^\s+m3\(a, b\)\s+Hello\s\(unbound\)$/
|
|
|
|
end
|
2010-11-05 21:31:54 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "class.private_instance_methods" do
|
|
|
|
it "index: should handle class.private_instance_methods" do
|
|
|
|
class Hello
|
|
|
|
private
|
|
|
|
def m1; end
|
|
|
|
def m2; end
|
|
|
|
end
|
|
|
|
out = Hello.private_instance_methods.ai(:plain => true).split("\n").grep(/m\d/)
|
|
|
|
out.first.should =~ /^\s+\[\s*\d+\]\s+m1\(\)\s+Hello\s\(unbound\)$/
|
|
|
|
out.last.should =~ /^\s+\[\s*\d+\]\s+m2\(\)\s+Hello\s\(unbound\)$/
|
|
|
|
end
|
|
|
|
|
|
|
|
it "no index: should handle class.private_instance_methods" do
|
|
|
|
class Hello
|
|
|
|
private
|
|
|
|
def m3(a,b); end
|
|
|
|
end
|
|
|
|
out = Hello.private_instance_methods.ai(:plain => true, :index => false).split("\n").grep(/m\d/)
|
2010-11-05 22:45:24 -04:00
|
|
|
if RUBY_VERSION < '1.9.2'
|
|
|
|
out.first.should =~ /^\s+m3\(arg1, arg2\)\s+Hello\s\(unbound\)$/
|
|
|
|
else
|
|
|
|
out.first.should =~ /^\s+m3\(a, b\)\s+Hello\s\(unbound\)$/
|
|
|
|
end
|
2010-10-31 18:02:12 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-11-05 22:45:24 -04:00
|
|
|
if RUBY_VERSION >= '1.9.2'
|
|
|
|
describe "Ruby 1.9.2+ Method#parameters" do
|
|
|
|
after do
|
|
|
|
Object.instance_eval{ remove_const :Hello } if defined?(Hello)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "()" do
|
|
|
|
class Hello
|
|
|
|
def m1; end
|
|
|
|
end
|
|
|
|
out = Hello.new.methods.ai(:plain => true).split("\n").grep(/m1/)
|
|
|
|
out.first.should =~ /^\s+\[\s*\d+\]\s+m1\(\)\s+Hello$/
|
|
|
|
end
|
|
|
|
|
|
|
|
it ":req" do
|
|
|
|
class Hello
|
|
|
|
def m1(a, b, c); end
|
|
|
|
end
|
|
|
|
out = Hello.new.methods.ai(:plain => true).split("\n").grep(/m1/)
|
|
|
|
out.first.should =~ /^\s+\[\s*\d+\]\s+m1\(a, b, c\)\s+Hello$/
|
|
|
|
end
|
|
|
|
|
|
|
|
it ":opt" do
|
|
|
|
class Hello
|
|
|
|
def m1(a, b = 1, c = 2); end # m1(a, *b, *c)
|
|
|
|
end
|
|
|
|
out = Hello.new.methods.ai(:plain => true).split("\n").grep(/m1/)
|
|
|
|
out.first.should =~ /^\s+\[\s*\d+\]\s+m1\(a, \*b, \*c\)\s+Hello$/
|
|
|
|
end
|
|
|
|
|
|
|
|
it ":rest" do
|
|
|
|
class Hello
|
|
|
|
def m1(*a); end # m1(*a)
|
|
|
|
end
|
|
|
|
out = Hello.new.methods.ai(:plain => true).split("\n").grep(/m1/)
|
|
|
|
out.first.should =~ /^\s+\[\s*\d+\]\s+m1\(\*a\)\s+Hello$/
|
|
|
|
end
|
|
|
|
|
|
|
|
it ":block" do
|
|
|
|
class Hello
|
|
|
|
def m1(a, b = nil, &blk); end # m1(a, *b, &blk)
|
|
|
|
end
|
|
|
|
out = Hello.new.methods.ai(:plain => true).split("\n").grep(/m1/)
|
|
|
|
out.first.should =~ /^\s+\[\s*\d+\]\s+m1\(a, \*b, &blk\)\s+Hello$/
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2010-11-06 15:45:27 -04:00
|
|
|
|
|
|
|
describe "Methods arrays" do
|
|
|
|
after do
|
|
|
|
Object.instance_eval{ remove_const :Hello } if defined?(Hello)
|
|
|
|
Object.instance_eval{ remove_const :World } if defined?(World)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "obj1.methods - obj2.methods should be awesome printed" do
|
|
|
|
class Hello
|
|
|
|
def self.m1; end
|
|
|
|
end
|
|
|
|
out = (Hello.methods - Class.methods).ai(:plain => true)
|
|
|
|
out.should == "[\n [0] m1() Hello\n]"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "obj1.methods & obj2.methods should be awesome printed" do
|
|
|
|
class Hello
|
|
|
|
def self.m1; end
|
|
|
|
def self.m2; end
|
|
|
|
end
|
|
|
|
class World
|
|
|
|
def self.m1; end
|
|
|
|
end
|
|
|
|
out = (Hello.methods & World.methods - Class.methods).ai(:plain => true)
|
|
|
|
out.should == "[\n [0] m1() Hello\n]"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "obj1.methods.grep(pattern) should be awesome printed" do
|
|
|
|
class Hello
|
|
|
|
def self.m1; end
|
|
|
|
def self.m2; end
|
|
|
|
def self.m3; end
|
|
|
|
end
|
|
|
|
out = Hello.methods.grep(/^m1$/).ai(:plain => true)
|
|
|
|
out.should == "[\n [0] m1() Hello\n]"
|
|
|
|
out = Hello.methods.grep(/^m\d$/).ai(:plain => true)
|
|
|
|
out.should == "[\n [0] m1() Hello\n [1] m2() Hello\n [2] m3() Hello\n]"
|
|
|
|
end
|
|
|
|
end
|