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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
|
require File.expand_path('../../../spec_helper', __FILE__)
platform_is_not :windows do
describe "Process.getrlimit" do
it "returns a two-element Array of Integers" do
result = Process.getrlimit Process::RLIMIT_CORE
result.size.should == 2
result.first.should be_kind_of(Integer)
result.last.should be_kind_of(Integer)
end
context "when passed an Object" do
before do
@resource = Process::RLIMIT_CORE
end
it "calls #to_int to convert to an Integer" do
obj = mock("process getrlimit integer")
obj.should_receive(:to_int).and_return(@resource)
Process.getrlimit(obj).should == Process.getrlimit(@resource)
end
it "raises a TypeError if #to_int does not return an Integer" do
obj = mock("process getrlimit integer")
obj.should_receive(:to_int).and_return(nil)
lambda { Process.getrlimit(obj) }.should raise_error(TypeError)
end
end
ruby_version_is ""..."1.9" do
it "raises a TypeError when passed a String" do
lambda { Process.getrlimit "CORE" }.should raise_error(TypeError)
end
deviates_on :rubinius do
it "raises a TypeError when passed a Symbol" do
lambda { Process.getrlimit :CORE }.should raise_error(TypeError)
end
end
end
ruby_version_is "1.9" do
context "when passed a Symbol" do
platform_is_not :openbsd do
it "coerces :AS into RLIMIT_AS" do
Process.getrlimit(:AS).should == Process.getrlimit(Process::RLIMIT_AS)
end
end
it "coerces :CORE into RLIMIT_CORE" do
Process.getrlimit(:CORE).should == Process.getrlimit(Process::RLIMIT_CORE)
end
it "coerces :CPU into RLIMIT_CPU" do
Process.getrlimit(:CPU).should == Process.getrlimit(Process::RLIMIT_CPU)
end
it "coerces :DATA into RLIMIT_DATA" do
Process.getrlimit(:DATA).should == Process.getrlimit(Process::RLIMIT_DATA)
end
it "coerces :FSIZE into RLIMIT_FSIZE" do
Process.getrlimit(:FSIZE).should == Process.getrlimit(Process::RLIMIT_FSIZE)
end
it "coerces :NOFILE into RLIMIT_NOFILE" do
Process.getrlimit(:NOFILE).should == Process.getrlimit(Process::RLIMIT_NOFILE)
end
it "coerces :STACK into RLIMIT_STACK" do
Process.getrlimit(:STACK).should == Process.getrlimit(Process::RLIMIT_STACK)
end
platform_is_not :solaris do
it "coerces :MEMLOCK into RLIMIT_MEMLOCK" do
Process.getrlimit(:MEMLOCK).should == Process.getrlimit(Process::RLIMIT_MEMLOCK)
end
it "coerces :NPROC into RLIMIT_NPROC" do
Process.getrlimit(:NPROC).should == Process.getrlimit(Process::RLIMIT_NPROC)
end
it "coerces :RSS into RLIMIT_RSS" do
Process.getrlimit(:RSS).should == Process.getrlimit(Process::RLIMIT_RSS)
end
end
platform_is :os => [:netbsd, :freebsd] do
it "coerces :SBSIZE into RLIMIT_SBSIZE" do
Process.getrlimit(:SBSIZE).should == Process.getrlimit(Process::RLIMIT_SBSIZE)
end
end
platform_is :linux do
it "coerces :RTPRIO into RLIMIT_RTPRIO" do
Process.getrlimit(:RTPRIO).should == Process.getrlimit(Process::RLIMIT_RTPRIO)
end
it "coerces :RTTIME into RLIMIT_RTTIME" do
Process.getrlimit(:RTTIME).should == Process.getrlimit(Process::RLIMIT_RTTIME)
end
it "coerces :SIGPENDING into RLIMIT_SIGPENDING" do
Process.getrlimit(:SIGPENDING).should == Process.getrlimit(Process::RLIMIT_SIGPENDING)
end
it "coerces :MSGQUEUE into RLIMIT_MSGQUEUE" do
Process.getrlimit(:MSGQUEUE).should == Process.getrlimit(Process::RLIMIT_MSGQUEUE)
end
it "coerces :NICE into RLIMIT_NICE" do
Process.getrlimit(:NICE).should == Process.getrlimit(Process::RLIMIT_NICE)
end
end
it "raises ArgumentError when passed an unknown resource" do
lambda { Process.getrlimit(:FOO) }.should raise_error(ArgumentError)
end
end
context "when passed a String" do
platform_is_not :openbsd do
it "coerces 'AS' into RLIMIT_AS" do
Process.getrlimit("AS").should == Process.getrlimit(Process::RLIMIT_AS)
end
end
it "coerces 'CORE' into RLIMIT_CORE" do
Process.getrlimit("CORE").should == Process.getrlimit(Process::RLIMIT_CORE)
end
it "coerces 'CPU' into RLIMIT_CPU" do
Process.getrlimit("CPU").should == Process.getrlimit(Process::RLIMIT_CPU)
end
it "coerces 'DATA' into RLIMIT_DATA" do
Process.getrlimit("DATA").should == Process.getrlimit(Process::RLIMIT_DATA)
end
it "coerces 'FSIZE' into RLIMIT_FSIZE" do
Process.getrlimit("FSIZE").should == Process.getrlimit(Process::RLIMIT_FSIZE)
end
it "coerces 'NOFILE' into RLIMIT_NOFILE" do
Process.getrlimit("NOFILE").should == Process.getrlimit(Process::RLIMIT_NOFILE)
end
it "coerces 'STACK' into RLIMIT_STACK" do
Process.getrlimit("STACK").should == Process.getrlimit(Process::RLIMIT_STACK)
end
platform_is_not :solaris do
it "coerces 'MEMLOCK' into RLIMIT_MEMLOCK" do
Process.getrlimit("MEMLOCK").should == Process.getrlimit(Process::RLIMIT_MEMLOCK)
end
it "coerces 'NPROC' into RLIMIT_NPROC" do
Process.getrlimit("NPROC").should == Process.getrlimit(Process::RLIMIT_NPROC)
end
it "coerces 'RSS' into RLIMIT_RSS" do
Process.getrlimit("RSS").should == Process.getrlimit(Process::RLIMIT_RSS)
end
end
platform_is :os => [:netbsd, :freebsd] do
it "coerces 'SBSIZE' into RLIMIT_SBSIZE" do
Process.getrlimit("SBSIZE").should == Process.getrlimit(Process::RLIMIT_SBSIZE)
end
end
platform_is :linux do
it "coerces 'RTPRIO' into RLIMIT_RTPRIO" do
Process.getrlimit("RTPRIO").should == Process.getrlimit(Process::RLIMIT_RTPRIO)
end
it "coerces 'RTTIME' into RLIMIT_RTTIME" do
Process.getrlimit("RTTIME").should == Process.getrlimit(Process::RLIMIT_RTTIME)
end
it "coerces 'SIGPENDING' into RLIMIT_SIGPENDING" do
Process.getrlimit("SIGPENDING").should == Process.getrlimit(Process::RLIMIT_SIGPENDING)
end
it "coerces 'MSGQUEUE' into RLIMIT_MSGQUEUE" do
Process.getrlimit("MSGQUEUE").should == Process.getrlimit(Process::RLIMIT_MSGQUEUE)
end
it "coerces 'NICE' into RLIMIT_NICE" do
Process.getrlimit("NICE").should == Process.getrlimit(Process::RLIMIT_NICE)
end
end
it "raises ArgumentError when passed an unknown resource" do
lambda { Process.getrlimit("FOO") }.should raise_error(ArgumentError)
end
end
context "when passed on Object" do
before do
@resource = Process::RLIMIT_CORE
end
it "calls #to_str to convert to a String" do
obj = mock("process getrlimit string")
obj.should_receive(:to_str).and_return("CORE")
obj.should_not_receive(:to_int)
Process.getrlimit(obj).should == Process.getrlimit(@resource)
end
it "calls #to_int if #to_str does not return a String" do
obj = mock("process getrlimit string")
obj.should_receive(:to_str).and_return(nil)
obj.should_receive(:to_int).and_return(@resource)
Process.getrlimit(obj).should == Process.getrlimit(@resource)
end
end
end
end
end
|