summaryrefslogtreecommitdiff
path: root/spec/ruby/core/numeric/arg_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/numeric/arg_spec.rb')
-rw-r--r--spec/ruby/core/numeric/arg_spec.rb38
1 files changed, 35 insertions, 3 deletions
diff --git a/spec/ruby/core/numeric/arg_spec.rb b/spec/ruby/core/numeric/arg_spec.rb
index 0729a29226..4fd059d7fc 100644
--- a/spec/ruby/core/numeric/arg_spec.rb
+++ b/spec/ruby/core/numeric/arg_spec.rb
@@ -1,6 +1,38 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/complex/numeric/arg', __FILE__)
+require_relative '../../spec_helper'
describe "Numeric#arg" do
- it_behaves_like(:numeric_arg, :arg)
+ before :each do
+ @numbers = [
+ 20,
+ Rational(3, 4),
+ bignum_value,
+ infinity_value
+ ]
+ end
+
+ it "returns 0 if positive" do
+ @numbers.each do |number|
+ number.arg.should == 0
+ end
+ end
+
+ it "returns Pi if negative" do
+ @numbers.each do |number|
+ (0-number).arg.should == Math::PI
+ end
+ end
+
+ describe "with a Numeric subclass" do
+ it "returns 0 if self#<(0) returns false" do
+ numeric = mock_numeric('positive')
+ numeric.should_receive(:<).with(0).and_return(false)
+ numeric.arg.should == 0
+ end
+
+ it "returns Pi if self#<(0) returns true" do
+ numeric = mock_numeric('positive')
+ numeric.should_receive(:<).with(0).and_return(true)
+ numeric.arg.should == Math::PI
+ end
+ end
end