2014-12-31 15:59:32 -05:00
|
|
|
require 'spec_helper'
|
2010-10-30 16:50:48 -04:00
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
RSpec.describe 'Single method' do
|
2010-11-05 21:31:54 -04:00
|
|
|
after do
|
2016-11-08 21:39:25 -05:00
|
|
|
Object.instance_eval { remove_const :Hello } if defined?(Hello)
|
2010-11-05 21:31:54 -04:00
|
|
|
end
|
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
it 'plain: should handle a method with no arguments' do
|
2010-10-30 16:50:48 -04:00
|
|
|
method = ''.method(:upcase)
|
2018-05-17 08:56:39 -04:00
|
|
|
if RUBY_VERSION >= '2.4.0'
|
|
|
|
expect(method.ai(plain: true)).to eq('String#upcase(*arg1)')
|
|
|
|
else
|
|
|
|
expect(method.ai(plain: true)).to eq('String#upcase()')
|
|
|
|
end
|
2010-10-30 16:50:48 -04:00
|
|
|
end
|
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
it 'color: should handle a method with no arguments' do
|
2010-10-30 16:50:48 -04:00
|
|
|
method = ''.method(:upcase)
|
2018-05-17 08:56:39 -04:00
|
|
|
if RUBY_VERSION >= '2.4.0'
|
|
|
|
expect(method.ai).to eq("\e[1;33mString\e[0m#\e[0;35mupcase\e[0m\e[0;37m(*arg1)\e[0m")
|
|
|
|
else
|
|
|
|
expect(method.ai).to eq("\e[1;33mString\e[0m#\e[0;35mupcase\e[0m\e[0;37m()\e[0m")
|
|
|
|
end
|
2010-10-30 16:50:48 -04:00
|
|
|
end
|
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
it 'plain: should handle a method with one argument' do
|
2010-11-01 01:34:50 -04:00
|
|
|
method = ''.method(:include?)
|
2016-11-08 09:53:17 -05:00
|
|
|
expect(method.ai(plain: true)).to eq('String#include?(arg1)')
|
2010-10-30 16:50:48 -04:00
|
|
|
end
|
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
it 'color: should handle a method with one argument' do
|
2010-11-01 01:34:50 -04:00
|
|
|
method = ''.method(:include?)
|
2014-05-15 16:47:57 -04:00
|
|
|
expect(method.ai).to eq("\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
|
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
it 'plain: should handle a method with two arguments' do
|
2010-10-30 16:50:48 -04:00
|
|
|
method = ''.method(:tr)
|
2016-11-08 09:53:17 -05:00
|
|
|
expect(method.ai(plain: true)).to eq('String#tr(arg1, arg2)')
|
2010-10-30 16:50:48 -04:00
|
|
|
end
|
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
it 'color: should handle a method with two arguments' do
|
2010-10-30 16:50:48 -04:00
|
|
|
method = ''.method(:tr)
|
2014-05-15 16:47:57 -04:00
|
|
|
expect(method.ai).to eq("\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
|
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
it 'plain: should handle a method with multiple arguments' do
|
2010-10-30 16:50:48 -04:00
|
|
|
method = ''.method(:split)
|
2016-11-08 09:53:17 -05:00
|
|
|
expect(method.ai(plain: true)).to eq('String#split(*arg1)')
|
2010-10-30 16:50:48 -04:00
|
|
|
end
|
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
it 'color: should handle a method with multiple arguments' do
|
2010-10-30 16:50:48 -04:00
|
|
|
method = ''.method(:split)
|
2014-05-15 16:47:57 -04:00
|
|
|
expect(method.ai).to eq("\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
|
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
it 'plain: should handle a method defined in mixin' do
|
2010-11-01 01:34:50 -04:00
|
|
|
method = ''.method(:is_a?)
|
2016-11-08 09:53:17 -05:00
|
|
|
expect(method.ai(plain: true)).to eq('String (Kernel)#is_a?(arg1)')
|
2010-10-30 16:50:48 -04:00
|
|
|
end
|
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
it 'color: should handle a method defined in mixin' do
|
2010-11-01 01:34:50 -04:00
|
|
|
method = ''.method(:is_a?)
|
2014-05-15 16:47:57 -04:00
|
|
|
expect(method.ai).to eq("\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
|
2019-01-22 16:11:07 -05:00
|
|
|
end
|
2010-10-31 18:02:12 -04:00
|
|
|
|
2019-01-22 16:11:07 -05:00
|
|
|
RSpec.describe 'unbound methods' do
|
2016-11-08 00:07:03 -05:00
|
|
|
it 'plain: should handle an unbound method' do
|
2010-10-31 18:02:12 -04:00
|
|
|
class Hello
|
|
|
|
def world; end
|
|
|
|
end
|
|
|
|
method = Hello.instance_method(:world)
|
2016-11-08 09:53:17 -05:00
|
|
|
expect(method.ai(plain: true)).to eq('Hello (unbound)#world()')
|
2010-10-31 18:02:12 -04:00
|
|
|
end
|
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
it 'color: should handle an unbound method' do
|
2010-10-31 18:02:12 -04:00
|
|
|
class Hello
|
2016-11-08 21:39:25 -05:00
|
|
|
def world(a, b); end
|
2010-10-31 18:02:12 -04:00
|
|
|
end
|
|
|
|
method = Hello.instance_method(:world)
|
2019-01-22 16:11:07 -05:00
|
|
|
expect(method.ai).to eq("\e[1;33mHello (unbound)\e[0m#\e[0;35mworld\e[0m\e[0;37m(a, b)\e[0m")
|
2010-10-30 16:50:48 -04:00
|
|
|
end
|
|
|
|
end
|
2010-10-31 18:02:12 -04:00
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
RSpec.describe 'Object methods' do
|
2010-11-05 21:31:54 -04:00
|
|
|
after do
|
2016-11-08 21:39:25 -05:00
|
|
|
Object.instance_eval { remove_const :Hello } if defined?(Hello)
|
2010-10-31 18:02:12 -04:00
|
|
|
end
|
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
describe 'object.methods' do
|
|
|
|
it 'index: should handle object.methods' do
|
2016-11-08 09:53:17 -05:00
|
|
|
out = nil.methods.ai(plain: true).split("\n").grep(/is_a\?/).first
|
2014-05-15 16:47:57 -04:00
|
|
|
expect(out).to match(/^\s+\[\s*\d+\]\s+is_a\?\(arg1\)\s+NilClass \(Kernel\)$/)
|
2010-11-05 21:31:54 -04:00
|
|
|
end
|
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
it 'no index: should handle object.methods' do
|
2016-11-08 09:53:17 -05:00
|
|
|
out = nil.methods.ai(plain: true, index: false).split("\n").grep(/is_a\?/).first
|
2014-05-15 16:47:57 -04:00
|
|
|
expect(out).to match(/^\s+is_a\?\(arg1\)\s+NilClass \(Kernel\)$/)
|
2010-11-05 21:31:54 -04:00
|
|
|
end
|
2010-10-31 18:02:12 -04:00
|
|
|
end
|
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
describe 'object.public_methods' do
|
|
|
|
it 'index: should handle object.public_methods' do
|
2016-11-08 09:53:17 -05:00
|
|
|
out = nil.public_methods.ai(plain: true).split("\n").grep(/is_a\?/).first
|
2014-05-15 16:47:57 -04:00
|
|
|
expect(out).to match(/^\s+\[\s*\d+\]\s+is_a\?\(arg1\)\s+NilClass \(Kernel\)$/)
|
2010-11-05 21:31:54 -04:00
|
|
|
end
|
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
it 'no index: should handle object.public_methods' do
|
2016-11-08 09:53:17 -05:00
|
|
|
out = nil.public_methods.ai(plain: true, index: false).split("\n").grep(/is_a\?/).first
|
2014-05-15 16:47:57 -04:00
|
|
|
expect(out).to match(/^\s+is_a\?\(arg1\)\s+NilClass \(Kernel\)$/)
|
2010-11-05 21:31:54 -04:00
|
|
|
end
|
2010-10-31 18:02:12 -04:00
|
|
|
end
|
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
describe 'object.private_methods' do
|
|
|
|
it 'index: should handle object.private_methods' do
|
2016-11-08 09:53:17 -05:00
|
|
|
out = nil.private_methods.ai(plain: true).split("\n").grep(/sleep/).first
|
2014-05-15 16:47:57 -04:00
|
|
|
expect(out).to match(/^\s+\[\s*\d+\]\s+sleep\(\*arg1\)\s+NilClass \(Kernel\)$/)
|
2010-11-05 21:31:54 -04:00
|
|
|
end
|
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
it 'no index: should handle object.private_methods' do
|
2016-11-08 09:53:17 -05:00
|
|
|
out = nil.private_methods.ai(plain: true, index: false).split("\n").grep(/sleep/).first
|
2014-05-15 16:47:57 -04:00
|
|
|
expect(out).to match(/^\s+sleep\(\*arg1\)\s+NilClass \(Kernel\)$/)
|
2010-11-05 21:31:54 -04:00
|
|
|
end
|
2010-10-31 18:02:12 -04:00
|
|
|
end
|
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
describe 'object.protected_methods' do
|
|
|
|
it 'index: should handle object.protected_methods' do
|
2010-11-05 21:31:54 -04:00
|
|
|
class Hello
|
|
|
|
protected
|
|
|
|
def m1; end
|
|
|
|
def m2; end
|
|
|
|
end
|
2016-11-08 09:53:17 -05:00
|
|
|
expect(Hello.new.protected_methods.ai(plain: true)).to eq("[\n [0] m1() Hello\n [1] m2() Hello\n]")
|
2010-11-05 21:31:54 -04:00
|
|
|
end
|
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
it 'no index: should handle object.protected_methods' do
|
2010-11-05 21:31:54 -04:00
|
|
|
class Hello
|
|
|
|
protected
|
2016-11-08 21:39:25 -05:00
|
|
|
def m3(a, b); end
|
2010-11-05 21:31:54 -04:00
|
|
|
end
|
2010-11-05 22:45:24 -04:00
|
|
|
if RUBY_VERSION < '1.9.2'
|
2016-11-08 09:53:17 -05:00
|
|
|
expect(Hello.new.protected_methods.ai(plain: true, index: false)).to eq("[\n m3(arg1, arg2) Hello\n]")
|
2010-11-05 22:45:24 -04:00
|
|
|
else
|
2016-11-08 09:53:17 -05:00
|
|
|
expect(Hello.new.protected_methods.ai(plain: true, index: false)).to eq("[\n m3(a, b) Hello\n]")
|
2010-11-05 22:45:24 -04:00
|
|
|
end
|
2010-11-05 21:31:54 -04:00
|
|
|
end
|
2010-10-31 18:02:12 -04:00
|
|
|
end
|
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
describe 'object.private_methods' do
|
|
|
|
it 'index: should handle object.private_methods' do
|
2010-11-05 21:31:54 -04:00
|
|
|
class Hello
|
|
|
|
private
|
|
|
|
def m1; end
|
|
|
|
def m2; end
|
|
|
|
end
|
2012-09-03 15:23:31 -04:00
|
|
|
|
2016-11-08 09:53:17 -05:00
|
|
|
out = Hello.new.private_methods.ai(plain: true).split("\n").grep(/m\d/)
|
2014-05-15 16:47:57 -04:00
|
|
|
expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(\)\s+Hello$/)
|
|
|
|
expect(out.last).to match(/^\s+\[\s*\d+\]\s+m2\(\)\s+Hello$/)
|
2010-11-05 21:31:54 -04:00
|
|
|
end
|
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
it 'no index: should handle object.private_methods' do
|
2010-11-05 21:31:54 -04:00
|
|
|
class Hello
|
|
|
|
private
|
2016-11-08 21:39:25 -05:00
|
|
|
def m3(a, b); end
|
2010-11-05 21:31:54 -04:00
|
|
|
end
|
2016-11-08 09:53:17 -05:00
|
|
|
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'
|
2014-05-15 16:47:57 -04:00
|
|
|
expect(out.first).to match(/^\s+\[\s*\d+\]\s+m3\(arg1, arg2\)\s+Hello$/)
|
2010-11-05 22:45:24 -04:00
|
|
|
else
|
2014-05-15 16:47:57 -04:00
|
|
|
expect(out.first).to match(/^\s+\[\s*\d+\]\s+m3\(a, b\)\s+Hello$/)
|
2010-11-05 22:45:24 -04:00
|
|
|
end
|
2010-11-05 21:31:54 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
describe 'object.singleton_methods' do
|
|
|
|
it 'index: should handle object.singleton_methods' do
|
2010-11-05 21:31:54 -04:00
|
|
|
class Hello
|
|
|
|
class << self
|
|
|
|
def m1; end
|
|
|
|
def m2; end
|
|
|
|
end
|
|
|
|
end
|
2016-11-08 09:53:17 -05:00
|
|
|
out = Hello.singleton_methods.ai(plain: true).split("\n").grep(/m\d/)
|
2014-05-15 16:47:57 -04:00
|
|
|
expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(\)\s+Hello$/)
|
|
|
|
expect(out.last).to match(/^\s+\[\s*\d+\]\s+m2\(\)\s+Hello$/)
|
2010-11-05 21:31:54 -04:00
|
|
|
end
|
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
it 'no index: should handle object.singleton_methods' do
|
2010-11-05 21:31:54 -04:00
|
|
|
class Hello
|
2016-11-08 21:39:25 -05:00
|
|
|
def self.m3(a, b); end
|
2010-11-05 21:31:54 -04:00
|
|
|
end
|
2016-11-08 09:53:17 -05:00
|
|
|
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'
|
2014-05-15 16:47:57 -04:00
|
|
|
expect(out.first).to match(/^\s+m3\(arg1, arg2\)\s+Hello$/)
|
2010-11-05 22:45:24 -04:00
|
|
|
else
|
2014-05-15 16:47:57 -04:00
|
|
|
expect(out.first).to match(/^\s+m3\(a, b\)\s+Hello$/)
|
2010-11-05 22:45:24 -04:00
|
|
|
end
|
2010-11-05 21:31:54 -04:00
|
|
|
end
|
2010-10-31 18:02:12 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
RSpec.describe 'Class methods' do
|
2010-11-05 21:31:54 -04:00
|
|
|
after do
|
2016-11-08 21:39:25 -05:00
|
|
|
Object.instance_eval { remove_const :Hello } if defined?(Hello)
|
2010-11-05 21:31:54 -04:00
|
|
|
end
|
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
describe 'class.instance_methods' do
|
|
|
|
it 'index: should handle unbound class.instance_methods' do
|
2010-11-05 21:31:54 -04:00
|
|
|
class Hello
|
|
|
|
def m1; end
|
|
|
|
def m2; end
|
|
|
|
end
|
2016-11-08 09:53:17 -05:00
|
|
|
out = Hello.instance_methods.ai(plain: true).split("\n").grep(/m\d/)
|
2014-05-15 16:47:57 -04:00
|
|
|
expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(\)\s+Hello\s\(unbound\)$/)
|
|
|
|
expect(out.last).to match(/^\s+\[\s*\d+\]\s+m2\(\)\s+Hello\s\(unbound\)$/)
|
2010-11-05 21:31:54 -04:00
|
|
|
end
|
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
it 'no index: should handle unbound class.instance_methods' do
|
2010-11-05 21:31:54 -04:00
|
|
|
class Hello
|
2016-11-08 21:39:25 -05:00
|
|
|
def m3(a, b); end
|
2010-11-05 21:31:54 -04:00
|
|
|
end
|
2016-11-08 09:53:17 -05:00
|
|
|
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'
|
2014-05-15 16:47:57 -04:00
|
|
|
expect(out.first).to match(/^\s+m3\(arg1, arg2\)\s+Hello\s\(unbound\)$/)
|
2010-11-05 22:45:24 -04:00
|
|
|
else
|
2014-05-15 16:47:57 -04:00
|
|
|
expect(out.first).to match(/^\s+m3\(a, b\)\s+Hello\s\(unbound\)$/)
|
2010-11-05 22:45:24 -04:00
|
|
|
end
|
2010-10-31 18:02:12 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
describe 'class.public_instance_methods' do
|
|
|
|
it 'index: should handle class.public_instance_methods' do
|
2010-11-05 21:31:54 -04:00
|
|
|
class Hello
|
|
|
|
def m1; end
|
|
|
|
def m2; end
|
|
|
|
end
|
2016-11-08 09:53:17 -05:00
|
|
|
out = Hello.public_instance_methods.ai(plain: true).split("\n").grep(/m\d/)
|
2014-05-15 16:47:57 -04:00
|
|
|
expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(\)\s+Hello\s\(unbound\)$/)
|
|
|
|
expect(out.last).to match(/^\s+\[\s*\d+\]\s+m2\(\)\s+Hello\s\(unbound\)$/)
|
2010-11-05 21:31:54 -04:00
|
|
|
end
|
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
it 'no index: should handle class.public_instance_methods' do
|
2010-11-05 21:31:54 -04:00
|
|
|
class Hello
|
2016-11-08 21:39:25 -05:00
|
|
|
def m3(a, b); end
|
2010-11-05 21:31:54 -04:00
|
|
|
end
|
2016-11-08 09:53:17 -05:00
|
|
|
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'
|
2014-05-15 16:47:57 -04:00
|
|
|
expect(out.first).to match(/^\s+m3\(arg1, arg2\)\s+Hello\s\(unbound\)$/)
|
2010-11-05 22:45:24 -04:00
|
|
|
else
|
2014-05-15 16:47:57 -04:00
|
|
|
expect(out.first).to match(/^\s+m3\(a, b\)\s+Hello\s\(unbound\)$/)
|
2010-11-05 22:45:24 -04:00
|
|
|
end
|
2010-11-05 21:31:54 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
describe 'class.protected_instance_methods' do
|
|
|
|
it 'index: should handle class.protected_instance_methods' do
|
2010-11-05 21:31:54 -04:00
|
|
|
class Hello
|
|
|
|
protected
|
|
|
|
def m1; end
|
|
|
|
def m2; end
|
|
|
|
end
|
2016-11-08 09:53:17 -05:00
|
|
|
out = Hello.protected_instance_methods.ai(plain: true).split("\n").grep(/m\d/)
|
2014-05-15 16:47:57 -04:00
|
|
|
expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(\)\s+Hello\s\(unbound\)$/)
|
|
|
|
expect(out.last).to match(/^\s+\[\s*\d+\]\s+m2\(\)\s+Hello\s\(unbound\)$/)
|
2010-11-05 21:31:54 -04:00
|
|
|
end
|
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
it 'no index: should handle class.protected_instance_methods' do
|
2010-11-05 21:31:54 -04:00
|
|
|
class Hello
|
|
|
|
protected
|
2016-11-08 21:39:25 -05:00
|
|
|
def m3(a, b); end
|
2010-11-05 21:31:54 -04:00
|
|
|
end
|
2016-11-08 09:53:17 -05:00
|
|
|
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'
|
2014-05-15 16:47:57 -04:00
|
|
|
expect(out.first).to match(/^\s+m3\(arg1, arg2\)\s+Hello\s\(unbound\)$/)
|
2010-11-05 22:45:24 -04:00
|
|
|
else
|
2014-05-15 16:47:57 -04:00
|
|
|
expect(out.first).to match(/^\s+m3\(a, b\)\s+Hello\s\(unbound\)$/)
|
2010-11-05 22:45:24 -04:00
|
|
|
end
|
2010-11-05 21:31:54 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
describe 'class.private_instance_methods' do
|
|
|
|
it 'index: should handle class.private_instance_methods' do
|
2010-11-05 21:31:54 -04:00
|
|
|
class Hello
|
|
|
|
private
|
|
|
|
def m1; end
|
|
|
|
def m2; end
|
|
|
|
end
|
2016-11-08 09:53:17 -05:00
|
|
|
out = Hello.private_instance_methods.ai(plain: true).split("\n").grep(/m\d/)
|
2014-05-15 16:47:57 -04:00
|
|
|
expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(\)\s+Hello\s\(unbound\)$/)
|
|
|
|
expect(out.last).to match(/^\s+\[\s*\d+\]\s+m2\(\)\s+Hello\s\(unbound\)$/)
|
2010-11-05 21:31:54 -04:00
|
|
|
end
|
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
it 'no index: should handle class.private_instance_methods' do
|
2010-11-05 21:31:54 -04:00
|
|
|
class Hello
|
|
|
|
private
|
2016-11-08 21:39:25 -05:00
|
|
|
def m3(a, b); end
|
2010-11-05 21:31:54 -04:00
|
|
|
end
|
2016-11-08 09:53:17 -05:00
|
|
|
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'
|
2014-05-15 16:47:57 -04:00
|
|
|
expect(out.first).to match(/^\s+m3\(arg1, arg2\)\s+Hello\s\(unbound\)$/)
|
2010-11-05 22:45:24 -04:00
|
|
|
else
|
2014-05-15 16:47:57 -04:00
|
|
|
expect(out.first).to match(/^\s+m3\(a, b\)\s+Hello\s\(unbound\)$/)
|
2010-11-05 22:45:24 -04:00
|
|
|
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'
|
2016-11-08 00:07:03 -05:00
|
|
|
RSpec.describe 'Ruby 1.9.2+ Method#parameters' do
|
2011-11-08 16:36:22 -05:00
|
|
|
before do
|
|
|
|
stub_dotfile!
|
|
|
|
end
|
|
|
|
|
2010-11-05 22:45:24 -04:00
|
|
|
after do
|
2016-11-08 21:39:25 -05:00
|
|
|
Object.instance_eval { remove_const :Hello } if defined?(Hello)
|
2010-11-05 22:45:24 -04:00
|
|
|
end
|
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
it '()' do
|
2010-11-05 22:45:24 -04:00
|
|
|
class Hello
|
|
|
|
def m1; end
|
|
|
|
end
|
2016-11-08 09:53:17 -05:00
|
|
|
out = Hello.new.methods.ai(plain: true).split("\n").grep(/m1/)
|
2014-05-15 16:47:57 -04:00
|
|
|
expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(\)\s+Hello$/)
|
2010-11-05 22:45:24 -04:00
|
|
|
end
|
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
it ':req' do
|
2010-11-05 22:45:24 -04:00
|
|
|
class Hello
|
|
|
|
def m1(a, b, c); end
|
|
|
|
end
|
2016-11-08 09:53:17 -05:00
|
|
|
out = Hello.new.methods.ai(plain: true).split("\n").grep(/m1/)
|
2014-05-15 16:47:57 -04:00
|
|
|
expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(a, b, c\)\s+Hello$/)
|
2010-11-05 22:45:24 -04:00
|
|
|
end
|
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
it ':opt' do
|
2010-11-05 22:45:24 -04:00
|
|
|
class Hello
|
|
|
|
def m1(a, b = 1, c = 2); end # m1(a, *b, *c)
|
|
|
|
end
|
2016-11-08 09:53:17 -05:00
|
|
|
out = Hello.new.methods.ai(plain: true).split("\n").grep(/m1/)
|
2014-05-15 16:47:57 -04:00
|
|
|
expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(a, \*b, \*c\)\s+Hello$/)
|
2010-11-05 22:45:24 -04:00
|
|
|
end
|
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
it ':rest' do
|
2010-11-05 22:45:24 -04:00
|
|
|
class Hello
|
|
|
|
def m1(*a); end # m1(*a)
|
|
|
|
end
|
2016-11-08 09:53:17 -05:00
|
|
|
out = Hello.new.methods.ai(plain: true).split("\n").grep(/m1/)
|
2014-05-15 16:47:57 -04:00
|
|
|
expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(\*a\)\s+Hello$/)
|
2010-11-05 22:45:24 -04:00
|
|
|
end
|
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
it ':block' do
|
2010-11-05 22:45:24 -04:00
|
|
|
class Hello
|
|
|
|
def m1(a, b = nil, &blk); end # m1(a, *b, &blk)
|
|
|
|
end
|
2016-11-08 09:53:17 -05:00
|
|
|
out = Hello.new.methods.ai(plain: true).split("\n").grep(/m1/)
|
2014-05-15 16:47:57 -04:00
|
|
|
expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(a, \*b, &blk\)\s+Hello$/)
|
2010-11-05 22:45:24 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2010-11-06 15:45:27 -04:00
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
RSpec.describe 'Methods arrays' do
|
2010-11-06 15:45:27 -04:00
|
|
|
after do
|
2016-11-08 21:39:25 -05:00
|
|
|
Object.instance_eval { remove_const :Hello } if defined?(Hello)
|
|
|
|
Object.instance_eval { remove_const :World } if defined?(World)
|
2010-11-06 15:45:27 -04:00
|
|
|
end
|
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
it 'obj1.methods - obj2.methods should be awesome printed' do
|
2011-11-08 16:36:22 -05:00
|
|
|
stub_dotfile!
|
2010-11-06 15:45:27 -04:00
|
|
|
class Hello
|
|
|
|
def self.m1; end
|
|
|
|
end
|
2016-11-08 09:53:17 -05:00
|
|
|
out = (Hello.methods - Class.methods).ai(plain: true)
|
2014-05-15 16:47:57 -04:00
|
|
|
expect(out).to eq("[\n [0] m1() Hello\n]")
|
2010-11-06 15:45:27 -04:00
|
|
|
end
|
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
it 'obj1.methods & obj2.methods should be awesome printed' do
|
2011-11-08 16:36:22 -05:00
|
|
|
stub_dotfile!
|
2010-11-06 15:45:27 -04:00
|
|
|
class Hello
|
|
|
|
def self.m1; end
|
|
|
|
def self.m2; end
|
|
|
|
end
|
|
|
|
class World
|
|
|
|
def self.m1; end
|
|
|
|
end
|
2016-11-08 09:53:17 -05:00
|
|
|
out = (Hello.methods & World.methods - Class.methods).ai(plain: true)
|
2014-05-15 16:47:57 -04:00
|
|
|
expect(out).to eq("[\n [0] m1() Hello\n]")
|
2010-11-06 15:45:27 -04:00
|
|
|
end
|
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
it 'obj1.methods.grep(pattern) should be awesome printed' do
|
2011-11-08 16:36:22 -05:00
|
|
|
stub_dotfile!
|
2010-11-06 15:45:27 -04:00
|
|
|
class Hello
|
|
|
|
def self.m1; end
|
|
|
|
def self.m2; end
|
|
|
|
def self.m3; end
|
|
|
|
end
|
2016-11-08 09:53:17 -05:00
|
|
|
out = Hello.methods.grep(/^m1$/).ai(plain: true)
|
2014-05-15 16:47:57 -04:00
|
|
|
expect(out).to eq("[\n [0] m1() Hello\n]")
|
2016-11-08 09:53:17 -05:00
|
|
|
out = Hello.methods.grep(/^m\d$/).ai(plain: true)
|
2014-05-15 16:47:57 -04:00
|
|
|
expect(out).to eq("[\n [0] m1() Hello\n [1] m2() Hello\n [2] m3() Hello\n]")
|
2010-11-06 15:45:27 -04:00
|
|
|
end
|
2010-11-09 22:48:43 -05:00
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
it 'obj1.methods.grep(pattern, &block) should pass the matching string within the block' do
|
2010-11-09 22:48:43 -05:00
|
|
|
class Hello
|
|
|
|
def self.m_one; end
|
|
|
|
def self.m_two; end
|
|
|
|
end
|
|
|
|
|
2012-09-03 16:57:10 -04:00
|
|
|
out = Hello.methods.sort.grep(/^m_(.+)$/) { $1.to_sym }
|
2014-05-15 16:47:57 -04:00
|
|
|
expect(out).to eq([:one, :two])
|
2010-11-09 22:48:43 -05:00
|
|
|
end
|
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
it 'obj1.methods.grep(pattern, &block) should be awesome printed' do
|
2011-11-08 16:36:22 -05:00
|
|
|
stub_dotfile!
|
2010-11-09 22:48:43 -05:00
|
|
|
class Hello
|
|
|
|
def self.m0; end
|
|
|
|
def self.none; end
|
|
|
|
def self.m1; end
|
|
|
|
def self.one; end
|
|
|
|
end
|
|
|
|
|
2016-11-08 09:53:17 -05:00
|
|
|
out = Hello.methods.grep(/^m(\d)$/) { %w(none one)[$1.to_i] }.ai(plain: true)
|
2014-05-15 16:47:57 -04:00
|
|
|
expect(out).to eq("[\n [0] none() Hello\n [1] one() Hello\n]")
|
2010-11-09 22:48:43 -05:00
|
|
|
end
|
2011-05-06 20:23:26 -04:00
|
|
|
|
2016-06-21 09:07:59 -04:00
|
|
|
# See https://github.com/awesome-print/awesome_print/issues/30 for details.
|
2016-11-08 00:07:03 -05:00
|
|
|
it 'grepping methods and converting them to_sym should work as expected' do
|
2011-05-06 20:23:26 -04:00
|
|
|
class Hello
|
|
|
|
private
|
|
|
|
def him; end
|
|
|
|
|
|
|
|
def his
|
|
|
|
private_methods.grep(/^h..$/) { |n| n.to_sym }
|
|
|
|
end
|
|
|
|
|
|
|
|
def her
|
|
|
|
private_methods.grep(/^.e.$/) { |n| n.to_sym }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
hello = Hello.new
|
2016-11-08 21:39:25 -05:00
|
|
|
expect((hello.send(:his) - hello.send(:her)).sort_by { |x| x.to_s }).to eq([:him, :his])
|
2011-05-06 20:23:26 -04:00
|
|
|
end
|
2011-12-05 16:49:13 -05:00
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
it 'appending garbage to methods array should not raise error' do
|
2016-11-08 21:39:25 -05:00
|
|
|
arr = 42.methods << [:wtf]
|
2016-11-08 09:53:17 -05:00
|
|
|
expect { arr.ai(plain: true) }.not_to raise_error
|
2011-12-13 19:01:14 -05:00
|
|
|
if RUBY_VERSION < '1.9.2'
|
2016-11-08 09:53:17 -05:00
|
|
|
expect(arr.ai(plain: true)).to match(/\s+wtf\(\?\)\s+\?/) # [ :wtf ].to_s => "wtf"
|
2011-12-13 19:01:14 -05:00
|
|
|
else
|
2016-11-08 09:53:17 -05:00
|
|
|
expect(arr.ai(plain: true)).to match(/\s+\[:wtf\]\(\?\)\s+\?/) # [ :wtf ].to_s => [:wtf]
|
2011-12-13 19:01:14 -05:00
|
|
|
end
|
2011-12-05 16:49:13 -05:00
|
|
|
end
|
2010-11-06 15:45:27 -04:00
|
|
|
end
|