Skip to content
This repository
Browse code

Fixed Process.getrlimit specs.

  • Loading branch information...
commit c19ab6475c7bb05af940207667cc364ec5f55316 1 parent f5c9e01
Brian Shirai brixen authored

Showing 1 changed file with 163 additions and 15 deletions. Show diff stats Hide diff stats

  1. +163 15 core/process/getrlimit_spec.rb
178 core/process/getrlimit_spec.rb
... ... @@ -1,13 +1,48 @@
1 1 require File.expand_path('../../../spec_helper', __FILE__)
2 2
3   -# see setrlimit_spec.rb
  3 +platform_is_not :windows do
  4 + describe "Process.getrlimit" do
  5 + it "returns a two-element Array of Integers" do
  6 + result = Process.getrlimit Process::RLIMIT_CORE
  7 + result.size.should == 2
  8 + result.first.should be_kind_of(Integer)
  9 + result.last.should be_kind_of(Integer)
  10 + end
  11 +
  12 + context "when passed an Object" do
  13 + before do
  14 + @resource = Process::RLIMIT_CORE
  15 + end
  16 +
  17 + it "calls #to_int to convert to an Integer" do
  18 + obj = mock("process getrlimit integer")
  19 + obj.should_receive(:to_int).and_return(@resource)
  20 +
  21 + Process.getrlimit(obj).should == Process.getrlimit(@resource)
  22 + end
4 23
5   -describe "Process.getrlimit" do
6   - it "needs to be reviewed for spec completeness"
  24 + it "raises a TypeError if #to_int does not return an Integer" do
  25 + obj = mock("process getrlimit integer")
  26 + obj.should_receive(:to_int).and_return(nil)
7 27
8   - ruby_version_is "1.9" do
9   - platform_is_not :windows do
10   - describe "symbol to constant cooercion" do
  28 + lambda { Process.getrlimit(obj) }.should raise_error(TypeError)
  29 + end
  30 + end
  31 +
  32 + ruby_version_is ""..."1.9" do
  33 + it "raises a TypeError when passed a String" do
  34 + lambda { Process.getrlimit "CORE" }.should raise_error(TypeError)
  35 + end
  36 +
  37 + deviates_on :rubinius do
  38 + it "raises a TypeError when passed a Symbol" do
  39 + lambda { Process.getrlimit :CORE }.should raise_error(TypeError)
  40 + end
  41 + end
  42 + end
  43 +
  44 + ruby_version_is "1.9" do
  45 + context "when passed a Symbol" do
11 46
12 47 platform_is_not :openbsd do
13 48 it "coerces :AS into RLIMIT_AS" do
@@ -59,19 +94,132 @@
59 94 end
60 95 end
61 96
62   - describe "not present in Rubinius" do
63   - it "coerces :RTPRIO into RLIMIT_RTPRIO"
64   - it "coerces :RTTIME into RLIMIT_RTTIME"
65   - it "coerces :SIGPENDING into RLIMIT_SIGPENDING"
66   - it "coerces :MSGQUEUE into RLIMIT_MSGQUEUE"
67   - it "coerces :NICE into RLIMIT_NICE"
  97 + platform_is :linux do
  98 + it "coerces :RTPRIO into RLIMIT_RTPRIO" do
  99 + Process.getrlimit(:RTPRIO).should == Process.getrlimit(Process::RLIMIT_RTPRIO)
  100 + end
  101 +
  102 + it "coerces :RTTIME into RLIMIT_RTTIME" do
  103 + Process.getrlimit(:RTTIME).should == Process.getrlimit(Process::RLIMIT_RTTIME)
  104 + end
  105 +
  106 + it "coerces :SIGPENDING into RLIMIT_SIGPENDING" do
  107 + Process.getrlimit(:SIGPENDING).should == Process.getrlimit(Process::RLIMIT_SIGPENDING)
  108 + end
  109 +
  110 + it "coerces :MSGQUEUE into RLIMIT_MSGQUEUE" do
  111 + Process.getrlimit(:MSGQUEUE).should == Process.getrlimit(Process::RLIMIT_MSGQUEUE)
  112 + end
  113 +
  114 + it "coerces :NICE into RLIMIT_NICE" do
  115 + Process.getrlimit(:NICE).should == Process.getrlimit(Process::RLIMIT_NICE)
  116 + end
  117 + end
  118 +
  119 + it "raises ArgumentError when passed an unknown resource" do
  120 + lambda { Process.getrlimit(:FOO) }.should raise_error(ArgumentError)
68 121 end
  122 + end
69 123
70   - context "when passed an unknown resource" do
71   - it "raises ArgumentError" do
72   - lambda { Process.getrlimit(:FOO) }.should raise_error(ArgumentError)
  124 + context "when passed a String" do
  125 +
  126 + platform_is_not :openbsd do
  127 + it "coerces 'AS' into RLIMIT_AS" do
  128 + Process.getrlimit("AS").should == Process.getrlimit(Process::RLIMIT_AS)
73 129 end
74 130 end
  131 +
  132 + it "coerces 'CORE' into RLIMIT_CORE" do
  133 + Process.getrlimit("CORE").should == Process.getrlimit(Process::RLIMIT_CORE)
  134 + end
  135 +
  136 + it "coerces 'CPU' into RLIMIT_CPU" do
  137 + Process.getrlimit("CPU").should == Process.getrlimit(Process::RLIMIT_CPU)
  138 + end
  139 +
  140 + it "coerces 'DATA' into RLIMIT_DATA" do
  141 + Process.getrlimit("DATA").should == Process.getrlimit(Process::RLIMIT_DATA)
  142 + end
  143 +
  144 + it "coerces 'FSIZE' into RLIMIT_FSIZE" do
  145 + Process.getrlimit("FSIZE").should == Process.getrlimit(Process::RLIMIT_FSIZE)
  146 + end
  147 +
  148 + it "coerces 'NOFILE' into RLIMIT_NOFILE" do
  149 + Process.getrlimit("NOFILE").should == Process.getrlimit(Process::RLIMIT_NOFILE)
  150 + end
  151 +
  152 + it "coerces 'STACK' into RLIMIT_STACK" do
  153 + Process.getrlimit("STACK").should == Process.getrlimit(Process::RLIMIT_STACK)
  154 + end
  155 +
  156 + platform_is_not :solaris do
  157 + it "coerces 'MEMLOCK' into RLIMIT_MEMLOCK" do
  158 + Process.getrlimit("MEMLOCK").should == Process.getrlimit(Process::RLIMIT_MEMLOCK)
  159 + end
  160 +
  161 + it "coerces 'NPROC' into RLIMIT_NPROC" do
  162 + Process.getrlimit("NPROC").should == Process.getrlimit(Process::RLIMIT_NPROC)
  163 + end
  164 +
  165 + it "coerces 'RSS' into RLIMIT_RSS" do
  166 + Process.getrlimit("RSS").should == Process.getrlimit(Process::RLIMIT_RSS)
  167 + end
  168 + end
  169 +
  170 + platform_is :os => [:netbsd, :freebsd] do
  171 + it "coerces 'SBSIZE' into RLIMIT_SBSIZE" do
  172 + Process.getrlimit("SBSIZE").should == Process.getrlimit(Process::RLIMIT_SBSIZE)
  173 + end
  174 + end
  175 +
  176 + platform_is :linux do
  177 + it "coerces 'RTPRIO' into RLIMIT_RTPRIO" do
  178 + Process.getrlimit("RTPRIO").should == Process.getrlimit(Process::RLIMIT_RTPRIO)
  179 + end
  180 +
  181 + it "coerces 'RTTIME' into RLIMIT_RTTIME" do
  182 + Process.getrlimit("RTTIME").should == Process.getrlimit(Process::RLIMIT_RTTIME)
  183 + end
  184 +
  185 + it "coerces 'SIGPENDING' into RLIMIT_SIGPENDING" do
  186 + Process.getrlimit("SIGPENDING").should == Process.getrlimit(Process::RLIMIT_SIGPENDING)
  187 + end
  188 +
  189 + it "coerces 'MSGQUEUE' into RLIMIT_MSGQUEUE" do
  190 + Process.getrlimit("MSGQUEUE").should == Process.getrlimit(Process::RLIMIT_MSGQUEUE)
  191 + end
  192 +
  193 + it "coerces 'NICE' into RLIMIT_NICE" do
  194 + Process.getrlimit("NICE").should == Process.getrlimit(Process::RLIMIT_NICE)
  195 + end
  196 + end
  197 +
  198 + it "raises ArgumentError when passed an unknown resource" do
  199 + lambda { Process.getrlimit("FOO") }.should raise_error(ArgumentError)
  200 + end
  201 + end
  202 +
  203 + context "when passed on Object" do
  204 + before do
  205 + @resource = Process::RLIMIT_CORE
  206 + end
  207 +
  208 + it "calls #to_str to convert to a String" do
  209 + obj = mock("process getrlimit string")
  210 + obj.should_receive(:to_str).and_return("CORE")
  211 + obj.should_not_receive(:to_int)
  212 +
  213 + Process.getrlimit(obj).should == Process.getrlimit(@resource)
  214 + end
  215 +
  216 + it "calls #to_int if #to_str does not return a String" do
  217 + obj = mock("process getrlimit string")
  218 + obj.should_receive(:to_str).and_return(nil)
  219 + obj.should_receive(:to_int).and_return(@resource)
  220 +
  221 + Process.getrlimit(obj).should == Process.getrlimit(@resource)
  222 + end
75 223 end
76 224 end
77 225 end

0 comments on commit c19ab64

Please sign in to comment.
Something went wrong with that request. Please try again.