summaryrefslogtreecommitdiff
path: root/spec/ruby/core/numeric
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/numeric')
-rw-r--r--spec/ruby/core/numeric/abs2_spec.rb2
-rw-r--r--spec/ruby/core/numeric/abs_spec.rb5
-rw-r--r--spec/ruby/core/numeric/angle_spec.rb6
-rw-r--r--spec/ruby/core/numeric/arg_spec.rb6
-rw-r--r--spec/ruby/core/numeric/ceil_spec.rb4
-rw-r--r--spec/ruby/core/numeric/clone_spec.rb30
-rw-r--r--spec/ruby/core/numeric/coerce_spec.rb49
-rw-r--r--spec/ruby/core/numeric/comparison_spec.rb4
-rw-r--r--spec/ruby/core/numeric/conj_spec.rb6
-rw-r--r--spec/ruby/core/numeric/conjugate_spec.rb6
-rw-r--r--spec/ruby/core/numeric/denominator_spec.rb2
-rw-r--r--spec/ruby/core/numeric/div_spec.rb10
-rw-r--r--spec/ruby/core/numeric/divmod_spec.rb4
-rw-r--r--spec/ruby/core/numeric/dup_spec.rb16
-rw-r--r--spec/ruby/core/numeric/eql_spec.rb4
-rw-r--r--spec/ruby/core/numeric/fdiv_spec.rb3
-rw-r--r--spec/ruby/core/numeric/finite_spec.rb12
-rw-r--r--spec/ruby/core/numeric/floor_spec.rb4
-rw-r--r--spec/ruby/core/numeric/i_spec.rb2
-rw-r--r--spec/ruby/core/numeric/imag_spec.rb6
-rw-r--r--spec/ruby/core/numeric/imaginary_spec.rb6
-rw-r--r--spec/ruby/core/numeric/infinite_spec.rb12
-rw-r--r--spec/ruby/core/numeric/integer_spec.rb6
-rw-r--r--spec/ruby/core/numeric/magnitude_spec.rb5
-rw-r--r--spec/ruby/core/numeric/modulo_spec.rb4
-rw-r--r--spec/ruby/core/numeric/negative_spec.rb60
-rw-r--r--spec/ruby/core/numeric/nonzero_spec.rb4
-rw-r--r--spec/ruby/core/numeric/numerator_spec.rb2
-rw-r--r--spec/ruby/core/numeric/numeric_spec.rb2
-rw-r--r--spec/ruby/core/numeric/phase_spec.rb6
-rw-r--r--spec/ruby/core/numeric/polar_spec.rb50
-rw-r--r--spec/ruby/core/numeric/positive_spec.rb60
-rw-r--r--spec/ruby/core/numeric/quo_spec.rb32
-rw-r--r--spec/ruby/core/numeric/real_spec.rb34
-rw-r--r--spec/ruby/core/numeric/rect_spec.rb6
-rw-r--r--spec/ruby/core/numeric/rectangular_spec.rb6
-rw-r--r--spec/ruby/core/numeric/remainder_spec.rb7
-rw-r--r--spec/ruby/core/numeric/round_spec.rb4
-rw-r--r--spec/ruby/core/numeric/shared/abs.rb4
-rw-r--r--spec/ruby/core/numeric/shared/arg.rb38
-rw-r--r--spec/ruby/core/numeric/shared/conj.rb20
-rw-r--r--spec/ruby/core/numeric/shared/imag.rb26
-rw-r--r--spec/ruby/core/numeric/shared/quo.rb7
-rw-r--r--spec/ruby/core/numeric/shared/rect.rb28
-rw-r--r--spec/ruby/core/numeric/shared/step.rb289
-rw-r--r--spec/ruby/core/numeric/singleton_method_added_spec.rb12
-rw-r--r--spec/ruby/core/numeric/step_spec.rb102
-rw-r--r--spec/ruby/core/numeric/to_c_spec.rb2
-rw-r--r--spec/ruby/core/numeric/to_int_spec.rb4
-rw-r--r--spec/ruby/core/numeric/truncate_spec.rb4
-rw-r--r--spec/ruby/core/numeric/uminus_spec.rb2
-rw-r--r--spec/ruby/core/numeric/uplus_spec.rb4
-rw-r--r--spec/ruby/core/numeric/zero_spec.rb8
53 files changed, 579 insertions, 458 deletions
diff --git a/spec/ruby/core/numeric/abs2_spec.rb b/spec/ruby/core/numeric/abs2_spec.rb
index f1094845fb..0e60cd0ae7 100644
--- a/spec/ruby/core/numeric/abs2_spec.rb
+++ b/spec/ruby/core/numeric/abs2_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Numeric#abs2" do
before :each do
diff --git a/spec/ruby/core/numeric/abs_spec.rb b/spec/ruby/core/numeric/abs_spec.rb
index 4aa25359a2..8bec50e337 100644
--- a/spec/ruby/core/numeric/abs_spec.rb
+++ b/spec/ruby/core/numeric/abs_spec.rb
@@ -1,5 +1,6 @@
-require File.expand_path('../shared/abs', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/abs'
describe "Numeric#abs" do
- it_behaves_like(:numeric_abs, :abs)
+ it_behaves_like :numeric_abs, :abs
end
diff --git a/spec/ruby/core/numeric/angle_spec.rb b/spec/ruby/core/numeric/angle_spec.rb
index d7134168b3..bb38165777 100644
--- a/spec/ruby/core/numeric/angle_spec.rb
+++ b/spec/ruby/core/numeric/angle_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/complex/numeric/arg', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/arg'
describe "Numeric#angle" do
- it_behaves_like(:numeric_arg, :angle)
+ it_behaves_like :numeric_arg, :angle
end
diff --git a/spec/ruby/core/numeric/arg_spec.rb b/spec/ruby/core/numeric/arg_spec.rb
index 0729a29226..ba3b57c687 100644
--- a/spec/ruby/core/numeric/arg_spec.rb
+++ b/spec/ruby/core/numeric/arg_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/complex/numeric/arg', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/arg'
describe "Numeric#arg" do
- it_behaves_like(:numeric_arg, :arg)
+ it_behaves_like :numeric_arg, :arg
end
diff --git a/spec/ruby/core/numeric/ceil_spec.rb b/spec/ruby/core/numeric/ceil_spec.rb
index 6e7d8211fb..00c856e79b 100644
--- a/spec/ruby/core/numeric/ceil_spec.rb
+++ b/spec/ruby/core/numeric/ceil_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Numeric#ceil" do
it "converts self to a Float (using #to_f) and returns the #ceil'ed result" do
diff --git a/spec/ruby/core/numeric/clone_spec.rb b/spec/ruby/core/numeric/clone_spec.rb
new file mode 100644
index 0000000000..423cec85dd
--- /dev/null
+++ b/spec/ruby/core/numeric/clone_spec.rb
@@ -0,0 +1,30 @@
+require_relative '../../spec_helper'
+
+describe "Numeric#clone" do
+ it "returns self" do
+ value = 1
+ value.clone.should equal(value)
+
+ subclass = Class.new(Numeric)
+ value = subclass.new
+ value.clone.should equal(value)
+ end
+
+ it "does not change frozen status" do
+ 1.clone.frozen?.should == true
+ end
+
+ it "accepts optional keyword argument :freeze" do
+ value = 1
+ value.clone(freeze: true).should equal(value)
+ end
+
+ it "raises ArgumentError if passed freeze: false" do
+ -> { 1.clone(freeze: false) }.should raise_error(ArgumentError, /can't unfreeze/)
+ end
+
+ it "does not change frozen status if passed freeze: nil" do
+ value = 1
+ value.clone(freeze: nil).should equal(value)
+ end
+end
diff --git a/spec/ruby/core/numeric/coerce_spec.rb b/spec/ruby/core/numeric/coerce_spec.rb
index 820d900dd5..4c4416d30b 100644
--- a/spec/ruby/core/numeric/coerce_spec.rb
+++ b/spec/ruby/core/numeric/coerce_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Numeric#coerce" do
before :each do
@@ -25,52 +25,35 @@ describe "Numeric#coerce" do
class << a; true; end
# watch it explode
- lambda { a.coerce(b) }.should raise_error(TypeError)
+ -> { a.coerce(b) }.should raise_error(TypeError)
end
end
- it "calls #to_f to convert other if self responds to #to_f" do
- # Do not use NumericSpecs::Subclass here, because coerce checks the classes of the receiver
- # and arguments before calling #to_f.
- other = mock("numeric")
- lambda { @obj.coerce(other) }.should raise_error(TypeError)
- end
-
it "returns [other.to_f, self.to_f] if self and other are instances of different classes" do
- result = @obj.coerce(2.5)
- result.should == [2.5, 10.5]
- result.first.should be_kind_of(Float)
- result.last.should be_kind_of(Float)
-
- result = @obj.coerce(3)
- result.should == [3.0, 10.5]
- result.first.should be_kind_of(Float)
- result.last.should be_kind_of(Float)
-
- result = @obj.coerce("4.4")
- result.should == [4.4, 10.5]
- result.first.should be_kind_of(Float)
- result.last.should be_kind_of(Float)
+ @obj.coerce(2.5).should == [2.5, 10.5]
+ @obj.coerce(3).should == [3.0, 10.5]
+ @obj.coerce("4.4").should == [4.4, 10.5]
+ @obj.coerce(bignum_value).should == [bignum_value.to_f, 10.5]
+ end
- result = @obj.coerce(bignum_value)
- result.should == [bignum_value.to_f, 10.5]
- result.first.should be_kind_of(Float)
- result.last.should be_kind_of(Float)
+ it "raise TypeError if they are instances of different classes and other does not respond to #to_f" do
+ other = mock("numeric")
+ -> { @obj.coerce(other) }.should raise_error(TypeError)
end
it "raises a TypeError when passed nil" do
- lambda { @obj.coerce(nil) }.should raise_error(TypeError)
+ -> { @obj.coerce(nil) }.should raise_error(TypeError)
end
it "raises a TypeError when passed a boolean" do
- lambda { @obj.coerce(false) }.should raise_error(TypeError)
+ -> { @obj.coerce(false) }.should raise_error(TypeError)
end
it "raises a TypeError when passed a Symbol" do
- lambda { @obj.coerce(:symbol) }.should raise_error(TypeError)
+ -> { @obj.coerce(:symbol) }.should raise_error(TypeError)
end
- it "raises an ArgumentError when passed a String" do
- lambda { @obj.coerce("test") }.should raise_error(ArgumentError)
+ it "raises an ArgumentError when passed a non-numeric String" do
+ -> { @obj.coerce("test") }.should raise_error(ArgumentError)
end
end
diff --git a/spec/ruby/core/numeric/comparison_spec.rb b/spec/ruby/core/numeric/comparison_spec.rb
index 59676c01ad..4b4d52501a 100644
--- a/spec/ruby/core/numeric/comparison_spec.rb
+++ b/spec/ruby/core/numeric/comparison_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Numeric#<=>" do
before :each do
diff --git a/spec/ruby/core/numeric/conj_spec.rb b/spec/ruby/core/numeric/conj_spec.rb
index 8fa0fd9457..7d4777ca60 100644
--- a/spec/ruby/core/numeric/conj_spec.rb
+++ b/spec/ruby/core/numeric/conj_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/complex/numeric/conj', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/conj'
describe "Numeric#conj" do
- it_behaves_like(:numeric_conj, :conj)
+ it_behaves_like :numeric_conj, :conj
end
diff --git a/spec/ruby/core/numeric/conjugate_spec.rb b/spec/ruby/core/numeric/conjugate_spec.rb
index f7e095514e..99854766e7 100644
--- a/spec/ruby/core/numeric/conjugate_spec.rb
+++ b/spec/ruby/core/numeric/conjugate_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/complex/numeric/conj', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/conj'
describe "Numeric#conjugate" do
- it_behaves_like(:numeric_conj, :conjugate)
+ it_behaves_like :numeric_conj, :conjugate
end
diff --git a/spec/ruby/core/numeric/denominator_spec.rb b/spec/ruby/core/numeric/denominator_spec.rb
index 3ae4530c18..34729446a2 100644
--- a/spec/ruby/core/numeric/denominator_spec.rb
+++ b/spec/ruby/core/numeric/denominator_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Numeric#denominator" do
# The Numeric child classes override this method, so their behaviour is
diff --git a/spec/ruby/core/numeric/div_spec.rb b/spec/ruby/core/numeric/div_spec.rb
index f3f82c3ca4..53917b84c9 100644
--- a/spec/ruby/core/numeric/div_spec.rb
+++ b/spec/ruby/core/numeric/div_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Numeric#div" do
before :each do
@@ -15,8 +15,8 @@ describe "Numeric#div" do
end
it "raises ZeroDivisionError for 0" do
- lambda { @obj.div(0) }.should raise_error(ZeroDivisionError)
- lambda { @obj.div(0.0) }.should raise_error(ZeroDivisionError)
- lambda { @obj.div(Complex(0,0)) }.should raise_error(ZeroDivisionError)
+ -> { @obj.div(0) }.should raise_error(ZeroDivisionError)
+ -> { @obj.div(0.0) }.should raise_error(ZeroDivisionError)
+ -> { @obj.div(Complex(0,0)) }.should raise_error(ZeroDivisionError)
end
end
diff --git a/spec/ruby/core/numeric/divmod_spec.rb b/spec/ruby/core/numeric/divmod_spec.rb
index 5de2d86c77..8d5259bbcd 100644
--- a/spec/ruby/core/numeric/divmod_spec.rb
+++ b/spec/ruby/core/numeric/divmod_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Numeric#divmod" do
before :each do
diff --git a/spec/ruby/core/numeric/dup_spec.rb b/spec/ruby/core/numeric/dup_spec.rb
new file mode 100644
index 0000000000..189a7ef44d
--- /dev/null
+++ b/spec/ruby/core/numeric/dup_spec.rb
@@ -0,0 +1,16 @@
+require_relative '../../spec_helper'
+
+describe "Numeric#dup" do
+ it "returns self" do
+ value = 1
+ value.dup.should equal(value)
+
+ subclass = Class.new(Numeric)
+ value = subclass.new
+ value.dup.should equal(value)
+ end
+
+ it "does not change frozen status" do
+ 1.dup.frozen?.should == true
+ end
+end
diff --git a/spec/ruby/core/numeric/eql_spec.rb b/spec/ruby/core/numeric/eql_spec.rb
index 367a298a74..b33e00e51f 100644
--- a/spec/ruby/core/numeric/eql_spec.rb
+++ b/spec/ruby/core/numeric/eql_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Numeric#eql?" do
before :each do
diff --git a/spec/ruby/core/numeric/fdiv_spec.rb b/spec/ruby/core/numeric/fdiv_spec.rb
index 4b27382012..e97fa77f79 100644
--- a/spec/ruby/core/numeric/fdiv_spec.rb
+++ b/spec/ruby/core/numeric/fdiv_spec.rb
@@ -1,5 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/quo', __FILE__)
+require_relative '../../spec_helper'
describe "Numeric#fdiv" do
it "coerces self with #to_f" do
diff --git a/spec/ruby/core/numeric/finite_spec.rb b/spec/ruby/core/numeric/finite_spec.rb
index 9fb2252845..05b5eebbd6 100644
--- a/spec/ruby/core/numeric/finite_spec.rb
+++ b/spec/ruby/core/numeric/finite_spec.rb
@@ -1,10 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
-ruby_version_is "2.4" do
- describe "Numeric#finite?" do
- it "returns true by default" do
- o = mock_numeric("finite")
- o.finite?.should be_true
- end
+describe "Numeric#finite?" do
+ it "returns true by default" do
+ o = mock_numeric("finite")
+ o.finite?.should be_true
end
end
diff --git a/spec/ruby/core/numeric/floor_spec.rb b/spec/ruby/core/numeric/floor_spec.rb
index c68ed0423a..80a4868e4d 100644
--- a/spec/ruby/core/numeric/floor_spec.rb
+++ b/spec/ruby/core/numeric/floor_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Numeric#floor" do
before :each do
diff --git a/spec/ruby/core/numeric/i_spec.rb b/spec/ruby/core/numeric/i_spec.rb
index fae4fefe3d..621ecc09ec 100644
--- a/spec/ruby/core/numeric/i_spec.rb
+++ b/spec/ruby/core/numeric/i_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Numeric#i" do
it "returns a Complex object" do
diff --git a/spec/ruby/core/numeric/imag_spec.rb b/spec/ruby/core/numeric/imag_spec.rb
index a80e42d265..b9e343cee9 100644
--- a/spec/ruby/core/numeric/imag_spec.rb
+++ b/spec/ruby/core/numeric/imag_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/complex/numeric/imag', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/imag'
describe "Numeric#imag" do
- it_behaves_like(:numeric_imag, :imag)
+ it_behaves_like :numeric_imag, :imag
end
diff --git a/spec/ruby/core/numeric/imaginary_spec.rb b/spec/ruby/core/numeric/imaginary_spec.rb
index 41226569b3..ec708cb505 100644
--- a/spec/ruby/core/numeric/imaginary_spec.rb
+++ b/spec/ruby/core/numeric/imaginary_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/complex/numeric/imag', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/imag'
describe "Numeric#imaginary" do
- it_behaves_like(:numeric_imag, :imaginary)
+ it_behaves_like :numeric_imag, :imaginary
end
diff --git a/spec/ruby/core/numeric/infinite_spec.rb b/spec/ruby/core/numeric/infinite_spec.rb
index a527cb4370..3ea7825c8c 100644
--- a/spec/ruby/core/numeric/infinite_spec.rb
+++ b/spec/ruby/core/numeric/infinite_spec.rb
@@ -1,10 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
-ruby_version_is "2.4" do
- describe "Numeric#infinite?" do
- it "returns nil by default" do
- o = mock_numeric("infinite")
- o.infinite?.should == nil
- end
+describe "Numeric#infinite?" do
+ it "returns nil by default" do
+ o = mock_numeric("infinite")
+ o.infinite?.should == nil
end
end
diff --git a/spec/ruby/core/numeric/integer_spec.rb b/spec/ruby/core/numeric/integer_spec.rb
index acff8eb830..adbac4d7aa 100644
--- a/spec/ruby/core/numeric/integer_spec.rb
+++ b/spec/ruby/core/numeric/integer_spec.rb
@@ -1,8 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Numeric#integer?" do
it "returns false" do
- NumericSpecs::Subclass.new.integer?.should == false
+ NumericSpecs::Subclass.new.should_not.integer?
end
end
diff --git a/spec/ruby/core/numeric/magnitude_spec.rb b/spec/ruby/core/numeric/magnitude_spec.rb
index 947ee69730..1371dff21f 100644
--- a/spec/ruby/core/numeric/magnitude_spec.rb
+++ b/spec/ruby/core/numeric/magnitude_spec.rb
@@ -1,5 +1,6 @@
-require File.expand_path('../shared/abs', __FILE__)
+require_relative "../../spec_helper"
+require_relative 'shared/abs'
describe "Numeric#magnitude" do
- it_behaves_like(:numeric_abs, :magnitude)
+ it_behaves_like :numeric_abs, :magnitude
end
diff --git a/spec/ruby/core/numeric/modulo_spec.rb b/spec/ruby/core/numeric/modulo_spec.rb
index a6ea7a8f14..e3dc7e56f3 100644
--- a/spec/ruby/core/numeric/modulo_spec.rb
+++ b/spec/ruby/core/numeric/modulo_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe :numeric_modulo_19, shared: true do
it "returns self - other * self.div(other)" do
diff --git a/spec/ruby/core/numeric/negative_spec.rb b/spec/ruby/core/numeric/negative_spec.rb
index 27e5c65fe3..9c6f95fd87 100644
--- a/spec/ruby/core/numeric/negative_spec.rb
+++ b/spec/ruby/core/numeric/negative_spec.rb
@@ -1,43 +1,41 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
-ruby_version_is "2.3" do
- describe "Numeric#negative?" do
- describe "on positive numbers" do
- it "returns false" do
- 1.negative?.should be_false
- 0.1.negative?.should be_false
- end
+describe "Numeric#negative?" do
+ describe "on positive numbers" do
+ it "returns false" do
+ 1.negative?.should be_false
+ 0.1.negative?.should be_false
end
+ end
- describe "on zero" do
- it "returns false" do
- 0.negative?.should be_false
- 0.0.negative?.should be_false
- end
+ describe "on zero" do
+ it "returns false" do
+ 0.negative?.should be_false
+ 0.0.negative?.should be_false
end
+ end
- describe "on negative numbers" do
- it "returns true" do
- -1.negative?.should be_true
- -0.1.negative?.should be_true
- end
+ describe "on negative numbers" do
+ it "returns true" do
+ -1.negative?.should be_true
+ -0.1.negative?.should be_true
end
end
+end
- describe "Numeric#negative?" do
- before(:each) do
- @obj = NumericSpecs::Subclass.new
- end
+describe "Numeric#negative?" do
+ before(:each) do
+ @obj = NumericSpecs::Subclass.new
+ end
- it "returns true if self is less than 0" do
- @obj.should_receive(:<).with(0).and_return(true)
- @obj.negative?.should == true
- end
+ it "returns true if self is less than 0" do
+ @obj.should_receive(:<).with(0).and_return(true)
+ @obj.should.negative?
+ end
- it "returns false if self is greater than 0" do
- @obj.should_receive(:<).with(0).and_return(false)
- @obj.negative?.should == false
- end
+ it "returns false if self is greater than 0" do
+ @obj.should_receive(:<).with(0).and_return(false)
+ @obj.should_not.negative?
end
end
diff --git a/spec/ruby/core/numeric/nonzero_spec.rb b/spec/ruby/core/numeric/nonzero_spec.rb
index 55b7880d0e..464ed4f4f8 100644
--- a/spec/ruby/core/numeric/nonzero_spec.rb
+++ b/spec/ruby/core/numeric/nonzero_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Numeric#nonzero?" do
before :each do
diff --git a/spec/ruby/core/numeric/numerator_spec.rb b/spec/ruby/core/numeric/numerator_spec.rb
index 4a20f8792a..668df8b797 100644
--- a/spec/ruby/core/numeric/numerator_spec.rb
+++ b/spec/ruby/core/numeric/numerator_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Numeric#numerator" do
before :all do
diff --git a/spec/ruby/core/numeric/numeric_spec.rb b/spec/ruby/core/numeric/numeric_spec.rb
index 9429ab55a0..2bcf2a1175 100644
--- a/spec/ruby/core/numeric/numeric_spec.rb
+++ b/spec/ruby/core/numeric/numeric_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Numeric" do
it "includes Comparable" do
diff --git a/spec/ruby/core/numeric/phase_spec.rb b/spec/ruby/core/numeric/phase_spec.rb
index 7c408db83b..bc1995303f 100644
--- a/spec/ruby/core/numeric/phase_spec.rb
+++ b/spec/ruby/core/numeric/phase_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/complex/numeric/arg', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/arg'
describe "Numeric#phase" do
- it_behaves_like(:numeric_arg, :phase)
+ it_behaves_like :numeric_arg, :phase
end
diff --git a/spec/ruby/core/numeric/polar_spec.rb b/spec/ruby/core/numeric/polar_spec.rb
index 5492483215..b594e408b2 100644
--- a/spec/ruby/core/numeric/polar_spec.rb
+++ b/spec/ruby/core/numeric/polar_spec.rb
@@ -1,6 +1,50 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/complex/numeric/polar', __FILE__)
+require_relative '../../spec_helper'
describe "Numeric#polar" do
- it_behaves_like(:numeric_polar, :polar)
+ before :each do
+ @pos_numbers = [
+ 1,
+ 3898172610**9,
+ 987.18273,
+ Float::MAX,
+ Rational(13,7),
+ infinity_value,
+ ]
+ @neg_numbers = @pos_numbers.map {|n| -n}
+ @numbers = @pos_numbers + @neg_numbers
+ @numbers.push(0, 0.0)
+ end
+
+ it "returns a two-element Array" do
+ @numbers.each do |number|
+ number.polar.should be_an_instance_of(Array)
+ number.polar.size.should == 2
+ end
+ end
+
+ it "sets the first value to the absolute value of self" do
+ @numbers.each do |number|
+ number.polar.first.should == number.abs
+ end
+ end
+
+ it "sets the last value to 0 if self is positive" do
+ (@numbers - @neg_numbers).each do |number|
+ number.should >= 0
+ number.polar.last.should == 0
+ end
+ end
+
+ it "sets the last value to Pi if self is negative" do
+ @neg_numbers.each do |number|
+ number.should < 0
+ number.polar.last.should == Math::PI
+ end
+ end
+
+ it "returns [NaN, NaN] if self is NaN" do
+ nan_value.polar.size.should == 2
+ nan_value.polar.first.nan?.should be_true
+ nan_value.polar.last.nan?.should be_true
+ end
end
diff --git a/spec/ruby/core/numeric/positive_spec.rb b/spec/ruby/core/numeric/positive_spec.rb
index 516de7db89..3b831b4d34 100644
--- a/spec/ruby/core/numeric/positive_spec.rb
+++ b/spec/ruby/core/numeric/positive_spec.rb
@@ -1,43 +1,41 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
-ruby_version_is "2.3" do
- describe "Numeric#positive?" do
- describe "on positive numbers" do
- it "returns true" do
- 1.positive?.should be_true
- 0.1.positive?.should be_true
- end
+describe "Numeric#positive?" do
+ describe "on positive numbers" do
+ it "returns true" do
+ 1.positive?.should be_true
+ 0.1.positive?.should be_true
end
+ end
- describe "on zero" do
- it "returns false" do
- 0.positive?.should be_false
- 0.0.positive?.should be_false
- end
+ describe "on zero" do
+ it "returns false" do
+ 0.positive?.should be_false
+ 0.0.positive?.should be_false
end
+ end
- describe "on negative numbers" do
- it "returns false" do
- -1.positive?.should be_false
- -0.1.positive?.should be_false
- end
+ describe "on negative numbers" do
+ it "returns false" do
+ -1.positive?.should be_false
+ -0.1.positive?.should be_false
end
end
+end
- describe "Numeric#positive?" do
- before(:each) do
- @obj = NumericSpecs::Subclass.new
- end
+describe "Numeric#positive?" do
+ before(:each) do
+ @obj = NumericSpecs::Subclass.new
+ end
- it "returns true if self is greater than 0" do
- @obj.should_receive(:>).with(0).and_return(true)
- @obj.positive?.should == true
- end
+ it "returns true if self is greater than 0" do
+ @obj.should_receive(:>).with(0).and_return(true)
+ @obj.should.positive?
+ end
- it "returns false if self is less than 0" do
- @obj.should_receive(:>).with(0).and_return(false)
- @obj.positive?.should == false
- end
+ it "returns false if self is less than 0" do
+ @obj.should_receive(:>).with(0).and_return(false)
+ @obj.should_not.positive?
end
end
diff --git a/spec/ruby/core/numeric/quo_spec.rb b/spec/ruby/core/numeric/quo_spec.rb
index 24c752aac1..6e3ce7a374 100644
--- a/spec/ruby/core/numeric/quo_spec.rb
+++ b/spec/ruby/core/numeric/quo_spec.rb
@@ -1,6 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/quo', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Numeric#quo" do
it "returns the result of self divided by the given Integer as a Rational" do
@@ -16,11 +15,11 @@ describe "Numeric#quo" do
end
it "raises a ZeroDivisionError when the given Integer is 0" do
- lambda { 0.quo(0) }.should raise_error(ZeroDivisionError)
- lambda { 10.quo(0) }.should raise_error(ZeroDivisionError)
- lambda { -10.quo(0) }.should raise_error(ZeroDivisionError)
- lambda { bignum_value.quo(0) }.should raise_error(ZeroDivisionError)
- lambda { -bignum_value.quo(0) }.should raise_error(ZeroDivisionError)
+ -> { 0.quo(0) }.should raise_error(ZeroDivisionError)
+ -> { 10.quo(0) }.should raise_error(ZeroDivisionError)
+ -> { -10.quo(0) }.should raise_error(ZeroDivisionError)
+ -> { bignum_value.quo(0) }.should raise_error(ZeroDivisionError)
+ -> { (-bignum_value).quo(0) }.should raise_error(ZeroDivisionError)
end
it "calls #to_r to convert the object to a Rational" do
@@ -34,16 +33,16 @@ describe "Numeric#quo" do
obj = NumericSpecs::Subclass.new
obj.should_receive(:to_r).and_return(1)
- lambda { obj.quo(19) }.should raise_error(TypeError)
+ -> { obj.quo(19) }.should raise_error(TypeError)
end
it "raises a TypeError when given a non-Integer" do
- lambda {
+ -> {
(obj = mock('x')).should_not_receive(:to_int)
13.quo(obj)
}.should raise_error(TypeError)
- lambda { 13.quo("10") }.should raise_error(TypeError)
- lambda { 13.quo(:symbol) }.should raise_error(TypeError)
+ -> { 13.quo("10") }.should raise_error(TypeError)
+ -> { 13.quo(:symbol) }.should raise_error(TypeError)
end
it "returns the result of calling self#/ with other" do
@@ -52,4 +51,13 @@ describe "Numeric#quo" do
obj.quo(19).should == 1.quo(20)
end
+
+ it "raises a ZeroDivisionError if the given argument is zero and not a Float" do
+ -> { 1.quo(0) }.should raise_error(ZeroDivisionError)
+ end
+
+ it "returns infinity if the given argument is zero and is a Float" do
+ (1.quo(0.0)).to_s.should == 'Infinity'
+ (-1.quo(0.0)).to_s.should == '-Infinity'
+ end
end
diff --git a/spec/ruby/core/numeric/real_spec.rb b/spec/ruby/core/numeric/real_spec.rb
index 3e34410155..2d2499bcce 100644
--- a/spec/ruby/core/numeric/real_spec.rb
+++ b/spec/ruby/core/numeric/real_spec.rb
@@ -1,13 +1,37 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/complex/numeric/real', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Numeric#real" do
- it_behaves_like(:numeric_real, :real)
+ before :each do
+ @numbers = [
+ 20, # Integer
+ 398.72, # Float
+ Rational(3, 4), # Rational
+ bignum_value, # Bignum
+ infinity_value,
+ nan_value
+ ].map{ |n| [n, -n] }.flatten
+ end
+
+ it "returns self" do
+ @numbers.each do |number|
+ if number.to_f.nan?
+ number.real.nan?.should be_true
+ else
+ number.real.should == number
+ end
+ end
+ end
+
+ it "raises an ArgumentError if given any arguments" do
+ @numbers.each do |number|
+ -> { number.real(number) }.should raise_error(ArgumentError)
+ end
+ end
end
describe "Numeric#real?" do
it "returns true" do
- NumericSpecs::Subclass.new.real?.should == true
+ NumericSpecs::Subclass.new.should.real?
end
end
diff --git a/spec/ruby/core/numeric/rect_spec.rb b/spec/ruby/core/numeric/rect_spec.rb
index 88d5ee3881..79a144c5a4 100644
--- a/spec/ruby/core/numeric/rect_spec.rb
+++ b/spec/ruby/core/numeric/rect_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/rect', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/rect'
describe "Numeric#rect" do
- it_behaves_like(:numeric_rect, :rect)
+ it_behaves_like :numeric_rect, :rect
end
diff --git a/spec/ruby/core/numeric/rectangular_spec.rb b/spec/ruby/core/numeric/rectangular_spec.rb
index b34100ca74..2c68985a16 100644
--- a/spec/ruby/core/numeric/rectangular_spec.rb
+++ b/spec/ruby/core/numeric/rectangular_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/rect', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/rect'
describe "Numeric#rectangular" do
- it_behaves_like(:numeric_rect, :rectangular)
+ it_behaves_like :numeric_rect, :rectangular
end
diff --git a/spec/ruby/core/numeric/remainder_spec.rb b/spec/ruby/core/numeric/remainder_spec.rb
index 6d26d39669..674fa22d8e 100644
--- a/spec/ruby/core/numeric/remainder_spec.rb
+++ b/spec/ruby/core/numeric/remainder_spec.rb
@@ -1,11 +1,14 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Numeric#remainder" do
before :each do
@obj = NumericSpecs::Subclass.new
@result = mock("Numeric#% result")
@other = mock("Passed Object")
+ ruby_version_is "3.3" do
+ @other.should_receive(:coerce).with(@obj).and_return([@obj, @other])
+ end
end
it "returns the result of calling self#% with other if self is 0" do
diff --git a/spec/ruby/core/numeric/round_spec.rb b/spec/ruby/core/numeric/round_spec.rb
index 6e79decfa0..47c5837693 100644
--- a/spec/ruby/core/numeric/round_spec.rb
+++ b/spec/ruby/core/numeric/round_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Numeric#round" do
before :each do
diff --git a/spec/ruby/core/numeric/shared/abs.rb b/spec/ruby/core/numeric/shared/abs.rb
index 406c9f3981..c3dadccfd6 100644
--- a/spec/ruby/core/numeric/shared/abs.rb
+++ b/spec/ruby/core/numeric/shared/abs.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
describe :numeric_abs, shared: true do
before :each do
diff --git a/spec/ruby/core/numeric/shared/arg.rb b/spec/ruby/core/numeric/shared/arg.rb
new file mode 100644
index 0000000000..c8e7ad8333
--- /dev/null
+++ b/spec/ruby/core/numeric/shared/arg.rb
@@ -0,0 +1,38 @@
+require_relative '../../../spec_helper'
+
+describe :numeric_arg, shared: true do
+ before :each do
+ @numbers = [
+ 20,
+ Rational(3, 4),
+ bignum_value,
+ infinity_value
+ ]
+ end
+
+ it "returns 0 if positive" do
+ @numbers.each do |number|
+ number.send(@method).should == 0
+ end
+ end
+
+ it "returns Pi if negative" do
+ @numbers.each do |number|
+ (0-number).send(@method).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.send(@method).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.send(@method).should == Math::PI
+ end
+ end
+end
diff --git a/spec/ruby/core/numeric/shared/conj.rb b/spec/ruby/core/numeric/shared/conj.rb
new file mode 100644
index 0000000000..6d5197ecab
--- /dev/null
+++ b/spec/ruby/core/numeric/shared/conj.rb
@@ -0,0 +1,20 @@
+require_relative '../../../spec_helper'
+
+describe :numeric_conj, shared: true do
+ before :each do
+ @numbers = [
+ 20, # Integer
+ 398.72, # Float
+ Rational(3, 4), # Rational
+ bignum_value,
+ infinity_value,
+ nan_value
+ ]
+ end
+
+ it "returns self" do
+ @numbers.each do |number|
+ number.send(@method).should equal(number)
+ end
+ end
+end
diff --git a/spec/ruby/core/numeric/shared/imag.rb b/spec/ruby/core/numeric/shared/imag.rb
new file mode 100644
index 0000000000..4f117e243a
--- /dev/null
+++ b/spec/ruby/core/numeric/shared/imag.rb
@@ -0,0 +1,26 @@
+require_relative '../../../spec_helper'
+
+describe :numeric_imag, shared: true do
+ before :each do
+ @numbers = [
+ 20, # Integer
+ 398.72, # Float
+ Rational(3, 4), # Rational
+ bignum_value, # Bignum
+ infinity_value,
+ nan_value
+ ].map{|n| [n,-n]}.flatten
+ end
+
+ it "returns 0" do
+ @numbers.each do |number|
+ number.send(@method).should == 0
+ end
+ end
+
+ it "raises an ArgumentError if given any arguments" do
+ @numbers.each do |number|
+ -> { number.send(@method, number) }.should raise_error(ArgumentError)
+ end
+ end
+end
diff --git a/spec/ruby/core/numeric/shared/quo.rb b/spec/ruby/core/numeric/shared/quo.rb
deleted file mode 100644
index 2392636fe7..0000000000
--- a/spec/ruby/core/numeric/shared/quo.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-describe :numeric_quo_18, shared: true do
- it "returns the result of calling self#/ with other" do
- obj = mock_numeric('numeric')
- obj.should_receive(:/).with(19).and_return(:result)
- obj.send(@method, 19).should == :result
- end
-end
diff --git a/spec/ruby/core/numeric/shared/rect.rb b/spec/ruby/core/numeric/shared/rect.rb
index cda5fede7f..120a69b1c4 100644
--- a/spec/ruby/core/numeric/shared/rect.rb
+++ b/spec/ruby/core/numeric/shared/rect.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe :numeric_rect, shared: true do
before :each do
@@ -25,24 +25,24 @@ describe :numeric_rect, shared: true do
end
it "returns self as the first element" do
- @numbers.each do |number|
- if Float === number and number.nan?
- number.send(@method).first.nan?.should be_true
- else
- number.send(@method).first.should == number
- end
- end
+ @numbers.each do |number|
+ if Float === number and number.nan?
+ number.send(@method).first.nan?.should be_true
+ else
+ number.send(@method).first.should == number
+ end
+ end
end
it "returns 0 as the last element" do
- @numbers.each do |number|
- number.send(@method).last.should == 0
- end
+ @numbers.each do |number|
+ number.send(@method).last.should == 0
+ end
end
it "raises an ArgumentError if given any arguments" do
- @numbers.each do |number|
- lambda { number.send(@method, number) }.should raise_error(ArgumentError)
- end
+ @numbers.each do |number|
+ -> { number.send(@method, number) }.should raise_error(ArgumentError)
+ end
end
end
diff --git a/spec/ruby/core/numeric/shared/step.rb b/spec/ruby/core/numeric/shared/step.rb
index 3072830534..977ec6de02 100644
--- a/spec/ruby/core/numeric/shared/step.rb
+++ b/spec/ruby/core/numeric/shared/step.rb
@@ -1,56 +1,64 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
# Describes Numeric#step shared specs between different argument styles.
-# To be able to do it, the @step_args var must contain a Proc that transforms
+# To be able to do it, the @step ivar must contain a Proc that transforms
# the step call arguments passed as positional arguments to the style of
# arguments pretended to test.
-describe :numeric_step, :shared => true do
+describe :numeric_step, shared: true do
before :each do
ScratchPad.record []
- @prc = lambda { |x| ScratchPad << x }
+ @prc = -> x { ScratchPad << x }
end
it "defaults to step = 1" do
- 1.send(@method, *@step_args.call(5), &@prc)
+ @step.call(1, 5, &@prc)
ScratchPad.recorded.should eql [1, 2, 3, 4, 5]
end
- describe "when self, stop and step are Fixnums" do
- it "yields only Fixnums" do
- 1.send(@method, *@step_args.call(5, 1)) { |x| x.should be_an_instance_of(Fixnum) }
+ it "defaults to an infinite limit with a step size of 1 for Integers" do
+ 1.step.first(5).should == [1, 2, 3, 4, 5]
+ end
+
+ it "defaults to an infinite limit with a step size of 1.0 for Floats" do
+ 1.0.step.first(5).should == [1.0, 2.0, 3.0, 4.0, 5.0]
+ end
+
+ describe "when self, stop and step are Integers" do
+ it "yields only Integers" do
+ @step.call(1, 5, 1) { |x| x.should be_an_instance_of(Integer) }
end
describe "with a positive step" do
it "yields while increasing self by step until stop is reached" do
- 1.send(@method, *@step_args.call(5, 1), &@prc)
+ @step.call(1, 5, 1, &@prc)
ScratchPad.recorded.should eql [1, 2, 3, 4, 5]
end
it "yields once when self equals stop" do
- 1.send(@method, *@step_args.call(1, 1), &@prc)
+ @step.call(1, 1, 1, &@prc)
ScratchPad.recorded.should eql [1]
end
it "does not yield when self is greater than stop" do
- 2.send(@method, *@step_args.call(1, 1), &@prc)
+ @step.call(2, 1, 1, &@prc)
ScratchPad.recorded.should eql []
end
end
describe "with a negative step" do
it "yields while decreasing self by step until stop is reached" do
- 5.send(@method, *@step_args.call(1, -1), &@prc)
+ @step.call(5, 1, -1, &@prc)
ScratchPad.recorded.should eql [5, 4, 3, 2, 1]
end
it "yields once when self equals stop" do
- 5.send(@method, *@step_args.call(5, -1), &@prc)
+ @step.call(5, 5, -1, &@prc)
ScratchPad.recorded.should eql [5]
end
it "does not yield when self is less than stop" do
- 1.send(@method, *@step_args.call(5, -1), &@prc)
+ @step.call(1, 5, -1, &@prc)
ScratchPad.recorded.should == []
end
end
@@ -58,156 +66,157 @@ describe :numeric_step, :shared => true do
describe "when at least one of self, stop or step is a Float" do
it "yields Floats even if only self is a Float" do
- 1.5.send(@method, *@step_args.call(5, 1)) { |x| x.should be_an_instance_of(Float) }
+ @step.call(1.5, 5, 1) { |x| x.should be_an_instance_of(Float) }
end
it "yields Floats even if only stop is a Float" do
- 1.send(@method, *@step_args.call(5.0, 1)) { |x| x.should be_an_instance_of(Float) }
+ @step.call(1, 5.0, 1) { |x| x.should be_an_instance_of(Float) }
end
it "yields Floats even if only step is a Float" do
- 1.send(@method, *@step_args.call(5, 1.0)) { |x| x.should be_an_instance_of(Float) }
+ @step.call(1, 5, 1.0) { |x| x.should be_an_instance_of(Float) }
end
describe "with a positive step" do
it "yields while increasing self by step while < stop" do
- 1.5.send(@method, *@step_args.call(5, 1), &@prc)
+ @step.call(1.5, 5, 1, &@prc)
ScratchPad.recorded.should eql [1.5, 2.5, 3.5, 4.5]
end
it "yields once when self equals stop" do
- 1.5.send(@method, *@step_args.call(1.5, 1), &@prc)
+ @step.call(1.5, 1.5, 1, &@prc)
ScratchPad.recorded.should eql [1.5]
end
it "does not yield when self is greater than stop" do
- 2.5.send(@method, *@step_args.call(1.5, 1), &@prc)
+ @step.call(2.5, 1.5, 1, &@prc)
ScratchPad.recorded.should == []
end
it "is careful about not yielding a value greater than limit" do
# As 9*1.3+1.0 == 12.700000000000001 > 12.7, we test:
- 1.0.send(@method, *@step_args.call(12.7, 1.3), &@prc)
+ @step.call(1.0, 12.7, 1.3, &@prc)
ScratchPad.recorded.should eql [1.0, 2.3, 3.6, 4.9, 6.2, 7.5, 8.8, 10.1, 11.4, 12.7]
end
end
describe "with a negative step" do
it "yields while decreasing self by step while self > stop" do
- 5.send(@method, *@step_args.call(1.5, -1), &@prc)
+ @step.call(5, 1.5, -1, &@prc)
ScratchPad.recorded.should eql [5.0, 4.0, 3.0, 2.0]
end
it "yields once when self equals stop" do
- 1.5.send(@method, *@step_args.call(1.5, -1), &@prc)
+ @step.call(1.5, 1.5, -1, &@prc)
ScratchPad.recorded.should eql [1.5]
end
it "does not yield when self is less than stop" do
- 1.send(@method, *@step_args.call(5, -1.5), &@prc)
+ @step.call(1, 5, -1.5, &@prc)
ScratchPad.recorded.should == []
end
it "is careful about not yielding a value smaller than limit" do
# As -9*1.3-1.0 == -12.700000000000001 < -12.7, we test:
- -1.0.send(@method, *@step_args.call(-12.7, -1.3), &@prc)
+ @step.call(-1.0, -12.7, -1.3, &@prc)
ScratchPad.recorded.should eql [-1.0, -2.3, -3.6, -4.9, -6.2, -7.5, -8.8, -10.1, -11.4, -12.7]
end
end
describe "with a positive Infinity step" do
it "yields once if self < stop" do
- 42.send(@method, *@step_args.call(100, infinity_value), &@prc)
+ @step.call(42, 100, infinity_value, &@prc)
ScratchPad.recorded.should eql [42.0]
end
it "yields once when stop is Infinity" do
- 42.send(@method, *@step_args.call(infinity_value, infinity_value), &@prc)
+ @step.call(42, infinity_value, infinity_value, &@prc)
ScratchPad.recorded.should eql [42.0]
end
it "yields once when self equals stop" do
- 42.send(@method, *@step_args.call(42, infinity_value), &@prc)
+ @step.call(42, 42, infinity_value, &@prc)
ScratchPad.recorded.should eql [42.0]
end
it "yields once when self and stop are Infinity" do
- (infinity_value).send(@method, *@step_args.call(infinity_value, infinity_value), &@prc)
+ # @step.call(infinity_value, infinity_value, infinity_value, &@prc)
+ @step.call(infinity_value, infinity_value, infinity_value, &@prc)
ScratchPad.recorded.should == [infinity_value]
end
it "does not yield when self > stop" do
- 100.send(@method, *@step_args.call(42, infinity_value), &@prc)
+ @step.call(100, 42, infinity_value, &@prc)
ScratchPad.recorded.should == []
end
it "does not yield when stop is -Infinity" do
- 42.send(@method, *@step_args.call(-infinity_value, infinity_value), &@prc)
+ @step.call(42, -infinity_value, infinity_value, &@prc)
ScratchPad.recorded.should == []
end
end
describe "with a negative Infinity step" do
it "yields once if self > stop" do
- 42.send(@method, *@step_args.call(6, -infinity_value), &@prc)
+ @step.call(42, 6, -infinity_value, &@prc)
ScratchPad.recorded.should eql [42.0]
end
it "yields once if stop is -Infinity" do
- 42.send(@method, *@step_args.call(-infinity_value, -infinity_value), &@prc)
+ @step.call(42, -infinity_value, -infinity_value, &@prc)
ScratchPad.recorded.should eql [42.0]
end
it "yields once when self equals stop" do
- 42.send(@method, *@step_args.call(42, -infinity_value), &@prc)
+ @step.call(42, 42, -infinity_value, &@prc)
ScratchPad.recorded.should eql [42.0]
end
it "yields once when self and stop are Infinity" do
- (infinity_value).send(@method, *@step_args.call(infinity_value, -infinity_value), &@prc)
+ @step.call(infinity_value, infinity_value, -infinity_value, &@prc)
ScratchPad.recorded.should == [infinity_value]
end
it "does not yield when self > stop" do
- 42.send(@method, *@step_args.call(100, -infinity_value), &@prc)
+ @step.call(42, 100, -infinity_value, &@prc)
ScratchPad.recorded.should == []
end
it "does not yield when stop is Infinity" do
- 42.send(@method, *@step_args.call(infinity_value, -infinity_value), &@prc)
+ @step.call(42, infinity_value, -infinity_value, &@prc)
ScratchPad.recorded.should == []
end
end
describe "with a Infinity stop and a positive step" do
it "does not yield when self is infinity" do
- (infinity_value).send(@method, *@step_args.call(infinity_value, 1), &@prc)
+ @step.call(infinity_value, infinity_value, 1, &@prc)
ScratchPad.recorded.should == []
end
end
describe "with a Infinity stop and a negative step" do
it "does not yield when self is negative infinity" do
- (-infinity_value).send(@method, *@step_args.call(infinity_value, -1), &@prc)
+ @step.call(-infinity_value, infinity_value, -1, &@prc)
ScratchPad.recorded.should == []
end
it "does not yield when self is positive infinity" do
- infinity_value.send(@method, *@step_args.call(infinity_value, -1), &@prc)
+ @step.call(infinity_value, infinity_value, -1, &@prc)
ScratchPad.recorded.should == []
end
end
describe "with a negative Infinity stop and a positive step" do
it "does not yield when self is negative infinity" do
- (-infinity_value).send(@method, *@step_args.call(-infinity_value, 1), &@prc)
+ @step.call(-infinity_value, -infinity_value, 1, &@prc)
ScratchPad.recorded.should == []
end
end
describe "with a negative Infinity stop and a negative step" do
it "does not yield when self is negative infinity" do
- (-infinity_value).send(@method, *@step_args.call(-infinity_value, -1), &@prc)
+ @step.call(-infinity_value, -infinity_value, -1, &@prc)
ScratchPad.recorded.should == []
end
end
@@ -215,75 +224,62 @@ describe :numeric_step, :shared => true do
end
describe "when step is a String" do
- error = nil
- ruby_version_is ""..."2.4" do
- error = ArgumentError
- end
- ruby_version_is "2.4"..."2.5" do
- error = TypeError
- end
- ruby_version_is "2.5" do
- error = ArgumentError
- end
-
- describe "with self and stop as Fixnums" do
- it "raises an #{error} when step is a numeric representation" do
- lambda { 1.send(@method, *@step_args.call(5, "1")) {} }.should raise_error(error)
- lambda { 1.send(@method, *@step_args.call(5, "0.1")) {} }.should raise_error(error)
- lambda { 1.send(@method, *@step_args.call(5, "1/3")) {} }.should raise_error(error)
+ describe "with self and stop as Integers" do
+ it "raises an ArgumentError when step is a numeric representation" do
+ -> { @step.call(1, 5, "1") {} }.should raise_error(ArgumentError)
+ -> { @step.call(1, 5, "0.1") {} }.should raise_error(ArgumentError)
+ -> { @step.call(1, 5, "1/3") {} }.should raise_error(ArgumentError)
end
- it "raises an #{error} with step as an alphanumeric string" do
- lambda { 1.send(@method, *@step_args.call(5, "foo")) {} }.should raise_error(error)
+ it "raises an ArgumentError with step as an alphanumeric string" do
+ -> { @step.call(1, 5, "foo") {} }.should raise_error(ArgumentError)
end
end
describe "with self and stop as Floats" do
- it "raises an #{error} when step is a numeric representation" do
- lambda { 1.1.send(@method, *@step_args.call(5.1, "1")) {} }.should raise_error(error)
- lambda { 1.1.send(@method, *@step_args.call(5.1, "0.1")) {} }.should raise_error(error)
- lambda { 1.1.send(@method, *@step_args.call(5.1, "1/3")) {} }.should raise_error(error)
+ it "raises an ArgumentError when step is a numeric representation" do
+ -> { @step.call(1.1, 5.1, "1") {} }.should raise_error(ArgumentError)
+ -> { @step.call(1.1, 5.1, "0.1") {} }.should raise_error(ArgumentError)
+ -> { @step.call(1.1, 5.1, "1/3") {} }.should raise_error(ArgumentError)
end
- it "raises an #{error} with step as an alphanumeric string" do
- lambda { 1.1.send(@method, *@step_args.call(5.1, "foo")) {} }.should raise_error(error)
+ it "raises an ArgumentError with step as an alphanumeric string" do
+ -> { @step.call(1.1, 5.1, "foo") {} }.should raise_error(ArgumentError)
end
end
end
it "does not rescue ArgumentError exceptions" do
- lambda { 1.send(@method, *@step_args.call(2)) { raise ArgumentError, "" }}.should raise_error(ArgumentError)
+ -> { @step.call(1, 2) { raise ArgumentError, "" }}.should raise_error(ArgumentError)
end
it "does not rescue TypeError exceptions" do
- lambda { 1.send(@method, *@step_args.call(2)) { raise TypeError, "" } }.should raise_error(TypeError)
+ -> { @step.call(1, 2) { raise TypeError, "" } }.should raise_error(TypeError)
end
describe "when no block is given" do
- it "returns an Enumerator when step is 0" do
- 1.send(@method, *@step_args.call(2, 0)).should be_an_instance_of(Enumerator)
- end
+ step_enum_class = Enumerator::ArithmeticSequence
- it "returns an Enumerator when not passed a block and self > stop" do
- 1.send(@method, *@step_args.call(0, 2)).should be_an_instance_of(Enumerator)
+ it "returns an #{step_enum_class} when not passed a block and self > stop" do
+ @step.call(1, 0, 2).should be_an_instance_of(step_enum_class)
end
- it "returns an Enumerator when not passed a block and self < stop" do
- 1.send(@method, *@step_args.call(2, 3)).should be_an_instance_of(Enumerator)
+ it "returns an #{step_enum_class} when not passed a block and self < stop" do
+ @step.call(1, 2, 3).should be_an_instance_of(step_enum_class)
end
- it "returns an Enumerator that uses the given step" do
- 0.send(@method, *@step_args.call(5, 2)).to_a.should eql [0, 2, 4]
+ it "returns an #{step_enum_class} that uses the given step" do
+ @step.call(0, 5, 2).to_a.should eql [0, 2, 4]
end
describe "when step is a String" do
- describe "with self and stop as Fixnums" do
+ describe "with self and stop as Integers" do
it "returns an Enumerator" do
- 1.send(@method, *@step_args.call(5, "foo")).should be_an_instance_of(Enumerator)
+ @step.call(1, 5, "foo").should be_an_instance_of(Enumerator)
end
end
describe "with self and stop as Floats" do
it "returns an Enumerator" do
- 1.1.send(@method, *@step_args.call(5.1, "foo")).should be_an_instance_of(Enumerator)
+ @step.call(1.1, 5.1, "foo").should be_an_instance_of(Enumerator)
end
end
end
@@ -291,132 +287,121 @@ describe :numeric_step, :shared => true do
describe "returned Enumerator" do
describe "size" do
describe "when step is a String" do
- error = nil
- ruby_version_is ""..."2.4" do
- error = ArgumentError
- end
- ruby_version_is "2.4"..."2.5" do
- error = TypeError
- end
- ruby_version_is "2.5" do
- error = ArgumentError
- end
-
- describe "with self and stop as Fixnums" do
- it "raises an #{error} when step is a numeric representation" do
- lambda { 1.send(@method, *@step_args.call(5, "1")).size }.should raise_error(error)
- lambda { 1.send(@method, *@step_args.call(5, "0.1")).size }.should raise_error(error)
- lambda { 1.send(@method, *@step_args.call(5, "1/3")).size }.should raise_error(error)
+ describe "with self and stop as Integers" do
+ it "raises an ArgumentError when step is a numeric representation" do
+ -> { @step.call(1, 5, "1").size }.should raise_error(ArgumentError)
+ -> { @step.call(1, 5, "0.1").size }.should raise_error(ArgumentError)
+ -> { @step.call(1, 5, "1/3").size }.should raise_error(ArgumentError)
end
- it "raises an #{error} with step as an alphanumeric string" do
- lambda { 1.send(@method, *@step_args.call(5, "foo")).size }.should raise_error(error)
+ it "raises an ArgumentError with step as an alphanumeric string" do
+ -> { @step.call(1, 5, "foo").size }.should raise_error(ArgumentError)
end
end
describe "with self and stop as Floats" do
- it "raises an #{error} when step is a numeric representation" do
- lambda { 1.1.send(@method, *@step_args.call(5.1, "1")).size }.should raise_error(error)
- lambda { 1.1.send(@method, *@step_args.call(5.1, "0.1")).size }.should raise_error(error)
- lambda { 1.1.send(@method, *@step_args.call(5.1, "1/3")).size }.should raise_error(error)
+ it "raises an ArgumentError when step is a numeric representation" do
+ -> { @step.call(1.1, 5.1, "1").size }.should raise_error(ArgumentError)
+ -> { @step.call(1.1, 5.1, "0.1").size }.should raise_error(ArgumentError)
+ -> { @step.call(1.1, 5.1, "1/3").size }.should raise_error(ArgumentError)
end
- it "raises an #{error} with step as an alphanumeric string" do
- lambda { 1.1.send(@method, *@step_args.call(5.1, "foo")).size }.should raise_error(error)
+ it "raises an ArgumentError with step as an alphanumeric string" do
+ -> { @step.call(1.1, 5.1, "foo").size }.should raise_error(ArgumentError)
end
end
end
- describe "when self, stop and step are Fixnums and step is positive" do
+ describe "when self, stop and step are Integers and step is positive" do
it "returns the difference between self and stop divided by the number of steps" do
- 5.send(@method, *@step_args.call(10, 11)).size.should == 1
- 5.send(@method, *@step_args.call(10, 6)).size.should == 1
- 5.send(@method, *@step_args.call(10, 5)).size.should == 2
- 5.send(@method, *@step_args.call(10, 4)).size.should == 2
- 5.send(@method, *@step_args.call(10, 2)).size.should == 3
- 5.send(@method, *@step_args.call(10, 1)).size.should == 6
- 5.send(@method, *@step_args.call(10)).size.should == 6
- 10.send(@method, *@step_args.call(10, 1)).size.should == 1
+ @step.call(5, 10, 11).size.should == 1
+ @step.call(5, 10, 6).size.should == 1
+ @step.call(5, 10, 5).size.should == 2
+ @step.call(5, 10, 4).size.should == 2
+ @step.call(5, 10, 2).size.should == 3
+ @step.call(5, 10, 1).size.should == 6
+ @step.call(5, 10).size.should == 6
+ @step.call(10, 10, 1).size.should == 1
end
it "returns 0 if value > limit" do
- 11.send(@method, *@step_args.call(10, 1)).size.should == 0
+ @step.call(11, 10, 1).size.should == 0
end
end
- describe "when self, stop and step are Fixnums and step is negative" do
+ describe "when self, stop and step are Integers and step is negative" do
it "returns the difference between self and stop divided by the number of steps" do
- 10.send(@method, *@step_args.call(5, -11)).size.should == 1
- 10.send(@method, *@step_args.call(5, -6)).size.should == 1
- 10.send(@method, *@step_args.call(5, -5)).size.should == 2
- 10.send(@method, *@step_args.call(5, -4)).size.should == 2
- 10.send(@method, *@step_args.call(5, -2)).size.should == 3
- 10.send(@method, *@step_args.call(5, -1)).size.should == 6
- 10.send(@method, *@step_args.call(10, -1)).size.should == 1
+ @step.call(10, 5, -11).size.should == 1
+ @step.call(10, 5, -6).size.should == 1
+ @step.call(10, 5, -5).size.should == 2
+ @step.call(10, 5, -4).size.should == 2
+ @step.call(10, 5, -2).size.should == 3
+ @step.call(10, 5, -1).size.should == 6
+ @step.call(10, 10, -1).size.should == 1
end
it "returns 0 if value < limit" do
- 10.send(@method, *@step_args.call(11, -1)).size.should == 0
+ @step.call(10, 11, -1).size.should == 0
end
end
describe "when self, stop or step is a Float" do
describe "and step is positive" do
it "returns the difference between self and stop divided by the number of steps" do
- 5.send(@method, *@step_args.call(10, 11.0)).size.should == 1
- 5.send(@method, *@step_args.call(10, 6.0)).size.should == 1
- 5.send(@method, *@step_args.call(10, 5.0)).size.should == 2
- 5.send(@method, *@step_args.call(10, 4.0)).size.should == 2
- 5.send(@method, *@step_args.call(10, 2.0)).size.should == 3
- 5.send(@method, *@step_args.call(10, 0.5)).size.should == 11
- 5.send(@method, *@step_args.call(10, 1.0)).size.should == 6
- 5.send(@method, *@step_args.call(10.5)).size.should == 6
- 10.send(@method, *@step_args.call(10, 1.0)).size.should == 1
+ @step.call(5, 10, 11.0).size.should == 1
+ @step.call(5, 10, 6.0).size.should == 1
+ @step.call(5, 10, 5.0).size.should == 2
+ @step.call(5, 10, 4.0).size.should == 2
+ @step.call(5, 10, 2.0).size.should == 3
+ @step.call(5, 10, 0.5).size.should == 11
+ @step.call(5, 10, 1.0).size.should == 6
+ @step.call(5, 10.5).size.should == 6
+ @step.call(10, 10, 1.0).size.should == 1
end
it "returns 0 if value > limit" do
- 10.send(@method, *@step_args.call(5.5)).size.should == 0
- 11.send(@method, *@step_args.call(10, 1.0)).size.should == 0
- 11.send(@method, *@step_args.call(10, 1.5)).size.should == 0
- 10.send(@method, *@step_args.call(5, infinity_value)).size.should == 0
+ @step.call(10, 5.5).size.should == 0
+ @step.call(11, 10, 1.0).size.should == 0
+ @step.call(11, 10, 1.5).size.should == 0
+ @step.call(10, 5, infinity_value).size.should == 0
end
it "returns 1 if step is infinity_value" do
- 5.send(@method, *@step_args.call(10, infinity_value)).size.should == 1
+ @step.call(5, 10, infinity_value).size.should == 1
end
end
describe "and step is negative" do
it "returns the difference between self and stop divided by the number of steps" do
- 10.send(@method, *@step_args.call(5, -11.0)).size.should == 1
- 10.send(@method, *@step_args.call(5, -6.0)).size.should == 1
- 10.send(@method, *@step_args.call(5, -5.0)).size.should == 2
- 10.send(@method, *@step_args.call(5, -4.0)).size.should == 2
- 10.send(@method, *@step_args.call(5, -2.0)).size.should == 3
- 10.send(@method, *@step_args.call(5, -0.5)).size.should == 11
- 10.send(@method, *@step_args.call(5, -1.0)).size.should == 6
- 10.send(@method, *@step_args.call(10, -1.0)).size.should == 1
+ @step.call(10, 5, -11.0).size.should == 1
+ @step.call(10, 5, -6.0).size.should == 1
+ @step.call(10, 5, -5.0).size.should == 2
+ @step.call(10, 5, -4.0).size.should == 2
+ @step.call(10, 5, -2.0).size.should == 3
+ @step.call(10, 5, -0.5).size.should == 11
+ @step.call(10, 5, -1.0).size.should == 6
+ @step.call(10, 10, -1.0).size.should == 1
end
it "returns 0 if value < limit" do
- 10.send(@method, *@step_args.call(11, -1.0)).size.should == 0
- 10.send(@method, *@step_args.call(11, -1.5)).size.should == 0
- 5.send(@method, *@step_args.call(10, -infinity_value)).size.should == 0
+ @step.call(10, 11, -1.0).size.should == 0
+ @step.call(10, 11, -1.5).size.should == 0
+ @step.call(5, 10, -infinity_value).size.should == 0
end
it "returns 1 if step is infinity_value" do
- 10.send(@method, *@step_args.call(5, -infinity_value)).size.should == 1
+ @step.call(10, 5, -infinity_value).size.should == 1
end
end
end
describe "when stop is not passed" do
it "returns infinity_value" do
- 1.send(@method, *@step_args.call()).size.should == infinity_value
+ @step.call(1).size.should == infinity_value
end
end
describe "when stop is nil" do
it "returns infinity_value" do
- 1.send(@method, *@step_args.call(nil, 5)).size.should == infinity_value
+ @step.call(1, nil, 5).size.should == infinity_value
end
end
end
diff --git a/spec/ruby/core/numeric/singleton_method_added_spec.rb b/spec/ruby/core/numeric/singleton_method_added_spec.rb
index a650d286f2..2091398e5d 100644
--- a/spec/ruby/core/numeric/singleton_method_added_spec.rb
+++ b/spec/ruby/core/numeric/singleton_method_added_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Numeric#singleton_method_added" do
before :all do
@@ -18,22 +18,22 @@ describe "Numeric#singleton_method_added" do
end
it "raises a TypeError when trying to define a singleton method on a Numeric" do
- lambda do
+ -> do
a = NumericSpecs::Subclass.new
def a.test; end
end.should raise_error(TypeError)
- lambda do
+ -> do
a = 1
def a.test; end
end.should raise_error(TypeError)
- lambda do
+ -> do
a = 1.5
def a.test; end
end.should raise_error(TypeError)
- lambda do
+ -> do
a = bignum_value
def a.test; end
end.should raise_error(TypeError)
diff --git a/spec/ruby/core/numeric/step_spec.rb b/spec/ruby/core/numeric/step_spec.rb
index 256c150d4e..1705fb1b4e 100644
--- a/spec/ruby/core/numeric/step_spec.rb
+++ b/spec/ruby/core/numeric/step_spec.rb
@@ -1,67 +1,46 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/step', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/step'
describe "Numeric#step" do
describe 'with positional args' do
it "raises an ArgumentError when step is 0" do
- lambda { 1.step(5, 0) {} }.should raise_error(ArgumentError)
+ -> { 1.step(5, 0) {} }.should raise_error(ArgumentError)
end
it "raises an ArgumentError when step is 0.0" do
- lambda { 1.step(2, 0.0) {} }.should raise_error(ArgumentError)
+ -> { 1.step(2, 0.0) {} }.should raise_error(ArgumentError)
end
before :all do
# This lambda definition limits to return the arguments it receives.
# It's needed to test numeric_step behaviour with positional arguments.
- @step_args = ->(*args) { args }
+ @step = -> receiver, *args, &block { receiver.step(*args, &block) }
end
-
it_behaves_like :numeric_step, :step
describe "when no block is given" do
- it "returns an Enumerator when step is 0" do
- 1.step(5, 0).should be_an_instance_of(Enumerator)
- end
-
- it "returns an Enumerator when step is 0.0" do
- 1.step(2, 0.0).should be_an_instance_of(Enumerator)
- end
+ step_enum_class = Enumerator::ArithmeticSequence
- describe "returned Enumerator" do
+ describe "returned #{step_enum_class}" do
describe "size" do
- it "raises an ArgumentError when step is 0" do
- enum = 1.step(5, 0)
- lambda { enum.size }.should raise_error(ArgumentError)
+ it "defaults to an infinite size" do
+ enum = 1.step
+ enum.size.should == Float::INFINITY
end
+ end
- it "raises an ArgumentError when step is 0.0" do
- enum = 1.step(2, 0.0)
- lambda { enum.size }.should raise_error(ArgumentError)
+ describe "type" do
+ it "returns an instance of Enumerator::ArithmeticSequence" do
+ 1.step(10).class.should == Enumerator::ArithmeticSequence
end
end
end
end
-
end
describe 'with keyword arguments' do
- it "doesn't raise an error when step is 0" do
- lambda { 1.step(to: 5, by: 0) { break } }.should_not raise_error
- end
-
- it "doesn't raise an error when step is 0.0" do
- lambda { 1.step(to: 2, by: 0.0) { break } }.should_not raise_error
- end
-
- it "should loop over self when step is 0 or 0.0" do
- 1.step(to: 2, by: 0.0).take(5).should eql [1.0, 1.0, 1.0, 1.0, 1.0]
- 1.step(to: 2, by: 0).take(5).should eql [1, 1, 1, 1, 1]
- 1.1.step(to: 2, by: 0).take(5).should eql [1.1, 1.1, 1.1, 1.1, 1.1]
- end
-
describe "when no block is given" do
describe "returned Enumerator" do
describe "size" do
@@ -69,19 +48,11 @@ describe "Numeric#step" do
1.step(by: 42).size.should == infinity_value
end
- it "should return infinity_value when step is 0" do
- 1.step(to: 5, by: 0).size.should == infinity_value
- end
-
- it "should return infinity_value when step is 0.0" do
- 1.step(to: 2, by: 0.0).size.should == infinity_value
- end
-
it "should return infinity_value when ascending towards a limit of Float::INFINITY" do
1.step(to: Float::INFINITY, by: 42).size.should == infinity_value
end
- it "should return infinity_value when decending towards a limit of -Float::INFINITY" do
+ it "should return infinity_value when descending towards a limit of -Float::INFINITY" do
1.step(to: -Float::INFINITY, by: -42).size.should == infinity_value
end
@@ -97,64 +68,51 @@ describe "Numeric#step" do
end
before :all do
- # This lambda transforms a positional step method args into
- # keyword arguments.
+ # This lambda transforms a positional step method args into keyword arguments.
# It's needed to test numeric_step behaviour with keyword arguments.
- @step_args = ->(*args) do
- kw_args = {to: args[0]}
+ @step = -> receiver, *args, &block do
+ kw_args = { to: args[0] }
kw_args[:by] = args[1] if args.size == 2
- [kw_args]
+ receiver.step(**kw_args, &block)
end
end
it_behaves_like :numeric_step, :step
end
describe 'with mixed arguments' do
- it "doesn't raise an error when step is 0" do
- lambda { 1.step(5, by: 0) { break } }.should_not raise_error
+ it " raises an ArgumentError when step is 0" do
+ -> { 1.step(5, by: 0) { break } }.should raise_error(ArgumentError)
end
- it "doesn't raise an error when step is 0.0" do
- lambda { 1.step(2, by: 0.0) { break } }.should_not raise_error
+ it "raises an ArgumentError when step is 0.0" do
+ -> { 1.step(2, by: 0.0) { break } }.should raise_error(ArgumentError)
end
it "raises a ArgumentError when limit and to are defined" do
- lambda { 1.step(5, 1, to: 5) { break } }.should raise_error(ArgumentError)
+ -> { 1.step(5, 1, to: 5) { break } }.should raise_error(ArgumentError)
end
it "raises a ArgumentError when step and by are defined" do
- lambda { 1.step(5, 1, by: 5) { break } }.should raise_error(ArgumentError)
- end
-
- it "should loop over self when step is 0 or 0.0" do
- 1.step(2, by: 0.0).take(5).should eql [1.0, 1.0, 1.0, 1.0, 1.0]
- 1.step(2, by: 0).take(5).should eql [1, 1, 1, 1, 1]
- 1.1.step(2, by: 0).take(5).should eql [1.1, 1.1, 1.1, 1.1, 1.1]
+ -> { 1.step(5, 1, by: 5) { break } }.should raise_error(ArgumentError)
end
describe "when no block is given" do
describe "returned Enumerator" do
describe "size" do
- it "should return infinity_value when step is 0" do
- 1.step(5, by: 0).size.should == infinity_value
- end
-
- it "should return infinity_value when step is 0.0" do
- 1.step(2, by: 0.0).size.should == infinity_value
- end
end
end
end
+
before :all do
# This lambda definition transforms a positional step method args into
# a mix of positional and keyword arguments.
# It's needed to test numeric_step behaviour with positional mixed with
# keyword arguments.
- @step_args = ->(*args) do
+ @step = -> receiver, *args, &block do
if args.size == 2
- [args[0], {by: args[1]}]
+ receiver.step(args[0], by: args[1], &block)
else
- args
+ receiver.step(*args, &block)
end
end
end
diff --git a/spec/ruby/core/numeric/to_c_spec.rb b/spec/ruby/core/numeric/to_c_spec.rb
index 38452231b0..75245a612e 100644
--- a/spec/ruby/core/numeric/to_c_spec.rb
+++ b/spec/ruby/core/numeric/to_c_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Numeric#to_c" do
before :all do
diff --git a/spec/ruby/core/numeric/to_int_spec.rb b/spec/ruby/core/numeric/to_int_spec.rb
index 4f1df3e042..3cc39a6d40 100644
--- a/spec/ruby/core/numeric/to_int_spec.rb
+++ b/spec/ruby/core/numeric/to_int_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Numeric#to_int" do
it "returns self#to_i" do
diff --git a/spec/ruby/core/numeric/truncate_spec.rb b/spec/ruby/core/numeric/truncate_spec.rb
index f1a2d4de64..f1592334c5 100644
--- a/spec/ruby/core/numeric/truncate_spec.rb
+++ b/spec/ruby/core/numeric/truncate_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Numeric#truncate" do
before :each do
diff --git a/spec/ruby/core/numeric/uminus_spec.rb b/spec/ruby/core/numeric/uminus_spec.rb
index 7385f5f599..39065fa392 100644
--- a/spec/ruby/core/numeric/uminus_spec.rb
+++ b/spec/ruby/core/numeric/uminus_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Numeric#-@" do
it "returns the same value with opposite sign (integers)" do
diff --git a/spec/ruby/core/numeric/uplus_spec.rb b/spec/ruby/core/numeric/uplus_spec.rb
index 557142295a..88cf5e037b 100644
--- a/spec/ruby/core/numeric/uplus_spec.rb
+++ b/spec/ruby/core/numeric/uplus_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Numeric#+@" do
it "returns self" do
diff --git a/spec/ruby/core/numeric/zero_spec.rb b/spec/ruby/core/numeric/zero_spec.rb
index d46e8807ea..0fb7619bcd 100644
--- a/spec/ruby/core/numeric/zero_spec.rb
+++ b/spec/ruby/core/numeric/zero_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Numeric#zero?" do
before :each do
@@ -8,11 +8,11 @@ describe "Numeric#zero?" do
it "returns true if self is 0" do
@obj.should_receive(:==).with(0).and_return(true)
- @obj.zero?.should == true
+ @obj.should.zero?
end
it "returns false if self is not 0" do
@obj.should_receive(:==).with(0).and_return(false)
- @obj.zero?.should == false
+ @obj.should_not.zero?
end
end