1require_relative '../../spec_helper'
2require_relative 'fixtures/classes'
3require_relative '../../fixtures/reflection'
4
5# TODO: rewrite
6describe "Kernel#private_methods" do
7  it "returns a list of the names of privately accessible methods in the object" do
8    m = KernelSpecs::Methods.private_methods(false)
9    m.should include(:shichi)
10    m = KernelSpecs::Methods.new.private_methods(false)
11    m.should include(:juu_shi)
12  end
13
14  it "returns a list of the names of privately accessible methods in the object and its ancestors and mixed-in modules" do
15    m = (KernelSpecs::Methods.private_methods(false) & KernelSpecs::Methods.private_methods)
16
17    m.should include(:shichi)
18    m = KernelSpecs::Methods.new.private_methods
19    m.should include(:juu_shi)
20  end
21
22  it "returns private methods mixed in to the metaclass" do
23    m = KernelSpecs::Methods.new
24    m.extend(KernelSpecs::Methods::MetaclassMethods)
25    m.private_methods.should include(:shoo)
26  end
27end
28
29describe :kernel_private_methods_supers, shared: true do
30  it "returns a unique list for an object extended by a module" do
31    m = ReflectSpecs.oed.private_methods(*@object)
32    m.select { |x| x == :pri }.sort.should == [:pri]
33  end
34
35  it "returns a unique list for a class including a module" do
36    m = ReflectSpecs::D.new.private_methods(*@object)
37    m.select { |x| x == :pri }.sort.should == [:pri]
38  end
39
40  it "returns a unique list for a subclass of a class that includes a module" do
41    m = ReflectSpecs::E.new.private_methods(*@object)
42    m.select { |x| x == :pri }.sort.should == [:pri]
43  end
44end
45
46describe :kernel_private_methods_with_falsy, shared: true do
47  it "returns a list of private methods in without its ancestors" do
48    ReflectSpecs::F.private_methods(@object).select{|m|/_pri\z/ =~ m}.sort.should == [:ds_pri, :fs_pri]
49    ReflectSpecs::F.new.private_methods(@object).should == [:f_pri]
50  end
51end
52
53describe "Kernel#private_methods" do
54  describe "when not passed an argument" do
55    it_behaves_like :kernel_private_methods_supers, nil, []
56  end
57
58  describe "when passed true" do
59    it_behaves_like :kernel_private_methods_supers, nil, true
60  end
61
62  describe "when passed false" do
63    it_behaves_like :kernel_private_methods_with_falsy, nil, false
64  end
65
66  describe "when passed nil" do
67    it_behaves_like :kernel_private_methods_with_falsy, nil, nil
68  end
69end
70