File: protected_instance_methods_spec.rb

package info (click to toggle)
jruby 1.7.26-1%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 84,572 kB
  • sloc: ruby: 669,910; java: 253,056; xml: 35,152; ansic: 9,187; yacc: 7,267; cpp: 5,244; sh: 1,036; makefile: 345; jsp: 48; tcl: 40
file content (81 lines) | stat: -rw-r--r-- 3,398 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../../../fixtures/reflection', __FILE__)

# TODO: rewrite
describe "Module#protected_instance_methods" do
  ruby_version_is ""..."1.9" do
    it "returns a list of protected methods in module and its ancestors" do
      methods = ModuleSpecs::CountsMixin.protected_instance_methods
      methods.should include('protected_3')

      methods = ModuleSpecs::CountsParent.protected_instance_methods
      methods.should include('protected_3')
      methods.should include('protected_2')

      methods = ModuleSpecs::CountsChild.protected_instance_methods
      methods.should include('protected_3')
      methods.should include('protected_2')
      methods.should include('protected_1')
    end

    it "when passed false as a parameter, should return only methods defined in that module" do
      ModuleSpecs::CountsMixin.protected_instance_methods(false).should == ['protected_3']
      ModuleSpecs::CountsParent.protected_instance_methods(false).should == ['protected_2']
      ModuleSpecs::CountsChild.protected_instance_methods(false).should == ['protected_1']
    end
  end

  ruby_version_is "1.9" do
    it "returns a list of protected methods in module and its ancestors" do
      methods = ModuleSpecs::CountsMixin.protected_instance_methods
      methods.should include(:protected_3)

      methods = ModuleSpecs::CountsParent.protected_instance_methods
      methods.should include(:protected_3)
      methods.should include(:protected_2)

      methods = ModuleSpecs::CountsChild.protected_instance_methods
      methods.should include(:protected_3)
      methods.should include(:protected_2)
      methods.should include(:protected_1)
    end

    it "when passed false as a parameter, should return only methods defined in that module" do
      ModuleSpecs::CountsMixin.protected_instance_methods(false).should == [:protected_3]
      ModuleSpecs::CountsParent.protected_instance_methods(false).should == [:protected_2]
      ModuleSpecs::CountsChild.protected_instance_methods(false).should == [:protected_1]
    end
  end

  it "default list should be the same as passing true as an argument" do
    ModuleSpecs::CountsMixin.protected_instance_methods(true).should ==
      ModuleSpecs::CountsMixin.protected_instance_methods
    ModuleSpecs::CountsParent.protected_instance_methods(true).should ==
      ModuleSpecs::CountsParent.protected_instance_methods
    ModuleSpecs::CountsChild.protected_instance_methods(true).should ==
      ModuleSpecs::CountsChild.protected_instance_methods
  end
end

describe :module_protected_instance_methods_supers, :shared => true do
  it "returns a unique list for a class including a module" do
    m = ReflectSpecs::D.protected_instance_methods(*@object)
    m.select { |x| x == stasy(:pro) }.sort.should == [stasy(:pro)]
  end

  it "returns a unique list for a subclass" do
    m = ReflectSpecs::E.protected_instance_methods(*@object)
    m.select { |x| x == stasy(:pro) }.sort.should == [stasy(:pro)]
  end
end

describe "Module#protected_instance_methods" do
  describe "when not passed an argument" do
    it_behaves_like :module_protected_instance_methods_supers, nil, []
  end

  describe "when passed true" do
    it_behaves_like :module_protected_instance_methods_supers, nil, true
  end
end