diff options
Diffstat (limited to 'spec/ruby/library')
1106 files changed, 14629 insertions, 15908 deletions
diff --git a/spec/ruby/library/English/English_spec.rb b/spec/ruby/library/English/English_spec.rb index 480602d5e5..4d615d1e25 100644 --- a/spec/ruby/library/English/English_spec.rb +++ b/spec/ruby/library/English/English_spec.rb @@ -130,13 +130,15 @@ describe "English" do $LAST_MATCH_INFO.should == $~ end - it "aliases $IGNORECASE to $=" do - $VERBOSE, verbose = nil, $VERBOSE - begin - $IGNORECASE.should_not be_nil - $IGNORECASE.should == $= - ensure - $VERBOSE = verbose + ruby_version_is ""..."3.3" do + it "aliases $IGNORECASE to $=" do + $VERBOSE, verbose = nil, $VERBOSE + begin + $IGNORECASE.should_not be_nil + $IGNORECASE.should == $= + ensure + $VERBOSE = verbose + end end end diff --git a/spec/ruby/library/bigdecimal/BigDecimal_spec.rb b/spec/ruby/library/bigdecimal/BigDecimal_spec.rb index 43a779b420..8596356abd 100644 --- a/spec/ruby/library/bigdecimal/BigDecimal_spec.rb +++ b/spec/ruby/library/bigdecimal/BigDecimal_spec.rb @@ -31,16 +31,12 @@ describe "Kernel#BigDecimal" do end it "accepts significant digits >= given precision" do - suppress_warning do - BigDecimal("3.1415923", 10).precs[1].should >= 10 - end + BigDecimal("3.1415923", 10).should == BigDecimal("3.1415923") end it "determines precision from initial value" do pi_string = "3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593014782083152134043" - suppress_warning { - BigDecimal(pi_string).precs[1] - }.should >= pi_string.size-1 + BigDecimal(pi_string).precision.should == pi_string.size-1 end it "ignores leading and trailing whitespace" do @@ -98,7 +94,11 @@ describe "Kernel#BigDecimal" do BigDecimal("invalid", exception: false).should be_nil BigDecimal("0invalid", exception: false).should be_nil BigDecimal("invalid0", exception: false).should be_nil - BigDecimal("0.", exception: false).should be_nil + if BigDecimal::VERSION >= "3.1.9" + BigDecimal("0.", exception: false).to_i.should == 0 + else + BigDecimal("0.", exception: false).should be_nil + end end end @@ -152,8 +152,10 @@ describe "Kernel#BigDecimal" do BigDecimal("-12345.6E-1").should == -reference end - it "raises ArgumentError when Float is used without precision" do - -> { BigDecimal(1.0) }.should raise_error(ArgumentError) + version_is BigDecimal::VERSION, "3.3.0" do + it "allows Float without precision" do + BigDecimal(1.2).should == BigDecimal("1.2") + end end it "returns appropriate BigDecimal zero for signed zero" do @@ -202,14 +204,6 @@ describe "Kernel#BigDecimal" do Float(@b).to_s.should == "166.66666666666666" end - it "has the expected precision on the LHS" do - suppress_warning { @a.precs[0] }.should == 18 - end - - it "has the expected maximum precision on the LHS" do - suppress_warning { @a.precs[1] }.should == 27 - end - it "produces the expected result when done via Float" do (Float(@a) - Float(@b)).to_s.should == "-6.666596163995564e-10" end @@ -220,34 +214,10 @@ describe "Kernel#BigDecimal" do # Check underlying methods work as we understand - it "BigDecimal precision is the number of digits rounded up to a multiple of nine" do - 1.upto(100) do |n| - b = BigDecimal('4' * n) - precs, _ = suppress_warning { b.precs } - (precs >= 9).should be_true - (precs >= n).should be_true - (precs % 9).should == 0 - end - suppress_warning { BigDecimal('NaN').precs[0] }.should == 9 - end - - it "BigDecimal maximum precision is nine more than precision except for abnormals" do - 1.upto(100) do |n| - b = BigDecimal('4' * n) - precs, max = suppress_warning { b.precs } - max.should == precs + 9 - end - suppress_warning { BigDecimal('NaN').precs[1] }.should == 9 - end - it "BigDecimal(Rational, 18) produces the result we expect" do BigDecimal(@b, 18).to_s.should == "0.166666666666666667e3" end - it "BigDecimal(Rational, BigDecimal.precs[0]) produces the result we expect" do - BigDecimal(@b, suppress_warning { @a.precs[0] }).to_s.should == "0.166666666666666667e3" - end - # Check the top-level expression works as we expect it "produces a BigDecimal" do @@ -255,8 +225,8 @@ describe "Kernel#BigDecimal" do end it "produces the expected result" do - @c.should == BigDecimal("-0.666667e-9") - @c.to_s.should == "-0.666667e-9" + @c.round(15).should == BigDecimal("-0.666667e-9") + @c.round(15).to_s.should == "-0.666667e-9" end it "produces the correct class for other arithmetic operators" do diff --git a/spec/ruby/library/bigdecimal/add_spec.rb b/spec/ruby/library/bigdecimal/add_spec.rb index 169a071aa6..9cdab7d910 100644 --- a/spec/ruby/library/bigdecimal/add_spec.rb +++ b/spec/ruby/library/bigdecimal/add_spec.rb @@ -24,7 +24,7 @@ describe "BigDecimal#add" do end it "returns a + b with given precision" do - # documentation states, that precision ist optional, but it ain't, + # documentation states that precision is optional, but it ain't, @two.add(@one, 1).should == @three @one .add(@two, 1).should == @three @one.add(@one_minus, 1).should == @zero @@ -73,14 +73,6 @@ describe "BigDecimal#add" do # BigDecimal("0.88").add(0.0, 1).should == BigDecimal("0.9") # end - describe "with Object" do - it "tries to coerce the other operand to self" do - object = mock("Object") - object.should_receive(:coerce).with(@frac_3).and_return([@frac_3, @frac_4]) - @frac_3.add(object, 1).should == BigDecimal("0.1E16") - end - end - describe "with Rational" do it "produces a BigDecimal" do (@three + Rational(500, 2)).should == BigDecimal("0.253e3") diff --git a/spec/ruby/library/bigdecimal/core_spec.rb b/spec/ruby/library/bigdecimal/core_spec.rb new file mode 100644 index 0000000000..5097d70865 --- /dev/null +++ b/spec/ruby/library/bigdecimal/core_spec.rb @@ -0,0 +1,62 @@ +require_relative '../../spec_helper' +require 'bigdecimal' + +describe "Core extension by bigdecimal" do + context "Integer#coerce" do + it "produces Floats" do + x, y = 3.coerce(BigDecimal("3.4")) + x.class.should == Float + x.should == 3.4 + y.class.should == Float + y.should == 3.0 + end + end + + describe "Time.at passed BigDecimal" do + it "doesn't round input value" do + Time.at(BigDecimal('1.1')).to_f.should == 1.1 + end + end + + describe "BigDecimal#log" do + it "handles high-precision Rational arguments" do + # log(BigDecimal(r, 50), 50) + result1 = BigDecimal('0.22314354220170971436137296411949880462556361100856e0') + # log(BigDecimal(r, 1000), 50) + result2 = BigDecimal('0.22314354220170971436137296411949880462556361100853e0') + r = Rational(1_234_567_890, 987_654_321) + [result1, result2].should include(BigMath.log(r, 50).mult(1, 50)) + end + end + + describe "Rational#coerce" do + it "returns the passed argument, self as Float, when given a Float" do + result = Rational(3, 4).coerce(1.0) + result.should == [1.0, 0.75] + result.first.is_a?(Float).should be_true + result.last.is_a?(Float).should be_true + end + + it "returns the passed argument, self as Rational, when given an Integer" do + result = Rational(3, 4).coerce(10) + result.should == [Rational(10, 1), Rational(3, 4)] + result.first.is_a?(Rational).should be_true + result.last.is_a?(Rational).should be_true + end + + it "coerces to Rational, when given a Complex" do + Rational(3, 4).coerce(Complex(5)).should == [Rational(5, 1), Rational(3, 4)] + Rational(12, 4).coerce(Complex(5, 1)).should == [Complex(5, 1), Complex(3)] + end + + it "returns [argument, self] when given a Rational" do + Rational(3, 7).coerce(Rational(9, 2)).should == [Rational(9, 2), Rational(3, 7)] + end + + it "raises an error when passed a BigDecimal" do + -> { + Rational(500, 3).coerce(BigDecimal('166.666666666')) + }.should raise_error(TypeError, /BigDecimal can't be coerced into Rational/) + end + end +end diff --git a/spec/ruby/library/bigdecimal/divmod_spec.rb b/spec/ruby/library/bigdecimal/divmod_spec.rb index 294f01cba0..85c014bb8c 100644 --- a/spec/ruby/library/bigdecimal/divmod_spec.rb +++ b/spec/ruby/library/bigdecimal/divmod_spec.rb @@ -33,14 +33,16 @@ describe "BigDecimal#mod_part_of_divmod" do end end - it_behaves_like :bigdecimal_modulo, :mod_part_of_divmod + version_is BigDecimal::VERSION, ""..."4.0.0" do + it_behaves_like :bigdecimal_modulo, :mod_part_of_divmod + end it "raises ZeroDivisionError if other is zero" do bd5667 = BigDecimal("5667.19") - + zero = BigDecimal("0") -> { bd5667.mod_part_of_divmod(0) }.should raise_error(ZeroDivisionError) -> { bd5667.mod_part_of_divmod(BigDecimal("0")) }.should raise_error(ZeroDivisionError) - -> { @zero.mod_part_of_divmod(@zero) }.should raise_error(ZeroDivisionError) + -> { zero.mod_part_of_divmod(zero) }.should raise_error(ZeroDivisionError) end end @@ -73,14 +75,25 @@ describe "BigDecimal#divmod" do @zeroes = [@zero, @zero_pos, @zero_neg] end - it "divides value, returns an array" do - res = @a.divmod(5) - res.kind_of?(Array).should == true + version_is BigDecimal::VERSION, ""..."4.0.0" do + it "divides value, returns [BigDecimal, BigDecimal]" do + res = @a.divmod(5) + res.kind_of?(Array).should == true + DivmodSpecs.check_both_bigdecimal(res) + end + end + + version_is BigDecimal::VERSION, "4.0.0" do + it "divides value, returns [Integer, BigDecimal]" do + res = @a.divmod(5) + res.kind_of?(Array).should == true + res[0].kind_of?(Integer).should == true + res[1].kind_of?(BigDecimal).should == true + end end it "array contains quotient and modulus as BigDecimal" do res = @a.divmod(5) - DivmodSpecs.check_both_bigdecimal(res) res[0].should == BigDecimal('0.8E1') res[1].should == BigDecimal('2.00000000000000000001') @@ -123,17 +136,27 @@ describe "BigDecimal#divmod" do values_and_zeroes.each do |val1| values.each do |val2| res = val1.divmod(val2) - DivmodSpecs.check_both_bigdecimal(res) res[0].should == ((val1/val2).floor) res[1].should == (val1 - res[0] * val2) end end end - it "returns an array of two NaNs if NaN is involved" do - (@special_vals + @regular_vals + @zeroes).each do |val| - DivmodSpecs.check_both_nan(val.divmod(@nan)) - DivmodSpecs.check_both_nan(@nan.divmod(val)) + version_is BigDecimal::VERSION, "4.0.0" do + it "raise FloatDomainError error if NaN is involved" do + (@special_vals + @regular_vals + @zeroes).each do |val| + -> { val.divmod(@nan) }.should raise_error(FloatDomainError) + -> { @nan.divmod(val) }.should raise_error(FloatDomainError) + end + end + end + + version_is BigDecimal::VERSION, ""..."4.0.0" do + it "returns an array of two NaNs if NaN is involved" do + (@special_vals + @regular_vals + @zeroes).each do |val| + DivmodSpecs.check_both_nan(val.divmod(@nan)) + DivmodSpecs.check_both_nan(@nan.divmod(val)) + end end end @@ -145,21 +168,30 @@ describe "BigDecimal#divmod" do end end - it "returns an array of Infinity and NaN if the dividend is Infinity" do - @regular_vals.each do |val| - array = @infinity.divmod(val) - array.length.should == 2 - array[0].infinite?.should == (val > 0 ? 1 : -1) - array[1].should.nan? + version_is BigDecimal::VERSION, ""..."4.0.0" do + it "returns an array of Infinity and NaN if the dividend is Infinity" do + @regular_vals.each do |val| + array = @infinity.divmod(val) + array.length.should == 2 + array[0].infinite?.should == (val > 0 ? 1 : -1) + array[1].should.nan? + end end end - it "returns an array of zero and the dividend if the divisor is Infinity" do - @regular_vals.each do |val| - array = val.divmod(@infinity) - array.length.should == 2 - array[0].should == @zero - array[1].should == val + version_is BigDecimal::VERSION, "3.3.0" do + it "returns an array of zero and the dividend or minus one and Infinity if the divisor is Infinity" do + @regular_vals.each do |val| + array = val.divmod(@infinity) + array.length.should == 2 + if val >= 0 + array[0].should == @zero + array[1].should == val + else + array[0].should == @one_minus + array[1].should == @infinity + end + end end end diff --git a/spec/ruby/library/bigdecimal/fix_spec.rb b/spec/ruby/library/bigdecimal/fix_spec.rb index 231c9a587e..2c6276899e 100644 --- a/spec/ruby/library/bigdecimal/fix_spec.rb +++ b/spec/ruby/library/bigdecimal/fix_spec.rb @@ -2,20 +2,20 @@ require_relative '../../spec_helper' require 'bigdecimal' describe "BigDecimal#fix" do - before :each do - @zero = BigDecimal("0") - @mixed = BigDecimal("1.23456789") - @pos_int = BigDecimal("2E5555") - @neg_int = BigDecimal("-2E5555") - @pos_frac = BigDecimal("2E-9999") - @neg_frac = BigDecimal("-2E-9999") - - @infinity = BigDecimal("Infinity") - @infinity_neg = BigDecimal("-Infinity") - @nan = BigDecimal("NaN") - @zero_pos = BigDecimal("+0") - @zero_neg = BigDecimal("-0") - end + before :each do + @zero = BigDecimal("0") + @mixed = BigDecimal("1.23456789") + @pos_int = BigDecimal("2E5555") + @neg_int = BigDecimal("-2E5555") + @pos_frac = BigDecimal("2E-9999") + @neg_frac = BigDecimal("-2E-9999") + + @infinity = BigDecimal("Infinity") + @infinity_neg = BigDecimal("-Infinity") + @nan = BigDecimal("NaN") + @zero_pos = BigDecimal("+0") + @zero_neg = BigDecimal("-0") + end it "returns a BigDecimal" do BigDecimal("2E100000000").fix.kind_of?(BigDecimal).should == true diff --git a/spec/ruby/library/bigdecimal/mult_spec.rb b/spec/ruby/library/bigdecimal/mult_spec.rb index b7f8044b0b..2353df9cb8 100644 --- a/spec/ruby/library/bigdecimal/mult_spec.rb +++ b/spec/ruby/library/bigdecimal/mult_spec.rb @@ -21,12 +21,4 @@ describe "BigDecimal#mult" do @e.mult(@one, 1).should be_close(@one, @tolerance) @e3_minus.mult(@one, 1).should be_close(0, @tolerance2) end - - describe "with Object" do - it "tries to coerce the other operand to self" do - object = mock("Object") - object.should_receive(:coerce).with(@e3_minus).and_return([@e3_minus, @e3_plus]) - @e3_minus.mult(object, 1).should == BigDecimal("9") - end - end end diff --git a/spec/ruby/library/bigdecimal/precs_spec.rb b/spec/ruby/library/bigdecimal/precs_spec.rb deleted file mode 100644 index 5fda8d3087..0000000000 --- a/spec/ruby/library/bigdecimal/precs_spec.rb +++ /dev/null @@ -1,55 +0,0 @@ -require_relative '../../spec_helper' -require 'bigdecimal' - -describe "BigDecimal#precs" do - before :each do - @infinity = BigDecimal("Infinity") - @infinity_neg = BigDecimal("-Infinity") - @nan = BigDecimal("NaN") - @zero = BigDecimal("0") - @zero_neg = BigDecimal("-0") - - @arr = [BigDecimal("2E40001"), BigDecimal("3E-20001"),\ - @infinity, @infinity_neg, @nan, @zero, @zero_neg] - @precision = BigDecimal::BASE.to_s.length - 1 - end - - it "returns array of two values" do - suppress_warning do - @arr.each do |x| - x.precs.kind_of?(Array).should == true - x.precs.size.should == 2 - end - end - end - - it "returns Integers as array values" do - suppress_warning do - @arr.each do |x| - x.precs[0].kind_of?(Integer).should == true - x.precs[1].kind_of?(Integer).should == true - end - end - end - - it "returns the current value of significant digits as the first value" do - suppress_warning do - BigDecimal("3.14159").precs[0].should >= 6 - BigDecimal('1').precs[0].should == BigDecimal('1' + '0' * 100).precs[0] - [@infinity, @infinity_neg, @nan, @zero, @zero_neg].each do |value| - value.precs[0].should <= @precision - end - end - end - - it "returns the maximum number of significant digits as the second value" do - suppress_warning do - BigDecimal("3.14159").precs[1].should >= 6 - BigDecimal('1').precs[1].should >= 1 - BigDecimal('1' + '0' * 100).precs[1].should >= 101 - [@infinity, @infinity_neg, @nan, @zero, @zero_neg].each do |value| - value.precs[1].should >= 1 - end - end - end -end diff --git a/spec/ruby/library/bigdecimal/remainder_spec.rb b/spec/ruby/library/bigdecimal/remainder_spec.rb index 35e131a0dc..0eb06f7ef1 100644 --- a/spec/ruby/library/bigdecimal/remainder_spec.rb +++ b/spec/ruby/library/bigdecimal/remainder_spec.rb @@ -37,9 +37,11 @@ describe "BigDecimal#remainder" do @neg_int.remainder(@pos_frac).should == @neg_int - @pos_frac * (@neg_int / @pos_frac).truncate end - it "returns NaN used with zero" do - @mixed.remainder(@zero).should.nan? - @zero.remainder(@zero).should.nan? + version_is BigDecimal::VERSION, "3.3.0" do + it "raises ZeroDivisionError used with zero" do + -> { @mixed.remainder(@zero) }.should raise_error(ZeroDivisionError) + -> { @zero.remainder(@zero) }.should raise_error(ZeroDivisionError) + end end it "returns zero if used on zero" do @@ -54,7 +56,7 @@ describe "BigDecimal#remainder" do @nan.remainder(@infinity).should.nan? end - version_is BigDecimal::VERSION, ""..."3.1.4" do + version_is BigDecimal::VERSION, ""..."3.1.4" do #ruby_version_is ""..."3.3" do it "returns NaN if Infinity is involved" do @infinity.remainder(@infinity).should.nan? @infinity.remainder(@one).should.nan? diff --git a/spec/ruby/library/bigdecimal/round_spec.rb b/spec/ruby/library/bigdecimal/round_spec.rb index bfc6dbc763..6a4d220417 100644 --- a/spec/ruby/library/bigdecimal/round_spec.rb +++ b/spec/ruby/library/bigdecimal/round_spec.rb @@ -228,15 +228,7 @@ describe "BigDecimal#round" do -> { BigDecimal('-Infinity').round(2) }.should_not raise_error(FloatDomainError) end - ruby_version_is ''...'3.2' do - it 'raise for a non-existent round mode' do - -> { @p1_50.round(0, :nonsense) }.should raise_error(ArgumentError, "invalid rounding mode") - end - end - - ruby_version_is '3.2' do - it 'raise for a non-existent round mode' do - -> { @p1_50.round(0, :nonsense) }.should raise_error(ArgumentError, "invalid rounding mode (nonsense)") - end + it 'raise for a non-existent round mode' do + -> { @p1_50.round(0, :nonsense) }.should raise_error(ArgumentError, "invalid rounding mode (nonsense)") end end diff --git a/spec/ruby/library/bigdecimal/shared/modulo.rb b/spec/ruby/library/bigdecimal/shared/modulo.rb index aa5c5a640b..eeb030fd23 100644 --- a/spec/ruby/library/bigdecimal/shared/modulo.rb +++ b/spec/ruby/library/bigdecimal/shared/modulo.rb @@ -101,10 +101,16 @@ describe :bigdecimal_modulo, shared: true do @infinity_minus.send(@method, @infinity).should.nan? end - it "returns the dividend if the divisor is Infinity" do - @one.send(@method, @infinity).should == @one - @one.send(@method, @infinity_minus).should == @one - @frac_2.send(@method, @infinity_minus).should == @frac_2 + version_is BigDecimal::VERSION, "3.3.0" do + it "returns the dividend if the divisor is Infinity and signs are same" do + @one.send(@method, @infinity).should == @one + (-@frac_2).send(@method, @infinity_minus).should == -@frac_2 + end + + it "returns the divisor if the divisor is Infinity and signs are different" do + (-@one).send(@method, @infinity).should == @infinity + @frac_2.send(@method, @infinity_minus).should == @infinity_minus + end end it "raises TypeError if the argument cannot be coerced to BigDecimal" do diff --git a/spec/ruby/library/bigdecimal/shared/power.rb b/spec/ruby/library/bigdecimal/shared/power.rb index 568a08589b..6dafb638e2 100644 --- a/spec/ruby/library/bigdecimal/shared/power.rb +++ b/spec/ruby/library/bigdecimal/shared/power.rb @@ -10,8 +10,8 @@ describe :bigdecimal_power, shared: true do e = BigDecimal("1.00000000000000000000123456789") one = BigDecimal("1") ten = BigDecimal("10") - # The tolerance is dependent upon the size of BASE_FIG - tolerance = BigDecimal("1E-70") + # Accuracy is at least ndigits(== 30) + DOUBLE_FIG(== 16) + tolerance = BigDecimal("1E-46") ten_powers = BigDecimal("1E10000") pi = BigDecimal("3.14159265358979") e3_minus.send(@method, 2).should == e3_minus_power_2 diff --git a/spec/ruby/library/bigdecimal/shared/quo.rb b/spec/ruby/library/bigdecimal/shared/quo.rb index 46e6d62bf4..18ff2fe9a5 100644 --- a/spec/ruby/library/bigdecimal/shared/quo.rb +++ b/spec/ruby/library/bigdecimal/shared/quo.rb @@ -31,6 +31,7 @@ describe :bigdecimal_quo, shared: true do describe "with Object" do it "tries to coerce the other operand to self" do + skip if @method == :div object = mock("Object") object.should_receive(:coerce).with(@one).and_return([@one, @two]) @one.send(@method, object, *@object).should == BigDecimal("0.5") diff --git a/spec/ruby/library/bigdecimal/shared/to_int.rb b/spec/ruby/library/bigdecimal/shared/to_int.rb index 0f16251612..44b6a3c7b2 100644 --- a/spec/ruby/library/bigdecimal/shared/to_int.rb +++ b/spec/ruby/library/bigdecimal/shared/to_int.rb @@ -1,6 +1,6 @@ require 'bigdecimal' -describe :bigdecimal_to_int , shared: true do +describe :bigdecimal_to_int, shared: true do it "raises FloatDomainError if BigDecimal is infinity or NaN" do -> { BigDecimal("Infinity").send(@method) }.should raise_error(FloatDomainError) -> { BigDecimal("NaN").send(@method) }.should raise_error(FloatDomainError) diff --git a/spec/ruby/library/bigdecimal/split_spec.rb b/spec/ruby/library/bigdecimal/split_spec.rb index f9b4bab5f7..53b1f649d9 100644 --- a/spec/ruby/library/bigdecimal/split_spec.rb +++ b/spec/ruby/library/bigdecimal/split_spec.rb @@ -58,16 +58,16 @@ describe "BigDecimal#split" do end it "third value: the base (currently always ten)" do - @arr[2].should == 10 - @arr_neg[2].should == 10 - @arr_big[2].should == 10 - @arr_big_neg[2].should == 10 - @huge[2].should == 10 - @infinity.split[2].should == 10 - @nan.split[2].should == 10 - @infinity_neg.split[2].should == 10 - @zero.split[2].should == 10 - @zero_neg.split[2].should == 10 + @arr[2].should == 10 + @arr_neg[2].should == 10 + @arr_big[2].should == 10 + @arr_big_neg[2].should == 10 + @huge[2].should == 10 + @infinity.split[2].should == 10 + @nan.split[2].should == 10 + @infinity_neg.split[2].should == 10 + @zero.split[2].should == 10 + @zero_neg.split[2].should == 10 end it "fourth value: the exponent" do diff --git a/spec/ruby/library/bigdecimal/sqrt_spec.rb b/spec/ruby/library/bigdecimal/sqrt_spec.rb index d149003b9f..42cf4545cb 100644 --- a/spec/ruby/library/bigdecimal/sqrt_spec.rb +++ b/spec/ruby/library/bigdecimal/sqrt_spec.rb @@ -36,8 +36,10 @@ describe "BigDecimal#sqrt" do BigDecimal('121').sqrt(5).should be_close(11, 0.00001) end - it "returns square root of 0.9E-99999 with desired precision" do - @frac_2.sqrt(1).to_s.should =~ /\A0\.3E-49999\z/i + platform_is_not c_long_size: 32 do # fails on i686 + it "returns square root of 0.9E-99999 with desired precision" do + @frac_2.sqrt(1).to_s.should =~ /\A0\.3E-49999\z/i + end end it "raises ArgumentError when no argument is given" do diff --git a/spec/ruby/library/bigdecimal/sub_spec.rb b/spec/ruby/library/bigdecimal/sub_spec.rb index bddfec2186..3b62a0c794 100644 --- a/spec/ruby/library/bigdecimal/sub_spec.rb +++ b/spec/ruby/library/bigdecimal/sub_spec.rb @@ -35,14 +35,6 @@ describe "BigDecimal#sub" do @frac_1.sub(@frac_1, 1000000).should == @zero end - describe "with Object" do - it "tries to coerce the other operand to self" do - object = mock("Object") - object.should_receive(:coerce).with(@frac_3).and_return([@frac_3, @frac_4]) - @frac_3.sub(object, 1).should == BigDecimal("-0.9E15") - end - end - describe "with Rational" do it "produces a BigDecimal" do (@three - Rational(500, 2)).should == BigDecimal('-0.247e3') diff --git a/spec/ruby/library/bigdecimal/to_i_spec.rb b/spec/ruby/library/bigdecimal/to_i_spec.rb index 09481fce15..e5e65c562e 100644 --- a/spec/ruby/library/bigdecimal/to_i_spec.rb +++ b/spec/ruby/library/bigdecimal/to_i_spec.rb @@ -3,5 +3,5 @@ require_relative 'shared/to_int' require 'bigdecimal' describe "BigDecimal#to_i" do - it_behaves_like :bigdecimal_to_int, :to_i + it_behaves_like :bigdecimal_to_int, :to_i end diff --git a/spec/ruby/library/bigdecimal/to_s_spec.rb b/spec/ruby/library/bigdecimal/to_s_spec.rb index 4f1054d38e..ba9f960eb3 100644 --- a/spec/ruby/library/bigdecimal/to_s_spec.rb +++ b/spec/ruby/library/bigdecimal/to_s_spec.rb @@ -39,20 +39,25 @@ describe "BigDecimal#to_s" do @bigneg.to_s("+").should_not =~ /^\+.*/ end - it "inserts a space every n chars, if integer n is supplied" do + it "inserts a space every n chars to fraction part, if integer n is supplied" do re =\ - /\A0\.314 159 265 358 979 323 846 264 338 327 950 288 419 716 939 937E1\z/i + /\A0\.314 159 265 358 979 323 846 264 338 327 950 288 419 716 939 937E1\z/i @bigdec.to_s(3).should =~ re str1 = '-123.45678 90123 45678 9' BigDecimal("-123.45678901234567890").to_s('5F').should == str1 - BigDecimal('1000010').to_s('5F').should == "10000 10.0" # trailing zeroes removed BigDecimal("1.00000000000").to_s('1F').should == "1.0" # 0 is treated as no spaces BigDecimal("1.2345").to_s('0F').should == "1.2345" end + version_is BigDecimal::VERSION, "3.1.5" do #ruby_version_is '3.3' do + it "inserts a space every n chars to integer part, if integer n is supplied" do + BigDecimal('1000010').to_s('5F').should == "10 00010.0" + end + end + it "can return a leading space for values > 0" do @bigdec.to_s(" F").should =~ /\ .*/ @bigneg.to_s(" F").should_not =~ /\ .*/ @@ -83,15 +88,13 @@ describe "BigDecimal#to_s" do end end - ruby_version_is "3.0" do - it "returns a String in US-ASCII encoding when Encoding.default_internal is nil" do - Encoding.default_internal = nil - BigDecimal('1.23').to_s.encoding.should equal(Encoding::US_ASCII) - end + it "returns a String in US-ASCII encoding when Encoding.default_internal is nil" do + Encoding.default_internal = nil + BigDecimal('1.23').to_s.encoding.should equal(Encoding::US_ASCII) + end - it "returns a String in US-ASCII encoding when Encoding.default_internal is not nil" do - Encoding.default_internal = Encoding::IBM437 - BigDecimal('1.23').to_s.encoding.should equal(Encoding::US_ASCII) - end + it "returns a String in US-ASCII encoding when Encoding.default_internal is not nil" do + Encoding.default_internal = Encoding::IBM437 + BigDecimal('1.23').to_s.encoding.should equal(Encoding::US_ASCII) end end diff --git a/spec/ruby/library/bigdecimal/truncate_spec.rb b/spec/ruby/library/bigdecimal/truncate_spec.rb index 4ad9eb92d1..0ae0421b30 100644 --- a/spec/ruby/library/bigdecimal/truncate_spec.rb +++ b/spec/ruby/library/bigdecimal/truncate_spec.rb @@ -4,11 +4,11 @@ require 'bigdecimal' describe "BigDecimal#truncate" do before :each do - @arr = ['3.14159', '8.7', "0.314159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593014782083152134043E1"] - @big = BigDecimal("123456.789") - @nan = BigDecimal('NaN') - @infinity = BigDecimal('Infinity') - @infinity_negative = BigDecimal('-Infinity') + @arr = ['3.14159', '8.7', "0.314159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593014782083152134043E1"] + @big = BigDecimal("123456.789") + @nan = BigDecimal('NaN') + @infinity = BigDecimal('Infinity') + @infinity_negative = BigDecimal('-Infinity') end it "returns value of type Integer." do diff --git a/spec/ruby/library/bigmath/log_spec.rb b/spec/ruby/library/bigmath/log_spec.rb deleted file mode 100644 index 2ffbf8b6b9..0000000000 --- a/spec/ruby/library/bigmath/log_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require_relative '../../spec_helper' -require 'bigdecimal' - -describe "BigDecimal#log" do - it "handles high-precision Rational arguments" do - result = BigDecimal('0.22314354220170971436137296411949880462556361100856391620766259404746040597133837784E0') - r = Rational(1_234_567_890, 987_654_321) - BigMath.log(r, 50).should == result - end -end diff --git a/spec/ruby/library/cgi/cookie/domain_spec.rb b/spec/ruby/library/cgi/cookie/domain_spec.rb index 962609ebaf..0ed56d6d61 100644 --- a/spec/ruby/library/cgi/cookie/domain_spec.rb +++ b/spec/ruby/library/cgi/cookie/domain_spec.rb @@ -1,23 +1,26 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::Cookie#domain" do - it "returns self's domain" do - cookie = CGI::Cookie.new("test-cookie") - cookie.domain.should be_nil +ruby_version_is ""..."4.0" do + require 'cgi' - cookie = CGI::Cookie.new("name" => "test-cookie", "domain" => "example.com") - cookie.domain.should == "example.com" + describe "CGI::Cookie#domain" do + it "returns self's domain" do + cookie = CGI::Cookie.new("test-cookie") + cookie.domain.should be_nil + + cookie = CGI::Cookie.new("name" => "test-cookie", "domain" => "example.com") + cookie.domain.should == "example.com" + end end -end -describe "CGI::Cookie#domain=" do - it "sets self's domain" do - cookie = CGI::Cookie.new("test-cookie") - cookie.domain = "test.com" - cookie.domain.should == "test.com" + describe "CGI::Cookie#domain=" do + it "sets self's domain" do + cookie = CGI::Cookie.new("test-cookie") + cookie.domain = "test.com" + cookie.domain.should == "test.com" - cookie.domain = "example.com" - cookie.domain.should == "example.com" + cookie.domain = "example.com" + cookie.domain.should == "example.com" + end end end diff --git a/spec/ruby/library/cgi/cookie/expires_spec.rb b/spec/ruby/library/cgi/cookie/expires_spec.rb index c8f26d01cd..c5b2c4faf9 100644 --- a/spec/ruby/library/cgi/cookie/expires_spec.rb +++ b/spec/ruby/library/cgi/cookie/expires_spec.rb @@ -1,23 +1,26 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::Cookie#expires" do - it "returns self's expiration date" do - cookie = CGI::Cookie.new("test-cookie") - cookie.expires.should be_nil +ruby_version_is ""..."4.0" do + require 'cgi' - cookie = CGI::Cookie.new("name" => "test-cookie", "expires" => Time.at(1196524602)) - cookie.expires.should == Time.at(1196524602) + describe "CGI::Cookie#expires" do + it "returns self's expiration date" do + cookie = CGI::Cookie.new("test-cookie") + cookie.expires.should be_nil + + cookie = CGI::Cookie.new("name" => "test-cookie", "expires" => Time.at(1196524602)) + cookie.expires.should == Time.at(1196524602) + end end -end -describe "CGI::Cookie#expires=" do - it "sets self's expiration date" do - cookie = CGI::Cookie.new("test-cookie") - cookie.expires = Time.at(1196524602) - cookie.expires.should == Time.at(1196524602) + describe "CGI::Cookie#expires=" do + it "sets self's expiration date" do + cookie = CGI::Cookie.new("test-cookie") + cookie.expires = Time.at(1196524602) + cookie.expires.should == Time.at(1196524602) - cookie.expires = Time.at(1196525000) - cookie.expires.should == Time.at(1196525000) + cookie.expires = Time.at(1196525000) + cookie.expires.should == Time.at(1196525000) + end end end diff --git a/spec/ruby/library/cgi/cookie/initialize_spec.rb b/spec/ruby/library/cgi/cookie/initialize_spec.rb index 4b6e104b10..248f35e78b 100644 --- a/spec/ruby/library/cgi/cookie/initialize_spec.rb +++ b/spec/ruby/library/cgi/cookie/initialize_spec.rb @@ -1,147 +1,150 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::Cookie#initialize when passed String" do - before :each do - @cookie = CGI::Cookie.allocate - end - - it "sets the self's name to the passed String" do - @cookie.send(:initialize, "test-cookie") - @cookie.name.should == "test-cookie" - end +ruby_version_is ""..."4.0" do + require 'cgi' - it "sets the self's value to an empty Array" do - @cookie.send(:initialize, "test-cookie") - @cookie.value.should == [] - end - - it "sets self to a non-secure cookie" do - @cookie.send(:initialize, "test") - @cookie.secure.should be_false - end - - it "does set self's path to an empty String when ENV[\"SCRIPT_NAME\"] is not set" do - @cookie.send(:initialize, "test-cookie") - @cookie.path.should == "" - end - - it "does set self's path based on ENV[\"SCRIPT_NAME\"] when ENV[\"SCRIPT_NAME\"] is set" do - old_script_name = ENV["SCRIPT_NAME"] + describe "CGI::Cookie#initialize when passed String" do + before :each do + @cookie = CGI::Cookie.allocate + end - begin - ENV["SCRIPT_NAME"] = "some/path/script.rb" + it "sets the self's name to the passed String" do @cookie.send(:initialize, "test-cookie") - @cookie.path.should == "some/path/" + @cookie.name.should == "test-cookie" + end - ENV["SCRIPT_NAME"] = "script.rb" + it "sets the self's value to an empty Array" do @cookie.send(:initialize, "test-cookie") - @cookie.path.should == "" + @cookie.value.should == [] + end - ENV["SCRIPT_NAME"] = nil + it "sets self to a non-secure cookie" do + @cookie.send(:initialize, "test") + @cookie.secure.should be_false + end + + it "does set self's path to an empty String when ENV[\"SCRIPT_NAME\"] is not set" do @cookie.send(:initialize, "test-cookie") @cookie.path.should == "" - ensure - ENV["SCRIPT_NAME"] = old_script_name end - end - it "does not set self's expiration date" do - @cookie.expires.should be_nil - end + it "does set self's path based on ENV[\"SCRIPT_NAME\"] when ENV[\"SCRIPT_NAME\"] is set" do + old_script_name = ENV["SCRIPT_NAME"] - it "does not set self's domain" do - @cookie.domain.should be_nil - end -end + begin + ENV["SCRIPT_NAME"] = "some/path/script.rb" + @cookie.send(:initialize, "test-cookie") + @cookie.path.should == "some/path/" -describe "CGI::Cookie#initialize when passed Hash" do - before :each do - @cookie = CGI::Cookie.allocate - end + ENV["SCRIPT_NAME"] = "script.rb" + @cookie.send(:initialize, "test-cookie") + @cookie.path.should == "" + + ENV["SCRIPT_NAME"] = nil + @cookie.send(:initialize, "test-cookie") + @cookie.path.should == "" + ensure + ENV["SCRIPT_NAME"] = old_script_name + end + end + + it "does not set self's expiration date" do + @cookie.expires.should be_nil + end - it "sets self's contents based on the passed Hash" do - @cookie.send(:initialize, - 'name' => 'test-cookie', - 'value' => ["one", "two", "three"], - 'path' => 'some/path/', - 'domain' => 'example.com', - 'expires' => Time.at(1196524602), - 'secure' => true) - - @cookie.name.should == "test-cookie" - @cookie.value.should == ["one", "two", "three"] - @cookie.path.should == "some/path/" - @cookie.domain.should == "example.com" - @cookie.expires.should == Time.at(1196524602) - @cookie.secure.should be_true + it "does not set self's domain" do + @cookie.domain.should be_nil + end end - it "does set self's path based on ENV[\"SCRIPT_NAME\"] when the Hash has no 'path' entry" do - old_script_name = ENV["SCRIPT_NAME"] + describe "CGI::Cookie#initialize when passed Hash" do + before :each do + @cookie = CGI::Cookie.allocate + end - begin - ENV["SCRIPT_NAME"] = "some/path/script.rb" - @cookie.send(:initialize, 'name' => 'test-cookie') + it "sets self's contents based on the passed Hash" do + @cookie.send(:initialize, + 'name' => 'test-cookie', + 'value' => ["one", "two", "three"], + 'path' => 'some/path/', + 'domain' => 'example.com', + 'expires' => Time.at(1196524602), + 'secure' => true) + + @cookie.name.should == "test-cookie" + @cookie.value.should == ["one", "two", "three"] @cookie.path.should == "some/path/" + @cookie.domain.should == "example.com" + @cookie.expires.should == Time.at(1196524602) + @cookie.secure.should be_true + end - ENV["SCRIPT_NAME"] = "script.rb" - @cookie.send(:initialize, 'name' => 'test-cookie') - @cookie.path.should == "" + it "does set self's path based on ENV[\"SCRIPT_NAME\"] when the Hash has no 'path' entry" do + old_script_name = ENV["SCRIPT_NAME"] - ENV["SCRIPT_NAME"] = nil - @cookie.send(:initialize, 'name' => 'test-cookie') - @cookie.path.should == "" - ensure - ENV["SCRIPT_NAME"] = old_script_name + begin + ENV["SCRIPT_NAME"] = "some/path/script.rb" + @cookie.send(:initialize, 'name' => 'test-cookie') + @cookie.path.should == "some/path/" + + ENV["SCRIPT_NAME"] = "script.rb" + @cookie.send(:initialize, 'name' => 'test-cookie') + @cookie.path.should == "" + + ENV["SCRIPT_NAME"] = nil + @cookie.send(:initialize, 'name' => 'test-cookie') + @cookie.path.should == "" + ensure + ENV["SCRIPT_NAME"] = old_script_name + end end - end - it "tries to convert the Hash's 'value' to an Array using #Array" do - obj = mock("Converted To Array") - obj.should_receive(:to_ary).and_return(["1", "2", "3"]) - @cookie.send(:initialize, - 'name' => 'test-cookie', - 'value' => obj) - @cookie.value.should == [ "1", "2", "3" ] - - obj = mock("Converted To Array") - obj.should_receive(:to_a).and_return(["one", "two", "three"]) - @cookie.send(:initialize, - 'name' => 'test-cookie', - 'value' => obj) - @cookie.value.should == [ "one", "two", "three" ] - - obj = mock("Put into an Array") - @cookie.send(:initialize, - 'name' => 'test-cookie', - 'value' => obj) - @cookie.value.should == [ obj ] - end + it "tries to convert the Hash's 'value' to an Array using #Array" do + obj = mock("Converted To Array") + obj.should_receive(:to_ary).and_return(["1", "2", "3"]) + @cookie.send(:initialize, + 'name' => 'test-cookie', + 'value' => obj) + @cookie.value.should == [ "1", "2", "3" ] + + obj = mock("Converted To Array") + obj.should_receive(:to_a).and_return(["one", "two", "three"]) + @cookie.send(:initialize, + 'name' => 'test-cookie', + 'value' => obj) + @cookie.value.should == [ "one", "two", "three" ] + + obj = mock("Put into an Array") + @cookie.send(:initialize, + 'name' => 'test-cookie', + 'value' => obj) + @cookie.value.should == [ obj ] + end - it "raises a ArgumentError when the passed Hash has no 'name' entry" do - -> { @cookie.send(:initialize, {}) }.should raise_error(ArgumentError) - -> { @cookie.send(:initialize, "value" => "test") }.should raise_error(ArgumentError) + it "raises a ArgumentError when the passed Hash has no 'name' entry" do + -> { @cookie.send(:initialize, {}) }.should raise_error(ArgumentError) + -> { @cookie.send(:initialize, "value" => "test") }.should raise_error(ArgumentError) + end end -end -describe "CGI::Cookie#initialize when passed String, values ..." do - before :each do - @cookie = CGI::Cookie.allocate - end + describe "CGI::Cookie#initialize when passed String, values ..." do + before :each do + @cookie = CGI::Cookie.allocate + end - it "sets the self's name to the passed String" do - @cookie.send(:initialize, "test-cookie", "one", "two", "three") - @cookie.name.should == "test-cookie" - end + it "sets the self's name to the passed String" do + @cookie.send(:initialize, "test-cookie", "one", "two", "three") + @cookie.name.should == "test-cookie" + end - it "sets the self's value to an Array containing all passed values" do - @cookie.send(:initialize, "test-cookie", "one", "two", "three") - @cookie.value.should == ["one", "two", "three"] - end + it "sets the self's value to an Array containing all passed values" do + @cookie.send(:initialize, "test-cookie", "one", "two", "three") + @cookie.value.should == ["one", "two", "three"] + end - it "sets self to a non-secure cookie" do - @cookie.send(:initialize, "test", "one", "two", "three") - @cookie.secure.should be_false + it "sets self to a non-secure cookie" do + @cookie.send(:initialize, "test", "one", "two", "three") + @cookie.secure.should be_false + end end end diff --git a/spec/ruby/library/cgi/cookie/name_spec.rb b/spec/ruby/library/cgi/cookie/name_spec.rb index 326a43ade3..4908204e8a 100644 --- a/spec/ruby/library/cgi/cookie/name_spec.rb +++ b/spec/ruby/library/cgi/cookie/name_spec.rb @@ -1,23 +1,26 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::Cookie#name" do - it "returns self's name" do - cookie = CGI::Cookie.new("test-cookie") - cookie.name.should == "test-cookie" +ruby_version_is ""..."4.0" do + require 'cgi' - cookie = CGI::Cookie.new("name" => "another-cookie") - cookie.name.should == "another-cookie" + describe "CGI::Cookie#name" do + it "returns self's name" do + cookie = CGI::Cookie.new("test-cookie") + cookie.name.should == "test-cookie" + + cookie = CGI::Cookie.new("name" => "another-cookie") + cookie.name.should == "another-cookie" + end end -end -describe "CGI::Cookie#name=" do - it "sets self's expiration date" do - cookie = CGI::Cookie.new("test-cookie") - cookie.name = "another-name" - cookie.name.should == "another-name" + describe "CGI::Cookie#name=" do + it "sets self's expiration date" do + cookie = CGI::Cookie.new("test-cookie") + cookie.name = "another-name" + cookie.name.should == "another-name" - cookie.name = "and-one-more" - cookie.name.should == "and-one-more" + cookie.name = "and-one-more" + cookie.name.should == "and-one-more" + end end end diff --git a/spec/ruby/library/cgi/cookie/parse_spec.rb b/spec/ruby/library/cgi/cookie/parse_spec.rb index d484c7bad9..bc505c37ba 100644 --- a/spec/ruby/library/cgi/cookie/parse_spec.rb +++ b/spec/ruby/library/cgi/cookie/parse_spec.rb @@ -1,26 +1,29 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::Cookie.parse" do - it "parses a raw cookie string into a hash of Cookies" do - expected = { "test-cookie" => ["one", "two", "three"] } - CGI::Cookie.parse("test-cookie=one&two&three").should == expected +ruby_version_is ""..."4.0" do + require 'cgi' - expected = { "second-cookie" => ["three", "four"], "first-cookie" => ["one", "two"] } - CGI::Cookie.parse("first-cookie=one&two;second-cookie=three&four").should == expected - end + describe "CGI::Cookie.parse" do + it "parses a raw cookie string into a hash of Cookies" do + expected = { "test-cookie" => ["one", "two", "three"] } + CGI::Cookie.parse("test-cookie=one&two&three").should == expected - it "does not use , for cookie separators" do - expected = { - "first-cookie" => ["one", "two"], - "second-cookie" => ["three", "four,third_cookie=five", "six"] - } - CGI::Cookie.parse("first-cookie=one&two;second-cookie=three&four,third_cookie=five&six").should == expected - end + expected = { "second-cookie" => ["three", "four"], "first-cookie" => ["one", "two"] } + CGI::Cookie.parse("first-cookie=one&two;second-cookie=three&four").should == expected + end + + it "does not use , for cookie separators" do + expected = { + "first-cookie" => ["one", "two"], + "second-cookie" => ["three", "four,third_cookie=five", "six"] + } + CGI::Cookie.parse("first-cookie=one&two;second-cookie=three&four,third_cookie=five&six").should == expected + end - it "unescapes the Cookie values" do - cookie = "test-cookie=+%21%22%23%24%25%26%27%28%29%2A%2B%2C-.%2F0123456789%3A%3B%3C%3D%3E%3F%40ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D%7E" - expected = { "test-cookie" => [ " !\"\#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~" ] } - CGI::Cookie.parse(cookie).should == expected + it "unescapes the Cookie values" do + cookie = "test-cookie=+%21%22%23%24%25%26%27%28%29%2A%2B%2C-.%2F0123456789%3A%3B%3C%3D%3E%3F%40ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D%7E" + expected = { "test-cookie" => [ " !\"\#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~" ] } + CGI::Cookie.parse(cookie).should == expected + end end end diff --git a/spec/ruby/library/cgi/cookie/path_spec.rb b/spec/ruby/library/cgi/cookie/path_spec.rb index 8a2f05aa50..13ee5d726b 100644 --- a/spec/ruby/library/cgi/cookie/path_spec.rb +++ b/spec/ruby/library/cgi/cookie/path_spec.rb @@ -1,23 +1,26 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::Cookie#path" do - it "returns self's path" do - cookie = CGI::Cookie.new("test-cookie") - cookie.path.should == "" +ruby_version_is ""..."4.0" do + require 'cgi' - cookie = CGI::Cookie.new("name" => "test-cookie", "path" => "/some/path/") - cookie.path.should == "/some/path/" + describe "CGI::Cookie#path" do + it "returns self's path" do + cookie = CGI::Cookie.new("test-cookie") + cookie.path.should == "" + + cookie = CGI::Cookie.new("name" => "test-cookie", "path" => "/some/path/") + cookie.path.should == "/some/path/" + end end -end -describe "CGI::Cookie#path=" do - it "sets self's path" do - cookie = CGI::Cookie.new("test-cookie") - cookie.path = "/some/path/" - cookie.path.should == "/some/path/" + describe "CGI::Cookie#path=" do + it "sets self's path" do + cookie = CGI::Cookie.new("test-cookie") + cookie.path = "/some/path/" + cookie.path.should == "/some/path/" - cookie.path = "/another/path/" - cookie.path.should == "/another/path/" + cookie.path = "/another/path/" + cookie.path.should == "/another/path/" + end end end diff --git a/spec/ruby/library/cgi/cookie/secure_spec.rb b/spec/ruby/library/cgi/cookie/secure_spec.rb index 694bc2eeed..cb38c8c2e0 100644 --- a/spec/ruby/library/cgi/cookie/secure_spec.rb +++ b/spec/ruby/library/cgi/cookie/secure_spec.rb @@ -1,70 +1,73 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::Cookie#secure" do - before :each do - @cookie = CGI::Cookie.new("test-cookie") - end +ruby_version_is ""..."4.0" do + require 'cgi' - it "returns whether self is a secure cookie or not" do - @cookie.secure = true - @cookie.secure.should be_true + describe "CGI::Cookie#secure" do + before :each do + @cookie = CGI::Cookie.new("test-cookie") + end - @cookie.secure = false - @cookie.secure.should be_false - end -end + it "returns whether self is a secure cookie or not" do + @cookie.secure = true + @cookie.secure.should be_true -describe "CGI::Cookie#secure= when passed true" do - before :each do - @cookie = CGI::Cookie.new("test-cookie") + @cookie.secure = false + @cookie.secure.should be_false + end end - it "returns true" do - (@cookie.secure = true).should be_true - end + describe "CGI::Cookie#secure= when passed true" do + before :each do + @cookie = CGI::Cookie.new("test-cookie") + end - it "sets self to a secure cookie" do - @cookie.secure = true - @cookie.secure.should be_true - end -end + it "returns true" do + (@cookie.secure = true).should be_true + end -describe "CGI::Cookie#secure= when passed false" do - before :each do - @cookie = CGI::Cookie.new("test-cookie") + it "sets self to a secure cookie" do + @cookie.secure = true + @cookie.secure.should be_true + end end - it "returns false" do - (@cookie.secure = false).should be_false - end + describe "CGI::Cookie#secure= when passed false" do + before :each do + @cookie = CGI::Cookie.new("test-cookie") + end - it "sets self to a non-secure cookie" do - @cookie.secure = false - @cookie.secure.should be_false - end -end + it "returns false" do + (@cookie.secure = false).should be_false + end -describe "CGI::Cookie#secure= when passed Object" do - before :each do - @cookie = CGI::Cookie.new("test-cookie") + it "sets self to a non-secure cookie" do + @cookie.secure = false + @cookie.secure.should be_false + end end - it "does not change self's secure value" do - @cookie.secure = false + describe "CGI::Cookie#secure= when passed Object" do + before :each do + @cookie = CGI::Cookie.new("test-cookie") + end + + it "does not change self's secure value" do + @cookie.secure = false - @cookie.secure = Object.new - @cookie.secure.should be_false + @cookie.secure = Object.new + @cookie.secure.should be_false - @cookie.secure = "Test" - @cookie.secure.should be_false + @cookie.secure = "Test" + @cookie.secure.should be_false - @cookie.secure = true + @cookie.secure = true - @cookie.secure = Object.new - @cookie.secure.should be_true + @cookie.secure = Object.new + @cookie.secure.should be_true - @cookie.secure = "Test" - @cookie.secure.should be_true + @cookie.secure = "Test" + @cookie.secure.should be_true + end end end diff --git a/spec/ruby/library/cgi/cookie/to_s_spec.rb b/spec/ruby/library/cgi/cookie/to_s_spec.rb index da15e6ed2a..20d2579f8d 100644 --- a/spec/ruby/library/cgi/cookie/to_s_spec.rb +++ b/spec/ruby/library/cgi/cookie/to_s_spec.rb @@ -1,33 +1,36 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::Cookie#to_s" do - it "returns a String representation of self" do - cookie = CGI::Cookie.new("test-cookie") - cookie.to_s.should == "test-cookie=; path=" +ruby_version_is ""..."4.0" do + require 'cgi' - cookie = CGI::Cookie.new("test-cookie", "value") - cookie.to_s.should == "test-cookie=value; path=" + describe "CGI::Cookie#to_s" do + it "returns a String representation of self" do + cookie = CGI::Cookie.new("test-cookie") + cookie.to_s.should == "test-cookie=; path=" - cookie = CGI::Cookie.new("test-cookie", "one", "two", "three") - cookie.to_s.should == "test-cookie=one&two&three; path=" + cookie = CGI::Cookie.new("test-cookie", "value") + cookie.to_s.should == "test-cookie=value; path=" - cookie = CGI::Cookie.new( - 'name' => 'test-cookie', - 'value' => ["one", "two", "three"], - 'path' => 'some/path/', - 'domain' => 'example.com', - 'expires' => Time.at(1196524602), - 'secure' => true) - cookie.to_s.should == "test-cookie=one&two&three; domain=example.com; path=some/path/; expires=Sat, 01 Dec 2007 15:56:42 GMT; secure" - end + cookie = CGI::Cookie.new("test-cookie", "one", "two", "three") + cookie.to_s.should == "test-cookie=one&two&three; path=" - it "escapes the self's values" do - cookie = CGI::Cookie.new("test-cookie", " !\"\#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}") - cookie.to_s.should == "test-cookie=+%21%22%23%24%25%26%27%28%29%2A%2B%2C-.%2F0123456789%3A%3B%3C%3D%3E%3F%40ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D; path=" - end + cookie = CGI::Cookie.new( + 'name' => 'test-cookie', + 'value' => ["one", "two", "three"], + 'path' => 'some/path/', + 'domain' => 'example.com', + 'expires' => Time.at(1196524602), + 'secure' => true) + cookie.to_s.should == "test-cookie=one&two&three; domain=example.com; path=some/path/; expires=Sat, 01 Dec 2007 15:56:42 GMT; secure" + end + + it "escapes the self's values" do + cookie = CGI::Cookie.new("test-cookie", " !\"\#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}") + cookie.to_s.should == "test-cookie=+%21%22%23%24%25%26%27%28%29%2A%2B%2C-.%2F0123456789%3A%3B%3C%3D%3E%3F%40ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D; path=" + end - it "does not escape tilde" do - cookie = CGI::Cookie.new("test-cookie", "~").to_s.should == "test-cookie=~; path=" + it "does not escape tilde" do + cookie = CGI::Cookie.new("test-cookie", "~").to_s.should == "test-cookie=~; path=" + end end end diff --git a/spec/ruby/library/cgi/cookie/value_spec.rb b/spec/ruby/library/cgi/cookie/value_spec.rb index 1d5da3a3ac..672653d7f4 100644 --- a/spec/ruby/library/cgi/cookie/value_spec.rb +++ b/spec/ruby/library/cgi/cookie/value_spec.rb @@ -1,76 +1,79 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::Cookie#value" do - it "returns self's value" do - cookie = CGI::Cookie.new("test-cookie") - cookie.value.should == [] +ruby_version_is ""..."4.0" do + require 'cgi' - cookie = CGI::Cookie.new("test-cookie", "one") - cookie.value.should == ["one"] + describe "CGI::Cookie#value" do + it "returns self's value" do + cookie = CGI::Cookie.new("test-cookie") + cookie.value.should == [] - cookie = CGI::Cookie.new("test-cookie", "one", "two", "three") - cookie.value.should == ["one", "two", "three"] + cookie = CGI::Cookie.new("test-cookie", "one") + cookie.value.should == ["one"] - cookie = CGI::Cookie.new("name" => "test-cookie", "value" => ["one", "two", "three"]) - cookie.value.should == ["one", "two", "three"] - end + cookie = CGI::Cookie.new("test-cookie", "one", "two", "three") + cookie.value.should == ["one", "two", "three"] - it "is in synch with self" do - fail = [] - [ - :pop, - :shift, - [:<<, "Hello"], - [:push, "Hello"], - [:unshift, "World"], - [:replace, ["A", "B"]], - [:[]=, 1, "Set"], - [:delete, "first"], - [:delete_at, 0], - ].each do |method, *args| - cookie1 = CGI::Cookie.new("test-cookie", "first", "second") - cookie2 = CGI::Cookie.new("test-cookie", "first", "second") - cookie1.send(method, *args) - cookie2.value.send(method, *args) - fail << method unless cookie1.value == cookie2.value + cookie = CGI::Cookie.new("name" => "test-cookie", "value" => ["one", "two", "three"]) + cookie.value.should == ["one", "two", "three"] end - fail.should be_empty - end -end -describe "CGI::Cookie#value=" do - before :each do - @cookie = CGI::Cookie.new("test-cookie") + it "is in synch with self" do + fail = [] + [ + :pop, + :shift, + [:<<, "Hello"], + [:push, "Hello"], + [:unshift, "World"], + [:replace, ["A", "B"]], + [:[]=, 1, "Set"], + [:delete, "first"], + [:delete_at, 0], + ].each do |method, *args| + cookie1 = CGI::Cookie.new("test-cookie", "first", "second") + cookie2 = CGI::Cookie.new("test-cookie", "first", "second") + cookie1.send(method, *args) + cookie2.value.send(method, *args) + fail << method unless cookie1.value == cookie2.value + end + fail.should be_empty + end end - it "sets self's value" do - @cookie.value = ["one"] - @cookie.value.should == ["one"] + describe "CGI::Cookie#value=" do + before :each do + @cookie = CGI::Cookie.new("test-cookie") + end - @cookie.value = ["one", "two", "three"] - @cookie.value.should == ["one", "two", "three"] - end + it "sets self's value" do + @cookie.value = ["one"] + @cookie.value.should == ["one"] - it "automatically converts the passed Object to an Array using #Array" do - @cookie.value = "test" - @cookie.value.should == ["test"] + @cookie.value = ["one", "two", "three"] + @cookie.value.should == ["one", "two", "three"] + end - obj = mock("to_a") - obj.should_receive(:to_a).and_return(["1", "2"]) - @cookie.value = obj - @cookie.value.should == ["1", "2"] + it "automatically converts the passed Object to an Array using #Array" do + @cookie.value = "test" + @cookie.value.should == ["test"] - obj = mock("to_ary") - obj.should_receive(:to_ary).and_return(["1", "2"]) - @cookie.value = obj - @cookie.value.should == ["1", "2"] - end + obj = mock("to_a") + obj.should_receive(:to_a).and_return(["1", "2"]) + @cookie.value = obj + @cookie.value.should == ["1", "2"] - it "does keep self and the values in sync" do - @cookie.value = ["one", "two", "three"] - @cookie[0].should == "one" - @cookie[1].should == "two" - @cookie[2].should == "three" + obj = mock("to_ary") + obj.should_receive(:to_ary).and_return(["1", "2"]) + @cookie.value = obj + @cookie.value.should == ["1", "2"] + end + + it "does keep self and the values in sync" do + @cookie.value = ["one", "two", "three"] + @cookie[0].should == "one" + @cookie[1].should == "two" + @cookie[2].should == "three" + end end end diff --git a/spec/ruby/library/cgi/escapeElement_spec.rb b/spec/ruby/library/cgi/escapeElement_spec.rb index 148926c453..72c38d6028 100644 --- a/spec/ruby/library/cgi/escapeElement_spec.rb +++ b/spec/ruby/library/cgi/escapeElement_spec.rb @@ -1,5 +1,11 @@ require_relative '../../spec_helper' -require 'cgi' + +ruby_version_is ""..."4.0" do + require 'cgi' +end +ruby_version_is "4.0" do + require 'cgi/escape' +end describe "CGI.escapeElement when passed String, elements, ..." do it "escapes only the tags of the passed elements in the passed String" do diff --git a/spec/ruby/library/cgi/escapeHTML_spec.rb b/spec/ruby/library/cgi/escapeHTML_spec.rb index 421aac5d4a..6e70e87ed7 100644 --- a/spec/ruby/library/cgi/escapeHTML_spec.rb +++ b/spec/ruby/library/cgi/escapeHTML_spec.rb @@ -1,5 +1,9 @@ require_relative '../../spec_helper' -require 'cgi' +begin + require 'cgi/escape' +rescue LoadError + require 'cgi' +end describe "CGI.escapeHTML" do it "escapes special HTML characters (&\"<>') in the passed argument" do diff --git a/spec/ruby/library/cgi/escapeURIComponent_spec.rb b/spec/ruby/library/cgi/escapeURIComponent_spec.rb new file mode 100644 index 0000000000..1cea2b786a --- /dev/null +++ b/spec/ruby/library/cgi/escapeURIComponent_spec.rb @@ -0,0 +1,78 @@ +require_relative '../../spec_helper' +begin + require 'cgi/escape' +rescue LoadError + require 'cgi' +end + +describe "CGI.escapeURIComponent" do + it "percent-encodes characters reserved according to RFC 3986" do + # https://www.rfc-editor.org/rfc/rfc3986#section-2.2 + string = ":/?#[]@!$&'()*+,;=" + CGI.escapeURIComponent(string).should == "%3A%2F%3F%23%5B%5D%40%21%24%26%27%28%29%2A%2B%2C%3B%3D" + end + + it "does not percent-encode unreserved characters according to RFC 3986" do + string = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~" + CGI.escapeURIComponent(string).should == "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~" + end + + it "encodes % character as %25" do + CGI.escapeURIComponent("%").should == "%25" + end + + # Compare to .escape which uses "+". + it "percent-encodes single whitespace" do + CGI.escapeURIComponent(" ").should == "%20" + end + + it "percent-encodes all non-reserved and non-unreserved ASCII characters" do + special_set = ":/?#[]@!$&'()*+,;=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~" + all_other = (0x00..0x7F).filter_map { |i| i.chr unless special_set.include?(i.chr) }.join + encoded = CGI.escapeURIComponent(all_other) + encoded.should.match?(/\A(?:%[0-9A-F]{2}){#{all_other.length}}\z/) + end + + it "percent-encodes non-ASCII bytes" do + bytes = (0x80..0xFF).map(&:chr).join + encoded = CGI.escapeURIComponent(bytes) + encoded.should.match?(/\A(?:%[0-9A-F]{2}){#{bytes.length}}\z/) + end + + it "processes multi-byte characters as separate bytes, percent-encoding each one" do + CGI.escapeURIComponent("β").should == "%CE%B2" # "β" bytes representation is CE B2 + end + + it "produces a copy of an empty string" do + string = "".encode(Encoding::BINARY) + encoded = CGI.escapeURIComponent(string) + encoded.should == "" + encoded.encoding.should == Encoding::BINARY + string.should_not.equal?(encoded) + end + + it "preserves string's encoding" do + string = "whatever".encode("ASCII-8BIT") + CGI.escapeURIComponent(string).encoding.should == Encoding::ASCII_8BIT + end + + it "processes even strings with invalid encoding, percent-encoding octets as-is" do + string = "\xC0<<".dup.force_encoding("UTF-8") + CGI.escapeURIComponent(string).should == "%C0%3C%3C" + end + + it "raises a TypeError with nil" do + -> { + CGI.escapeURIComponent(nil) + }.should raise_error(TypeError, "no implicit conversion of nil into String") + end + + it "uses implicit type conversion to String" do + object = Object.new + def object.to_str + "a b" + end + + CGI.escapeURIComponent(object).should == "a%20b" + end +end diff --git a/spec/ruby/library/cgi/escape_spec.rb b/spec/ruby/library/cgi/escape_spec.rb index c599a73cf0..55eb0b66c2 100644 --- a/spec/ruby/library/cgi/escape_spec.rb +++ b/spec/ruby/library/cgi/escape_spec.rb @@ -1,5 +1,9 @@ require_relative '../../spec_helper' -require 'cgi' +begin + require 'cgi/escape' +rescue LoadError + require 'cgi' +end describe "CGI.escape" do it "url-encodes the passed argument" do diff --git a/spec/ruby/library/cgi/htmlextension/a_spec.rb b/spec/ruby/library/cgi/htmlextension/a_spec.rb index 05b4c2d14c..78d3dec8fa 100644 --- a/spec/ruby/library/cgi/htmlextension/a_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/a_spec.rb @@ -1,49 +1,52 @@ require_relative '../../../spec_helper' -require 'cgi' -require_relative 'fixtures/common' -describe "CGI::HtmlExtension#a" do - before :each do - @html = CGISpecs.cgi_new - end +ruby_version_is ""..."4.0" do + require 'cgi' + require_relative 'fixtures/common' - describe "when passed a String" do - it "returns an 'a'-element, using the passed String as the 'href'-attribute" do - output = @html.a("http://www.example.com") - output.should equal_element("A", "HREF" => "http://www.example.com") + describe "CGI::HtmlExtension#a" do + before :each do + @html = CGISpecs.cgi_new end - it "includes the passed block's return value when passed a block" do - output = @html.a("http://www.example.com") { "Example" } - output.should equal_element("A", { "HREF" => "http://www.example.com" }, "Example") - end - end + describe "when passed a String" do + it "returns an 'a'-element, using the passed String as the 'href'-attribute" do + output = @html.a("http://www.example.com") + output.should equal_element("A", "HREF" => "http://www.example.com") + end - describe "when passed a Hash" do - it "returns an 'a'-element, using the passed Hash for attributes" do - attributes = {"HREF" => "http://www.example.com", "TARGET" => "_top"} - @html.a(attributes).should equal_element("A", attributes) + it "includes the passed block's return value when passed a block" do + output = @html.a("http://www.example.com") { "Example" } + output.should equal_element("A", { "HREF" => "http://www.example.com" }, "Example") + end end - it "includes the passed block's return value when passed a block" do - attributes = {"HREF" => "http://www.example.com", "TARGET" => "_top"} - @html.a(attributes) { "Example" }.should equal_element("A", attributes, "Example") - end - end + describe "when passed a Hash" do + it "returns an 'a'-element, using the passed Hash for attributes" do + attributes = {"HREF" => "http://www.example.com", "TARGET" => "_top"} + @html.a(attributes).should equal_element("A", attributes) + end - describe "when each HTML generation" do - it "returns the doctype declaration for HTML3" do - CGISpecs.cgi_new("html3").a.should == %(<A HREF=""></A>) - CGISpecs.cgi_new("html3").a { "link text" }.should == %(<A HREF="">link text</A>) + it "includes the passed block's return value when passed a block" do + attributes = {"HREF" => "http://www.example.com", "TARGET" => "_top"} + @html.a(attributes) { "Example" }.should equal_element("A", attributes, "Example") + end end - it "returns the doctype declaration for HTML4" do - CGISpecs.cgi_new("html4").a.should == %(<A HREF=""></A>) - CGISpecs.cgi_new("html4").a { "link text" }.should == %(<A HREF="">link text</A>) - end - it "returns the doctype declaration for the Transitional version of HTML4" do - CGISpecs.cgi_new("html4Tr").a.should == %(<A HREF=""></A>) - CGISpecs.cgi_new("html4Tr").a { "link text" }.should == %(<A HREF="">link text</A>) + describe "when each HTML generation" do + it "returns the doctype declaration for HTML3" do + CGISpecs.cgi_new("html3").a.should == %(<A HREF=""></A>) + CGISpecs.cgi_new("html3").a { "link text" }.should == %(<A HREF="">link text</A>) + end + + it "returns the doctype declaration for HTML4" do + CGISpecs.cgi_new("html4").a.should == %(<A HREF=""></A>) + CGISpecs.cgi_new("html4").a { "link text" }.should == %(<A HREF="">link text</A>) + end + it "returns the doctype declaration for the Transitional version of HTML4" do + CGISpecs.cgi_new("html4Tr").a.should == %(<A HREF=""></A>) + CGISpecs.cgi_new("html4Tr").a { "link text" }.should == %(<A HREF="">link text</A>) + end end end end diff --git a/spec/ruby/library/cgi/htmlextension/base_spec.rb b/spec/ruby/library/cgi/htmlextension/base_spec.rb index 877ac321cd..1eedfdea54 100644 --- a/spec/ruby/library/cgi/htmlextension/base_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/base_spec.rb @@ -1,33 +1,36 @@ require_relative '../../../spec_helper' -require 'cgi' -require_relative 'fixtures/common' -describe "CGI::HtmlExtension#base" do - before :each do - @html = CGISpecs.cgi_new - end +ruby_version_is ""..."4.0" do + require 'cgi' + require_relative 'fixtures/common' - describe "when bassed a String" do - it "returns a 'base'-element, using the passed String as the 'href'-attribute" do - output = @html.base("http://www.example.com") - output.should equal_element("BASE", {"HREF" => "http://www.example.com"}, nil, not_closed: true) + describe "CGI::HtmlExtension#base" do + before :each do + @html = CGISpecs.cgi_new end - it "ignores a passed block" do - output = @html.base("http://www.example.com") { "Example" } - output.should equal_element("BASE", {"HREF" => "http://www.example.com"}, nil, not_closed: true) - end - end + describe "when bassed a String" do + it "returns a 'base'-element, using the passed String as the 'href'-attribute" do + output = @html.base("http://www.example.com") + output.should equal_element("BASE", {"HREF" => "http://www.example.com"}, nil, not_closed: true) + end - describe "when passed a Hash" do - it "returns a 'base'-element, using the passed Hash for attributes" do - output = @html.base("HREF" => "http://www.example.com", "ID" => "test") - output.should equal_element("BASE", {"HREF" => "http://www.example.com", "ID" => "test"}, nil, not_closed: true) + it "ignores a passed block" do + output = @html.base("http://www.example.com") { "Example" } + output.should equal_element("BASE", {"HREF" => "http://www.example.com"}, nil, not_closed: true) + end end - it "ignores a passed block" do - output = @html.base("HREF" => "http://www.example.com", "ID" => "test") { "Example" } - output.should equal_element("BASE", {"HREF" => "http://www.example.com", "ID" => "test"}, nil, not_closed: true) + describe "when passed a Hash" do + it "returns a 'base'-element, using the passed Hash for attributes" do + output = @html.base("HREF" => "http://www.example.com", "ID" => "test") + output.should equal_element("BASE", {"HREF" => "http://www.example.com", "ID" => "test"}, nil, not_closed: true) + end + + it "ignores a passed block" do + output = @html.base("HREF" => "http://www.example.com", "ID" => "test") { "Example" } + output.should equal_element("BASE", {"HREF" => "http://www.example.com", "ID" => "test"}, nil, not_closed: true) + end end end end diff --git a/spec/ruby/library/cgi/htmlextension/blockquote_spec.rb b/spec/ruby/library/cgi/htmlextension/blockquote_spec.rb index a7b833b1c5..883e36f78b 100644 --- a/spec/ruby/library/cgi/htmlextension/blockquote_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/blockquote_spec.rb @@ -1,33 +1,36 @@ require_relative '../../../spec_helper' -require 'cgi' -require_relative 'fixtures/common' -describe "CGI::HtmlExtension#blockquote" do - before :each do - @html = CGISpecs.cgi_new - end +ruby_version_is ""..."4.0" do + require 'cgi' + require_relative 'fixtures/common' - describe "when passed a String" do - it "returns a 'blockquote'-element, using the passed String for the 'cite'-attribute" do - output = @html.blockquote("http://www.example.com/quotes/foo.html") - output.should equal_element("BLOCKQUOTE", "CITE" => "http://www.example.com/quotes/foo.html") + describe "CGI::HtmlExtension#blockquote" do + before :each do + @html = CGISpecs.cgi_new end - it "includes the passed block's return value when passed a block" do - output = @html.blockquote("http://www.example.com/quotes/foo.html") { "Foo!" } - output.should equal_element("BLOCKQUOTE", { "CITE" => "http://www.example.com/quotes/foo.html" }, "Foo!") - end - end + describe "when passed a String" do + it "returns a 'blockquote'-element, using the passed String for the 'cite'-attribute" do + output = @html.blockquote("http://www.example.com/quotes/foo.html") + output.should equal_element("BLOCKQUOTE", "CITE" => "http://www.example.com/quotes/foo.html") + end - describe "when passed a Hash" do - it "returns a 'blockquote'-element, using the passed Hash for attributes" do - output = @html.blockquote("CITE" => "http://www.example.com/quotes/foo.html", "ID" => "test") - output.should equal_element("BLOCKQUOTE", "CITE" => "http://www.example.com/quotes/foo.html", "ID" => "test") + it "includes the passed block's return value when passed a block" do + output = @html.blockquote("http://www.example.com/quotes/foo.html") { "Foo!" } + output.should equal_element("BLOCKQUOTE", { "CITE" => "http://www.example.com/quotes/foo.html" }, "Foo!") + end end - it "includes the passed block's return value when passed a block" do - output = @html.blockquote("CITE" => "http://www.example.com/quotes/foo.html", "ID" => "test") { "Foo!" } - output.should equal_element("BLOCKQUOTE", {"CITE" => "http://www.example.com/quotes/foo.html", "ID" => "test"}, "Foo!") + describe "when passed a Hash" do + it "returns a 'blockquote'-element, using the passed Hash for attributes" do + output = @html.blockquote("CITE" => "http://www.example.com/quotes/foo.html", "ID" => "test") + output.should equal_element("BLOCKQUOTE", "CITE" => "http://www.example.com/quotes/foo.html", "ID" => "test") + end + + it "includes the passed block's return value when passed a block" do + output = @html.blockquote("CITE" => "http://www.example.com/quotes/foo.html", "ID" => "test") { "Foo!" } + output.should equal_element("BLOCKQUOTE", {"CITE" => "http://www.example.com/quotes/foo.html", "ID" => "test"}, "Foo!") + end end end end diff --git a/spec/ruby/library/cgi/htmlextension/br_spec.rb b/spec/ruby/library/cgi/htmlextension/br_spec.rb index dfca121884..23c2cb4a48 100644 --- a/spec/ruby/library/cgi/htmlextension/br_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/br_spec.rb @@ -1,22 +1,25 @@ require_relative '../../../spec_helper' -require 'cgi' -require_relative 'fixtures/common' -describe "CGI::HtmlExtension#br" do - before :each do - @html = CGISpecs.cgi_new - end +ruby_version_is ""..."4.0" do + require 'cgi' + require_relative 'fixtures/common' - describe "when each HTML generation" do - it "returns the doctype declaration for HTML3" do - CGISpecs.cgi_new("html3").br.should == "<BR>" + describe "CGI::HtmlExtension#br" do + before :each do + @html = CGISpecs.cgi_new end - it "returns the doctype declaration for HTML4" do - CGISpecs.cgi_new("html4").br.should == "<BR>" - end - it "returns the doctype declaration for the Transitional version of HTML4" do - CGISpecs.cgi_new("html4Tr").br.should == "<BR>" + describe "when each HTML generation" do + it "returns the doctype declaration for HTML3" do + CGISpecs.cgi_new("html3").br.should == "<BR>" + end + + it "returns the doctype declaration for HTML4" do + CGISpecs.cgi_new("html4").br.should == "<BR>" + end + it "returns the doctype declaration for the Transitional version of HTML4" do + CGISpecs.cgi_new("html4Tr").br.should == "<BR>" + end end end end diff --git a/spec/ruby/library/cgi/htmlextension/caption_spec.rb b/spec/ruby/library/cgi/htmlextension/caption_spec.rb index 16615028b8..3d3e21ecaa 100644 --- a/spec/ruby/library/cgi/htmlextension/caption_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/caption_spec.rb @@ -1,33 +1,36 @@ require_relative '../../../spec_helper' -require 'cgi' -require_relative 'fixtures/common' -describe "CGI::HtmlExtension#caption" do - before :each do - @html = CGISpecs.cgi_new - end +ruby_version_is ""..."4.0" do + require 'cgi' + require_relative 'fixtures/common' - describe "when passed a String" do - it "returns a 'caption'-element, using the passed String for the 'align'-attribute" do - output = @html.caption("left") - output.should equal_element("CAPTION", "ALIGN" => "left") + describe "CGI::HtmlExtension#caption" do + before :each do + @html = CGISpecs.cgi_new end - it "includes the passed block's return value when passed a block" do - output = @html.caption("left") { "Capital Cities" } - output.should equal_element("CAPTION", {"ALIGN" => "left"}, "Capital Cities") - end - end + describe "when passed a String" do + it "returns a 'caption'-element, using the passed String for the 'align'-attribute" do + output = @html.caption("left") + output.should equal_element("CAPTION", "ALIGN" => "left") + end - describe "when passed a Hash" do - it "returns a 'caption'-element, using the passed Hash for attributes" do - output = @html.caption("ALIGN" => "left", "ID" => "test") - output.should equal_element("CAPTION", "ALIGN" => "left", "ID" => "test") + it "includes the passed block's return value when passed a block" do + output = @html.caption("left") { "Capital Cities" } + output.should equal_element("CAPTION", {"ALIGN" => "left"}, "Capital Cities") + end end - it "includes the passed block's return value when passed a block" do - output = @html.caption("ALIGN" => "left", "ID" => "test") { "Capital Cities" } - output.should equal_element("CAPTION", {"ALIGN" => "left", "ID" => "test"}, "Capital Cities") + describe "when passed a Hash" do + it "returns a 'caption'-element, using the passed Hash for attributes" do + output = @html.caption("ALIGN" => "left", "ID" => "test") + output.should equal_element("CAPTION", "ALIGN" => "left", "ID" => "test") + end + + it "includes the passed block's return value when passed a block" do + output = @html.caption("ALIGN" => "left", "ID" => "test") { "Capital Cities" } + output.should equal_element("CAPTION", {"ALIGN" => "left", "ID" => "test"}, "Capital Cities") + end end end end diff --git a/spec/ruby/library/cgi/htmlextension/checkbox_group_spec.rb b/spec/ruby/library/cgi/htmlextension/checkbox_group_spec.rb index 64f852cc52..07163c010e 100644 --- a/spec/ruby/library/cgi/htmlextension/checkbox_group_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/checkbox_group_spec.rb @@ -1,76 +1,79 @@ require_relative '../../../spec_helper' -require 'cgi' -require_relative 'fixtures/common' -describe "CGI::HtmlExtension#checkbox_group" do - before :each do - @html = CGISpecs.cgi_new - end +ruby_version_is ""..."4.0" do + require 'cgi' + require_relative 'fixtures/common' - describe "when passed name, values ..." do - it "returns a sequence of 'checkbox'-elements with the passed name and the passed values" do - output = CGISpecs.split(@html.checkbox_group("test", "foo", "bar", "baz")) - output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "foo"}, "foo", not_closed: true) - output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "bar"}, "bar", not_closed: true) - output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "baz"}, "baz", not_closed: true) + describe "CGI::HtmlExtension#checkbox_group" do + before :each do + @html = CGISpecs.cgi_new end - it "allows passing a value inside an Array" do - output = CGISpecs.split(@html.checkbox_group("test", ["foo"], "bar", ["baz"])) - output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "foo"}, "foo", not_closed: true) - output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "bar"}, "bar", not_closed: true) - output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "baz"}, "baz", not_closed: true) - end + describe "when passed name, values ..." do + it "returns a sequence of 'checkbox'-elements with the passed name and the passed values" do + output = CGISpecs.split(@html.checkbox_group("test", "foo", "bar", "baz")) + output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "foo"}, "foo", not_closed: true) + output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "bar"}, "bar", not_closed: true) + output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "baz"}, "baz", not_closed: true) + end - it "allows passing a value as an Array containing the value and the checked state or a label" do - output = CGISpecs.split(@html.checkbox_group("test", ["foo"], ["bar", true], ["baz", "label for baz"])) - output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "foo"}, "foo", not_closed: true) - output[1].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "checkbox", "VALUE" => "bar"}, "bar", not_closed: true) - output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "baz"}, "label for baz", not_closed: true) - end + it "allows passing a value inside an Array" do + output = CGISpecs.split(@html.checkbox_group("test", ["foo"], "bar", ["baz"])) + output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "foo"}, "foo", not_closed: true) + output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "bar"}, "bar", not_closed: true) + output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "baz"}, "baz", not_closed: true) + end - it "allows passing a value as an Array containing the value, a label and the checked state" do - output = CGISpecs.split(@html.checkbox_group("test", ["foo", "label for foo", true], ["bar", "label for bar", false], ["baz", "label for baz", true])) - output[0].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "checkbox", "VALUE" => "foo"}, "label for foo", not_closed: true) - output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "bar"}, "label for bar", not_closed: true) - output[2].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "checkbox", "VALUE" => "baz"}, "label for baz", not_closed: true) - end + it "allows passing a value as an Array containing the value and the checked state or a label" do + output = CGISpecs.split(@html.checkbox_group("test", ["foo"], ["bar", true], ["baz", "label for baz"])) + output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "foo"}, "foo", not_closed: true) + output[1].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "checkbox", "VALUE" => "bar"}, "bar", not_closed: true) + output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "baz"}, "label for baz", not_closed: true) + end - it "returns an empty String when passed no values" do - @html.checkbox_group("test").should == "" - end + it "allows passing a value as an Array containing the value, a label and the checked state" do + output = CGISpecs.split(@html.checkbox_group("test", ["foo", "label for foo", true], ["bar", "label for bar", false], ["baz", "label for baz", true])) + output[0].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "checkbox", "VALUE" => "foo"}, "label for foo", not_closed: true) + output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "bar"}, "label for bar", not_closed: true) + output[2].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "checkbox", "VALUE" => "baz"}, "label for baz", not_closed: true) + end + + it "returns an empty String when passed no values" do + @html.checkbox_group("test").should == "" + end - it "ignores a passed block" do - output = CGISpecs.split(@html.checkbox_group("test", "foo", "bar", "baz") { "test" }) - output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "foo"}, "foo", not_closed: true) - output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "bar"}, "bar", not_closed: true) - output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "baz"}, "baz", not_closed: true) + it "ignores a passed block" do + output = CGISpecs.split(@html.checkbox_group("test", "foo", "bar", "baz") { "test" }) + output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "foo"}, "foo", not_closed: true) + output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "bar"}, "bar", not_closed: true) + output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "baz"}, "baz", not_closed: true) + end end - end - describe "when passed Hash" do - it "uses the passed Hash to generate the checkbox sequence" do - output = CGISpecs.split(@html.checkbox_group("NAME" => "name", "VALUES" => ["foo", "bar", "baz"])) - output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "foo"}, "foo", not_closed: true) - output[1].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "bar"}, "bar", not_closed: true) - output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "baz"}, "baz", not_closed: true) + describe "when passed Hash" do + it "uses the passed Hash to generate the checkbox sequence" do + output = CGISpecs.split(@html.checkbox_group("NAME" => "name", "VALUES" => ["foo", "bar", "baz"])) + output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "foo"}, "foo", not_closed: true) + output[1].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "bar"}, "bar", not_closed: true) + output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "baz"}, "baz", not_closed: true) - output = CGISpecs.split(@html.checkbox_group("NAME" => "name", "VALUES" => [["foo"], ["bar", true], "baz"])) - output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "foo"}, "foo", not_closed: true) - output[1].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "name", "TYPE" => "checkbox", "VALUE" => "bar"}, "bar", not_closed: true) - output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "baz"}, "baz", not_closed: true) + output = CGISpecs.split(@html.checkbox_group("NAME" => "name", "VALUES" => [["foo"], ["bar", true], "baz"])) + output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "foo"}, "foo", not_closed: true) + output[1].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "name", "TYPE" => "checkbox", "VALUE" => "bar"}, "bar", not_closed: true) + output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "baz"}, "baz", not_closed: true) - output = CGISpecs.split(@html.checkbox_group("NAME" => "name", "VALUES" => [["1", "Foo"], ["2", "Bar", true], "Baz"])) - output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "1"}, "Foo", not_closed: true) - output[1].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "name", "TYPE" => "checkbox", "VALUE" => "2"}, "Bar", not_closed: true) - output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "Baz"}, "Baz", not_closed: true) - end + output = CGISpecs.split(@html.checkbox_group("NAME" => "name", "VALUES" => [["1", "Foo"], ["2", "Bar", true], "Baz"])) + output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "1"}, "Foo", not_closed: true) + output[1].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "name", "TYPE" => "checkbox", "VALUE" => "2"}, "Bar", not_closed: true) + output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "Baz"}, "Baz", not_closed: true) + end - it "ignores a passed block" do - output = CGISpecs.split(@html.checkbox_group("NAME" => "name", "VALUES" => ["foo", "bar", "baz"]) { "test" }) - output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "foo"}, "foo", not_closed: true) - output[1].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "bar"}, "bar", not_closed: true) - output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "baz"}, "baz", not_closed: true) + it "ignores a passed block" do + output = CGISpecs.split(@html.checkbox_group("NAME" => "name", "VALUES" => ["foo", "bar", "baz"]) { "test" }) + output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "foo"}, "foo", not_closed: true) + output[1].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "bar"}, "bar", not_closed: true) + output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "baz"}, "baz", not_closed: true) + end end end end diff --git a/spec/ruby/library/cgi/htmlextension/checkbox_spec.rb b/spec/ruby/library/cgi/htmlextension/checkbox_spec.rb index af76fa1da9..ad87b78061 100644 --- a/spec/ruby/library/cgi/htmlextension/checkbox_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/checkbox_spec.rb @@ -1,77 +1,80 @@ require_relative '../../../spec_helper' -require 'cgi' -require_relative 'fixtures/common' -describe "CGI::HtmlExtension#checkbox" do - before :each do - @html = CGISpecs.cgi_new - end +ruby_version_is ""..."4.0" do + require 'cgi' + require_relative 'fixtures/common' - describe "when passed no arguments" do - it "returns a checkbox-'input'-element without a name" do - output = @html.checkbox - output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "checkbox"}, "", not_closed: true) + describe "CGI::HtmlExtension#checkbox" do + before :each do + @html = CGISpecs.cgi_new end - it "ignores a passed block" do - output = @html.checkbox { "test" } - output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "checkbox"}, "", not_closed: true) - end - end + describe "when passed no arguments" do + it "returns a checkbox-'input'-element without a name" do + output = @html.checkbox + output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "checkbox"}, "", not_closed: true) + end - describe "when passed name" do - it "returns a checkbox-'input'-element with the passed name" do - output = @html.checkbox("test") - output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox"}, "", not_closed: true) + it "ignores a passed block" do + output = @html.checkbox { "test" } + output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "checkbox"}, "", not_closed: true) + end end - it "ignores a passed block" do - output = @html.checkbox("test") { "test" } - output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox"}, "", not_closed: true) - end - end + describe "when passed name" do + it "returns a checkbox-'input'-element with the passed name" do + output = @html.checkbox("test") + output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox"}, "", not_closed: true) + end - describe "CGI::HtmlExtension#checkbox when passed name, value" do - it "returns a checkbox-'input'-element with the passed name and value" do - output = @html.checkbox("test", "test-value") - output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "test-value"}, "", not_closed: true) + it "ignores a passed block" do + output = @html.checkbox("test") { "test" } + output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox"}, "", not_closed: true) + end end - it "ignores a passed block" do - output = @html.checkbox("test", "test-value") { "test" } - output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "test-value"}, "", not_closed: true) + describe "CGI::HtmlExtension#checkbox when passed name, value" do + it "returns a checkbox-'input'-element with the passed name and value" do + output = @html.checkbox("test", "test-value") + output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "test-value"}, "", not_closed: true) + end + + it "ignores a passed block" do + output = @html.checkbox("test", "test-value") { "test" } + output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "test-value"}, "", not_closed: true) + end end - end - describe "when passed name, value, checked" do - it "returns a checked checkbox-'input'-element with the passed name and value when checked is true" do - output = @html.checkbox("test", "test-value", true) - output.should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "checkbox", "VALUE" => "test-value"}, "", not_closed: true) + describe "when passed name, value, checked" do + it "returns a checked checkbox-'input'-element with the passed name and value when checked is true" do + output = @html.checkbox("test", "test-value", true) + output.should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "checkbox", "VALUE" => "test-value"}, "", not_closed: true) - output = @html.checkbox("test", "test-value", false) - output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "test-value"}, "", not_closed: true) + output = @html.checkbox("test", "test-value", false) + output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "test-value"}, "", not_closed: true) - output = @html.checkbox("test", "test-value", nil) - output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "test-value"}, "", not_closed: true) - end + output = @html.checkbox("test", "test-value", nil) + output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "test-value"}, "", not_closed: true) + end - it "ignores a passed block" do - output = @html.checkbox("test", "test-value", nil) { "test" } - output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "test-value"}, "", not_closed: true) + it "ignores a passed block" do + output = @html.checkbox("test", "test-value", nil) { "test" } + output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "test-value"}, "", not_closed: true) + end end - end - describe "when passed Hash" do - it "returns a checkbox-'input'-element using the passed Hash for attributes" do - attributes = {"NAME" => "test", "VALUE" => "test-value", "CHECKED" => true} - output = @html.checkbox(attributes) - output.should equal_element("INPUT", attributes, "", not_closed: true) - end + describe "when passed Hash" do + it "returns a checkbox-'input'-element using the passed Hash for attributes" do + attributes = {"NAME" => "test", "VALUE" => "test-value", "CHECKED" => true} + output = @html.checkbox(attributes) + output.should equal_element("INPUT", attributes, "", not_closed: true) + end - it "ignores a passed block" do - attributes = {"NAME" => "test", "VALUE" => "test-value", "CHECKED" => true} - output = @html.checkbox(attributes) { "test" } - output.should equal_element("INPUT", attributes, "", not_closed: true) + it "ignores a passed block" do + attributes = {"NAME" => "test", "VALUE" => "test-value", "CHECKED" => true} + output = @html.checkbox(attributes) { "test" } + output.should equal_element("INPUT", attributes, "", not_closed: true) + end end end end diff --git a/spec/ruby/library/cgi/htmlextension/doctype_spec.rb b/spec/ruby/library/cgi/htmlextension/doctype_spec.rb index 9a28a8883b..02af831855 100644 --- a/spec/ruby/library/cgi/htmlextension/doctype_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/doctype_spec.rb @@ -1,27 +1,30 @@ require_relative '../../../spec_helper' -require 'cgi' -require_relative 'fixtures/common' -describe "CGI::HtmlExtension#doctype" do - describe "when each HTML generation" do - it "returns the doctype declaration for HTML3" do - expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">' - CGISpecs.cgi_new("html3").doctype.should == expect - end +ruby_version_is ""..."4.0" do + require 'cgi' + require_relative 'fixtures/common' - it "returns the doctype declaration for HTML4" do - expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">' - CGISpecs.cgi_new("html4").doctype.should == expect - end + describe "CGI::HtmlExtension#doctype" do + describe "when each HTML generation" do + it "returns the doctype declaration for HTML3" do + expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">' + CGISpecs.cgi_new("html3").doctype.should == expect + end - it "returns the doctype declaration for the Frameset version of HTML4" do - expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">' - CGISpecs.cgi_new("html4Fr").doctype.should == expect - end + it "returns the doctype declaration for HTML4" do + expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">' + CGISpecs.cgi_new("html4").doctype.should == expect + end + + it "returns the doctype declaration for the Frameset version of HTML4" do + expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">' + CGISpecs.cgi_new("html4Fr").doctype.should == expect + end - it "returns the doctype declaration for the Transitional version of HTML4" do - expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">' - CGISpecs.cgi_new("html4Tr").doctype.should == expect + it "returns the doctype declaration for the Transitional version of HTML4" do + expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">' + CGISpecs.cgi_new("html4Tr").doctype.should == expect + end end end end diff --git a/spec/ruby/library/cgi/htmlextension/file_field_spec.rb b/spec/ruby/library/cgi/htmlextension/file_field_spec.rb index 2a0632fd58..eff077b9a2 100644 --- a/spec/ruby/library/cgi/htmlextension/file_field_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/file_field_spec.rb @@ -1,72 +1,75 @@ require_relative '../../../spec_helper' -require 'cgi' -require_relative 'fixtures/common' -describe "CGI::HtmlExtension#file_field" do - before :each do - @html = CGISpecs.cgi_new - end +ruby_version_is ""..."4.0" do + require 'cgi' + require_relative 'fixtures/common' - describe "when passed no arguments" do - it "returns a file-'input'-element without a name and a size of 20" do - output = @html.file_field - output.should equal_element("INPUT", {"SIZE" => 20, "NAME" => "", "TYPE" => "file"}, "", not_closed: true) + describe "CGI::HtmlExtension#file_field" do + before :each do + @html = CGISpecs.cgi_new end - it "ignores a passed block" do - output = @html.file_field { "test" } - output.should equal_element("INPUT", {"SIZE" => 20, "NAME" => "", "TYPE" => "file"}, "", not_closed: true) - end - end + describe "when passed no arguments" do + it "returns a file-'input'-element without a name and a size of 20" do + output = @html.file_field + output.should equal_element("INPUT", {"SIZE" => 20, "NAME" => "", "TYPE" => "file"}, "", not_closed: true) + end - describe "when passed name" do - it "returns a checkbox-'input'-element with the passed name" do - output = @html.file_field("Example") - output.should equal_element("INPUT", {"SIZE" => 20, "NAME" => "Example", "TYPE" => "file"}, "", not_closed: true) + it "ignores a passed block" do + output = @html.file_field { "test" } + output.should equal_element("INPUT", {"SIZE" => 20, "NAME" => "", "TYPE" => "file"}, "", not_closed: true) + end end - it "ignores a passed block" do - output = @html.file_field("Example") { "test" } - output.should equal_element("INPUT", {"SIZE" => 20, "NAME" => "Example", "TYPE" => "file"}, "", not_closed: true) - end - end + describe "when passed name" do + it "returns a checkbox-'input'-element with the passed name" do + output = @html.file_field("Example") + output.should equal_element("INPUT", {"SIZE" => 20, "NAME" => "Example", "TYPE" => "file"}, "", not_closed: true) + end - describe "when passed name, size" do - it "returns a checkbox-'input'-element with the passed name and size" do - output = @html.file_field("Example", 40) - output.should equal_element("INPUT", {"SIZE" => 40, "NAME" => "Example", "TYPE" => "file"}, "", not_closed: true) + it "ignores a passed block" do + output = @html.file_field("Example") { "test" } + output.should equal_element("INPUT", {"SIZE" => 20, "NAME" => "Example", "TYPE" => "file"}, "", not_closed: true) + end end - it "ignores a passed block" do - output = @html.file_field("Example", 40) { "test" } - output.should equal_element("INPUT", {"SIZE" => 40, "NAME" => "Example", "TYPE" => "file"}, "", not_closed: true) - end - end + describe "when passed name, size" do + it "returns a checkbox-'input'-element with the passed name and size" do + output = @html.file_field("Example", 40) + output.should equal_element("INPUT", {"SIZE" => 40, "NAME" => "Example", "TYPE" => "file"}, "", not_closed: true) + end - describe "when passed name, size, maxlength" do - it "returns a checkbox-'input'-element with the passed name, size and maxlength" do - output = @html.file_field("Example", 40, 100) - output.should equal_element("INPUT", {"SIZE" => 40, "NAME" => "Example", "TYPE" => "file", "MAXLENGTH" => 100}, "", not_closed: true) + it "ignores a passed block" do + output = @html.file_field("Example", 40) { "test" } + output.should equal_element("INPUT", {"SIZE" => 40, "NAME" => "Example", "TYPE" => "file"}, "", not_closed: true) + end end - it "ignores a passed block" do - output = @html.file_field("Example", 40, 100) { "test" } - output.should equal_element("INPUT", {"SIZE" => 40, "NAME" => "Example", "TYPE" => "file", "MAXLENGTH" => 100}, "", not_closed: true) + describe "when passed name, size, maxlength" do + it "returns a checkbox-'input'-element with the passed name, size and maxlength" do + output = @html.file_field("Example", 40, 100) + output.should equal_element("INPUT", {"SIZE" => 40, "NAME" => "Example", "TYPE" => "file", "MAXLENGTH" => 100}, "", not_closed: true) + end + + it "ignores a passed block" do + output = @html.file_field("Example", 40, 100) { "test" } + output.should equal_element("INPUT", {"SIZE" => 40, "NAME" => "Example", "TYPE" => "file", "MAXLENGTH" => 100}, "", not_closed: true) + end end - end - describe "when passed a Hash" do - it "returns a file-'input'-element using the passed Hash for attributes" do - output = @html.file_field("NAME" => "test", "SIZE" => 40) - output.should equal_element("INPUT", {"NAME" => "test", "SIZE" => 40}, "", not_closed: true) + describe "when passed a Hash" do + it "returns a file-'input'-element using the passed Hash for attributes" do + output = @html.file_field("NAME" => "test", "SIZE" => 40) + output.should equal_element("INPUT", {"NAME" => "test", "SIZE" => 40}, "", not_closed: true) - output = @html.file_field("NAME" => "test", "MAXLENGTH" => 100) - output.should equal_element("INPUT", {"NAME" => "test", "MAXLENGTH" => 100}, "", not_closed: true) - end + output = @html.file_field("NAME" => "test", "MAXLENGTH" => 100) + output.should equal_element("INPUT", {"NAME" => "test", "MAXLENGTH" => 100}, "", not_closed: true) + end - it "ignores a passed block" do - output = @html.file_field("NAME" => "test", "SIZE" => 40) { "test" } - output.should equal_element("INPUT", {"NAME" => "test", "SIZE" => 40}, "", not_closed: true) + it "ignores a passed block" do + output = @html.file_field("NAME" => "test", "SIZE" => 40) { "test" } + output.should equal_element("INPUT", {"NAME" => "test", "SIZE" => 40}, "", not_closed: true) + end end end end diff --git a/spec/ruby/library/cgi/htmlextension/form_spec.rb b/spec/ruby/library/cgi/htmlextension/form_spec.rb index 8c0ac97735..55ac63152b 100644 --- a/spec/ruby/library/cgi/htmlextension/form_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/form_spec.rb @@ -1,58 +1,61 @@ require_relative '../../../spec_helper' -require 'cgi' -require_relative 'fixtures/common' -describe "CGI::HtmlExtension#form" do - before :each do - @html = CGISpecs.cgi_new - @html.stub!(:script_name).and_return("/path/to/some/script") - end +ruby_version_is ""..."4.0" do + require 'cgi' + require_relative 'fixtures/common' - describe "when passed no arguments" do - it "returns a 'form'-element" do - output = @html.form - output.should equal_element("FORM", {"ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "post", "ACTION" => "/path/to/some/script"}, "") + describe "CGI::HtmlExtension#form" do + before :each do + @html = CGISpecs.cgi_new + @html.stub!(:script_name).and_return("/path/to/some/script") end - it "includes the return value of the passed block when passed a block" do - output = @html.form { "test" } - output.should equal_element("FORM", {"ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "post", "ACTION" => "/path/to/some/script"}, "test") - end - end + describe "when passed no arguments" do + it "returns a 'form'-element" do + output = @html.form + output.should equal_element("FORM", {"ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "post", "ACTION" => "/path/to/some/script"}, "") + end - describe "when passed method" do - it "returns a 'form'-element with the passed method" do - output = @html.form("get") - output.should equal_element("FORM", {"ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get", "ACTION" => "/path/to/some/script"}, "") + it "includes the return value of the passed block when passed a block" do + output = @html.form { "test" } + output.should equal_element("FORM", {"ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "post", "ACTION" => "/path/to/some/script"}, "test") + end end - it "includes the return value of the passed block when passed a block" do - output = @html.form("get") { "test" } - output.should equal_element("FORM", {"ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get", "ACTION" => "/path/to/some/script"}, "test") - end - end + describe "when passed method" do + it "returns a 'form'-element with the passed method" do + output = @html.form("get") + output.should equal_element("FORM", {"ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get", "ACTION" => "/path/to/some/script"}, "") + end - describe "when passed method, action" do - it "returns a 'form'-element with the passed method and the passed action" do - output = @html.form("get", "/some/other/script") - output.should equal_element("FORM", {"ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get", "ACTION" => "/some/other/script"}, "") + it "includes the return value of the passed block when passed a block" do + output = @html.form("get") { "test" } + output.should equal_element("FORM", {"ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get", "ACTION" => "/path/to/some/script"}, "test") + end end - it "includes the return value of the passed block when passed a block" do - output = @html.form("get", "/some/other/script") { "test" } - output.should equal_element("FORM", {"ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get", "ACTION" => "/some/other/script"}, "test") - end - end + describe "when passed method, action" do + it "returns a 'form'-element with the passed method and the passed action" do + output = @html.form("get", "/some/other/script") + output.should equal_element("FORM", {"ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get", "ACTION" => "/some/other/script"}, "") + end - describe "when passed method, action, enctype" do - it "returns a 'form'-element with the passed method, action and enctype" do - output = @html.form("get", "/some/other/script", "multipart/form-data") - output.should equal_element("FORM", {"ENCTYPE" => "multipart/form-data", "METHOD" => "get", "ACTION" => "/some/other/script"}, "") + it "includes the return value of the passed block when passed a block" do + output = @html.form("get", "/some/other/script") { "test" } + output.should equal_element("FORM", {"ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get", "ACTION" => "/some/other/script"}, "test") + end end - it "includes the return value of the passed block when passed a block" do - output = @html.form("get", "/some/other/script", "multipart/form-data") { "test" } - output.should equal_element("FORM", {"ENCTYPE" => "multipart/form-data", "METHOD" => "get", "ACTION" => "/some/other/script"}, "test") + describe "when passed method, action, enctype" do + it "returns a 'form'-element with the passed method, action and enctype" do + output = @html.form("get", "/some/other/script", "multipart/form-data") + output.should equal_element("FORM", {"ENCTYPE" => "multipart/form-data", "METHOD" => "get", "ACTION" => "/some/other/script"}, "") + end + + it "includes the return value of the passed block when passed a block" do + output = @html.form("get", "/some/other/script", "multipart/form-data") { "test" } + output.should equal_element("FORM", {"ENCTYPE" => "multipart/form-data", "METHOD" => "get", "ACTION" => "/some/other/script"}, "test") + end end end end diff --git a/spec/ruby/library/cgi/htmlextension/frame_spec.rb b/spec/ruby/library/cgi/htmlextension/frame_spec.rb index 2ddd4e1ef0..fef40849eb 100644 --- a/spec/ruby/library/cgi/htmlextension/frame_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/frame_spec.rb @@ -1,14 +1,17 @@ require_relative '../../../spec_helper' -require_relative 'fixtures/common' -require 'cgi' -describe "CGI::HtmlExtension#frame" do - before :each do - @html = CGISpecs.cgi_new("html4Fr") - end +ruby_version_is ""..."4.0" do + require_relative 'fixtures/common' + require 'cgi' + + describe "CGI::HtmlExtension#frame" do + before :each do + @html = CGISpecs.cgi_new("html4Fr") + end - it "initializes the HTML Generation methods for the Frameset version of HTML4" do - @html.frameset.should == "<FRAMESET></FRAMESET>" - @html.frameset { "link text" }.should == "<FRAMESET>link text</FRAMESET>" + it "initializes the HTML Generation methods for the Frameset version of HTML4" do + @html.frameset.should == "<FRAMESET></FRAMESET>" + @html.frameset { "link text" }.should == "<FRAMESET>link text</FRAMESET>" + end end end diff --git a/spec/ruby/library/cgi/htmlextension/frameset_spec.rb b/spec/ruby/library/cgi/htmlextension/frameset_spec.rb index baeb446593..3ad0a9c4d2 100644 --- a/spec/ruby/library/cgi/htmlextension/frameset_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/frameset_spec.rb @@ -1,14 +1,17 @@ require_relative '../../../spec_helper' -require_relative 'fixtures/common' -require 'cgi' -describe "CGI::HtmlExtension#frameset" do - before :each do - @html = CGISpecs.cgi_new("html4Fr") - end +ruby_version_is ""..."4.0" do + require_relative 'fixtures/common' + require 'cgi' + + describe "CGI::HtmlExtension#frameset" do + before :each do + @html = CGISpecs.cgi_new("html4Fr") + end - it "initializes the HTML Generation methods for the Frameset version of HTML4" do - @html.frameset.should == "<FRAMESET></FRAMESET>" - @html.frameset { "link text" }.should == "<FRAMESET>link text</FRAMESET>" + it "initializes the HTML Generation methods for the Frameset version of HTML4" do + @html.frameset.should == "<FRAMESET></FRAMESET>" + @html.frameset { "link text" }.should == "<FRAMESET>link text</FRAMESET>" + end end end diff --git a/spec/ruby/library/cgi/htmlextension/hidden_spec.rb b/spec/ruby/library/cgi/htmlextension/hidden_spec.rb index 52ebd8c261..b2323775f6 100644 --- a/spec/ruby/library/cgi/htmlextension/hidden_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/hidden_spec.rb @@ -1,59 +1,62 @@ require_relative '../../../spec_helper' -require 'cgi' -require_relative 'fixtures/common' -describe "CGI::HtmlExtension#hidden" do - before :each do - @html = CGISpecs.cgi_new - end +ruby_version_is ""..."4.0" do + require 'cgi' + require_relative 'fixtures/common' - describe "when passed no arguments" do - it "returns an hidden-'input'-element without a name" do - output = @html.hidden - output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "hidden"}, "", not_closed: true) + describe "CGI::HtmlExtension#hidden" do + before :each do + @html = CGISpecs.cgi_new end - it "ignores a passed block" do - output = @html.hidden { "test" } - output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "hidden"}, "", not_closed: true) - end - end + describe "when passed no arguments" do + it "returns an hidden-'input'-element without a name" do + output = @html.hidden + output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "hidden"}, "", not_closed: true) + end - describe "when passed name" do - it "returns an hidden-'input'-element with the passed name" do - output = @html.hidden("test") - output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "hidden"}, "", not_closed: true) + it "ignores a passed block" do + output = @html.hidden { "test" } + output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "hidden"}, "", not_closed: true) + end end - it "ignores a passed block" do - output = @html.hidden("test") { "test" } - output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "hidden"}, "", not_closed: true) - end - end + describe "when passed name" do + it "returns an hidden-'input'-element with the passed name" do + output = @html.hidden("test") + output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "hidden"}, "", not_closed: true) + end - describe "when passed name, value" do - it "returns an hidden-'input'-element with the passed name and value" do - output = @html.hidden("test", "some value") - output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "hidden", "VALUE" => "some value"}, "", not_closed: true) + it "ignores a passed block" do + output = @html.hidden("test") { "test" } + output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "hidden"}, "", not_closed: true) + end end - it "ignores a passed block" do - output = @html.hidden("test", "some value") { "test" } - output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "hidden", "VALUE" => "some value"}, "", not_closed: true) - end - end + describe "when passed name, value" do + it "returns an hidden-'input'-element with the passed name and value" do + output = @html.hidden("test", "some value") + output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "hidden", "VALUE" => "some value"}, "", not_closed: true) + end - describe "when passed Hash" do - it "returns a checkbox-'input'-element using the passed Hash for attributes" do - attributes = { "NAME" => "test", "VALUE" => "some value" } - output = @html.hidden("test", "some value") - output.should equal_element("INPUT", attributes, "", not_closed: true) + it "ignores a passed block" do + output = @html.hidden("test", "some value") { "test" } + output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "hidden", "VALUE" => "some value"}, "", not_closed: true) + end end - it "ignores a passed block" do - attributes = { "NAME" => "test", "VALUE" => "some value" } - output = @html.hidden("test", "some value") { "test" } - output.should equal_element("INPUT", attributes, "", not_closed: true) + describe "when passed Hash" do + it "returns a checkbox-'input'-element using the passed Hash for attributes" do + attributes = { "NAME" => "test", "VALUE" => "some value" } + output = @html.hidden("test", "some value") + output.should equal_element("INPUT", attributes, "", not_closed: true) + end + + it "ignores a passed block" do + attributes = { "NAME" => "test", "VALUE" => "some value" } + output = @html.hidden("test", "some value") { "test" } + output.should equal_element("INPUT", attributes, "", not_closed: true) + end end end end diff --git a/spec/ruby/library/cgi/htmlextension/html_spec.rb b/spec/ruby/library/cgi/htmlextension/html_spec.rb index 5d89c82086..60a10fb6b4 100644 --- a/spec/ruby/library/cgi/htmlextension/html_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/html_spec.rb @@ -1,66 +1,69 @@ require_relative '../../../spec_helper' -require 'cgi' -require_relative 'fixtures/common' -describe "CGI::HtmlExtension#html" do - before :each do - @html = CGISpecs.cgi_new - @html.stub!(:doctype).and_return("<!DOCTYPE SUPA-FUNKAY-RUBYSPEC-DOCTYPE>") - end +ruby_version_is ""..."4.0" do + require 'cgi' + require_relative 'fixtures/common' - describe "when passed no arguments" do - it "returns a self's doctype and an 'html'-element" do - expected = '<!DOCTYPE SUPA-FUNKAY-RUBYSPEC-DOCTYPE><HTML>' - @html.html.should == expected + describe "CGI::HtmlExtension#html" do + before :each do + @html = CGISpecs.cgi_new + @html.stub!(:doctype).and_return("<!DOCTYPE SUPA-FUNKAY-RUBYSPEC-DOCTYPE>") end - it "includes the passed block when passed a block" do - expected = '<!DOCTYPE SUPA-FUNKAY-RUBYSPEC-DOCTYPE><HTML>test</HTML>' - @html.html { "test" }.should == expected - end - end + describe "when passed no arguments" do + it "returns a self's doctype and an 'html'-element" do + expected = '<!DOCTYPE SUPA-FUNKAY-RUBYSPEC-DOCTYPE><HTML>' + @html.html.should == expected + end - describe "when passed 'PRETTY'" do - it "returns pretty output when the passed String is 'PRETTY" do - expected = "<!DOCTYPE SUPA-FUNKAY-RUBYSPEC-DOCTYPE>\n<HTML>\n" - @html.html("PRETTY").should == expected + it "includes the passed block when passed a block" do + expected = '<!DOCTYPE SUPA-FUNKAY-RUBYSPEC-DOCTYPE><HTML>test</HTML>' + @html.html { "test" }.should == expected + end end - it "includes the passed block when passed a block" do - expected = "<!DOCTYPE SUPA-FUNKAY-RUBYSPEC-DOCTYPE>\n<HTML>\n test\n</HTML>\n" - @html.html("PRETTY") { "test" }.should == expected - end - end + describe "when passed 'PRETTY'" do + it "returns pretty output when the passed String is 'PRETTY" do + expected = "<!DOCTYPE SUPA-FUNKAY-RUBYSPEC-DOCTYPE>\n<HTML>\n" + @html.html("PRETTY").should == expected + end - describe "when passed a Hash" do - it "returns an 'html'-element using the passed Hash for attributes" do - expected = '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"><HTML BLA="TEST">' - @html.html("DOCTYPE" => '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">', "BLA" => "TEST").should == expected + it "includes the passed block when passed a block" do + expected = "<!DOCTYPE SUPA-FUNKAY-RUBYSPEC-DOCTYPE>\n<HTML>\n test\n</HTML>\n" + @html.html("PRETTY") { "test" }.should == expected + end end - it "omits the doctype when the Hash contains a 'DOCTYPE' entry that's false or nil" do - @html.html("DOCTYPE" => false).should == "<HTML>" - @html.html("DOCTYPE" => nil).should == "<HTML>" - end - end + describe "when passed a Hash" do + it "returns an 'html'-element using the passed Hash for attributes" do + expected = '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"><HTML BLA="TEST">' + @html.html("DOCTYPE" => '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">', "BLA" => "TEST").should == expected + end - describe "when each HTML generation" do - it "returns the doctype declaration for HTML3" do - expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">' - CGISpecs.cgi_new("html3").html.should == expect + "<HTML>" - CGISpecs.cgi_new("html3").html { "html body" }.should == expect + "<HTML>html body</HTML>" + it "omits the doctype when the Hash contains a 'DOCTYPE' entry that's false or nil" do + @html.html("DOCTYPE" => false).should == "<HTML>" + @html.html("DOCTYPE" => nil).should == "<HTML>" + end end - it "returns the doctype declaration for HTML4" do - expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">' - CGISpecs.cgi_new("html4").html.should == expect + "<HTML>" - CGISpecs.cgi_new("html4").html { "html body" }.should == expect + "<HTML>html body</HTML>" - end + describe "when each HTML generation" do + it "returns the doctype declaration for HTML3" do + expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">' + CGISpecs.cgi_new("html3").html.should == expect + "<HTML>" + CGISpecs.cgi_new("html3").html { "html body" }.should == expect + "<HTML>html body</HTML>" + end + + it "returns the doctype declaration for HTML4" do + expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">' + CGISpecs.cgi_new("html4").html.should == expect + "<HTML>" + CGISpecs.cgi_new("html4").html { "html body" }.should == expect + "<HTML>html body</HTML>" + end - it "returns the doctype declaration for the Transitional version of HTML4" do - expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">' - CGISpecs.cgi_new("html4Tr").html.should == expect + "<HTML>" - CGISpecs.cgi_new("html4Tr").html { "html body" }.should == expect + "<HTML>html body</HTML>" + it "returns the doctype declaration for the Transitional version of HTML4" do + expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">' + CGISpecs.cgi_new("html4Tr").html.should == expect + "<HTML>" + CGISpecs.cgi_new("html4Tr").html { "html body" }.should == expect + "<HTML>html body</HTML>" + end end end end diff --git a/spec/ruby/library/cgi/htmlextension/image_button_spec.rb b/spec/ruby/library/cgi/htmlextension/image_button_spec.rb index d14bec9ca3..f8770119d4 100644 --- a/spec/ruby/library/cgi/htmlextension/image_button_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/image_button_spec.rb @@ -1,69 +1,72 @@ require_relative '../../../spec_helper' -require 'cgi' -require_relative 'fixtures/common' -describe "CGI::HtmlExtension#image_button" do - before :each do - @html = CGISpecs.cgi_new - end +ruby_version_is ""..."4.0" do + require 'cgi' + require_relative 'fixtures/common' - describe "when passed no arguments" do - it "returns an image-'input'-element without a source image" do - output = @html.image_button - output.should equal_element("INPUT", {"SRC" => "", "TYPE" => "image"}, "", not_closed: true) + describe "CGI::HtmlExtension#image_button" do + before :each do + @html = CGISpecs.cgi_new end - it "ignores a passed block" do - output = @html.image_button { "test" } - output.should equal_element("INPUT", {"SRC" => "", "TYPE" => "image"}, "", not_closed: true) - end - end + describe "when passed no arguments" do + it "returns an image-'input'-element without a source image" do + output = @html.image_button + output.should equal_element("INPUT", {"SRC" => "", "TYPE" => "image"}, "", not_closed: true) + end - describe "when passed src" do - it "returns an image-'input'-element with the passed src" do - output = @html.image_button("/path/to/image.png") - output.should equal_element("INPUT", {"SRC" => "/path/to/image.png", "TYPE" => "image"}, "", not_closed: true) + it "ignores a passed block" do + output = @html.image_button { "test" } + output.should equal_element("INPUT", {"SRC" => "", "TYPE" => "image"}, "", not_closed: true) + end end - it "ignores a passed block" do - output = @html.image_button("/path/to/image.png") { "test" } - output.should equal_element("INPUT", {"SRC" => "/path/to/image.png", "TYPE" => "image"}, "", not_closed: true) - end - end + describe "when passed src" do + it "returns an image-'input'-element with the passed src" do + output = @html.image_button("/path/to/image.png") + output.should equal_element("INPUT", {"SRC" => "/path/to/image.png", "TYPE" => "image"}, "", not_closed: true) + end - describe "when passed src, name" do - it "returns an image-'input'-element with the passed src and name" do - output = @html.image_button("/path/to/image.png", "test") - output.should equal_element("INPUT", {"SRC" => "/path/to/image.png", "TYPE" => "image", "NAME" => "test"}, "", not_closed: true) + it "ignores a passed block" do + output = @html.image_button("/path/to/image.png") { "test" } + output.should equal_element("INPUT", {"SRC" => "/path/to/image.png", "TYPE" => "image"}, "", not_closed: true) + end end - it "ignores a passed block" do - output = @html.image_button("/path/to/image.png", "test") { "test" } - output.should equal_element("INPUT", {"SRC" => "/path/to/image.png", "TYPE" => "image", "NAME" => "test"}, "", not_closed: true) - end - end + describe "when passed src, name" do + it "returns an image-'input'-element with the passed src and name" do + output = @html.image_button("/path/to/image.png", "test") + output.should equal_element("INPUT", {"SRC" => "/path/to/image.png", "TYPE" => "image", "NAME" => "test"}, "", not_closed: true) + end - describe "when passed src, name, alt" do - it "returns an image-'input'-element with the passed src, name and alt" do - output = @html.image_button("/path/to/image.png", "test", "alternative") - output.should equal_element("INPUT", {"SRC" => "/path/to/image.png", "TYPE" => "image", "NAME" => "test", "ALT" => "alternative"}, "", not_closed: true) + it "ignores a passed block" do + output = @html.image_button("/path/to/image.png", "test") { "test" } + output.should equal_element("INPUT", {"SRC" => "/path/to/image.png", "TYPE" => "image", "NAME" => "test"}, "", not_closed: true) + end end - it "ignores a passed block" do - output = @html.image_button("/path/to/image.png", "test", "alternative") { "test" } - output.should equal_element("INPUT", {"SRC" => "/path/to/image.png", "TYPE" => "image", "NAME" => "test", "ALT" => "alternative"}, "", not_closed: true) - end - end + describe "when passed src, name, alt" do + it "returns an image-'input'-element with the passed src, name and alt" do + output = @html.image_button("/path/to/image.png", "test", "alternative") + output.should equal_element("INPUT", {"SRC" => "/path/to/image.png", "TYPE" => "image", "NAME" => "test", "ALT" => "alternative"}, "", not_closed: true) + end - describe "when passed Hash" do - it "returns a image-'input'-element using the passed Hash for attributes" do - output = @html.image_button("NAME" => "test", "VALUE" => "test-value") - output.should equal_element("INPUT", {"SRC" => "", "TYPE" => "image", "NAME" => "test", "VALUE" => "test-value"}, "", not_closed: true) + it "ignores a passed block" do + output = @html.image_button("/path/to/image.png", "test", "alternative") { "test" } + output.should equal_element("INPUT", {"SRC" => "/path/to/image.png", "TYPE" => "image", "NAME" => "test", "ALT" => "alternative"}, "", not_closed: true) + end end - it "ignores a passed block" do - output = @html.image_button("NAME" => "test", "VALUE" => "test-value") { "test" } - output.should equal_element("INPUT", {"SRC" => "", "TYPE" => "image", "NAME" => "test", "VALUE" => "test-value"}, "", not_closed: true) + describe "when passed Hash" do + it "returns a image-'input'-element using the passed Hash for attributes" do + output = @html.image_button("NAME" => "test", "VALUE" => "test-value") + output.should equal_element("INPUT", {"SRC" => "", "TYPE" => "image", "NAME" => "test", "VALUE" => "test-value"}, "", not_closed: true) + end + + it "ignores a passed block" do + output = @html.image_button("NAME" => "test", "VALUE" => "test-value") { "test" } + output.should equal_element("INPUT", {"SRC" => "", "TYPE" => "image", "NAME" => "test", "VALUE" => "test-value"}, "", not_closed: true) + end end end end diff --git a/spec/ruby/library/cgi/htmlextension/img_spec.rb b/spec/ruby/library/cgi/htmlextension/img_spec.rb index 994ae7fedf..a05cfdea48 100644 --- a/spec/ruby/library/cgi/htmlextension/img_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/img_spec.rb @@ -1,83 +1,86 @@ require_relative '../../../spec_helper' -require 'cgi' -require_relative 'fixtures/common' -describe "CGI::HtmlExtension#img" do - before :each do - @html = CGISpecs.cgi_new - end +ruby_version_is ""..."4.0" do + require 'cgi' + require_relative 'fixtures/common' - describe "when passed no arguments" do - it "returns an 'img'-element without an src-url or alt-text" do - output = @html.img - output.should equal_element("IMG", { "SRC" => "", "ALT" => "" }, "", not_closed: true) + describe "CGI::HtmlExtension#img" do + before :each do + @html = CGISpecs.cgi_new end - it "ignores a passed block" do - output = @html.img { "test" } - output.should equal_element("IMG", { "SRC" => "", "ALT" => "" }, "", not_closed: true) - end - end + describe "when passed no arguments" do + it "returns an 'img'-element without an src-url or alt-text" do + output = @html.img + output.should equal_element("IMG", { "SRC" => "", "ALT" => "" }, "", not_closed: true) + end - describe "when passed src" do - it "returns an 'img'-element with the passed src-url" do - output = @html.img("/path/to/some/image.png") - output.should equal_element("IMG", { "SRC" => "/path/to/some/image.png", "ALT" => "" }, "", not_closed: true) + it "ignores a passed block" do + output = @html.img { "test" } + output.should equal_element("IMG", { "SRC" => "", "ALT" => "" }, "", not_closed: true) + end end - it "ignores a passed block" do - output = @html.img("/path/to/some/image.png") - output.should equal_element("IMG", { "SRC" => "/path/to/some/image.png", "ALT" => "" }, "", not_closed: true) - end - end + describe "when passed src" do + it "returns an 'img'-element with the passed src-url" do + output = @html.img("/path/to/some/image.png") + output.should equal_element("IMG", { "SRC" => "/path/to/some/image.png", "ALT" => "" }, "", not_closed: true) + end - describe "when passed src, alt" do - it "returns an 'img'-element with the passed src-url and the passed alt-text" do - output = @html.img("/path/to/some/image.png", "Alternative") - output.should equal_element("IMG", { "SRC" => "/path/to/some/image.png", "ALT" => "Alternative" }, "", not_closed: true) + it "ignores a passed block" do + output = @html.img("/path/to/some/image.png") + output.should equal_element("IMG", { "SRC" => "/path/to/some/image.png", "ALT" => "" }, "", not_closed: true) + end end - it "ignores a passed block" do - output = @html.img("/path/to/some/image.png", "Alternative") { "test" } - output.should equal_element("IMG", { "SRC" => "/path/to/some/image.png", "ALT" => "Alternative" }, "", not_closed: true) - end - end + describe "when passed src, alt" do + it "returns an 'img'-element with the passed src-url and the passed alt-text" do + output = @html.img("/path/to/some/image.png", "Alternative") + output.should equal_element("IMG", { "SRC" => "/path/to/some/image.png", "ALT" => "Alternative" }, "", not_closed: true) + end - describe "when passed src, alt, width" do - it "returns an 'img'-element with the passed src-url, the passed alt-text and the passed width" do - output = @html.img("/path/to/some/image.png", "Alternative", 40) - output.should equal_element("IMG", { "SRC" => "/path/to/some/image.png", "ALT" => "Alternative", "WIDTH" => "40" }, "", not_closed: true) + it "ignores a passed block" do + output = @html.img("/path/to/some/image.png", "Alternative") { "test" } + output.should equal_element("IMG", { "SRC" => "/path/to/some/image.png", "ALT" => "Alternative" }, "", not_closed: true) + end end - it "ignores a passed block" do - output = @html.img("/path/to/some/image.png", "Alternative", 40) { "test" } - output.should equal_element("IMG", { "SRC" => "/path/to/some/image.png", "ALT" => "Alternative", "WIDTH" => "40" }, "", not_closed: true) - end - end + describe "when passed src, alt, width" do + it "returns an 'img'-element with the passed src-url, the passed alt-text and the passed width" do + output = @html.img("/path/to/some/image.png", "Alternative", 40) + output.should equal_element("IMG", { "SRC" => "/path/to/some/image.png", "ALT" => "Alternative", "WIDTH" => "40" }, "", not_closed: true) + end - describe "when passed src, alt, width, height" do - it "returns an 'img'-element with the passed src-url, the passed alt-text, the passed width and the passed height" do - output = @html.img("/path/to/some/image.png", "Alternative", 40, 60) - output.should equal_element("IMG", { "SRC" => "/path/to/some/image.png", "ALT" => "Alternative", "WIDTH" => "40", "HEIGHT" => "60" }, "", not_closed: true) + it "ignores a passed block" do + output = @html.img("/path/to/some/image.png", "Alternative", 40) { "test" } + output.should equal_element("IMG", { "SRC" => "/path/to/some/image.png", "ALT" => "Alternative", "WIDTH" => "40" }, "", not_closed: true) + end end - it "ignores a passed block" do - output = @html.img { "test" } - output.should equal_element("IMG", { "SRC" => "", "ALT" => "" }, "", not_closed: true) - end - end + describe "when passed src, alt, width, height" do + it "returns an 'img'-element with the passed src-url, the passed alt-text, the passed width and the passed height" do + output = @html.img("/path/to/some/image.png", "Alternative", 40, 60) + output.should equal_element("IMG", { "SRC" => "/path/to/some/image.png", "ALT" => "Alternative", "WIDTH" => "40", "HEIGHT" => "60" }, "", not_closed: true) + end - describe "when passed Hash" do - it "returns an 'img'-element with the passed Hash as attributes" do - attributes = { "SRC" => "src", "ALT" => "alt", "WIDTH" => 100, "HEIGHT" => 50 } - output = @html.img(attributes) - output.should equal_element("IMG", attributes, "", not_closed: true) + it "ignores a passed block" do + output = @html.img { "test" } + output.should equal_element("IMG", { "SRC" => "", "ALT" => "" }, "", not_closed: true) + end end - it "ignores a passed block" do - attributes = { "SRC" => "src", "ALT" => "alt", "WIDTH" => 100, "HEIGHT" => 50 } - output = @html.img(attributes) { "test" } - output.should equal_element("IMG", attributes, "", not_closed: true) + describe "when passed Hash" do + it "returns an 'img'-element with the passed Hash as attributes" do + attributes = { "SRC" => "src", "ALT" => "alt", "WIDTH" => 100, "HEIGHT" => 50 } + output = @html.img(attributes) + output.should equal_element("IMG", attributes, "", not_closed: true) + end + + it "ignores a passed block" do + attributes = { "SRC" => "src", "ALT" => "alt", "WIDTH" => 100, "HEIGHT" => 50 } + output = @html.img(attributes) { "test" } + output.should equal_element("IMG", attributes, "", not_closed: true) + end end end end diff --git a/spec/ruby/library/cgi/htmlextension/multipart_form_spec.rb b/spec/ruby/library/cgi/htmlextension/multipart_form_spec.rb index 0bf2042a33..ee1c45b84e 100644 --- a/spec/ruby/library/cgi/htmlextension/multipart_form_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/multipart_form_spec.rb @@ -1,64 +1,67 @@ require_relative '../../../spec_helper' -require 'cgi' -require_relative 'fixtures/common' -describe "CGI::HtmlExtension#multipart_form" do - before :each do - @html = CGISpecs.cgi_new - @html.stub!(:script_name).and_return("/path/to/some/script.rb") - end +ruby_version_is ""..."4.0" do + require 'cgi' + require_relative 'fixtures/common' - describe "when passed no arguments" do - it "returns a 'form'-element with it's enctype set to multipart" do - output = @html.multipart_form - output.should equal_element("FORM", { "ENCTYPE" => "multipart/form-data", "METHOD" => "post" }, "") + describe "CGI::HtmlExtension#multipart_form" do + before :each do + @html = CGISpecs.cgi_new + @html.stub!(:script_name).and_return("/path/to/some/script.rb") end - it "includes the return value of the passed block when passed a block" do - output = @html.multipart_form { "test" } - output.should equal_element("FORM", { "ENCTYPE" => "multipart/form-data", "METHOD" => "post" }, "test") - end - end + describe "when passed no arguments" do + it "returns a 'form'-element with it's enctype set to multipart" do + output = @html.multipart_form + output.should equal_element("FORM", { "ENCTYPE" => "multipart/form-data", "METHOD" => "post" }, "") + end - describe "when passed action" do - it "returns a 'form'-element with the passed action" do - output = @html.multipart_form("/some/other/script.rb") - output.should equal_element("FORM", { "ENCTYPE" => "multipart/form-data", "METHOD" => "post", "ACTION" => "/some/other/script.rb" }, "") + it "includes the return value of the passed block when passed a block" do + output = @html.multipart_form { "test" } + output.should equal_element("FORM", { "ENCTYPE" => "multipart/form-data", "METHOD" => "post" }, "test") + end end - it "includes the return value of the passed block when passed a block" do - output = @html.multipart_form("/some/other/script.rb") { "test" } - output.should equal_element("FORM", { "ENCTYPE" => "multipart/form-data", "METHOD" => "post", "ACTION" => "/some/other/script.rb" }, "test") - end - end + describe "when passed action" do + it "returns a 'form'-element with the passed action" do + output = @html.multipart_form("/some/other/script.rb") + output.should equal_element("FORM", { "ENCTYPE" => "multipart/form-data", "METHOD" => "post", "ACTION" => "/some/other/script.rb" }, "") + end - describe "when passed action, enctype" do - it "returns a 'form'-element with the passed action and enctype" do - output = @html.multipart_form("/some/other/script.rb", "application/x-www-form-urlencoded") - output.should equal_element("FORM", { "ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "post", "ACTION" => "/some/other/script.rb" }, "") + it "includes the return value of the passed block when passed a block" do + output = @html.multipart_form("/some/other/script.rb") { "test" } + output.should equal_element("FORM", { "ENCTYPE" => "multipart/form-data", "METHOD" => "post", "ACTION" => "/some/other/script.rb" }, "test") + end end - it "includes the return value of the passed block when passed a block" do - output = @html.multipart_form("/some/other/script.rb", "application/x-www-form-urlencoded") { "test" } - output.should equal_element("FORM", { "ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "post", "ACTION" => "/some/other/script.rb" }, "test") + describe "when passed action, enctype" do + it "returns a 'form'-element with the passed action and enctype" do + output = @html.multipart_form("/some/other/script.rb", "application/x-www-form-urlencoded") + output.should equal_element("FORM", { "ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "post", "ACTION" => "/some/other/script.rb" }, "") + end + + it "includes the return value of the passed block when passed a block" do + output = @html.multipart_form("/some/other/script.rb", "application/x-www-form-urlencoded") { "test" } + output.should equal_element("FORM", { "ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "post", "ACTION" => "/some/other/script.rb" }, "test") + end end - end - describe "when passed Hash" do - it "returns a 'form'-element with the passed Hash as attributes" do - output = @html.multipart_form("ID" => "test") - output.should equal_element("FORM", { "ENCTYPE" => "multipart/form-data", "METHOD" => "post", "ID" => "test" }, "") + describe "when passed Hash" do + it "returns a 'form'-element with the passed Hash as attributes" do + output = @html.multipart_form("ID" => "test") + output.should equal_element("FORM", { "ENCTYPE" => "multipart/form-data", "METHOD" => "post", "ID" => "test" }, "") - output = @html.multipart_form("ID" => "test", "ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get") - output.should equal_element("FORM", { "ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get", "ID" => "test" }, "") - end + output = @html.multipart_form("ID" => "test", "ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get") + output.should equal_element("FORM", { "ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get", "ID" => "test" }, "") + end - it "includes the return value of the passed block when passed a block" do - output = @html.multipart_form("ID" => "test") { "test" } - output.should equal_element("FORM", { "ENCTYPE" => "multipart/form-data", "METHOD" => "post", "ID" => "test" }, "test") + it "includes the return value of the passed block when passed a block" do + output = @html.multipart_form("ID" => "test") { "test" } + output.should equal_element("FORM", { "ENCTYPE" => "multipart/form-data", "METHOD" => "post", "ID" => "test" }, "test") - output = @html.multipart_form("ID" => "test", "ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get") { "test" } - output.should equal_element("FORM", { "ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get", "ID" => "test" }, "test") + output = @html.multipart_form("ID" => "test", "ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get") { "test" } + output.should equal_element("FORM", { "ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get", "ID" => "test" }, "test") + end end end end diff --git a/spec/ruby/library/cgi/htmlextension/password_field_spec.rb b/spec/ruby/library/cgi/htmlextension/password_field_spec.rb index 683bc428ba..0fefdd5c45 100644 --- a/spec/ruby/library/cgi/htmlextension/password_field_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/password_field_spec.rb @@ -1,84 +1,87 @@ require_relative '../../../spec_helper' -require 'cgi' -require_relative 'fixtures/common' -describe "CGI::HtmlExtension#password_field" do - before :each do - @html = CGISpecs.cgi_new - end +ruby_version_is ""..."4.0" do + require 'cgi' + require_relative 'fixtures/common' - describe "when passed no arguments" do - it "returns an password-'input'-element without a name" do - output = @html.password_field - output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "password", "SIZE" => "40"}, "", not_closed: true) + describe "CGI::HtmlExtension#password_field" do + before :each do + @html = CGISpecs.cgi_new end - it "ignores a passed block" do - output = @html.password_field { "test" } - output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "password", "SIZE" => "40"}, "", not_closed: true) - end - end + describe "when passed no arguments" do + it "returns an password-'input'-element without a name" do + output = @html.password_field + output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "password", "SIZE" => "40"}, "", not_closed: true) + end - describe "when passed name" do - it "returns an password-'input'-element with the passed name" do - output = @html.password_field("test") - output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "SIZE" => "40"}, "", not_closed: true) + it "ignores a passed block" do + output = @html.password_field { "test" } + output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "password", "SIZE" => "40"}, "", not_closed: true) + end end - it "ignores a passed block" do - output = @html.password_field("test") { "test" } - output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "SIZE" => "40"}, "", not_closed: true) - end - end + describe "when passed name" do + it "returns an password-'input'-element with the passed name" do + output = @html.password_field("test") + output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "SIZE" => "40"}, "", not_closed: true) + end - describe "when passed name, value" do - it "returns an password-'input'-element with the passed name and value" do - output = @html.password_field("test", "some value") - output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "VALUE" => "some value", "SIZE" => "40"}, "", not_closed: true) + it "ignores a passed block" do + output = @html.password_field("test") { "test" } + output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "SIZE" => "40"}, "", not_closed: true) + end end - it "ignores a passed block" do - output = @html.password_field("test", "some value") { "test" } - output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "VALUE" => "some value", "SIZE" => "40"}, "", not_closed: true) - end - end + describe "when passed name, value" do + it "returns an password-'input'-element with the passed name and value" do + output = @html.password_field("test", "some value") + output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "VALUE" => "some value", "SIZE" => "40"}, "", not_closed: true) + end - describe "when passed name, value, size" do - it "returns an password-'input'-element with the passed name, value and size" do - output = @html.password_field("test", "some value", 60) - output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "VALUE" => "some value", "SIZE" => "60"}, "", not_closed: true) + it "ignores a passed block" do + output = @html.password_field("test", "some value") { "test" } + output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "VALUE" => "some value", "SIZE" => "40"}, "", not_closed: true) + end end - it "ignores a passed block" do - output = @html.password_field("test", "some value", 60) { "test" } - output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "VALUE" => "some value", "SIZE" => "60"}, "", not_closed: true) - end - end + describe "when passed name, value, size" do + it "returns an password-'input'-element with the passed name, value and size" do + output = @html.password_field("test", "some value", 60) + output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "VALUE" => "some value", "SIZE" => "60"}, "", not_closed: true) + end - describe "when passed name, value, size, maxlength" do - it "returns an password-'input'-element with the passed name, value, size and maxlength" do - output = @html.password_field("test", "some value", 60, 12) - output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "VALUE" => "some value", "SIZE" => "60", "MAXLENGTH" => 12}, "", not_closed: true) + it "ignores a passed block" do + output = @html.password_field("test", "some value", 60) { "test" } + output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "VALUE" => "some value", "SIZE" => "60"}, "", not_closed: true) + end end - it "ignores a passed block" do - output = @html.password_field("test", "some value", 60, 12) { "test" } - output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "VALUE" => "some value", "SIZE" => "60", "MAXLENGTH" => 12}, "", not_closed: true) + describe "when passed name, value, size, maxlength" do + it "returns an password-'input'-element with the passed name, value, size and maxlength" do + output = @html.password_field("test", "some value", 60, 12) + output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "VALUE" => "some value", "SIZE" => "60", "MAXLENGTH" => 12}, "", not_closed: true) + end + + it "ignores a passed block" do + output = @html.password_field("test", "some value", 60, 12) { "test" } + output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "VALUE" => "some value", "SIZE" => "60", "MAXLENGTH" => 12}, "", not_closed: true) + end end - end - describe "when passed Hash" do - it "returns a checkbox-'input'-element using the passed Hash for attributes" do - output = @html.password_field("NAME" => "test", "VALUE" => "some value") - output.should equal_element("INPUT", { "NAME" => "test", "VALUE" => "some value", "TYPE" => "password" }, "", not_closed: true) + describe "when passed Hash" do + it "returns a checkbox-'input'-element using the passed Hash for attributes" do + output = @html.password_field("NAME" => "test", "VALUE" => "some value") + output.should equal_element("INPUT", { "NAME" => "test", "VALUE" => "some value", "TYPE" => "password" }, "", not_closed: true) - output = @html.password_field("TYPE" => "hidden") - output.should equal_element("INPUT", {"TYPE" => "password"}, "", not_closed: true) - end + output = @html.password_field("TYPE" => "hidden") + output.should equal_element("INPUT", {"TYPE" => "password"}, "", not_closed: true) + end - it "ignores a passed block" do - output = @html.password_field("NAME" => "test", "VALUE" => "some value") { "test" } - output.should equal_element("INPUT", { "NAME" => "test", "VALUE" => "some value", "TYPE" => "password" }, "", not_closed: true) + it "ignores a passed block" do + output = @html.password_field("NAME" => "test", "VALUE" => "some value") { "test" } + output.should equal_element("INPUT", { "NAME" => "test", "VALUE" => "some value", "TYPE" => "password" }, "", not_closed: true) + end end end end diff --git a/spec/ruby/library/cgi/htmlextension/popup_menu_spec.rb b/spec/ruby/library/cgi/htmlextension/popup_menu_spec.rb index 3462be09b0..7452d15317 100644 --- a/spec/ruby/library/cgi/htmlextension/popup_menu_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/popup_menu_spec.rb @@ -1,8 +1,11 @@ require_relative '../../../spec_helper' -require 'cgi' -require_relative 'fixtures/common' -require_relative 'shared/popup_menu' -describe "CGI::HtmlExtension#popup_menu" do - it_behaves_like :cgi_htmlextension_popup_menu, :popup_menu +ruby_version_is ""..."4.0" do + require 'cgi' + require_relative 'fixtures/common' + require_relative 'shared/popup_menu' + + describe "CGI::HtmlExtension#popup_menu" do + it_behaves_like :cgi_htmlextension_popup_menu, :popup_menu + end end diff --git a/spec/ruby/library/cgi/htmlextension/radio_button_spec.rb b/spec/ruby/library/cgi/htmlextension/radio_button_spec.rb index 3dc3c879b5..8458685cdc 100644 --- a/spec/ruby/library/cgi/htmlextension/radio_button_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/radio_button_spec.rb @@ -1,77 +1,80 @@ require_relative '../../../spec_helper' -require 'cgi' -require_relative 'fixtures/common' -describe "CGI::HtmlExtension#radio_button" do - before :each do - @html = CGISpecs.cgi_new - end +ruby_version_is ""..."4.0" do + require 'cgi' + require_relative 'fixtures/common' - describe "when passed no arguments" do - it "returns a radio-'input'-element without a name" do - output = @html.radio_button - output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "radio"}, "", not_closed: true) + describe "CGI::HtmlExtension#radio_button" do + before :each do + @html = CGISpecs.cgi_new end - it "ignores a passed block" do - output = @html.radio_button { "test" } - output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "radio"}, "", not_closed: true) - end - end + describe "when passed no arguments" do + it "returns a radio-'input'-element without a name" do + output = @html.radio_button + output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "radio"}, "", not_closed: true) + end - describe "when passed name" do - it "returns a radio-'input'-element with the passed name" do - output = @html.radio_button("test") - output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio"}, "", not_closed: true) + it "ignores a passed block" do + output = @html.radio_button { "test" } + output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "radio"}, "", not_closed: true) + end end - it "ignores a passed block" do - output = @html.radio_button("test") { "test" } - output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio"}, "", not_closed: true) - end - end + describe "when passed name" do + it "returns a radio-'input'-element with the passed name" do + output = @html.radio_button("test") + output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio"}, "", not_closed: true) + end - describe "CGI::HtmlExtension#checkbox when passed name, value" do - it "returns a radio-'input'-element with the passed name and value" do - output = @html.radio_button("test", "test-value") - output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "test-value"}, "", not_closed: true) + it "ignores a passed block" do + output = @html.radio_button("test") { "test" } + output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio"}, "", not_closed: true) + end end - it "ignores a passed block" do - output = @html.radio_button("test", "test-value") { "test" } - output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "test-value"}, "", not_closed: true) + describe "CGI::HtmlExtension#checkbox when passed name, value" do + it "returns a radio-'input'-element with the passed name and value" do + output = @html.radio_button("test", "test-value") + output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "test-value"}, "", not_closed: true) + end + + it "ignores a passed block" do + output = @html.radio_button("test", "test-value") { "test" } + output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "test-value"}, "", not_closed: true) + end end - end - describe "when passed name, value, checked" do - it "returns a checked radio-'input'-element with the passed name and value when checked is true" do - output = @html.radio_button("test", "test-value", true) - output.should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "radio", "VALUE" => "test-value"}, "", not_closed: true) + describe "when passed name, value, checked" do + it "returns a checked radio-'input'-element with the passed name and value when checked is true" do + output = @html.radio_button("test", "test-value", true) + output.should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "radio", "VALUE" => "test-value"}, "", not_closed: true) - output = @html.radio_button("test", "test-value", false) - output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "test-value"}, "", not_closed: true) + output = @html.radio_button("test", "test-value", false) + output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "test-value"}, "", not_closed: true) - output = @html.radio_button("test", "test-value", nil) - output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "test-value"}, "", not_closed: true) - end + output = @html.radio_button("test", "test-value", nil) + output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "test-value"}, "", not_closed: true) + end - it "ignores a passed block" do - output = @html.radio_button("test", "test-value", nil) { "test" } - output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "test-value"}, "", not_closed: true) + it "ignores a passed block" do + output = @html.radio_button("test", "test-value", nil) { "test" } + output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "test-value"}, "", not_closed: true) + end end - end - describe "when passed Hash" do - it "returns a radio-'input'-element using the passed Hash for attributes" do - attributes = {"NAME" => "test", "VALUE" => "test-value", "CHECKED" => true} - output = @html.radio_button(attributes) - output.should equal_element("INPUT", attributes, "", not_closed: true) - end + describe "when passed Hash" do + it "returns a radio-'input'-element using the passed Hash for attributes" do + attributes = {"NAME" => "test", "VALUE" => "test-value", "CHECKED" => true} + output = @html.radio_button(attributes) + output.should equal_element("INPUT", attributes, "", not_closed: true) + end - it "ignores a passed block" do - attributes = {"NAME" => "test", "VALUE" => "test-value", "CHECKED" => true} - output = @html.radio_button(attributes) { "test" } - output.should equal_element("INPUT", attributes, "", not_closed: true) + it "ignores a passed block" do + attributes = {"NAME" => "test", "VALUE" => "test-value", "CHECKED" => true} + output = @html.radio_button(attributes) { "test" } + output.should equal_element("INPUT", attributes, "", not_closed: true) + end end end end diff --git a/spec/ruby/library/cgi/htmlextension/radio_group_spec.rb b/spec/ruby/library/cgi/htmlextension/radio_group_spec.rb index 1bfd43449d..fd925a5165 100644 --- a/spec/ruby/library/cgi/htmlextension/radio_group_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/radio_group_spec.rb @@ -1,77 +1,80 @@ require_relative '../../../spec_helper' -require 'cgi' -require_relative 'fixtures/common' -describe "CGI::HtmlExtension#radio_group" do - before :each do - @html = CGISpecs.cgi_new - end +ruby_version_is ""..."4.0" do + require 'cgi' + require_relative 'fixtures/common' - describe "when passed name, values ..." do - it "returns a sequence of 'radio'-elements with the passed name and the passed values" do - output = CGISpecs.split(@html.radio_group("test", "foo", "bar", "baz")) - output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "foo"}, "foo", not_closed: true) - output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "bar"}, "bar", not_closed: true) - output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "baz"}, "baz", not_closed: true) + describe "CGI::HtmlExtension#radio_group" do + before :each do + @html = CGISpecs.cgi_new end - it "allows passing a value inside an Array" do - output = CGISpecs.split(@html.radio_group("test", ["foo"], "bar", ["baz"])) - output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "foo"}, "foo", not_closed: true) - output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "bar"}, "bar", not_closed: true) - output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "baz"}, "baz", not_closed: true) - end + describe "when passed name, values ..." do + it "returns a sequence of 'radio'-elements with the passed name and the passed values" do + output = CGISpecs.split(@html.radio_group("test", "foo", "bar", "baz")) + output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "foo"}, "foo", not_closed: true) + output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "bar"}, "bar", not_closed: true) + output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "baz"}, "baz", not_closed: true) + end - it "allows passing a value as an Array containing the value and the checked state or a label" do - output = CGISpecs.split(@html.radio_group("test", ["foo"], ["bar", true], ["baz", "label for baz"])) - output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "foo"}, "foo", not_closed: true) - output[1].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "radio", "VALUE" => "bar"}, "bar", not_closed: true) - output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "baz"}, "label for baz", not_closed: true) - end + it "allows passing a value inside an Array" do + output = CGISpecs.split(@html.radio_group("test", ["foo"], "bar", ["baz"])) + output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "foo"}, "foo", not_closed: true) + output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "bar"}, "bar", not_closed: true) + output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "baz"}, "baz", not_closed: true) + end - # TODO: CGI does not like passing false instead of true. - it "allows passing a value as an Array containing the value, a label and the checked state" do - output = CGISpecs.split(@html.radio_group("test", ["foo", "label for foo", true], ["bar", "label for bar", false], ["baz", "label for baz", true])) - output[0].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "radio", "VALUE" => "foo"}, "label for foo", not_closed: true) - output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "bar"}, "label for bar", not_closed: true) - output[2].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "radio", "VALUE" => "baz"}, "label for baz", not_closed: true) - end + it "allows passing a value as an Array containing the value and the checked state or a label" do + output = CGISpecs.split(@html.radio_group("test", ["foo"], ["bar", true], ["baz", "label for baz"])) + output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "foo"}, "foo", not_closed: true) + output[1].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "radio", "VALUE" => "bar"}, "bar", not_closed: true) + output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "baz"}, "label for baz", not_closed: true) + end - it "returns an empty String when passed no values" do - @html.radio_group("test").should == "" - end + # TODO: CGI does not like passing false instead of true. + it "allows passing a value as an Array containing the value, a label and the checked state" do + output = CGISpecs.split(@html.radio_group("test", ["foo", "label for foo", true], ["bar", "label for bar", false], ["baz", "label for baz", true])) + output[0].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "radio", "VALUE" => "foo"}, "label for foo", not_closed: true) + output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "bar"}, "label for bar", not_closed: true) + output[2].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "radio", "VALUE" => "baz"}, "label for baz", not_closed: true) + end + + it "returns an empty String when passed no values" do + @html.radio_group("test").should == "" + end - it "ignores a passed block" do - output = CGISpecs.split(@html.radio_group("test", "foo", "bar", "baz") { "test" }) - output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "foo"}, "foo", not_closed: true) - output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "bar"}, "bar", not_closed: true) - output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "baz"}, "baz", not_closed: true) + it "ignores a passed block" do + output = CGISpecs.split(@html.radio_group("test", "foo", "bar", "baz") { "test" }) + output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "foo"}, "foo", not_closed: true) + output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "bar"}, "bar", not_closed: true) + output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "baz"}, "baz", not_closed: true) + end end - end - describe "when passed Hash" do - it "uses the passed Hash to generate the radio sequence" do - output = CGISpecs.split(@html.radio_group("NAME" => "name", "VALUES" => ["foo", "bar", "baz"])) - output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "foo"}, "foo", not_closed: true) - output[1].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "bar"}, "bar", not_closed: true) - output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "baz"}, "baz", not_closed: true) + describe "when passed Hash" do + it "uses the passed Hash to generate the radio sequence" do + output = CGISpecs.split(@html.radio_group("NAME" => "name", "VALUES" => ["foo", "bar", "baz"])) + output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "foo"}, "foo", not_closed: true) + output[1].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "bar"}, "bar", not_closed: true) + output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "baz"}, "baz", not_closed: true) - output = CGISpecs.split(@html.radio_group("NAME" => "name", "VALUES" => [["foo"], ["bar", true], "baz"])) - output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "foo"}, "foo", not_closed: true) - output[1].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "name", "TYPE" => "radio", "VALUE" => "bar"}, "bar", not_closed: true) - output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "baz"}, "baz", not_closed: true) + output = CGISpecs.split(@html.radio_group("NAME" => "name", "VALUES" => [["foo"], ["bar", true], "baz"])) + output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "foo"}, "foo", not_closed: true) + output[1].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "name", "TYPE" => "radio", "VALUE" => "bar"}, "bar", not_closed: true) + output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "baz"}, "baz", not_closed: true) - output = CGISpecs.split(@html.radio_group("NAME" => "name", "VALUES" => [["1", "Foo"], ["2", "Bar", true], "Baz"])) - output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "1"}, "Foo", not_closed: true) - output[1].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "name", "TYPE" => "radio", "VALUE" => "2"}, "Bar", not_closed: true) - output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "Baz"}, "Baz", not_closed: true) - end + output = CGISpecs.split(@html.radio_group("NAME" => "name", "VALUES" => [["1", "Foo"], ["2", "Bar", true], "Baz"])) + output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "1"}, "Foo", not_closed: true) + output[1].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "name", "TYPE" => "radio", "VALUE" => "2"}, "Bar", not_closed: true) + output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "Baz"}, "Baz", not_closed: true) + end - it "ignores a passed block" do - output = CGISpecs.split(@html.radio_group("NAME" => "name", "VALUES" => ["foo", "bar", "baz"]) { "test" }) - output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "foo"}, "foo", not_closed: true) - output[1].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "bar"}, "bar", not_closed: true) - output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "baz"}, "baz", not_closed: true) + it "ignores a passed block" do + output = CGISpecs.split(@html.radio_group("NAME" => "name", "VALUES" => ["foo", "bar", "baz"]) { "test" }) + output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "foo"}, "foo", not_closed: true) + output[1].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "bar"}, "bar", not_closed: true) + output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "baz"}, "baz", not_closed: true) + end end end end diff --git a/spec/ruby/library/cgi/htmlextension/reset_spec.rb b/spec/ruby/library/cgi/htmlextension/reset_spec.rb index 86fa25fc8a..80e4441b16 100644 --- a/spec/ruby/library/cgi/htmlextension/reset_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/reset_spec.rb @@ -1,57 +1,60 @@ require_relative '../../../spec_helper' -require 'cgi' -require_relative 'fixtures/common' -describe "CGI::HtmlExtension#reset" do - before :each do - @html = CGISpecs.cgi_new - end +ruby_version_is ""..."4.0" do + require 'cgi' + require_relative 'fixtures/common' - describe "when passed no arguments" do - it "returns a reset-'input'-element" do - output = @html.reset - output.should equal_element("INPUT", {"TYPE" => "reset"}, "", not_closed: true) + describe "CGI::HtmlExtension#reset" do + before :each do + @html = CGISpecs.cgi_new end - it "ignores a passed block" do - output = @html.reset { "test" } - output.should equal_element("INPUT", {"TYPE" => "reset"}, "", not_closed: true) - end - end + describe "when passed no arguments" do + it "returns a reset-'input'-element" do + output = @html.reset + output.should equal_element("INPUT", {"TYPE" => "reset"}, "", not_closed: true) + end - describe "when passed value" do - it "returns a reset-'input'-element with the passed value" do - output = @html.reset("Example") - output.should equal_element("INPUT", {"TYPE" => "reset", "VALUE" => "Example"}, "", not_closed: true) + it "ignores a passed block" do + output = @html.reset { "test" } + output.should equal_element("INPUT", {"TYPE" => "reset"}, "", not_closed: true) + end end - it "ignores a passed block" do - output = @html.reset("Example") { "test" } - output.should equal_element("INPUT", {"TYPE" => "reset", "VALUE" => "Example"}, "", not_closed: true) - end - end + describe "when passed value" do + it "returns a reset-'input'-element with the passed value" do + output = @html.reset("Example") + output.should equal_element("INPUT", {"TYPE" => "reset", "VALUE" => "Example"}, "", not_closed: true) + end - describe "when passed value, name" do - it "returns a reset-'input'-element with the passed value and the passed name" do - output = @html.reset("Example", "test-name") - output.should equal_element("INPUT", {"TYPE" => "reset", "VALUE" => "Example", "NAME" => "test-name"}, "", not_closed: true) + it "ignores a passed block" do + output = @html.reset("Example") { "test" } + output.should equal_element("INPUT", {"TYPE" => "reset", "VALUE" => "Example"}, "", not_closed: true) + end end - it "ignores a passed block" do - output = @html.reset("Example", "test-name") { "test" } - output.should equal_element("INPUT", {"TYPE" => "reset", "VALUE" => "Example", "NAME" => "test-name"}, "", not_closed: true) - end - end + describe "when passed value, name" do + it "returns a reset-'input'-element with the passed value and the passed name" do + output = @html.reset("Example", "test-name") + output.should equal_element("INPUT", {"TYPE" => "reset", "VALUE" => "Example", "NAME" => "test-name"}, "", not_closed: true) + end - describe "when passed Hash" do - it "returns a reset-'input'-element with the passed value" do - output = @html.reset("Example") - output.should equal_element("INPUT", {"TYPE" => "reset", "VALUE" => "Example"}, "", not_closed: true) + it "ignores a passed block" do + output = @html.reset("Example", "test-name") { "test" } + output.should equal_element("INPUT", {"TYPE" => "reset", "VALUE" => "Example", "NAME" => "test-name"}, "", not_closed: true) + end end - it "ignores a passed block" do - output = @html.reset("Example") { "test" } - output.should equal_element("INPUT", {"TYPE" => "reset", "VALUE" => "Example"}, "", not_closed: true) + describe "when passed Hash" do + it "returns a reset-'input'-element with the passed value" do + output = @html.reset("Example") + output.should equal_element("INPUT", {"TYPE" => "reset", "VALUE" => "Example"}, "", not_closed: true) + end + + it "ignores a passed block" do + output = @html.reset("Example") { "test" } + output.should equal_element("INPUT", {"TYPE" => "reset", "VALUE" => "Example"}, "", not_closed: true) + end end end end diff --git a/spec/ruby/library/cgi/htmlextension/scrolling_list_spec.rb b/spec/ruby/library/cgi/htmlextension/scrolling_list_spec.rb index 4eb0c86c1a..b565444679 100644 --- a/spec/ruby/library/cgi/htmlextension/scrolling_list_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/scrolling_list_spec.rb @@ -1,8 +1,11 @@ require_relative '../../../spec_helper' -require_relative 'fixtures/common' -require 'cgi' -require_relative 'shared/popup_menu' -describe "CGI::HtmlExtension#scrolling_list" do - it_behaves_like :cgi_htmlextension_popup_menu, :scrolling_list +ruby_version_is ""..."4.0" do + require_relative 'fixtures/common' + require 'cgi' + require_relative 'shared/popup_menu' + + describe "CGI::HtmlExtension#scrolling_list" do + it_behaves_like :cgi_htmlextension_popup_menu, :scrolling_list + end end diff --git a/spec/ruby/library/cgi/htmlextension/submit_spec.rb b/spec/ruby/library/cgi/htmlextension/submit_spec.rb index 063891b959..bb6e079c4e 100644 --- a/spec/ruby/library/cgi/htmlextension/submit_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/submit_spec.rb @@ -1,57 +1,60 @@ require_relative '../../../spec_helper' -require 'cgi' -require_relative 'fixtures/common' -describe "CGI::HtmlExtension#submit" do - before :each do - @html = CGISpecs.cgi_new - end +ruby_version_is ""..."4.0" do + require 'cgi' + require_relative 'fixtures/common' - describe "when passed no arguments" do - it "returns a submit-'input'-element" do - output = @html.submit - output.should equal_element("INPUT", {"TYPE" => "submit"}, "", not_closed: true) + describe "CGI::HtmlExtension#submit" do + before :each do + @html = CGISpecs.cgi_new end - it "ignores a passed block" do - output = @html.submit { "test" } - output.should equal_element("INPUT", {"TYPE" => "submit"}, "", not_closed: true) - end - end + describe "when passed no arguments" do + it "returns a submit-'input'-element" do + output = @html.submit + output.should equal_element("INPUT", {"TYPE" => "submit"}, "", not_closed: true) + end - describe "when passed value" do - it "returns a submit-'input'-element with the passed value" do - output = @html.submit("Example") - output.should equal_element("INPUT", {"TYPE" => "submit", "VALUE" => "Example"}, "", not_closed: true) + it "ignores a passed block" do + output = @html.submit { "test" } + output.should equal_element("INPUT", {"TYPE" => "submit"}, "", not_closed: true) + end end - it "ignores a passed block" do - output = @html.submit("Example") { "test" } - output.should equal_element("INPUT", {"TYPE" => "submit", "VALUE" => "Example"}, "", not_closed: true) - end - end + describe "when passed value" do + it "returns a submit-'input'-element with the passed value" do + output = @html.submit("Example") + output.should equal_element("INPUT", {"TYPE" => "submit", "VALUE" => "Example"}, "", not_closed: true) + end - describe "when passed value, name" do - it "returns a submit-'input'-element with the passed value and the passed name" do - output = @html.submit("Example", "test-name") - output.should equal_element("INPUT", {"TYPE" => "submit", "VALUE" => "Example", "NAME" => "test-name"}, "", not_closed: true) + it "ignores a passed block" do + output = @html.submit("Example") { "test" } + output.should equal_element("INPUT", {"TYPE" => "submit", "VALUE" => "Example"}, "", not_closed: true) + end end - it "ignores a passed block" do - output = @html.submit("Example", "test-name") { "test" } - output.should equal_element("INPUT", {"TYPE" => "submit", "VALUE" => "Example", "NAME" => "test-name"}, "", not_closed: true) - end - end + describe "when passed value, name" do + it "returns a submit-'input'-element with the passed value and the passed name" do + output = @html.submit("Example", "test-name") + output.should equal_element("INPUT", {"TYPE" => "submit", "VALUE" => "Example", "NAME" => "test-name"}, "", not_closed: true) + end - describe "when passed Hash" do - it "returns a submit-'input'-element with the passed value" do - output = @html.submit("Example") - output.should equal_element("INPUT", {"TYPE" => "submit", "VALUE" => "Example"}, "", not_closed: true) + it "ignores a passed block" do + output = @html.submit("Example", "test-name") { "test" } + output.should equal_element("INPUT", {"TYPE" => "submit", "VALUE" => "Example", "NAME" => "test-name"}, "", not_closed: true) + end end - it "ignores a passed block" do - output = @html.submit("Example") { "test" } - output.should equal_element("INPUT", {"TYPE" => "submit", "VALUE" => "Example"}, "", not_closed: true) + describe "when passed Hash" do + it "returns a submit-'input'-element with the passed value" do + output = @html.submit("Example") + output.should equal_element("INPUT", {"TYPE" => "submit", "VALUE" => "Example"}, "", not_closed: true) + end + + it "ignores a passed block" do + output = @html.submit("Example") { "test" } + output.should equal_element("INPUT", {"TYPE" => "submit", "VALUE" => "Example"}, "", not_closed: true) + end end end end diff --git a/spec/ruby/library/cgi/htmlextension/text_field_spec.rb b/spec/ruby/library/cgi/htmlextension/text_field_spec.rb index 44b5a5e69f..37e13e3746 100644 --- a/spec/ruby/library/cgi/htmlextension/text_field_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/text_field_spec.rb @@ -1,84 +1,87 @@ require_relative '../../../spec_helper' -require 'cgi' -require_relative 'fixtures/common' -describe "CGI::HtmlExtension#text_field" do - before :each do - @html = CGISpecs.cgi_new - end +ruby_version_is ""..."4.0" do + require 'cgi' + require_relative 'fixtures/common' - describe "when passed no arguments" do - it "returns an text-'input'-element without a name" do - output = @html.text_field - output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "text", "SIZE" => "40"}, "", not_closed: true) + describe "CGI::HtmlExtension#text_field" do + before :each do + @html = CGISpecs.cgi_new end - it "ignores a passed block" do - output = @html.text_field { "test" } - output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "text", "SIZE" => "40"}, "", not_closed: true) - end - end + describe "when passed no arguments" do + it "returns an text-'input'-element without a name" do + output = @html.text_field + output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "text", "SIZE" => "40"}, "", not_closed: true) + end - describe "when passed name" do - it "returns an text-'input'-element with the passed name" do - output = @html.text_field("test") - output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "SIZE" => "40"}, "", not_closed: true) + it "ignores a passed block" do + output = @html.text_field { "test" } + output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "text", "SIZE" => "40"}, "", not_closed: true) + end end - it "ignores a passed block" do - output = @html.text_field("test") { "test" } - output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "SIZE" => "40"}, "", not_closed: true) - end - end + describe "when passed name" do + it "returns an text-'input'-element with the passed name" do + output = @html.text_field("test") + output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "SIZE" => "40"}, "", not_closed: true) + end - describe "when passed name, value" do - it "returns an text-'input'-element with the passed name and value" do - output = @html.text_field("test", "some value") - output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "VALUE" => "some value", "SIZE" => "40"}, "", not_closed: true) + it "ignores a passed block" do + output = @html.text_field("test") { "test" } + output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "SIZE" => "40"}, "", not_closed: true) + end end - it "ignores a passed block" do - output = @html.text_field("test", "some value") { "test" } - output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "VALUE" => "some value", "SIZE" => "40"}, "", not_closed: true) - end - end + describe "when passed name, value" do + it "returns an text-'input'-element with the passed name and value" do + output = @html.text_field("test", "some value") + output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "VALUE" => "some value", "SIZE" => "40"}, "", not_closed: true) + end - describe "when passed name, value, size" do - it "returns an text-'input'-element with the passed name, value and size" do - output = @html.text_field("test", "some value", 60) - output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "VALUE" => "some value", "SIZE" => "60"}, "", not_closed: true) + it "ignores a passed block" do + output = @html.text_field("test", "some value") { "test" } + output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "VALUE" => "some value", "SIZE" => "40"}, "", not_closed: true) + end end - it "ignores a passed block" do - output = @html.text_field("test", "some value", 60) { "test" } - output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "VALUE" => "some value", "SIZE" => "60"}, "", not_closed: true) - end - end + describe "when passed name, value, size" do + it "returns an text-'input'-element with the passed name, value and size" do + output = @html.text_field("test", "some value", 60) + output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "VALUE" => "some value", "SIZE" => "60"}, "", not_closed: true) + end - describe "when passed name, value, size, maxlength" do - it "returns an text-'input'-element with the passed name, value, size and maxlength" do - output = @html.text_field("test", "some value", 60, 12) - output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "VALUE" => "some value", "SIZE" => "60", "MAXLENGTH" => 12}, "", not_closed: true) + it "ignores a passed block" do + output = @html.text_field("test", "some value", 60) { "test" } + output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "VALUE" => "some value", "SIZE" => "60"}, "", not_closed: true) + end end - it "ignores a passed block" do - output = @html.text_field("test", "some value", 60, 12) { "test" } - output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "VALUE" => "some value", "SIZE" => "60", "MAXLENGTH" => 12}, "", not_closed: true) + describe "when passed name, value, size, maxlength" do + it "returns an text-'input'-element with the passed name, value, size and maxlength" do + output = @html.text_field("test", "some value", 60, 12) + output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "VALUE" => "some value", "SIZE" => "60", "MAXLENGTH" => 12}, "", not_closed: true) + end + + it "ignores a passed block" do + output = @html.text_field("test", "some value", 60, 12) { "test" } + output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "VALUE" => "some value", "SIZE" => "60", "MAXLENGTH" => 12}, "", not_closed: true) + end end - end - describe "when passed Hash" do - it "returns a checkbox-'input'-element using the passed Hash for attributes" do - output = @html.text_field("NAME" => "test", "VALUE" => "some value") - output.should equal_element("INPUT", { "NAME" => "test", "VALUE" => "some value", "TYPE" => "text" }, "", not_closed: true) + describe "when passed Hash" do + it "returns a checkbox-'input'-element using the passed Hash for attributes" do + output = @html.text_field("NAME" => "test", "VALUE" => "some value") + output.should equal_element("INPUT", { "NAME" => "test", "VALUE" => "some value", "TYPE" => "text" }, "", not_closed: true) - output = @html.text_field("TYPE" => "hidden") - output.should equal_element("INPUT", {"TYPE" => "text"}, "", not_closed: true) - end + output = @html.text_field("TYPE" => "hidden") + output.should equal_element("INPUT", {"TYPE" => "text"}, "", not_closed: true) + end - it "ignores a passed block" do - output = @html.text_field("NAME" => "test", "VALUE" => "some value") { "test" } - output.should equal_element("INPUT", { "NAME" => "test", "VALUE" => "some value", "TYPE" => "text" }, "", not_closed: true) + it "ignores a passed block" do + output = @html.text_field("NAME" => "test", "VALUE" => "some value") { "test" } + output.should equal_element("INPUT", { "NAME" => "test", "VALUE" => "some value", "TYPE" => "text" }, "", not_closed: true) + end end end end diff --git a/spec/ruby/library/cgi/htmlextension/textarea_spec.rb b/spec/ruby/library/cgi/htmlextension/textarea_spec.rb index db84a973d2..99c6d3dd2d 100644 --- a/spec/ruby/library/cgi/htmlextension/textarea_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/textarea_spec.rb @@ -1,73 +1,76 @@ require_relative '../../../spec_helper' -require 'cgi' -require_relative 'fixtures/common' -describe "CGI::HtmlExtension#textarea" do - before :each do - @html = CGISpecs.cgi_new - end +ruby_version_is ""..."4.0" do + require 'cgi' + require_relative 'fixtures/common' - describe "when passed no arguments" do - it "returns an 'textarea'-element without a name" do - output = @html.textarea - output.should equal_element("TEXTAREA", {"NAME" => "", "COLS" => "70", "ROWS" => "10"}, "") + describe "CGI::HtmlExtension#textarea" do + before :each do + @html = CGISpecs.cgi_new end - it "includes the return value of the passed block when passed a block" do - output = @html.textarea { "Example" } - output.should equal_element("TEXTAREA", {"NAME" => "", "COLS" => "70", "ROWS" => "10"}, "Example") - end - end + describe "when passed no arguments" do + it "returns an 'textarea'-element without a name" do + output = @html.textarea + output.should equal_element("TEXTAREA", {"NAME" => "", "COLS" => "70", "ROWS" => "10"}, "") + end - describe "when passed name" do - it "returns an 'textarea'-element with the passed name" do - output = @html.textarea("test") - output.should equal_element("TEXTAREA", {"NAME" => "test", "COLS" => "70", "ROWS" => "10"}, "") + it "includes the return value of the passed block when passed a block" do + output = @html.textarea { "Example" } + output.should equal_element("TEXTAREA", {"NAME" => "", "COLS" => "70", "ROWS" => "10"}, "Example") + end end - it "includes the return value of the passed block when passed a block" do - output = @html.textarea("test") { "Example" } - output.should equal_element("TEXTAREA", {"NAME" => "test", "COLS" => "70", "ROWS" => "10"}, "Example") - end - end + describe "when passed name" do + it "returns an 'textarea'-element with the passed name" do + output = @html.textarea("test") + output.should equal_element("TEXTAREA", {"NAME" => "test", "COLS" => "70", "ROWS" => "10"}, "") + end - describe "when passed name, cols" do - it "returns an 'textarea'-element with the passed name and the passed amount of columns" do - output = @html.textarea("test", 40) - output.should equal_element("TEXTAREA", {"NAME" => "test", "COLS" => "40", "ROWS" => "10"}, "") + it "includes the return value of the passed block when passed a block" do + output = @html.textarea("test") { "Example" } + output.should equal_element("TEXTAREA", {"NAME" => "test", "COLS" => "70", "ROWS" => "10"}, "Example") + end end - it "includes the return value of the passed block when passed a block" do - output = @html.textarea("test", 40) { "Example" } - output.should equal_element("TEXTAREA", {"NAME" => "test", "COLS" => "40", "ROWS" => "10"}, "Example") - end - end + describe "when passed name, cols" do + it "returns an 'textarea'-element with the passed name and the passed amount of columns" do + output = @html.textarea("test", 40) + output.should equal_element("TEXTAREA", {"NAME" => "test", "COLS" => "40", "ROWS" => "10"}, "") + end - describe "when passed name, cols, rows" do - it "returns an 'textarea'-element with the passed name, the passed amount of columns and the passed number of rows" do - output = @html.textarea("test", 40, 5) - output.should equal_element("TEXTAREA", {"NAME" => "test", "COLS" => "40", "ROWS" => "5"}, "") + it "includes the return value of the passed block when passed a block" do + output = @html.textarea("test", 40) { "Example" } + output.should equal_element("TEXTAREA", {"NAME" => "test", "COLS" => "40", "ROWS" => "10"}, "Example") + end end - it "includes the return value of the passed block when passed a block" do - output = @html.textarea("test", 40, 5) { "Example" } - output.should equal_element("TEXTAREA", {"NAME" => "test", "COLS" => "40", "ROWS" => "5"}, "Example") + describe "when passed name, cols, rows" do + it "returns an 'textarea'-element with the passed name, the passed amount of columns and the passed number of rows" do + output = @html.textarea("test", 40, 5) + output.should equal_element("TEXTAREA", {"NAME" => "test", "COLS" => "40", "ROWS" => "5"}, "") + end + + it "includes the return value of the passed block when passed a block" do + output = @html.textarea("test", 40, 5) { "Example" } + output.should equal_element("TEXTAREA", {"NAME" => "test", "COLS" => "40", "ROWS" => "5"}, "Example") + end end - end - describe "when passed Hash" do - it "uses the passed Hash as attributes" do - @html.textarea("ID" => "test").should == '<TEXTAREA ID="test"></TEXTAREA>' + describe "when passed Hash" do + it "uses the passed Hash as attributes" do + @html.textarea("ID" => "test").should == '<TEXTAREA ID="test"></TEXTAREA>' - attributes = {"ID" => "test-id", "NAME" => "test-name"} - output = @html.textarea(attributes) - output.should equal_element("TEXTAREA", attributes, "") - end + attributes = {"ID" => "test-id", "NAME" => "test-name"} + output = @html.textarea(attributes) + output.should equal_element("TEXTAREA", attributes, "") + end - it "includes the return value of the passed block when passed a block" do - attributes = {"ID" => "test-id", "NAME" => "test-name"} - output = @html.textarea(attributes) { "test" } - output.should equal_element("TEXTAREA", attributes, "test") + it "includes the return value of the passed block when passed a block" do + attributes = {"ID" => "test-id", "NAME" => "test-name"} + output = @html.textarea(attributes) { "test" } + output.should equal_element("TEXTAREA", attributes, "test") + end end end end diff --git a/spec/ruby/library/cgi/http_header_spec.rb b/spec/ruby/library/cgi/http_header_spec.rb index 4094bebed3..8d9f3fe9b8 100644 --- a/spec/ruby/library/cgi/http_header_spec.rb +++ b/spec/ruby/library/cgi/http_header_spec.rb @@ -1,8 +1,11 @@ require_relative '../../spec_helper' -require 'cgi' -require_relative 'shared/http_header' +ruby_version_is ""..."4.0" do + require 'cgi' -describe "CGI#http_header" do - it_behaves_like :cgi_http_header, :http_header + require_relative 'shared/http_header' + + describe "CGI#http_header" do + it_behaves_like :cgi_http_header, :http_header + end end diff --git a/spec/ruby/library/cgi/initialize_spec.rb b/spec/ruby/library/cgi/initialize_spec.rb index f794f157f0..b8ecf5cac2 100644 --- a/spec/ruby/library/cgi/initialize_spec.rb +++ b/spec/ruby/library/cgi/initialize_spec.rb @@ -1,133 +1,136 @@ require_relative '../../spec_helper' -require 'cgi' -describe "CGI#initialize" do - it "is private" do - CGI.should have_private_instance_method(:initialize) - end -end +ruby_version_is ""..."4.0" do + require 'cgi' -describe "CGI#initialize when passed no arguments" do - before :each do - ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] - @cgi = CGI.allocate - end - - after :each do - ENV['REQUEST_METHOD'] = @old_request_method - end - - it "extends self with CGI::QueryExtension" do - @cgi.send(:initialize) - @cgi.should be_kind_of(CGI::QueryExtension) + describe "CGI#initialize" do + it "is private" do + CGI.should have_private_instance_method(:initialize) + end end - it "does not extend self with CGI::HtmlExtension" do - @cgi.send(:initialize) - @cgi.should_not be_kind_of(CGI::HtmlExtension) - end + describe "CGI#initialize when passed no arguments" do + before :each do + ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] + @cgi = CGI.allocate + end - it "does not extend self with any of the other HTML modules" do - @cgi.send(:initialize) - @cgi.should_not be_kind_of(CGI::Html3) - @cgi.should_not be_kind_of(CGI::HtmlExtension) - @cgi.should_not be_kind_of(CGI::Html4) - @cgi.should_not be_kind_of(CGI::Html4Tr) - @cgi.should_not be_kind_of(CGI::Html4Fr) - end + after :each do + ENV['REQUEST_METHOD'] = @old_request_method + end - it "sets #cookies based on ENV['HTTP_COOKIE']" do - begin - old_env, ENV["HTTP_COOKIE"] = ENV["HTTP_COOKIE"], "test=test yay" + it "extends self with CGI::QueryExtension" do @cgi.send(:initialize) - @cgi.cookies.should == { "test"=>[ "test yay" ] } - ensure - ENV["HTTP_COOKIE"] = old_env + @cgi.should be_kind_of(CGI::QueryExtension) end - end - it "sets #params based on ENV['QUERY_STRING'] when ENV['REQUEST_METHOD'] is GET" do - begin - old_env_query, ENV["QUERY_STRING"] = ENV["QUERY_STRING"], "?test=a&test2=b" - old_env_method, ENV["REQUEST_METHOD"] = ENV["REQUEST_METHOD"], "GET" + it "does not extend self with CGI::HtmlExtension" do @cgi.send(:initialize) - @cgi.params.should == { "test2" => ["b"], "?test" => ["a"] } - ensure - ENV["QUERY_STRING"] = old_env_query - ENV["REQUEST_METHOD"] = old_env_method + @cgi.should_not be_kind_of(CGI::HtmlExtension) end - end - it "sets #params based on ENV['QUERY_STRING'] when ENV['REQUEST_METHOD'] is HEAD" do - begin - old_env_query, ENV["QUERY_STRING"] = ENV["QUERY_STRING"], "?test=a&test2=b" - old_env_method, ENV["REQUEST_METHOD"] = ENV["REQUEST_METHOD"], "HEAD" + it "does not extend self with any of the other HTML modules" do @cgi.send(:initialize) - @cgi.params.should == { "test2" => ["b"], "?test" => ["a"] } - ensure - ENV["QUERY_STRING"] = old_env_query - ENV["REQUEST_METHOD"] = old_env_method + @cgi.should_not be_kind_of(CGI::HtmlExtension) + @cgi.should_not be_kind_of(CGI::Html3) + @cgi.should_not be_kind_of(CGI::Html4) + @cgi.should_not be_kind_of(CGI::Html4Tr) + @cgi.should_not be_kind_of(CGI::Html4Fr) end - end -end -describe "CGI#initialize when passed type" do - before :each do - ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] - @cgi = CGI.allocate - end + it "sets #cookies based on ENV['HTTP_COOKIE']" do + begin + old_env, ENV["HTTP_COOKIE"] = ENV["HTTP_COOKIE"], "test=test yay" + @cgi.send(:initialize) + @cgi.cookies.should == { "test"=>[ "test yay" ] } + ensure + ENV["HTTP_COOKIE"] = old_env + end + end - after :each do - ENV['REQUEST_METHOD'] = @old_request_method + it "sets #params based on ENV['QUERY_STRING'] when ENV['REQUEST_METHOD'] is GET" do + begin + old_env_query, ENV["QUERY_STRING"] = ENV["QUERY_STRING"], "?test=a&test2=b" + old_env_method, ENV["REQUEST_METHOD"] = ENV["REQUEST_METHOD"], "GET" + @cgi.send(:initialize) + @cgi.params.should == { "test2" => ["b"], "?test" => ["a"] } + ensure + ENV["QUERY_STRING"] = old_env_query + ENV["REQUEST_METHOD"] = old_env_method + end + end + + it "sets #params based on ENV['QUERY_STRING'] when ENV['REQUEST_METHOD'] is HEAD" do + begin + old_env_query, ENV["QUERY_STRING"] = ENV["QUERY_STRING"], "?test=a&test2=b" + old_env_method, ENV["REQUEST_METHOD"] = ENV["REQUEST_METHOD"], "HEAD" + @cgi.send(:initialize) + @cgi.params.should == { "test2" => ["b"], "?test" => ["a"] } + ensure + ENV["QUERY_STRING"] = old_env_query + ENV["REQUEST_METHOD"] = old_env_method + end + end end + describe "CGI#initialize when passed type" do + before :each do + ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] + @cgi = CGI.allocate + end - it "extends self with CGI::QueryExtension" do - @cgi.send(:initialize, "test") - @cgi.should be_kind_of(CGI::QueryExtension) - end + after :each do + ENV['REQUEST_METHOD'] = @old_request_method + end - it "extends self with CGI::QueryExtension, CGI::Html3 and CGI::HtmlExtension when the passed type is 'html3'" do - @cgi.send(:initialize, "html3") - @cgi.should be_kind_of(CGI::Html3) - @cgi.should be_kind_of(CGI::HtmlExtension) - @cgi.should be_kind_of(CGI::QueryExtension) - @cgi.should_not be_kind_of(CGI::Html4) - @cgi.should_not be_kind_of(CGI::Html4Tr) - @cgi.should_not be_kind_of(CGI::Html4Fr) - end + it "extends self with CGI::QueryExtension" do + @cgi.send(:initialize, "test") + @cgi.should be_kind_of(CGI::QueryExtension) + end - it "extends self with CGI::QueryExtension, CGI::Html4 and CGI::HtmlExtension when the passed type is 'html4'" do - @cgi.send(:initialize, "html4") - @cgi.should be_kind_of(CGI::Html4) - @cgi.should be_kind_of(CGI::HtmlExtension) - @cgi.should be_kind_of(CGI::QueryExtension) + it "extends self with CGI::QueryExtension, CGI::Html3 and CGI::HtmlExtension when the passed type is 'html3'" do + @cgi.send(:initialize, "html3") + @cgi.should be_kind_of(CGI::Html3) + @cgi.should be_kind_of(CGI::HtmlExtension) + @cgi.should be_kind_of(CGI::QueryExtension) - @cgi.should_not be_kind_of(CGI::Html3) - @cgi.should_not be_kind_of(CGI::Html4Tr) - @cgi.should_not be_kind_of(CGI::Html4Fr) - end + @cgi.should_not be_kind_of(CGI::Html4) + @cgi.should_not be_kind_of(CGI::Html4Tr) + @cgi.should_not be_kind_of(CGI::Html4Fr) + end - it "extends self with CGI::QueryExtension, CGI::Html4Tr and CGI::HtmlExtension when the passed type is 'html4Tr'" do - @cgi.send(:initialize, "html4Tr") - @cgi.should be_kind_of(CGI::Html4Tr) - @cgi.should be_kind_of(CGI::HtmlExtension) - @cgi.should be_kind_of(CGI::QueryExtension) + it "extends self with CGI::QueryExtension, CGI::Html4 and CGI::HtmlExtension when the passed type is 'html4'" do + @cgi.send(:initialize, "html4") + @cgi.should be_kind_of(CGI::Html4) + @cgi.should be_kind_of(CGI::HtmlExtension) + @cgi.should be_kind_of(CGI::QueryExtension) - @cgi.should_not be_kind_of(CGI::Html3) - @cgi.should_not be_kind_of(CGI::Html4) - @cgi.should_not be_kind_of(CGI::Html4Fr) - end + @cgi.should_not be_kind_of(CGI::Html3) + @cgi.should_not be_kind_of(CGI::Html4Tr) + @cgi.should_not be_kind_of(CGI::Html4Fr) + end - it "extends self with CGI::QueryExtension, CGI::Html4Tr, CGI::Html4Fr and CGI::HtmlExtension when the passed type is 'html4Fr'" do - @cgi.send(:initialize, "html4Fr") - @cgi.should be_kind_of(CGI::Html4Tr) - @cgi.should be_kind_of(CGI::Html4Fr) - @cgi.should be_kind_of(CGI::HtmlExtension) - @cgi.should be_kind_of(CGI::QueryExtension) + it "extends self with CGI::QueryExtension, CGI::Html4Tr and CGI::HtmlExtension when the passed type is 'html4Tr'" do + @cgi.send(:initialize, "html4Tr") + @cgi.should be_kind_of(CGI::Html4Tr) + @cgi.should be_kind_of(CGI::HtmlExtension) + @cgi.should be_kind_of(CGI::QueryExtension) - @cgi.should_not be_kind_of(CGI::Html3) - @cgi.should_not be_kind_of(CGI::Html4) + @cgi.should_not be_kind_of(CGI::Html3) + @cgi.should_not be_kind_of(CGI::Html4) + @cgi.should_not be_kind_of(CGI::Html4Fr) + end + + it "extends self with CGI::QueryExtension, CGI::Html4Tr, CGI::Html4Fr and CGI::HtmlExtension when the passed type is 'html4Fr'" do + @cgi.send(:initialize, "html4Fr") + @cgi.should be_kind_of(CGI::Html4Tr) + @cgi.should be_kind_of(CGI::Html4Fr) + @cgi.should be_kind_of(CGI::HtmlExtension) + @cgi.should be_kind_of(CGI::QueryExtension) + + @cgi.should_not be_kind_of(CGI::Html3) + @cgi.should_not be_kind_of(CGI::Html4) + end end end diff --git a/spec/ruby/library/cgi/out_spec.rb b/spec/ruby/library/cgi/out_spec.rb index bc09f5bcbb..733e656ea1 100644 --- a/spec/ruby/library/cgi/out_spec.rb +++ b/spec/ruby/library/cgi/out_spec.rb @@ -1,51 +1,54 @@ require_relative '../../spec_helper' -require 'cgi' -describe "CGI#out" do - before :each do - ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] - @cgi = CGI.new - $stdout, @old_stdout = IOStub.new, $stdout - end - - after :each do - $stdout = @old_stdout - ENV['REQUEST_METHOD'] = @old_request_method - end - - it "it writes a HTMl header based on the passed argument to $stdout" do - @cgi.out { "" } - $stdout.should == "Content-Type: text/html\r\nContent-Length: 0\r\n\r\n" - end - - it "appends the block's return value to the HTML header" do - @cgi.out { "test!" } - $stdout.should == "Content-Type: text/html\r\nContent-Length: 5\r\n\r\ntest!" - end - - it "automatically sets the Content-Length Header based on the block's return value" do - @cgi.out { "0123456789" } - $stdout.should == "Content-Type: text/html\r\nContent-Length: 10\r\n\r\n0123456789" - end - - it "includes Cookies in the @output_cookies field" do - @cgi.instance_variable_set(:@output_cookies, ["multiple", "cookies"]) - @cgi.out { "" } - $stdout.should == "Content-Type: text/html\r\nContent-Length: 0\r\nSet-Cookie: multiple\r\nSet-Cookie: cookies\r\n\r\n" - end -end - -describe "CGI#out when passed no block" do - before :each do - ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] - @cgi = CGI.new - end - - after :each do - ENV['REQUEST_METHOD'] = @old_request_method - end - - it "raises a LocalJumpError" do - -> { @cgi.out }.should raise_error(LocalJumpError) +ruby_version_is ""..."4.0" do + require 'cgi' + + describe "CGI#out" do + before :each do + ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] + @cgi = CGI.new + $stdout, @old_stdout = IOStub.new, $stdout + end + + after :each do + $stdout = @old_stdout + ENV['REQUEST_METHOD'] = @old_request_method + end + + it "it writes a HTMl header based on the passed argument to $stdout" do + @cgi.out { "" } + $stdout.should == "Content-Type: text/html\r\nContent-Length: 0\r\n\r\n" + end + + it "appends the block's return value to the HTML header" do + @cgi.out { "test!" } + $stdout.should == "Content-Type: text/html\r\nContent-Length: 5\r\n\r\ntest!" + end + + it "automatically sets the Content-Length Header based on the block's return value" do + @cgi.out { "0123456789" } + $stdout.should == "Content-Type: text/html\r\nContent-Length: 10\r\n\r\n0123456789" + end + + it "includes Cookies in the @output_cookies field" do + @cgi.instance_variable_set(:@output_cookies, ["multiple", "cookies"]) + @cgi.out { "" } + $stdout.should == "Content-Type: text/html\r\nContent-Length: 0\r\nSet-Cookie: multiple\r\nSet-Cookie: cookies\r\n\r\n" + end + end + + describe "CGI#out when passed no block" do + before :each do + ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] + @cgi = CGI.new + end + + after :each do + ENV['REQUEST_METHOD'] = @old_request_method + end + + it "raises a LocalJumpError" do + -> { @cgi.out }.should raise_error(LocalJumpError) + end end end diff --git a/spec/ruby/library/cgi/parse_spec.rb b/spec/ruby/library/cgi/parse_spec.rb index 04539b1226..f09270c195 100644 --- a/spec/ruby/library/cgi/parse_spec.rb +++ b/spec/ruby/library/cgi/parse_spec.rb @@ -1,24 +1,27 @@ require_relative '../../spec_helper' -require 'cgi' -describe "CGI.parse when passed String" do - it "parses a HTTP Query String into a Hash" do - CGI.parse("test=test&a=b").should == { "a" => ["b"], "test" => ["test"] } - CGI.parse("test=1,2,3").should == { "test" => ["1,2,3"] } - CGI.parse("test=a&a=&b=").should == { "test" => ["a"], "a" => [""], "b" => [""] } - end +ruby_version_is ""..."4.0" do + require 'cgi' - it "parses query strings with semicolons in place of ampersands" do - CGI.parse("test=test;a=b").should == { "a" => ["b"], "test" => ["test"] } - CGI.parse("test=a;a=;b=").should == { "test" => ["a"], "a" => [""], "b" => [""] } - end + describe "CGI.parse when passed String" do + it "parses a HTTP Query String into a Hash" do + CGI.parse("test=test&a=b").should == { "a" => ["b"], "test" => ["test"] } + CGI.parse("test=1,2,3").should == { "test" => ["1,2,3"] } + CGI.parse("test=a&a=&b=").should == { "test" => ["a"], "a" => [""], "b" => [""] } + end - it "allows passing multiple values for one key" do - CGI.parse("test=1&test=2&test=3").should == { "test" => ["1", "2", "3"] } - CGI.parse("test[]=1&test[]=2&test[]=3").should == { "test[]" => [ "1", "2", "3" ] } - end + it "parses query strings with semicolons in place of ampersands" do + CGI.parse("test=test;a=b").should == { "a" => ["b"], "test" => ["test"] } + CGI.parse("test=a;a=;b=").should == { "test" => ["a"], "a" => [""], "b" => [""] } + end + + it "allows passing multiple values for one key" do + CGI.parse("test=1&test=2&test=3").should == { "test" => ["1", "2", "3"] } + CGI.parse("test[]=1&test[]=2&test[]=3").should == { "test[]" => [ "1", "2", "3" ] } + end - it "unescapes keys and values" do - CGI.parse("hello%3F=hello%21").should == { "hello?" => ["hello!"] } + it "unescapes keys and values" do + CGI.parse("hello%3F=hello%21").should == { "hello?" => ["hello!"] } + end end end diff --git a/spec/ruby/library/cgi/pretty_spec.rb b/spec/ruby/library/cgi/pretty_spec.rb index a7b7505c15..9df1611037 100644 --- a/spec/ruby/library/cgi/pretty_spec.rb +++ b/spec/ruby/library/cgi/pretty_spec.rb @@ -1,24 +1,27 @@ require_relative '../../spec_helper' -require 'cgi' -describe "CGI.pretty when passed html" do - it "indents the passed html String with two spaces" do - CGI.pretty("<HTML><BODY></BODY></HTML>").should == <<-EOS +ruby_version_is ""..."4.0" do + require 'cgi' + + describe "CGI.pretty when passed html" do + it "indents the passed html String with two spaces" do + CGI.pretty("<HTML><BODY></BODY></HTML>").should == <<-EOS <HTML> <BODY> </BODY> </HTML> EOS + end end -end -describe "CGI.pretty when passed html, indentation_unit" do - it "indents the passed html String with the passed indentation_unit" do - CGI.pretty("<HTML><BODY></BODY></HTML>", "\t").should == <<-EOS + describe "CGI.pretty when passed html, indentation_unit" do + it "indents the passed html String with the passed indentation_unit" do + CGI.pretty("<HTML><BODY></BODY></HTML>", "\t").should == <<-EOS <HTML> \t<BODY> \t</BODY> </HTML> EOS + end end end diff --git a/spec/ruby/library/cgi/print_spec.rb b/spec/ruby/library/cgi/print_spec.rb index 18ab8d673b..f4f461c5c0 100644 --- a/spec/ruby/library/cgi/print_spec.rb +++ b/spec/ruby/library/cgi/print_spec.rb @@ -1,26 +1,29 @@ require_relative '../../spec_helper' -require 'cgi' -describe "CGI#print" do - before :each do - ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] - @cgi = CGI.new - end +ruby_version_is ""..."4.0" do + require 'cgi' - after :each do - ENV['REQUEST_METHOD'] = @old_request_method - end + describe "CGI#print" do + before :each do + ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] + @cgi = CGI.new + end - it "passes all arguments to $stdout.print" do - $stdout.should_receive(:print).with("test") - @cgi.print("test") + after :each do + ENV['REQUEST_METHOD'] = @old_request_method + end - $stdout.should_receive(:print).with("one", "two", "three", ["four", "five"]) - @cgi.print("one", "two", "three", ["four", "five"]) - end + it "passes all arguments to $stdout.print" do + $stdout.should_receive(:print).with("test") + @cgi.print("test") + + $stdout.should_receive(:print).with("one", "two", "three", ["four", "five"]) + @cgi.print("one", "two", "three", ["four", "five"]) + end - it "returns the result of calling $stdout.print" do - $stdout.should_receive(:print).with("test").and_return(:expected) - @cgi.print("test").should == :expected + it "returns the result of calling $stdout.print" do + $stdout.should_receive(:print).with("test").and_return(:expected) + @cgi.print("test").should == :expected + end end end diff --git a/spec/ruby/library/cgi/queryextension/accept_charset_spec.rb b/spec/ruby/library/cgi/queryextension/accept_charset_spec.rb index 0487569b9c..be05f0c175 100644 --- a/spec/ruby/library/cgi/queryextension/accept_charset_spec.rb +++ b/spec/ruby/library/cgi/queryextension/accept_charset_spec.rb @@ -1,22 +1,25 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::QueryExtension#accept_charset" do - before :each do - ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] - @cgi = CGI.new - end +ruby_version_is ""..."4.0" do + require 'cgi' - after :each do - ENV['REQUEST_METHOD'] = @old_request_method - end + describe "CGI::QueryExtension#accept_charset" do + before :each do + ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] + @cgi = CGI.new + end + + after :each do + ENV['REQUEST_METHOD'] = @old_request_method + end - it "returns ENV['HTTP_ACCEPT_CHARSET']" do - old_value, ENV['HTTP_ACCEPT_CHARSET'] = ENV['HTTP_ACCEPT_CHARSET'], "ISO-8859-1,utf-8;q=0.7,*;q=0.7" - begin - @cgi.accept_charset.should == "ISO-8859-1,utf-8;q=0.7,*;q=0.7" - ensure - ENV['HTTP_ACCEPT_CHARSET'] = old_value + it "returns ENV['HTTP_ACCEPT_CHARSET']" do + old_value, ENV['HTTP_ACCEPT_CHARSET'] = ENV['HTTP_ACCEPT_CHARSET'], "ISO-8859-1,utf-8;q=0.7,*;q=0.7" + begin + @cgi.accept_charset.should == "ISO-8859-1,utf-8;q=0.7,*;q=0.7" + ensure + ENV['HTTP_ACCEPT_CHARSET'] = old_value + end end end end diff --git a/spec/ruby/library/cgi/queryextension/accept_encoding_spec.rb b/spec/ruby/library/cgi/queryextension/accept_encoding_spec.rb index 35ff3c2b30..42eb4a49b5 100644 --- a/spec/ruby/library/cgi/queryextension/accept_encoding_spec.rb +++ b/spec/ruby/library/cgi/queryextension/accept_encoding_spec.rb @@ -1,22 +1,25 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::QueryExtension#accept_encoding" do - before :each do - ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] - @cgi = CGI.new - end +ruby_version_is ""..."4.0" do + require 'cgi' - after :each do - ENV['REQUEST_METHOD'] = @old_request_method - end + describe "CGI::QueryExtension#accept_encoding" do + before :each do + ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] + @cgi = CGI.new + end + + after :each do + ENV['REQUEST_METHOD'] = @old_request_method + end - it "returns ENV['HTTP_ACCEPT_ENCODING']" do - old_value, ENV['HTTP_ACCEPT_ENCODING'] = ENV['HTTP_ACCEPT_ENCODING'], "gzip,deflate" - begin - @cgi.accept_encoding.should == "gzip,deflate" - ensure - ENV['HTTP_ACCEPT_ENCODING'] = old_value + it "returns ENV['HTTP_ACCEPT_ENCODING']" do + old_value, ENV['HTTP_ACCEPT_ENCODING'] = ENV['HTTP_ACCEPT_ENCODING'], "gzip,deflate" + begin + @cgi.accept_encoding.should == "gzip,deflate" + ensure + ENV['HTTP_ACCEPT_ENCODING'] = old_value + end end end end diff --git a/spec/ruby/library/cgi/queryextension/accept_language_spec.rb b/spec/ruby/library/cgi/queryextension/accept_language_spec.rb index 4a15d58914..19f29c6345 100644 --- a/spec/ruby/library/cgi/queryextension/accept_language_spec.rb +++ b/spec/ruby/library/cgi/queryextension/accept_language_spec.rb @@ -1,22 +1,25 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::QueryExtension#accept_language" do - before :each do - ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] - @cgi = CGI.new - end +ruby_version_is ""..."4.0" do + require 'cgi' - after :each do - ENV['REQUEST_METHOD'] = @old_request_method - end + describe "CGI::QueryExtension#accept_language" do + before :each do + ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] + @cgi = CGI.new + end + + after :each do + ENV['REQUEST_METHOD'] = @old_request_method + end - it "returns ENV['HTTP_ACCEPT_LANGUAGE']" do - old_value, ENV['HTTP_ACCEPT_LANGUAGE'] = ENV['HTTP_ACCEPT_LANGUAGE'], "en-us,en;q=0.5" - begin - @cgi.accept_language.should == "en-us,en;q=0.5" - ensure - ENV['HTTP_ACCEPT_LANGUAGE'] = old_value + it "returns ENV['HTTP_ACCEPT_LANGUAGE']" do + old_value, ENV['HTTP_ACCEPT_LANGUAGE'] = ENV['HTTP_ACCEPT_LANGUAGE'], "en-us,en;q=0.5" + begin + @cgi.accept_language.should == "en-us,en;q=0.5" + ensure + ENV['HTTP_ACCEPT_LANGUAGE'] = old_value + end end end end diff --git a/spec/ruby/library/cgi/queryextension/accept_spec.rb b/spec/ruby/library/cgi/queryextension/accept_spec.rb index af5209ffbe..dcae39a736 100644 --- a/spec/ruby/library/cgi/queryextension/accept_spec.rb +++ b/spec/ruby/library/cgi/queryextension/accept_spec.rb @@ -1,22 +1,25 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::QueryExtension#accept" do - before :each do - ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] - @cgi = CGI.new - end +ruby_version_is ""..."4.0" do + require 'cgi' - after :each do - ENV['REQUEST_METHOD'] = @old_request_method - end + describe "CGI::QueryExtension#accept" do + before :each do + ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] + @cgi = CGI.new + end + + after :each do + ENV['REQUEST_METHOD'] = @old_request_method + end - it "returns ENV['HTTP_ACCEPT']" do - old_value, ENV['HTTP_ACCEPT'] = ENV['HTTP_ACCEPT'], "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5" - begin - @cgi.accept.should == "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5" - ensure - ENV['HTTP_ACCEPT'] = old_value + it "returns ENV['HTTP_ACCEPT']" do + old_value, ENV['HTTP_ACCEPT'] = ENV['HTTP_ACCEPT'], "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5" + begin + @cgi.accept.should == "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5" + ensure + ENV['HTTP_ACCEPT'] = old_value + end end end end diff --git a/spec/ruby/library/cgi/queryextension/auth_type_spec.rb b/spec/ruby/library/cgi/queryextension/auth_type_spec.rb index 25318269b1..75e9cdb27a 100644 --- a/spec/ruby/library/cgi/queryextension/auth_type_spec.rb +++ b/spec/ruby/library/cgi/queryextension/auth_type_spec.rb @@ -1,22 +1,25 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::QueryExtension#auth_type" do - before :each do - ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] - @cgi = CGI.new - end +ruby_version_is ""..."4.0" do + require 'cgi' - after :each do - ENV['REQUEST_METHOD'] = @old_request_method - end + describe "CGI::QueryExtension#auth_type" do + before :each do + ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] + @cgi = CGI.new + end + + after :each do + ENV['REQUEST_METHOD'] = @old_request_method + end - it "returns ENV['AUTH_TYPE']" do - old_value, ENV['AUTH_TYPE'] = ENV['AUTH_TYPE'], "Basic" - begin - @cgi.auth_type.should == "Basic" - ensure - ENV['AUTH_TYPE'] = old_value + it "returns ENV['AUTH_TYPE']" do + old_value, ENV['AUTH_TYPE'] = ENV['AUTH_TYPE'], "Basic" + begin + @cgi.auth_type.should == "Basic" + ensure + ENV['AUTH_TYPE'] = old_value + end end end end diff --git a/spec/ruby/library/cgi/queryextension/cache_control_spec.rb b/spec/ruby/library/cgi/queryextension/cache_control_spec.rb index 0471307c22..c4b727e671 100644 --- a/spec/ruby/library/cgi/queryextension/cache_control_spec.rb +++ b/spec/ruby/library/cgi/queryextension/cache_control_spec.rb @@ -1,22 +1,25 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::QueryExtension#cache_control" do - before :each do - ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] - @cgi = CGI.new - end +ruby_version_is ""..."4.0" do + require 'cgi' - after :each do - ENV['REQUEST_METHOD'] = @old_request_method - end + describe "CGI::QueryExtension#cache_control" do + before :each do + ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] + @cgi = CGI.new + end + + after :each do + ENV['REQUEST_METHOD'] = @old_request_method + end - it "returns ENV['HTTP_CACHE_CONTROL']" do - old_value, ENV['HTTP_CACHE_CONTROL'] = ENV['HTTP_CACHE_CONTROL'], "no-cache" - begin - @cgi.cache_control.should == "no-cache" - ensure - ENV['HTTP_CACHE_CONTROL'] = old_value + it "returns ENV['HTTP_CACHE_CONTROL']" do + old_value, ENV['HTTP_CACHE_CONTROL'] = ENV['HTTP_CACHE_CONTROL'], "no-cache" + begin + @cgi.cache_control.should == "no-cache" + ensure + ENV['HTTP_CACHE_CONTROL'] = old_value + end end end end diff --git a/spec/ruby/library/cgi/queryextension/content_length_spec.rb b/spec/ruby/library/cgi/queryextension/content_length_spec.rb index de823f7119..a8b87e148c 100644 --- a/spec/ruby/library/cgi/queryextension/content_length_spec.rb +++ b/spec/ruby/library/cgi/queryextension/content_length_spec.rb @@ -1,26 +1,29 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::QueryExtension#content_length" do - before :each do - ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] - @cgi = CGI.new - end +ruby_version_is ""..."4.0" do + require 'cgi' - after :each do - ENV['REQUEST_METHOD'] = @old_request_method - end + describe "CGI::QueryExtension#content_length" do + before :each do + ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] + @cgi = CGI.new + end + + after :each do + ENV['REQUEST_METHOD'] = @old_request_method + end - it "returns ENV['CONTENT_LENGTH'] as Integer" do - old_value = ENV['CONTENT_LENGTH'] - begin - ENV['CONTENT_LENGTH'] = nil - @cgi.content_length.should be_nil + it "returns ENV['CONTENT_LENGTH'] as Integer" do + old_value = ENV['CONTENT_LENGTH'] + begin + ENV['CONTENT_LENGTH'] = nil + @cgi.content_length.should be_nil - ENV['CONTENT_LENGTH'] = "100" - @cgi.content_length.should eql(100) - ensure - ENV['CONTENT_LENGTH'] = old_value + ENV['CONTENT_LENGTH'] = "100" + @cgi.content_length.should eql(100) + ensure + ENV['CONTENT_LENGTH'] = old_value + end end end end diff --git a/spec/ruby/library/cgi/queryextension/content_type_spec.rb b/spec/ruby/library/cgi/queryextension/content_type_spec.rb index 49b8389c87..d3cbdf0b14 100644 --- a/spec/ruby/library/cgi/queryextension/content_type_spec.rb +++ b/spec/ruby/library/cgi/queryextension/content_type_spec.rb @@ -1,22 +1,25 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::QueryExtension#content_type" do - before :each do - ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] - @cgi = CGI.new - end +ruby_version_is ""..."4.0" do + require 'cgi' - after :each do - ENV['REQUEST_METHOD'] = @old_request_method - end + describe "CGI::QueryExtension#content_type" do + before :each do + ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] + @cgi = CGI.new + end + + after :each do + ENV['REQUEST_METHOD'] = @old_request_method + end - it "returns ENV['CONTENT_TYPE']" do - old_value, ENV['CONTENT_TYPE'] = ENV['CONTENT_TYPE'], "text/html" - begin - @cgi.content_type.should == "text/html" - ensure - ENV['CONTENT_TYPE'] = old_value + it "returns ENV['CONTENT_TYPE']" do + old_value, ENV['CONTENT_TYPE'] = ENV['CONTENT_TYPE'], "text/html" + begin + @cgi.content_type.should == "text/html" + ensure + ENV['CONTENT_TYPE'] = old_value + end end end end diff --git a/spec/ruby/library/cgi/queryextension/cookies_spec.rb b/spec/ruby/library/cgi/queryextension/cookies_spec.rb index 4befd61ab7..266fe0c721 100644 --- a/spec/ruby/library/cgi/queryextension/cookies_spec.rb +++ b/spec/ruby/library/cgi/queryextension/cookies_spec.rb @@ -1,10 +1,13 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::QueryExtension#cookies" do - it "needs to be reviewed for spec completeness" -end +ruby_version_is ""..."4.0" do + require 'cgi' + + describe "CGI::QueryExtension#cookies" do + it "needs to be reviewed for spec completeness" + end -describe "CGI::QueryExtension#cookies=" do - it "needs to be reviewed for spec completeness" + describe "CGI::QueryExtension#cookies=" do + it "needs to be reviewed for spec completeness" + end end diff --git a/spec/ruby/library/cgi/queryextension/element_reference_spec.rb b/spec/ruby/library/cgi/queryextension/element_reference_spec.rb index 6ac5b46407..0b57387efc 100644 --- a/spec/ruby/library/cgi/queryextension/element_reference_spec.rb +++ b/spec/ruby/library/cgi/queryextension/element_reference_spec.rb @@ -1,27 +1,30 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::QueryExtension#[]" do - before :each do - ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] - ENV['QUERY_STRING'], @old_query_string = "one=a&two=b&two=c", ENV['QUERY_STRING'] - @cgi = CGI.new - end +ruby_version_is ""..."4.0" do + require 'cgi' - after :each do - ENV['REQUEST_METHOD'] = @old_request_method - ENV['QUERY_STRING'] = @old_query_string - end + describe "CGI::QueryExtension#[]" do + before :each do + ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] + ENV['QUERY_STRING'], @old_query_string = "one=a&two=b&two=c", ENV['QUERY_STRING'] + @cgi = CGI.new + end - it "it returns the value for the parameter with the given key" do - @cgi["one"].should == "a" - end + after :each do + ENV['REQUEST_METHOD'] = @old_request_method + ENV['QUERY_STRING'] = @old_query_string + end - it "only returns the first value for parameters with multiple values" do - @cgi["two"].should == "b" - end + it "it returns the value for the parameter with the given key" do + @cgi["one"].should == "a" + end + + it "only returns the first value for parameters with multiple values" do + @cgi["two"].should == "b" + end - it "returns a String" do - @cgi["one"].should be_kind_of(String) + it "returns a String" do + @cgi["one"].should be_kind_of(String) + end end end diff --git a/spec/ruby/library/cgi/queryextension/from_spec.rb b/spec/ruby/library/cgi/queryextension/from_spec.rb index 04a992cfc7..b341e0be10 100644 --- a/spec/ruby/library/cgi/queryextension/from_spec.rb +++ b/spec/ruby/library/cgi/queryextension/from_spec.rb @@ -1,22 +1,25 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::QueryExtension#from" do - before :each do - ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] - @cgi = CGI.new - end +ruby_version_is ""..."4.0" do + require 'cgi' - after :each do - ENV['REQUEST_METHOD'] = @old_request_method - end + describe "CGI::QueryExtension#from" do + before :each do + ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] + @cgi = CGI.new + end + + after :each do + ENV['REQUEST_METHOD'] = @old_request_method + end - it "returns ENV['HTTP_FROM']" do - old_value, ENV['HTTP_FROM'] = ENV['HTTP_FROM'], "googlebot(at)googlebot.com" - begin - @cgi.from.should == "googlebot(at)googlebot.com" - ensure - ENV['HTTP_FROM'] = old_value + it "returns ENV['HTTP_FROM']" do + old_value, ENV['HTTP_FROM'] = ENV['HTTP_FROM'], "googlebot(at)googlebot.com" + begin + @cgi.from.should == "googlebot(at)googlebot.com" + ensure + ENV['HTTP_FROM'] = old_value + end end end end diff --git a/spec/ruby/library/cgi/queryextension/gateway_interface_spec.rb b/spec/ruby/library/cgi/queryextension/gateway_interface_spec.rb index 3ead5bd8bf..c82522326b 100644 --- a/spec/ruby/library/cgi/queryextension/gateway_interface_spec.rb +++ b/spec/ruby/library/cgi/queryextension/gateway_interface_spec.rb @@ -1,22 +1,25 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::QueryExtension#gateway_interface" do - before :each do - ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] - @cgi = CGI.new - end +ruby_version_is ""..."4.0" do + require 'cgi' - after :each do - ENV['REQUEST_METHOD'] = @old_request_method - end + describe "CGI::QueryExtension#gateway_interface" do + before :each do + ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] + @cgi = CGI.new + end + + after :each do + ENV['REQUEST_METHOD'] = @old_request_method + end - it "returns ENV['GATEWAY_INTERFACE']" do - old_value, ENV['GATEWAY_INTERFACE'] = ENV['GATEWAY_INTERFACE'], "CGI/1.1" - begin - @cgi.gateway_interface.should == "CGI/1.1" - ensure - ENV['GATEWAY_INTERFACE'] = old_value + it "returns ENV['GATEWAY_INTERFACE']" do + old_value, ENV['GATEWAY_INTERFACE'] = ENV['GATEWAY_INTERFACE'], "CGI/1.1" + begin + @cgi.gateway_interface.should == "CGI/1.1" + ensure + ENV['GATEWAY_INTERFACE'] = old_value + end end end end diff --git a/spec/ruby/library/cgi/queryextension/has_key_spec.rb b/spec/ruby/library/cgi/queryextension/has_key_spec.rb index 525b45b507..43f7aae1b2 100644 --- a/spec/ruby/library/cgi/queryextension/has_key_spec.rb +++ b/spec/ruby/library/cgi/queryextension/has_key_spec.rb @@ -1,7 +1,10 @@ require_relative '../../../spec_helper' -require 'cgi' -require_relative 'shared/has_key' -describe "CGI::QueryExtension#has_key?" do - it_behaves_like :cgi_query_extension_has_key_p, :has_key? +ruby_version_is ""..."4.0" do + require 'cgi' + require_relative 'shared/has_key' + + describe "CGI::QueryExtension#has_key?" do + it_behaves_like :cgi_query_extension_has_key_p, :has_key? + end end diff --git a/spec/ruby/library/cgi/queryextension/host_spec.rb b/spec/ruby/library/cgi/queryextension/host_spec.rb index e820e0afc3..e1047c942b 100644 --- a/spec/ruby/library/cgi/queryextension/host_spec.rb +++ b/spec/ruby/library/cgi/queryextension/host_spec.rb @@ -1,22 +1,25 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::QueryExtension#host" do - before :each do - ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] - @cgi = CGI.new - end +ruby_version_is ""..."4.0" do + require 'cgi' - after :each do - ENV['REQUEST_METHOD'] = @old_request_method - end + describe "CGI::QueryExtension#host" do + before :each do + ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] + @cgi = CGI.new + end + + after :each do + ENV['REQUEST_METHOD'] = @old_request_method + end - it "returns ENV['HTTP_HOST']" do - old_value, ENV['HTTP_HOST'] = ENV['HTTP_HOST'], "localhost" - begin - @cgi.host.should == "localhost" - ensure - ENV['HTTP_HOST'] = old_value + it "returns ENV['HTTP_HOST']" do + old_value, ENV['HTTP_HOST'] = ENV['HTTP_HOST'], "localhost" + begin + @cgi.host.should == "localhost" + ensure + ENV['HTTP_HOST'] = old_value + end end end end diff --git a/spec/ruby/library/cgi/queryextension/include_spec.rb b/spec/ruby/library/cgi/queryextension/include_spec.rb index 12365ea284..7275c309f9 100644 --- a/spec/ruby/library/cgi/queryextension/include_spec.rb +++ b/spec/ruby/library/cgi/queryextension/include_spec.rb @@ -1,7 +1,10 @@ require_relative '../../../spec_helper' -require 'cgi' -require_relative 'shared/has_key' -describe "CGI::QueryExtension#include?" do - it_behaves_like :cgi_query_extension_has_key_p, :include? +ruby_version_is ""..."4.0" do + require 'cgi' + require_relative 'shared/has_key' + + describe "CGI::QueryExtension#include?" do + it_behaves_like :cgi_query_extension_has_key_p, :include? + end end diff --git a/spec/ruby/library/cgi/queryextension/key_spec.rb b/spec/ruby/library/cgi/queryextension/key_spec.rb index d0f1e4cee2..dc2f52fbe0 100644 --- a/spec/ruby/library/cgi/queryextension/key_spec.rb +++ b/spec/ruby/library/cgi/queryextension/key_spec.rb @@ -1,7 +1,10 @@ require_relative '../../../spec_helper' -require 'cgi' -require_relative 'shared/has_key' -describe "CGI::QueryExtension#key?" do - it_behaves_like :cgi_query_extension_has_key_p, :key? +ruby_version_is ""..."4.0" do + require 'cgi' + require_relative 'shared/has_key' + + describe "CGI::QueryExtension#key?" do + it_behaves_like :cgi_query_extension_has_key_p, :key? + end end diff --git a/spec/ruby/library/cgi/queryextension/keys_spec.rb b/spec/ruby/library/cgi/queryextension/keys_spec.rb index 14d77180fa..bb16914065 100644 --- a/spec/ruby/library/cgi/queryextension/keys_spec.rb +++ b/spec/ruby/library/cgi/queryextension/keys_spec.rb @@ -1,20 +1,23 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::QueryExtension#keys" do - before :each do - ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] - ENV['QUERY_STRING'], @old_query_string = "one=a&two=b", ENV['QUERY_STRING'] +ruby_version_is ""..."4.0" do + require 'cgi' - @cgi = CGI.new - end + describe "CGI::QueryExtension#keys" do + before :each do + ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] + ENV['QUERY_STRING'], @old_query_string = "one=a&two=b", ENV['QUERY_STRING'] - after :each do - ENV['REQUEST_METHOD'] = @old_request_method - ENV['QUERY_STRING'] = @old_query_string - end + @cgi = CGI.new + end + + after :each do + ENV['REQUEST_METHOD'] = @old_request_method + ENV['QUERY_STRING'] = @old_query_string + end - it "returns all parameter keys as an Array" do - @cgi.keys.sort.should == ["one", "two"] + it "returns all parameter keys as an Array" do + @cgi.keys.sort.should == ["one", "two"] + end end end diff --git a/spec/ruby/library/cgi/queryextension/multipart_spec.rb b/spec/ruby/library/cgi/queryextension/multipart_spec.rb index ced4cb05a1..281791892c 100644 --- a/spec/ruby/library/cgi/queryextension/multipart_spec.rb +++ b/spec/ruby/library/cgi/queryextension/multipart_spec.rb @@ -1,20 +1,22 @@ require_relative '../../../spec_helper' -require 'cgi' -require "stringio" -describe "CGI::QueryExtension#multipart?" do - before :each do - @old_stdin = $stdin +ruby_version_is ""..."4.0" do + require 'cgi' + require "stringio" - @old_request_method = ENV['REQUEST_METHOD'] - @old_content_type = ENV['CONTENT_TYPE'] - @old_content_length = ENV['CONTENT_LENGTH'] + describe "CGI::QueryExtension#multipart?" do + before :each do + @old_stdin = $stdin - ENV['REQUEST_METHOD'] = "POST" - ENV["CONTENT_TYPE"] = "multipart/form-data; boundary=---------------------------1137522503144128232716531729" - ENV["CONTENT_LENGTH"] = "222" + @old_request_method = ENV['REQUEST_METHOD'] + @old_content_type = ENV['CONTENT_TYPE'] + @old_content_length = ENV['CONTENT_LENGTH'] - $stdin = StringIO.new <<-EOS + ENV['REQUEST_METHOD'] = "POST" + ENV["CONTENT_TYPE"] = "multipart/form-data; boundary=---------------------------1137522503144128232716531729" + ENV["CONTENT_LENGTH"] = "222" + + $stdin = StringIO.new <<-EOS -----------------------------1137522503144128232716531729\r Content-Disposition: form-data; name="file"; filename=""\r Content-Type: application/octet-stream\r @@ -23,18 +25,19 @@ Content-Type: application/octet-stream\r -----------------------------1137522503144128232716531729--\r EOS - @cgi = CGI.new - end + @cgi = CGI.new + end - after :each do - $stdin = @old_stdin + after :each do + $stdin = @old_stdin - ENV['REQUEST_METHOD'] = @old_request_method - ENV['CONTENT_TYPE'] = @old_content_type - ENV['CONTENT_LENGTH'] = @old_content_length - end + ENV['REQUEST_METHOD'] = @old_request_method + ENV['CONTENT_TYPE'] = @old_content_type + ENV['CONTENT_LENGTH'] = @old_content_length + end - it "returns true if the current Request is a multipart request" do - @cgi.multipart?.should be_true + it "returns true if the current Request is a multipart request" do + @cgi.multipart?.should be_true + end end end diff --git a/spec/ruby/library/cgi/queryextension/negotiate_spec.rb b/spec/ruby/library/cgi/queryextension/negotiate_spec.rb index b6fe036042..4083e6a8cd 100644 --- a/spec/ruby/library/cgi/queryextension/negotiate_spec.rb +++ b/spec/ruby/library/cgi/queryextension/negotiate_spec.rb @@ -1,22 +1,25 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::QueryExtension#negotiate" do - before :each do - ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] - @cgi = CGI.new - end +ruby_version_is ""..."4.0" do + require 'cgi' - after :each do - ENV['REQUEST_METHOD'] = @old_request_method - end + describe "CGI::QueryExtension#negotiate" do + before :each do + ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] + @cgi = CGI.new + end + + after :each do + ENV['REQUEST_METHOD'] = @old_request_method + end - it "returns ENV['HTTP_NEGOTIATE']" do - old_value, ENV['HTTP_NEGOTIATE'] = ENV['HTTP_NEGOTIATE'], "trans" - begin - @cgi.negotiate.should == "trans" - ensure - ENV['HTTP_NEGOTIATE'] = old_value + it "returns ENV['HTTP_NEGOTIATE']" do + old_value, ENV['HTTP_NEGOTIATE'] = ENV['HTTP_NEGOTIATE'], "trans" + begin + @cgi.negotiate.should == "trans" + ensure + ENV['HTTP_NEGOTIATE'] = old_value + end end end end diff --git a/spec/ruby/library/cgi/queryextension/params_spec.rb b/spec/ruby/library/cgi/queryextension/params_spec.rb index f4449e3c8a..938028ea14 100644 --- a/spec/ruby/library/cgi/queryextension/params_spec.rb +++ b/spec/ruby/library/cgi/queryextension/params_spec.rb @@ -1,37 +1,40 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::QueryExtension#params" do - before :each do - ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] - ENV['QUERY_STRING'], @old_query_string = "one=a&two=b&two=c&three", ENV['QUERY_STRING'] - @cgi = CGI.new - end +ruby_version_is ""..."4.0" do + require 'cgi' - after :each do - ENV['QUERY_STRING'] = @old_query_string - ENV['REQUEST_METHOD'] = @old_request_method - end + describe "CGI::QueryExtension#params" do + before :each do + ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] + ENV['QUERY_STRING'], @old_query_string = "one=a&two=b&two=c&three", ENV['QUERY_STRING'] + @cgi = CGI.new + end - it "returns the parsed HTTP Query Params" do - @cgi.params.should == {"three"=>[], "two"=>["b", "c"], "one"=>["a"]} - end -end + after :each do + ENV['QUERY_STRING'] = @old_query_string + ENV['REQUEST_METHOD'] = @old_request_method + end -describe "CGI::QueryExtension#params=" do - before :each do - ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] - @cgi = CGI.new + it "returns the parsed HTTP Query Params" do + @cgi.params.should == {"three"=>[], "two"=>["b", "c"], "one"=>["a"]} + end end - after :each do - ENV['REQUEST_METHOD'] = @old_request_method - end + describe "CGI::QueryExtension#params=" do + before :each do + ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] + @cgi = CGI.new + end + + after :each do + ENV['REQUEST_METHOD'] = @old_request_method + end - it "sets the HTTP Query Params to the passed argument" do - @cgi.params.should == {} + it "sets the HTTP Query Params to the passed argument" do + @cgi.params.should == {} - @cgi.params = {"one"=>["a"], "two"=>["b", "c"]} - @cgi.params.should == {"one"=>["a"], "two"=>["b", "c"]} + @cgi.params = {"one"=>["a"], "two"=>["b", "c"]} + @cgi.params.should == {"one"=>["a"], "two"=>["b", "c"]} + end end end diff --git a/spec/ruby/library/cgi/queryextension/path_info_spec.rb b/spec/ruby/library/cgi/queryextension/path_info_spec.rb index 9785df85f1..9b7834c514 100644 --- a/spec/ruby/library/cgi/queryextension/path_info_spec.rb +++ b/spec/ruby/library/cgi/queryextension/path_info_spec.rb @@ -1,22 +1,25 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::QueryExtension#path_info" do - before :each do - ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] - @cgi = CGI.new - end +ruby_version_is ""..."4.0" do + require 'cgi' - after :each do - ENV['REQUEST_METHOD'] = @old_request_method - end + describe "CGI::QueryExtension#path_info" do + before :each do + ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] + @cgi = CGI.new + end + + after :each do + ENV['REQUEST_METHOD'] = @old_request_method + end - it "returns ENV['PATH_INFO']" do - old_value, ENV['PATH_INFO'] = ENV['PATH_INFO'], "/test/path" - begin - @cgi.path_info.should == "/test/path" - ensure - ENV['PATH_INFO'] = old_value + it "returns ENV['PATH_INFO']" do + old_value, ENV['PATH_INFO'] = ENV['PATH_INFO'], "/test/path" + begin + @cgi.path_info.should == "/test/path" + ensure + ENV['PATH_INFO'] = old_value + end end end end diff --git a/spec/ruby/library/cgi/queryextension/path_translated_spec.rb b/spec/ruby/library/cgi/queryextension/path_translated_spec.rb index 417a749341..a773aaafdb 100644 --- a/spec/ruby/library/cgi/queryextension/path_translated_spec.rb +++ b/spec/ruby/library/cgi/queryextension/path_translated_spec.rb @@ -1,22 +1,25 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::QueryExtension#path_translated" do - before :each do - ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] - @cgi = CGI.new - end +ruby_version_is ""..."4.0" do + require 'cgi' - after :each do - ENV['REQUEST_METHOD'] = @old_request_method - end + describe "CGI::QueryExtension#path_translated" do + before :each do + ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] + @cgi = CGI.new + end + + after :each do + ENV['REQUEST_METHOD'] = @old_request_method + end - it "returns ENV['PATH_TRANSLATED']" do - old_value, ENV['PATH_TRANSLATED'] = ENV['PATH_TRANSLATED'], "/full/path/to/dir" - begin - @cgi.path_translated.should == "/full/path/to/dir" - ensure - ENV['PATH_TRANSLATED'] = old_value + it "returns ENV['PATH_TRANSLATED']" do + old_value, ENV['PATH_TRANSLATED'] = ENV['PATH_TRANSLATED'], "/full/path/to/dir" + begin + @cgi.path_translated.should == "/full/path/to/dir" + ensure + ENV['PATH_TRANSLATED'] = old_value + end end end end diff --git a/spec/ruby/library/cgi/queryextension/pragma_spec.rb b/spec/ruby/library/cgi/queryextension/pragma_spec.rb index 02d5c91221..be384182a5 100644 --- a/spec/ruby/library/cgi/queryextension/pragma_spec.rb +++ b/spec/ruby/library/cgi/queryextension/pragma_spec.rb @@ -1,22 +1,25 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::QueryExtension#pragma" do - before :each do - ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] - @cgi = CGI.new - end +ruby_version_is ""..."4.0" do + require 'cgi' - after :each do - ENV['REQUEST_METHOD'] = @old_request_method - end + describe "CGI::QueryExtension#pragma" do + before :each do + ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] + @cgi = CGI.new + end + + after :each do + ENV['REQUEST_METHOD'] = @old_request_method + end - it "returns ENV['HTTP_PRAGMA']" do - old_value, ENV['HTTP_PRAGMA'] = ENV['HTTP_PRAGMA'], "no-cache" - begin - @cgi.pragma.should == "no-cache" - ensure - ENV['HTTP_PRAGMA'] = old_value + it "returns ENV['HTTP_PRAGMA']" do + old_value, ENV['HTTP_PRAGMA'] = ENV['HTTP_PRAGMA'], "no-cache" + begin + @cgi.pragma.should == "no-cache" + ensure + ENV['HTTP_PRAGMA'] = old_value + end end end end diff --git a/spec/ruby/library/cgi/queryextension/query_string_spec.rb b/spec/ruby/library/cgi/queryextension/query_string_spec.rb index a6b454a7eb..64fbeaea10 100644 --- a/spec/ruby/library/cgi/queryextension/query_string_spec.rb +++ b/spec/ruby/library/cgi/queryextension/query_string_spec.rb @@ -1,22 +1,25 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::QueryExtension#query_string" do - before :each do - ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] - @cgi = CGI.new - end +ruby_version_is ""..."4.0" do + require 'cgi' - after :each do - ENV['REQUEST_METHOD'] = @old_request_method - end + describe "CGI::QueryExtension#query_string" do + before :each do + ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] + @cgi = CGI.new + end + + after :each do + ENV['REQUEST_METHOD'] = @old_request_method + end - it "returns ENV['QUERY_STRING']" do - old_value, ENV['QUERY_STRING'] = ENV['QUERY_STRING'], "one=a&two=b" - begin - @cgi.query_string.should == "one=a&two=b" - ensure - ENV['QUERY_STRING'] = old_value + it "returns ENV['QUERY_STRING']" do + old_value, ENV['QUERY_STRING'] = ENV['QUERY_STRING'], "one=a&two=b" + begin + @cgi.query_string.should == "one=a&two=b" + ensure + ENV['QUERY_STRING'] = old_value + end end end end diff --git a/spec/ruby/library/cgi/queryextension/raw_cookie2_spec.rb b/spec/ruby/library/cgi/queryextension/raw_cookie2_spec.rb index 3d7072e346..30d314aca1 100644 --- a/spec/ruby/library/cgi/queryextension/raw_cookie2_spec.rb +++ b/spec/ruby/library/cgi/queryextension/raw_cookie2_spec.rb @@ -1,22 +1,25 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::QueryExtension#raw_cookie2" do - before :each do - ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] - @cgi = CGI.new - end +ruby_version_is ""..."4.0" do + require 'cgi' - after :each do - ENV['REQUEST_METHOD'] = @old_request_method - end + describe "CGI::QueryExtension#raw_cookie2" do + before :each do + ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] + @cgi = CGI.new + end + + after :each do + ENV['REQUEST_METHOD'] = @old_request_method + end - it "returns ENV['HTTP_COOKIE2']" do - old_value, ENV['HTTP_COOKIE2'] = ENV['HTTP_COOKIE2'], "some_cookie=data" - begin - @cgi.raw_cookie2.should == "some_cookie=data" - ensure - ENV['HTTP_COOKIE2'] = old_value + it "returns ENV['HTTP_COOKIE2']" do + old_value, ENV['HTTP_COOKIE2'] = ENV['HTTP_COOKIE2'], "some_cookie=data" + begin + @cgi.raw_cookie2.should == "some_cookie=data" + ensure + ENV['HTTP_COOKIE2'] = old_value + end end end end diff --git a/spec/ruby/library/cgi/queryextension/raw_cookie_spec.rb b/spec/ruby/library/cgi/queryextension/raw_cookie_spec.rb index ede7b9ff87..affa504b39 100644 --- a/spec/ruby/library/cgi/queryextension/raw_cookie_spec.rb +++ b/spec/ruby/library/cgi/queryextension/raw_cookie_spec.rb @@ -1,22 +1,25 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::QueryExtension#raw_cookie" do - before :each do - ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] - @cgi = CGI.new - end +ruby_version_is ""..."4.0" do + require 'cgi' - after :each do - ENV['REQUEST_METHOD'] = @old_request_method - end + describe "CGI::QueryExtension#raw_cookie" do + before :each do + ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] + @cgi = CGI.new + end + + after :each do + ENV['REQUEST_METHOD'] = @old_request_method + end - it "returns ENV['HTTP_COOKIE']" do - old_value, ENV['HTTP_COOKIE'] = ENV['HTTP_COOKIE'], "some_cookie=data" - begin - @cgi.raw_cookie.should == "some_cookie=data" - ensure - ENV['HTTP_COOKIE'] = old_value + it "returns ENV['HTTP_COOKIE']" do + old_value, ENV['HTTP_COOKIE'] = ENV['HTTP_COOKIE'], "some_cookie=data" + begin + @cgi.raw_cookie.should == "some_cookie=data" + ensure + ENV['HTTP_COOKIE'] = old_value + end end end end diff --git a/spec/ruby/library/cgi/queryextension/referer_spec.rb b/spec/ruby/library/cgi/queryextension/referer_spec.rb index 6cd5dc96f8..53fc19ddd0 100644 --- a/spec/ruby/library/cgi/queryextension/referer_spec.rb +++ b/spec/ruby/library/cgi/queryextension/referer_spec.rb @@ -1,22 +1,25 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::QueryExtension#referer" do - before :each do - ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] - @cgi = CGI.new - end +ruby_version_is ""..."4.0" do + require 'cgi' - after :each do - ENV['REQUEST_METHOD'] = @old_request_method - end + describe "CGI::QueryExtension#referer" do + before :each do + ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] + @cgi = CGI.new + end + + after :each do + ENV['REQUEST_METHOD'] = @old_request_method + end - it "returns ENV['HTTP_REFERER']" do - old_value, ENV['HTTP_REFERER'] = ENV['HTTP_REFERER'], "example.com" - begin - @cgi.referer.should == "example.com" - ensure - ENV['HTTP_REFERER'] = old_value + it "returns ENV['HTTP_REFERER']" do + old_value, ENV['HTTP_REFERER'] = ENV['HTTP_REFERER'], "example.com" + begin + @cgi.referer.should == "example.com" + ensure + ENV['HTTP_REFERER'] = old_value + end end end end diff --git a/spec/ruby/library/cgi/queryextension/remote_addr_spec.rb b/spec/ruby/library/cgi/queryextension/remote_addr_spec.rb index 0259402b23..7b5addc2d5 100644 --- a/spec/ruby/library/cgi/queryextension/remote_addr_spec.rb +++ b/spec/ruby/library/cgi/queryextension/remote_addr_spec.rb @@ -1,22 +1,25 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::QueryExtension#remote_addr" do - before :each do - ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] - @cgi = CGI.new - end +ruby_version_is ""..."4.0" do + require 'cgi' - after :each do - ENV['REQUEST_METHOD'] = @old_request_method - end + describe "CGI::QueryExtension#remote_addr" do + before :each do + ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] + @cgi = CGI.new + end + + after :each do + ENV['REQUEST_METHOD'] = @old_request_method + end - it "returns ENV['REMOTE_ADDR']" do - old_value, ENV['REMOTE_ADDR'] = ENV['REMOTE_ADDR'], "127.0.0.1" - begin - @cgi.remote_addr.should == "127.0.0.1" - ensure - ENV['REMOTE_ADDR'] = old_value + it "returns ENV['REMOTE_ADDR']" do + old_value, ENV['REMOTE_ADDR'] = ENV['REMOTE_ADDR'], "127.0.0.1" + begin + @cgi.remote_addr.should == "127.0.0.1" + ensure + ENV['REMOTE_ADDR'] = old_value + end end end end diff --git a/spec/ruby/library/cgi/queryextension/remote_host_spec.rb b/spec/ruby/library/cgi/queryextension/remote_host_spec.rb index cf77e0031b..2dfe59ca38 100644 --- a/spec/ruby/library/cgi/queryextension/remote_host_spec.rb +++ b/spec/ruby/library/cgi/queryextension/remote_host_spec.rb @@ -1,22 +1,25 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::QueryExtension#remote_host" do - before :each do - ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] - @cgi = CGI.new - end +ruby_version_is ""..."4.0" do + require 'cgi' - after :each do - ENV['REQUEST_METHOD'] = @old_request_method - end + describe "CGI::QueryExtension#remote_host" do + before :each do + ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] + @cgi = CGI.new + end + + after :each do + ENV['REQUEST_METHOD'] = @old_request_method + end - it "returns ENV['REMOTE_HOST']" do - old_value, ENV['REMOTE_HOST'] = ENV['REMOTE_HOST'], "test.host" - begin - @cgi.remote_host.should == "test.host" - ensure - ENV['REMOTE_HOST'] = old_value + it "returns ENV['REMOTE_HOST']" do + old_value, ENV['REMOTE_HOST'] = ENV['REMOTE_HOST'], "test.host" + begin + @cgi.remote_host.should == "test.host" + ensure + ENV['REMOTE_HOST'] = old_value + end end end end diff --git a/spec/ruby/library/cgi/queryextension/remote_ident_spec.rb b/spec/ruby/library/cgi/queryextension/remote_ident_spec.rb index 5b51d6b8ee..bb05fc7942 100644 --- a/spec/ruby/library/cgi/queryextension/remote_ident_spec.rb +++ b/spec/ruby/library/cgi/queryextension/remote_ident_spec.rb @@ -1,22 +1,25 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::QueryExtension#remote_ident" do - before :each do - ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] - @cgi = CGI.new - end +ruby_version_is ""..."4.0" do + require 'cgi' - after :each do - ENV['REQUEST_METHOD'] = @old_request_method - end + describe "CGI::QueryExtension#remote_ident" do + before :each do + ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] + @cgi = CGI.new + end + + after :each do + ENV['REQUEST_METHOD'] = @old_request_method + end - it "returns ENV['REMOTE_IDENT']" do - old_value, ENV['REMOTE_IDENT'] = ENV['REMOTE_IDENT'], "no-idea-what-this-is-for" - begin - @cgi.remote_ident.should == "no-idea-what-this-is-for" - ensure - ENV['REMOTE_IDENT'] = old_value + it "returns ENV['REMOTE_IDENT']" do + old_value, ENV['REMOTE_IDENT'] = ENV['REMOTE_IDENT'], "no-idea-what-this-is-for" + begin + @cgi.remote_ident.should == "no-idea-what-this-is-for" + ensure + ENV['REMOTE_IDENT'] = old_value + end end end end diff --git a/spec/ruby/library/cgi/queryextension/remote_user_spec.rb b/spec/ruby/library/cgi/queryextension/remote_user_spec.rb index 1a93bb6561..29856302ab 100644 --- a/spec/ruby/library/cgi/queryextension/remote_user_spec.rb +++ b/spec/ruby/library/cgi/queryextension/remote_user_spec.rb @@ -1,22 +1,25 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::QueryExtension#remote_user" do - before :each do - ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] - @cgi = CGI.new - end +ruby_version_is ""..."4.0" do + require 'cgi' - after :each do - ENV['REQUEST_METHOD'] = @old_request_method - end + describe "CGI::QueryExtension#remote_user" do + before :each do + ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] + @cgi = CGI.new + end + + after :each do + ENV['REQUEST_METHOD'] = @old_request_method + end - it "returns ENV['REMOTE_USER']" do - old_value, ENV['REMOTE_USER'] = ENV['REMOTE_USER'], "username" - begin - @cgi.remote_user.should == "username" - ensure - ENV['REMOTE_USER'] = old_value + it "returns ENV['REMOTE_USER']" do + old_value, ENV['REMOTE_USER'] = ENV['REMOTE_USER'], "username" + begin + @cgi.remote_user.should == "username" + ensure + ENV['REMOTE_USER'] = old_value + end end end end diff --git a/spec/ruby/library/cgi/queryextension/request_method_spec.rb b/spec/ruby/library/cgi/queryextension/request_method_spec.rb index eabdd6998b..7331b134d2 100644 --- a/spec/ruby/library/cgi/queryextension/request_method_spec.rb +++ b/spec/ruby/library/cgi/queryextension/request_method_spec.rb @@ -1,22 +1,25 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::QueryExtension#request_method" do - before :each do - ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] - @cgi = CGI.new - end +ruby_version_is ""..."4.0" do + require 'cgi' - after :each do - ENV['REQUEST_METHOD'] = @old_request_method - end + describe "CGI::QueryExtension#request_method" do + before :each do + ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] + @cgi = CGI.new + end + + after :each do + ENV['REQUEST_METHOD'] = @old_request_method + end - it "returns ENV['REQUEST_METHOD']" do - old_value, ENV['REQUEST_METHOD'] = ENV['REQUEST_METHOD'], "GET" - begin - @cgi.request_method.should == "GET" - ensure - ENV['REQUEST_METHOD'] = old_value + it "returns ENV['REQUEST_METHOD']" do + old_value, ENV['REQUEST_METHOD'] = ENV['REQUEST_METHOD'], "GET" + begin + @cgi.request_method.should == "GET" + ensure + ENV['REQUEST_METHOD'] = old_value + end end end end diff --git a/spec/ruby/library/cgi/queryextension/script_name_spec.rb b/spec/ruby/library/cgi/queryextension/script_name_spec.rb index 341b7b6fea..4b359a545f 100644 --- a/spec/ruby/library/cgi/queryextension/script_name_spec.rb +++ b/spec/ruby/library/cgi/queryextension/script_name_spec.rb @@ -1,22 +1,25 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::QueryExtension#script_name" do - before :each do - ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] - @cgi = CGI.new - end +ruby_version_is ""..."4.0" do + require 'cgi' - after :each do - ENV['REQUEST_METHOD'] = @old_request_method - end + describe "CGI::QueryExtension#script_name" do + before :each do + ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] + @cgi = CGI.new + end + + after :each do + ENV['REQUEST_METHOD'] = @old_request_method + end - it "returns ENV['SCRIPT_NAME']" do - old_value, ENV['SCRIPT_NAME'] = ENV['SCRIPT_NAME'], "/path/to/script.rb" - begin - @cgi.script_name.should == "/path/to/script.rb" - ensure - ENV['SCRIPT_NAME'] = old_value + it "returns ENV['SCRIPT_NAME']" do + old_value, ENV['SCRIPT_NAME'] = ENV['SCRIPT_NAME'], "/path/to/script.rb" + begin + @cgi.script_name.should == "/path/to/script.rb" + ensure + ENV['SCRIPT_NAME'] = old_value + end end end end diff --git a/spec/ruby/library/cgi/queryextension/server_name_spec.rb b/spec/ruby/library/cgi/queryextension/server_name_spec.rb index b12aaf8c5c..c1f7fb4c54 100644 --- a/spec/ruby/library/cgi/queryextension/server_name_spec.rb +++ b/spec/ruby/library/cgi/queryextension/server_name_spec.rb @@ -1,22 +1,25 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::QueryExtension#server_name" do - before :each do - ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] - @cgi = CGI.new - end +ruby_version_is ""..."4.0" do + require 'cgi' - after :each do - ENV['REQUEST_METHOD'] = @old_request_method - end + describe "CGI::QueryExtension#server_name" do + before :each do + ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] + @cgi = CGI.new + end + + after :each do + ENV['REQUEST_METHOD'] = @old_request_method + end - it "returns ENV['SERVER_NAME']" do - old_value, ENV['SERVER_NAME'] = ENV['SERVER_NAME'], "localhost" - begin - @cgi.server_name.should == "localhost" - ensure - ENV['SERVER_NAME'] = old_value + it "returns ENV['SERVER_NAME']" do + old_value, ENV['SERVER_NAME'] = ENV['SERVER_NAME'], "localhost" + begin + @cgi.server_name.should == "localhost" + ensure + ENV['SERVER_NAME'] = old_value + end end end end diff --git a/spec/ruby/library/cgi/queryextension/server_port_spec.rb b/spec/ruby/library/cgi/queryextension/server_port_spec.rb index 0e688a99bf..60c03ea639 100644 --- a/spec/ruby/library/cgi/queryextension/server_port_spec.rb +++ b/spec/ruby/library/cgi/queryextension/server_port_spec.rb @@ -1,26 +1,29 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::QueryExtension#server_port" do - before :each do - ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] - @cgi = CGI.new - end +ruby_version_is ""..."4.0" do + require 'cgi' - after :each do - ENV['REQUEST_METHOD'] = @old_request_method - end + describe "CGI::QueryExtension#server_port" do + before :each do + ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] + @cgi = CGI.new + end + + after :each do + ENV['REQUEST_METHOD'] = @old_request_method + end - it "returns ENV['SERVER_PORT'] as Integer" do - old_value = ENV['SERVER_PORT'] - begin - ENV['SERVER_PORT'] = nil - @cgi.server_port.should be_nil + it "returns ENV['SERVER_PORT'] as Integer" do + old_value = ENV['SERVER_PORT'] + begin + ENV['SERVER_PORT'] = nil + @cgi.server_port.should be_nil - ENV['SERVER_PORT'] = "3000" - @cgi.server_port.should eql(3000) - ensure - ENV['SERVER_PORT'] = old_value + ENV['SERVER_PORT'] = "3000" + @cgi.server_port.should eql(3000) + ensure + ENV['SERVER_PORT'] = old_value + end end end end diff --git a/spec/ruby/library/cgi/queryextension/server_protocol_spec.rb b/spec/ruby/library/cgi/queryextension/server_protocol_spec.rb index f9dcf3c5b8..fdbcc2108f 100644 --- a/spec/ruby/library/cgi/queryextension/server_protocol_spec.rb +++ b/spec/ruby/library/cgi/queryextension/server_protocol_spec.rb @@ -1,22 +1,25 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::QueryExtension#server_protocol" do - before :each do - ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] - @cgi = CGI.new - end +ruby_version_is ""..."4.0" do + require 'cgi' - after :each do - ENV['REQUEST_METHOD'] = @old_request_method - end + describe "CGI::QueryExtension#server_protocol" do + before :each do + ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] + @cgi = CGI.new + end + + after :each do + ENV['REQUEST_METHOD'] = @old_request_method + end - it "returns ENV['SERVER_PROTOCOL']" do - old_value, ENV['SERVER_PROTOCOL'] = ENV['SERVER_PROTOCOL'], "HTTP/1.1" - begin - @cgi.server_protocol.should == "HTTP/1.1" - ensure - ENV['SERVER_PROTOCOL'] = old_value + it "returns ENV['SERVER_PROTOCOL']" do + old_value, ENV['SERVER_PROTOCOL'] = ENV['SERVER_PROTOCOL'], "HTTP/1.1" + begin + @cgi.server_protocol.should == "HTTP/1.1" + ensure + ENV['SERVER_PROTOCOL'] = old_value + end end end end diff --git a/spec/ruby/library/cgi/queryextension/server_software_spec.rb b/spec/ruby/library/cgi/queryextension/server_software_spec.rb index df349cdf2e..c5811a2268 100644 --- a/spec/ruby/library/cgi/queryextension/server_software_spec.rb +++ b/spec/ruby/library/cgi/queryextension/server_software_spec.rb @@ -1,22 +1,25 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::QueryExtension#server_software" do - before :each do - ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] - @cgi = CGI.new - end +ruby_version_is ""..."4.0" do + require 'cgi' - after :each do - ENV['REQUEST_METHOD'] = @old_request_method - end + describe "CGI::QueryExtension#server_software" do + before :each do + ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] + @cgi = CGI.new + end + + after :each do + ENV['REQUEST_METHOD'] = @old_request_method + end - it "returns ENV['SERVER_SOFTWARE']" do - old_value, ENV['SERVER_SOFTWARE'] = ENV['SERVER_SOFTWARE'], "Server/1.0.0" - begin - @cgi.server_software.should == "Server/1.0.0" - ensure - ENV['SERVER_SOFTWARE'] = old_value + it "returns ENV['SERVER_SOFTWARE']" do + old_value, ENV['SERVER_SOFTWARE'] = ENV['SERVER_SOFTWARE'], "Server/1.0.0" + begin + @cgi.server_software.should == "Server/1.0.0" + ensure + ENV['SERVER_SOFTWARE'] = old_value + end end end end diff --git a/spec/ruby/library/cgi/queryextension/user_agent_spec.rb b/spec/ruby/library/cgi/queryextension/user_agent_spec.rb index ec5ef187dd..3240352ef6 100644 --- a/spec/ruby/library/cgi/queryextension/user_agent_spec.rb +++ b/spec/ruby/library/cgi/queryextension/user_agent_spec.rb @@ -1,22 +1,25 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::QueryExtension#user_agent" do - before :each do - ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] - @cgi = CGI.new - end +ruby_version_is ""..."4.0" do + require 'cgi' - after :each do - ENV['REQUEST_METHOD'] = @old_request_method - end + describe "CGI::QueryExtension#user_agent" do + before :each do + ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD'] + @cgi = CGI.new + end + + after :each do + ENV['REQUEST_METHOD'] = @old_request_method + end - it "returns ENV['HTTP_USER_AGENT']" do - old_value, ENV['HTTP_USER_AGENT'] = ENV['HTTP_USER_AGENT'], "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_2; de-de) AppleWebKit/527+ (KHTML, like Gecko) Version/3.1 Safari/525.13" - begin - @cgi.user_agent.should == "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_2; de-de) AppleWebKit/527+ (KHTML, like Gecko) Version/3.1 Safari/525.13" - ensure - ENV['HTTP_USER_AGENT'] = old_value + it "returns ENV['HTTP_USER_AGENT']" do + old_value, ENV['HTTP_USER_AGENT'] = ENV['HTTP_USER_AGENT'], "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_2; de-de) AppleWebKit/527+ (KHTML, like Gecko) Version/3.1 Safari/525.13" + begin + @cgi.user_agent.should == "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_2; de-de) AppleWebKit/527+ (KHTML, like Gecko) Version/3.1 Safari/525.13" + ensure + ENV['HTTP_USER_AGENT'] = old_value + end end end end diff --git a/spec/ruby/library/cgi/rfc1123_date_spec.rb b/spec/ruby/library/cgi/rfc1123_date_spec.rb index 6904eeabaa..636185f22c 100644 --- a/spec/ruby/library/cgi/rfc1123_date_spec.rb +++ b/spec/ruby/library/cgi/rfc1123_date_spec.rb @@ -1,10 +1,13 @@ require_relative '../../spec_helper' -require 'cgi' -describe "CGI.rfc1123_date when passed Time" do - it "returns the passed Time formatted in RFC1123 ('Sat, 01 Dec 2007 15:56:42 GMT')" do - input = Time.at(1196524602) - expected = 'Sat, 01 Dec 2007 15:56:42 GMT' - CGI.rfc1123_date(input).should == expected +ruby_version_is ""..."4.0" do + require 'cgi' + + describe "CGI.rfc1123_date when passed Time" do + it "returns the passed Time formatted in RFC1123 ('Sat, 01 Dec 2007 15:56:42 GMT')" do + input = Time.at(1196524602) + expected = 'Sat, 01 Dec 2007 15:56:42 GMT' + CGI.rfc1123_date(input).should == expected + end end end diff --git a/spec/ruby/library/cgi/unescapeElement_spec.rb b/spec/ruby/library/cgi/unescapeElement_spec.rb index ae4d50b076..db83f0d2fb 100644 --- a/spec/ruby/library/cgi/unescapeElement_spec.rb +++ b/spec/ruby/library/cgi/unescapeElement_spec.rb @@ -1,5 +1,11 @@ require_relative '../../spec_helper' -require 'cgi' + +ruby_version_is ""..."4.0" do + require 'cgi' +end +ruby_version_is "4.0" do + require 'cgi/escape' +end describe "CGI.unescapeElement when passed String, elements, ..." do it "unescapes only the tags of the passed elements in the passed String" do diff --git a/spec/ruby/library/cgi/unescapeHTML_spec.rb b/spec/ruby/library/cgi/unescapeHTML_spec.rb index 84b30c6aa6..e43dcc83e5 100644 --- a/spec/ruby/library/cgi/unescapeHTML_spec.rb +++ b/spec/ruby/library/cgi/unescapeHTML_spec.rb @@ -1,5 +1,9 @@ require_relative '../../spec_helper' -require 'cgi' +begin + require 'cgi/escape' +rescue LoadError + require 'cgi' +end describe "CGI.unescapeHTML" do it "unescapes '& < > "' to '& < > \"'" do diff --git a/spec/ruby/library/cgi/unescapeURIComponent_spec.rb b/spec/ruby/library/cgi/unescapeURIComponent_spec.rb new file mode 100644 index 0000000000..f80eb1626b --- /dev/null +++ b/spec/ruby/library/cgi/unescapeURIComponent_spec.rb @@ -0,0 +1,128 @@ +require_relative '../../spec_helper' + +ruby_version_is ""..."4.0" do + require 'cgi' +end +ruby_version_is "4.0" do + require 'cgi/escape' +end + +describe "CGI.unescapeURIComponent" do + it "decodes any percent-encoded octets to their corresponding bytes according to RFC 3986" do + string = (0x00..0xff).map { |i| "%%%02x" % i }.join + expected = (0x00..0xff).map { |i| i.chr }.join.force_encoding(Encoding::UTF_8) + CGI.unescapeURIComponent(string).should == expected + end + + it "disregards case of characters in a percent-encoding triplet" do + CGI.unescapeURIComponent("%CE%B2abc").should == "βabc" + CGI.unescapeURIComponent("%ce%b2ABC").should == "βABC" + end + + it "leaves any non-percent-encoded characters as-is" do + string = "ABCDEFGHIJKLMNOPQRSTUVWXYZ:/?#[]@!$&'()*+,;=\t\x0D\xFFβᛉ▒90%" + decoded = CGI.unescapeURIComponent(string) + decoded.should == string + string.should_not.equal?(decoded) + end + + it "leaves sequences which can't be a percent-encoded octet as-is" do + string = "%AZ%B" + decoded = CGI.unescapeURIComponent(string) + decoded.should == string + string.should_not.equal?(decoded) + end + + it "creates a String with the specified target Encoding" do + string = CGI.unescapeURIComponent("%D2%3C%3CABC", Encoding::ISO_8859_1) + string.encoding.should == Encoding::ISO_8859_1 + string.should == "Ò<<ABC".encode("ISO-8859-1") + end + + it "accepts a string name of an Encoding" do + CGI.unescapeURIComponent("%D2%3C%3CABC", "ISO-8859-1").should == "Ò<<ABC".encode("ISO-8859-1") + end + + it "raises ArgumentError if specified encoding is unknown" do + -> { CGI.unescapeURIComponent("ABC", "ISO-JOKE-1") }.should raise_error(ArgumentError, "unknown encoding name - ISO-JOKE-1") + end + + ruby_version_is ""..."4.0" do + it "uses CGI.accept_charset as the default target encoding" do + original_charset = CGI.accept_charset + CGI.accept_charset = "ISO-8859-1" + decoded = CGI.unescapeURIComponent("%D2%3C%3CABC") + decoded.should == "Ò<<ABC".encode("ISO-8859-1") + decoded.encoding.should == Encoding::ISO_8859_1 + ensure + CGI.accept_charset = original_charset + end + + it "has CGI.accept_charset as UTF-8 by default" do + decoded = CGI.unescapeURIComponent("%CE%B2ABC") + decoded.should == "βABC" + decoded.encoding.should == Encoding::UTF_8 + end + end + + ruby_version_is "4.0" do + # "cgi/escape" does not have methods to access @@accept_charset. + # Full "cgi" gem provides them, allowing to possibly change it. + it "uses CGI's @@accept_charset as the default target encoding" do + original_charset = CGI.class_variable_get(:@@accept_charset) + CGI.class_variable_set(:@@accept_charset, "ISO-8859-1") + decoded = CGI.unescapeURIComponent("%D2%3C%3CABC") + decoded.should == "Ò<<ABC".encode("ISO-8859-1") + decoded.encoding.should == Encoding::ISO_8859_1 + ensure + CGI.class_variable_set(:@@accept_charset, original_charset) + end + + it "has CGI's @@accept_charset as UTF-8 by default" do + decoded = CGI.unescapeURIComponent("%CE%B2ABC") + decoded.should == "βABC" + decoded.encoding.should == Encoding::UTF_8 + end + end + + context "when source string specifies octets invalid in target encoding" do + it "uses source string's encoding" do + string = "%A2%A6%A3".encode(Encoding::SHIFT_JIS) + decoded = CGI.unescapeURIComponent(string, Encoding::US_ASCII) + decoded.encoding.should == Encoding::SHIFT_JIS + decoded.should == "「ヲ」".encode(Encoding::SHIFT_JIS) + decoded.valid_encoding?.should be_true + end + + it "uses source string's encoding even if it's also invalid" do + string = "%FF".encode(Encoding::US_ASCII) + decoded = CGI.unescapeURIComponent(string, Encoding::SHIFT_JIS) + decoded.encoding.should == Encoding::US_ASCII + decoded.should == "\xFF".dup.force_encoding(Encoding::US_ASCII) + decoded.valid_encoding?.should be_false + end + end + + it "decodes an empty string as an empty string with target encoding" do + string = "".encode(Encoding::BINARY) + decoded = CGI.unescapeURIComponent(string, "UTF-8") + decoded.should == "" + decoded.encoding.should == Encoding::UTF_8 + string.should_not.equal?(decoded) + end + + it "raises a TypeError with nil" do + -> { + CGI.unescapeURIComponent(nil) + }.should raise_error(TypeError, "no implicit conversion of nil into String") + end + + it "uses implicit type conversion to String" do + object = Object.new + def object.to_str + "a%20b" + end + + CGI.unescapeURIComponent(object).should == "a b" + end +end diff --git a/spec/ruby/library/cgi/unescape_spec.rb b/spec/ruby/library/cgi/unescape_spec.rb index c593e24b4a..aa731b9367 100644 --- a/spec/ruby/library/cgi/unescape_spec.rb +++ b/spec/ruby/library/cgi/unescape_spec.rb @@ -1,6 +1,12 @@ # -*- encoding: utf-8 -*- require_relative '../../spec_helper' -require 'cgi' + +ruby_version_is ""..."4.0" do + require 'cgi' +end +ruby_version_is "4.0" do + require 'cgi/escape' +end describe "CGI.unescape" do it "url-decodes the passed argument" do diff --git a/spec/ruby/library/coverage/fixtures/code_with_begin.rb b/spec/ruby/library/coverage/fixtures/code_with_begin.rb new file mode 100644 index 0000000000..9a6384e337 --- /dev/null +++ b/spec/ruby/library/coverage/fixtures/code_with_begin.rb @@ -0,0 +1,3 @@ +begin + 'coverage with begin' +end diff --git a/spec/ruby/library/coverage/result_spec.rb b/spec/ruby/library/coverage/result_spec.rb index 4bcce00cd7..0101eb6a64 100644 --- a/spec/ruby/library/coverage/result_spec.rb +++ b/spec/ruby/library/coverage/result_spec.rb @@ -6,12 +6,20 @@ describe 'Coverage.result' do @class_file = fixture __FILE__, 'some_class.rb' @config_file = fixture __FILE__, 'start_coverage.rb' @eval_code_file = fixture __FILE__, 'eval_code.rb' + @with_begin_file = fixture __FILE__, 'code_with_begin.rb' + end + + before :each do + Coverage.running?.should == false end after :each do $LOADED_FEATURES.delete(@class_file) $LOADED_FEATURES.delete(@config_file) $LOADED_FEATURES.delete(@eval_code_file) + $LOADED_FEATURES.delete(@with_begin_file) + + Coverage.result if Coverage.running? end it 'gives the covered files as a hash with arrays of count or nil' do @@ -26,6 +34,39 @@ describe 'Coverage.result' do } end + it 'returns results for each mode separately when enabled :all modes' do + Coverage.start(:all) + require @class_file.chomp('.rb') + result = Coverage.result + + result.should == { + @class_file => { + lines: [ + nil, nil, 1, nil, nil, 1, nil, nil, 0, nil, nil, nil, nil, nil, nil, nil + ], + branches: {}, + methods: { + [SomeClass, :some_method, 6, 2, 11, 5] => 0 + } + } + } + end + + it 'returns results for each mode separately when enabled any mode explicitly' do + Coverage.start(lines: true) + require @class_file.chomp('.rb') + result = Coverage.result + + result.should == { + @class_file => + { + lines: [ + nil, nil, 1, nil, nil, 1, nil, nil, 0, nil, nil, nil, nil, nil, nil, nil + ] + } + } + end + it 'no requires/loads should give empty hash' do Coverage.start result = Coverage.result @@ -65,77 +106,238 @@ describe 'Coverage.result' do result.should == {} end - ruby_version_is ''...'3.1' do - it 'second Coverage.start does nothing' do - Coverage.start - require @config_file.chomp('.rb') - result = Coverage.result + it 'does not include the file starting coverage since it is not tracked' do + require @config_file.chomp('.rb') + Coverage.result.should_not include(@config_file) + end + + it 'returns the correct results when eval coverage is enabled' do + Coverage.supported?(:eval).should == true + + Coverage.start(lines: true, eval: true) + require @eval_code_file.chomp('.rb') + result = Coverage.result - result.should == { @config_file => [1, 1, 1] } - end + result.should == { + @eval_code_file => { + lines: [1, nil, 1, nil, 1, 1, nil, nil, nil, nil, 1] + } + } end - ruby_version_is '3.1' do - it 'second Coverage.start give exception' do - Coverage.start - -> { - require @config_file.chomp('.rb') - }.should raise_error(RuntimeError, 'coverage measurement is already setup') - ensure - Coverage.result - end + it 'returns the correct results when eval coverage is disabled' do + Coverage.supported?(:eval).should == true + + Coverage.start(lines: true, eval: false) + require @eval_code_file.chomp('.rb') + result = Coverage.result + + result.should == { + @eval_code_file => { + lines: [1, nil, 1, nil, 1, nil, nil, nil, nil, nil, 1] + } + } end - it 'does not include the file starting coverage since it is not tracked' do - require @config_file.chomp('.rb') - Coverage.result.should_not include(@config_file) + it "disables coverage measurement when stop option is not specified" do + Coverage.start + require @class_file.chomp('.rb') + + Coverage.result + Coverage.running?.should == false end - ruby_version_is '3.1'...'3.2' do - it 'returns the correct results when eval is used' do - Coverage.start - require @eval_code_file.chomp('.rb') - result = Coverage.result + it "disables coverage measurement when stop: true option is specified" do + Coverage.start + require @class_file.chomp('.rb') - result.should == { - @eval_code_file => [ - 1, nil, 1, nil, 1, nil, nil, nil, nil, nil, 1 - ] - } - end + -> { + Coverage.result(stop: true) + }.should complain(/warning: stop implies clear/) + + Coverage.running?.should == false end - ruby_version_is '3.2' do - it 'indicates support for different features' do - Coverage.supported?(:lines).should == true - end + it "does not disable coverage measurement when stop: false option is specified" do + Coverage.start + require @class_file.chomp('.rb') - it 'returns the correct results when eval coverage is enabled' do - Coverage.supported?(:eval).should == true + Coverage.result(stop: false) + Coverage.running?.should == true + end - Coverage.start(lines: true, eval: true) - require @eval_code_file.chomp('.rb') - result = Coverage.result + it "does not disable coverage measurement when stop option is not specified but clear: true specified" do + Coverage.start + require @class_file.chomp('.rb') - result.should == { - @eval_code_file => { - lines: [1, nil, 1, nil, 1, 1, nil, nil, nil, nil, 1] - } - } - end + Coverage.result(clear: true) + Coverage.running?.should == true + end + + it "does not disable coverage measurement when stop option is not specified but clear: false specified" do + Coverage.start + require @class_file.chomp('.rb') - it 'returns the correct results when eval coverage is enabled' do - Coverage.supported?(:eval).should == true + Coverage.result(clear: false) + Coverage.running?.should == true + end - Coverage.start(lines: true, eval: false) - require @eval_code_file.chomp('.rb') - result = Coverage.result + it "disables coverage measurement when stop: true and clear: true specified" do + Coverage.start + require @class_file.chomp('.rb') - result.should == { - @eval_code_file => { - lines: [1, nil, 1, nil, 1, nil, nil, nil, nil, nil, 1] - } - } - end + Coverage.result(stop: true, clear: true) + Coverage.running?.should == false + end + + it "disables coverage measurement when stop: true and clear: false specified" do + Coverage.start + require @class_file.chomp('.rb') + + -> { + Coverage.result(stop: true, clear: false) + }.should complain(/warning: stop implies clear/) + + Coverage.running?.should == false + end + + it "does not disable coverage measurement when stop: false and clear: true specified" do + Coverage.start + require @class_file.chomp('.rb') + + Coverage.result(stop: false, clear: true) + Coverage.running?.should == true + end + + it "does not disable coverage measurement when stop: false and clear: false specified" do + Coverage.start + require @class_file.chomp('.rb') + + Coverage.result(stop: false, clear: false) + Coverage.running?.should == true + end + + it "resets counters (remove them) when stop: true specified but clear option is not specified" do + Coverage.start + require @class_file.chomp('.rb') + + -> { + Coverage.result(stop: true) # clears counters + }.should complain(/warning: stop implies clear/) + + Coverage.start + Coverage.peek_result.should == {} + end + + it "resets counters (remove them) when stop: true and clear: true specified" do + Coverage.start + require @class_file.chomp('.rb') + + Coverage.result(stop: true, clear: true) # clears counters + + Coverage.start + Coverage.peek_result.should == {} + end + + it "resets counters (remove them) when stop: true and clear: false specified" do + Coverage.start + require @class_file.chomp('.rb') + + -> { + Coverage.result(stop: true, clear: false) # clears counters + }.should complain(/warning: stop implies clear/) + + Coverage.start + Coverage.peek_result.should == {} + end + + it "resets counters (remove them) when both stop and clear options are not specified" do + Coverage.start + require @class_file.chomp('.rb') + + Coverage.result # clears counters + + Coverage.start + Coverage.peek_result.should == {} + end + + it "clears counters (sets 0 values) when stop is not specified but clear: true specified" do + Coverage.start + require @class_file.chomp('.rb') + + Coverage.result(clear: true) # clears counters + + Coverage.peek_result.should == { + @class_file => [ + nil, nil, 0, nil, nil, 0, nil, nil, 0, nil, nil, nil, nil, nil, nil, nil + ] + } + end + + it "does not clear counters when stop is not specified but clear: false specified" do + Coverage.start + require @class_file.chomp('.rb') + + result = Coverage.result(clear: false) # doesn't clear counters + result.should == { + @class_file => [ + nil, nil, 1, nil, nil, 1, nil, nil, 0, nil, nil, nil, nil, nil, nil, nil + ] + } + + Coverage.peek_result.should == result + end + + it "does not clear counters when stop: false and clear is not specified" do + Coverage.start + require @class_file.chomp('.rb') + + result = Coverage.result(stop: false) # doesn't clear counters + result.should == { + @class_file => [ + nil, nil, 1, nil, nil, 1, nil, nil, 0, nil, nil, nil, nil, nil, nil, nil + ] + } + + Coverage.peek_result.should == result + end + + it "clears counters (sets 0 values) when stop: false and clear: true specified" do + Coverage.start + require @class_file.chomp('.rb') + + Coverage.result(stop: false, clear: true) # clears counters + + Coverage.peek_result.should == { + @class_file => [ + nil, nil, 0, nil, nil, 0, nil, nil, 0, nil, nil, nil, nil, nil, nil, nil + ] + } + end + + it "does not clear counters when stop: false and clear: false specified" do + Coverage.start + require @class_file.chomp('.rb') + + result = Coverage.result(stop: false, clear: false) # doesn't clear counters + result.should == { + @class_file => [ + nil, nil, 1, nil, nil, 1, nil, nil, 0, nil, nil, nil, nil, nil, nil, nil + ] + } + + Coverage.peek_result.should == result + end + + it 'covers 100% lines with begin' do + Coverage.start + require @with_begin_file.chomp('.rb') + result = Coverage.result + + result.should == { + @with_begin_file => [ + nil, 1, nil + ] + } end end diff --git a/spec/ruby/library/coverage/start_spec.rb b/spec/ruby/library/coverage/start_spec.rb index a993abbf4e..c921b85401 100644 --- a/spec/ruby/library/coverage/start_spec.rb +++ b/spec/ruby/library/coverage/start_spec.rb @@ -2,11 +2,86 @@ require_relative '../../spec_helper' require 'coverage' describe 'Coverage.start' do - ruby_version_is '3.2' do - it "can measure coverage within eval" do - Coverage.start(lines: true, eval: true) - eval("Object.new\n"*3, binding, "test.rb", 1) - Coverage.result["test.rb"].should == {lines: [1, 1, 1]} - end + before :each do + Coverage.should_not.running? + end + + after :each do + Coverage.result(stop: true, clear: true) if Coverage.running? + end + + it "enables the coverage measurement" do + Coverage.start + Coverage.should.running? + end + + it "returns nil" do + Coverage.start.should == nil + end + + it 'raises error when repeated Coverage.start call happens' do + Coverage.start + + -> { + Coverage.start + }.should raise_error(RuntimeError, 'coverage measurement is already setup') + end + + it "accepts :all optional argument" do + Coverage.start(:all) + Coverage.should.running? + end + + it "accepts lines: optional keyword argument" do + Coverage.start(lines: true) + Coverage.should.running? + end + + it "accepts branches: optional keyword argument" do + Coverage.start(branches: true) + Coverage.should.running? + end + + it "accepts methods: optional keyword argument" do + Coverage.start(methods: true) + Coverage.should.running? + end + + it "accepts eval: optional keyword argument" do + Coverage.start(eval: true) + Coverage.should.running? + end + + it "accepts oneshot_lines: optional keyword argument" do + Coverage.start(oneshot_lines: true) + Coverage.should.running? + end + + it "ignores unknown keyword arguments" do + Coverage.start(foo: true) + Coverage.should.running? + end + + it "expects a Hash if not passed :all" do + -> { + Coverage.start(42) + }.should raise_error(TypeError, "no implicit conversion of Integer into Hash") + end + + it "does not accept both lines: and oneshot_lines: keyword arguments" do + -> { + Coverage.start(lines: true, oneshot_lines: true) + }.should raise_error(RuntimeError, "cannot enable lines and oneshot_lines simultaneously") + end + + it "enables the coverage measurement if passed options with `false` value" do + Coverage.start(lines: false, branches: false, methods: false, eval: false, oneshot_lines: false) + Coverage.should.running? + end + + it "measures coverage within eval" do + Coverage.start(lines: true, eval: true) + eval("Object.new\n"*3, binding, "test.rb", 1) + Coverage.result["test.rb"].should == {lines: [1, 1, 1]} end end diff --git a/spec/ruby/library/coverage/supported_spec.rb b/spec/ruby/library/coverage/supported_spec.rb new file mode 100644 index 0000000000..9226548c1f --- /dev/null +++ b/spec/ruby/library/coverage/supported_spec.rb @@ -0,0 +1,30 @@ +require_relative '../../spec_helper' +require 'coverage' + +describe "Coverage.supported?" do + it "returns true or false if coverage measurement is supported for the given mode" do + [true, false].should.include?(Coverage.supported?(:lines)) + [true, false].should.include?(Coverage.supported?(:branches)) + [true, false].should.include?(Coverage.supported?(:methods)) + [true, false].should.include?(Coverage.supported?(:eval)) + end + + it "returns false for not existing modes" do + Coverage.supported?(:foo).should == false + Coverage.supported?(:bar).should == false + end + + it "raise TypeError if argument is not Symbol" do + -> { + Coverage.supported?("lines") + }.should raise_error(TypeError, "wrong argument type String (expected Symbol)") + + -> { + Coverage.supported?([]) + }.should raise_error(TypeError, "wrong argument type Array (expected Symbol)") + + -> { + Coverage.supported?(1) + }.should raise_error(TypeError, "wrong argument type Integer (expected Symbol)") + end +end diff --git a/spec/ruby/library/csv/generate_spec.rb b/spec/ruby/library/csv/generate_spec.rb index 0a1e3d9604..b45e2eb95b 100644 --- a/spec/ruby/library/csv/generate_spec.rb +++ b/spec/ruby/library/csv/generate_spec.rb @@ -21,7 +21,7 @@ describe "CSV.generate" do end it "appends and returns the argument itself" do - str = "" + str = +"" csv_str = CSV.generate(str) do |csv| csv.add_row [1, 2, 3] csv << [4, 5, 6] diff --git a/spec/ruby/library/date/accessor_spec.rb b/spec/ruby/library/date/accessor_spec.rb index 68a2d9f3de..74ed0e9c21 100644 --- a/spec/ruby/library/date/accessor_spec.rb +++ b/spec/ruby/library/date/accessor_spec.rb @@ -38,7 +38,7 @@ describe "Date#year" do end describe "Date#yday" do - it "determines the year" do + it "determines the day of the year" do Date.civil(2007, 1, 17).yday.should == 17 Date.civil(2008, 10, 28).yday.should == 302 end diff --git a/spec/ruby/library/date/deconstruct_keys_spec.rb b/spec/ruby/library/date/deconstruct_keys_spec.rb new file mode 100644 index 0000000000..b9dd6b8816 --- /dev/null +++ b/spec/ruby/library/date/deconstruct_keys_spec.rb @@ -0,0 +1,42 @@ +require_relative '../../spec_helper' +require 'date' +date_version = defined?(Date::VERSION) ? Date::VERSION : '3.1.0' + +describe "Date#deconstruct_keys" do + it "returns whole hash for nil as an argument" do + d = Date.new(2022, 10, 5) + d.deconstruct_keys(nil).should == { year: 2022, month: 10, day: 5, yday: 278, wday: 3 } + end + + it "returns only specified keys" do + d = Date.new(2022, 10, 5) + d.deconstruct_keys([:year, :month]).should == { year: 2022, month: 10 } + end + + it "requires one argument" do + -> { + Date.new(2022, 10, 5).deconstruct_keys + }.should raise_error(ArgumentError) + end + + it "it raises error when argument is neither nil nor array" do + d = Date.new(2022, 10, 5) + + -> { d.deconstruct_keys(1) }.should raise_error(TypeError, "wrong argument type Integer (expected Array or nil)") + -> { d.deconstruct_keys("asd") }.should raise_error(TypeError, "wrong argument type String (expected Array or nil)") + -> { d.deconstruct_keys(:x) }.should raise_error(TypeError, "wrong argument type Symbol (expected Array or nil)") + -> { d.deconstruct_keys({}) }.should raise_error(TypeError, "wrong argument type Hash (expected Array or nil)") + end + + it "returns {} when passed []" do + Date.new(2022, 10, 5).deconstruct_keys([]).should == {} + end + + it "ignores non-Symbol keys" do + Date.new(2022, 10, 5).deconstruct_keys(['year', []]).should == {} + end + + it "ignores not existing Symbol keys" do + Date.new(2022, 10, 5).deconstruct_keys([:year, :a]).should == { year: 2022 } + end +end diff --git a/spec/ruby/library/date/iso8601_spec.rb b/spec/ruby/library/date/iso8601_spec.rb index a29652014e..af66845a6b 100644 --- a/spec/ruby/library/date/iso8601_spec.rb +++ b/spec/ruby/library/date/iso8601_spec.rb @@ -22,6 +22,18 @@ describe "Date.iso8601" do d.should == Date.civil(-4712, 1, 1) end + it "raises a Date::Error if the argument is a invalid Date" do + -> { + Date.iso8601('invalid') + }.should raise_error(Date::Error, "invalid date") + end + + it "raises a Date::Error when passed a nil" do + -> { + Date.iso8601(nil) + }.should raise_error(Date::Error, "invalid date") + end + it "raises a TypeError when passed an Object" do -> { Date.iso8601(Object.new) }.should raise_error(TypeError) end @@ -32,4 +44,13 @@ describe "Date._iso8601" do h = Date._iso8601('invalid') h.should == {} end + + it "returns an empty hash if the argument is nil" do + h = Date._iso8601(nil) + h.should == {} + end + + it "raises a TypeError when passed an Object" do + -> { Date._iso8601(Object.new) }.should raise_error(TypeError) + end end diff --git a/spec/ruby/library/date/mon_spec.rb b/spec/ruby/library/date/mon_spec.rb index 724e7d6564..616d72cf88 100644 --- a/spec/ruby/library/date/mon_spec.rb +++ b/spec/ruby/library/date/mon_spec.rb @@ -1,6 +1,7 @@ require_relative '../../spec_helper' +require_relative 'shared/month' require 'date' describe "Date#mon" do - it "needs to be reviewed for spec completeness" + it_behaves_like :date_month, :mon end diff --git a/spec/ruby/library/date/month_spec.rb b/spec/ruby/library/date/month_spec.rb index e040f9a94c..f493ec8119 100644 --- a/spec/ruby/library/date/month_spec.rb +++ b/spec/ruby/library/date/month_spec.rb @@ -1,9 +1,7 @@ require_relative '../../spec_helper' +require_relative 'shared/month' require 'date' describe "Date#month" do - it "returns the month" do - m = Date.new(2000, 7, 1).month - m.should == 7 - end + it_behaves_like :date_month, :month end diff --git a/spec/ruby/library/date/new_spec.rb b/spec/ruby/library/date/new_spec.rb index 18120118c0..cb64cabce6 100644 --- a/spec/ruby/library/date/new_spec.rb +++ b/spec/ruby/library/date/new_spec.rb @@ -1,7 +1,6 @@ require 'date' require_relative '../../spec_helper' require_relative 'shared/civil' -require_relative 'shared/new_bang' describe "Date.new" do it_behaves_like :date_civil, :new diff --git a/spec/ruby/library/date/parse_spec.rb b/spec/ruby/library/date/parse_spec.rb index bfbe86fbac..5ef4f6e9b5 100644 --- a/spec/ruby/library/date/parse_spec.rb +++ b/spec/ruby/library/date/parse_spec.rb @@ -93,7 +93,7 @@ describe "Date#parse with '.' separator" do @sep = '.' end - it_should_behave_like "date_parse" + it_should_behave_like :date_parse end describe "Date#parse with '/' separator" do @@ -101,7 +101,7 @@ describe "Date#parse with '/' separator" do @sep = '/' end - it_should_behave_like "date_parse" + it_should_behave_like :date_parse end describe "Date#parse with ' ' separator" do @@ -109,7 +109,7 @@ describe "Date#parse with ' ' separator" do @sep = ' ' end - it_should_behave_like "date_parse" + it_should_behave_like :date_parse end describe "Date#parse with '/' separator US-style" do @@ -117,7 +117,7 @@ describe "Date#parse with '/' separator US-style" do @sep = '/' end - it_should_behave_like "date_parse_us" + it_should_behave_like :date_parse_us end describe "Date#parse with '-' separator EU-style" do @@ -125,7 +125,7 @@ describe "Date#parse with '-' separator EU-style" do @sep = '-' end - it_should_behave_like "date_parse_eu" + it_should_behave_like :date_parse_eu end describe "Date#parse(.)" do diff --git a/spec/ruby/library/date/shared/month.rb b/spec/ruby/library/date/shared/month.rb new file mode 100644 index 0000000000..5fcb2cbeb0 --- /dev/null +++ b/spec/ruby/library/date/shared/month.rb @@ -0,0 +1,6 @@ +describe :date_month, shared: true do + it "returns the month" do + m = Date.new(2000, 7, 1).send(@method) + m.should == 7 + end +end diff --git a/spec/ruby/library/date/shared/new_bang.rb b/spec/ruby/library/date/shared/new_bang.rb deleted file mode 100644 index 90f1b432f0..0000000000 --- a/spec/ruby/library/date/shared/new_bang.rb +++ /dev/null @@ -1,14 +0,0 @@ -describe :date_new_bang, shared: true do - - it "returns a new Date object set to Astronomical Julian Day 0 if no arguments passed" do - d = Date.send(@method) - d.ajd.should == 0 - end - - it "accepts astronomical julian day number, offset as a fraction of a day and returns a new Date object" do - d = Date.send(@method, 10, 0.5) - d.ajd.should == 10 - d.jd.should == 11 - end - -end diff --git a/spec/ruby/library/date/shared/parse.rb b/spec/ruby/library/date/shared/parse.rb index 1015285e04..40af908386 100644 --- a/spec/ruby/library/date/shared/parse.rb +++ b/spec/ruby/library/date/shared/parse.rb @@ -13,7 +13,7 @@ describe :date_parse, shared: true do d.day.should == 23 end - it "can parse a 'mmm DD YYYY' string into a Date object" do + it "can parse a 'DD mmm YYYY' string into a Date object" do d = Date.parse("23#{@sep}feb#{@sep}2008") d.year.should == 2008 d.month.should == 2 @@ -42,7 +42,7 @@ describe :date_parse, shared: true do d.should == Date.civil(2005, 11, 5) end - it "can parse a year, day and month name into a Date object" do + it "can parse a day, month name and year into a Date object" do d = Date.parse("5th#{@sep}november#{@sep}2005") d.should == Date.civil(2005, 11, 5) end diff --git a/spec/ruby/library/date/shared/parse_eu.rb b/spec/ruby/library/date/shared/parse_eu.rb index ecb15e3c0e..3819524a57 100644 --- a/spec/ruby/library/date/shared/parse_eu.rb +++ b/spec/ruby/library/date/shared/parse_eu.rb @@ -7,28 +7,28 @@ describe :date_parse_eu, shared: true do d.day.should == 1 end - it "can parse a MM-DD-YYYY string into a Date object" do + it "can parse a DD-MM-YYYY string into a Date object" do d = Date.parse("10#{@sep}01#{@sep}2007") d.year.should == 2007 d.month.should == 1 d.day.should == 10 end - it "can parse a MM-DD-YY string into a Date object" do + it "can parse a YY-MM-DD string into a Date object" do d = Date.parse("10#{@sep}01#{@sep}07") d.year.should == 2010 d.month.should == 1 d.day.should == 7 end - it "can parse a MM-DD-YY string into a Date object NOT using the year digits as 20XX" do + it "can parse a YY-MM-DD string into a Date object NOT using the year digits as 20XX" do d = Date.parse("10#{@sep}01#{@sep}07", false) d.year.should == 10 d.month.should == 1 d.day.should == 7 end - it "can parse a MM-DD-YY string into a Date object using the year digits as 20XX" do + it "can parse a YY-MM-DD string into a Date object using the year digits as 20XX" do d = Date.parse("10#{@sep}01#{@sep}07", true) d.year.should == 2010 d.month.should == 1 diff --git a/spec/ruby/library/date/shared/parse_us.rb b/spec/ruby/library/date/shared/parse_us.rb index 7be62b1af1..17e2fc96c1 100644 --- a/spec/ruby/library/date/shared/parse_us.rb +++ b/spec/ruby/library/date/shared/parse_us.rb @@ -6,28 +6,28 @@ describe :date_parse_us, shared: true do d.day.should == 1 end - it "parses a MM#{@sep}DD#{@sep}YYYY string into a Date object" do + it "parses a DD#{@sep}MM#{@sep}YYYY string into a Date object" do d = Date.parse("10#{@sep}01#{@sep}2007") d.year.should == 2007 d.month.should == 1 d.day.should == 10 end - it "parses a MM#{@sep}DD#{@sep}YY string into a Date object" do + it "parses a YY#{@sep}MM#{@sep}DD string into a Date object" do d = Date.parse("10#{@sep}01#{@sep}07") d.year.should == 2010 d.month.should == 1 d.day.should == 7 end - it "parses a MM#{@sep}DD#{@sep}YY string into a Date object NOT using the year digits as 20XX" do + it "parses a YY#{@sep}MM#{@sep}DD string into a Date object NOT using the year digits as 20XX" do d = Date.parse("10#{@sep}01#{@sep}07", false) d.year.should == 10 d.month.should == 1 d.day.should == 7 end - it "parses a MM#{@sep}DD#{@sep}YY string into a Date object using the year digits as 20XX" do + it "parses a YY#{@sep}MM#{@sep}DD string into a Date object using the year digits as 20XX" do d = Date.parse("10#{@sep}01#{@sep}07", true) d.year.should == 2010 d.month.should == 1 diff --git a/spec/ruby/library/date/strftime_spec.rb b/spec/ruby/library/date/strftime_spec.rb index 33ecc4ce9d..1b93a8d1b2 100644 --- a/spec/ruby/library/date/strftime_spec.rb +++ b/spec/ruby/library/date/strftime_spec.rb @@ -1,6 +1,7 @@ require_relative "../../spec_helper" require 'date' require_relative '../../shared/time/strftime_for_date' +date_version = defined?(Date::VERSION) ? Date::VERSION : '3.1.0' describe "Date#strftime" do before :all do @@ -22,19 +23,9 @@ describe "Date#strftime" do @date.strftime("%Z").should == "+00:00" end - # %v is %e-%b-%Y for Date/DateTime - ruby_version_is ""..."3.1" do - it "should be able to show the commercial week" do - @date.strftime("%v").should == " 9-Apr-2000" - @date.strftime("%v").should == @date.strftime('%e-%b-%Y') - end - end - - ruby_version_is "3.1" do - it "should be able to show the commercial week" do - @date.strftime("%v").should == " 9-APR-2000" - @date.strftime("%v").should != @date.strftime('%e-%b-%Y') - end + it "should be able to show the commercial week" do + @date.strftime("%v").should == " 9-APR-2000" + @date.strftime("%v").should != @date.strftime('%e-%b-%Y') end # additional conversion specifiers only in Date/DateTime diff --git a/spec/ruby/library/time/to_date_spec.rb b/spec/ruby/library/date/time/to_date_spec.rb index baeafe0847..f9132da289 100644 --- a/spec/ruby/library/time/to_date_spec.rb +++ b/spec/ruby/library/date/time/to_date_spec.rb @@ -1,5 +1,5 @@ -require_relative '../../spec_helper' +require_relative '../../../spec_helper' require 'time' describe "Time#to_date" do diff --git a/spec/ruby/library/date/yday_spec.rb b/spec/ruby/library/date/yday_spec.rb index cfb174a4c2..7dd42e52a5 100644 --- a/spec/ruby/library/date/yday_spec.rb +++ b/spec/ruby/library/date/yday_spec.rb @@ -1,6 +1,7 @@ require_relative '../../spec_helper' +require_relative '../../shared/time/yday' require 'date' describe "Date#yday" do - it "needs to be reviewed for spec completeness" + it_behaves_like :time_yday, -> year, month, day { Date.new(year, month, day).yday } end diff --git a/spec/ruby/library/datetime/deconstruct_keys_spec.rb b/spec/ruby/library/datetime/deconstruct_keys_spec.rb new file mode 100644 index 0000000000..154c024a23 --- /dev/null +++ b/spec/ruby/library/datetime/deconstruct_keys_spec.rb @@ -0,0 +1,44 @@ +require_relative '../../spec_helper' +require 'date' +date_version = defined?(Date::VERSION) ? Date::VERSION : '3.1.0' + +describe "DateTime#deconstruct_keys" do + it "returns whole hash for nil as an argument" do + d = DateTime.new(2022, 10, 5, 13, 30) + res = { year: 2022, month: 10, day: 5, yday: 278, wday: 3, hour: 13, + min: 30, sec: 0, sec_fraction: (0/1), zone: "+00:00" } + d.deconstruct_keys(nil).should == res + end + + it "returns only specified keys" do + d = DateTime.new(2022, 10, 5, 13, 39) + d.deconstruct_keys([:zone, :hour]).should == { zone: "+00:00", hour: 13 } + end + + it "requires one argument" do + -> { + DateTime.new(2022, 10, 5, 13, 30).deconstruct_keys + }.should raise_error(ArgumentError) + end + + it "it raises error when argument is neither nil nor array" do + d = DateTime.new(2022, 10, 5, 13, 30) + + -> { d.deconstruct_keys(1) }.should raise_error(TypeError, "wrong argument type Integer (expected Array or nil)") + -> { d.deconstruct_keys("asd") }.should raise_error(TypeError, "wrong argument type String (expected Array or nil)") + -> { d.deconstruct_keys(:x) }.should raise_error(TypeError, "wrong argument type Symbol (expected Array or nil)") + -> { d.deconstruct_keys({}) }.should raise_error(TypeError, "wrong argument type Hash (expected Array or nil)") + end + + it "returns {} when passed []" do + DateTime.new(2022, 10, 5, 13, 30).deconstruct_keys([]).should == {} + end + + it "ignores non-Symbol keys" do + DateTime.new(2022, 10, 5, 13, 30).deconstruct_keys(['year', []]).should == {} + end + + it "ignores not existing Symbol keys" do + DateTime.new(2022, 10, 5, 13, 30).deconstruct_keys([:year, :a]).should == { year: 2022 } + end +end diff --git a/spec/ruby/library/datetime/rfc2822_spec.rb b/spec/ruby/library/datetime/rfc2822_spec.rb index 70bfca60b4..83f7fa8d5b 100644 --- a/spec/ruby/library/datetime/rfc2822_spec.rb +++ b/spec/ruby/library/datetime/rfc2822_spec.rb @@ -3,4 +3,8 @@ require 'date' describe "DateTime.rfc2822" do it "needs to be reviewed for spec completeness" + + it "raises DateError if passed nil" do + -> { DateTime.rfc2822(nil) }.should raise_error(Date::Error, "invalid date") + end end diff --git a/spec/ruby/library/datetime/strftime_spec.rb b/spec/ruby/library/datetime/strftime_spec.rb index 725bcafb0d..a07cc9c1aa 100644 --- a/spec/ruby/library/datetime/strftime_spec.rb +++ b/spec/ruby/library/datetime/strftime_spec.rb @@ -2,6 +2,7 @@ require_relative '../../spec_helper' require 'date' require_relative '../../shared/time/strftime_for_date' require_relative '../../shared/time/strftime_for_time' +date_version = defined?(Date::VERSION) ? Date::VERSION : '3.1.0' describe "DateTime#strftime" do before :all do @@ -32,19 +33,9 @@ describe "DateTime#strftime" do @time.strftime("%Z").should == "+00:00" end - # %v is %e-%b-%Y for Date/DateTime - ruby_version_is ""..."3.1" do - it "should be able to show the commercial week" do - @time.strftime("%v").should == " 3-Feb-2001" - @time.strftime("%v").should == @time.strftime('%e-%b-%Y') - end - end - - ruby_version_is "3.1" do - it "should be able to show the commercial week" do - @time.strftime("%v").should == " 3-FEB-2001" - @time.strftime("%v").should != @time.strftime('%e-%b-%Y') - end + it "should be able to show the commercial week" do + @time.strftime("%v").should == " 3-FEB-2001" + @time.strftime("%v").should != @time.strftime('%e-%b-%Y') end # additional conversion specifiers only in Date/DateTime diff --git a/spec/ruby/library/time/to_datetime_spec.rb b/spec/ruby/library/datetime/time/to_datetime_spec.rb index 6025950b59..5589725238 100644 --- a/spec/ruby/library/time/to_datetime_spec.rb +++ b/spec/ruby/library/datetime/time/to_datetime_spec.rb @@ -1,5 +1,7 @@ -require_relative '../../spec_helper' +require_relative '../../../spec_helper' require 'time' +require 'date' +date_version = defined?(Date::VERSION) ? Date::VERSION : '3.1.0' describe "Time#to_datetime" do it "returns a DateTime representing the same instant" do @@ -13,18 +15,15 @@ describe "Time#to_datetime" do datetime.sec.should == 59 end - date_version = defined?(Date::VERSION) ? Date::VERSION : '0.0.0' - version_is(date_version, '3.2.3') do - it "returns a DateTime representing the same instant before Gregorian" do - time = Time.utc(1582, 10, 14, 23, 58, 59) - datetime = time.to_datetime - datetime.year.should == 1582 - datetime.month.should == 10 - datetime.day.should == 4 - datetime.hour.should == 23 - datetime.min.should == 58 - datetime.sec.should == 59 - end + it "returns a DateTime representing the same instant before Gregorian" do + time = Time.utc(1582, 10, 14, 23, 58, 59) + datetime = time.to_datetime + datetime.year.should == 1582 + datetime.month.should == 10 + datetime.day.should == 4 + datetime.hour.should == 23 + datetime.min.should == 58 + datetime.sec.should == 59 end it "roundtrips" do diff --git a/spec/ruby/library/datetime/to_time_spec.rb b/spec/ruby/library/datetime/to_time_spec.rb index 95eca864da..58bb363653 100644 --- a/spec/ruby/library/datetime/to_time_spec.rb +++ b/spec/ruby/library/datetime/to_time_spec.rb @@ -1,5 +1,6 @@ require_relative '../../spec_helper' require 'date' +date_version = defined?(Date::VERSION) ? Date::VERSION : '3.1.0' describe "DateTime#to_time" do it "yields a new Time object" do @@ -18,18 +19,15 @@ describe "DateTime#to_time" do time.sec.should == 59 end - date_version = defined?(Date::VERSION) ? Date::VERSION : '0.0.0' - version_is(date_version, '3.2.3') do - it "returns a Time representing the same instant before Gregorian" do - datetime = DateTime.civil(1582, 10, 4, 23, 58, 59) - time = datetime.to_time.utc - time.year.should == 1582 - time.month.should == 10 - time.day.should == 14 - time.hour.should == 23 - time.min.should == 58 - time.sec.should == 59 - end + it "returns a Time representing the same instant before Gregorian" do + datetime = DateTime.civil(1582, 10, 4, 23, 58, 59) + time = datetime.to_time.utc + time.year.should == 1582 + time.month.should == 10 + time.day.should == 14 + time.hour.should == 23 + time.min.should == 58 + time.sec.should == 59 end it "preserves the same time regardless of local time or zone" do diff --git a/spec/ruby/library/datetime/yday_spec.rb b/spec/ruby/library/datetime/yday_spec.rb new file mode 100644 index 0000000000..08a72c6480 --- /dev/null +++ b/spec/ruby/library/datetime/yday_spec.rb @@ -0,0 +1,7 @@ +require_relative '../../spec_helper' +require_relative '../../shared/time/yday' +require 'date' + +describe "DateTime#yday" do + it_behaves_like :time_yday, -> year, month, day { DateTime.new(year, month, day).yday } +end diff --git a/spec/ruby/library/digest/instance/shared/update.rb b/spec/ruby/library/digest/instance/shared/update.rb index dccc8f80df..17779e54a4 100644 --- a/spec/ruby/library/digest/instance/shared/update.rb +++ b/spec/ruby/library/digest/instance/shared/update.rb @@ -3,6 +3,6 @@ describe :digest_instance_update, shared: true do c = Class.new do include Digest::Instance end - -> { c.new.update("test") }.should raise_error(RuntimeError) + -> { c.new.send(@method, "test") }.should raise_error(RuntimeError) end end diff --git a/spec/ruby/library/digest/md5/append_spec.rb b/spec/ruby/library/digest/md5/append_spec.rb index a7f841c883..0abdc074a1 100644 --- a/spec/ruby/library/digest/md5/append_spec.rb +++ b/spec/ruby/library/digest/md5/append_spec.rb @@ -3,5 +3,5 @@ require_relative 'shared/constants' require_relative 'shared/update' describe "Digest::MD5#<<" do - it_behaves_like :md5_update, :<< + it_behaves_like :md5_update, :<< end diff --git a/spec/ruby/library/digest/md5/shared/constants.rb b/spec/ruby/library/digest/md5/shared/constants.rb index e807b96f9f..664dd18e9c 100644 --- a/spec/ruby/library/digest/md5/shared/constants.rb +++ b/spec/ruby/library/digest/md5/shared/constants.rb @@ -1,4 +1,4 @@ -# -*- encoding: binary -*- +# encoding: binary require 'digest/md5' module MD5Constants diff --git a/spec/ruby/library/digest/md5/shared/sample.rb b/spec/ruby/library/digest/md5/shared/sample.rb deleted file mode 100644 index 2bb4f658b1..0000000000 --- a/spec/ruby/library/digest/md5/shared/sample.rb +++ /dev/null @@ -1,17 +0,0 @@ -# -*- encoding: binary -*- - -require 'digest/md5' - -module MD5Constants - - Contents = "Ipsum is simply dummy text of the printing and typesetting industry. \nLorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. \nIt has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. \nIt was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum." - - Klass = ::Digest::MD5 - BlockLength = 64 - DigestLength = 16 - BlankDigest = "\324\035\214\331\217\000\262\004\351\200\t\230\354\370B~" - Digest = "\2473\267qw\276\364\343\345\320\304\350\313\314\217n" - BlankHexdigest = "d41d8cd98f00b204e9800998ecf8427e" - Hexdigest = "a733b77177bef4e3e5d0c4e8cbcc8f6e" - -end diff --git a/spec/ruby/library/digest/sha1/shared/constants.rb b/spec/ruby/library/digest/sha1/shared/constants.rb index 169438747f..d77c05a968 100644 --- a/spec/ruby/library/digest/sha1/shared/constants.rb +++ b/spec/ruby/library/digest/sha1/shared/constants.rb @@ -1,4 +1,4 @@ -# -*- encoding: binary -*- +# encoding: binary require 'digest/sha1' diff --git a/spec/ruby/library/digest/sha256/append_spec.rb b/spec/ruby/library/digest/sha256/append_spec.rb index 9ca3496afc..ab594c105f 100644 --- a/spec/ruby/library/digest/sha256/append_spec.rb +++ b/spec/ruby/library/digest/sha256/append_spec.rb @@ -3,5 +3,5 @@ require_relative 'shared/constants' require_relative 'shared/update' describe "Digest::SHA256#<<" do - it_behaves_like :sha256_update, :<< + it_behaves_like :sha256_update, :<< end diff --git a/spec/ruby/library/digest/sha256/shared/constants.rb b/spec/ruby/library/digest/sha256/shared/constants.rb index 351679f344..afe8f11426 100644 --- a/spec/ruby/library/digest/sha256/shared/constants.rb +++ b/spec/ruby/library/digest/sha256/shared/constants.rb @@ -1,4 +1,4 @@ -# -*- encoding: binary -*- +# encoding: binary require 'digest/sha2' diff --git a/spec/ruby/library/digest/sha384/append_spec.rb b/spec/ruby/library/digest/sha384/append_spec.rb index 2bc0c5b90b..94c036cc3f 100644 --- a/spec/ruby/library/digest/sha384/append_spec.rb +++ b/spec/ruby/library/digest/sha384/append_spec.rb @@ -3,5 +3,5 @@ require_relative 'shared/constants' require_relative 'shared/update' describe "Digest::SHA384#<<" do - it_behaves_like :sha384_update, :<< + it_behaves_like :sha384_update, :<< end diff --git a/spec/ruby/library/digest/sha384/shared/constants.rb b/spec/ruby/library/digest/sha384/shared/constants.rb index 2050f03f2b..a78d571d26 100644 --- a/spec/ruby/library/digest/sha384/shared/constants.rb +++ b/spec/ruby/library/digest/sha384/shared/constants.rb @@ -1,4 +1,4 @@ -# -*- encoding: binary -*- +# encoding: binary require 'digest/sha2' diff --git a/spec/ruby/library/digest/sha512/append_spec.rb b/spec/ruby/library/digest/sha512/append_spec.rb index e5f84b56f4..9106e9685d 100644 --- a/spec/ruby/library/digest/sha512/append_spec.rb +++ b/spec/ruby/library/digest/sha512/append_spec.rb @@ -3,5 +3,5 @@ require_relative 'shared/constants' require_relative 'shared/update' describe "Digest::SHA512#<<" do - it_behaves_like :sha512_update, :<< + it_behaves_like :sha512_update, :<< end diff --git a/spec/ruby/library/digest/sha512/shared/constants.rb b/spec/ruby/library/digest/sha512/shared/constants.rb index 2765a1ec16..91787381ee 100644 --- a/spec/ruby/library/digest/sha512/shared/constants.rb +++ b/spec/ruby/library/digest/sha512/shared/constants.rb @@ -1,4 +1,4 @@ -# -*- encoding: binary -*- +# encoding: binary require 'digest/sha2' diff --git a/spec/ruby/library/drb/start_service_spec.rb b/spec/ruby/library/drb/start_service_spec.rb index 016c8b2cff..57a8cf6e15 100644 --- a/spec/ruby/library/drb/start_service_spec.rb +++ b/spec/ruby/library/drb/start_service_spec.rb @@ -1,28 +1,33 @@ require_relative '../../spec_helper' -require_relative 'fixtures/test_server' -require 'drb' -describe "DRb.start_service" do - before :each do - @server = DRb.start_service("druby://localhost:0", TestServer.new) - end +# This does not work yet when run in CRuby via make test-spec: +# Gem::MissingSpecError: Could not find 'ruby2_keywords' (>= 0) among 28 total gem(s) +guard_not -> { MSpecScript.instance_variable_defined?(:@testing_ruby) } do + require_relative 'fixtures/test_server' + require 'drb' - after :each do - DRb.stop_service if @server - end + describe "DRb.start_service" do + before :each do + @server = DRb.start_service("druby://localhost:0", TestServer.new) + end - it "runs a basic remote call" do - DRb.current_server.should == @server - obj = DRbObject.new(nil, @server.uri) - obj.add(1,2,3).should == 6 - end + after :each do + DRb.stop_service if @server + end + + it "runs a basic remote call" do + DRb.current_server.should == @server + obj = DRbObject.new(nil, @server.uri) + obj.add(1,2,3).should == 6 + end - it "runs a basic remote call passing a block" do - DRb.current_server.should == @server - obj = DRbObject.new(nil, @server.uri) - obj.add_yield(2) do |i| - i.should == 2 - i+1 - end.should == 4 + it "runs a basic remote call passing a block" do + DRb.current_server.should == @server + obj = DRbObject.new(nil, @server.uri) + obj.add_yield(2) do |i| + i.should == 2 + i+1 + end.should == 4 + end end end diff --git a/spec/ruby/library/erb/def_class_spec.rb b/spec/ruby/library/erb/def_class_spec.rb index 88bd385f4c..fb687531e0 100644 --- a/spec/ruby/library/erb/def_class_spec.rb +++ b/spec/ruby/library/erb/def_class_spec.rb @@ -24,6 +24,8 @@ END MyClass1ForErb = erb.def_class(MyClass1ForErb_, 'render()') MyClass1ForErb.method_defined?(:render).should == true MyClass1ForErb.new('foo', 123).render().should == expected + ensure + Object.send(:remove_const, :MyClass1ForErb) end end diff --git a/spec/ruby/library/erb/def_module_spec.rb b/spec/ruby/library/erb/def_module_spec.rb index 806e564ef0..5f67aeb2b9 100644 --- a/spec/ruby/library/erb/def_module_spec.rb +++ b/spec/ruby/library/erb/def_module_spec.rb @@ -22,6 +22,9 @@ END include MyModule2ForErb end MyClass2ForErb.new.render('foo', 123).should == expected + ensure + Object.send(:remove_const, :MyClass2ForErb) + Object.send(:remove_const, :MyModule2ForErb) end end diff --git a/spec/ruby/library/erb/defmethod/def_erb_method_spec.rb b/spec/ruby/library/erb/defmethod/def_erb_method_spec.rb index dc1e044d9c..1cd7582936 100644 --- a/spec/ruby/library/erb/defmethod/def_erb_method_spec.rb +++ b/spec/ruby/library/erb/defmethod/def_erb_method_spec.rb @@ -58,6 +58,8 @@ END end end MyClass4ForErb.new([10,20,30]).render().should == expected + ensure + Object.send(:remove_const, :MY_INPUT4_FOR_ERB) end diff --git a/spec/ruby/library/erb/new_spec.rb b/spec/ruby/library/erb/new_spec.rb index 4d7f7bf36a..f8192bff99 100644 --- a/spec/ruby/library/erb/new_spec.rb +++ b/spec/ruby/library/erb/new_spec.rb @@ -130,7 +130,7 @@ END <b><%#= item %></b> <%# end %> END - ERBSpecs.new_erb(input).result.should == "\n<b></b>\n\n" + ERBSpecs.new_erb(input).result.should == "\n<b></b>\n\n" ERBSpecs.new_erb(input, trim_mode: '<>').result.should == "<b></b>\n" end @@ -139,8 +139,8 @@ END ->{ ERB.new("<%= list %>").result }.should raise_error(NameError) end - describe "warning about arguments" do - ruby_version_is "3.1" do + version_is ERB.const_get(:VERSION, false), ""..."6.0.0" do + describe "warning about arguments" do it "warns when passed safe_level and later arguments" do -> { ERB.new(@eruby_str, nil, '%') diff --git a/spec/ruby/library/erb/run_spec.rb b/spec/ruby/library/erb/run_spec.rb index 8c07442d8f..602e53ab38 100644 --- a/spec/ruby/library/erb/run_spec.rb +++ b/spec/ruby/library/erb/run_spec.rb @@ -6,7 +6,7 @@ describe "ERB#run" do # lambda { ... }.should output def _steal_stdout orig = $stdout - s = '' + s = +'' def s.write(arg); self << arg.to_s; end $stdout = s begin diff --git a/spec/ruby/library/etc/uname_spec.rb b/spec/ruby/library/etc/uname_spec.rb new file mode 100644 index 0000000000..a42558f593 --- /dev/null +++ b/spec/ruby/library/etc/uname_spec.rb @@ -0,0 +1,14 @@ +require_relative '../../spec_helper' +require 'etc' + +describe "Etc.uname" do + it "returns a Hash with the documented keys" do + uname = Etc.uname + uname.should be_kind_of(Hash) + uname.should.key?(:sysname) + uname.should.key?(:nodename) + uname.should.key?(:release) + uname.should.key?(:version) + uname.should.key?(:machine) + end +end diff --git a/spec/ruby/library/fiber/alive_spec.rb b/spec/ruby/library/fiber/alive_spec.rb deleted file mode 100644 index 47149d5279..0000000000 --- a/spec/ruby/library/fiber/alive_spec.rb +++ /dev/null @@ -1,46 +0,0 @@ -require_relative '../../spec_helper' - -require 'fiber' - -describe "Fiber#alive?" do - it "returns true for a Fiber that hasn't had #resume called" do - fiber = Fiber.new { true } - fiber.alive?.should be_true - end - - # FIXME: Better description? - it "returns true for a Fiber that's yielded to the caller" do - fiber = Fiber.new { Fiber.yield } - fiber.resume - fiber.alive?.should be_true - end - - it "returns true when called from its Fiber" do - fiber = Fiber.new { fiber.alive?.should be_true } - fiber.resume - end - - it "doesn't invoke the block associated with the Fiber" do - offthehook = mock('do not call') - offthehook.should_not_receive(:ring) - fiber = Fiber.new { offthehook.ring } - fiber.alive? - end - - it "returns false for a Fiber that's dead" do - fiber = Fiber.new { true } - fiber.resume - -> { fiber.resume }.should raise_error(FiberError) - fiber.alive?.should be_false - end - - it "always returns false for a dead Fiber" do - fiber = Fiber.new { true } - fiber.resume - -> { fiber.resume }.should raise_error(FiberError) - fiber.alive?.should be_false - -> { fiber.resume }.should raise_error(FiberError) - fiber.alive?.should be_false - fiber.alive?.should be_false - end -end diff --git a/spec/ruby/library/fiber/current_spec.rb b/spec/ruby/library/fiber/current_spec.rb deleted file mode 100644 index e67d7d050a..0000000000 --- a/spec/ruby/library/fiber/current_spec.rb +++ /dev/null @@ -1,63 +0,0 @@ -require_relative '../../spec_helper' - -require 'fiber' - -describe "Fiber.current" do - it "returns the root Fiber when called outside of a Fiber" do - root = Fiber.current - root.should be_an_instance_of(Fiber) - # We can always transfer to the root Fiber; it will never die - 5.times do - root.transfer.should be_nil - root.alive?.should be_true - end - end - - it "returns the current Fiber when called from a Fiber" do - fiber = Fiber.new do - this = Fiber.current - this.should be_an_instance_of(Fiber) - this.should == fiber - this.alive?.should be_true - end - fiber.resume - end - - it "returns the current Fiber when called from a Fiber that transferred to another" do - states = [] - fiber = Fiber.new do - states << :fiber - this = Fiber.current - this.should be_an_instance_of(Fiber) - this.should == fiber - this.alive?.should be_true - end - - fiber2 = Fiber.new do - states << :fiber2 - fiber.transfer - flunk - end - - fiber3 = Fiber.new do - states << :fiber3 - fiber2.transfer - ruby_version_is '3.0' do - states << :fiber3_terminated - end - ruby_version_is '' ... '3.0' do - flunk - end - end - - fiber3.resume - - ruby_version_is "" ... "3.0" do - states.should == [:fiber3, :fiber2, :fiber] - end - - ruby_version_is "3.0" do - states.should == [:fiber3, :fiber2, :fiber, :fiber3_terminated] - end - end -end diff --git a/spec/ruby/library/fiber/resume_spec.rb b/spec/ruby/library/fiber/resume_spec.rb deleted file mode 100644 index 8b7c104a6f..0000000000 --- a/spec/ruby/library/fiber/resume_spec.rb +++ /dev/null @@ -1,35 +0,0 @@ -require_relative '../../spec_helper' - -require 'fiber' - -describe "Fiber#resume" do - ruby_version_is '' ... '3.0' do - it "raises a FiberError if the Fiber has transferred control to another Fiber" do - fiber1 = Fiber.new { true } - fiber2 = Fiber.new { fiber1.transfer; Fiber.yield } - fiber2.resume - -> { fiber2.resume }.should raise_error(FiberError) - end - - it "raises a FiberError if the Fiber attempts to resume a resuming fiber" do - root_fiber = Fiber.current - fiber1 = Fiber.new { root_fiber.resume } - -> { fiber1.resume }.should raise_error(FiberError, /double resume/) - end - end - - ruby_version_is '3.0' do - it "can work with Fiber#transfer" do - fiber1 = Fiber.new { true } - fiber2 = Fiber.new { fiber1.transfer; Fiber.yield 10 ; Fiber.yield 20; raise } - fiber2.resume.should == 10 - fiber2.resume.should == 20 - end - - it "raises a FiberError if the Fiber attempts to resume a resuming fiber" do - root_fiber = Fiber.current - fiber1 = Fiber.new { root_fiber.resume } - -> { fiber1.resume }.should raise_error(FiberError, /attempt to resume a resuming fiber/) - end - end -end diff --git a/spec/ruby/library/fiber/transfer_spec.rb b/spec/ruby/library/fiber/transfer_spec.rb deleted file mode 100644 index 7af548da1a..0000000000 --- a/spec/ruby/library/fiber/transfer_spec.rb +++ /dev/null @@ -1,128 +0,0 @@ -require_relative '../../spec_helper' -require_relative '../../shared/fiber/resume' - -require 'fiber' - -describe "Fiber#transfer" do - it_behaves_like :fiber_resume, :transfer -end - -describe "Fiber#transfer" do - it "transfers control from one Fiber to another when called from a Fiber" do - fiber1 = Fiber.new { :fiber1 } - fiber2 = Fiber.new { fiber1.transfer; :fiber2 } - - ruby_version_is '' ... '3.0' do - fiber2.resume.should == :fiber1 - end - ruby_version_is '3.0' do - fiber2.resume.should == :fiber2 - end - end - - it "returns to the root Fiber when finished" do - f1 = Fiber.new { :fiber_1 } - f2 = Fiber.new { f1.transfer; :fiber_2 } - - f2.transfer.should == :fiber_1 - f2.transfer.should == :fiber_2 - end - - it "can be invoked from the same Fiber it transfers control to" do - states = [] - fiber = Fiber.new { states << :start; fiber.transfer; states << :end } - fiber.transfer - states.should == [:start, :end] - - states = [] - fiber = Fiber.new { states << :start; fiber.transfer; states << :end } - fiber.resume - states.should == [:start, :end] - end - - ruby_version_is '' ... '3.0' do - it "can transfer control to a Fiber that has transferred to another Fiber" do - states = [] - fiber1 = Fiber.new { states << :fiber1 } - fiber2 = Fiber.new { states << :fiber2_start; fiber1.transfer; states << :fiber2_end} - fiber2.resume.should == [:fiber2_start, :fiber1] - fiber2.transfer.should == [:fiber2_start, :fiber1, :fiber2_end] - end - end - - ruby_version_is '3.0' do - it "can not transfer control to a Fiber that has suspended by Fiber.yield" do - states = [] - fiber1 = Fiber.new { states << :fiber1 } - fiber2 = Fiber.new { states << :fiber2_start; Fiber.yield fiber1.transfer; states << :fiber2_end} - fiber2.resume.should == [:fiber2_start, :fiber1] - -> { fiber2.transfer }.should raise_error(FiberError) - end - end - - it "raises a FiberError when transferring to a Fiber which resumes itself" do - fiber = Fiber.new { fiber.resume } - -> { fiber.transfer }.should raise_error(FiberError) - end - - it "works if Fibers in different Threads each transfer to a Fiber in the same Thread" do - # This catches a bug where Fibers are running on a thread-pool - # and Fibers from a different Ruby Thread reuse the same native thread. - # Caching the Ruby Thread based on the native thread is not correct in that case, - # and the check for "fiber called across threads" in Fiber#transfer - # might be incorrect based on that. - 2.times do - Thread.new do - io_fiber = Fiber.new do |calling_fiber| - calling_fiber.transfer - end - io_fiber.transfer(Fiber.current) - value = Object.new - io_fiber.transfer(value).should equal value - end.join - end - end - - it "transfers control between a non-main thread's root fiber to a child fiber and back again" do - states = [] - thread = Thread.new do - f1 = Fiber.new do |f0| - states << 0 - value2 = f0.transfer(1) - states << value2 - 3 - end - - value1 = f1.transfer(Fiber.current) - states << value1 - value3 = f1.transfer(2) - states << value3 - end - thread.join - states.should == [0, 1, 2, 3] - end - - ruby_version_is "" ... "3.0" do - it "runs until Fiber.yield" do - obj = mock('obj') - obj.should_not_receive(:do) - fiber = Fiber.new { 1 + 2; Fiber.yield; obj.do } - fiber.transfer - end - - it "resumes from the last call to Fiber.yield on subsequent invocations" do - fiber = Fiber.new { Fiber.yield :first; :second } - fiber.transfer.should == :first - fiber.transfer.should == :second - end - - it "sets the block parameters to its arguments on the first invocation" do - first = mock('first') - first.should_receive(:arg).with(:first).twice - - fiber = Fiber.new { |arg| first.arg arg; Fiber.yield; first.arg arg; } - fiber.transfer :first - fiber.transfer :second - end - end -end diff --git a/spec/ruby/library/find/fixtures/common.rb b/spec/ruby/library/find/fixtures/common.rb index 14a7edb09a..99f3bbb45a 100644 --- a/spec/ruby/library/find/fixtures/common.rb +++ b/spec/ruby/library/find/fixtures/common.rb @@ -71,13 +71,17 @@ module FindDirSpecs end def self.create_mock_dirs + tmp('') # make sure there is an tmpdir umask = File.umask 0 - mock_dir_files.each do |name| - file = File.join mock_dir, name - mkdir_p File.dirname(file) - touch file + begin + mock_dir_files.each do |name| + file = File.join mock_dir, name + mkdir_p File.dirname(file) + touch file + end + ensure + File.umask umask end - File.umask umask end def self.delete_mock_dirs diff --git a/spec/ruby/library/io-wait/wait_readable_spec.rb b/spec/ruby/library/io-wait/wait_readable_spec.rb index 06ffbda5c8..d7473f029f 100644 --- a/spec/ruby/library/io-wait/wait_readable_spec.rb +++ b/spec/ruby/library/io-wait/wait_readable_spec.rb @@ -1,9 +1,5 @@ require_relative '../../spec_helper' -ruby_version_is ''...'3.2' do - require 'io/wait' -end - describe "IO#wait_readable" do before :each do @io = File.new(__FILE__ ) @@ -24,4 +20,23 @@ describe "IO#wait_readable" do it "waits for the IO to become readable with the given large timeout" do @io.wait_readable(365 * 24 * 60 * 60).should == @io end + + it "can be interrupted" do + rd, wr = IO.pipe + start = Process.clock_gettime(Process::CLOCK_MONOTONIC) + + t = Thread.new do + rd.wait_readable(10) + end + + Thread.pass until t.stop? + t.kill + t.join + + finish = Process.clock_gettime(Process::CLOCK_MONOTONIC) + (finish - start).should < 9 + ensure + rd.close + wr.close + end end diff --git a/spec/ruby/library/io-wait/wait_spec.rb b/spec/ruby/library/io-wait/wait_spec.rb new file mode 100644 index 0000000000..6a3890a401 --- /dev/null +++ b/spec/ruby/library/io-wait/wait_spec.rb @@ -0,0 +1,162 @@ +require_relative '../../spec_helper' +require_relative '../../fixtures/io' + +describe "IO#wait" do + before :each do + @io = File.new(__FILE__ ) + + if /mswin|mingw/ =~ RUBY_PLATFORM + require 'socket' + @r, @w = Socket.pair(Socket::AF_INET, Socket::SOCK_STREAM, 0) + else + @r, @w = IO.pipe + end + end + + after :each do + @io.close unless @io.closed? + + @r.close unless @r.closed? + @w.close unless @w.closed? + end + + context "[events, timeout] passed" do + it "returns events mask when the READABLE event is ready during the timeout" do + @w.write('data to read') + @r.wait(IO::READABLE, 2).should == IO::READABLE + end + + it "returns events mask when the WRITABLE event is ready during the timeout" do + @w.wait(IO::WRITABLE, 0).should == IO::WRITABLE + end + + it "waits for the READABLE event to be ready" do + @r.wait(IO::READABLE, 0).should == nil + + @w.write('data to read') + @r.wait(IO::READABLE, 0).should_not == nil + end + + it "waits for the WRITABLE event to be ready" do + written_bytes = IOSpec.exhaust_write_buffer(@w) + @w.wait(IO::WRITABLE, 0).should == nil + + @r.read(written_bytes) + @w.wait(IO::WRITABLE, 0).should_not == nil + end + + it "returns nil when the READABLE event is not ready during the timeout" do + @w.wait(IO::READABLE, 0).should == nil + end + + it "returns nil when the WRITABLE event is not ready during the timeout" do + IOSpec.exhaust_write_buffer(@w) + @w.wait(IO::WRITABLE, 0).should == nil + end + + it "raises IOError when io is closed (closed stream (IOError))" do + @io.close + -> { @io.wait(IO::READABLE, 0) }.should raise_error(IOError, "closed stream") + end + + it "raises ArgumentError when events is not positive" do + -> { @w.wait(0, 0) }.should raise_error(ArgumentError, "Events must be positive integer!") + -> { @w.wait(-1, 0) }.should raise_error(ArgumentError, "Events must be positive integer!") + end + + it "changes thread status to 'sleep' when waits for READABLE event" do + t = Thread.new { @r.wait(IO::READABLE, 10) } + sleep 1 + t.status.should == 'sleep' + t.kill + t.join # Thread#kill doesn't wait for the thread to end + end + + # https://github.com/ruby/ruby/actions/runs/11948300522/job/33305664284?pr=12139 + platform_is_not :windows do + it "changes thread status to 'sleep' when waits for WRITABLE event" do + IOSpec.exhaust_write_buffer(@w) + + t = Thread.new { @w.wait(IO::WRITABLE, 10) } + sleep 1 + t.status.should == 'sleep' + t.kill + t.join # Thread#kill doesn't wait for the thread to end + end + end + + it "can be interrupted when waiting for READABLE event" do + start = Process.clock_gettime(Process::CLOCK_MONOTONIC) + + t = Thread.new do + @r.wait(IO::READABLE, 10) + end + + Thread.pass until t.stop? + t.kill + t.join # Thread#kill doesn't wait for the thread to end + + finish = Process.clock_gettime(Process::CLOCK_MONOTONIC) + (finish - start).should < 9 + end + + it "can be interrupted when waiting for WRITABLE event" do + IOSpec.exhaust_write_buffer(@w) + start = Process.clock_gettime(Process::CLOCK_MONOTONIC) + + t = Thread.new do + @w.wait(IO::WRITABLE, 10) + end + + Thread.pass until t.stop? + t.kill + t.join # Thread#kill doesn't wait for the thread to end + + finish = Process.clock_gettime(Process::CLOCK_MONOTONIC) + (finish - start).should < 9 + end + end + + context "[timeout, mode] passed" do + it "accepts :r, :read, :readable mode to check READABLE event" do + @io.wait(0, :r).should == @io + @io.wait(0, :read).should == @io + @io.wait(0, :readable).should == @io + end + + it "accepts :w, :write, :writable mode to check WRITABLE event" do + @io.wait(0, :w).should == @io + @io.wait(0, :write).should == @io + @io.wait(0, :writable).should == @io + end + + it "accepts :rw, :read_write, :readable_writable mode to check READABLE and WRITABLE events" do + @io.wait(0, :rw).should == @io + @io.wait(0, :read_write).should == @io + @io.wait(0, :readable_writable).should == @io + end + + it "accepts a list of modes" do + @io.wait(0, :r, :w, :rw).should == @io + end + + it "accepts timeout and mode in any order" do + @io.wait(0, :r).should == @io + @io.wait(:r, 0).should == @io + @io.wait(:r, 0, :w).should == @io + end + + it "raises ArgumentError when passed wrong Symbol value as mode argument" do + -> { @io.wait(0, :wrong) }.should raise_error(ArgumentError, "unsupported mode: wrong") + end + + it "raises ArgumentError when several Integer arguments passed" do + -> { @w.wait(0, 10, :r) }.should raise_error(ArgumentError, "timeout given more than once") + end + + it "raises IOError when io is closed (closed stream (IOError))" do + @io.close + -> { @io.wait(0, :r) }.should raise_error(IOError, "closed stream") + end + end +end diff --git a/spec/ruby/library/io-wait/wait_writable_spec.rb b/spec/ruby/library/io-wait/wait_writable_spec.rb index 8c44780d39..2017817caa 100644 --- a/spec/ruby/library/io-wait/wait_writable_spec.rb +++ b/spec/ruby/library/io-wait/wait_writable_spec.rb @@ -1,8 +1,5 @@ require_relative '../../spec_helper' - -ruby_version_is ''...'3.2' do - require 'io/wait' -end +require_relative '../../fixtures/io' describe "IO#wait_writable" do it "waits for the IO to become writable with no timeout" do @@ -17,4 +14,24 @@ describe "IO#wait_writable" do # Represents one year and is larger than a 32-bit int STDOUT.wait_writable(365 * 24 * 60 * 60).should == STDOUT end + + it "can be interrupted" do + rd, wr = IO.pipe + IOSpec.exhaust_write_buffer(wr) + start = Process.clock_gettime(Process::CLOCK_MONOTONIC) + + t = Thread.new do + wr.wait_writable(10) + end + + Thread.pass until t.stop? + t.kill + t.join + + finish = Process.clock_gettime(Process::CLOCK_MONOTONIC) + (finish - start).should < 9 + ensure + rd.close unless rd.closed? + wr.close unless wr.closed? + end end diff --git a/spec/ruby/library/ipaddr/new_spec.rb b/spec/ruby/library/ipaddr/new_spec.rb index 053928c3cf..2c0f44acf2 100644 --- a/spec/ruby/library/ipaddr/new_spec.rb +++ b/spec/ruby/library/ipaddr/new_spec.rb @@ -77,34 +77,16 @@ describe "IPAddr#new" do a.family.should == Socket::AF_INET6 end - ruby_version_is ""..."3.1" do - it "raises on incorrect IPAddr strings" do - [ - ["fe80::1%fxp0"], - ["::1/255.255.255.0"], - [IPAddr.new("::1").to_i], - ["::ffff:192.168.1.2/120", Socket::AF_INET], - ["[192.168.1.2]/120"], - ].each { |args| - ->{ - IPAddr.new(*args) - }.should raise_error(ArgumentError) - } - end - end - - ruby_version_is "3.1" do - it "raises on incorrect IPAddr strings" do - [ - ["::1/255.255.255.0"], - [IPAddr.new("::1").to_i], - ["::ffff:192.168.1.2/120", Socket::AF_INET], - ["[192.168.1.2]/120"], - ].each { |args| - ->{ - IPAddr.new(*args) - }.should raise_error(ArgumentError) - } - end + it "raises on incorrect IPAddr strings" do + [ + ["::1/255.255.255.0"], + [IPAddr.new("::1").to_i], + ["::ffff:192.168.1.2/120", Socket::AF_INET], + ["[192.168.1.2]/120"], + ].each { |args| + ->{ + IPAddr.new(*args) + }.should raise_error(ArgumentError) + } end end diff --git a/spec/ruby/library/irb/fixtures/irb.rb b/spec/ruby/library/irb/fixtures/irb.rb new file mode 100644 index 0000000000..8d386dfda1 --- /dev/null +++ b/spec/ruby/library/irb/fixtures/irb.rb @@ -0,0 +1,3 @@ +a = 10 + +binding.irb # rubocop:disable Lint/Debugger diff --git a/spec/ruby/library/irb/irb_spec.rb b/spec/ruby/library/irb/irb_spec.rb new file mode 100644 index 0000000000..2607c7ef33 --- /dev/null +++ b/spec/ruby/library/irb/irb_spec.rb @@ -0,0 +1,19 @@ +require_relative '../../spec_helper' +require 'tmpdir' + +describe "Binding#irb" do + it "creates an IRB session with the binding in scope" do + irb_fixture = fixture __FILE__, "irb.rb" + envs = %w[IRBRC HOME XDG_CONFIG_HOME].to_h {|e| [e, nil]} + + out = Dir.mktmpdir do |dir| + IO.popen([envs, *ruby_exe, irb_fixture, chdir: dir], "r+") do |pipe| + pipe.puts "a ** 2" + pipe.puts "exit" + pipe.readlines.map(&:chomp).reject(&:empty?) + end + end + + out.last(3).should == ["a ** 2", "100", "exit"] + end +end diff --git a/spec/ruby/library/logger/device/close_spec.rb b/spec/ruby/library/logger/device/close_spec.rb index 7c5e118d56..1db5d582a7 100644 --- a/spec/ruby/library/logger/device/close_spec.rb +++ b/spec/ruby/library/logger/device/close_spec.rb @@ -15,17 +15,8 @@ describe "Logger::LogDevice#close" do rm_r @file_path end - version_is Logger::VERSION, ""..."1.4.0" do - it "closes the LogDevice's stream" do - @device.close - -> { @device.write("Test") }.should complain(/\Alog writing failed\./) - end - end - - version_is Logger::VERSION, "1.4.0" do - it "closes the LogDevice's stream" do - @device.close - -> { @device.write("Test") }.should complain(/\Alog shifting failed\./) - end + it "closes the LogDevice's stream" do + @device.close + -> { @device.write("Test") }.should complain(/\Alog shifting failed\./) end end diff --git a/spec/ruby/library/logger/device/write_spec.rb b/spec/ruby/library/logger/device/write_spec.rb index cd2d7e27a9..87ecf2ad6a 100644 --- a/spec/ruby/library/logger/device/write_spec.rb +++ b/spec/ruby/library/logger/device/write_spec.rb @@ -35,17 +35,8 @@ describe "Logger::LogDevice#write" do rm_r path end - version_is Logger::VERSION, ""..."1.4.0" do - it "fails if the device is already closed" do - @device.close - -> { @device.write "foo" }.should complain(/\Alog writing failed\./) - end - end - - version_is Logger::VERSION, "1.4.0" do - it "fails if the device is already closed" do - @device.close - -> { @device.write "foo" }.should complain(/\Alog shifting failed\./) - end + it "fails if the device is already closed" do + @device.close + -> { @device.write "foo" }.should complain(/\Alog shifting failed\./) end end diff --git a/spec/ruby/library/logger/logger/new_spec.rb b/spec/ruby/library/logger/logger/new_spec.rb index d3100ee2d1..3db20e7432 100644 --- a/spec/ruby/library/logger/logger/new_spec.rb +++ b/spec/ruby/library/logger/logger/new_spec.rb @@ -13,24 +13,24 @@ describe "Logger#new" do rm_r @file_path end - it "creates a new logger object" do - l = Logger.new(STDERR) - -> { l.add(Logger::WARN, "Foo") }.should output_to_fd(/Foo/, STDERR) - end + it "creates a new logger object" do + l = Logger.new(STDERR) + -> { l.add(Logger::WARN, "Foo") }.should output_to_fd(/Foo/, STDERR) + end - it "receives a logging device as first argument" do - l = Logger.new(@log_file) - l.add(Logger::WARN, "Test message") + it "receives a logging device as first argument" do + l = Logger.new(@log_file) + l.add(Logger::WARN, "Test message") - @log_file.rewind - LoggerSpecs.strip_date(@log_file.readline).should == "WARN -- : Test message\n" - l.close - end + @log_file.rewind + LoggerSpecs.strip_date(@log_file.readline).should == "WARN -- : Test message\n" + l.close + end it "receives a frequency rotation as second argument" do - -> { Logger.new(@log_file, "daily") }.should_not raise_error - -> { Logger.new(@log_file, "weekly") }.should_not raise_error - -> { Logger.new(@log_file, "monthly") }.should_not raise_error + -> { Logger.new(@log_file, "daily") }.should_not raise_error + -> { Logger.new(@log_file, "weekly") }.should_not raise_error + -> { Logger.new(@log_file, "monthly") }.should_not raise_error end it "also receives a number of log files to keep as second argument" do diff --git a/spec/ruby/library/matrix/I_spec.rb b/spec/ruby/library/matrix/I_spec.rb index aa064ed54b..6eeffe8e98 100644 --- a/spec/ruby/library/matrix/I_spec.rb +++ b/spec/ruby/library/matrix/I_spec.rb @@ -1,9 +1,6 @@ require_relative '../../spec_helper' +require_relative 'shared/identity' -ruby_version_is ""..."3.1" do - require_relative 'shared/identity' - - describe "Matrix.I" do - it_behaves_like :matrix_identity, :I - end +describe "Matrix.I" do + it_behaves_like :matrix_identity, :I end diff --git a/spec/ruby/library/matrix/antisymmetric_spec.rb b/spec/ruby/library/matrix/antisymmetric_spec.rb index dcc3c30f3e..200df703cb 100644 --- a/spec/ruby/library/matrix/antisymmetric_spec.rb +++ b/spec/ruby/library/matrix/antisymmetric_spec.rb @@ -1,38 +1,36 @@ require_relative '../../spec_helper' -ruby_version_is ""..."3.1" do - require 'matrix' +require 'matrix' - describe "Matrix#antisymmetric?" do - it "returns true for an antisymmetric Matrix" do - Matrix[[0, -2, Complex(1, 3)], [2, 0, 5], [-Complex(1, 3), -5, 0]].antisymmetric?.should be_true - end +describe "Matrix#antisymmetric?" do + it "returns true for an antisymmetric Matrix" do + Matrix[[0, -2, Complex(1, 3)], [2, 0, 5], [-Complex(1, 3), -5, 0]].antisymmetric?.should be_true + end - it "returns true for a 0x0 empty matrix" do - Matrix.empty.antisymmetric?.should be_true - end + it "returns true for a 0x0 empty matrix" do + Matrix.empty.antisymmetric?.should be_true + end - it "returns false for non-antisymmetric matrices" do - [ - Matrix[[1, 2, 3], [4, 5, 6], [7, 8, 9]], - Matrix[[1, -2, 3], [2, 0, 6], [-3, -6, 0]], # wrong diagonal element - Matrix[[0, 2, -3], [2, 0, 6], [-3, 6, 0]] # only signs wrong - ].each do |matrix| - matrix.antisymmetric?.should be_false - end + it "returns false for non-antisymmetric matrices" do + [ + Matrix[[1, 2, 3], [4, 5, 6], [7, 8, 9]], + Matrix[[1, -2, 3], [2, 0, 6], [-3, -6, 0]], # wrong diagonal element + Matrix[[0, 2, -3], [2, 0, 6], [-3, 6, 0]] # only signs wrong + ].each do |matrix| + matrix.antisymmetric?.should be_false end + end - it "raises an error for rectangular matrices" do - [ - Matrix[[0], [0]], - Matrix[[0, 0]], - Matrix.empty(0, 2), - Matrix.empty(2, 0), - ].each do |rectangular_matrix| - -> { - rectangular_matrix.antisymmetric? - }.should raise_error(Matrix::ErrDimensionMismatch) - end + it "raises an error for rectangular matrices" do + [ + Matrix[[0], [0]], + Matrix[[0, 0]], + Matrix.empty(0, 2), + Matrix.empty(2, 0), + ].each do |rectangular_matrix| + -> { + rectangular_matrix.antisymmetric? + }.should raise_error(Matrix::ErrDimensionMismatch) end end end diff --git a/spec/ruby/library/matrix/build_spec.rb b/spec/ruby/library/matrix/build_spec.rb index d3055a1aa7..6d8017a3df 100644 --- a/spec/ruby/library/matrix/build_spec.rb +++ b/spec/ruby/library/matrix/build_spec.rb @@ -1,76 +1,73 @@ require_relative '../../spec_helper' +require_relative 'fixtures/classes' +require 'matrix' -ruby_version_is ""..."3.1" do - require_relative 'fixtures/classes' - require 'matrix' +describe "Matrix.build" do - describe "Matrix.build" do - - it "returns a Matrix object of the given size" do - m = Matrix.build(3, 4){1} - m.should be_an_instance_of(Matrix) - m.row_size.should == 3 - m.column_size.should == 4 - end + it "returns a Matrix object of the given size" do + m = Matrix.build(3, 4){1} + m.should be_an_instance_of(Matrix) + m.row_size.should == 3 + m.column_size.should == 4 + end - it "builds the Matrix using the given block" do - Matrix.build(2, 3){|col, row| 10*col - row}.should == - Matrix[[0, -1, -2], [10, 9, 8]] - end + it "builds the Matrix using the given block" do + Matrix.build(2, 3){|col, row| 10*col - row}.should == + Matrix[[0, -1, -2], [10, 9, 8]] + end - it "iterates through the first row, then the second, ..." do - acc = [] - Matrix.build(2, 3){|*args| acc << args} - acc.should == [[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2]] - end + it "iterates through the first row, then the second, ..." do + acc = [] + Matrix.build(2, 3){|*args| acc << args} + acc.should == [[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2]] + end - it "returns an Enumerator is no block is given" do - enum = Matrix.build(2, 1) - enum.should be_an_instance_of(Enumerator) - enum.each{1}.should == Matrix[[1], [1]] - end + it "returns an Enumerator is no block is given" do + enum = Matrix.build(2, 1) + enum.should be_an_instance_of(Enumerator) + enum.each{1}.should == Matrix[[1], [1]] + end - it "requires integers as parameters" do - -> { Matrix.build("1", "2"){1} }.should raise_error(TypeError) - -> { Matrix.build(nil, nil){1} }.should raise_error(TypeError) - -> { Matrix.build(1..2){1} }.should raise_error(TypeError) - end + it "requires integers as parameters" do + -> { Matrix.build("1", "2"){1} }.should raise_error(TypeError) + -> { Matrix.build(nil, nil){1} }.should raise_error(TypeError) + -> { Matrix.build(1..2){1} }.should raise_error(TypeError) + end - it "requires non-negative integers" do - -> { Matrix.build(-1, 1){1} }.should raise_error(ArgumentError) - -> { Matrix.build(+1,-1){1} }.should raise_error(ArgumentError) - end + it "requires non-negative integers" do + -> { Matrix.build(-1, 1){1} }.should raise_error(ArgumentError) + -> { Matrix.build(+1,-1){1} }.should raise_error(ArgumentError) + end - it "returns empty Matrix if one argument is zero" do - m = Matrix.build(0, 3){ - raise "Should not yield" - } - m.should be_empty - m.column_size.should == 3 + it "returns empty Matrix if one argument is zero" do + m = Matrix.build(0, 3){ + raise "Should not yield" + } + m.should be_empty + m.column_size.should == 3 - m = Matrix.build(3, 0){ - raise "Should not yield" - } - m.should be_empty - m.row_size.should == 3 - end + m = Matrix.build(3, 0){ + raise "Should not yield" + } + m.should be_empty + m.row_size.should == 3 + end - it "tries to calls :to_int on arguments" do - int = mock('int') - int.should_receive(:to_int).twice.and_return(2) - Matrix.build(int, int){ 1 }.should == Matrix[ [1,1], [1,1] ] - end + it "tries to calls :to_int on arguments" do + int = mock('int') + int.should_receive(:to_int).twice.and_return(2) + Matrix.build(int, int){ 1 }.should == Matrix[ [1,1], [1,1] ] + end - it "builds an nxn Matrix when given only one argument" do - m = Matrix.build(3){1} - m.row_size.should == 3 - m.column_size.should == 3 - end + it "builds an nxn Matrix when given only one argument" do + m = Matrix.build(3){1} + m.row_size.should == 3 + m.column_size.should == 3 end +end - describe "for a subclass of Matrix" do - it "returns an instance of that subclass" do - MatrixSub.build(3){1}.should be_an_instance_of(MatrixSub) - end +describe "for a subclass of Matrix" do + it "returns an instance of that subclass" do + MatrixSub.build(3){1}.should be_an_instance_of(MatrixSub) end end diff --git a/spec/ruby/library/matrix/clone_spec.rb b/spec/ruby/library/matrix/clone_spec.rb index bde119988f..74e5bf157e 100644 --- a/spec/ruby/library/matrix/clone_spec.rb +++ b/spec/ruby/library/matrix/clone_spec.rb @@ -1,28 +1,25 @@ require_relative '../../spec_helper' +require_relative 'fixtures/classes' +require 'matrix' -ruby_version_is ""..."3.1" do - require_relative 'fixtures/classes' - require 'matrix' - - describe "Matrix#clone" do - before :each do - @a = Matrix[[1, 2], [3, 4], [5, 6]] - end +describe "Matrix#clone" do + before :each do + @a = Matrix[[1, 2], [3, 4], [5, 6]] + end - it "returns a shallow copy of the matrix" do - b = @a.clone - @a.should_not equal(b) - b.should be_kind_of(Matrix) - b.should == @a - 0.upto(@a.row_size - 1) do |i| - @a.row(i).should_not equal(b.row(i)) - end + it "returns a shallow copy of the matrix" do + b = @a.clone + @a.should_not equal(b) + b.should be_kind_of(Matrix) + b.should == @a + 0.upto(@a.row_size - 1) do |i| + @a.row(i).should_not equal(b.row(i)) end + end - describe "for a subclass of Matrix" do - it "returns an instance of that subclass" do - MatrixSub.ins.clone.should be_an_instance_of(MatrixSub) - end + describe "for a subclass of Matrix" do + it "returns an instance of that subclass" do + MatrixSub.ins.clone.should be_an_instance_of(MatrixSub) end end end diff --git a/spec/ruby/library/matrix/coerce_spec.rb b/spec/ruby/library/matrix/coerce_spec.rb index aa3a32765a..4022f00236 100644 --- a/spec/ruby/library/matrix/coerce_spec.rb +++ b/spec/ruby/library/matrix/coerce_spec.rb @@ -1,11 +1,8 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix#coerce" do - it "allows the division of integer by a Matrix " do - (1/Matrix[[0,1],[-1,0]]).should == Matrix[[0,-1],[1,0]] - end +describe "Matrix#coerce" do + it "allows the division of integer by a Matrix " do + (1/Matrix[[0,1],[-1,0]]).should == Matrix[[0,-1],[1,0]] end end diff --git a/spec/ruby/library/matrix/collect_spec.rb b/spec/ruby/library/matrix/collect_spec.rb index 66ec3486c8..bba640213b 100644 --- a/spec/ruby/library/matrix/collect_spec.rb +++ b/spec/ruby/library/matrix/collect_spec.rb @@ -1,9 +1,6 @@ require_relative '../../spec_helper' +require_relative 'shared/collect' -ruby_version_is ""..."3.1" do - require_relative 'shared/collect' - - describe "Matrix#collect" do - it_behaves_like :collect, :collect - end +describe "Matrix#collect" do + it_behaves_like :collect, :collect end diff --git a/spec/ruby/library/matrix/column_size_spec.rb b/spec/ruby/library/matrix/column_size_spec.rb index e7b42b101e..041914e5b9 100644 --- a/spec/ruby/library/matrix/column_size_spec.rb +++ b/spec/ruby/library/matrix/column_size_spec.rb @@ -1,16 +1,13 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix#column_size" do - it "returns the number of columns" do - Matrix[ [1,2], [3,4] ].column_size.should == 2 - end +describe "Matrix#column_size" do + it "returns the number of columns" do + Matrix[ [1,2], [3,4] ].column_size.should == 2 + end - it "returns 0 for empty matrices" do - Matrix[ [], [] ].column_size.should == 0 - Matrix[ ].column_size.should == 0 - end + it "returns 0 for empty matrices" do + Matrix[ [], [] ].column_size.should == 0 + Matrix[ ].column_size.should == 0 end end diff --git a/spec/ruby/library/matrix/column_spec.rb b/spec/ruby/library/matrix/column_spec.rb index 98a767ad08..1f3c80964a 100644 --- a/spec/ruby/library/matrix/column_spec.rb +++ b/spec/ruby/library/matrix/column_spec.rb @@ -1,38 +1,35 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix#column" do - before :all do - @m = Matrix[[1,2,3], [2,3,4]] - end +describe "Matrix#column" do + before :all do + @m = Matrix[[1,2,3], [2,3,4]] + end - it "returns a Vector when called without a block" do - @m.column(1).should == Vector[2,3] - end + it "returns a Vector when called without a block" do + @m.column(1).should == Vector[2,3] + end - it "yields each element in the column to the block" do - a = [] - @m.column(1) {|n| a << n } - a.should == [2,3] - end + it "yields each element in the column to the block" do + a = [] + @m.column(1) {|n| a << n } + a.should == [2,3] + end - it "counts backwards for negative argument" do - @m.column(-1).should == Vector[3, 4] - end + it "counts backwards for negative argument" do + @m.column(-1).should == Vector[3, 4] + end - it "returns self when called with a block" do - @m.column(0) { |x| x }.should equal(@m) - end + it "returns self when called with a block" do + @m.column(0) { |x| x }.should equal(@m) + end - it "returns nil when out of bounds" do - @m.column(3).should == nil - end + it "returns nil when out of bounds" do + @m.column(3).should == nil + end - it "never yields when out of bounds" do - -> { @m.column(3){ raise } }.should_not raise_error - -> { @m.column(-4){ raise } }.should_not raise_error - end + it "never yields when out of bounds" do + -> { @m.column(3){ raise } }.should_not raise_error + -> { @m.column(-4){ raise } }.should_not raise_error end end diff --git a/spec/ruby/library/matrix/column_vector_spec.rb b/spec/ruby/library/matrix/column_vector_spec.rb index afdeaced47..47e866a8d5 100644 --- a/spec/ruby/library/matrix/column_vector_spec.rb +++ b/spec/ruby/library/matrix/column_vector_spec.rb @@ -1,28 +1,25 @@ require_relative '../../spec_helper' +require_relative 'fixtures/classes' +require 'matrix' -ruby_version_is ""..."3.1" do - require_relative 'fixtures/classes' - require 'matrix' +describe "Matrix.column_vector" do - describe "Matrix.column_vector" do - - it "returns a single column Matrix when called with an Array" do - m = Matrix.column_vector([4,5,6]) - m.should be_an_instance_of(Matrix) - m.should == Matrix[ [4],[5],[6] ] - end + it "returns a single column Matrix when called with an Array" do + m = Matrix.column_vector([4,5,6]) + m.should be_an_instance_of(Matrix) + m.should == Matrix[ [4],[5],[6] ] + end - it "returns an empty Matrix when called with an empty Array" do - m = Matrix.column_vector([]) - m.should be_an_instance_of(Matrix) - m.row_size.should == 0 - m.column_size.should == 1 - end + it "returns an empty Matrix when called with an empty Array" do + m = Matrix.column_vector([]) + m.should be_an_instance_of(Matrix) + m.row_size.should == 0 + m.column_size.should == 1 + end - describe "for a subclass of Matrix" do - it "returns an instance of that subclass" do - MatrixSub.column_vector([4,5,6]).should be_an_instance_of(MatrixSub) - end + describe "for a subclass of Matrix" do + it "returns an instance of that subclass" do + MatrixSub.column_vector([4,5,6]).should be_an_instance_of(MatrixSub) end end end diff --git a/spec/ruby/library/matrix/column_vectors_spec.rb b/spec/ruby/library/matrix/column_vectors_spec.rb index 7bec095b9a..b0cb6f914c 100644 --- a/spec/ruby/library/matrix/column_vectors_spec.rb +++ b/spec/ruby/library/matrix/column_vectors_spec.rb @@ -1,29 +1,26 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' +describe "Matrix#column_vectors" do - describe "Matrix#column_vectors" do - - before :each do - @vectors = Matrix[ [1,2], [3,4] ].column_vectors - end - - it "returns an Array" do - Matrix[ [1,2], [3,4] ].column_vectors.should be_an_instance_of(Array) - end + before :each do + @vectors = Matrix[ [1,2], [3,4] ].column_vectors + end - it "returns an Array of Vectors" do - @vectors.all? {|v| v.should be_an_instance_of(Vector)} - end + it "returns an Array" do + Matrix[ [1,2], [3,4] ].column_vectors.should be_an_instance_of(Array) + end - it "returns each column as a Vector" do - @vectors.should == [Vector[1,3], Vector[2,4]] - end + it "returns an Array of Vectors" do + @vectors.all? {|v| v.should be_an_instance_of(Vector)} + end - it "returns an empty Array for empty matrices" do - Matrix[ [] ].column_vectors.should == [] - end + it "returns each column as a Vector" do + @vectors.should == [Vector[1,3], Vector[2,4]] + end + it "returns an empty Array for empty matrices" do + Matrix[ [] ].column_vectors.should == [] end + end diff --git a/spec/ruby/library/matrix/columns_spec.rb b/spec/ruby/library/matrix/columns_spec.rb index 757086c14b..3095fdd7af 100644 --- a/spec/ruby/library/matrix/columns_spec.rb +++ b/spec/ruby/library/matrix/columns_spec.rb @@ -1,45 +1,42 @@ require_relative '../../spec_helper' +require_relative 'fixtures/classes' +require 'matrix' -ruby_version_is ""..."3.1" do - require_relative 'fixtures/classes' - require 'matrix' - - describe "Matrix.columns" do - before :each do - @a = [1, 2] - @b = [3, 4] - @m = Matrix.columns([@a, @b]) - end +describe "Matrix.columns" do + before :each do + @a = [1, 2] + @b = [3, 4] + @m = Matrix.columns([@a, @b]) + end - it "creates a Matrix from argument columns" do - @m.should be_an_instance_of(Matrix) - @m.column(0).to_a.should == @a - @m.column(1).to_a.should == @b - end + it "creates a Matrix from argument columns" do + @m.should be_an_instance_of(Matrix) + @m.column(0).to_a.should == @a + @m.column(1).to_a.should == @b + end - it "accepts Vectors as argument columns" do - m = Matrix.columns([Vector[*@a], Vector[*@b]]) - m.should == @m - m.column(0).to_a.should == @a - m.column(1).to_a.should == @b - end + it "accepts Vectors as argument columns" do + m = Matrix.columns([Vector[*@a], Vector[*@b]]) + m.should == @m + m.column(0).to_a.should == @a + m.column(1).to_a.should == @b + end - it "handles empty matrices" do - e = Matrix.columns([]) - e.row_size.should == 0 - e.column_size.should == 0 - e.should == Matrix[] + it "handles empty matrices" do + e = Matrix.columns([]) + e.row_size.should == 0 + e.column_size.should == 0 + e.should == Matrix[] - v = Matrix.columns([[],[],[]]) - v.row_size.should == 0 - v.column_size.should == 3 - v.should == Matrix[[], [], []].transpose - end + v = Matrix.columns([[],[],[]]) + v.row_size.should == 0 + v.column_size.should == 3 + v.should == Matrix[[], [], []].transpose + end - describe "for a subclass of Matrix" do - it "returns an instance of that subclass" do - MatrixSub.columns([[1]]).should be_an_instance_of(MatrixSub) - end + describe "for a subclass of Matrix" do + it "returns an instance of that subclass" do + MatrixSub.columns([[1]]).should be_an_instance_of(MatrixSub) end end end diff --git a/spec/ruby/library/matrix/conj_spec.rb b/spec/ruby/library/matrix/conj_spec.rb index a922580399..ecee95c255 100644 --- a/spec/ruby/library/matrix/conj_spec.rb +++ b/spec/ruby/library/matrix/conj_spec.rb @@ -1,9 +1,6 @@ require_relative '../../spec_helper' +require_relative 'shared/conjugate' -ruby_version_is ""..."3.1" do - require_relative 'shared/conjugate' - - describe "Matrix#conj" do - it_behaves_like :matrix_conjugate, :conj - end +describe "Matrix#conj" do + it_behaves_like :matrix_conjugate, :conj end diff --git a/spec/ruby/library/matrix/conjugate_spec.rb b/spec/ruby/library/matrix/conjugate_spec.rb index b99792a24b..682bd41d94 100644 --- a/spec/ruby/library/matrix/conjugate_spec.rb +++ b/spec/ruby/library/matrix/conjugate_spec.rb @@ -1,9 +1,6 @@ require_relative '../../spec_helper' +require_relative 'shared/conjugate' -ruby_version_is ""..."3.1" do - require_relative 'shared/conjugate' - - describe "Matrix#conjugate" do - it_behaves_like :matrix_conjugate, :conjugate - end +describe "Matrix#conjugate" do + it_behaves_like :matrix_conjugate, :conjugate end diff --git a/spec/ruby/library/matrix/constructor_spec.rb b/spec/ruby/library/matrix/constructor_spec.rb index d8224b4430..70d77babbb 100644 --- a/spec/ruby/library/matrix/constructor_spec.rb +++ b/spec/ruby/library/matrix/constructor_spec.rb @@ -1,68 +1,65 @@ require_relative '../../spec_helper' +require_relative 'fixtures/classes' +require 'matrix' -ruby_version_is ""..."3.1" do - require_relative 'fixtures/classes' - require 'matrix' +describe "Matrix.[]" do - describe "Matrix.[]" do - - it "requires arrays as parameters" do - -> { Matrix[5] }.should raise_error(TypeError) - -> { Matrix[nil] }.should raise_error(TypeError) - -> { Matrix[1..2] }.should raise_error(TypeError) - -> { Matrix[[1, 2], 3] }.should raise_error(TypeError) - end + it "requires arrays as parameters" do + -> { Matrix[5] }.should raise_error(TypeError) + -> { Matrix[nil] }.should raise_error(TypeError) + -> { Matrix[1..2] }.should raise_error(TypeError) + -> { Matrix[[1, 2], 3] }.should raise_error(TypeError) + end - it "creates an empty Matrix with no arguments" do - m = Matrix[] - m.column_size.should == 0 - m.row_size.should == 0 - end + it "creates an empty Matrix with no arguments" do + m = Matrix[] + m.column_size.should == 0 + m.row_size.should == 0 + end - it "raises for non-rectangular matrices" do - ->{ Matrix[ [0], [0,1] ] }.should \ - raise_error(Matrix::ErrDimensionMismatch) - ->{ Matrix[ [0,1], [0,1,2], [0,1] ]}.should \ - raise_error(Matrix::ErrDimensionMismatch) - end + it "raises for non-rectangular matrices" do + ->{ Matrix[ [0], [0,1] ] }.should \ + raise_error(Matrix::ErrDimensionMismatch) + ->{ Matrix[ [0,1], [0,1,2], [0,1] ]}.should \ + raise_error(Matrix::ErrDimensionMismatch) + end - it "accepts vector arguments" do - a = Matrix[Vector[1, 2], Vector[3, 4]] - a.should be_an_instance_of(Matrix) - a.should == Matrix[ [1, 2], [3, 4] ] - end + it "accepts vector arguments" do + a = Matrix[Vector[1, 2], Vector[3, 4]] + a.should be_an_instance_of(Matrix) + a.should == Matrix[ [1, 2], [3, 4] ] + end - it "tries to calls :to_ary on arguments" do - array = mock('ary') - array.should_receive(:to_ary).and_return([1,2]) - Matrix[array, [3,4] ].should == Matrix[ [1,2], [3,4] ] - end + it "tries to calls :to_ary on arguments" do + array = mock('ary') + array.should_receive(:to_ary).and_return([1,2]) + Matrix[array, [3,4] ].should == Matrix[ [1,2], [3,4] ] + end - it "returns a Matrix object" do - Matrix[ [1] ].should be_an_instance_of(Matrix) - end + it "returns a Matrix object" do + Matrix[ [1] ].should be_an_instance_of(Matrix) + end - it "can create an nxn Matrix" do - m = Matrix[ [20,30], [40.5, 9] ] - m.row_size.should == 2 - m.column_size.should == 2 - m.column(0).should == Vector[20, 40.5] - m.column(1).should == Vector[30, 9] - m.row(0).should == Vector[20, 30] - m.row(1).should == Vector[40.5, 9] - end + it "can create an nxn Matrix" do + m = Matrix[ [20,30], [40.5, 9] ] + m.row_size.should == 2 + m.column_size.should == 2 + m.column(0).should == Vector[20, 40.5] + m.column(1).should == Vector[30, 9] + m.row(0).should == Vector[20, 30] + m.row(1).should == Vector[40.5, 9] + end - it "can create a 0xn Matrix" do - m = Matrix[ [], [], [] ] - m.row_size.should == 3 - m.column_size.should == 0 - end + it "can create a 0xn Matrix" do + m = Matrix[ [], [], [] ] + m.row_size.should == 3 + m.column_size.should == 0 + end - describe "for a subclass of Matrix" do - it "returns an instance of that subclass" do - MatrixSub[ [20,30], [40.5, 9] ].should be_an_instance_of(MatrixSub) - end + describe "for a subclass of Matrix" do + it "returns an instance of that subclass" do + MatrixSub[ [20,30], [40.5, 9] ].should be_an_instance_of(MatrixSub) end end end diff --git a/spec/ruby/library/matrix/det_spec.rb b/spec/ruby/library/matrix/det_spec.rb index 7d3d547735..aa7086cacf 100644 --- a/spec/ruby/library/matrix/det_spec.rb +++ b/spec/ruby/library/matrix/det_spec.rb @@ -1,10 +1,7 @@ require_relative '../../spec_helper' +require_relative 'shared/determinant' +require 'matrix' -ruby_version_is ""..."3.1" do - require_relative 'shared/determinant' - require 'matrix' - - describe "Matrix#det" do - it_behaves_like :determinant, :det - end +describe "Matrix#det" do + it_behaves_like :determinant, :det end diff --git a/spec/ruby/library/matrix/determinant_spec.rb b/spec/ruby/library/matrix/determinant_spec.rb index bfd91fcf68..825c9907b1 100644 --- a/spec/ruby/library/matrix/determinant_spec.rb +++ b/spec/ruby/library/matrix/determinant_spec.rb @@ -1,10 +1,7 @@ require_relative '../../spec_helper' +require_relative 'shared/determinant' +require 'matrix' -ruby_version_is ""..."3.1" do - require_relative 'shared/determinant' - require 'matrix' - - describe "Matrix#determinant" do - it_behaves_like :determinant, :determinant - end +describe "Matrix#determinant" do + it_behaves_like :determinant, :determinant end diff --git a/spec/ruby/library/matrix/diagonal_spec.rb b/spec/ruby/library/matrix/diagonal_spec.rb index 8c82433fde..ef9738e73e 100644 --- a/spec/ruby/library/matrix/diagonal_spec.rb +++ b/spec/ruby/library/matrix/diagonal_spec.rb @@ -1,75 +1,72 @@ require_relative '../../spec_helper' +require_relative 'fixtures/classes' +require 'matrix' -ruby_version_is ""..."3.1" do - require_relative 'fixtures/classes' - require 'matrix' - - describe "Matrix.diagonal" do - before :each do - @m = Matrix.diagonal(10, 11, 12, 13, 14) - end +describe "Matrix.diagonal" do + before :each do + @m = Matrix.diagonal(10, 11, 12, 13, 14) + end - it "returns an object of type Matrix" do - @m.should be_kind_of(Matrix) - end + it "returns an object of type Matrix" do + @m.should be_kind_of(Matrix) + end - it "returns a square Matrix of the right size" do - @m.column_size.should == 5 - @m.row_size.should == 5 - end + it "returns a square Matrix of the right size" do + @m.column_size.should == 5 + @m.row_size.should == 5 + end - it "sets the diagonal to the arguments" do - (0..4).each do |i| - @m[i, i].should == i + 10 - end + it "sets the diagonal to the arguments" do + (0..4).each do |i| + @m[i, i].should == i + 10 end + end - it "fills all non-diagonal cells with 0" do - (0..4).each do |i| - (0..4).each do |j| - if i != j - @m[i, j].should == 0 - end + it "fills all non-diagonal cells with 0" do + (0..4).each do |i| + (0..4).each do |j| + if i != j + @m[i, j].should == 0 end end end + end - describe "for a subclass of Matrix" do - it "returns an instance of that subclass" do - MatrixSub.diagonal(1).should be_an_instance_of(MatrixSub) - end + describe "for a subclass of Matrix" do + it "returns an instance of that subclass" do + MatrixSub.diagonal(1).should be_an_instance_of(MatrixSub) end end +end - describe "Matrix.diagonal?" do - it "returns true for a diagonal Matrix" do - Matrix.diagonal([1, 2, 3]).diagonal?.should be_true - end +describe "Matrix.diagonal?" do + it "returns true for a diagonal Matrix" do + Matrix.diagonal([1, 2, 3]).diagonal?.should be_true + end - it "returns true for a zero square Matrix" do - Matrix.zero(3).diagonal?.should be_true - end + it "returns true for a zero square Matrix" do + Matrix.zero(3).diagonal?.should be_true + end - it "returns false for a non diagonal square Matrix" do - Matrix[[0, 1], [0, 0]].diagonal?.should be_false - Matrix[[1, 2, 3], [1, 2, 3], [1, 2, 3]].diagonal?.should be_false - end + it "returns false for a non diagonal square Matrix" do + Matrix[[0, 1], [0, 0]].diagonal?.should be_false + Matrix[[1, 2, 3], [1, 2, 3], [1, 2, 3]].diagonal?.should be_false + end - it "returns true for an empty 0x0 matrix" do - Matrix.empty(0,0).diagonal?.should be_true - end + it "returns true for an empty 0x0 matrix" do + Matrix.empty(0,0).diagonal?.should be_true + end - it "raises an error for rectangular matrices" do - [ - Matrix[[0], [0]], - Matrix[[0, 0]], - Matrix.empty(0, 2), - Matrix.empty(2, 0), - ].each do |rectangular_matrix| - -> { - rectangular_matrix.diagonal? - }.should raise_error(Matrix::ErrDimensionMismatch) - end + it "raises an error for rectangular matrices" do + [ + Matrix[[0], [0]], + Matrix[[0, 0]], + Matrix.empty(0, 2), + Matrix.empty(2, 0), + ].each do |rectangular_matrix| + -> { + rectangular_matrix.diagonal? + }.should raise_error(Matrix::ErrDimensionMismatch) end end end diff --git a/spec/ruby/library/matrix/divide_spec.rb b/spec/ruby/library/matrix/divide_spec.rb index 68e6f1fde5..2e3bb85bf6 100644 --- a/spec/ruby/library/matrix/divide_spec.rb +++ b/spec/ruby/library/matrix/divide_spec.rb @@ -1,57 +1,54 @@ require_relative '../../spec_helper' +require_relative 'spec_helper' +require_relative 'fixtures/classes' +require 'matrix' + +describe "Matrix#/" do + before :each do + @a = Matrix[ [1, 2], [3, 4] ] + @b = Matrix[ [4, 5], [6, 7] ] + @c = Matrix[ [1.2, 2.4], [3.6, 4.8] ] + end -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - require_relative 'fixtures/classes' - require 'matrix' + it "returns the result of dividing self by another Matrix" do + (@a / @b).should be_close_to_matrix([[2.5, -1.5], [1.5, -0.5]]) + end - describe "Matrix#/" do - before :each do - @a = Matrix[ [1, 2], [3, 4] ] - @b = Matrix[ [4, 5], [6, 7] ] - @c = Matrix[ [1.2, 2.4], [3.6, 4.8] ] + # Guard against the Mathn library + guard -> { !defined?(Math.rsqrt) } do + it "returns the result of dividing self by a Fixnum" do + (@a / 2).should == Matrix[ [0, 1], [1, 2] ] end - it "returns the result of dividing self by another Matrix" do - (@a / @b).should be_close_to_matrix([[2.5, -1.5], [1.5, -0.5]]) - end - - # Guard against the Mathn library - guard -> { !defined?(Math.rsqrt) } do - it "returns the result of dividing self by a Fixnum" do - (@a / 2).should == Matrix[ [0, 1], [1, 2] ] - end - - it "returns the result of dividing self by a Bignum" do - (@a / bignum_value).should == Matrix[ [0, 0], [0, 0] ] - end + it "returns the result of dividing self by a Bignum" do + (@a / bignum_value).should == Matrix[ [0, 0], [0, 0] ] end + end - it "returns the result of dividing self by a Float" do - (@c / 1.2).should == Matrix[ [1, 2], [3, 4] ] - end + it "returns the result of dividing self by a Float" do + (@c / 1.2).should == Matrix[ [1, 2], [3, 4] ] + end - it "raises a Matrix::ErrDimensionMismatch if the matrices are different sizes" do - -> { @a / Matrix[ [1] ] }.should raise_error(Matrix::ErrDimensionMismatch) - end + it "raises a Matrix::ErrDimensionMismatch if the matrices are different sizes" do + -> { @a / Matrix[ [1] ] }.should raise_error(Matrix::ErrDimensionMismatch) + end - it "returns an instance of Matrix" do - (@a / @b).should be_kind_of(Matrix) - end + it "returns an instance of Matrix" do + (@a / @b).should be_kind_of(Matrix) + end - describe "for a subclass of Matrix" do - it "returns an instance of that subclass" do - m = MatrixSub.ins - (m/m).should be_an_instance_of(MatrixSub) - (m/1).should be_an_instance_of(MatrixSub) - end + describe "for a subclass of Matrix" do + it "returns an instance of that subclass" do + m = MatrixSub.ins + (m/m).should be_an_instance_of(MatrixSub) + (m/1).should be_an_instance_of(MatrixSub) end + end - it "raises a TypeError if other is of wrong type" do - -> { @a / nil }.should raise_error(TypeError) - -> { @a / "a" }.should raise_error(TypeError) - -> { @a / [ [1, 2] ] }.should raise_error(TypeError) - -> { @a / Object.new }.should raise_error(TypeError) - end + it "raises a TypeError if other is of wrong type" do + -> { @a / nil }.should raise_error(TypeError) + -> { @a / "a" }.should raise_error(TypeError) + -> { @a / [ [1, 2] ] }.should raise_error(TypeError) + -> { @a / Object.new }.should raise_error(TypeError) end end diff --git a/spec/ruby/library/matrix/each_spec.rb b/spec/ruby/library/matrix/each_spec.rb index d2b13c80b6..f3b0f01867 100644 --- a/spec/ruby/library/matrix/each_spec.rb +++ b/spec/ruby/library/matrix/each_spec.rb @@ -1,77 +1,74 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix#each" do - before :all do - @m = Matrix[ [1, 2, 3], [4, 5, 6] ] - @result = (1..6).to_a - end +describe "Matrix#each" do + before :all do + @m = Matrix[ [1, 2, 3], [4, 5, 6] ] + @result = (1..6).to_a + end - it "returns an Enumerator when called without a block" do - enum = @m.each - enum.should be_an_instance_of(Enumerator) - enum.to_a.should == @result - end + it "returns an Enumerator when called without a block" do + enum = @m.each + enum.should be_an_instance_of(Enumerator) + enum.to_a.should == @result + end - it "returns self" do - @m.each{}.should equal(@m) - end + it "returns self" do + @m.each{}.should equal(@m) + end - it "yields the elements starting with the those of the first row" do - a = [] - @m.each {|x| a << x} - a.should == @result - end + it "yields the elements starting with the those of the first row" do + a = [] + @m.each {|x| a << x} + a.should == @result end +end - describe "Matrix#each with an argument" do - before :all do - @m = Matrix[ [1, 2, 3, 4], [5, 6, 7, 8] ] - @t = Matrix[ [1, 2], [3, 4], [5, 6], [7, 8] ] - end +describe "Matrix#each with an argument" do + before :all do + @m = Matrix[ [1, 2, 3, 4], [5, 6, 7, 8] ] + @t = Matrix[ [1, 2], [3, 4], [5, 6], [7, 8] ] + end - it "raises an ArgumentError for unrecognized argument" do - -> { - @m.each("all"){} - }.should raise_error(ArgumentError) - -> { - @m.each(nil){} - }.should raise_error(ArgumentError) - -> { - @m.each(:left){} - }.should raise_error(ArgumentError) - end + it "raises an ArgumentError for unrecognized argument" do + -> { + @m.each("all"){} + }.should raise_error(ArgumentError) + -> { + @m.each(nil){} + }.should raise_error(ArgumentError) + -> { + @m.each(:left){} + }.should raise_error(ArgumentError) + end - it "yields the rights elements when passed :diagonal" do - @m.each(:diagonal).to_a.should == [1, 6] - @t.each(:diagonal).to_a.should == [1, 4] - end + it "yields the rights elements when passed :diagonal" do + @m.each(:diagonal).to_a.should == [1, 6] + @t.each(:diagonal).to_a.should == [1, 4] + end - it "yields the rights elements when passed :off_diagonal" do - @m.each(:off_diagonal).to_a.should == [2, 3, 4, 5, 7, 8] - @t.each(:off_diagonal).to_a.should == [2, 3, 5, 6, 7, 8] - end + it "yields the rights elements when passed :off_diagonal" do + @m.each(:off_diagonal).to_a.should == [2, 3, 4, 5, 7, 8] + @t.each(:off_diagonal).to_a.should == [2, 3, 5, 6, 7, 8] + end - it "yields the rights elements when passed :lower" do - @m.each(:lower).to_a.should == [1, 5, 6] - @t.each(:lower).to_a.should == [1, 3, 4, 5, 6, 7, 8] - end + it "yields the rights elements when passed :lower" do + @m.each(:lower).to_a.should == [1, 5, 6] + @t.each(:lower).to_a.should == [1, 3, 4, 5, 6, 7, 8] + end - it "yields the rights elements when passed :strict_lower" do - @m.each(:strict_lower).to_a.should == [5] - @t.each(:strict_lower).to_a.should == [3, 5, 6, 7, 8] - end + it "yields the rights elements when passed :strict_lower" do + @m.each(:strict_lower).to_a.should == [5] + @t.each(:strict_lower).to_a.should == [3, 5, 6, 7, 8] + end - it "yields the rights elements when passed :strict_upper" do - @m.each(:strict_upper).to_a.should == [2, 3, 4, 7, 8] - @t.each(:strict_upper).to_a.should == [2] - end + it "yields the rights elements when passed :strict_upper" do + @m.each(:strict_upper).to_a.should == [2, 3, 4, 7, 8] + @t.each(:strict_upper).to_a.should == [2] + end - it "yields the rights elements when passed :upper" do - @m.each(:upper).to_a.should == [1, 2, 3, 4, 6, 7, 8] - @t.each(:upper).to_a.should == [1, 2, 4] - end + it "yields the rights elements when passed :upper" do + @m.each(:upper).to_a.should == [1, 2, 3, 4, 6, 7, 8] + @t.each(:upper).to_a.should == [1, 2, 4] end end diff --git a/spec/ruby/library/matrix/each_with_index_spec.rb b/spec/ruby/library/matrix/each_with_index_spec.rb index 59549f77b7..a005b88621 100644 --- a/spec/ruby/library/matrix/each_with_index_spec.rb +++ b/spec/ruby/library/matrix/each_with_index_spec.rb @@ -1,84 +1,81 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix#each_with_index" do - before :all do - @m = Matrix[ [1, 2, 3], [4, 5, 6] ] - @result = [ - [1, 0, 0], - [2, 0, 1], - [3, 0, 2], - [4, 1, 0], - [5, 1, 1], - [6, 1, 2] - ] - end +describe "Matrix#each_with_index" do + before :all do + @m = Matrix[ [1, 2, 3], [4, 5, 6] ] + @result = [ + [1, 0, 0], + [2, 0, 1], + [3, 0, 2], + [4, 1, 0], + [5, 1, 1], + [6, 1, 2] + ] + end - it "returns an Enumerator when called without a block" do - enum = @m.each_with_index - enum.should be_an_instance_of(Enumerator) - enum.to_a.should == @result - end + it "returns an Enumerator when called without a block" do + enum = @m.each_with_index + enum.should be_an_instance_of(Enumerator) + enum.to_a.should == @result + end - it "returns self" do - @m.each_with_index{}.should equal(@m) - end + it "returns self" do + @m.each_with_index{}.should equal(@m) + end - it "yields the elements starting with the those of the first row" do - a = [] - @m.each_with_index {|x, r, c| a << [x, r, c]} - a.should == @result - end + it "yields the elements starting with the those of the first row" do + a = [] + @m.each_with_index {|x, r, c| a << [x, r, c]} + a.should == @result end +end - describe "Matrix#each_with_index with an argument" do - before :all do - @m = Matrix[ [1, 2, 3, 4], [5, 6, 7, 8] ] - @t = Matrix[ [1, 2], [3, 4], [5, 6], [7, 8] ] - end +describe "Matrix#each_with_index with an argument" do + before :all do + @m = Matrix[ [1, 2, 3, 4], [5, 6, 7, 8] ] + @t = Matrix[ [1, 2], [3, 4], [5, 6], [7, 8] ] + end - it "raises an ArgumentError for unrecognized argument" do - -> { - @m.each_with_index("all"){} - }.should raise_error(ArgumentError) - -> { - @m.each_with_index(nil){} - }.should raise_error(ArgumentError) - -> { - @m.each_with_index(:left){} - }.should raise_error(ArgumentError) - end + it "raises an ArgumentError for unrecognized argument" do + -> { + @m.each_with_index("all"){} + }.should raise_error(ArgumentError) + -> { + @m.each_with_index(nil){} + }.should raise_error(ArgumentError) + -> { + @m.each_with_index(:left){} + }.should raise_error(ArgumentError) + end - it "yields the rights elements when passed :diagonal" do - @m.each_with_index(:diagonal).to_a.should == [[1, 0, 0], [6, 1, 1]] - @t.each_with_index(:diagonal).to_a.should == [[1, 0, 0], [4, 1, 1]] - end + it "yields the rights elements when passed :diagonal" do + @m.each_with_index(:diagonal).to_a.should == [[1, 0, 0], [6, 1, 1]] + @t.each_with_index(:diagonal).to_a.should == [[1, 0, 0], [4, 1, 1]] + end - it "yields the rights elements when passed :off_diagonal" do - @m.each_with_index(:off_diagonal).to_a.should == [[2, 0, 1], [3, 0, 2], [4, 0, 3], [5, 1, 0], [7, 1, 2], [8, 1, 3]] - @t.each_with_index(:off_diagonal).to_a.should == [[2, 0, 1], [3, 1, 0], [5, 2, 0], [6, 2, 1], [7, 3, 0], [8, 3, 1]] - end + it "yields the rights elements when passed :off_diagonal" do + @m.each_with_index(:off_diagonal).to_a.should == [[2, 0, 1], [3, 0, 2], [4, 0, 3], [5, 1, 0], [7, 1, 2], [8, 1, 3]] + @t.each_with_index(:off_diagonal).to_a.should == [[2, 0, 1], [3, 1, 0], [5, 2, 0], [6, 2, 1], [7, 3, 0], [8, 3, 1]] + end - it "yields the rights elements when passed :lower" do - @m.each_with_index(:lower).to_a.should == [[1, 0, 0], [5, 1, 0], [6, 1, 1]] - @t.each_with_index(:lower).to_a.should == [[1, 0, 0], [3, 1, 0], [4, 1, 1], [5, 2, 0], [6, 2, 1], [7, 3, 0], [8, 3, 1]] - end + it "yields the rights elements when passed :lower" do + @m.each_with_index(:lower).to_a.should == [[1, 0, 0], [5, 1, 0], [6, 1, 1]] + @t.each_with_index(:lower).to_a.should == [[1, 0, 0], [3, 1, 0], [4, 1, 1], [5, 2, 0], [6, 2, 1], [7, 3, 0], [8, 3, 1]] + end - it "yields the rights elements when passed :strict_lower" do - @m.each_with_index(:strict_lower).to_a.should == [[5, 1, 0]] - @t.each_with_index(:strict_lower).to_a.should == [[3, 1, 0], [5, 2, 0], [6, 2, 1], [7, 3, 0], [8, 3, 1]] - end + it "yields the rights elements when passed :strict_lower" do + @m.each_with_index(:strict_lower).to_a.should == [[5, 1, 0]] + @t.each_with_index(:strict_lower).to_a.should == [[3, 1, 0], [5, 2, 0], [6, 2, 1], [7, 3, 0], [8, 3, 1]] + end - it "yields the rights elements when passed :strict_upper" do - @m.each_with_index(:strict_upper).to_a.should == [[2, 0, 1], [3, 0, 2], [4, 0, 3], [7, 1, 2], [8, 1, 3]] - @t.each_with_index(:strict_upper).to_a.should == [[2, 0, 1]] - end + it "yields the rights elements when passed :strict_upper" do + @m.each_with_index(:strict_upper).to_a.should == [[2, 0, 1], [3, 0, 2], [4, 0, 3], [7, 1, 2], [8, 1, 3]] + @t.each_with_index(:strict_upper).to_a.should == [[2, 0, 1]] + end - it "yields the rights elements when passed :upper" do - @m.each_with_index(:upper).to_a.should == [[1, 0, 0], [2, 0, 1], [3, 0, 2], [4, 0, 3], [6, 1, 1], [7, 1, 2], [8, 1, 3]] - @t.each_with_index(:upper).to_a.should == [[1, 0, 0], [2, 0, 1], [4, 1, 1]] - end + it "yields the rights elements when passed :upper" do + @m.each_with_index(:upper).to_a.should == [[1, 0, 0], [2, 0, 1], [3, 0, 2], [4, 0, 3], [6, 1, 1], [7, 1, 2], [8, 1, 3]] + @t.each_with_index(:upper).to_a.should == [[1, 0, 0], [2, 0, 1], [4, 1, 1]] end end diff --git a/spec/ruby/library/matrix/eigenvalue_decomposition/eigenvalue_matrix_spec.rb b/spec/ruby/library/matrix/eigenvalue_decomposition/eigenvalue_matrix_spec.rb index f9ffca0123..67f9dd1c19 100644 --- a/spec/ruby/library/matrix/eigenvalue_decomposition/eigenvalue_matrix_spec.rb +++ b/spec/ruby/library/matrix/eigenvalue_decomposition/eigenvalue_matrix_spec.rb @@ -1,12 +1,9 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix::EigenvalueDecomposition#eigenvalue_matrix" do - it "returns a diagonal matrix with the eigenvalues on the diagonal" do - Matrix[[14, 16], [-6, -6]].eigensystem.eigenvalue_matrix.should == Matrix[[6, 0],[0, 2]] - Matrix[[1, 1], [-1, 1]].eigensystem.eigenvalue_matrix.should == Matrix[[Complex(1,1), 0],[0, Complex(1,-1)]] - end +describe "Matrix::EigenvalueDecomposition#eigenvalue_matrix" do + it "returns a diagonal matrix with the eigenvalues on the diagonal" do + Matrix[[14, 16], [-6, -6]].eigensystem.eigenvalue_matrix.should == Matrix[[6, 0],[0, 2]] + Matrix[[1, 1], [-1, 1]].eigensystem.eigenvalue_matrix.should == Matrix[[Complex(1,1), 0],[0, Complex(1,-1)]] end end diff --git a/spec/ruby/library/matrix/eigenvalue_decomposition/eigenvalues_spec.rb b/spec/ruby/library/matrix/eigenvalue_decomposition/eigenvalues_spec.rb index 650d43d90f..7552b7616c 100644 --- a/spec/ruby/library/matrix/eigenvalue_decomposition/eigenvalues_spec.rb +++ b/spec/ruby/library/matrix/eigenvalue_decomposition/eigenvalues_spec.rb @@ -1,25 +1,22 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix::EigenvalueDecomposition#eigenvalues" do - it "returns an array of complex eigenvalues for a rotation matrix" do - Matrix[[ 1, 1], - [-1, 1]].eigensystem.eigenvalues.sort_by{|v| v.imag}.should == - [ Complex(1, -1), Complex(1, 1)] - end +describe "Matrix::EigenvalueDecomposition#eigenvalues" do + it "returns an array of complex eigenvalues for a rotation matrix" do + Matrix[[ 1, 1], + [-1, 1]].eigensystem.eigenvalues.sort_by{|v| v.imag}.should == + [ Complex(1, -1), Complex(1, 1)] + end - it "returns an array of real eigenvalues for a symmetric matrix" do - Matrix[[1, 2], - [2, 1]].eigensystem.eigenvalues.sort.map!{|x| x.round(10)}.should == - [ -1, 3 ] - end + it "returns an array of real eigenvalues for a symmetric matrix" do + Matrix[[1, 2], + [2, 1]].eigensystem.eigenvalues.sort.map!{|x| x.round(10)}.should == + [ -1, 3 ] + end - it "returns an array of real eigenvalues for a matrix" do - Matrix[[14, 16], - [-6, -6]].eigensystem.eigenvalues.sort.map!{|x| x.round(10)}.should == - [ 2, 6 ] - end + it "returns an array of real eigenvalues for a matrix" do + Matrix[[14, 16], + [-6, -6]].eigensystem.eigenvalues.sort.map!{|x| x.round(10)}.should == + [ 2, 6 ] end end diff --git a/spec/ruby/library/matrix/eigenvalue_decomposition/eigenvector_matrix_spec.rb b/spec/ruby/library/matrix/eigenvalue_decomposition/eigenvector_matrix_spec.rb index 57299ce69e..09f229ee15 100644 --- a/spec/ruby/library/matrix/eigenvalue_decomposition/eigenvector_matrix_spec.rb +++ b/spec/ruby/library/matrix/eigenvalue_decomposition/eigenvector_matrix_spec.rb @@ -1,23 +1,20 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix::EigenvalueDecomposition#eigenvector_matrix" do - it "returns a complex eigenvector matrix given a rotation matrix" do - # Fix me: should test for linearity, not for equality - Matrix[[ 1, 1], - [-1, 1]].eigensystem.eigenvector_matrix.should == - Matrix[[1, 1], - [Complex(0, 1), Complex(0, -1)]] - end +describe "Matrix::EigenvalueDecomposition#eigenvector_matrix" do + it "returns a complex eigenvector matrix given a rotation matrix" do + # Fix me: should test for linearity, not for equality + Matrix[[ 1, 1], + [-1, 1]].eigensystem.eigenvector_matrix.should == + Matrix[[1, 1], + [Complex(0, 1), Complex(0, -1)]] + end - it "returns an real eigenvector matrix for a symmetric matrix" do - # Fix me: should test for linearity, not for equality - Matrix[[1, 2], - [2, 1]].eigensystem.eigenvector_matrix.should == - Matrix[[0.7071067811865475, 0.7071067811865475], - [-0.7071067811865475, 0.7071067811865475]] - end + it "returns an real eigenvector matrix for a symmetric matrix" do + # Fix me: should test for linearity, not for equality + Matrix[[1, 2], + [2, 1]].eigensystem.eigenvector_matrix.should == + Matrix[[0.7071067811865475, 0.7071067811865475], + [-0.7071067811865475, 0.7071067811865475]] end end diff --git a/spec/ruby/library/matrix/eigenvalue_decomposition/eigenvectors_spec.rb b/spec/ruby/library/matrix/eigenvalue_decomposition/eigenvectors_spec.rb index 54e6857bf3..2b6ce74ea8 100644 --- a/spec/ruby/library/matrix/eigenvalue_decomposition/eigenvectors_spec.rb +++ b/spec/ruby/library/matrix/eigenvalue_decomposition/eigenvectors_spec.rb @@ -1,25 +1,22 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix::EigenvalueDecomposition#eigenvectors" do - it "returns an array of complex eigenvectors for a rotation matrix" do - # Fix me: should test for linearity, not for equality - Matrix[[ 1, 1], - [-1, 1]].eigensystem.eigenvectors.should == - [ Vector[1, Complex(0, 1)], - Vector[1, Complex(0, -1)] - ] - end +describe "Matrix::EigenvalueDecomposition#eigenvectors" do + it "returns an array of complex eigenvectors for a rotation matrix" do + # Fix me: should test for linearity, not for equality + Matrix[[ 1, 1], + [-1, 1]].eigensystem.eigenvectors.should == + [ Vector[1, Complex(0, 1)], + Vector[1, Complex(0, -1)] + ] + end - it "returns an array of real eigenvectors for a symmetric matrix" do - # Fix me: should test for linearity, not for equality - Matrix[[1, 2], - [2, 1]].eigensystem.eigenvectors.should == - [ Vector[0.7071067811865475, -0.7071067811865475], - Vector[0.7071067811865475, 0.7071067811865475] - ] - end + it "returns an array of real eigenvectors for a symmetric matrix" do + # Fix me: should test for linearity, not for equality + Matrix[[1, 2], + [2, 1]].eigensystem.eigenvectors.should == + [ Vector[0.7071067811865475, -0.7071067811865475], + Vector[0.7071067811865475, 0.7071067811865475] + ] end end diff --git a/spec/ruby/library/matrix/eigenvalue_decomposition/initialize_spec.rb b/spec/ruby/library/matrix/eigenvalue_decomposition/initialize_spec.rb index 02aad65c4b..8438f63133 100644 --- a/spec/ruby/library/matrix/eigenvalue_decomposition/initialize_spec.rb +++ b/spec/ruby/library/matrix/eigenvalue_decomposition/initialize_spec.rb @@ -1,27 +1,24 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix::EigenvalueDecomposition#initialize" do - it "raises an error if argument is not a matrix" do - -> { - Matrix::EigenvalueDecomposition.new([[]]) - }.should raise_error(TypeError) - -> { - Matrix::EigenvalueDecomposition.new(42) - }.should raise_error(TypeError) - end +describe "Matrix::EigenvalueDecomposition#initialize" do + it "raises an error if argument is not a matrix" do + -> { + Matrix::EigenvalueDecomposition.new([[]]) + }.should raise_error(TypeError) + -> { + Matrix::EigenvalueDecomposition.new(42) + }.should raise_error(TypeError) + end - it "raises an error if matrix is not square" do - -> { - Matrix::EigenvalueDecomposition.new(Matrix[[1, 2]]) - }.should raise_error(Matrix::ErrDimensionMismatch) - end + it "raises an error if matrix is not square" do + -> { + Matrix::EigenvalueDecomposition.new(Matrix[[1, 2]]) + }.should raise_error(Matrix::ErrDimensionMismatch) + end - it "never hangs" do - m = Matrix[ [0,0,0,0,0], [0,0,0,0,1], [0,0,0,1,0], [1,1,0,0,1], [1,0,1,0,1] ] - Matrix::EigenvalueDecomposition.new(m).should_not == "infinite loop" - end + it "never hangs" do + m = Matrix[ [0,0,0,0,0], [0,0,0,0,1], [0,0,0,1,0], [1,1,0,0,1], [1,0,1,0,1] ] + Matrix::EigenvalueDecomposition.new(m).should_not == "infinite loop" end end diff --git a/spec/ruby/library/matrix/eigenvalue_decomposition/to_a_spec.rb b/spec/ruby/library/matrix/eigenvalue_decomposition/to_a_spec.rb index 352ae274b4..8be41a5720 100644 --- a/spec/ruby/library/matrix/eigenvalue_decomposition/to_a_spec.rb +++ b/spec/ruby/library/matrix/eigenvalue_decomposition/to_a_spec.rb @@ -1,21 +1,18 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix::EigenvalueDecomposition#to_a" do - before :each do - @a = Matrix[[14, 16], [-6, -6]] - @e = Matrix::EigenvalueDecomposition.new(@a) - end +describe "Matrix::EigenvalueDecomposition#to_a" do + before :each do + @a = Matrix[[14, 16], [-6, -6]] + @e = Matrix::EigenvalueDecomposition.new(@a) + end - it "returns an array of with [V, D, V.inv]" do - @e.to_a.should == [@e.v, @e.d, @e.v_inv] - end + it "returns an array of with [V, D, V.inv]" do + @e.to_a.should == [@e.v, @e.d, @e.v_inv] + end - it "returns a factorization" do - v, d, v_inv = @e.to_a - (v * d * v_inv).map{|e| e.round(10)}.should == @a - end + it "returns a factorization" do + v, d, v_inv = @e.to_a + (v * d * v_inv).map{|e| e.round(10)}.should == @a end end diff --git a/spec/ruby/library/matrix/element_reference_spec.rb b/spec/ruby/library/matrix/element_reference_spec.rb index 286ab851bd..b950d1c391 100644 --- a/spec/ruby/library/matrix/element_reference_spec.rb +++ b/spec/ruby/library/matrix/element_reference_spec.rb @@ -1,26 +1,23 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' +describe "Matrix#[]" do - describe "Matrix#[]" do - - before :all do - @m = Matrix[[0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10, 11]] - end + before :all do + @m = Matrix[[0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10, 11]] + end - it "returns element at (i, j)" do - (0..3).each do |i| - (0..2).each do |j| - @m[i, j].should == (i * 3) + j - end + it "returns element at (i, j)" do + (0..3).each do |i| + (0..2).each do |j| + @m[i, j].should == (i * 3) + j end end + end - it "returns nil for an invalid index pair" do - @m[8,1].should be_nil - @m[1,8].should be_nil - end - + it "returns nil for an invalid index pair" do + @m[8,1].should be_nil + @m[1,8].should be_nil end + end diff --git a/spec/ruby/library/matrix/empty_spec.rb b/spec/ruby/library/matrix/empty_spec.rb index 0b5d5ffe0f..5f294711db 100644 --- a/spec/ruby/library/matrix/empty_spec.rb +++ b/spec/ruby/library/matrix/empty_spec.rb @@ -1,71 +1,68 @@ require_relative '../../spec_helper' +require_relative 'fixtures/classes' +require 'matrix' -ruby_version_is ""..."3.1" do - require_relative 'fixtures/classes' - require 'matrix' - - describe "Matrix#empty?" do - it "returns true when the Matrix is empty" do - Matrix[ ].empty?.should be_true - Matrix[ [], [], [] ].empty?.should be_true - Matrix[ [], [], [] ].transpose.empty?.should be_true - end - - it "returns false when the Matrix has elements" do - Matrix[ [1, 2] ].empty?.should be_false - Matrix[ [1], [2] ].empty?.should be_false - end +describe "Matrix#empty?" do + it "returns true when the Matrix is empty" do + Matrix[ ].empty?.should be_true + Matrix[ [], [], [] ].empty?.should be_true + Matrix[ [], [], [] ].transpose.empty?.should be_true + end - it "doesn't accept any parameter" do - ->{ - Matrix[ [1, 2] ].empty?(42) - }.should raise_error(ArgumentError) - end + it "returns false when the Matrix has elements" do + Matrix[ [1, 2] ].empty?.should be_false + Matrix[ [1], [2] ].empty?.should be_false end - describe "Matrix.empty" do - it "returns an empty matrix of the requested size" do - m = Matrix.empty(3, 0) - m.row_size.should == 3 - m.column_size.should == 0 + it "doesn't accept any parameter" do + ->{ + Matrix[ [1, 2] ].empty?(42) + }.should raise_error(ArgumentError) + end +end - m = Matrix.empty(0, 3) - m.row_size.should == 0 - m.column_size.should == 3 - end +describe "Matrix.empty" do + it "returns an empty matrix of the requested size" do + m = Matrix.empty(3, 0) + m.row_size.should == 3 + m.column_size.should == 0 - it "has arguments defaulting to 0" do - Matrix.empty.should == Matrix.empty(0, 0) - Matrix.empty(42).should == Matrix.empty(42, 0) - end + m = Matrix.empty(0, 3) + m.row_size.should == 0 + m.column_size.should == 3 + end - it "does not accept more than two parameters" do - ->{ - Matrix.empty(1, 2, 3) - }.should raise_error(ArgumentError) - end + it "has arguments defaulting to 0" do + Matrix.empty.should == Matrix.empty(0, 0) + Matrix.empty(42).should == Matrix.empty(42, 0) + end - it "raises an error if both dimensions are > 0" do - ->{ - Matrix.empty(1, 2) - }.should raise_error(ArgumentError) - end + it "does not accept more than two parameters" do + ->{ + Matrix.empty(1, 2, 3) + }.should raise_error(ArgumentError) + end - it "raises an error if any dimension is < 0" do - ->{ - Matrix.empty(-2, 0) - }.should raise_error(ArgumentError) + it "raises an error if both dimensions are > 0" do + ->{ + Matrix.empty(1, 2) + }.should raise_error(ArgumentError) + end - ->{ - Matrix.empty(0, -2) - }.should raise_error(ArgumentError) - end + it "raises an error if any dimension is < 0" do + ->{ + Matrix.empty(-2, 0) + }.should raise_error(ArgumentError) + ->{ + Matrix.empty(0, -2) + }.should raise_error(ArgumentError) end - describe "for a subclass of Matrix" do - it "returns an instance of that subclass" do - MatrixSub.empty(0, 1).should be_an_instance_of(MatrixSub) - end +end + +describe "for a subclass of Matrix" do + it "returns an instance of that subclass" do + MatrixSub.empty(0, 1).should be_an_instance_of(MatrixSub) end end diff --git a/spec/ruby/library/matrix/eql_spec.rb b/spec/ruby/library/matrix/eql_spec.rb index d3f03dd6f3..ea26c3320d 100644 --- a/spec/ruby/library/matrix/eql_spec.rb +++ b/spec/ruby/library/matrix/eql_spec.rb @@ -1,14 +1,11 @@ require_relative '../../spec_helper' +require_relative 'shared/equal_value' +require 'matrix' -ruby_version_is ""..."3.1" do - require_relative 'shared/equal_value' - require 'matrix' +describe "Matrix#eql?" do + it_behaves_like :equal, :eql? - describe "Matrix#eql?" do - it_behaves_like :equal, :eql? - - it "returns false if some elements are == but not eql?" do - Matrix[[1, 2],[3, 4]].eql?(Matrix[[1, 2],[3, 4.0]]).should be_false - end + it "returns false if some elements are == but not eql?" do + Matrix[[1, 2],[3, 4]].eql?(Matrix[[1, 2],[3, 4.0]]).should be_false end end diff --git a/spec/ruby/library/matrix/equal_value_spec.rb b/spec/ruby/library/matrix/equal_value_spec.rb index 0408a8ef3e..10cf1e6c29 100644 --- a/spec/ruby/library/matrix/equal_value_spec.rb +++ b/spec/ruby/library/matrix/equal_value_spec.rb @@ -1,14 +1,11 @@ require_relative '../../spec_helper' +require_relative 'shared/equal_value' +require 'matrix' -ruby_version_is ""..."3.1" do - require_relative 'shared/equal_value' - require 'matrix' +describe "Matrix#==" do + it_behaves_like :equal, :== - describe "Matrix#==" do - it_behaves_like :equal, :== - - it "returns true if some elements are == but not eql?" do - Matrix[[1, 2],[3, 4]].should == Matrix[[1, 2],[3, 4.0]] - end + it "returns true if some elements are == but not eql?" do + Matrix[[1, 2],[3, 4]].should == Matrix[[1, 2],[3, 4.0]] end end diff --git a/spec/ruby/library/matrix/exponent_spec.rb b/spec/ruby/library/matrix/exponent_spec.rb index 5262627fd5..38cdfa9276 100644 --- a/spec/ruby/library/matrix/exponent_spec.rb +++ b/spec/ruby/library/matrix/exponent_spec.rb @@ -1,67 +1,62 @@ require_relative '../../spec_helper' +require_relative 'fixtures/classes' +require 'matrix' + +describe "Matrix#**" do + + describe "given an integer _n_" do + it "multiples the Matrix by itself _n_ times" do + m = Matrix[ [7,6], [3,9] ] + (m ** 1).should == m + (m ** 2).should == Matrix[ [67, 96], [48,99] ] + (m ** 2).should == m * m + (m ** 3).should == m * m * m + (m ** 4).should == m * m * m * m + (m ** 5).should == m * m * m * m * m + end -ruby_version_is ""..."3.1" do - require_relative 'fixtures/classes' - require 'matrix' - - describe "Matrix#**" do + it "raises a ErrDimensionMismatch for non square matrices" do + m = Matrix[ [1, 1], [1, 2], [2, 3]] + -> { m ** 3 }.should raise_error(Matrix::ErrDimensionMismatch) + -> { m ** 0 }.should raise_error(Matrix::ErrDimensionMismatch) + end - describe "given an integer _n_" do - it "multiples the Matrix by itself _n_ times" do - m = Matrix[ [7,6], [3,9] ] - (m ** 1).should == m - (m ** 2).should == Matrix[ [67, 96], [48,99] ] - (m ** 2).should == m * m - (m ** 3).should == m * m * m - (m ** 4).should == m * m * m * m - (m ** 5).should == m * m * m * m * m + describe "that is < 0" do + it "returns the inverse of **(-n)" do + m = Matrix[ [1, 1], [1, 2] ] + (m ** -2).should == Matrix[ [5, -3], [-3, 2]] + (m ** -4).should == (m.inverse ** 4) end - it "raises a ErrDimensionMismatch for non square matrices" do - m = Matrix[ [1, 1], [1, 2], [2, 3]] - -> { m ** 3 }.should raise_error(Matrix::ErrDimensionMismatch) - -> { m ** 0 }.should raise_error(Matrix::ErrDimensionMismatch) + it "raises a ErrNotRegular for irregular matrices" do + m = Matrix[ [1, 1], [1, 1] ] + -> { m ** -2 }.should raise_error(Matrix::ErrNotRegular) end + end - describe "that is < 0" do - it "returns the inverse of **(-n)" do - m = Matrix[ [1, 1], [1, 2] ] - (m ** -2).should == Matrix[ [5, -3], [-3, 2]] - (m ** -4).should == (m.inverse ** 4) - end - - it "raises a ErrNotRegular for irregular matrices" do - m = Matrix[ [1, 1], [1, 1] ] - -> { m ** -2 }.should raise_error(Matrix::ErrNotRegular) - end + describe "that is 0" do + it "returns the identity for square matrices" do + m = Matrix[ [1, 1], [1, 1] ] + (m ** 0).should == Matrix.identity(2) end - ruby_version_is '3.1.0' do # https://bugs.ruby-lang.org/issues/17521 - describe "that is 0" do - it "returns the identity for square matrices" do - m = Matrix[ [1, 1], [1, 1] ] - (m ** 0).should == Matrix.identity(2) - end - - it "raises an ErrDimensionMismatch for non-square matrices" do - m = Matrix[ [1, 1] ] - -> { m ** 0 }.should raise_error(Matrix::ErrDimensionMismatch) - end - end + it "raises an ErrDimensionMismatch for non-square matrices" do + m = Matrix[ [1, 1] ] + -> { m ** 0 }.should raise_error(Matrix::ErrDimensionMismatch) end end + end - it "returns the power for non integer powers" do - a = Matrix[[5, 4], [4, 5]] - ((a ** 0.5) ** 2).round(8).should == a - a = Matrix[[7, 10], [15, 22]] - ((a ** 0.25) ** 4).round(8).should == a - end + it "returns the power for non integer powers" do + a = Matrix[[5, 4], [4, 5]] + ((a ** 0.5) ** 2).round(8).should == a + a = Matrix[[7, 10], [15, 22]] + ((a ** 0.25) ** 4).round(8).should == a + end - describe "for a subclass of Matrix" do - it "returns an instance of that subclass" do - (MatrixSub.ins ** 1).should be_an_instance_of(MatrixSub) - end + describe "for a subclass of Matrix" do + it "returns an instance of that subclass" do + (MatrixSub.ins ** 1).should be_an_instance_of(MatrixSub) end end end diff --git a/spec/ruby/library/matrix/find_index_spec.rb b/spec/ruby/library/matrix/find_index_spec.rb index a0e3679aef..c2bfa6d61a 100644 --- a/spec/ruby/library/matrix/find_index_spec.rb +++ b/spec/ruby/library/matrix/find_index_spec.rb @@ -1,149 +1,146 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix#find_index without any argument" do - before :all do - @m = Matrix[ [1, 2, 3, 4], [5, 6, 7, 8] ] - end +describe "Matrix#find_index without any argument" do + before :all do + @m = Matrix[ [1, 2, 3, 4], [5, 6, 7, 8] ] + end - it "returns an Enumerator when called without a block" do - enum = @m.find_index - enum.should be_an_instance_of(Enumerator) - enum.to_a.should == [1, 2, 3, 4, 5, 6, 7, 8] - end + it "returns an Enumerator when called without a block" do + enum = @m.find_index + enum.should be_an_instance_of(Enumerator) + enum.to_a.should == [1, 2, 3, 4, 5, 6, 7, 8] + end - it "returns nil if the block is always false" do - @m.find_index{false}.should be_nil - end + it "returns nil if the block is always false" do + @m.find_index{false}.should be_nil + end - it "returns the first index for which the block is true" do - @m.find_index{|x| x >= 3}.should == [0, 2] - end + it "returns the first index for which the block is true" do + @m.find_index{|x| x >= 3}.should == [0, 2] end +end - describe "Matrix#find_index with a subselection argument" do - before :all do - @tests = [ - [ Matrix[ [1, 2, 3, 4], [5, 6, 7, 8] ], { - diagonal: [1, 6] , - off_diagonal: [2, 3, 4, 5, 7, 8], - lower: [1, 5, 6] , - strict_lower: [5] , - strict_upper: [2, 3, 4, 7, 8] , - upper: [1, 2, 3, 4, 6, 7, 8] , - } - ], - [ Matrix[ [1, 2], [3, 4], [5, 6], [7, 8] ], { - diagonal: [1, 4] , - off_diagonal: [2, 3, 5, 6, 7, 8], - lower: [1, 3, 4, 5, 6, 7, 8] , - strict_lower: [3, 5, 6, 7, 8] , - strict_upper: [2] , - upper: [1, 2, 4] , - } - ]] - end +describe "Matrix#find_index with a subselection argument" do + before :all do + @tests = [ + [ Matrix[ [1, 2, 3, 4], [5, 6, 7, 8] ], { + diagonal: [1, 6] , + off_diagonal: [2, 3, 4, 5, 7, 8], + lower: [1, 5, 6] , + strict_lower: [5] , + strict_upper: [2, 3, 4, 7, 8] , + upper: [1, 2, 3, 4, 6, 7, 8] , + } + ], + [ Matrix[ [1, 2], [3, 4], [5, 6], [7, 8] ], { + diagonal: [1, 4] , + off_diagonal: [2, 3, 5, 6, 7, 8], + lower: [1, 3, 4, 5, 6, 7, 8] , + strict_lower: [3, 5, 6, 7, 8] , + strict_upper: [2] , + upper: [1, 2, 4] , + } + ]] + end - describe "and no generic argument" do - it "returns an Enumerator when called without a block" do - @tests.each do |matrix, h| - h.each do |selector, result| - matrix.find_index(selector).should be_an_instance_of(Enumerator) - end + describe "and no generic argument" do + it "returns an Enumerator when called without a block" do + @tests.each do |matrix, h| + h.each do |selector, result| + matrix.find_index(selector).should be_an_instance_of(Enumerator) end end + end - it "yields the rights elements" do - @tests.each do |matrix, h| - h.each do |selector, result| - matrix.find_index(selector).to_a.should == result - end + it "yields the rights elements" do + @tests.each do |matrix, h| + h.each do |selector, result| + matrix.find_index(selector).to_a.should == result end end + end - it "returns the first index for which the block returns true" do - @tests.each do |matrix, h| - h.each do |selector, result| - cnt = result.size.div 2 - which = result[cnt] - idx = matrix.find_index(selector){|x| cnt -= 1; x == which} - matrix[*idx].should == which - cnt.should == -1 - end + it "returns the first index for which the block returns true" do + @tests.each do |matrix, h| + h.each do |selector, result| + cnt = result.size.div 2 + which = result[cnt] + idx = matrix.find_index(selector){|x| cnt -= 1; x == which} + matrix[*idx].should == which + cnt.should == -1 end end + end - it "returns nil if the block is always false" do - @tests.each do |matrix, h| - h.each do |selector, result| - matrix.find_index(selector){ nil }.should == nil - end + it "returns nil if the block is always false" do + @tests.each do |matrix, h| + h.each do |selector, result| + matrix.find_index(selector){ nil }.should == nil end end - end - describe "and a generic argument" do - it "ignores a block" do - @m.find_index(42, :diagonal){raise "oups"}.should == nil - end + end + + describe "and a generic argument" do + it "ignores a block" do + @m.find_index(42, :diagonal){raise "oups"}.should == nil + end - it "returns the index of the requested value" do - @tests.each do |matrix, h| - h.each do |selector, result| - cnt = result.size / 2 - which = result[cnt] - idx = matrix.find_index(which, selector) - matrix[*idx].should == which - end + it "returns the index of the requested value" do + @tests.each do |matrix, h| + h.each do |selector, result| + cnt = result.size / 2 + which = result[cnt] + idx = matrix.find_index(which, selector) + matrix[*idx].should == which end end + end - it "returns nil if the requested value is not found" do - @tests.each do |matrix, h| - h.each do |selector, result| - matrix.find_index(42, selector).should == nil - end + it "returns nil if the requested value is not found" do + @tests.each do |matrix, h| + h.each do |selector, result| + matrix.find_index(42, selector).should == nil end end end - end - describe "Matrix#find_index with only a generic argument" do - before :all do - @m = Matrix[ [1, 2, 3, 4], [1, 2, 3, 4] ] - end +end - it "returns nil if the value is not found" do - @m.find_index(42).should be_nil - end +describe "Matrix#find_index with only a generic argument" do + before :all do + @m = Matrix[ [1, 2, 3, 4], [1, 2, 3, 4] ] + end - it "returns the first index for of the requested value" do - @m.find_index(3).should == [0, 2] - end + it "returns nil if the value is not found" do + @m.find_index(42).should be_nil + end - it "ignores a block" do - @m.find_index(4){raise "oups"}.should == [0, 3] - end + it "returns the first index for of the requested value" do + @m.find_index(3).should == [0, 2] end - describe "Matrix#find_index with two arguments" do - it "raises an ArgumentError for an unrecognized last argument" do - -> { - @m.find_index(1, "all"){} - }.should raise_error(ArgumentError) - -> { - @m.find_index(1, nil){} - }.should raise_error(ArgumentError) - -> { - @m.find_index(1, :left){} - }.should raise_error(ArgumentError) - -> { - @m.find_index(:diagonal, 1){} - }.should raise_error(ArgumentError) - end + it "ignores a block" do + @m.find_index(4){raise "oups"}.should == [0, 3] + end +end + +describe "Matrix#find_index with two arguments" do + it "raises an ArgumentError for an unrecognized last argument" do + -> { + @m.find_index(1, "all"){} + }.should raise_error(ArgumentError) + -> { + @m.find_index(1, nil){} + }.should raise_error(ArgumentError) + -> { + @m.find_index(1, :left){} + }.should raise_error(ArgumentError) + -> { + @m.find_index(:diagonal, 1){} + }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/library/matrix/hash_spec.rb b/spec/ruby/library/matrix/hash_spec.rb index 7c1970511b..7dabcd3737 100644 --- a/spec/ruby/library/matrix/hash_spec.rb +++ b/spec/ruby/library/matrix/hash_spec.rb @@ -1,18 +1,15 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' +describe "Matrix#hash" do - describe "Matrix#hash" do - - it "returns an Integer" do - Matrix[ [1,2] ].hash.should be_an_instance_of(Integer) - end - - it "returns the same value for the same matrix" do - data = [ [40,5], [2,7] ] - Matrix[ *data ].hash.should == Matrix[ *data ].hash - end + it "returns an Integer" do + Matrix[ [1,2] ].hash.should be_an_instance_of(Integer) + end + it "returns the same value for the same matrix" do + data = [ [40,5], [2,7] ] + Matrix[ *data ].hash.should == Matrix[ *data ].hash end + end diff --git a/spec/ruby/library/matrix/hermitian_spec.rb b/spec/ruby/library/matrix/hermitian_spec.rb index 4038ee3fa9..177ca64d83 100644 --- a/spec/ruby/library/matrix/hermitian_spec.rb +++ b/spec/ruby/library/matrix/hermitian_spec.rb @@ -1,37 +1,34 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix.hermitian?" do - it "returns true for a hermitian Matrix" do - Matrix[[1, 2, Complex(0, 3)], [2, 4, 5], [Complex(0, -3), 5, 6]].hermitian?.should be_true - end +describe "Matrix.hermitian?" do + it "returns true for a hermitian Matrix" do + Matrix[[1, 2, Complex(0, 3)], [2, 4, 5], [Complex(0, -3), 5, 6]].hermitian?.should be_true + end - it "returns true for a 0x0 empty matrix" do - Matrix.empty.hermitian?.should be_true - end + it "returns true for a 0x0 empty matrix" do + Matrix.empty.hermitian?.should be_true + end - it "returns false for an asymmetric Matrix" do - Matrix[[1, 2],[-2, 1]].hermitian?.should be_false - end + it "returns false for an asymmetric Matrix" do + Matrix[[1, 2],[-2, 1]].hermitian?.should be_false + end - it "raises an error for rectangular matrices" do - [ - Matrix[[0], [0]], - Matrix[[0, 0]], - Matrix.empty(0, 2), - Matrix.empty(2, 0), - ].each do |rectangular_matrix| - -> { - rectangular_matrix.hermitian? - }.should raise_error(Matrix::ErrDimensionMismatch) - end + it "raises an error for rectangular matrices" do + [ + Matrix[[0], [0]], + Matrix[[0, 0]], + Matrix.empty(0, 2), + Matrix.empty(2, 0), + ].each do |rectangular_matrix| + -> { + rectangular_matrix.hermitian? + }.should raise_error(Matrix::ErrDimensionMismatch) end + end - it "returns false for a matrix with complex values on the diagonal" do - Matrix[[Complex(1,1)]].hermitian?.should be_false - Matrix[[Complex(1,0)]].hermitian?.should be_true - end + it "returns false for a matrix with complex values on the diagonal" do + Matrix[[Complex(1,1)]].hermitian?.should be_false + Matrix[[Complex(1,0)]].hermitian?.should be_true end end diff --git a/spec/ruby/library/matrix/identity_spec.rb b/spec/ruby/library/matrix/identity_spec.rb index 14f51c402e..646462bc47 100644 --- a/spec/ruby/library/matrix/identity_spec.rb +++ b/spec/ruby/library/matrix/identity_spec.rb @@ -1,9 +1,6 @@ require_relative '../../spec_helper' +require_relative 'shared/identity' -ruby_version_is ""..."3.1" do - require_relative 'shared/identity' - - describe "Matrix.identity" do - it_behaves_like :matrix_identity, :identity - end +describe "Matrix.identity" do + it_behaves_like :matrix_identity, :identity end diff --git a/spec/ruby/library/matrix/imag_spec.rb b/spec/ruby/library/matrix/imag_spec.rb index a89186ec02..1c988753d8 100644 --- a/spec/ruby/library/matrix/imag_spec.rb +++ b/spec/ruby/library/matrix/imag_spec.rb @@ -1,9 +1,6 @@ require_relative '../../spec_helper' +require_relative 'shared/imaginary' -ruby_version_is ""..."3.1" do - require_relative 'shared/imaginary' - - describe "Matrix#imag" do - it_behaves_like :matrix_imaginary, :imag - end +describe "Matrix#imag" do + it_behaves_like :matrix_imaginary, :imag end diff --git a/spec/ruby/library/matrix/imaginary_spec.rb b/spec/ruby/library/matrix/imaginary_spec.rb index e7f0e49d31..ceae4bbe8d 100644 --- a/spec/ruby/library/matrix/imaginary_spec.rb +++ b/spec/ruby/library/matrix/imaginary_spec.rb @@ -1,9 +1,6 @@ require_relative '../../spec_helper' +require_relative 'shared/imaginary' -ruby_version_is ""..."3.1" do - require_relative 'shared/imaginary' - - describe "Matrix#imaginary" do - it_behaves_like :matrix_imaginary, :imaginary - end +describe "Matrix#imaginary" do + it_behaves_like :matrix_imaginary, :imaginary end diff --git a/spec/ruby/library/matrix/inspect_spec.rb b/spec/ruby/library/matrix/inspect_spec.rb index d754c0fe7f..508f478252 100644 --- a/spec/ruby/library/matrix/inspect_spec.rb +++ b/spec/ruby/library/matrix/inspect_spec.rb @@ -1,30 +1,27 @@ require_relative '../../spec_helper' +require_relative 'fixtures/classes' +require 'matrix' -ruby_version_is ""..."3.1" do - require_relative 'fixtures/classes' - require 'matrix' +describe "Matrix#inspect" do - describe "Matrix#inspect" do - - it "returns a stringified representation of the Matrix" do - Matrix[ [1,2], [2,1] ].inspect.should == "Matrix[[1, 2], [2, 1]]" - end + it "returns a stringified representation of the Matrix" do + Matrix[ [1,2], [2,1] ].inspect.should == "Matrix[[1, 2], [2, 1]]" + end - it "returns 'Matrix.empty(...)' for empty matrices" do - Matrix[ [], [], [] ].inspect.should == "Matrix.empty(3, 0)" - Matrix.columns([ [], [], [] ]).inspect.should == "Matrix.empty(0, 3)" - end + it "returns 'Matrix.empty(...)' for empty matrices" do + Matrix[ [], [], [] ].inspect.should == "Matrix.empty(3, 0)" + Matrix.columns([ [], [], [] ]).inspect.should == "Matrix.empty(0, 3)" + end - it "calls inspect on its contents" do - obj = mock("some_value") - obj.should_receive(:inspect).and_return("some_value") - Matrix[ [1, 2], [3, obj] ].inspect.should == "Matrix[[1, 2], [3, some_value]]" - end + it "calls inspect on its contents" do + obj = mock("some_value") + obj.should_receive(:inspect).and_return("some_value") + Matrix[ [1, 2], [3, obj] ].inspect.should == "Matrix[[1, 2], [3, some_value]]" + end - describe "for a subclass of Matrix" do - it "returns a string using the subclass' name" do - MatrixSub.ins.inspect.should == "MatrixSub[[1, 0], [0, 1]]" - end + describe "for a subclass of Matrix" do + it "returns a string using the subclass' name" do + MatrixSub.ins.inspect.should == "MatrixSub[[1, 0], [0, 1]]" end end end diff --git a/spec/ruby/library/matrix/inv_spec.rb b/spec/ruby/library/matrix/inv_spec.rb index 0ad817a253..82879a6d82 100644 --- a/spec/ruby/library/matrix/inv_spec.rb +++ b/spec/ruby/library/matrix/inv_spec.rb @@ -1,10 +1,7 @@ require_relative '../../spec_helper' +require_relative 'spec_helper' +require_relative 'shared/inverse' -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - require_relative 'shared/inverse' - - describe "Matrix#inv" do - it_behaves_like :inverse, :inv - end +describe "Matrix#inv" do + it_behaves_like :inverse, :inv end diff --git a/spec/ruby/library/matrix/inverse_from_spec.rb b/spec/ruby/library/matrix/inverse_from_spec.rb index bca40542f6..651d56a244 100644 --- a/spec/ruby/library/matrix/inverse_from_spec.rb +++ b/spec/ruby/library/matrix/inverse_from_spec.rb @@ -1,9 +1,6 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix#inverse_from" do - it "needs to be reviewed for spec completeness" - end +describe "Matrix#inverse_from" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/matrix/inverse_spec.rb b/spec/ruby/library/matrix/inverse_spec.rb index dd9099bec5..fa3fa7de8a 100644 --- a/spec/ruby/library/matrix/inverse_spec.rb +++ b/spec/ruby/library/matrix/inverse_spec.rb @@ -1,10 +1,7 @@ require_relative '../../spec_helper' +require_relative 'spec_helper' +require_relative 'shared/inverse' -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - require_relative 'shared/inverse' - - describe "Matrix#inverse" do - it_behaves_like :inverse, :inverse - end +describe "Matrix#inverse" do + it_behaves_like :inverse, :inverse end diff --git a/spec/ruby/library/matrix/lower_triangular_spec.rb b/spec/ruby/library/matrix/lower_triangular_spec.rb index 0223b8b619..f3aa4501f4 100644 --- a/spec/ruby/library/matrix/lower_triangular_spec.rb +++ b/spec/ruby/library/matrix/lower_triangular_spec.rb @@ -1,27 +1,24 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix.lower_triangular?" do - it "returns true for a square lower triangular Matrix" do - Matrix[[1, 0, 0], [1, 2, 0], [1, 2, 3]].lower_triangular?.should be_true - Matrix.diagonal([1, 2, 3]).lower_triangular?.should be_true - Matrix[[1, 0], [1, 2], [1, 2], [1, 2]].lower_triangular?.should be_true - Matrix[[1, 0, 0, 0], [1, 2, 0, 0]].lower_triangular?.should be_true - end +describe "Matrix.lower_triangular?" do + it "returns true for a square lower triangular Matrix" do + Matrix[[1, 0, 0], [1, 2, 0], [1, 2, 3]].lower_triangular?.should be_true + Matrix.diagonal([1, 2, 3]).lower_triangular?.should be_true + Matrix[[1, 0], [1, 2], [1, 2], [1, 2]].lower_triangular?.should be_true + Matrix[[1, 0, 0, 0], [1, 2, 0, 0]].lower_triangular?.should be_true + end - it "returns true for an empty Matrix" do - Matrix.empty(3, 0).lower_triangular?.should be_true - Matrix.empty(0, 3).lower_triangular?.should be_true - Matrix.empty(0, 0).lower_triangular?.should be_true - end + it "returns true for an empty Matrix" do + Matrix.empty(3, 0).lower_triangular?.should be_true + Matrix.empty(0, 3).lower_triangular?.should be_true + Matrix.empty(0, 0).lower_triangular?.should be_true + end - it "returns false for a non lower triangular square Matrix" do - Matrix[[0, 1], [0, 0]].lower_triangular?.should be_false - Matrix[[1, 2, 3], [1, 2, 3], [1, 2, 3]].lower_triangular?.should be_false - Matrix[[0, 1], [0, 0], [0, 0], [0, 0]].lower_triangular?.should be_false - Matrix[[0, 0, 0, 1], [0, 0, 0, 0]].lower_triangular?.should be_false - end + it "returns false for a non lower triangular square Matrix" do + Matrix[[0, 1], [0, 0]].lower_triangular?.should be_false + Matrix[[1, 2, 3], [1, 2, 3], [1, 2, 3]].lower_triangular?.should be_false + Matrix[[0, 1], [0, 0], [0, 0], [0, 0]].lower_triangular?.should be_false + Matrix[[0, 0, 0, 1], [0, 0, 0, 0]].lower_triangular?.should be_false end end diff --git a/spec/ruby/library/matrix/lup_decomposition/determinant_spec.rb b/spec/ruby/library/matrix/lup_decomposition/determinant_spec.rb index 1ac4bc971e..9d733066c1 100644 --- a/spec/ruby/library/matrix/lup_decomposition/determinant_spec.rb +++ b/spec/ruby/library/matrix/lup_decomposition/determinant_spec.rb @@ -1,24 +1,21 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix::LUPDecomposition#determinant" do - it "returns the determinant when the matrix is square" do - a = Matrix[[7, 8, 9], [14, 46, 51], [28, 82, 163]] - a.lup.determinant.should == 15120 # == a.determinant - end +describe "Matrix::LUPDecomposition#determinant" do + it "returns the determinant when the matrix is square" do + a = Matrix[[7, 8, 9], [14, 46, 51], [28, 82, 163]] + a.lup.determinant.should == 15120 # == a.determinant + end - it "raises an error for rectangular matrices" do - [ - Matrix[[7, 8, 9], [14, 46, 51]], - Matrix[[7, 8], [14, 46], [28, 82]], - ].each do |m| - lup = m.lup - -> { - lup.determinant - }.should raise_error(Matrix::ErrDimensionMismatch) - end + it "raises an error for rectangular matrices" do + [ + Matrix[[7, 8, 9], [14, 46, 51]], + Matrix[[7, 8], [14, 46], [28, 82]], + ].each do |m| + lup = m.lup + -> { + lup.determinant + }.should raise_error(Matrix::ErrDimensionMismatch) end end end diff --git a/spec/ruby/library/matrix/lup_decomposition/initialize_spec.rb b/spec/ruby/library/matrix/lup_decomposition/initialize_spec.rb index 42f78c7540..36afb349e6 100644 --- a/spec/ruby/library/matrix/lup_decomposition/initialize_spec.rb +++ b/spec/ruby/library/matrix/lup_decomposition/initialize_spec.rb @@ -1,16 +1,13 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix::LUPDecomposition#initialize" do - it "raises an error if argument is not a matrix" do - -> { - Matrix::LUPDecomposition.new([[]]) - }.should raise_error(TypeError) - -> { - Matrix::LUPDecomposition.new(42) - }.should raise_error(TypeError) - end +describe "Matrix::LUPDecomposition#initialize" do + it "raises an error if argument is not a matrix" do + -> { + Matrix::LUPDecomposition.new([[]]) + }.should raise_error(TypeError) + -> { + Matrix::LUPDecomposition.new(42) + }.should raise_error(TypeError) end end diff --git a/spec/ruby/library/matrix/lup_decomposition/l_spec.rb b/spec/ruby/library/matrix/lup_decomposition/l_spec.rb index 6c751f12b7..9514ab5d06 100644 --- a/spec/ruby/library/matrix/lup_decomposition/l_spec.rb +++ b/spec/ruby/library/matrix/lup_decomposition/l_spec.rb @@ -1,21 +1,18 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix::LUPDecomposition#l" do - before :each do - @a = Matrix[[7, 8, 9], [14, 46, 51], [28, 82, 163]] - @lu = Matrix::LUPDecomposition.new(@a) - @l = @lu.l - end +describe "Matrix::LUPDecomposition#l" do + before :each do + @a = Matrix[[7, 8, 9], [14, 46, 51], [28, 82, 163]] + @lu = Matrix::LUPDecomposition.new(@a) + @l = @lu.l + end - it "returns the first element of to_a" do - @l.should == @lu.to_a[0] - end + it "returns the first element of to_a" do + @l.should == @lu.to_a[0] + end - it "returns a lower triangular matrix" do - @l.lower_triangular?.should be_true - end + it "returns a lower triangular matrix" do + @l.lower_triangular?.should be_true end end diff --git a/spec/ruby/library/matrix/lup_decomposition/p_spec.rb b/spec/ruby/library/matrix/lup_decomposition/p_spec.rb index 481f8a17d5..c7b5e9196e 100644 --- a/spec/ruby/library/matrix/lup_decomposition/p_spec.rb +++ b/spec/ruby/library/matrix/lup_decomposition/p_spec.rb @@ -1,21 +1,18 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix::LUPDecomposition#p" do - before :each do - @a = Matrix[[7, 8, 9], [14, 46, 51], [28, 82, 163]] - @lu = Matrix::LUPDecomposition.new(@a) - @p = @lu.p - end +describe "Matrix::LUPDecomposition#p" do + before :each do + @a = Matrix[[7, 8, 9], [14, 46, 51], [28, 82, 163]] + @lu = Matrix::LUPDecomposition.new(@a) + @p = @lu.p + end - it "returns the third element of to_a" do - @p.should == @lu.to_a[2] - end + it "returns the third element of to_a" do + @p.should == @lu.to_a[2] + end - it "returns a permutation matrix" do - @p.permutation?.should be_true - end + it "returns a permutation matrix" do + @p.permutation?.should be_true end end diff --git a/spec/ruby/library/matrix/lup_decomposition/solve_spec.rb b/spec/ruby/library/matrix/lup_decomposition/solve_spec.rb index 773fcb3e65..66242627e9 100644 --- a/spec/ruby/library/matrix/lup_decomposition/solve_spec.rb +++ b/spec/ruby/library/matrix/lup_decomposition/solve_spec.rb @@ -1,55 +1,52 @@ require_relative '../../../spec_helper' +require 'matrix' + +describe "Matrix::LUPDecomposition#solve" do + describe "for rectangular matrices" do + it "raises an error for singular matrices" do + a = Matrix[[1, 2, 3], [1, 3, 5], [2, 5, 8]] + lu = Matrix::LUPDecomposition.new(a) + -> { + lu.solve(a) + }.should raise_error(Matrix::ErrNotRegular) + end -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix::LUPDecomposition#solve" do - describe "for rectangular matrices" do - it "raises an error for singular matrices" do - a = Matrix[[1, 2, 3], [1, 3, 5], [2, 5, 8]] - lu = Matrix::LUPDecomposition.new(a) - -> { - lu.solve(a) - }.should raise_error(Matrix::ErrNotRegular) + describe "for non singular matrices" do + before :each do + @a = Matrix[[7, 8, 9], [14, 46, 51], [28, 82, 163]] + @lu = Matrix::LUPDecomposition.new(@a) end - describe "for non singular matrices" do - before :each do - @a = Matrix[[7, 8, 9], [14, 46, 51], [28, 82, 163]] - @lu = Matrix::LUPDecomposition.new(@a) - end - - it "returns the appropriate empty matrix when given an empty matrix" do - @lu.solve(Matrix.empty(3,0)).should == Matrix.empty(3,0) - empty = Matrix::LUPDecomposition.new(Matrix.empty(0, 0)) - empty.solve(Matrix.empty(0,3)).should == Matrix.empty(0,3) - end + it "returns the appropriate empty matrix when given an empty matrix" do + @lu.solve(Matrix.empty(3,0)).should == Matrix.empty(3,0) + empty = Matrix::LUPDecomposition.new(Matrix.empty(0, 0)) + empty.solve(Matrix.empty(0,3)).should == Matrix.empty(0,3) + end - it "returns the right matrix when given a matrix of the appropriate size" do - solution = Matrix[[1, 2, 3, 4], [0, 1, 2, 3], [-1, -2, -3, -4]] - values = Matrix[[-2, 4, 10, 16], [-37, -28, -19, -10], [-135, -188, -241, -294]] # == @a * solution - @lu.solve(values).should == solution - end + it "returns the right matrix when given a matrix of the appropriate size" do + solution = Matrix[[1, 2, 3, 4], [0, 1, 2, 3], [-1, -2, -3, -4]] + values = Matrix[[-2, 4, 10, 16], [-37, -28, -19, -10], [-135, -188, -241, -294]] # == @a * solution + @lu.solve(values).should == solution + end - it "raises an error when given a matrix of the wrong size" do - values = Matrix[[1, 2, 3, 4], [0, 1, 2, 3]] - -> { - @lu.solve(values) - }.should raise_error(Matrix::ErrDimensionMismatch) - end + it "raises an error when given a matrix of the wrong size" do + values = Matrix[[1, 2, 3, 4], [0, 1, 2, 3]] + -> { + @lu.solve(values) + }.should raise_error(Matrix::ErrDimensionMismatch) + end - it "returns the right vector when given a vector of the appropriate size" do - solution = Vector[1, 2, -1] - values = Vector[14, 55, 29] # == @a * solution - @lu.solve(values).should == solution - end + it "returns the right vector when given a vector of the appropriate size" do + solution = Vector[1, 2, -1] + values = Vector[14, 55, 29] # == @a * solution + @lu.solve(values).should == solution + end - it "raises an error when given a vector of the wrong size" do - values = Vector[14, 55] - -> { - @lu.solve(values) - }.should raise_error(Matrix::ErrDimensionMismatch) - end + it "raises an error when given a vector of the wrong size" do + values = Vector[14, 55] + -> { + @lu.solve(values) + }.should raise_error(Matrix::ErrDimensionMismatch) end end end diff --git a/spec/ruby/library/matrix/lup_decomposition/to_a_spec.rb b/spec/ruby/library/matrix/lup_decomposition/to_a_spec.rb index 8702292865..9b1dccbbac 100644 --- a/spec/ruby/library/matrix/lup_decomposition/to_a_spec.rb +++ b/spec/ruby/library/matrix/lup_decomposition/to_a_spec.rb @@ -1,36 +1,33 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix::LUPDecomposition#to_a" do - before :each do - @a = Matrix[[7, 8, 9], [14, 46, 51], [28, 82, 163]] - @lu = Matrix::LUPDecomposition.new(@a) - @to_a = @lu.to_a - @l, @u, @p = @to_a - end +describe "Matrix::LUPDecomposition#to_a" do + before :each do + @a = Matrix[[7, 8, 9], [14, 46, 51], [28, 82, 163]] + @lu = Matrix::LUPDecomposition.new(@a) + @to_a = @lu.to_a + @l, @u, @p = @to_a + end - it "returns an array of three matrices" do - @to_a.should be_kind_of(Array) - @to_a.length.should == 3 - @to_a.each{|m| m.should be_kind_of(Matrix)} - end + it "returns an array of three matrices" do + @to_a.should be_kind_of(Array) + @to_a.length.should == 3 + @to_a.each{|m| m.should be_kind_of(Matrix)} + end - it "returns [l, u, p] such that l*u == a*p" do - (@l * @u).should == (@p * @a) - end + it "returns [l, u, p] such that l*u == a*p" do + (@l * @u).should == (@p * @a) + end - it "returns the right values for rectangular matrices" do - [ - Matrix[[7, 8, 9], [14, 46, 51]], - Matrix[[4, 11], [5, 8], [3, 4]], - ].each do |a| - l, u, p = Matrix::LUPDecomposition.new(a).to_a - (l * u).should == (p * a) - end + it "returns the right values for rectangular matrices" do + [ + Matrix[[7, 8, 9], [14, 46, 51]], + Matrix[[4, 11], [5, 8], [3, 4]], + ].each do |a| + l, u, p = Matrix::LUPDecomposition.new(a).to_a + (l * u).should == (p * a) end - - it "has other properties implied by the specs of #l, #u and #p" end + + it "has other properties implied by the specs of #l, #u and #p" end diff --git a/spec/ruby/library/matrix/lup_decomposition/u_spec.rb b/spec/ruby/library/matrix/lup_decomposition/u_spec.rb index cd884b88ec..ca3dfc1f00 100644 --- a/spec/ruby/library/matrix/lup_decomposition/u_spec.rb +++ b/spec/ruby/library/matrix/lup_decomposition/u_spec.rb @@ -1,21 +1,18 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix::LUPDecomposition#u" do - before :each do - @a = Matrix[[7, 8, 9], [14, 46, 51], [28, 82, 163]] - @lu = Matrix::LUPDecomposition.new(@a) - @u = @lu.u - end +describe "Matrix::LUPDecomposition#u" do + before :each do + @a = Matrix[[7, 8, 9], [14, 46, 51], [28, 82, 163]] + @lu = Matrix::LUPDecomposition.new(@a) + @u = @lu.u + end - it "returns the second element of to_a" do - @u.should == @lu.to_a[1] - end + it "returns the second element of to_a" do + @u.should == @lu.to_a[1] + end - it "returns an upper triangular matrix" do - @u.upper_triangular?.should be_true - end + it "returns an upper triangular matrix" do + @u.upper_triangular?.should be_true end end diff --git a/spec/ruby/library/matrix/map_spec.rb b/spec/ruby/library/matrix/map_spec.rb index cde0df5441..bc07c48cda 100644 --- a/spec/ruby/library/matrix/map_spec.rb +++ b/spec/ruby/library/matrix/map_spec.rb @@ -1,9 +1,6 @@ require_relative '../../spec_helper' +require_relative 'shared/collect' -ruby_version_is ""..."3.1" do - require_relative 'shared/collect' - - describe "Matrix#map" do - it_behaves_like :collect, :map - end +describe "Matrix#map" do + it_behaves_like :collect, :map end diff --git a/spec/ruby/library/matrix/minor_spec.rb b/spec/ruby/library/matrix/minor_spec.rb index 0a6b0823c8..009826c3d6 100644 --- a/spec/ruby/library/matrix/minor_spec.rb +++ b/spec/ruby/library/matrix/minor_spec.rb @@ -1,88 +1,85 @@ require_relative '../../spec_helper' +require_relative 'fixtures/classes' +require 'matrix' -ruby_version_is ""..."3.1" do - require_relative 'fixtures/classes' - require 'matrix' +describe "Matrix#minor" do + before :each do + @matrix = Matrix[ [1,2], [3,4], [5,6] ] + end - describe "Matrix#minor" do - before :each do - @matrix = Matrix[ [1,2], [3,4], [5,6] ] + describe "with start_row, nrows, start_col, ncols" do + it "returns the given portion of the Matrix" do + @matrix.minor(0,1,0,2).should == Matrix[ [1, 2] ] + @matrix.minor(1,2,1,1).should == Matrix[ [4], [6] ] end - describe "with start_row, nrows, start_col, ncols" do - it "returns the given portion of the Matrix" do - @matrix.minor(0,1,0,2).should == Matrix[ [1, 2] ] - @matrix.minor(1,2,1,1).should == Matrix[ [4], [6] ] - end - - it "returns an empty Matrix if nrows or ncols is 0" do - @matrix.minor(0,0,0,0).should == Matrix[] - @matrix.minor(1,0,1,0).should == Matrix[] - @matrix.minor(1,0,1,1).should == Matrix.columns([[]]) - @matrix.minor(1,1,1,0).should == Matrix[[]] - end + it "returns an empty Matrix if nrows or ncols is 0" do + @matrix.minor(0,0,0,0).should == Matrix[] + @matrix.minor(1,0,1,0).should == Matrix[] + @matrix.minor(1,0,1,1).should == Matrix.columns([[]]) + @matrix.minor(1,1,1,0).should == Matrix[[]] + end - it "returns nil for out-of-bounds start_row/col" do - r = @matrix.row_size + 1 - c = @matrix.column_size + 1 - @matrix.minor(r,0,0,10).should == nil - @matrix.minor(0,10,c,9).should == nil - @matrix.minor(-r,0,0,10).should == nil - @matrix.minor(0,10,-c,9).should == nil - end + it "returns nil for out-of-bounds start_row/col" do + r = @matrix.row_size + 1 + c = @matrix.column_size + 1 + @matrix.minor(r,0,0,10).should == nil + @matrix.minor(0,10,c,9).should == nil + @matrix.minor(-r,0,0,10).should == nil + @matrix.minor(0,10,-c,9).should == nil + end - it "returns nil for negative nrows or ncols" do - @matrix.minor(0,1,0,-1).should == nil - @matrix.minor(0,-1,0,1).should == nil - end + it "returns nil for negative nrows or ncols" do + @matrix.minor(0,1,0,-1).should == nil + @matrix.minor(0,-1,0,1).should == nil + end - it "start counting backwards for start_row or start_col below zero" do - @matrix.minor(0, 1, -1, 1).should == @matrix.minor(0, 1, 1, 1) - @matrix.minor(-1, 1, 0, 1).should == @matrix.minor(2, 1, 0, 1) - end + it "start counting backwards for start_row or start_col below zero" do + @matrix.minor(0, 1, -1, 1).should == @matrix.minor(0, 1, 1, 1) + @matrix.minor(-1, 1, 0, 1).should == @matrix.minor(2, 1, 0, 1) + end - it "returns empty matrices for extreme start_row/col" do - @matrix.minor(3,10,1,10).should == Matrix.columns([[]]) - @matrix.minor(1,10,2,10).should == Matrix[[], []] - @matrix.minor(3,0,0,10).should == Matrix.columns([[], []]) - end + it "returns empty matrices for extreme start_row/col" do + @matrix.minor(3,10,1,10).should == Matrix.columns([[]]) + @matrix.minor(1,10,2,10).should == Matrix[[], []] + @matrix.minor(3,0,0,10).should == Matrix.columns([[], []]) + end - it "ignores big nrows or ncols" do - @matrix.minor(0,1,0,20).should == Matrix[ [1, 2] ] - @matrix.minor(1,20,1,1).should == Matrix[ [4], [6] ] - end + it "ignores big nrows or ncols" do + @matrix.minor(0,1,0,20).should == Matrix[ [1, 2] ] + @matrix.minor(1,20,1,1).should == Matrix[ [4], [6] ] end + end - describe "with col_range, row_range" do - it "returns the given portion of the Matrix" do - @matrix.minor(0..0, 0..1).should == Matrix[ [1, 2] ] - @matrix.minor(1..2, 1..2).should == Matrix[ [4], [6] ] - @matrix.minor(1...3, 1...3).should == Matrix[ [4], [6] ] - end + describe "with col_range, row_range" do + it "returns the given portion of the Matrix" do + @matrix.minor(0..0, 0..1).should == Matrix[ [1, 2] ] + @matrix.minor(1..2, 1..2).should == Matrix[ [4], [6] ] + @matrix.minor(1...3, 1...3).should == Matrix[ [4], [6] ] + end - it "returns nil if col_range or row_range is out of range" do - r = @matrix.row_size + 1 - c = @matrix.column_size + 1 - @matrix.minor(r..6, c..6).should == nil - @matrix.minor(0..1, c..6).should == nil - @matrix.minor(r..6, 0..1).should == nil - @matrix.minor(-r..6, -c..6).should == nil - @matrix.minor(0..1, -c..6).should == nil - @matrix.minor(-r..6, 0..1).should == nil - end + it "returns nil if col_range or row_range is out of range" do + r = @matrix.row_size + 1 + c = @matrix.column_size + 1 + @matrix.minor(r..6, c..6).should == nil + @matrix.minor(0..1, c..6).should == nil + @matrix.minor(r..6, 0..1).should == nil + @matrix.minor(-r..6, -c..6).should == nil + @matrix.minor(0..1, -c..6).should == nil + @matrix.minor(-r..6, 0..1).should == nil + end - it "start counting backwards for col_range or row_range below zero" do - @matrix.minor(0..1, -2..-1).should == @matrix.minor(0..1, 0..1) - @matrix.minor(0..1, -2..1).should == @matrix.minor(0..1, 0..1) - @matrix.minor(-2..-1, 0..1).should == @matrix.minor(1..2, 0..1) - @matrix.minor(-2..2, 0..1).should == @matrix.minor(1..2, 0..1) - end + it "start counting backwards for col_range or row_range below zero" do + @matrix.minor(0..1, -2..-1).should == @matrix.minor(0..1, 0..1) + @matrix.minor(0..1, -2..1).should == @matrix.minor(0..1, 0..1) + @matrix.minor(-2..-1, 0..1).should == @matrix.minor(1..2, 0..1) + @matrix.minor(-2..2, 0..1).should == @matrix.minor(1..2, 0..1) end + end - describe "for a subclass of Matrix" do - it "returns an instance of that subclass" do - MatrixSub.ins.minor(0, 1, 0, 1).should be_an_instance_of(MatrixSub) - end + describe "for a subclass of Matrix" do + it "returns an instance of that subclass" do + MatrixSub.ins.minor(0, 1, 0, 1).should be_an_instance_of(MatrixSub) end end end diff --git a/spec/ruby/library/matrix/minus_spec.rb b/spec/ruby/library/matrix/minus_spec.rb index 27dfbeaea5..95cf4a6072 100644 --- a/spec/ruby/library/matrix/minus_spec.rb +++ b/spec/ruby/library/matrix/minus_spec.rb @@ -1,45 +1,42 @@ require_relative '../../spec_helper' +require_relative 'fixtures/classes' +require 'matrix' -ruby_version_is ""..."3.1" do - require_relative 'fixtures/classes' - require 'matrix' - - describe "Matrix#-" do - before :each do - @a = Matrix[ [1, 2], [3, 4] ] - @b = Matrix[ [4, 5], [6, 7] ] - end +describe "Matrix#-" do + before :each do + @a = Matrix[ [1, 2], [3, 4] ] + @b = Matrix[ [4, 5], [6, 7] ] + end - it "returns the result of subtracting the corresponding elements of other from self" do - (@a - @b).should == Matrix[ [-3,-3], [-3,-3] ] - end + it "returns the result of subtracting the corresponding elements of other from self" do + (@a - @b).should == Matrix[ [-3,-3], [-3,-3] ] + end - it "returns an instance of Matrix" do - (@a - @b).should be_kind_of(Matrix) - end + it "returns an instance of Matrix" do + (@a - @b).should be_kind_of(Matrix) + end - it "raises a Matrix::ErrDimensionMismatch if the matrices are different sizes" do - -> { @a - Matrix[ [1] ] }.should raise_error(Matrix::ErrDimensionMismatch) - end + it "raises a Matrix::ErrDimensionMismatch if the matrices are different sizes" do + -> { @a - Matrix[ [1] ] }.should raise_error(Matrix::ErrDimensionMismatch) + end - it "raises a ExceptionForMatrix::ErrOperationNotDefined if other is a Numeric Type" do - -> { @a - 2 }.should raise_error(Matrix::ErrOperationNotDefined) - -> { @a - 1.2 }.should raise_error(Matrix::ErrOperationNotDefined) - -> { @a - bignum_value }.should raise_error(Matrix::ErrOperationNotDefined) - end + it "raises a ExceptionForMatrix::ErrOperationNotDefined if other is a Numeric Type" do + -> { @a - 2 }.should raise_error(Matrix::ErrOperationNotDefined) + -> { @a - 1.2 }.should raise_error(Matrix::ErrOperationNotDefined) + -> { @a - bignum_value }.should raise_error(Matrix::ErrOperationNotDefined) + end - it "raises a TypeError if other is of wrong type" do - -> { @a - nil }.should raise_error(TypeError) - -> { @a - "a" }.should raise_error(TypeError) - -> { @a - [ [1, 2] ] }.should raise_error(TypeError) - -> { @a - Object.new }.should raise_error(TypeError) - end + it "raises a TypeError if other is of wrong type" do + -> { @a - nil }.should raise_error(TypeError) + -> { @a - "a" }.should raise_error(TypeError) + -> { @a - [ [1, 2] ] }.should raise_error(TypeError) + -> { @a - Object.new }.should raise_error(TypeError) + end - describe "for a subclass of Matrix" do - it "returns an instance of that subclass" do - m = MatrixSub.ins - (m-m).should be_an_instance_of(MatrixSub) - end + describe "for a subclass of Matrix" do + it "returns an instance of that subclass" do + m = MatrixSub.ins + (m-m).should be_an_instance_of(MatrixSub) end end end diff --git a/spec/ruby/library/matrix/multiply_spec.rb b/spec/ruby/library/matrix/multiply_spec.rb index a63fcf4020..206868af92 100644 --- a/spec/ruby/library/matrix/multiply_spec.rb +++ b/spec/ruby/library/matrix/multiply_spec.rb @@ -1,71 +1,69 @@ require_relative '../../spec_helper' -ruby_version_is ""..."3.1" do - require_relative 'fixtures/classes' - require 'matrix' +require_relative 'fixtures/classes' +require 'matrix' - describe "Matrix#*" do - before :each do - @a = Matrix[ [1, 2], [3, 4] ] - @b = Matrix[ [4, 5], [6, 7] ] - end +describe "Matrix#*" do + before :each do + @a = Matrix[ [1, 2], [3, 4] ] + @b = Matrix[ [4, 5], [6, 7] ] + end - it "returns the result of multiplying the corresponding elements of self and a Matrix" do - (@a * @b).should == Matrix[ [16,19], [36,43] ] - end + it "returns the result of multiplying the corresponding elements of self and a Matrix" do + (@a * @b).should == Matrix[ [16,19], [36,43] ] + end - it "returns the result of multiplying the corresponding elements of self and a Vector" do - (@a * Vector[1,2]).should == Vector[5, 11] - end + it "returns the result of multiplying the corresponding elements of self and a Vector" do + (@a * Vector[1,2]).should == Vector[5, 11] + end - it "returns the result of multiplying the elements of self and a Fixnum" do - (@a * 2).should == Matrix[ [2, 4], [6, 8] ] - end + it "returns the result of multiplying the elements of self and a Fixnum" do + (@a * 2).should == Matrix[ [2, 4], [6, 8] ] + end - it "returns the result of multiplying the elements of self and a Bignum" do - (@a * bignum_value).should == Matrix[ - [18446744073709551616, 36893488147419103232], - [55340232221128654848, 73786976294838206464] - ] - end + it "returns the result of multiplying the elements of self and a Bignum" do + (@a * bignum_value).should == Matrix[ + [18446744073709551616, 36893488147419103232], + [55340232221128654848, 73786976294838206464] + ] + end - it "returns the result of multiplying the elements of self and a Float" do - (@a * 2.0).should == Matrix[ [2.0, 4.0], [6.0, 8.0] ] - end + it "returns the result of multiplying the elements of self and a Float" do + (@a * 2.0).should == Matrix[ [2.0, 4.0], [6.0, 8.0] ] + end - it "raises a Matrix::ErrDimensionMismatch if the matrices are different sizes" do - -> { @a * Matrix[ [1] ] }.should raise_error(Matrix::ErrDimensionMismatch) - end + it "raises a Matrix::ErrDimensionMismatch if the matrices are different sizes" do + -> { @a * Matrix[ [1] ] }.should raise_error(Matrix::ErrDimensionMismatch) + end - it "returns a zero matrix if (nx0) * (0xn)" do - (Matrix[[],[],[]] * Matrix.columns([[],[],[]])).should == Matrix.zero(3) - end + it "returns a zero matrix if (nx0) * (0xn)" do + (Matrix[[],[],[]] * Matrix.columns([[],[],[]])).should == Matrix.zero(3) + end - it "returns an empty matrix if (0xn) * (nx0)" do - (Matrix.columns([[],[],[]]) * Matrix[[],[],[]]).should == Matrix[] - end + it "returns an empty matrix if (0xn) * (nx0)" do + (Matrix.columns([[],[],[]]) * Matrix[[],[],[]]).should == Matrix[] + end - it "returns a mx0 matrix if (mxn) * (nx0)" do - (Matrix[[1,2],[3,4],[5,6]] * Matrix[[],[]]).should == Matrix[[],[],[]] - end + it "returns a mx0 matrix if (mxn) * (nx0)" do + (Matrix[[1,2],[3,4],[5,6]] * Matrix[[],[]]).should == Matrix[[],[],[]] + end - it "returns a 0xm matrix if (0xm) * (mxn)" do - (Matrix.columns([[], [], []]) * Matrix[[1,2],[3,4],[5,6]]).should == Matrix.columns([[],[]]) - end + it "returns a 0xm matrix if (0xm) * (mxn)" do + (Matrix.columns([[], [], []]) * Matrix[[1,2],[3,4],[5,6]]).should == Matrix.columns([[],[]]) + end - it "raises a TypeError if other is of wrong type" do - -> { @a * nil }.should raise_error(TypeError) - -> { @a * "a" }.should raise_error(TypeError) - -> { @a * [ [1, 2] ] }.should raise_error(TypeError) - -> { @a * Object.new }.should raise_error(TypeError) - end + it "raises a TypeError if other is of wrong type" do + -> { @a * nil }.should raise_error(TypeError) + -> { @a * "a" }.should raise_error(TypeError) + -> { @a * [ [1, 2] ] }.should raise_error(TypeError) + -> { @a * Object.new }.should raise_error(TypeError) + end - describe "for a subclass of Matrix" do - it "returns an instance of that subclass" do - m = MatrixSub.ins - (m*m).should be_an_instance_of(MatrixSub) - (m*1).should be_an_instance_of(MatrixSub) - end + describe "for a subclass of Matrix" do + it "returns an instance of that subclass" do + m = MatrixSub.ins + (m*m).should be_an_instance_of(MatrixSub) + (m*1).should be_an_instance_of(MatrixSub) end end end diff --git a/spec/ruby/library/matrix/new_spec.rb b/spec/ruby/library/matrix/new_spec.rb index 4be2e17116..3005066846 100644 --- a/spec/ruby/library/matrix/new_spec.rb +++ b/spec/ruby/library/matrix/new_spec.rb @@ -1,11 +1,8 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix.new" do - it "is private" do - Matrix.should have_private_method(:new) - end +describe "Matrix.new" do + it "is private" do + Matrix.should have_private_method(:new) end end diff --git a/spec/ruby/library/matrix/normal_spec.rb b/spec/ruby/library/matrix/normal_spec.rb index 2f2e138c1b..a9e6c645fa 100644 --- a/spec/ruby/library/matrix/normal_spec.rb +++ b/spec/ruby/library/matrix/normal_spec.rb @@ -1,29 +1,26 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' +describe "Matrix.normal?" do + # it "returns false for non normal matrices" do + # Matrix[[0, 1], [1, 2]].should_not.normal? + # end - describe "Matrix.normal?" do - # it "returns false for non normal matrices" do - # Matrix[[0, 1], [1, 2]].should_not.normal? - # end - - it "returns true for normal matrices" do - Matrix[[1, 1, 0], [0, 1, 1], [1, 0, 1]].should.normal? - Matrix[[0, Complex(0, 2)], [Complex(0, -2), 0]].should.normal? - end + it "returns true for normal matrices" do + Matrix[[1, 1, 0], [0, 1, 1], [1, 0, 1]].should.normal? + Matrix[[0, Complex(0, 2)], [Complex(0, -2), 0]].should.normal? + end - it "raises an error for rectangular matrices" do - [ - Matrix[[0], [0]], - Matrix[[0, 0]], - Matrix.empty(0, 2), - Matrix.empty(2, 0), - ].each do |rectangular_matrix| - -> { - rectangular_matrix.normal? - }.should raise_error(Matrix::ErrDimensionMismatch) - end + it "raises an error for rectangular matrices" do + [ + Matrix[[0], [0]], + Matrix[[0, 0]], + Matrix.empty(0, 2), + Matrix.empty(2, 0), + ].each do |rectangular_matrix| + -> { + rectangular_matrix.normal? + }.should raise_error(Matrix::ErrDimensionMismatch) end end end diff --git a/spec/ruby/library/matrix/orthogonal_spec.rb b/spec/ruby/library/matrix/orthogonal_spec.rb index eb06305040..26afe89ff0 100644 --- a/spec/ruby/library/matrix/orthogonal_spec.rb +++ b/spec/ruby/library/matrix/orthogonal_spec.rb @@ -1,29 +1,26 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix.orthogonal?" do - it "returns false for non orthogonal matrices" do - Matrix[[0, 1], [1, 2]].should_not.orthogonal? - Matrix[[1, 1, 0], [0, 1, 1], [1, 0, 1]].should_not.orthogonal? - end +describe "Matrix.orthogonal?" do + it "returns false for non orthogonal matrices" do + Matrix[[0, 1], [1, 2]].should_not.orthogonal? + Matrix[[1, 1, 0], [0, 1, 1], [1, 0, 1]].should_not.orthogonal? + end - it "returns true for orthogonal matrices" do - Matrix[[0, 1], [1, 0]].should.orthogonal? - end + it "returns true for orthogonal matrices" do + Matrix[[0, 1], [1, 0]].should.orthogonal? + end - it "raises an error for rectangular matrices" do - [ - Matrix[[0], [0]], - Matrix[[0, 0]], - Matrix.empty(0, 2), - Matrix.empty(2, 0), - ].each do |rectangular_matrix| - -> { - rectangular_matrix.orthogonal? - }.should raise_error(Matrix::ErrDimensionMismatch) - end + it "raises an error for rectangular matrices" do + [ + Matrix[[0], [0]], + Matrix[[0, 0]], + Matrix.empty(0, 2), + Matrix.empty(2, 0), + ].each do |rectangular_matrix| + -> { + rectangular_matrix.orthogonal? + }.should raise_error(Matrix::ErrDimensionMismatch) end end end diff --git a/spec/ruby/library/matrix/permutation_spec.rb b/spec/ruby/library/matrix/permutation_spec.rb index ed8edad755..825a9d982c 100644 --- a/spec/ruby/library/matrix/permutation_spec.rb +++ b/spec/ruby/library/matrix/permutation_spec.rb @@ -1,35 +1,32 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix#permutation?" do - it "returns true for a permutation Matrix" do - Matrix[[0, 1, 0], [0, 0, 1], [1, 0, 0]].permutation?.should be_true - end +describe "Matrix#permutation?" do + it "returns true for a permutation Matrix" do + Matrix[[0, 1, 0], [0, 0, 1], [1, 0, 0]].permutation?.should be_true + end - it "returns false for a non permutation square Matrix" do - Matrix[[0, 1], [0, 0]].permutation?.should be_false - Matrix[[-1, 0], [0, -1]].permutation?.should be_false - Matrix[[1, 0], [1, 0]].permutation?.should be_false - Matrix[[1, 0], [1, 1]].permutation?.should be_false - end + it "returns false for a non permutation square Matrix" do + Matrix[[0, 1], [0, 0]].permutation?.should be_false + Matrix[[-1, 0], [0, -1]].permutation?.should be_false + Matrix[[1, 0], [1, 0]].permutation?.should be_false + Matrix[[1, 0], [1, 1]].permutation?.should be_false + end - it "returns true for an empty 0x0 matrix" do - Matrix.empty(0,0).permutation?.should be_true - end + it "returns true for an empty 0x0 matrix" do + Matrix.empty(0,0).permutation?.should be_true + end - it "raises an error for rectangular matrices" do - [ - Matrix[[0], [0]], - Matrix[[0, 0]], - Matrix.empty(0, 2), - Matrix.empty(2, 0), - ].each do |rectangular_matrix| - -> { - rectangular_matrix.permutation? - }.should raise_error(Matrix::ErrDimensionMismatch) - end + it "raises an error for rectangular matrices" do + [ + Matrix[[0], [0]], + Matrix[[0, 0]], + Matrix.empty(0, 2), + Matrix.empty(2, 0), + ].each do |rectangular_matrix| + -> { + rectangular_matrix.permutation? + }.should raise_error(Matrix::ErrDimensionMismatch) end end end diff --git a/spec/ruby/library/matrix/plus_spec.rb b/spec/ruby/library/matrix/plus_spec.rb index 99e6615778..2706bad060 100644 --- a/spec/ruby/library/matrix/plus_spec.rb +++ b/spec/ruby/library/matrix/plus_spec.rb @@ -1,45 +1,42 @@ require_relative '../../spec_helper' +require_relative 'fixtures/classes' +require 'matrix' -ruby_version_is ""..."3.1" do - require_relative 'fixtures/classes' - require 'matrix' - - describe "Matrix#+" do - before :each do - @a = Matrix[ [1,2], [3,4] ] - @b = Matrix[ [4,5], [6,7] ] - end +describe "Matrix#+" do + before :each do + @a = Matrix[ [1,2], [3,4] ] + @b = Matrix[ [4,5], [6,7] ] + end - it "returns the result of adding the corresponding elements of self and other" do - (@a + @b).should == Matrix[ [5,7], [9,11] ] - end + it "returns the result of adding the corresponding elements of self and other" do + (@a + @b).should == Matrix[ [5,7], [9,11] ] + end - it "returns an instance of Matrix" do - (@a + @b).should be_kind_of(Matrix) - end + it "returns an instance of Matrix" do + (@a + @b).should be_kind_of(Matrix) + end - it "raises a Matrix::ErrDimensionMismatch if the matrices are different sizes" do - -> { @a + Matrix[ [1] ] }.should raise_error(Matrix::ErrDimensionMismatch) - end + it "raises a Matrix::ErrDimensionMismatch if the matrices are different sizes" do + -> { @a + Matrix[ [1] ] }.should raise_error(Matrix::ErrDimensionMismatch) + end - it "raises a ExceptionForMatrix::ErrOperationNotDefined if other is a Numeric Type" do - -> { @a + 2 }.should raise_error(ExceptionForMatrix::ErrOperationNotDefined) - -> { @a + 1.2 }.should raise_error(ExceptionForMatrix::ErrOperationNotDefined) - -> { @a + bignum_value }.should raise_error(ExceptionForMatrix::ErrOperationNotDefined) - end + it "raises a ExceptionForMatrix::ErrOperationNotDefined if other is a Numeric Type" do + -> { @a + 2 }.should raise_error(ExceptionForMatrix::ErrOperationNotDefined) + -> { @a + 1.2 }.should raise_error(ExceptionForMatrix::ErrOperationNotDefined) + -> { @a + bignum_value }.should raise_error(ExceptionForMatrix::ErrOperationNotDefined) + end - it "raises a TypeError if other is of wrong type" do - -> { @a + nil }.should raise_error(TypeError) - -> { @a + "a" }.should raise_error(TypeError) - -> { @a + [ [1, 2] ] }.should raise_error(TypeError) - -> { @a + Object.new }.should raise_error(TypeError) - end + it "raises a TypeError if other is of wrong type" do + -> { @a + nil }.should raise_error(TypeError) + -> { @a + "a" }.should raise_error(TypeError) + -> { @a + [ [1, 2] ] }.should raise_error(TypeError) + -> { @a + Object.new }.should raise_error(TypeError) + end - describe "for a subclass of Matrix" do - it "returns an instance of that subclass" do - m = MatrixSub.ins - (m+m).should be_an_instance_of(MatrixSub) - end + describe "for a subclass of Matrix" do + it "returns an instance of that subclass" do + m = MatrixSub.ins + (m+m).should be_an_instance_of(MatrixSub) end end end diff --git a/spec/ruby/library/matrix/rank_spec.rb b/spec/ruby/library/matrix/rank_spec.rb index fc795b58c1..d4403d23ed 100644 --- a/spec/ruby/library/matrix/rank_spec.rb +++ b/spec/ruby/library/matrix/rank_spec.rb @@ -1,22 +1,19 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix#rank" do - it "returns the rank of the Matrix" do - Matrix[ [7,6], [3,9] ].rank.should == 2 - end +describe "Matrix#rank" do + it "returns the rank of the Matrix" do + Matrix[ [7,6], [3,9] ].rank.should == 2 + end - it "doesn't loop forever" do - Matrix[ [1,2,3], [4,5,6], [7,8,9] ].rank.should == 2 - Matrix[ [1, 2, 0, 3], [1, -2, 3, 0], [0, 0, 4, 8], [2, 4, 0, 6] ].rank. - should == 3 - end + it "doesn't loop forever" do + Matrix[ [1,2,3], [4,5,6], [7,8,9] ].rank.should == 2 + Matrix[ [1, 2, 0, 3], [1, -2, 3, 0], [0, 0, 4, 8], [2, 4, 0, 6] ].rank. + should == 3 + end - it "works for some easy rectangular matrices" do - Matrix[[0,0],[0,0],[1,0]].rank.should == 1 - Matrix[[0,1],[0,0],[1,0]].rank.should == 2 - end + it "works for some easy rectangular matrices" do + Matrix[[0,0],[0,0],[1,0]].rank.should == 1 + Matrix[[0,1],[0,0],[1,0]].rank.should == 2 end end diff --git a/spec/ruby/library/matrix/real_spec.rb b/spec/ruby/library/matrix/real_spec.rb index 63a6bde923..38033c63c8 100644 --- a/spec/ruby/library/matrix/real_spec.rb +++ b/spec/ruby/library/matrix/real_spec.rb @@ -1,46 +1,43 @@ require_relative '../../spec_helper' +require_relative 'fixtures/classes' +require 'matrix' -ruby_version_is ""..."3.1" do - require_relative 'fixtures/classes' - require 'matrix' - - describe "Matrix#real?" do - it "returns true for matrices with all real entries" do - Matrix[ [1, 2], [3, 4] ].real?.should be_true - Matrix[ [1.9, 2], [3, 4] ].real?.should be_true - end +describe "Matrix#real?" do + it "returns true for matrices with all real entries" do + Matrix[ [1, 2], [3, 4] ].real?.should be_true + Matrix[ [1.9, 2], [3, 4] ].real?.should be_true + end - it "returns true for empty matrices" do - Matrix.empty.real?.should be_true - end + it "returns true for empty matrices" do + Matrix.empty.real?.should be_true + end - it "returns false if one element is a Complex" do - Matrix[ [Complex(1,1), 2], [3, 4] ].real?.should be_false - end + it "returns false if one element is a Complex" do + Matrix[ [Complex(1,1), 2], [3, 4] ].real?.should be_false + end - # Guard against the Mathn library - guard -> { !defined?(Math.rsqrt) } do - it "returns false if one element is a Complex whose imaginary part is 0" do - Matrix[ [Complex(1,0), 2], [3, 4] ].real?.should be_false - end + # Guard against the Mathn library + guard -> { !defined?(Math.rsqrt) } do + it "returns false if one element is a Complex whose imaginary part is 0" do + Matrix[ [Complex(1,0), 2], [3, 4] ].real?.should be_false end end +end - describe "Matrix#real" do - it "returns a matrix with the real part of the elements of the receiver" do - Matrix[ [1, 2], [3, 4] ].real.should == Matrix[ [1, 2], [3, 4] ] - Matrix[ [1.9, Complex(1,1)], [Complex(-0.42, 0), 4] ].real.should == Matrix[ [1.9, 1], [-0.42, 4] ] - end +describe "Matrix#real" do + it "returns a matrix with the real part of the elements of the receiver" do + Matrix[ [1, 2], [3, 4] ].real.should == Matrix[ [1, 2], [3, 4] ] + Matrix[ [1.9, Complex(1,1)], [Complex(-0.42, 0), 4] ].real.should == Matrix[ [1.9, 1], [-0.42, 4] ] + end - it "returns empty matrices on the same size if empty" do - Matrix.empty(0, 3).real.should == Matrix.empty(0, 3) - Matrix.empty(3, 0).real.should == Matrix.empty(3, 0) - end + it "returns empty matrices on the same size if empty" do + Matrix.empty(0, 3).real.should == Matrix.empty(0, 3) + Matrix.empty(3, 0).real.should == Matrix.empty(3, 0) + end - describe "for a subclass of Matrix" do - it "returns an instance of that subclass" do - MatrixSub.ins.real.should be_an_instance_of(MatrixSub) - end + describe "for a subclass of Matrix" do + it "returns an instance of that subclass" do + MatrixSub.ins.real.should be_an_instance_of(MatrixSub) end end end diff --git a/spec/ruby/library/matrix/rect_spec.rb b/spec/ruby/library/matrix/rect_spec.rb index b3b7ac05c9..83a0404e47 100644 --- a/spec/ruby/library/matrix/rect_spec.rb +++ b/spec/ruby/library/matrix/rect_spec.rb @@ -1,9 +1,6 @@ require_relative '../../spec_helper' +require_relative 'shared/rectangular' -ruby_version_is ""..."3.1" do - require_relative 'shared/rectangular' - - describe "Matrix#rect" do - it_behaves_like :matrix_rectangular, :rect - end +describe "Matrix#rect" do + it_behaves_like :matrix_rectangular, :rect end diff --git a/spec/ruby/library/matrix/rectangular_spec.rb b/spec/ruby/library/matrix/rectangular_spec.rb index 1fc2e0e60d..a235fac640 100644 --- a/spec/ruby/library/matrix/rectangular_spec.rb +++ b/spec/ruby/library/matrix/rectangular_spec.rb @@ -1,9 +1,6 @@ require_relative '../../spec_helper' +require_relative 'shared/rectangular' -ruby_version_is ""..."3.1" do - require_relative 'shared/rectangular' - - describe "Matrix#rectangular" do - it_behaves_like :matrix_rectangular, :rectangular - end +describe "Matrix#rectangular" do + it_behaves_like :matrix_rectangular, :rectangular end diff --git a/spec/ruby/library/matrix/regular_spec.rb b/spec/ruby/library/matrix/regular_spec.rb index f6688bba30..3699d0ef8b 100644 --- a/spec/ruby/library/matrix/regular_spec.rb +++ b/spec/ruby/library/matrix/regular_spec.rb @@ -1,34 +1,31 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' +describe "Matrix#regular?" do - describe "Matrix#regular?" do + it "returns false for singular matrices" do + m = Matrix[ [1,2,3], [3,4,3], [0,0,0] ] + m.regular?.should be_false - it "returns false for singular matrices" do - m = Matrix[ [1,2,3], [3,4,3], [0,0,0] ] - m.regular?.should be_false - - m = Matrix[ [1,2,9], [3,4,9], [1,2,9] ] - m.regular?.should be_false - end + m = Matrix[ [1,2,9], [3,4,9], [1,2,9] ] + m.regular?.should be_false + end - it "returns true if the Matrix is regular" do - Matrix[ [0,1], [1,0] ].regular?.should be_true - end + it "returns true if the Matrix is regular" do + Matrix[ [0,1], [1,0] ].regular?.should be_true + end - it "returns true for an empty 0x0 matrix" do - Matrix.empty(0,0).regular?.should be_true - end + it "returns true for an empty 0x0 matrix" do + Matrix.empty(0,0).regular?.should be_true + end - it "raises an error for rectangular matrices" do - -> { - Matrix[[1], [2], [3]].regular? - }.should raise_error(Matrix::ErrDimensionMismatch) + it "raises an error for rectangular matrices" do + -> { + Matrix[[1], [2], [3]].regular? + }.should raise_error(Matrix::ErrDimensionMismatch) - -> { - Matrix.empty(3,0).regular? - }.should raise_error(Matrix::ErrDimensionMismatch) - end + -> { + Matrix.empty(3,0).regular? + }.should raise_error(Matrix::ErrDimensionMismatch) end end diff --git a/spec/ruby/library/matrix/round_spec.rb b/spec/ruby/library/matrix/round_spec.rb index db33268414..1dc29df890 100644 --- a/spec/ruby/library/matrix/round_spec.rb +++ b/spec/ruby/library/matrix/round_spec.rb @@ -1,24 +1,21 @@ require_relative '../../spec_helper' +require_relative 'fixtures/classes' +require 'matrix' -ruby_version_is ""..."3.1" do - require_relative 'fixtures/classes' - require 'matrix' - - describe "Matrix#round" do - it "returns a matrix with all entries rounded" do - Matrix[ [1, 2.34], [5.67, 8] ].round.should == Matrix[ [1, 2], [6, 8] ] - Matrix[ [1, 2.34], [5.67, 8] ].round(1).should == Matrix[ [1, 2.3], [5.7, 8] ] - end +describe "Matrix#round" do + it "returns a matrix with all entries rounded" do + Matrix[ [1, 2.34], [5.67, 8] ].round.should == Matrix[ [1, 2], [6, 8] ] + Matrix[ [1, 2.34], [5.67, 8] ].round(1).should == Matrix[ [1, 2.3], [5.7, 8] ] + end - it "returns empty matrices on the same size if empty" do - Matrix.empty(0, 3).round.should == Matrix.empty(0, 3) - Matrix.empty(3, 0).round(42).should == Matrix.empty(3, 0) - end + it "returns empty matrices on the same size if empty" do + Matrix.empty(0, 3).round.should == Matrix.empty(0, 3) + Matrix.empty(3, 0).round(42).should == Matrix.empty(3, 0) + end - describe "for a subclass of Matrix" do - it "returns an instance of that subclass" do - MatrixSub.ins.round.should be_an_instance_of(MatrixSub) - end + describe "for a subclass of Matrix" do + it "returns an instance of that subclass" do + MatrixSub.ins.round.should be_an_instance_of(MatrixSub) end end end diff --git a/spec/ruby/library/matrix/row_size_spec.rb b/spec/ruby/library/matrix/row_size_spec.rb index fca5a846ab..eb3aef2e2f 100644 --- a/spec/ruby/library/matrix/row_size_spec.rb +++ b/spec/ruby/library/matrix/row_size_spec.rb @@ -1,16 +1,13 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix#row_size" do - it "returns the number rows" do - Matrix[ [1,2], [3, 4], [5, 6] ].row_size.should == 3 - end - - it "returns the number rows even for some empty matrices" do - Matrix[ [], [], [] ].row_size.should == 3 - end +describe "Matrix#row_size" do + it "returns the number rows" do + Matrix[ [1,2], [3, 4], [5, 6] ].row_size.should == 3 + end + it "returns the number rows even for some empty matrices" do + Matrix[ [], [], [] ].row_size.should == 3 end + end diff --git a/spec/ruby/library/matrix/row_spec.rb b/spec/ruby/library/matrix/row_spec.rb index eb05cd9273..00b1f02a8e 100644 --- a/spec/ruby/library/matrix/row_spec.rb +++ b/spec/ruby/library/matrix/row_spec.rb @@ -1,39 +1,36 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix#row" do - before :all do - @m = Matrix[ [1, 2], [2, 3], [3, 4] ] - end +describe "Matrix#row" do + before :all do + @m = Matrix[ [1, 2], [2, 3], [3, 4] ] + end - it "returns a Vector when called without a block" do - @m.row(0).should == Vector[1,2] - end + it "returns a Vector when called without a block" do + @m.row(0).should == Vector[1,2] + end - it "yields the elements of the row when called with a block" do - a = [] - @m.row(0) {|x| a << x} - a.should == [1,2] - end + it "yields the elements of the row when called with a block" do + a = [] + @m.row(0) {|x| a << x} + a.should == [1,2] + end - it "counts backwards for negative argument" do - @m.row(-1).should == Vector[3, 4] - end + it "counts backwards for negative argument" do + @m.row(-1).should == Vector[3, 4] + end - it "returns self when called with a block" do - @m.row(0) { |x| x }.should equal(@m) - end + it "returns self when called with a block" do + @m.row(0) { |x| x }.should equal(@m) + end - it "returns nil when out of bounds" do - @m.row(3).should == nil - @m.row(-4).should == nil - end + it "returns nil when out of bounds" do + @m.row(3).should == nil + @m.row(-4).should == nil + end - it "never yields when out of bounds" do - -> { @m.row(3){ raise } }.should_not raise_error - -> { @m.row(-4){ raise } }.should_not raise_error - end + it "never yields when out of bounds" do + -> { @m.row(3){ raise } }.should_not raise_error + -> { @m.row(-4){ raise } }.should_not raise_error end end diff --git a/spec/ruby/library/matrix/row_vector_spec.rb b/spec/ruby/library/matrix/row_vector_spec.rb index 4c97d6013a..341437ee05 100644 --- a/spec/ruby/library/matrix/row_vector_spec.rb +++ b/spec/ruby/library/matrix/row_vector_spec.rb @@ -1,27 +1,24 @@ require_relative '../../spec_helper' +require_relative 'fixtures/classes' +require 'matrix' -ruby_version_is ""..."3.1" do - require_relative 'fixtures/classes' - require 'matrix' +describe "Matrix.row_vector" do - describe "Matrix.row_vector" do - - it "returns a Matrix" do - Matrix.row_vector([]).should be_an_instance_of(Matrix) - end + it "returns a Matrix" do + Matrix.row_vector([]).should be_an_instance_of(Matrix) + end - it "returns a single-row Matrix with the specified values" do - Matrix.row_vector([1,2]).should == Matrix[ [1,2] ] - end + it "returns a single-row Matrix with the specified values" do + Matrix.row_vector([1,2]).should == Matrix[ [1,2] ] + end - it "returns a 1x0 matrix when called with an empty Array" do - Matrix.row_vector([]).should == Matrix[ [] ] - end + it "returns a 1x0 matrix when called with an empty Array" do + Matrix.row_vector([]).should == Matrix[ [] ] + end - describe "for a subclass of Matrix" do - it "returns an instance of that subclass" do - MatrixSub.row_vector([1]).should be_an_instance_of(MatrixSub) - end + describe "for a subclass of Matrix" do + it "returns an instance of that subclass" do + MatrixSub.row_vector([1]).should be_an_instance_of(MatrixSub) end end end diff --git a/spec/ruby/library/matrix/row_vectors_spec.rb b/spec/ruby/library/matrix/row_vectors_spec.rb index d01a4ca10d..6f99c439a6 100644 --- a/spec/ruby/library/matrix/row_vectors_spec.rb +++ b/spec/ruby/library/matrix/row_vectors_spec.rb @@ -1,29 +1,26 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' +describe "Matrix#row_vectors" do - describe "Matrix#row_vectors" do - - before :each do - @vectors = Matrix[ [1,2], [3,4] ].row_vectors - end + before :each do + @vectors = Matrix[ [1,2], [3,4] ].row_vectors + end - it "returns an Array" do - Matrix[ [1,2], [3,4] ].row_vectors.should be_an_instance_of(Array) - end + it "returns an Array" do + Matrix[ [1,2], [3,4] ].row_vectors.should be_an_instance_of(Array) + end - it "returns an Array of Vectors" do - @vectors.all? {|v| v.should be_an_instance_of(Vector)} - end + it "returns an Array of Vectors" do + @vectors.all? {|v| v.should be_an_instance_of(Vector)} + end - it "returns each row as a Vector" do - @vectors.should == [Vector[1,2], Vector[3,4]] - end + it "returns each row as a Vector" do + @vectors.should == [Vector[1,2], Vector[3,4]] + end - it "returns an empty Array for empty matrices" do - Matrix[].row_vectors.should == [] - Matrix[ [] ].row_vectors.should == [ Vector[] ] - end + it "returns an empty Array for empty matrices" do + Matrix[].row_vectors.should == [] + Matrix[ [] ].row_vectors.should == [ Vector[] ] end end diff --git a/spec/ruby/library/matrix/rows_spec.rb b/spec/ruby/library/matrix/rows_spec.rb index 5f0515a37b..41ba635775 100644 --- a/spec/ruby/library/matrix/rows_spec.rb +++ b/spec/ruby/library/matrix/rows_spec.rb @@ -1,44 +1,41 @@ require_relative '../../spec_helper' +require_relative 'fixtures/classes' +require 'matrix' -ruby_version_is ""..."3.1" do - require_relative 'fixtures/classes' - require 'matrix' - - describe "Matrix.rows" do - before :each do - @a = [1, 2] - @b = [3, 4] - @m = Matrix.rows([@a, @b]) - end +describe "Matrix.rows" do + before :each do + @a = [1, 2] + @b = [3, 4] + @m = Matrix.rows([@a, @b]) + end - it "returns a Matrix" do - @m.should be_kind_of(Matrix) - end + it "returns a Matrix" do + @m.should be_kind_of(Matrix) + end - it "creates a matrix from argument rows" do - @m.row(0).to_a.should == @a - @m.row(1).to_a.should == @b - end + it "creates a matrix from argument rows" do + @m.row(0).to_a.should == @a + @m.row(1).to_a.should == @b + end - it "copies the original rows by default" do - @a << 3 - @b << 6 - @m.row(0).should_not equal(@a) - @m.row(1).should_not equal(@b) - end + it "copies the original rows by default" do + @a << 3 + @b << 6 + @m.row(0).should_not equal(@a) + @m.row(1).should_not equal(@b) + end - it "references the original rows if copy is false" do - @m_ref = Matrix.rows([@a, @b], false) - @a << 3 - @b << 6 - @m_ref.row(0).to_a.should == @a - @m_ref.row(1).to_a.should == @b - end + it "references the original rows if copy is false" do + @m_ref = Matrix.rows([@a, @b], false) + @a << 3 + @b << 6 + @m_ref.row(0).to_a.should == @a + @m_ref.row(1).to_a.should == @b + end - describe "for a subclass of Matrix" do - it "returns an instance of that subclass" do - MatrixSub.rows([[0, 1], [0, 1]]).should be_an_instance_of(MatrixSub) - end + describe "for a subclass of Matrix" do + it "returns an instance of that subclass" do + MatrixSub.rows([[0, 1], [0, 1]]).should be_an_instance_of(MatrixSub) end end end diff --git a/spec/ruby/library/matrix/scalar/Fail_spec.rb b/spec/ruby/library/matrix/scalar/Fail_spec.rb index 4f774eda28..9d8f9bd5e8 100644 --- a/spec/ruby/library/matrix/scalar/Fail_spec.rb +++ b/spec/ruby/library/matrix/scalar/Fail_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix::Scalar#Fail" do - it "needs to be reviewed for spec completeness" - end +describe "Matrix::Scalar#Fail" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/matrix/scalar/Raise_spec.rb b/spec/ruby/library/matrix/scalar/Raise_spec.rb index b405b6d6c5..27e11c1f77 100644 --- a/spec/ruby/library/matrix/scalar/Raise_spec.rb +++ b/spec/ruby/library/matrix/scalar/Raise_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix::Scalar#Raise" do - it "needs to be reviewed for spec completeness" - end +describe "Matrix::Scalar#Raise" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/matrix/scalar/divide_spec.rb b/spec/ruby/library/matrix/scalar/divide_spec.rb index 0ef2206bf6..5d726943fe 100644 --- a/spec/ruby/library/matrix/scalar/divide_spec.rb +++ b/spec/ruby/library/matrix/scalar/divide_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix::Scalar#/" do - it "needs to be reviewed for spec completeness" - end +describe "Matrix::Scalar#/" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/matrix/scalar/exponent_spec.rb b/spec/ruby/library/matrix/scalar/exponent_spec.rb index 87eea283d1..8e9ef52ff2 100644 --- a/spec/ruby/library/matrix/scalar/exponent_spec.rb +++ b/spec/ruby/library/matrix/scalar/exponent_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix::Scalar#**" do - it "needs to be reviewed for spec completeness" - end +describe "Matrix::Scalar#**" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/matrix/scalar/included_spec.rb b/spec/ruby/library/matrix/scalar/included_spec.rb index bab80e5120..cb3beb2ecd 100644 --- a/spec/ruby/library/matrix/scalar/included_spec.rb +++ b/spec/ruby/library/matrix/scalar/included_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix::Scalar.included" do - it "needs to be reviewed for spec completeness" - end +describe "Matrix::Scalar.included" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/matrix/scalar/initialize_spec.rb b/spec/ruby/library/matrix/scalar/initialize_spec.rb index af51562b43..23145ad0de 100644 --- a/spec/ruby/library/matrix/scalar/initialize_spec.rb +++ b/spec/ruby/library/matrix/scalar/initialize_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix::Scalar#initialize" do - it "needs to be reviewed for spec completeness" - end +describe "Matrix::Scalar#initialize" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/matrix/scalar/minus_spec.rb b/spec/ruby/library/matrix/scalar/minus_spec.rb index 966db1d75b..c727ea1659 100644 --- a/spec/ruby/library/matrix/scalar/minus_spec.rb +++ b/spec/ruby/library/matrix/scalar/minus_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix::Scalar#-" do - it "needs to be reviewed for spec completeness" - end +describe "Matrix::Scalar#-" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/matrix/scalar/multiply_spec.rb b/spec/ruby/library/matrix/scalar/multiply_spec.rb index 21caac478b..1a2a83d83e 100644 --- a/spec/ruby/library/matrix/scalar/multiply_spec.rb +++ b/spec/ruby/library/matrix/scalar/multiply_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix::Scalar#*" do - it "needs to be reviewed for spec completeness" - end +describe "Matrix::Scalar#*" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/matrix/scalar/plus_spec.rb b/spec/ruby/library/matrix/scalar/plus_spec.rb index 78cdf9367f..c94689a702 100644 --- a/spec/ruby/library/matrix/scalar/plus_spec.rb +++ b/spec/ruby/library/matrix/scalar/plus_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix::Scalar#+" do - it "needs to be reviewed for spec completeness" - end +describe "Matrix::Scalar#+" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/matrix/scalar_spec.rb b/spec/ruby/library/matrix/scalar_spec.rb index 1ec64d2d78..7fdd64c9d9 100644 --- a/spec/ruby/library/matrix/scalar_spec.rb +++ b/spec/ruby/library/matrix/scalar_spec.rb @@ -1,68 +1,65 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' +describe "Matrix.scalar" do - describe "Matrix.scalar" do - - before :each do - @side = 3 - @value = 8 - @a = Matrix.scalar(@side, @value) - end + before :each do + @side = 3 + @value = 8 + @a = Matrix.scalar(@side, @value) + end - it "returns a Matrix" do - @a.should be_kind_of(Matrix) - end + it "returns a Matrix" do + @a.should be_kind_of(Matrix) + end - it "returns a n x n matrix" do - @a.row_size.should == @side - @a.column_size.should == @side - end + it "returns a n x n matrix" do + @a.row_size.should == @side + @a.column_size.should == @side + end - it "initializes diagonal to value" do - (0...@a.row_size).each do |i| - @a[i, i].should == @value - end + it "initializes diagonal to value" do + (0...@a.row_size).each do |i| + @a[i, i].should == @value end + end - it "initializes all non-diagonal values to 0" do - (0...@a.row_size).each do |i| - (0...@a.column_size).each do |j| - if i != j - @a[i, j].should == 0 - end + it "initializes all non-diagonal values to 0" do + (0...@a.row_size).each do |i| + (0...@a.column_size).each do |j| + if i != j + @a[i, j].should == 0 end end end + end - before :each do - @side = 3 - @value = 8 - @a = Matrix.scalar(@side, @value) - end + before :each do + @side = 3 + @value = 8 + @a = Matrix.scalar(@side, @value) + end - it "returns a Matrix" do - @a.should be_kind_of(Matrix) - end + it "returns a Matrix" do + @a.should be_kind_of(Matrix) + end - it "returns a square matrix, where the first argument specifies the side of the square" do - @a.row_size.should == @side - @a.column_size.should == @side - end + it "returns a square matrix, where the first argument specifies the side of the square" do + @a.row_size.should == @side + @a.column_size.should == @side + end - it "puts the second argument in all diagonal values" do - (0...@a.row_size).each do |i| - @a[i, i].should == @value - end + it "puts the second argument in all diagonal values" do + (0...@a.row_size).each do |i| + @a[i, i].should == @value end + end - it "fills all values not on the main diagonal with 0" do - (0...@a.row_size).each do |i| - (0...@a.column_size).each do |j| - if i != j - @a[i, j].should == 0 - end + it "fills all values not on the main diagonal with 0" do + (0...@a.row_size).each do |i| + (0...@a.column_size).each do |j| + if i != j + @a[i, j].should == 0 end end end diff --git a/spec/ruby/library/matrix/singular_spec.rb b/spec/ruby/library/matrix/singular_spec.rb index 341c2675a8..7bba36a54a 100644 --- a/spec/ruby/library/matrix/singular_spec.rb +++ b/spec/ruby/library/matrix/singular_spec.rb @@ -1,34 +1,31 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' +describe "Matrix#singular?" do + it "returns true for singular matrices" do + m = Matrix[ [1,2,3], [3,4,3], [0,0,0] ] + m.singular?.should be_true - describe "Matrix#singular?" do - it "returns true for singular matrices" do - m = Matrix[ [1,2,3], [3,4,3], [0,0,0] ] - m.singular?.should be_true - - m = Matrix[ [1,2,9], [3,4,9], [1,2,9] ] - m.singular?.should be_true - end - - it "returns false if the Matrix is regular" do - Matrix[ [0,1], [1,0] ].singular?.should be_false - end + m = Matrix[ [1,2,9], [3,4,9], [1,2,9] ] + m.singular?.should be_true + end - it "returns false for an empty 0x0 matrix" do - Matrix.empty(0,0).singular?.should be_false - end + it "returns false if the Matrix is regular" do + Matrix[ [0,1], [1,0] ].singular?.should be_false + end - it "raises an error for rectangular matrices" do - -> { - Matrix[[1], [2], [3]].singular? - }.should raise_error(Matrix::ErrDimensionMismatch) + it "returns false for an empty 0x0 matrix" do + Matrix.empty(0,0).singular?.should be_false + end - -> { - Matrix.empty(3,0).singular? - }.should raise_error(Matrix::ErrDimensionMismatch) - end + it "raises an error for rectangular matrices" do + -> { + Matrix[[1], [2], [3]].singular? + }.should raise_error(Matrix::ErrDimensionMismatch) + -> { + Matrix.empty(3,0).singular? + }.should raise_error(Matrix::ErrDimensionMismatch) end + end diff --git a/spec/ruby/library/matrix/square_spec.rb b/spec/ruby/library/matrix/square_spec.rb index e678f1c702..25d2d1ad9c 100644 --- a/spec/ruby/library/matrix/square_spec.rb +++ b/spec/ruby/library/matrix/square_spec.rb @@ -1,31 +1,28 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' +describe "Matrix#square?" do - describe "Matrix#square?" do - - it "returns true when the Matrix is square" do - Matrix[ [1,2], [2,4] ].square?.should be_true - Matrix[ [100,3,5], [9.5, 4.9, 8], [2,0,77] ].square?.should be_true - end + it "returns true when the Matrix is square" do + Matrix[ [1,2], [2,4] ].square?.should be_true + Matrix[ [100,3,5], [9.5, 4.9, 8], [2,0,77] ].square?.should be_true + end - it "returns true when the Matrix has only one element" do - Matrix[ [9] ].square?.should be_true - end + it "returns true when the Matrix has only one element" do + Matrix[ [9] ].square?.should be_true + end - it "returns false when the Matrix is rectangular" do - Matrix[ [1, 2] ].square?.should be_false - end + it "returns false when the Matrix is rectangular" do + Matrix[ [1, 2] ].square?.should be_false + end - it "returns false when the Matrix is rectangular" do - Matrix[ [1], [2] ].square?.should be_false - end + it "returns false when the Matrix is rectangular" do + Matrix[ [1], [2] ].square?.should be_false + end - it "returns handles empty matrices" do - Matrix[].square?.should be_true - Matrix[[]].square?.should be_false - Matrix.columns([[]]).square?.should be_false - end + it "returns handles empty matrices" do + Matrix[].square?.should be_true + Matrix[[]].square?.should be_false + Matrix.columns([[]]).square?.should be_false end end diff --git a/spec/ruby/library/matrix/symmetric_spec.rb b/spec/ruby/library/matrix/symmetric_spec.rb index 9eed28ac0d..6f2a99276a 100644 --- a/spec/ruby/library/matrix/symmetric_spec.rb +++ b/spec/ruby/library/matrix/symmetric_spec.rb @@ -1,32 +1,29 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix.symmetric?" do - it "returns true for a symmetric Matrix" do - Matrix[[1, 2, Complex(0, 3)], [2, 4, 5], [Complex(0, 3), 5, 6]].symmetric?.should be_true - end +describe "Matrix.symmetric?" do + it "returns true for a symmetric Matrix" do + Matrix[[1, 2, Complex(0, 3)], [2, 4, 5], [Complex(0, 3), 5, 6]].symmetric?.should be_true + end - it "returns true for a 0x0 empty matrix" do - Matrix.empty.symmetric?.should be_true - end + it "returns true for a 0x0 empty matrix" do + Matrix.empty.symmetric?.should be_true + end - it "returns false for an asymmetric Matrix" do - Matrix[[1, 2],[-2, 1]].symmetric?.should be_false - end + it "returns false for an asymmetric Matrix" do + Matrix[[1, 2],[-2, 1]].symmetric?.should be_false + end - it "raises an error for rectangular matrices" do - [ - Matrix[[0], [0]], - Matrix[[0, 0]], - Matrix.empty(0, 2), - Matrix.empty(2, 0), - ].each do |rectangular_matrix| - -> { - rectangular_matrix.symmetric? - }.should raise_error(Matrix::ErrDimensionMismatch) - end + it "raises an error for rectangular matrices" do + [ + Matrix[[0], [0]], + Matrix[[0, 0]], + Matrix.empty(0, 2), + Matrix.empty(2, 0), + ].each do |rectangular_matrix| + -> { + rectangular_matrix.symmetric? + }.should raise_error(Matrix::ErrDimensionMismatch) end end end diff --git a/spec/ruby/library/matrix/t_spec.rb b/spec/ruby/library/matrix/t_spec.rb index 6eb54371ee..6f1a5178e0 100644 --- a/spec/ruby/library/matrix/t_spec.rb +++ b/spec/ruby/library/matrix/t_spec.rb @@ -1,9 +1,6 @@ require_relative '../../spec_helper' +require_relative 'shared/transpose' -ruby_version_is ""..."3.1" do - require_relative 'shared/transpose' - - describe "Matrix#transpose" do - it_behaves_like :matrix_transpose, :t - end +describe "Matrix#transpose" do + it_behaves_like :matrix_transpose, :t end diff --git a/spec/ruby/library/matrix/to_a_spec.rb b/spec/ruby/library/matrix/to_a_spec.rb index 0222a663ac..b5d55c5d67 100644 --- a/spec/ruby/library/matrix/to_a_spec.rb +++ b/spec/ruby/library/matrix/to_a_spec.rb @@ -1,14 +1,11 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix#to_a" do - it "returns the array of arrays that describe the rows of the matrix" do - Matrix[].to_a.should == [] - Matrix[[]].to_a.should == [[]] - Matrix[[1]].to_a.should == [[1]] - Matrix[[1, 2], [3, 4]].to_a.should == [[1, 2],[3, 4]] - end +describe "Matrix#to_a" do + it "returns the array of arrays that describe the rows of the matrix" do + Matrix[].to_a.should == [] + Matrix[[]].to_a.should == [[]] + Matrix[[1]].to_a.should == [[1]] + Matrix[[1, 2], [3, 4]].to_a.should == [[1, 2],[3, 4]] end end diff --git a/spec/ruby/library/matrix/to_s_spec.rb b/spec/ruby/library/matrix/to_s_spec.rb index 7d38655e0d..f529fe3bcd 100644 --- a/spec/ruby/library/matrix/to_s_spec.rb +++ b/spec/ruby/library/matrix/to_s_spec.rb @@ -1,9 +1,6 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix#to_s" do - it "needs to be reviewed for spec completeness" - end +describe "Matrix#to_s" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/matrix/tr_spec.rb b/spec/ruby/library/matrix/tr_spec.rb index bbf274bb5e..e17bd790d7 100644 --- a/spec/ruby/library/matrix/tr_spec.rb +++ b/spec/ruby/library/matrix/tr_spec.rb @@ -1,10 +1,7 @@ require_relative '../../spec_helper' +require_relative 'shared/trace' +require 'matrix' -ruby_version_is ""..."3.1" do - require_relative 'shared/trace' - require 'matrix' - - describe "Matrix#tr" do - it_behaves_like :trace, :tr - end +describe "Matrix#tr" do + it_behaves_like :trace, :tr end diff --git a/spec/ruby/library/matrix/trace_spec.rb b/spec/ruby/library/matrix/trace_spec.rb index ac6ce7927d..290e7cb1f7 100644 --- a/spec/ruby/library/matrix/trace_spec.rb +++ b/spec/ruby/library/matrix/trace_spec.rb @@ -1,10 +1,7 @@ require_relative '../../spec_helper' +require_relative 'shared/trace' +require 'matrix' -ruby_version_is ""..."3.1" do - require_relative 'shared/trace' - require 'matrix' - - describe "Matrix#trace" do - it_behaves_like :trace, :trace - end +describe "Matrix#trace" do + it_behaves_like :trace, :trace end diff --git a/spec/ruby/library/matrix/transpose_spec.rb b/spec/ruby/library/matrix/transpose_spec.rb index d7f495b946..79600dd439 100644 --- a/spec/ruby/library/matrix/transpose_spec.rb +++ b/spec/ruby/library/matrix/transpose_spec.rb @@ -1,9 +1,6 @@ require_relative '../../spec_helper' +require_relative 'shared/transpose' -ruby_version_is ""..."3.1" do - require_relative 'shared/transpose' - - describe "Matrix#transpose" do - it_behaves_like :matrix_transpose, :transpose - end +describe "Matrix#transpose" do + it_behaves_like :matrix_transpose, :transpose end diff --git a/spec/ruby/library/matrix/unit_spec.rb b/spec/ruby/library/matrix/unit_spec.rb index 439e0d616b..6a41d729c7 100644 --- a/spec/ruby/library/matrix/unit_spec.rb +++ b/spec/ruby/library/matrix/unit_spec.rb @@ -1,9 +1,6 @@ require_relative '../../spec_helper' +require_relative 'shared/identity' -ruby_version_is ""..."3.1" do - require_relative 'shared/identity' - - describe "Matrix.unit" do - it_behaves_like :matrix_identity, :unit - end +describe "Matrix.unit" do + it_behaves_like :matrix_identity, :unit end diff --git a/spec/ruby/library/matrix/unitary_spec.rb b/spec/ruby/library/matrix/unitary_spec.rb index b579cb244d..c214ee9b2f 100644 --- a/spec/ruby/library/matrix/unitary_spec.rb +++ b/spec/ruby/library/matrix/unitary_spec.rb @@ -1,36 +1,32 @@ require_relative '../../spec_helper' -ruby_version_is ""..."3.1" do - require 'matrix' +require 'matrix' - describe "Matrix.unitary?" do - it "returns false for non unitary matrices" do - Matrix[[0, 1], [1, 2]].should_not.unitary? - Matrix[[0, Complex(0, 2)], [Complex(0, 2), 0]].should_not.unitary? - Matrix[[1, 1, 0], [0, 1, 1], [1, 0, 1]].should_not.unitary? - end +describe "Matrix.unitary?" do + it "returns false for non unitary matrices" do + Matrix[[0, 1], [1, 2]].should_not.unitary? + Matrix[[0, Complex(0, 2)], [Complex(0, 2), 0]].should_not.unitary? + Matrix[[1, 1, 0], [0, 1, 1], [1, 0, 1]].should_not.unitary? + end - it "returns true for unitary matrices" do - Matrix[[0, Complex(0, 1)], [Complex(0, 1), 0]].should.unitary? - end + it "returns true for unitary matrices" do + Matrix[[0, Complex(0, 1)], [Complex(0, 1), 0]].should.unitary? + end - version_is((Matrix::const_defined?(:VERSION) ? Matrix::VERSION : "0.1.0"), "0.3.0") do - it "returns true for unitary matrices with a Complex and a negative #imag" do - Matrix[[0, Complex(0, 1)], [Complex(0, -1), 0]].should.unitary? - end - end + it "returns true for unitary matrices with a Complex and a negative #imag" do + Matrix[[0, Complex(0, 1)], [Complex(0, -1), 0]].should.unitary? + end - it "raises an error for rectangular matrices" do - [ - Matrix[[0], [0]], - Matrix[[0, 0]], - Matrix.empty(0, 2), - Matrix.empty(2, 0), - ].each do |rectangular_matrix| - -> { - rectangular_matrix.unitary? - }.should raise_error(Matrix::ErrDimensionMismatch) - end + it "raises an error for rectangular matrices" do + [ + Matrix[[0], [0]], + Matrix[[0, 0]], + Matrix.empty(0, 2), + Matrix.empty(2, 0), + ].each do |rectangular_matrix| + -> { + rectangular_matrix.unitary? + }.should raise_error(Matrix::ErrDimensionMismatch) end end end diff --git a/spec/ruby/library/matrix/upper_triangular_spec.rb b/spec/ruby/library/matrix/upper_triangular_spec.rb index cc2aeb7233..2514294a80 100644 --- a/spec/ruby/library/matrix/upper_triangular_spec.rb +++ b/spec/ruby/library/matrix/upper_triangular_spec.rb @@ -1,27 +1,24 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix.upper_triangular?" do - it "returns true for an upper triangular Matrix" do - Matrix[[1, 2, 3], [0, 2, 3], [0, 0, 3]].upper_triangular?.should be_true - Matrix.diagonal([1, 2, 3]).upper_triangular?.should be_true - Matrix[[1, 2], [0, 2], [0, 0], [0, 0]].upper_triangular?.should be_true - Matrix[[1, 2, 3, 4], [0, 2, 3, 4]].upper_triangular?.should be_true - end +describe "Matrix.upper_triangular?" do + it "returns true for an upper triangular Matrix" do + Matrix[[1, 2, 3], [0, 2, 3], [0, 0, 3]].upper_triangular?.should be_true + Matrix.diagonal([1, 2, 3]).upper_triangular?.should be_true + Matrix[[1, 2], [0, 2], [0, 0], [0, 0]].upper_triangular?.should be_true + Matrix[[1, 2, 3, 4], [0, 2, 3, 4]].upper_triangular?.should be_true + end - it "returns false for a non upper triangular square Matrix" do - Matrix[[0, 0], [1, 0]].upper_triangular?.should be_false - Matrix[[1, 2, 3], [1, 2, 3], [1, 2, 3]].upper_triangular?.should be_false - Matrix[[0, 0], [0, 0], [0, 0], [0, 1]].upper_triangular?.should be_false - Matrix[[0, 0, 0, 0], [1, 0, 0, 0]].upper_triangular?.should be_false - end + it "returns false for a non upper triangular square Matrix" do + Matrix[[0, 0], [1, 0]].upper_triangular?.should be_false + Matrix[[1, 2, 3], [1, 2, 3], [1, 2, 3]].upper_triangular?.should be_false + Matrix[[0, 0], [0, 0], [0, 0], [0, 1]].upper_triangular?.should be_false + Matrix[[0, 0, 0, 0], [1, 0, 0, 0]].upper_triangular?.should be_false + end - it "returns true for an empty matrix" do - Matrix.empty(3,0).upper_triangular?.should be_true - Matrix.empty(0,3).upper_triangular?.should be_true - Matrix.empty(0,0).upper_triangular?.should be_true - end + it "returns true for an empty matrix" do + Matrix.empty(3,0).upper_triangular?.should be_true + Matrix.empty(0,3).upper_triangular?.should be_true + Matrix.empty(0,0).upper_triangular?.should be_true end end diff --git a/spec/ruby/library/matrix/vector/cross_product_spec.rb b/spec/ruby/library/matrix/vector/cross_product_spec.rb index 88523824cd..c2698ade4c 100644 --- a/spec/ruby/library/matrix/vector/cross_product_spec.rb +++ b/spec/ruby/library/matrix/vector/cross_product_spec.rb @@ -1,17 +1,14 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Vector#cross_product" do - it "returns the cross product of a vector" do - Vector[1, 2, 3].cross_product(Vector[0, -4, 5]).should == Vector[22, -5, -4] - end +describe "Vector#cross_product" do + it "returns the cross product of a vector" do + Vector[1, 2, 3].cross_product(Vector[0, -4, 5]).should == Vector[22, -5, -4] + end - it "raises an error unless both vectors have dimension 3" do - -> { - Vector[1, 2, 3].cross_product(Vector[0, -4]) - }.should raise_error(Vector::ErrDimensionMismatch) - end + it "raises an error unless both vectors have dimension 3" do + -> { + Vector[1, 2, 3].cross_product(Vector[0, -4]) + }.should raise_error(Vector::ErrDimensionMismatch) end end diff --git a/spec/ruby/library/matrix/vector/each2_spec.rb b/spec/ruby/library/matrix/vector/each2_spec.rb index bdd6966472..10d2fc404d 100644 --- a/spec/ruby/library/matrix/vector/each2_spec.rb +++ b/spec/ruby/library/matrix/vector/each2_spec.rb @@ -1,52 +1,49 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' +describe "Vector.each2" do + before :all do + @v = Vector[1, 2, 3] + @v2 = Vector[4, 5, 6] + end + + it "requires one argument" do + -> { @v.each2(@v2, @v2){} }.should raise_error(ArgumentError) + -> { @v.each2(){} }.should raise_error(ArgumentError) + end + + describe "given one argument" do + it "accepts an Array argument" do + a = [] + @v.each2([7, 8, 9]){|x, y| a << x << y} + a.should == [1, 7, 2, 8, 3, 9] + end + + it "raises a DimensionMismatch error if the Vector size is different" do + -> { @v.each2(Vector[1,2]){} }.should raise_error(Vector::ErrDimensionMismatch) + -> { @v.each2(Vector[1,2,3,4]){} }.should raise_error(Vector::ErrDimensionMismatch) + end + + it "yields arguments in sequence" do + a = [] + @v.each2(@v2){|first, second| a << [first, second]} + a.should == [[1, 4], [2, 5], [3, 6]] + end - describe "Vector.each2" do - before :all do - @v = Vector[1, 2, 3] - @v2 = Vector[4, 5, 6] + it "yield arguments in pairs" do + a = [] + @v.each2(@v2){|*pair| a << pair} + a.should == [[1, 4], [2, 5], [3, 6]] end - it "requires one argument" do - -> { @v.each2(@v2, @v2){} }.should raise_error(ArgumentError) - -> { @v.each2(){} }.should raise_error(ArgumentError) + it "returns self when given a block" do + @v.each2(@v2){}.should equal(@v) end - describe "given one argument" do - it "accepts an Array argument" do - a = [] - @v.each2([7, 8, 9]){|x, y| a << x << y} - a.should == [1, 7, 2, 8, 3, 9] - end - - it "raises a DimensionMismatch error if the Vector size is different" do - -> { @v.each2(Vector[1,2]){} }.should raise_error(Vector::ErrDimensionMismatch) - -> { @v.each2(Vector[1,2,3,4]){} }.should raise_error(Vector::ErrDimensionMismatch) - end - - it "yields arguments in sequence" do - a = [] - @v.each2(@v2){|first, second| a << [first, second]} - a.should == [[1, 4], [2, 5], [3, 6]] - end - - it "yield arguments in pairs" do - a = [] - @v.each2(@v2){|*pair| a << pair} - a.should == [[1, 4], [2, 5], [3, 6]] - end - - it "returns self when given a block" do - @v.each2(@v2){}.should equal(@v) - end - - it "returns an enumerator if no block given" do - enum = @v.each2(@v2) - enum.should be_an_instance_of(Enumerator) - enum.to_a.should == [[1, 4], [2, 5], [3, 6]] - end + it "returns an enumerator if no block given" do + enum = @v.each2(@v2) + enum.should be_an_instance_of(Enumerator) + enum.to_a.should == [[1, 4], [2, 5], [3, 6]] end end end diff --git a/spec/ruby/library/matrix/vector/eql_spec.rb b/spec/ruby/library/matrix/vector/eql_spec.rb index fa086bd33a..eb2451b550 100644 --- a/spec/ruby/library/matrix/vector/eql_spec.rb +++ b/spec/ruby/library/matrix/vector/eql_spec.rb @@ -1,19 +1,16 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Vector#eql?" do - before do - @vector = Vector[1, 2, 3, 4, 5] - end +describe "Vector#eql?" do + before do + @vector = Vector[1, 2, 3, 4, 5] + end - it "returns true for self" do - @vector.eql?(@vector).should be_true - end + it "returns true for self" do + @vector.eql?(@vector).should be_true + end - it "returns false when there are a pair corresponding elements which are not equal in the sense of Kernel#eql?" do - @vector.eql?(Vector[1, 2, 3, 4, 5.0]).should be_false - end + it "returns false when there are a pair corresponding elements which are not equal in the sense of Kernel#eql?" do + @vector.eql?(Vector[1, 2, 3, 4, 5.0]).should be_false end end diff --git a/spec/ruby/library/matrix/vector/inner_product_spec.rb b/spec/ruby/library/matrix/vector/inner_product_spec.rb index 95dc4806b5..1cf8771e04 100644 --- a/spec/ruby/library/matrix/vector/inner_product_spec.rb +++ b/spec/ruby/library/matrix/vector/inner_product_spec.rb @@ -1,25 +1,22 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Vector#inner_product" do - it "returns the inner product of a vector" do - Vector[1, 2, 3].inner_product(Vector[0, -4, 5]).should == 7 - end +describe "Vector#inner_product" do + it "returns the inner product of a vector" do + Vector[1, 2, 3].inner_product(Vector[0, -4, 5]).should == 7 + end - it "returns 0 for empty vectors" do - Vector[].inner_product(Vector[]).should == 0 - end + it "returns 0 for empty vectors" do + Vector[].inner_product(Vector[]).should == 0 + end - it "raises an error for mismatched vectors" do - -> { - Vector[1, 2, 3].inner_product(Vector[0, -4]) - }.should raise_error(Vector::ErrDimensionMismatch) - end + it "raises an error for mismatched vectors" do + -> { + Vector[1, 2, 3].inner_product(Vector[0, -4]) + }.should raise_error(Vector::ErrDimensionMismatch) + end - it "uses the conjugate of its argument" do - Vector[Complex(1,2)].inner_product(Vector[Complex(3,4)]).should == Complex(11, 2) - end + it "uses the conjugate of its argument" do + Vector[Complex(1,2)].inner_product(Vector[Complex(3,4)]).should == Complex(11, 2) end end diff --git a/spec/ruby/library/matrix/vector/normalize_spec.rb b/spec/ruby/library/matrix/vector/normalize_spec.rb index 7345e11fa4..527c9260de 100644 --- a/spec/ruby/library/matrix/vector/normalize_spec.rb +++ b/spec/ruby/library/matrix/vector/normalize_spec.rb @@ -1,21 +1,18 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Vector#normalize" do - it "returns a normalized copy of the vector" do - x = 0.2672612419124244 - Vector[1, 2, 3].normalize.should == Vector[x, x * 2, x * 3] - end +describe "Vector#normalize" do + it "returns a normalized copy of the vector" do + x = 0.2672612419124244 + Vector[1, 2, 3].normalize.should == Vector[x, x * 2, x * 3] + end - it "raises an error for zero vectors" do - -> { - Vector[].normalize - }.should raise_error(Vector::ZeroVectorError) - -> { - Vector[0, 0, 0].normalize - }.should raise_error(Vector::ZeroVectorError) - end + it "raises an error for zero vectors" do + -> { + Vector[].normalize + }.should raise_error(Vector::ZeroVectorError) + -> { + Vector[0, 0, 0].normalize + }.should raise_error(Vector::ZeroVectorError) end end diff --git a/spec/ruby/library/matrix/zero_spec.rb b/spec/ruby/library/matrix/zero_spec.rb index 80162a03d0..68e8567c26 100644 --- a/spec/ruby/library/matrix/zero_spec.rb +++ b/spec/ruby/library/matrix/zero_spec.rb @@ -1,55 +1,52 @@ require_relative '../../spec_helper' +require_relative 'fixtures/classes' +require 'matrix' -ruby_version_is ""..."3.1" do - require_relative 'fixtures/classes' - require 'matrix' - - describe "Matrix.zero" do - it "returns an object of type Matrix" do - Matrix.zero(3).should be_kind_of(Matrix) - end +describe "Matrix.zero" do + it "returns an object of type Matrix" do + Matrix.zero(3).should be_kind_of(Matrix) + end - it "creates a n x n matrix" do - m3 = Matrix.zero(3) - m3.row_size.should == 3 - m3.column_size.should == 3 + it "creates a n x n matrix" do + m3 = Matrix.zero(3) + m3.row_size.should == 3 + m3.column_size.should == 3 - m8 = Matrix.zero(8) - m8.row_size.should == 8 - m8.column_size.should == 8 - end + m8 = Matrix.zero(8) + m8.row_size.should == 8 + m8.column_size.should == 8 + end - it "initializes all cells to 0" do - size = 10 - m = Matrix.zero(size) + it "initializes all cells to 0" do + size = 10 + m = Matrix.zero(size) - (0...size).each do |i| - (0...size).each do |j| - m[i, j].should == 0 - end + (0...size).each do |i| + (0...size).each do |j| + m[i, j].should == 0 end end + end - describe "for a subclass of Matrix" do - it "returns an instance of that subclass" do - MatrixSub.zero(3).should be_an_instance_of(MatrixSub) - end + describe "for a subclass of Matrix" do + it "returns an instance of that subclass" do + MatrixSub.zero(3).should be_an_instance_of(MatrixSub) end end +end - describe "Matrix.zero?" do - it "returns true for empty matrices" do - Matrix.empty.should.zero? - Matrix.empty(3,0).should.zero? - Matrix.empty(0,3).should.zero? - end +describe "Matrix.zero?" do + it "returns true for empty matrices" do + Matrix.empty.should.zero? + Matrix.empty(3,0).should.zero? + Matrix.empty(0,3).should.zero? + end - it "returns true for matrices with zero entries" do - Matrix.zero(2,3).should.zero? - end + it "returns true for matrices with zero entries" do + Matrix.zero(2,3).should.zero? + end - it "returns false for matrices with non zero entries" do - Matrix[[1]].should_not.zero? - end + it "returns false for matrices with non zero entries" do + Matrix[[1]].should_not.zero? end end diff --git a/spec/ruby/library/monitor/exit_spec.rb b/spec/ruby/library/monitor/exit_spec.rb new file mode 100644 index 0000000000..952ad9525d --- /dev/null +++ b/spec/ruby/library/monitor/exit_spec.rb @@ -0,0 +1,10 @@ +require_relative '../../spec_helper' +require 'monitor' + +describe "Monitor#exit" do + it "raises ThreadError when monitor is not entered" do + m = Monitor.new + + -> { m.exit }.should raise_error(ThreadError) + end +end diff --git a/spec/ruby/library/net-ftp/FTPError_spec.rb b/spec/ruby/library/net-ftp/FTPError_spec.rb new file mode 100644 index 0000000000..0c31b65dcc --- /dev/null +++ b/spec/ruby/library/net-ftp/FTPError_spec.rb @@ -0,0 +1,8 @@ +require_relative '../../spec_helper' +require 'net/ftp' + +describe "Net::FTPError" do + it "is an Exception" do + Net::FTPError.should < Exception + end +end diff --git a/spec/ruby/library/net-ftp/FTPPermError_spec.rb b/spec/ruby/library/net-ftp/FTPPermError_spec.rb new file mode 100644 index 0000000000..b43e12c503 --- /dev/null +++ b/spec/ruby/library/net-ftp/FTPPermError_spec.rb @@ -0,0 +1,12 @@ +require_relative '../../spec_helper' +require 'net/ftp' + +describe "Net::FTPPermError" do + it "is an Exception" do + Net::FTPPermError.should < Exception + end + + it "is a subclass of Net::FTPError" do + Net::FTPPermError.should < Net::FTPError + end +end diff --git a/spec/ruby/library/net-ftp/FTPProtoError_spec.rb b/spec/ruby/library/net-ftp/FTPProtoError_spec.rb new file mode 100644 index 0000000000..e7abbc0dd8 --- /dev/null +++ b/spec/ruby/library/net-ftp/FTPProtoError_spec.rb @@ -0,0 +1,12 @@ +require_relative '../../spec_helper' +require 'net/ftp' + +describe "Net::FTPProtoError" do + it "is an Exception" do + Net::FTPProtoError.should < Exception + end + + it "is a subclass of Net::FTPError" do + Net::FTPPermError.should < Net::FTPError + end +end diff --git a/spec/ruby/library/net-ftp/FTPReplyError_spec.rb b/spec/ruby/library/net-ftp/FTPReplyError_spec.rb new file mode 100644 index 0000000000..fcc7501fc1 --- /dev/null +++ b/spec/ruby/library/net-ftp/FTPReplyError_spec.rb @@ -0,0 +1,12 @@ +require_relative '../../spec_helper' +require 'net/ftp' + +describe "Net::FTPReplyError" do + it "is an Exception" do + Net::FTPReplyError.should < Exception + end + + it "is a subclass of Net::FTPError" do + Net::FTPPermError.should < Net::FTPError + end +end diff --git a/spec/ruby/library/net-ftp/FTPTempError_spec.rb b/spec/ruby/library/net-ftp/FTPTempError_spec.rb new file mode 100644 index 0000000000..f4b045dfb5 --- /dev/null +++ b/spec/ruby/library/net-ftp/FTPTempError_spec.rb @@ -0,0 +1,12 @@ +require_relative '../../spec_helper' +require 'net/ftp' + +describe "Net::FTPTempError" do + it "is an Exception" do + Net::FTPTempError.should < Exception + end + + it "is a subclass of Net::FTPError" do + Net::FTPPermError.should < Net::FTPError + end +end diff --git a/spec/ruby/library/net-ftp/abort_spec.rb b/spec/ruby/library/net-ftp/abort_spec.rb new file mode 100644 index 0000000000..335d056512 --- /dev/null +++ b/spec/ruby/library/net-ftp/abort_spec.rb @@ -0,0 +1,62 @@ +require_relative '../../spec_helper' +require_relative 'spec_helper' +require_relative 'fixtures/server' + +describe "Net::FTP#abort" do + before :each do + @server = NetFTPSpecs::DummyFTP.new + @server.serve_once + + @ftp = Net::FTP.new + @ftp.connect(@server.hostname, @server.server_port) + end + + after :each do + @ftp.quit rescue nil + @ftp.close + @server.stop + end + + it "sends the ABOR command to the server" do + -> { @ftp.abort }.should_not raise_error + end + + it "ignores the response" do + @ftp.abort + @ftp.last_response.should == "220 Dummy FTP Server ready!\n" + end + + it "returns the full response" do + @ftp.abort.should == "226 Closing data connection. (ABOR)\n" + end + + it "does not raise any error when the response code is 225" do + @server.should_receive(:abor).and_respond("225 Data connection open; no transfer in progress.") + -> { @ftp.abort }.should_not raise_error + end + + it "does not raise any error when the response code is 226" do + @server.should_receive(:abor).and_respond("226 Closing data connection.") + -> { @ftp.abort }.should_not raise_error + end + + it "raises a Net::FTPProtoError when the response code is 500" do + @server.should_receive(:abor).and_respond("500 Syntax error, command unrecognized.") + -> { @ftp.abort }.should raise_error(Net::FTPProtoError) + end + + it "raises a Net::FTPProtoError when the response code is 501" do + @server.should_receive(:abor).and_respond("501 Syntax error in parameters or arguments.") + -> { @ftp.abort }.should raise_error(Net::FTPProtoError) + end + + it "raises a Net::FTPProtoError when the response code is 502" do + @server.should_receive(:abor).and_respond("502 Command not implemented.") + -> { @ftp.abort }.should raise_error(Net::FTPProtoError) + end + + it "raises a Net::FTPProtoError when the response code is 421" do + @server.should_receive(:abor).and_respond("421 Service not available, closing control connection.") + -> { @ftp.abort }.should raise_error(Net::FTPProtoError) + end +end diff --git a/spec/ruby/library/net-ftp/acct_spec.rb b/spec/ruby/library/net-ftp/acct_spec.rb new file mode 100644 index 0000000000..ab093448a2 --- /dev/null +++ b/spec/ruby/library/net-ftp/acct_spec.rb @@ -0,0 +1,58 @@ +require_relative '../../spec_helper' +require_relative 'spec_helper' +require_relative 'fixtures/server' + +describe "Net::FTP#acct" do + before :each do + @server = NetFTPSpecs::DummyFTP.new + @server.serve_once + + @ftp = Net::FTP.new + @ftp.connect(@server.hostname, @server.server_port) + end + + after :each do + @ftp.quit rescue nil + @ftp.close + @server.stop + end + + it "writes the ACCT command to the server" do + @ftp.acct("my_account") + @ftp.last_response.should == "230 User 'my_account' logged in, proceed. (ACCT)\n" + end + + it "returns nil" do + @ftp.acct("my_account").should == nil + end + + it "does not raise any error when the response code is 230" do + @server.should_receive(:acct).and_respond("230 User logged in, proceed.") + -> { @ftp.acct("my_account") }.should_not raise_error + end + + it "raises a Net::FTPPermError when the response code is 530" do + @server.should_receive(:acct).and_respond("530 Not logged in.") + -> { @ftp.acct("my_account") }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 500" do + @server.should_receive(:acct).and_respond("500 Syntax error, command unrecognized.") + -> { @ftp.acct("my_account") }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 501" do + @server.should_receive(:acct).and_respond("501 Syntax error in parameters or arguments.") + -> { @ftp.acct("my_account") }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 503" do + @server.should_receive(:acct).and_respond("503 Bad sequence of commands.") + -> { @ftp.acct("my_account") }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPTempError when the response code is 421" do + @server.should_receive(:acct).and_respond("421 Service not available, closing control connection.") + -> { @ftp.acct("my_account") }.should raise_error(Net::FTPTempError) + end +end diff --git a/spec/ruby/library/net-ftp/binary_spec.rb b/spec/ruby/library/net-ftp/binary_spec.rb new file mode 100644 index 0000000000..1e0585b795 --- /dev/null +++ b/spec/ruby/library/net-ftp/binary_spec.rb @@ -0,0 +1,24 @@ +require_relative '../../spec_helper' +require_relative 'spec_helper' + +describe "Net::FTP#binary" do + it "returns true when self is in binary mode" do + ftp = Net::FTP.new + ftp.binary.should be_true + + ftp.binary = false + ftp.binary.should be_false + end +end + +describe "Net::FTP#binary=" do + it "sets self to binary mode when passed true" do + ftp = Net::FTP.new + + ftp.binary = true + ftp.binary.should be_true + + ftp.binary = false + ftp.binary.should be_false + end +end diff --git a/spec/ruby/library/net-ftp/chdir_spec.rb b/spec/ruby/library/net-ftp/chdir_spec.rb new file mode 100644 index 0000000000..cc129b5e42 --- /dev/null +++ b/spec/ruby/library/net-ftp/chdir_spec.rb @@ -0,0 +1,99 @@ +require_relative '../../spec_helper' +require_relative 'spec_helper' +require_relative 'fixtures/server' + +describe "Net::FTP#chdir" do + before :each do + @server = NetFTPSpecs::DummyFTP.new + @server.serve_once + + @ftp = Net::FTP.new + @ftp.connect(@server.hostname, @server.server_port) + end + + after :each do + @ftp.quit rescue nil + @ftp.close + @server.stop + end + + describe "when switching to the parent directory" do + it "sends the 'CDUP' command to the server" do + @ftp.chdir("..") + @ftp.last_response.should == "200 Command okay. (CDUP)\n" + end + + it "returns nil" do + @ftp.chdir("..").should be_nil + end + + it "does not raise a Net::FTPPermError when the response code is 500" do + @server.should_receive(:cdup).and_respond("500 Syntax error, command unrecognized.") + -> { @ftp.chdir("..") }.should_not raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 501" do + @server.should_receive(:cdup).and_respond("501 Syntax error in parameters or arguments.") + -> { @ftp.chdir("..") }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 502" do + @server.should_receive(:cdup).and_respond("502 Command not implemented.") + -> { @ftp.chdir("..") }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPTempError when the response code is 421" do + @server.should_receive(:cdup).and_respond("421 Service not available, closing control connection.") + -> { @ftp.chdir("..") }.should raise_error(Net::FTPTempError) + end + + it "raises a Net::FTPPermError when the response code is 530" do + @server.should_receive(:cdup).and_respond("530 Not logged in.") + -> { @ftp.chdir("..") }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 550" do + @server.should_receive(:cdup).and_respond("550 Requested action not taken.") + -> { @ftp.chdir("..") }.should raise_error(Net::FTPPermError) + end + end + + it "writes the 'CWD' command with the passed directory to the socket" do + @ftp.chdir("test") + @ftp.last_response.should == "200 Command okay. (CWD test)\n" + end + + it "returns nil" do + @ftp.chdir("test").should be_nil + end + + it "raises a Net::FTPPermError when the response code is 500" do + @server.should_receive(:cwd).and_respond("500 Syntax error, command unrecognized.") + -> { @ftp.chdir("test") }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 501" do + @server.should_receive(:cwd).and_respond("501 Syntax error in parameters or arguments.") + -> { @ftp.chdir("test") }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 502" do + @server.should_receive(:cwd).and_respond("502 Command not implemented.") + -> { @ftp.chdir("test") }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPTempError when the response code is 421" do + @server.should_receive(:cwd).and_respond("421 Service not available, closing control connection.") + -> { @ftp.chdir("test") }.should raise_error(Net::FTPTempError) + end + + it "raises a Net::FTPPermError when the response code is 530" do + @server.should_receive(:cwd).and_respond("530 Not logged in.") + -> { @ftp.chdir("test") }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 550" do + @server.should_receive(:cwd).and_respond("550 Requested action not taken.") + -> { @ftp.chdir("test") }.should raise_error(Net::FTPPermError) + end +end diff --git a/spec/ruby/library/net-ftp/close_spec.rb b/spec/ruby/library/net-ftp/close_spec.rb new file mode 100644 index 0000000000..183f14a84b --- /dev/null +++ b/spec/ruby/library/net-ftp/close_spec.rb @@ -0,0 +1,30 @@ +require_relative '../../spec_helper' +require_relative 'spec_helper' + +describe "Net::FTP#close" do + before :each do + @socket = mock("Socket") + @socket.stub!(:closed?).and_return(false) + @socket.stub!(:read_timeout).and_return(60) + @socket.stub!(:read_timeout=).and_return(3) + + @ftp = Net::FTP.new + @ftp.instance_variable_set(:@sock, @socket) + end + + it "closes the socket" do + @socket.should_receive(:close) + @ftp.close.should be_nil + end + + it "does not try to close the socket if it has already been closed" do + @socket.should_receive(:closed?).and_return(true) + @socket.should_not_receive(:close) + @ftp.close.should be_nil + end + + it "does not try to close the socket if it is nil" do + @ftp.instance_variable_set(:@sock, nil) + @ftp.close.should be_nil + end +end diff --git a/spec/ruby/library/net-ftp/closed_spec.rb b/spec/ruby/library/net-ftp/closed_spec.rb new file mode 100644 index 0000000000..84001cdc0f --- /dev/null +++ b/spec/ruby/library/net-ftp/closed_spec.rb @@ -0,0 +1,21 @@ +require_relative '../../spec_helper' +require_relative 'spec_helper' + +describe "Net::FTP#closed?" do + before :each do + @socket = mock("Socket") + + @ftp = Net::FTP.new + @ftp.instance_variable_set(:@sock, @socket) + end + + it "returns true when the socket is closed" do + @socket.should_receive(:closed?).and_return(true) + @ftp.closed?.should be_true + end + + it "returns true when the socket is nil" do + @ftp.instance_variable_set(:@sock, nil) + @ftp.closed?.should be_true + end +end diff --git a/spec/ruby/library/net-ftp/connect_spec.rb b/spec/ruby/library/net-ftp/connect_spec.rb new file mode 100644 index 0000000000..e606b11e2a --- /dev/null +++ b/spec/ruby/library/net-ftp/connect_spec.rb @@ -0,0 +1,43 @@ +require_relative '../../spec_helper' +require_relative 'spec_helper' +require_relative 'fixtures/server' + +# TODO: Add specs for using the SOCKSSocket +describe "Net::FTP#connect" do + before :each do + @server = NetFTPSpecs::DummyFTP.new + @server.serve_once + + @ftp = Net::FTP.new + end + + after :each do + @server.connect_message = nil + @ftp.quit rescue nil + @ftp.close + @server.stop + end + + it "tries to connect to the FTP Server on the given host and port" do + -> { @ftp.connect(@server.hostname, @server.server_port) }.should_not raise_error + end + + it "returns nil" do + @ftp.connect(@server.hostname, @server.server_port).should be_nil + end + + it "does not raise any error when the response code is 220" do + @server.connect_message = "220 Dummy FTP Server ready!" + -> { @ftp.connect(@server.hostname, @server.server_port) }.should_not raise_error + end + + it "raises a Net::FTPReplyError when the response code is 120" do + @server.connect_message = "120 Service ready in nnn minutes." + -> { @ftp.connect(@server.hostname, @server.server_port) }.should raise_error(Net::FTPReplyError) + end + + it "raises a Net::FTPTempError when the response code is 421" do + @server.connect_message = "421 Service not available, closing control connection." + -> { @ftp.connect(@server.hostname, @server.server_port) }.should raise_error(Net::FTPTempError) + end +end diff --git a/spec/ruby/library/net-ftp/debug_mode_spec.rb b/spec/ruby/library/net-ftp/debug_mode_spec.rb new file mode 100644 index 0000000000..f2ef53c089 --- /dev/null +++ b/spec/ruby/library/net-ftp/debug_mode_spec.rb @@ -0,0 +1,23 @@ +require_relative '../../spec_helper' +require_relative 'spec_helper' + +describe "Net::FTP#debug_mode" do + it "returns true when self is in debug mode" do + ftp = Net::FTP.new + ftp.debug_mode.should be_false + + ftp.debug_mode = true + ftp.debug_mode.should be_true + end +end + +describe "Net::FTP#debug_mode=" do + it "sets self into debug mode when passed true" do + ftp = Net::FTP.new + ftp.debug_mode = true + ftp.debug_mode.should be_true + + ftp.debug_mode = false + ftp.debug_mode.should be_false + end +end diff --git a/spec/ruby/library/net-ftp/default_passive_spec.rb b/spec/ruby/library/net-ftp/default_passive_spec.rb new file mode 100644 index 0000000000..3f14f6187e --- /dev/null +++ b/spec/ruby/library/net-ftp/default_passive_spec.rb @@ -0,0 +1,8 @@ +require_relative '../../spec_helper' +require_relative 'spec_helper' + +describe "Net::FTP#default_passive" do + it "is true by default" do + ruby_exe(fixture(__FILE__, "default_passive.rb")).should == "true\ntrue\n" + end +end diff --git a/spec/ruby/library/net-ftp/delete_spec.rb b/spec/ruby/library/net-ftp/delete_spec.rb new file mode 100644 index 0000000000..bfb7da1ffe --- /dev/null +++ b/spec/ruby/library/net-ftp/delete_spec.rb @@ -0,0 +1,59 @@ +require_relative '../../spec_helper' +require_relative 'spec_helper' +require_relative 'fixtures/server' + +describe "Net::FTP#delete" do + before :each do + @server = NetFTPSpecs::DummyFTP.new + @server.serve_once + + @ftp = Net::FTP.new + @ftp.connect(@server.hostname, @server.server_port) + end + + after :each do + @ftp.quit rescue nil + @ftp.close + @server.stop + end + + it "sends the DELE command with the passed filename to the server" do + @ftp.delete("test.file") + @ftp.last_response.should == "250 Requested file action okay, completed. (DELE test.file)\n" + end + + it "raises a Net::FTPTempError when the response code is 450" do + @server.should_receive(:dele).and_respond("450 Requested file action not taken.") + -> { @ftp.delete("test.file") }.should raise_error(Net::FTPTempError) + end + + it "raises a Net::FTPPermError when the response code is 550" do + @server.should_receive(:dele).and_respond("550 Requested action not taken.") + -> { @ftp.delete("test.file") }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 500" do + @server.should_receive(:dele).and_respond("500 Syntax error, command unrecognized.") + -> { @ftp.delete("test.file") }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 501" do + @server.should_receive(:dele).and_respond("501 Syntax error in parameters or arguments.") + -> { @ftp.delete("test.file") }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 502" do + @server.should_receive(:dele).and_respond("502 Command not implemented.") + -> { @ftp.delete("test.file") }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPTempError when the response code is 421" do + @server.should_receive(:dele).and_respond("421 Service not available, closing control connection.") + -> { @ftp.delete("test.file") }.should raise_error(Net::FTPTempError) + end + + it "raises a Net::FTPPermError when the response code is 530" do + @server.should_receive(:dele).and_respond("530 Not logged in.") + -> { @ftp.delete("test.file") }.should raise_error(Net::FTPPermError) + end +end diff --git a/spec/ruby/library/net-ftp/dir_spec.rb b/spec/ruby/library/net-ftp/dir_spec.rb new file mode 100644 index 0000000000..894f03dd7b --- /dev/null +++ b/spec/ruby/library/net-ftp/dir_spec.rb @@ -0,0 +1,8 @@ +require_relative '../../spec_helper' +require_relative 'spec_helper' +require_relative 'fixtures/server' +require_relative 'shared/list' + +describe "Net::FTP#dir" do + it_behaves_like :net_ftp_list, :dir +end diff --git a/spec/ruby/library/net/ftp/fixtures/default_passive.rb b/spec/ruby/library/net-ftp/fixtures/default_passive.rb index b6995d6f34..b6995d6f34 100644 --- a/spec/ruby/library/net/ftp/fixtures/default_passive.rb +++ b/spec/ruby/library/net-ftp/fixtures/default_passive.rb diff --git a/spec/ruby/library/net/ftp/fixtures/passive.rb b/spec/ruby/library/net-ftp/fixtures/passive.rb index 6b5cde82df..6b5cde82df 100644 --- a/spec/ruby/library/net/ftp/fixtures/passive.rb +++ b/spec/ruby/library/net-ftp/fixtures/passive.rb diff --git a/spec/ruby/library/net/ftp/fixtures/putbinaryfile b/spec/ruby/library/net-ftp/fixtures/putbinaryfile index f3130c6e43..f3130c6e43 100644 --- a/spec/ruby/library/net/ftp/fixtures/putbinaryfile +++ b/spec/ruby/library/net-ftp/fixtures/putbinaryfile diff --git a/spec/ruby/library/net/ftp/fixtures/puttextfile b/spec/ruby/library/net-ftp/fixtures/puttextfile index b4f3b2b62d..b4f3b2b62d 100644 --- a/spec/ruby/library/net/ftp/fixtures/puttextfile +++ b/spec/ruby/library/net-ftp/fixtures/puttextfile diff --git a/spec/ruby/library/net/ftp/fixtures/server.rb b/spec/ruby/library/net-ftp/fixtures/server.rb index ecbed591d5..8b34d3f8bd 100644 --- a/spec/ruby/library/net/ftp/fixtures/server.rb +++ b/spec/ruby/library/net-ftp/fixtures/server.rb @@ -9,7 +9,7 @@ module NetFTPSpecs attr_reader :server_port def initialize - @hostname = "localhost" + @hostname = "127.0.0.1" @server = TCPServer.new(@hostname, 0) @server_port = @server.addr[1] diff --git a/spec/ruby/library/net-ftp/get_spec.rb b/spec/ruby/library/net-ftp/get_spec.rb new file mode 100644 index 0000000000..1bc1bd744b --- /dev/null +++ b/spec/ruby/library/net-ftp/get_spec.rb @@ -0,0 +1,21 @@ +require_relative '../../spec_helper' +require_relative 'spec_helper' +require_relative 'fixtures/server' +require_relative 'shared/gettextfile' +require_relative 'shared/getbinaryfile' + +describe "Net::FTP#get (binary mode)" do + before :each do + @binary_mode = true + end + + it_behaves_like :net_ftp_getbinaryfile, :get +end + +describe "Net::FTP#get (text mode)" do + before :each do + @binary_mode = false + end + + it_behaves_like :net_ftp_gettextfile, :get +end diff --git a/spec/ruby/library/net-ftp/getbinaryfile_spec.rb b/spec/ruby/library/net-ftp/getbinaryfile_spec.rb new file mode 100644 index 0000000000..e9898fccc7 --- /dev/null +++ b/spec/ruby/library/net-ftp/getbinaryfile_spec.rb @@ -0,0 +1,8 @@ +require_relative '../../spec_helper' +require_relative 'spec_helper' +require_relative 'fixtures/server' +require_relative 'shared/getbinaryfile' + +describe "Net::FTP#getbinaryfile" do + it_behaves_like :net_ftp_getbinaryfile, :getbinaryfile +end diff --git a/spec/ruby/library/net-ftp/getdir_spec.rb b/spec/ruby/library/net-ftp/getdir_spec.rb new file mode 100644 index 0000000000..756d6a23af --- /dev/null +++ b/spec/ruby/library/net-ftp/getdir_spec.rb @@ -0,0 +1,7 @@ +require_relative '../../spec_helper' +require_relative 'spec_helper' +require_relative 'shared/pwd' + +describe "Net::FTP#getdir" do + it_behaves_like :net_ftp_pwd, :getdir +end diff --git a/spec/ruby/library/net-ftp/gettextfile_spec.rb b/spec/ruby/library/net-ftp/gettextfile_spec.rb new file mode 100644 index 0000000000..cdd1b4c797 --- /dev/null +++ b/spec/ruby/library/net-ftp/gettextfile_spec.rb @@ -0,0 +1,8 @@ +require_relative '../../spec_helper' +require_relative 'spec_helper' +require_relative 'fixtures/server' +require_relative 'shared/gettextfile' + +describe "Net::FTP#gettextfile" do + it_behaves_like :net_ftp_gettextfile, :gettextfile +end diff --git a/spec/ruby/library/net-ftp/help_spec.rb b/spec/ruby/library/net-ftp/help_spec.rb new file mode 100644 index 0000000000..c562be50b2 --- /dev/null +++ b/spec/ruby/library/net-ftp/help_spec.rb @@ -0,0 +1,66 @@ +require_relative '../../spec_helper' +require_relative 'spec_helper' +require_relative 'fixtures/server' + +describe "Net::FTP#help" do + def with_connection + yield + end + + before :each do + @server = NetFTPSpecs::DummyFTP.new + @server.serve_once + + @ftp = Net::FTP.new + @ftp.connect(@server.hostname, @server.server_port) + end + + after :each do + @ftp.quit rescue nil + @ftp.close + @server.stop + end + + it "writes the HELP command to the server" do + @ftp.help + @ftp.last_response.should == "211 System status, or system help reply. (HELP)\n" + end + + it "returns the server's response" do + @ftp.help.should == "211 System status, or system help reply. (HELP)\n" + end + + it "writes the HELP command with an optional parameter to the socket" do + @ftp.help("some parameter").should == "211 System status, or system help reply. (HELP some parameter)\n" + end + + it "does not raise any error when the response code is 211" do + @server.should_receive(:help).and_respond("211 System status, or system help reply.") + -> { @ftp.help }.should_not raise_error + end + + it "does not raise any error when the response code is 214" do + @server.should_receive(:help).and_respond("214 Help message.") + -> { @ftp.help }.should_not raise_error + end + + it "raises a Net::FTPPermError when the response code is 500" do + @server.should_receive(:help).and_respond("500 Syntax error, command unrecognized.") + -> { @ftp.help }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 501" do + @server.should_receive(:help).and_respond("501 Syntax error in parameters or arguments.") + -> { @ftp.help }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 502" do + @server.should_receive(:help).and_respond("502 Command not implemented.") + -> { @ftp.help }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPTempError when the response code is 421" do + @server.should_receive(:help).and_respond("421 Service not available, closing control connection.") + -> { @ftp.help }.should raise_error(Net::FTPTempError) + end +end diff --git a/spec/ruby/library/net-ftp/initialize_spec.rb b/spec/ruby/library/net-ftp/initialize_spec.rb new file mode 100644 index 0000000000..4d775e8dc1 --- /dev/null +++ b/spec/ruby/library/net-ftp/initialize_spec.rb @@ -0,0 +1,405 @@ +require_relative '../../spec_helper' +require_relative 'spec_helper' + +describe "Net::FTP#initialize" do + before :each do + @ftp = Net::FTP.allocate + @ftp.stub!(:connect) + @port_args = [] + @port_args << 21 + end + + it "is private" do + Net::FTP.should have_private_instance_method(:initialize) + end + + it "sets self into binary mode" do + @ftp.binary.should be_nil + @ftp.send(:initialize) + @ftp.binary.should be_true + end + + it "sets self into active mode" do + @ftp.passive.should be_nil + @ftp.send(:initialize) + @ftp.passive.should be_false + end + + it "sets self into non-debug mode" do + @ftp.debug_mode.should be_nil + @ftp.send(:initialize) + @ftp.debug_mode.should be_false + end + + it "sets self to not resume file uploads/downloads" do + @ftp.resume.should be_nil + @ftp.send(:initialize) + @ftp.resume.should be_false + end + + describe "when passed no arguments" do + it "does not try to connect" do + @ftp.should_not_receive(:connect) + @ftp.send(:initialize) + end + end + + describe "when passed host" do + it "tries to connect to the passed host" do + @ftp.should_receive(:connect).with("localhost", *@port_args) + @ftp.send(:initialize, "localhost") + end + end + + describe "when passed host, user" do + it "tries to connect to the passed host" do + @ftp.should_receive(:connect).with("localhost", *@port_args) + @ftp.send(:initialize, "localhost") + end + + it "tries to login with the passed username" do + @ftp.should_receive(:login).with("rubyspec", nil, nil) + @ftp.send(:initialize, "localhost", "rubyspec") + end + end + + describe "when passed host, user, password" do + it "tries to connect to the passed host" do + @ftp.should_receive(:connect).with("localhost", *@port_args) + @ftp.send(:initialize, "localhost") + end + + it "tries to login with the passed username and password" do + @ftp.should_receive(:login).with("rubyspec", "rocks", nil) + @ftp.send(:initialize, "localhost", "rubyspec", "rocks") + end + end + + describe "when passed host, user" do + it "tries to connect to the passed host" do + @ftp.should_receive(:connect).with("localhost", *@port_args) + @ftp.send(:initialize, "localhost") + end + + it "tries to login with the passed username, password and account" do + @ftp.should_receive(:login).with("rubyspec", "rocks", "account") + @ftp.send(:initialize, "localhost", "rubyspec", "rocks", "account") + end + end + + before :each do + @ftp.stub!(:login) + end + + describe 'when the host' do + describe 'is set' do + describe 'and port option' do + describe 'is set' do + it 'tries to connect to the host on the specified port' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ port: 8080 }) + @ftp.should_receive(:connect).with('localhost', 8080) + + @ftp.send(:initialize, 'localhost', options) + end + end + + describe 'is not set' do + it 'tries to connect to the host without a port' do + @ftp.should_receive(:connect).with("localhost", *@port_args) + + @ftp.send(:initialize, 'localhost') + end + end + end + + describe 'when the username option' do + describe 'is set' do + describe 'and the password option' do + describe 'is set' do + describe 'and the account option' do + describe 'is set' do + it 'tries to log in with the supplied parameters' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ username: 'a', password: 'topsecret', account: 'b' }) + @ftp.should_receive(:login).with('a', 'topsecret', 'b') + + @ftp.send(:initialize, 'localhost', options) + end + end + + describe 'is unset' do + it 'tries to log in with the supplied parameters' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ username: 'a', password: 'topsecret' }) + @ftp.should_receive(:login).with('a', 'topsecret', nil) + + @ftp.send(:initialize, 'localhost', options) + end + end + end + end + + describe 'is unset' do + describe 'and the account option' do + describe 'is set' do + it 'tries to log in with the supplied parameters' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ username: 'a', account: 'b' }) + @ftp.should_receive(:login).with('a', nil, 'b') + + @ftp.send(:initialize, 'localhost', options) + end + end + + describe 'is unset' do + it 'tries to log in with the supplied parameters' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ username: 'a'}) + @ftp.should_receive(:login).with('a', nil, nil) + + @ftp.send(:initialize, 'localhost', options) + end + end + end + end + end + end + + describe 'is not set' do + it 'does not try to log in' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({}) + @ftp.should_not_receive(:login) + + @ftp.send(:initialize, 'localhost', options) + end + end + end + end + + describe 'is unset' do + it 'does not try to connect' do + @ftp.should_not_receive(:connect) + + @ftp.send(:initialize) + end + + it 'does not try to log in' do + @ftp.should_not_receive(:login) + + @ftp.send(:initialize) + end + end + end + + describe 'when the passive option' do + describe 'is set' do + describe 'to true' do + it 'sets passive to true' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ passive: true }) + + @ftp.send(:initialize, nil, options) + @ftp.passive.should == true + end + end + + describe 'to false' do + it 'sets passive to false' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ passive: false }) + + @ftp.send(:initialize, nil, options) + @ftp.passive.should == false + end + end + end + + describe 'is unset' do + it 'sets passive to false' do + @ftp.send(:initialize) + @ftp.passive.should == false + end + end + end + + describe 'when the debug_mode option' do + describe 'is set' do + describe 'to true' do + it 'sets debug_mode to true' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ debug_mode: true }) + + @ftp.send(:initialize, nil, options) + @ftp.debug_mode.should == true + end + end + + describe 'to false' do + it 'sets debug_mode to false' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ debug_mode: false }) + + @ftp.send(:initialize, nil, options) + @ftp.debug_mode.should == false + end + end + end + + describe 'is unset' do + it 'sets debug_mode to false' do + @ftp.send(:initialize) + @ftp.debug_mode.should == false + end + end + end + + describe 'when the open_timeout option' do + describe 'is set' do + it 'sets open_timeout to the specified value' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ open_timeout: 42 }) + + @ftp.send(:initialize, nil, options) + @ftp.open_timeout.should == 42 + end + end + + describe 'is not set' do + it 'sets open_timeout to nil' do + @ftp.send(:initialize) + @ftp.open_timeout.should == nil + end + end + end + + describe 'when the read_timeout option' do + describe 'is set' do + it 'sets read_timeout to the specified value' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ read_timeout: 100 }) + + @ftp.send(:initialize, nil, options) + @ftp.read_timeout.should == 100 + end + end + + describe 'is not set' do + it 'sets read_timeout to the default value' do + @ftp.send(:initialize) + @ftp.read_timeout.should == 60 + end + end + end + + describe 'when the ssl_handshake_timeout option' do + describe 'is set' do + it 'sets ssl_handshake_timeout to the specified value' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ ssl_handshake_timeout: 23 }) + + @ftp.send(:initialize, nil, options) + @ftp.ssl_handshake_timeout.should == 23 + end + end + + describe 'is not set' do + it 'sets ssl_handshake_timeout to nil' do + @ftp.send(:initialize) + @ftp.ssl_handshake_timeout.should == nil + end + end + end + + describe 'when the ssl option' do + describe 'is set' do + describe "and the ssl option's value is true" do + it 'initializes ssl_context to a blank SSLContext object' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ ssl: true }) + + ssl_context = OpenSSL::SSL::SSLContext.allocate + ssl_context.stub!(:set_params) + + OpenSSL::SSL::SSLContext.should_receive(:new).and_return(ssl_context) + ssl_context.should_receive(:set_params).with({}) + + @ftp.send(:initialize, nil, options) + @ftp.instance_variable_get(:@ssl_context).should == ssl_context + end + end + + describe "and the ssl option's value is a hash" do + it 'initializes ssl_context to a configured SSLContext object' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ ssl: {key: 'value'} }) + + ssl_context = OpenSSL::SSL::SSLContext.allocate + ssl_context.stub!(:set_params) + + OpenSSL::SSL::SSLContext.should_receive(:new).and_return(ssl_context) + ssl_context.should_receive(:set_params).with({key: 'value'}) + + @ftp.send(:initialize, nil, options) + @ftp.instance_variable_get(:@ssl_context).should == ssl_context + end + end + + describe 'and private_data_connection' do + describe 'is set' do + it 'sets private_data_connection to that value' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ ssl: true, private_data_connection: 'true' }) + + @ftp.send(:initialize, nil, options) + @ftp.instance_variable_get(:@private_data_connection).should == 'true' + end + end + + describe 'is not set' do + it 'sets private_data_connection to nil' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ ssl: true }) + + @ftp.send(:initialize, nil, options) + @ftp.instance_variable_get(:@private_data_connection).should == true + end + end + end + end + + describe 'is not set' do + it 'sets ssl_context to nil' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({}) + + @ftp.send(:initialize, nil, options) + @ftp.instance_variable_get(:@ssl_context).should == nil + end + + describe 'private_data_connection' do + describe 'is set' do + it 'raises an ArgumentError' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ private_data_connection: true }) + + -> { + @ftp.send(:initialize, nil, options) + }.should raise_error(ArgumentError, /private_data_connection can be set to true only when ssl is enabled/) + end + end + + describe 'is not set' do + it 'sets private_data_connection to false' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({}) + + @ftp.send(:initialize, nil, options) + @ftp.instance_variable_get(:@private_data_connection).should == false + end + end + end + end + end +end diff --git a/spec/ruby/library/net-ftp/last_response_code_spec.rb b/spec/ruby/library/net-ftp/last_response_code_spec.rb new file mode 100644 index 0000000000..c17c28f0f8 --- /dev/null +++ b/spec/ruby/library/net-ftp/last_response_code_spec.rb @@ -0,0 +1,8 @@ +require_relative '../../spec_helper' +require_relative 'spec_helper' +require_relative 'shared/last_response_code' +require_relative 'fixtures/server' + +describe "Net::FTP#last_response_code" do + it_behaves_like :net_ftp_last_response_code, :last_response_code +end diff --git a/spec/ruby/library/net-ftp/last_response_spec.rb b/spec/ruby/library/net-ftp/last_response_spec.rb new file mode 100644 index 0000000000..c9d9d70f35 --- /dev/null +++ b/spec/ruby/library/net-ftp/last_response_spec.rb @@ -0,0 +1,25 @@ +require_relative '../../spec_helper' +require_relative 'spec_helper' +require_relative 'fixtures/server' + +describe "Net::FTP#last_response" do + before :each do + @server = NetFTPSpecs::DummyFTP.new + @server.serve_once + + @ftp = Net::FTP.new + @ftp.connect(@server.hostname, @server.server_port) + end + + after :each do + @ftp.quit rescue nil + @ftp.close + @server.stop + end + + it "returns the last response" do + @ftp.last_response.should == "220 Dummy FTP Server ready!\n" + @ftp.help + @ftp.last_response.should == "211 System status, or system help reply. (HELP)\n" + end +end diff --git a/spec/ruby/library/net-ftp/lastresp_spec.rb b/spec/ruby/library/net-ftp/lastresp_spec.rb new file mode 100644 index 0000000000..e0c1b862a0 --- /dev/null +++ b/spec/ruby/library/net-ftp/lastresp_spec.rb @@ -0,0 +1,8 @@ +require_relative '../../spec_helper' +require_relative 'spec_helper' +require_relative 'shared/last_response_code' +require_relative 'fixtures/server' + +describe "Net::FTP#lastresp" do + it_behaves_like :net_ftp_last_response_code, :lastresp +end diff --git a/spec/ruby/library/net-ftp/list_spec.rb b/spec/ruby/library/net-ftp/list_spec.rb new file mode 100644 index 0000000000..6cb1bbc4b8 --- /dev/null +++ b/spec/ruby/library/net-ftp/list_spec.rb @@ -0,0 +1,8 @@ +require_relative '../../spec_helper' +require_relative 'spec_helper' +require_relative 'fixtures/server' +require_relative 'shared/list' + +describe "Net::FTP#list" do + it_behaves_like :net_ftp_list, :list +end diff --git a/spec/ruby/library/net-ftp/login_spec.rb b/spec/ruby/library/net-ftp/login_spec.rb new file mode 100644 index 0000000000..0de2f5cc63 --- /dev/null +++ b/spec/ruby/library/net-ftp/login_spec.rb @@ -0,0 +1,195 @@ +require_relative '../../spec_helper' +require_relative 'spec_helper' +require_relative 'fixtures/server' + +describe "Net::FTP#login" do + before :each do + @server = NetFTPSpecs::DummyFTP.new + @server.serve_once + + @ftp = Net::FTP.new + @ftp.connect(@server.hostname, @server.server_port) + end + + after :each do + @ftp.quit rescue nil + @ftp.close + @server.stop + end + + describe "when passed no arguments" do + it "sends the USER command with 'anonymous' as name to the server" do + @ftp.login + @server.login_user.should == "anonymous" + end + + it "sends 'anonymous@' as a password when required" do + @server.should_receive(:user).and_respond("331 User name okay, need password.") + @ftp.login + @server.login_pass.should == "anonymous@" + end + + it "raises a Net::FTPReplyError when the server requests an account" do + @server.should_receive(:user).and_respond("331 User name okay, need password.") + @server.should_receive(:pass).and_respond("332 Need account for login.") + -> { @ftp.login }.should raise_error(Net::FTPReplyError) + end + end + + describe "when passed name" do + it "sends the USER command with the passed name to the server" do + @ftp.login("rubyspec") + @server.login_user.should == "rubyspec" + end + + it "raises a Net::FTPReplyError when the server requests a password, but none was given" do + @server.should_receive(:user).and_respond("331 User name okay, need password.") + -> { @ftp.login("rubyspec") }.should raise_error(Net::FTPReplyError) + end + + it "raises a Net::FTPReplyError when the server requests an account, but none was given" do + @server.should_receive(:user).and_respond("331 User name okay, need password.") + @server.should_receive(:pass).and_respond("332 Need account for login.") + -> { @ftp.login("rubyspec") }.should raise_error(Net::FTPReplyError) + end + end + + describe "when passed name, password" do + it "sends the USER command with the passed name to the server" do + @ftp.login("rubyspec", "rocks") + @server.login_user.should == "rubyspec" + end + + it "sends the passed password when required" do + @server.should_receive(:user).and_respond("331 User name okay, need password.") + @ftp.login("rubyspec", "rocks") + @server.login_pass.should == "rocks" + end + + it "raises a Net::FTPReplyError when the server requests an account" do + @server.should_receive(:user).and_respond("331 User name okay, need password.") + @server.should_receive(:pass).and_respond("332 Need account for login.") + -> { @ftp.login("rubyspec", "rocks") }.should raise_error(Net::FTPReplyError) + end + end + + describe "when passed name, password, account" do + it "sends the USER command with the passed name to the server" do + @ftp.login("rubyspec", "rocks", "account") + @server.login_user.should == "rubyspec" + end + + it "sends the passed password when required" do + @server.should_receive(:user).and_respond("331 User name okay, need password.") + @ftp.login("rubyspec", "rocks", "account") + @server.login_pass.should == "rocks" + end + + it "sends the passed account when required" do + @server.should_receive(:user).and_respond("331 User name okay, need password.") + @server.should_receive(:pass).and_respond("332 Need account for login.") + @ftp.login("rubyspec", "rocks", "account") + @server.login_acct.should == "account" + end + end + + describe "when the USER command fails" do + it "raises a Net::FTPPermError when the response code is 500" do + @server.should_receive(:user).and_respond("500 Syntax error, command unrecognized.") + -> { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 501" do + @server.should_receive(:user).and_respond("501 Syntax error in parameters or arguments.") + -> { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 502" do + @server.should_receive(:user).and_respond("502 Command not implemented.") + -> { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPTempError when the response code is 421" do + @server.should_receive(:user).and_respond("421 Service not available, closing control connection.") + -> { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPTempError) + end + + it "raises a Net::FTPPermError when the response code is 530" do + @server.should_receive(:user).and_respond("530 Not logged in.") + -> { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError) + end + end + + describe "when the PASS command fails" do + before :each do + @server.should_receive(:user).and_respond("331 User name okay, need password.") + end + + it "does not raise an Error when the response code is 202" do + @server.should_receive(:pass).and_respond("202 Command not implemented, superfluous at this site.") + -> { @ftp.login("rubyspec", "rocks", "account") }.should_not raise_error + end + + it "raises a Net::FTPPermError when the response code is 500" do + @server.should_receive(:pass).and_respond("500 Syntax error, command unrecognized.") + -> { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 501" do + @server.should_receive(:pass).and_respond("501 Syntax error in parameters or arguments.") + -> { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 502" do + @server.should_receive(:pass).and_respond("502 Command not implemented.") + -> { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPTempError when the response code is 421" do + @server.should_receive(:pass).and_respond("421 Service not available, closing control connection.") + -> { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPTempError) + end + + it "raises a Net::FTPPermError when the response code is 530" do + @server.should_receive(:pass).and_respond("530 Not logged in.") + -> { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError) + end + end + + describe "when the ACCT command fails" do + before :each do + @server.should_receive(:user).and_respond("331 User name okay, need password.") + @server.should_receive(:pass).and_respond("332 Need account for login.") + end + + it "does not raise an Error when the response code is 202" do + @server.should_receive(:acct).and_respond("202 Command not implemented, superfluous at this site.") + -> { @ftp.login("rubyspec", "rocks", "account") }.should_not raise_error + end + + it "raises a Net::FTPPermError when the response code is 500" do + @server.should_receive(:acct).and_respond("500 Syntax error, command unrecognized.") + -> { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 501" do + @server.should_receive(:acct).and_respond("501 Syntax error in parameters or arguments.") + -> { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 502" do + @server.should_receive(:acct).and_respond("502 Command not implemented.") + -> { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPTempError when the response code is 421" do + @server.should_receive(:acct).and_respond("421 Service not available, closing control connection.") + -> { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPTempError) + end + + it "raises a Net::FTPPermError when the response code is 530" do + @server.should_receive(:acct).and_respond("530 Not logged in.") + -> { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError) + end + end +end diff --git a/spec/ruby/library/net-ftp/ls_spec.rb b/spec/ruby/library/net-ftp/ls_spec.rb new file mode 100644 index 0000000000..acd7e9e523 --- /dev/null +++ b/spec/ruby/library/net-ftp/ls_spec.rb @@ -0,0 +1,8 @@ +require_relative '../../spec_helper' +require_relative 'spec_helper' +require_relative 'fixtures/server' +require_relative 'shared/list' + +describe "Net::FTP#ls" do + it_behaves_like :net_ftp_list, :ls +end diff --git a/spec/ruby/library/net-ftp/mdtm_spec.rb b/spec/ruby/library/net-ftp/mdtm_spec.rb new file mode 100644 index 0000000000..a504507c84 --- /dev/null +++ b/spec/ruby/library/net-ftp/mdtm_spec.rb @@ -0,0 +1,38 @@ +require_relative '../../spec_helper' +require_relative 'spec_helper' +require_relative 'fixtures/server' + +describe "Net::FTP#mdtm" do + before :each do + @server = NetFTPSpecs::DummyFTP.new + @server.serve_once + + @ftp = Net::FTP.new + @ftp.connect(@server.hostname, @server.server_port) + end + + after :each do + @ftp.quit rescue nil + @ftp.close + @server.stop + end + + it "sends the MDTM with the passed filename command to the server" do + @ftp.mdtm("test.file") + @ftp.last_response.should == "213 19980705132316\n" + end + + it "returns the last modification time of the passed file" do + @ftp.mdtm("test.file").should == "19980705132316" + end + + it "raises a Net::FTPPermError when the response code is 550" do + @server.should_receive(:mdtm).and_respond("550 Requested action not taken.") + -> { @ftp.mdtm("test.file") }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPTempError when the response code is 421" do + @server.should_receive(:mdtm).and_respond("421 Service not available, closing control connection.") + -> { @ftp.mdtm("test.file") }.should raise_error(Net::FTPTempError) + end +end diff --git a/spec/ruby/library/net-ftp/mkdir_spec.rb b/spec/ruby/library/net-ftp/mkdir_spec.rb new file mode 100644 index 0000000000..8cc6ae785e --- /dev/null +++ b/spec/ruby/library/net-ftp/mkdir_spec.rb @@ -0,0 +1,61 @@ +require_relative '../../spec_helper' +require_relative 'spec_helper' +require_relative 'fixtures/server' + +describe "Net::FTP#mkdir" do + before :each do + @server = NetFTPSpecs::DummyFTP.new + @server.serve_once + + @ftp = Net::FTP.new + @ftp.connect(@server.hostname, @server.server_port) + end + + after :each do + @ftp.quit rescue nil + @ftp.close + @server.stop + end + + it "sends the MKD command with the passed pathname to the server" do + @ftp.mkdir("test.folder") + @ftp.last_response.should == %{257 "test.folder" created.\n} + end + + it "returns the path to the newly created directory" do + @ftp.mkdir("test.folder").should == "test.folder" + @ftp.mkdir("/absolute/path/to/test.folder").should == "/absolute/path/to/test.folder" + @ftp.mkdir("relative/path/to/test.folder").should == "relative/path/to/test.folder" + @ftp.mkdir('/usr/dm/foo"bar').should == '/usr/dm/foo"bar' + end + + it "raises a Net::FTPPermError when the response code is 500" do + @server.should_receive(:mkd).and_respond("500 Syntax error, command unrecognized.") + -> { @ftp.mkdir("test.folder") }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 501" do + @server.should_receive(:mkd).and_respond("501 Syntax error in parameters or arguments.") + -> { @ftp.mkdir("test.folder") }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 502" do + @server.should_receive(:mkd).and_respond("502 Command not implemented.") + -> { @ftp.mkdir("test.folder") }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPTempError when the response code is 421" do + @server.should_receive(:mkd).and_respond("421 Service not available, closing control connection.") + -> { @ftp.mkdir("test.folder") }.should raise_error(Net::FTPTempError) + end + + it "raises a Net::FTPPermError when the response code is 530" do + @server.should_receive(:mkd).and_respond("530 Not logged in.") + -> { @ftp.mkdir("test.folder") }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 550" do + @server.should_receive(:mkd).and_respond("550 Requested action not taken.") + -> { @ftp.mkdir("test.folder") }.should raise_error(Net::FTPPermError) + end +end diff --git a/spec/ruby/library/net-ftp/mtime_spec.rb b/spec/ruby/library/net-ftp/mtime_spec.rb new file mode 100644 index 0000000000..9dde1278a8 --- /dev/null +++ b/spec/ruby/library/net-ftp/mtime_spec.rb @@ -0,0 +1,50 @@ +require_relative '../../spec_helper' +require_relative 'spec_helper' +require_relative 'fixtures/server' + +describe "Net::FTP#mtime" do + before :each do + @server = NetFTPSpecs::DummyFTP.new + @server.serve_once + + @ftp = Net::FTP.new + @ftp.connect(@server.hostname, @server.server_port) + end + + after :each do + @ftp.quit rescue nil + @ftp.close + @server.stop + end + + it "sends the MDTM with the passed filename command to the server" do + @ftp.mtime("test.file") + @ftp.last_response.should == "213 19980705132316\n" + end + + describe "when passed filename" do + it "returns the last modification time of the passed file as a Time object in the local time" do + @ftp.mtime("test.file").should == Time.gm("1998", "07", "05", "13", "23", "16") + end + end + + describe "when passed filename, local_time" do + it "returns the last modification time as a Time object in UTC when local_time is true" do + @ftp.mtime("test.file", true).should == Time.local("1998", "07", "05", "13", "23", "16") + end + + it "returns the last modification time as a Time object in the local time when local_time is false" do + @ftp.mtime("test.file", false).should == Time.gm("1998", "07", "05", "13", "23", "16") + end + end + + it "raises a Net::FTPPermError when the response code is 550" do + @server.should_receive(:mdtm).and_respond("550 Requested action not taken.") + -> { @ftp.mtime("test.file") }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPTempError when the response code is 421" do + @server.should_receive(:mdtm).and_respond("421 Service not available, closing control connection.") + -> { @ftp.mtime("test.file") }.should raise_error(Net::FTPTempError) + end +end diff --git a/spec/ruby/library/net-ftp/nlst_spec.rb b/spec/ruby/library/net-ftp/nlst_spec.rb new file mode 100644 index 0000000000..2f22543af6 --- /dev/null +++ b/spec/ruby/library/net-ftp/nlst_spec.rb @@ -0,0 +1,92 @@ +require_relative '../../spec_helper' +require_relative 'spec_helper' +require_relative 'fixtures/server' + +describe "Net::FTP#nlst" do + before :each do + @server = NetFTPSpecs::DummyFTP.new + @server.serve_once + + @ftp = Net::FTP.new + @ftp.passive = false + @ftp.connect(@server.hostname, @server.server_port) + end + + after :each do + @ftp.quit rescue nil + @ftp.close + @server.stop + end + + describe "when passed no arguments" do + it "returns an Array containing a list of files in the current dir" do + @ftp.nlst.should == ["last_response_code.rb", "list.rb", "pwd.rb"] + @ftp.last_response.should == "226 transfer complete (NLST)\n" + end + end + + describe "when passed dir" do + it "returns an Array containing a list of files in the passed dir" do + @ftp.nlst("test.folder").should == ["last_response_code.rb", "list.rb", "pwd.rb"] + @ftp.last_response.should == "226 transfer complete (NLST test.folder)\n" + end + end + + describe "when the NLST command fails" do + it "raises a Net::FTPTempError when the response code is 450" do + @server.should_receive(:nlst).and_respond("450 Requested file action not taken..") + -> { @ftp.nlst }.should raise_error(Net::FTPTempError) + end + + it "raises a Net::FTPPermError when the response code is 500" do + @server.should_receive(:nlst).and_respond("500 Syntax error, command unrecognized.") + -> { @ftp.nlst }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 501" do + @server.should_receive(:nlst).and_respond("501 Syntax error, command unrecognized.") + -> { @ftp.nlst }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 502" do + @server.should_receive(:nlst).and_respond("502 Command not implemented.") + -> { @ftp.nlst }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPTempError when the response code is 421" do + @server.should_receive(:nlst).and_respond("421 Service not available, closing control connection.") + -> { @ftp.nlst }.should raise_error(Net::FTPTempError) + end + + it "raises a Net::FTPPermError when the response code is 530" do + @server.should_receive(:nlst).and_respond("530 Not logged in.") + -> { @ftp.nlst }.should raise_error(Net::FTPPermError) + end + end + + describe "when opening the data port fails" do + it "raises a Net::FTPPermError when the response code is 500" do + @server.should_receive(:eprt).and_respond("500 Syntax error, command unrecognized.") + @server.should_receive(:port).and_respond("500 Syntax error, command unrecognized.") + -> { @ftp.nlst }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 501" do + @server.should_receive(:eprt).and_respond("501 Syntax error in parameters or arguments.") + @server.should_receive(:port).and_respond("501 Syntax error in parameters or arguments.") + -> { @ftp.nlst }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPTempError when the response code is 421" do + @server.should_receive(:eprt).and_respond("421 Service not available, closing control connection.") + @server.should_receive(:port).and_respond("421 Service not available, closing control connection.") + -> { @ftp.nlst }.should raise_error(Net::FTPTempError) + end + + it "raises a Net::FTPPermError when the response code is 530" do + @server.should_receive(:eprt).and_respond("530 Not logged in.") + @server.should_receive(:port).and_respond("530 Not logged in.") + -> { @ftp.nlst }.should raise_error(Net::FTPPermError) + end + end +end diff --git a/spec/ruby/library/net-ftp/noop_spec.rb b/spec/ruby/library/net-ftp/noop_spec.rb new file mode 100644 index 0000000000..4743a39ef6 --- /dev/null +++ b/spec/ruby/library/net-ftp/noop_spec.rb @@ -0,0 +1,38 @@ +require_relative '../../spec_helper' +require_relative 'spec_helper' +require_relative 'fixtures/server' + +describe "Net::FTP#noop" do + before :each do + @server = NetFTPSpecs::DummyFTP.new + @server.serve_once + + @ftp = Net::FTP.new + @ftp.connect(@server.hostname, @server.server_port) + end + + after :each do + @ftp.quit rescue nil + @ftp.close + @server.stop + end + + it "sends the NOOP command to the server" do + @ftp.noop + @ftp.last_response.should == "200 Command okay. (NOOP)\n" + end + + it "returns nil" do + @ftp.noop.should be_nil + end + + it "raises a Net::FTPPermError when the response code is 500" do + @server.should_receive(:noop).and_respond("500 Syntax error, command unrecognized.") + -> { @ftp.noop }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPTempError when the response code is 421" do + @server.should_receive(:noop).and_respond("421 Service not available, closing control connection.") + -> { @ftp.noop }.should raise_error(Net::FTPTempError) + end +end diff --git a/spec/ruby/library/net-ftp/open_spec.rb b/spec/ruby/library/net-ftp/open_spec.rb new file mode 100644 index 0000000000..e59496dc3c --- /dev/null +++ b/spec/ruby/library/net-ftp/open_spec.rb @@ -0,0 +1,55 @@ +require_relative '../../spec_helper' +require_relative 'spec_helper' + +describe "Net::FTP.open" do + before :each do + @ftp = mock("Net::FTP instance") + Net::FTP.stub!(:new).and_return(@ftp) + end + + describe "when passed no block" do + it "returns a new Net::FTP instance" do + Net::FTP.open("localhost").should equal(@ftp) + end + + it "passes the passed arguments down to Net::FTP.new" do + Net::FTP.should_receive(:new).with("localhost", "user", "password", "account") + Net::FTP.open("localhost", "user", "password", "account") + end + end + + describe "when passed a block" do + before :each do + @ftp.stub!(:close) + end + + it "yields a new Net::FTP instance to the passed block" do + yielded = false + Net::FTP.open("localhost") do |ftp| + yielded = true + ftp.should equal(@ftp) + end + yielded.should be_true + end + + it "closes the Net::FTP instance after yielding" do + Net::FTP.open("localhost") do |ftp| + ftp.should_receive(:close) + end + end + + it "closes the Net::FTP instance even if an exception is raised while yielding" do + begin + Net::FTP.open("localhost") do |ftp| + ftp.should_receive(:close) + raise ArgumentError, "some exception" + end + rescue ArgumentError + end + end + + it "returns the block's return value" do + Net::FTP.open("localhost") { :test }.should == :test + end + end +end diff --git a/spec/ruby/library/net-ftp/passive_spec.rb b/spec/ruby/library/net-ftp/passive_spec.rb new file mode 100644 index 0000000000..97659f1b68 --- /dev/null +++ b/spec/ruby/library/net-ftp/passive_spec.rb @@ -0,0 +1,28 @@ +require_relative '../../spec_helper' +require_relative 'spec_helper' + +describe "Net::FTP#passive" do + it "returns true when self is in passive mode" do + ftp = Net::FTP.new + ftp.passive.should be_false + + ftp.passive = true + ftp.passive.should be_true + end + + it "is the value of Net::FTP.default_value by default" do + ruby_exe(fixture(__FILE__, "passive.rb")).should == "true" + end +end + +describe "Net::FTP#passive=" do + it "sets self to passive mode when passed true" do + ftp = Net::FTP.new + + ftp.passive = true + ftp.passive.should be_true + + ftp.passive = false + ftp.passive.should be_false + end +end diff --git a/spec/ruby/library/net-ftp/put_spec.rb b/spec/ruby/library/net-ftp/put_spec.rb new file mode 100644 index 0000000000..6d40d3d5b9 --- /dev/null +++ b/spec/ruby/library/net-ftp/put_spec.rb @@ -0,0 +1,21 @@ +require_relative '../../spec_helper' +require_relative 'spec_helper' +require_relative 'fixtures/server' +require_relative 'shared/puttextfile' +require_relative 'shared/putbinaryfile' + +describe "Net::FTP#put (binary mode)" do + before :each do + @binary_mode = true + end + + it_behaves_like :net_ftp_putbinaryfile, :put +end + +describe "Net::FTP#put (text mode)" do + before :each do + @binary_mode = false + end + + it_behaves_like :net_ftp_puttextfile, :put +end diff --git a/spec/ruby/library/net-ftp/putbinaryfile_spec.rb b/spec/ruby/library/net-ftp/putbinaryfile_spec.rb new file mode 100644 index 0000000000..d0398229e5 --- /dev/null +++ b/spec/ruby/library/net-ftp/putbinaryfile_spec.rb @@ -0,0 +1,8 @@ +require_relative '../../spec_helper' +require_relative 'spec_helper' +require_relative 'fixtures/server' +require_relative 'shared/putbinaryfile' + +describe "Net::FTP#putbinaryfile" do + it_behaves_like :net_ftp_putbinaryfile, :putbinaryfile +end diff --git a/spec/ruby/library/net-ftp/puttextfile_spec.rb b/spec/ruby/library/net-ftp/puttextfile_spec.rb new file mode 100644 index 0000000000..b8bcac33df --- /dev/null +++ b/spec/ruby/library/net-ftp/puttextfile_spec.rb @@ -0,0 +1,8 @@ +require_relative '../../spec_helper' +require_relative 'spec_helper' +require_relative 'fixtures/server' +require_relative 'shared/puttextfile' + +describe "Net::FTP#puttextfile" do + it_behaves_like :net_ftp_puttextfile, :puttextfile +end diff --git a/spec/ruby/library/net-ftp/pwd_spec.rb b/spec/ruby/library/net-ftp/pwd_spec.rb new file mode 100644 index 0000000000..992e2c4ed2 --- /dev/null +++ b/spec/ruby/library/net-ftp/pwd_spec.rb @@ -0,0 +1,53 @@ +require_relative '../../spec_helper' +require_relative 'spec_helper' +require_relative 'fixtures/server' + +describe "Net::FTP#pwd" do + before :each do + @server = NetFTPSpecs::DummyFTP.new + @server.serve_once + + @ftp = Net::FTP.new + @ftp.connect(@server.hostname, @server.server_port) + end + + after :each do + @ftp.quit rescue nil + @ftp.close + @server.stop + end + + it "sends the PWD command to the server" do + @ftp.pwd + @ftp.last_response.should == "257 \"/some/dir/\" - current directory\n" + end + + it "returns the current directory" do + @ftp.pwd.should == "/some/dir/" + end + + it "raises a Net::FTPPermError when the response code is 500" do + @server.should_receive(:pwd).and_respond("500 Syntax error, command unrecognized.") + -> { @ftp.pwd }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 501" do + @server.should_receive(:pwd).and_respond("501 Syntax error in parameters or arguments.") + -> { @ftp.pwd }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 502" do + @server.should_receive(:pwd).and_respond("502 Command not implemented.") + -> { @ftp.pwd }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPTempError when the response code is 421" do + @server.should_receive(:pwd).and_respond("421 Service not available, closing control connection.") + -> { @ftp.pwd }.should raise_error(Net::FTPTempError) + end + + it "raises a Net::FTPPermError when the response code is 550" do + @server.should_receive(:pwd).and_respond("550 Requested action not taken.") + -> { @ftp.pwd }.should raise_error(Net::FTPPermError) + end +end diff --git a/spec/ruby/library/net-ftp/quit_spec.rb b/spec/ruby/library/net-ftp/quit_spec.rb new file mode 100644 index 0000000000..c5352ceada --- /dev/null +++ b/spec/ruby/library/net-ftp/quit_spec.rb @@ -0,0 +1,33 @@ +require_relative '../../spec_helper' +require_relative 'spec_helper' +require_relative 'fixtures/server' + +describe "Net::FTP#quit" do + before :each do + @server = NetFTPSpecs::DummyFTP.new + @server.serve_once + + @ftp = Net::FTP.new + @ftp.connect(@server.hostname, @server.server_port) + end + + after :each do + @ftp.quit rescue nil + @ftp.close + @server.stop + end + + it "sends the QUIT command to the server" do + @ftp.quit + @ftp.last_response.should == "221 OK, bye\n" + end + + it "does not close the socket automatically" do + @ftp.quit + @ftp.closed?.should be_false + end + + it "returns nil" do + @ftp.quit.should be_nil + end +end diff --git a/spec/ruby/library/net-ftp/rename_spec.rb b/spec/ruby/library/net-ftp/rename_spec.rb new file mode 100644 index 0000000000..48f81b7deb --- /dev/null +++ b/spec/ruby/library/net-ftp/rename_spec.rb @@ -0,0 +1,94 @@ +require_relative '../../spec_helper' +require_relative 'spec_helper' +require_relative 'fixtures/server' + +describe "Net::FTP#rename" do + before :each do + @server = NetFTPSpecs::DummyFTP.new + @server.serve_once + + @ftp = Net::FTP.new + @ftp.connect(@server.hostname, @server.server_port) + end + + after :each do + @ftp.quit rescue nil + @ftp.close + @server.stop + end + + describe "when passed from_name, to_name" do + it "sends the RNFR command with the passed from_name and the RNTO command with the passed to_name to the server" do + @ftp.rename("from.file", "to.file") + @ftp.last_response.should == "250 Requested file action okay, completed. (Renamed from.file to to.file)\n" + end + + it "returns something" do + @ftp.rename("from.file", "to.file").should be_nil + end + end + + describe "when the RNFR command fails" do + it "raises a Net::FTPTempError when the response code is 450" do + @server.should_receive(:rnfr).and_respond("450 Requested file action not taken.") + -> { @ftp.rename("from.file", "to.file") }.should raise_error(Net::FTPTempError) + end + + it "raises a Net::FTPPermError when the response code is 550" do + @server.should_receive(:rnfr).and_respond("550 Requested action not taken.") + -> { @ftp.rename("from.file", "to.file") }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 501" do + @server.should_receive(:rnfr).and_respond("501 Syntax error in parameters or arguments.") + -> { @ftp.rename("from.file", "to.file") }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 502" do + @server.should_receive(:rnfr).and_respond("502 Command not implemented.") + -> { @ftp.rename("from.file", "to.file") }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPTempError when the response code is 421" do + @server.should_receive(:rnfr).and_respond("421 Service not available, closing control connection.") + -> { @ftp.rename("from.file", "to.file") }.should raise_error(Net::FTPTempError) + end + + it "raises a Net::FTPPermError when the response code is 530" do + @server.should_receive(:rnfr).and_respond("530 Not logged in.") + -> { @ftp.rename("from.file", "to.file") }.should raise_error(Net::FTPPermError) + end + end + + describe "when the RNTO command fails" do + it "raises a Net::FTPPermError when the response code is 532" do + @server.should_receive(:rnfr).and_respond("532 Need account for storing files.") + -> { @ftp.rename("from.file", "to.file") }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 553" do + @server.should_receive(:rnto).and_respond("553 Requested action not taken.") + -> { @ftp.rename("from.file", "to.file") }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 501" do + @server.should_receive(:rnto).and_respond("501 Syntax error in parameters or arguments.") + -> { @ftp.rename("from.file", "to.file") }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 502" do + @server.should_receive(:rnto).and_respond("502 Command not implemented.") + -> { @ftp.rename("from.file", "to.file") }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPTempError when the response code is 421" do + @server.should_receive(:rnto).and_respond("421 Service not available, closing control connection.") + -> { @ftp.rename("from.file", "to.file") }.should raise_error(Net::FTPTempError) + end + + it "raises a Net::FTPPermError when the response code is 530" do + @server.should_receive(:rnto).and_respond("530 Not logged in.") + -> { @ftp.rename("from.file", "to.file") }.should raise_error(Net::FTPPermError) + end + end +end diff --git a/spec/ruby/library/net-ftp/resume_spec.rb b/spec/ruby/library/net-ftp/resume_spec.rb new file mode 100644 index 0000000000..6592fc5bb0 --- /dev/null +++ b/spec/ruby/library/net-ftp/resume_spec.rb @@ -0,0 +1,23 @@ +require_relative '../../spec_helper' +require_relative 'spec_helper' + +describe "Net::FTP#resume" do + it "returns true when self is set to resume uploads/downloads" do + ftp = Net::FTP.new + ftp.resume.should be_false + + ftp.resume = true + ftp.resume.should be_true + end +end + +describe "Net::FTP#resume=" do + it "sets self to resume uploads/downloads when set to true" do + ftp = Net::FTP.new + ftp.resume = true + ftp.resume.should be_true + + ftp.resume = false + ftp.resume.should be_false + end +end diff --git a/spec/ruby/library/net-ftp/retrbinary_spec.rb b/spec/ruby/library/net-ftp/retrbinary_spec.rb new file mode 100644 index 0000000000..de024208aa --- /dev/null +++ b/spec/ruby/library/net-ftp/retrbinary_spec.rb @@ -0,0 +1,30 @@ +require_relative '../../spec_helper' +require_relative 'spec_helper' +require_relative 'fixtures/server' + +describe "Net::FTP#retrbinary" do + before :each do + @server = NetFTPSpecs::DummyFTP.new + @server.serve_once + + @ftp = Net::FTP.new + @ftp.connect(@server.hostname, @server.server_port) + end + + after :each do + @ftp.quit rescue nil + @ftp.close + @server.stop + end + + it "sends the passed command to the server" do + @ftp.retrbinary("RETR test", 4096) {} + @ftp.last_response.should == "226 Closing data connection. (RETR test)\n" + end + + it "yields the received content as binary blocks of the passed size" do + res = [] + @ftp.retrbinary("RETR test", 10) { |bin| res << bin } + res.should == [ "This is th", "e content\n", "of the fil", "e named 't", "est'.\n" ] + end +end diff --git a/spec/ruby/library/net-ftp/retrlines_spec.rb b/spec/ruby/library/net-ftp/retrlines_spec.rb new file mode 100644 index 0000000000..866ecb5f40 --- /dev/null +++ b/spec/ruby/library/net-ftp/retrlines_spec.rb @@ -0,0 +1,34 @@ +require_relative '../../spec_helper' +require_relative 'spec_helper' +require_relative 'fixtures/server' + +describe "Net::FTP#retrlines" do + before :each do + @server = NetFTPSpecs::DummyFTP.new + @server.serve_once + + @ftp = Net::FTP.new + @ftp.connect(@server.hostname, @server.server_port) + end + + after :each do + @ftp.quit rescue nil + @ftp.close + @server.stop + end + + it "sends the passed command over the socket" do + @ftp.retrlines("LIST test.dir") {} + @ftp.last_response.should == "226 transfer complete (LIST test.dir)\n" + end + + it "yields each received line to the passed block" do + res = [] + @ftp.retrlines("LIST test.dir") { |x| res << x } + res.should == [ + "-rw-r--r-- 1 spec staff 507 17 Jul 18:41 last_response_code.rb", + "-rw-r--r-- 1 spec staff 50 17 Jul 18:41 list.rb", + "-rw-r--r-- 1 spec staff 48 17 Jul 18:41 pwd.rb" + ] + end +end diff --git a/spec/ruby/library/net-ftp/return_code_spec.rb b/spec/ruby/library/net-ftp/return_code_spec.rb new file mode 100644 index 0000000000..35a6232f7e --- /dev/null +++ b/spec/ruby/library/net-ftp/return_code_spec.rb @@ -0,0 +1,24 @@ +require_relative '../../spec_helper' +require_relative 'spec_helper' + +describe "Net::FTP#return_code" do + before :each do + @ftp = Net::FTP.new + end + + it "outputs a warning and returns a newline" do + -> do + @ftp.return_code.should == "\n" + end.should complain(/warning: Net::FTP#return_code is obsolete and do nothing/) + end +end + +describe "Net::FTP#return_code=" do + before :each do + @ftp = Net::FTP.new + end + + it "outputs a warning" do + -> { @ftp.return_code = 123 }.should complain(/warning: Net::FTP#return_code= is obsolete and do nothing/) + end +end diff --git a/spec/ruby/library/net-ftp/rmdir_spec.rb b/spec/ruby/library/net-ftp/rmdir_spec.rb new file mode 100644 index 0000000000..400874d60d --- /dev/null +++ b/spec/ruby/library/net-ftp/rmdir_spec.rb @@ -0,0 +1,58 @@ +require_relative '../../spec_helper' +require_relative 'spec_helper' +require_relative 'fixtures/server' + +describe "Net::FTP#rmdir" do + before :each do + @server = NetFTPSpecs::DummyFTP.new + @server.serve_once + + @ftp = Net::FTP.new + @ftp.connect(@server.hostname, @server.server_port) + end + + after :each do + @ftp.quit rescue nil + @ftp.close + @server.stop + end + + it "sends the RMD command with the passed pathname to the server" do + @ftp.rmdir("test.folder") + @ftp.last_response.should == "250 Requested file action okay, completed. (RMD test.folder)\n" + end + + it "returns nil" do + @ftp.rmdir("test.folder").should be_nil + end + + it "raises a Net::FTPPermError when the response code is 500" do + @server.should_receive(:rmd).and_respond("500 Syntax error, command unrecognized.") + -> { @ftp.rmdir("test.folder") }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 501" do + @server.should_receive(:rmd).and_respond("501 Syntax error in parameters or arguments.") + -> { @ftp.rmdir("test.folder") }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 502" do + @server.should_receive(:rmd).and_respond("502 Command not implemented.") + -> { @ftp.rmdir("test.folder") }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPTempError when the response code is 421" do + @server.should_receive(:rmd).and_respond("421 Service not available, closing control connection.") + -> { @ftp.rmdir("test.folder") }.should raise_error(Net::FTPTempError) + end + + it "raises a Net::FTPPermError when the response code is 530" do + @server.should_receive(:rmd).and_respond("530 Not logged in.") + -> { @ftp.rmdir("test.folder") }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 550" do + @server.should_receive(:rmd).and_respond("550 Requested action not taken.") + -> { @ftp.rmdir("test.folder") }.should raise_error(Net::FTPPermError) + end +end diff --git a/spec/ruby/library/net-ftp/sendcmd_spec.rb b/spec/ruby/library/net-ftp/sendcmd_spec.rb new file mode 100644 index 0000000000..c50b373869 --- /dev/null +++ b/spec/ruby/library/net-ftp/sendcmd_spec.rb @@ -0,0 +1,54 @@ +require_relative '../../spec_helper' +require_relative 'spec_helper' +require_relative 'fixtures/server' + +describe "Net::FTP#sendcmd" do + before :each do + @server = NetFTPSpecs::DummyFTP.new + @server.serve_once + + @ftp = Net::FTP.new + @ftp.connect(@server.hostname, @server.server_port) + end + + after :each do + @ftp.quit rescue nil + @ftp.close + @server.stop + end + + it "sends the passed command to the server" do + @ftp.sendcmd("HELP") + @ftp.last_response.should == "211 System status, or system help reply. (HELP)\n" + end + + it "returns the server's response" do + @ftp.sendcmd("HELP").should == "211 System status, or system help reply. (HELP)\n" + end + + it "raises no error when the response code is 1xx, 2xx or 3xx" do + @server.should_receive(:help).and_respond("120 Service ready in nnn minutes.") + -> { @ftp.sendcmd("HELP") }.should_not raise_error + + @server.should_receive(:help).and_respond("200 Command okay.") + -> { @ftp.sendcmd("HELP") }.should_not raise_error + + @server.should_receive(:help).and_respond("350 Requested file action pending further information.") + -> { @ftp.sendcmd("HELP") }.should_not raise_error + end + + it "raises a Net::FTPTempError when the response code is 4xx" do + @server.should_receive(:help).and_respond("421 Service not available, closing control connection.") + -> { @ftp.sendcmd("HELP") }.should raise_error(Net::FTPTempError) + end + + it "raises a Net::FTPPermError when the response code is 5xx" do + @server.should_receive(:help).and_respond("500 Syntax error, command unrecognized.") + -> { @ftp.sendcmd("HELP") }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPProtoError when the response code is not between 1xx-5xx" do + @server.should_receive(:help).and_respond("999 Invalid response.") + -> { @ftp.sendcmd("HELP") }.should raise_error(Net::FTPProtoError) + end +end diff --git a/spec/ruby/library/net-ftp/set_socket_spec.rb b/spec/ruby/library/net-ftp/set_socket_spec.rb new file mode 100644 index 0000000000..8182dd8b33 --- /dev/null +++ b/spec/ruby/library/net-ftp/set_socket_spec.rb @@ -0,0 +1,8 @@ +require_relative '../../spec_helper' +require_relative 'spec_helper' + +describe "Net::FTP#set_socket" do + # TODO: I won't spec this method, as it is not used + # anywhere and it should be private anyway. + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/net/ftp/shared/getbinaryfile.rb b/spec/ruby/library/net-ftp/shared/getbinaryfile.rb index f324f5b85d..ceec8e7cd5 100644 --- a/spec/ruby/library/net/ftp/shared/getbinaryfile.rb +++ b/spec/ruby/library/net-ftp/shared/getbinaryfile.rb @@ -1,6 +1,6 @@ -describe :net_ftp_getbinaryfile, shared: :true do +describe :net_ftp_getbinaryfile, shared: true do before :each do - @fixture_file = File.dirname(__FILE__) + "/../fixtures/getbinaryfile" + @fixture_file = __dir__ + "/../fixtures/getbinaryfile" @tmp_file = tmp("getbinaryfile") @server = NetFTPSpecs::DummyFTP.new diff --git a/spec/ruby/library/net/ftp/shared/gettextfile.rb b/spec/ruby/library/net-ftp/shared/gettextfile.rb index 82bec2a4a7..7fe14f7dfb 100644 --- a/spec/ruby/library/net/ftp/shared/gettextfile.rb +++ b/spec/ruby/library/net-ftp/shared/gettextfile.rb @@ -1,4 +1,4 @@ -describe :net_ftp_gettextfile, shared: :true do +describe :net_ftp_gettextfile, shared: true do before :each do @tmp_file = tmp("gettextfile") diff --git a/spec/ruby/library/net/ftp/shared/last_response_code.rb b/spec/ruby/library/net-ftp/shared/last_response_code.rb index 4fe53677db..4fe53677db 100644 --- a/spec/ruby/library/net/ftp/shared/last_response_code.rb +++ b/spec/ruby/library/net-ftp/shared/last_response_code.rb diff --git a/spec/ruby/library/net/ftp/shared/list.rb b/spec/ruby/library/net-ftp/shared/list.rb index adc3fa59c1..adc3fa59c1 100644 --- a/spec/ruby/library/net/ftp/shared/list.rb +++ b/spec/ruby/library/net-ftp/shared/list.rb diff --git a/spec/ruby/library/net/ftp/shared/putbinaryfile.rb b/spec/ruby/library/net-ftp/shared/putbinaryfile.rb index 1163a1cfea..45f53adc2a 100644 --- a/spec/ruby/library/net/ftp/shared/putbinaryfile.rb +++ b/spec/ruby/library/net-ftp/shared/putbinaryfile.rb @@ -1,9 +1,9 @@ -describe :net_ftp_putbinaryfile, shared: :true do +describe :net_ftp_putbinaryfile, shared: true do before :each do @server = NetFTPSpecs::DummyFTP.new @server.serve_once - @local_fixture_file = File.dirname(__FILE__) + "/../fixtures/putbinaryfile" + @local_fixture_file = __dir__ + "/../fixtures/putbinaryfile" @remote_tmp_file = tmp("binaryfile", false) @ftp = Net::FTP.new diff --git a/spec/ruby/library/net/ftp/shared/puttextfile.rb b/spec/ruby/library/net-ftp/shared/puttextfile.rb index 50e8de28e6..e2c0453352 100644 --- a/spec/ruby/library/net/ftp/shared/puttextfile.rb +++ b/spec/ruby/library/net-ftp/shared/puttextfile.rb @@ -3,7 +3,7 @@ describe :net_ftp_puttextfile, shared: true do @server = NetFTPSpecs::DummyFTP.new @server.serve_once - @local_fixture_file = File.dirname(__FILE__) + "/../fixtures/puttextfile" + @local_fixture_file = __dir__ + "/../fixtures/puttextfile" @remote_tmp_file = tmp("textfile", false) @ftp = Net::FTP.new @@ -27,15 +27,23 @@ describe :net_ftp_puttextfile, shared: true do it "sends the contents of the passed local_file, using \\r\\n as the newline separator" do @ftp.send(@method, @local_fixture_file, "text") - remote_lines = open(@remote_tmp_file, "rb") {|f| f.read } - local_lines = open(@local_fixture_file, "rb") {|f| f.read } + remote_lines = File.binread(@remote_tmp_file) + local_lines = File.binread(@local_fixture_file) remote_lines.should_not == local_lines remote_lines.should == local_lines.gsub("\n", "\r\n") end - it "returns nil" do - @ftp.send(@method, @local_fixture_file, "text").should be_nil + guard -> { Net::FTP::VERSION < '0.3.6' } do + it "returns nil" do + @ftp.send(@method, @local_fixture_file, "text").should be_nil + end + end + + guard -> { Net::FTP::VERSION >= '0.3.6' } do + it "returns the response" do + @ftp.send(@method, @local_fixture_file, "text").should == @ftp.last_response + end end describe "when passed a block" do diff --git a/spec/ruby/library/net/ftp/shared/pwd.rb b/spec/ruby/library/net-ftp/shared/pwd.rb index 951d020f2d..951d020f2d 100644 --- a/spec/ruby/library/net/ftp/shared/pwd.rb +++ b/spec/ruby/library/net-ftp/shared/pwd.rb diff --git a/spec/ruby/library/net-ftp/site_spec.rb b/spec/ruby/library/net-ftp/site_spec.rb new file mode 100644 index 0000000000..c3e589a920 --- /dev/null +++ b/spec/ruby/library/net-ftp/site_spec.rb @@ -0,0 +1,53 @@ +require_relative '../../spec_helper' +require_relative 'spec_helper' +require_relative 'fixtures/server' + +describe "Net::FTP#site" do + before :each do + @server = NetFTPSpecs::DummyFTP.new + @server.serve_once + + @ftp = Net::FTP.new + @ftp.connect(@server.hostname, @server.server_port) + end + + after :each do + @ftp.quit rescue nil + @ftp.close + @server.stop + end + + it "sends the SITE command with the passed argument to the server" do + @ftp.site("param") + @ftp.last_response.should == "200 Command okay. (SITE param)\n" + end + + it "returns nil" do + @ftp.site("param").should be_nil + end + + it "does not raise an error when the response code is 202" do + @server.should_receive(:site).and_respond("202 Command not implemented, superfluous at this site.") + -> { @ftp.site("param") }.should_not raise_error + end + + it "raises a Net::FTPPermError when the response code is 500" do + @server.should_receive(:site).and_respond("500 Syntax error, command unrecognized.") + -> { @ftp.site("param") }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 501" do + @server.should_receive(:site).and_respond("501 Syntax error in parameters or arguments.") + -> { @ftp.site("param") }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPTempError when the response code is 421" do + @server.should_receive(:site).and_respond("421 Service not available, closing control connection.") + -> { @ftp.site("param") }.should raise_error(Net::FTPTempError) + end + + it "raises a Net::FTPPermError when the response code is 530" do + @server.should_receive(:site).and_respond("530 Requested action not taken.") + -> { @ftp.site("param") }.should raise_error(Net::FTPPermError) + end +end diff --git a/spec/ruby/library/net-ftp/size_spec.rb b/spec/ruby/library/net-ftp/size_spec.rb new file mode 100644 index 0000000000..0cf2e24477 --- /dev/null +++ b/spec/ruby/library/net-ftp/size_spec.rb @@ -0,0 +1,48 @@ +require_relative '../../spec_helper' +require_relative 'spec_helper' +require_relative 'fixtures/server' + +describe "Net::FTP#size" do + before :each do + @server = NetFTPSpecs::DummyFTP.new + @server.serve_once + + @ftp = Net::FTP.new + @ftp.connect(@server.hostname, @server.server_port) + end + + after :each do + @ftp.quit rescue nil + @ftp.close + @server.stop + end + + it "sends the SIZE command to the server" do + @ftp.size("test.file") + @ftp.last_response.should == "213 1024\n" + end + + it "returns the size of the passed file as Integer" do + @ftp.size("test.file").should eql(1024) + end + + it "raises a Net::FTPPermError when the response code is 500" do + @server.should_receive(:size).and_respond("500 Syntax error, command unrecognized.") + -> { @ftp.size("test.file") }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 501" do + @server.should_receive(:size).and_respond("501 Syntax error in parameters or arguments.") + -> { @ftp.size("test.file") }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPTempError when the response code is 421" do + @server.should_receive(:size).and_respond("421 Service not available, closing control connection.") + -> { @ftp.size("test.file") }.should raise_error(Net::FTPTempError) + end + + it "raises a Net::FTPPermError when the response code is 550" do + @server.should_receive(:size).and_respond("550 Requested action not taken.") + -> { @ftp.size("test.file") }.should raise_error(Net::FTPPermError) + end +end diff --git a/spec/ruby/library/net/ftp/spec_helper.rb b/spec/ruby/library/net-ftp/spec_helper.rb index c87d16218b..c87d16218b 100644 --- a/spec/ruby/library/net/ftp/spec_helper.rb +++ b/spec/ruby/library/net-ftp/spec_helper.rb diff --git a/spec/ruby/library/net-ftp/status_spec.rb b/spec/ruby/library/net-ftp/status_spec.rb new file mode 100644 index 0000000000..9d9f86c381 --- /dev/null +++ b/spec/ruby/library/net-ftp/status_spec.rb @@ -0,0 +1,67 @@ +require_relative '../../spec_helper' +require_relative 'spec_helper' +require_relative 'fixtures/server' + +describe "Net::FTP#status" do + before :each do + @server = NetFTPSpecs::DummyFTP.new + @server.serve_once + + @ftp = Net::FTP.new + @ftp.connect(@server.hostname, @server.server_port) + end + + after :each do + @ftp.quit rescue nil + @ftp.close + @server.stop + end + + it "sends the STAT command to the server" do + @ftp.status + @ftp.last_response.should == "211 System status, or system help reply. (STAT)\n" + end + + it "sends the STAT command with an optional parameter to the server" do + @ftp.status("/pub").should == "211 System status, or system help reply. (STAT /pub)\n" + end + + it "returns the received information" do + @ftp.status.should == "211 System status, or system help reply. (STAT)\n" + end + + it "does not raise an error when the response code is 212" do + @server.should_receive(:stat).and_respond("212 Directory status.") + -> { @ftp.status }.should_not raise_error + end + + it "does not raise an error when the response code is 213" do + @server.should_receive(:stat).and_respond("213 File status.") + -> { @ftp.status }.should_not raise_error + end + + it "raises a Net::FTPPermError when the response code is 500" do + @server.should_receive(:stat).and_respond("500 Syntax error, command unrecognized.") + -> { @ftp.status }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 501" do + @server.should_receive(:stat).and_respond("501 Syntax error in parameters or arguments.") + -> { @ftp.status }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 502" do + @server.should_receive(:stat).and_respond("502 Command not implemented.") + -> { @ftp.status }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPTempError when the response code is 421" do + @server.should_receive(:stat).and_respond("421 Service not available, closing control connection.") + -> { @ftp.status }.should raise_error(Net::FTPTempError) + end + + it "raises a Net::FTPPermError when the response code is 530" do + @server.should_receive(:stat).and_respond("530 Requested action not taken.") + -> { @ftp.status }.should raise_error(Net::FTPPermError) + end +end diff --git a/spec/ruby/library/net-ftp/storbinary_spec.rb b/spec/ruby/library/net-ftp/storbinary_spec.rb new file mode 100644 index 0000000000..aa4c51f2e8 --- /dev/null +++ b/spec/ruby/library/net-ftp/storbinary_spec.rb @@ -0,0 +1,49 @@ +require_relative '../../spec_helper' + +require_relative 'spec_helper' +require_relative 'fixtures/server' + +describe "Net::FTP#storbinary" do + before :each do + @server = NetFTPSpecs::DummyFTP.new + @server.serve_once + + @local_fixture_file = __dir__ + "/fixtures/putbinaryfile" + @tmp_file = tmp("binaryfile", false) + + @ftp = Net::FTP.new + @ftp.connect(@server.hostname, @server.server_port) + end + + after :each do + @ftp.quit rescue nil + @ftp.close + @server.stop + + rm_r @tmp_file + end + + it "sends the passed command and the passed File object's content to the server" do + File.open(@local_fixture_file) do |f| + f.binmode + + @ftp.storbinary("STOR binary", f, 4096) {} + @ftp.last_response.should == "200 OK, Data received. (STOR binary)\n" + end + end + + it "yields the transmitted content as binary blocks of the passed size" do + File.open(@local_fixture_file) do |f| + f.binmode + + res = [] + @ftp.storbinary("STOR binary", f, 10) { |x| res << x } + res.should == [ + "This is an", " example f", + "ile\nwhich ", "is going t", + "o be trans", "mitted\nusi", + "ng #putbin", "aryfile.\n" + ] + end + end +end diff --git a/spec/ruby/library/net-ftp/storlines_spec.rb b/spec/ruby/library/net-ftp/storlines_spec.rb new file mode 100644 index 0000000000..dc6830da7b --- /dev/null +++ b/spec/ruby/library/net-ftp/storlines_spec.rb @@ -0,0 +1,44 @@ +require_relative '../../spec_helper' + +require_relative 'spec_helper' +require_relative 'fixtures/server' + +describe "Net::FTP#storlines" do + before :each do + @server = NetFTPSpecs::DummyFTP.new + @server.serve_once + + @local_fixture_file = __dir__ + "/fixtures/puttextfile" + @tmp_file = tmp("textfile", false) + + @ftp = Net::FTP.new + @ftp.connect(@server.hostname, @server.server_port) + end + + after :each do + @ftp.quit rescue nil + @ftp.close + @server.stop + + rm_r @tmp_file + end + + it "sends the passed command and the passed File object's content to the server" do + File.open(@local_fixture_file) do |f| + @ftp.storlines("STOR text", f) {} + @ftp.last_response.should == "200 OK, Data received. (STOR text)\n" + end + end + + it "yields each line of the transmitted content" do + File.open(@local_fixture_file) do |f| + res = [] + @ftp.storlines("STOR text", f) { |x| res << x } + res.should == [ + "This is an example file\r\n", + "which is going to be transmitted\r\n", + "using #puttextfile.\r\n" + ] + end + end +end diff --git a/spec/ruby/library/net-ftp/system_spec.rb b/spec/ruby/library/net-ftp/system_spec.rb new file mode 100644 index 0000000000..2b7f0d2560 --- /dev/null +++ b/spec/ruby/library/net-ftp/system_spec.rb @@ -0,0 +1,48 @@ +require_relative '../../spec_helper' +require_relative 'spec_helper' +require_relative 'fixtures/server' + +describe "Net::FTP#system" do + before :each do + @server = NetFTPSpecs::DummyFTP.new + @server.serve_once + + @ftp = Net::FTP.new + @ftp.connect(@server.hostname, @server.server_port) + end + + after :each do + @ftp.quit rescue nil + @ftp.close + @server.stop + end + + it "sends the SYST command to the server" do + @ftp.system + @ftp.last_response.should =~ /\A215 FTP Dummy Server \(SYST\)\Z/ + end + + it "returns the received information" do + @ftp.system.should =~ /\AFTP Dummy Server \(SYST\)\Z/ + end + + it "raises a Net::FTPPermError when the response code is 500" do + @server.should_receive(:syst).and_respond("500 Syntax error, command unrecognized.") + -> { @ftp.system }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 501" do + @server.should_receive(:syst).and_respond("501 Syntax error in parameters or arguments.") + -> { @ftp.system }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 502" do + @server.should_receive(:syst).and_respond("502 Command not implemented.") + -> { @ftp.system }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPTempError when the response code is 421" do + @server.should_receive(:syst).and_respond("421 Service not available, closing control connection.") + -> { @ftp.system }.should raise_error(Net::FTPTempError) + end +end diff --git a/spec/ruby/library/net-ftp/voidcmd_spec.rb b/spec/ruby/library/net-ftp/voidcmd_spec.rb new file mode 100644 index 0000000000..f2536fe697 --- /dev/null +++ b/spec/ruby/library/net-ftp/voidcmd_spec.rb @@ -0,0 +1,54 @@ +require_relative '../../spec_helper' +require_relative 'spec_helper' +require_relative 'fixtures/server' + +describe "Net::FTP#voidcmd" do + before :each do + @server = NetFTPSpecs::DummyFTP.new + @server.serve_once + + @ftp = Net::FTP.new + @ftp.connect(@server.hostname, @server.server_port) + end + + after :each do + @ftp.quit rescue nil + @ftp.close + @server.stop + end + + it "sends the passed command to the server" do + @server.should_receive(:help).and_respond("2xx Does not raise.") + -> { @ftp.voidcmd("HELP") }.should_not raise_error + end + + it "returns nil" do + @server.should_receive(:help).and_respond("2xx Does not raise.") + @ftp.voidcmd("HELP").should be_nil + end + + it "raises a Net::FTPReplyError when the response code is 1xx" do + @server.should_receive(:help).and_respond("1xx Does raise a Net::FTPReplyError.") + -> { @ftp.voidcmd("HELP") }.should raise_error(Net::FTPReplyError) + end + + it "raises a Net::FTPReplyError when the response code is 3xx" do + @server.should_receive(:help).and_respond("3xx Does raise a Net::FTPReplyError.") + -> { @ftp.voidcmd("HELP") }.should raise_error(Net::FTPReplyError) + end + + it "raises a Net::FTPTempError when the response code is 4xx" do + @server.should_receive(:help).and_respond("4xx Does raise a Net::FTPTempError.") + -> { @ftp.voidcmd("HELP") }.should raise_error(Net::FTPTempError) + end + + it "raises a Net::FTPPermError when the response code is 5xx" do + @server.should_receive(:help).and_respond("5xx Does raise a Net::FTPPermError.") + -> { @ftp.voidcmd("HELP") }.should raise_error(Net::FTPPermError) + end + + it "raises a Net::FTPProtoError when the response code is not valid" do + @server.should_receive(:help).and_respond("999 Does raise a Net::FTPProtoError.") + -> { @ftp.voidcmd("HELP") }.should raise_error(Net::FTPProtoError) + end +end diff --git a/spec/ruby/library/net-ftp/welcome_spec.rb b/spec/ruby/library/net-ftp/welcome_spec.rb new file mode 100644 index 0000000000..4279127ce3 --- /dev/null +++ b/spec/ruby/library/net-ftp/welcome_spec.rb @@ -0,0 +1,25 @@ +require_relative '../../spec_helper' +require_relative 'spec_helper' +require_relative 'fixtures/server' + +describe "Net::FTP#welcome" do + before :each do + @server = NetFTPSpecs::DummyFTP.new + @server.serve_once + + @ftp = Net::FTP.new + @ftp.connect(@server.hostname, @server.server_port) + end + + after :each do + @ftp.quit rescue nil + @ftp.close + @server.stop + end + + it "returns the server's welcome message" do + @ftp.welcome.should be_nil + @ftp.login + @ftp.welcome.should == "230 User logged in, proceed. (USER anonymous)\n" + end +end diff --git a/spec/ruby/library/net/http/HTTPBadResponse_spec.rb b/spec/ruby/library/net-http/HTTPBadResponse_spec.rb index be644968f5..8f2e8ccfaf 100644 --- a/spec/ruby/library/net/http/HTTPBadResponse_spec.rb +++ b/spec/ruby/library/net-http/HTTPBadResponse_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../spec_helper' +require_relative '../../spec_helper' require 'net/http' describe "Net::HTTPBadResponse" do diff --git a/spec/ruby/library/net/http/HTTPClientExcepton_spec.rb b/spec/ruby/library/net-http/HTTPClientExcepton_spec.rb index d576349a57..2992e6596f 100644 --- a/spec/ruby/library/net/http/HTTPClientExcepton_spec.rb +++ b/spec/ruby/library/net-http/HTTPClientExcepton_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../spec_helper' +require_relative '../../spec_helper' require 'net/http' describe "Net::HTTPClientException" do diff --git a/spec/ruby/library/net/http/HTTPError_spec.rb b/spec/ruby/library/net-http/HTTPError_spec.rb index ab5f491bb7..7f79eef8cf 100644 --- a/spec/ruby/library/net/http/HTTPError_spec.rb +++ b/spec/ruby/library/net-http/HTTPError_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../spec_helper' +require_relative '../../spec_helper' require 'net/http' describe "Net::HTTPError" do diff --git a/spec/ruby/library/net/http/HTTPFatalError_spec.rb b/spec/ruby/library/net-http/HTTPFatalError_spec.rb index 6ab36bff6c..0113b9da2d 100644 --- a/spec/ruby/library/net/http/HTTPFatalError_spec.rb +++ b/spec/ruby/library/net-http/HTTPFatalError_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../spec_helper' +require_relative '../../spec_helper' require 'net/http' describe "Net::HTTPFatalError" do diff --git a/spec/ruby/library/net/http/HTTPHeaderSyntaxError_spec.rb b/spec/ruby/library/net-http/HTTPHeaderSyntaxError_spec.rb index 38e9454f99..b3b73ff46f 100644 --- a/spec/ruby/library/net/http/HTTPHeaderSyntaxError_spec.rb +++ b/spec/ruby/library/net-http/HTTPHeaderSyntaxError_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../spec_helper' +require_relative '../../spec_helper' require 'net/http' describe "Net::HTTPHeaderSyntaxError" do diff --git a/spec/ruby/library/net/http/HTTPRetriableError_spec.rb b/spec/ruby/library/net-http/HTTPRetriableError_spec.rb index 3a4bb9146c..677731fb68 100644 --- a/spec/ruby/library/net/http/HTTPRetriableError_spec.rb +++ b/spec/ruby/library/net-http/HTTPRetriableError_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../spec_helper' +require_relative '../../spec_helper' require 'net/http' describe "Net::HTTPRetriableError" do diff --git a/spec/ruby/library/net-http/HTTPServerException_spec.rb b/spec/ruby/library/net-http/HTTPServerException_spec.rb new file mode 100644 index 0000000000..020d3cce85 --- /dev/null +++ b/spec/ruby/library/net-http/HTTPServerException_spec.rb @@ -0,0 +1,12 @@ +require_relative '../../spec_helper' +require 'net/http' + +describe "Net::HTTPServerException" do + it "is a subclass of Net::ProtoServerError and is warned as deprecated" do + -> { eval("Net::HTTPServerException").should < Net::ProtoServerError }.should complain(/warning: constant Net::HTTPServerException is deprecated/) + end + + it "includes the Net::HTTPExceptions module and is warned as deprecated" do + -> { eval("Net::HTTPServerException").should < Net::HTTPExceptions }.should complain(/warning: constant Net::HTTPServerException is deprecated/) + end +end diff --git a/spec/ruby/library/net/http/http/Proxy_spec.rb b/spec/ruby/library/net-http/http/Proxy_spec.rb index f85ccc0ee9..a1a04fa00b 100644 --- a/spec/ruby/library/net/http/http/Proxy_spec.rb +++ b/spec/ruby/library/net-http/http/Proxy_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTP.Proxy" do diff --git a/spec/ruby/library/net/http/http/active_spec.rb b/spec/ruby/library/net-http/http/active_spec.rb index ef657243ba..c260274594 100644 --- a/spec/ruby/library/net/http/http/active_spec.rb +++ b/spec/ruby/library/net-http/http/active_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' require_relative 'shared/started' diff --git a/spec/ruby/library/net/http/http/address_spec.rb b/spec/ruby/library/net-http/http/address_spec.rb index 5fce76d767..7c5b82a8f9 100644 --- a/spec/ruby/library/net/http/http/address_spec.rb +++ b/spec/ruby/library/net-http/http/address_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTP#address" do diff --git a/spec/ruby/library/net/http/http/close_on_empty_response_spec.rb b/spec/ruby/library/net-http/http/close_on_empty_response_spec.rb index a97b7b6c43..9cc756befb 100644 --- a/spec/ruby/library/net/http/http/close_on_empty_response_spec.rb +++ b/spec/ruby/library/net-http/http/close_on_empty_response_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTP#close_on_empty_response" do diff --git a/spec/ruby/library/net/http/http/copy_spec.rb b/spec/ruby/library/net-http/http/copy_spec.rb index 5ebfdc334e..fba96c0f11 100644 --- a/spec/ruby/library/net/http/http/copy_spec.rb +++ b/spec/ruby/library/net-http/http/copy_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' diff --git a/spec/ruby/library/net/http/http/default_port_spec.rb b/spec/ruby/library/net-http/http/default_port_spec.rb index 30db18efae..95b7316a0c 100644 --- a/spec/ruby/library/net/http/http/default_port_spec.rb +++ b/spec/ruby/library/net-http/http/default_port_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTP.default_port" do diff --git a/spec/ruby/library/net/http/http/delete_spec.rb b/spec/ruby/library/net-http/http/delete_spec.rb index 160c653115..d73aa5b375 100644 --- a/spec/ruby/library/net/http/http/delete_spec.rb +++ b/spec/ruby/library/net-http/http/delete_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' diff --git a/spec/ruby/library/net/http/http/finish_spec.rb b/spec/ruby/library/net-http/http/finish_spec.rb index f98bc7be13..d4aa00dffe 100644 --- a/spec/ruby/library/net/http/http/finish_spec.rb +++ b/spec/ruby/library/net-http/http/finish_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' diff --git a/spec/ruby/library/net/http/http/fixtures/http_server.rb b/spec/ruby/library/net-http/http/fixtures/http_server.rb index c1cedbfa76..c1cedbfa76 100644 --- a/spec/ruby/library/net/http/http/fixtures/http_server.rb +++ b/spec/ruby/library/net-http/http/fixtures/http_server.rb diff --git a/spec/ruby/library/net/http/http/get2_spec.rb b/spec/ruby/library/net-http/http/get2_spec.rb index 519e4c2599..57c05ec64b 100644 --- a/spec/ruby/library/net/http/http/get2_spec.rb +++ b/spec/ruby/library/net-http/http/get2_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' require_relative 'shared/request_get' diff --git a/spec/ruby/library/net/http/http/get_print_spec.rb b/spec/ruby/library/net-http/http/get_print_spec.rb index f59dd68c81..3c24ce44ea 100644 --- a/spec/ruby/library/net/http/http/get_print_spec.rb +++ b/spec/ruby/library/net-http/http/get_print_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' diff --git a/spec/ruby/library/net/http/http/get_response_spec.rb b/spec/ruby/library/net-http/http/get_response_spec.rb index 941b35e773..7133ef8101 100644 --- a/spec/ruby/library/net/http/http/get_response_spec.rb +++ b/spec/ruby/library/net-http/http/get_response_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' diff --git a/spec/ruby/library/net/http/http/get_spec.rb b/spec/ruby/library/net-http/http/get_spec.rb index 9f6c45f26b..e64a61c52c 100644 --- a/spec/ruby/library/net/http/http/get_spec.rb +++ b/spec/ruby/library/net-http/http/get_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' @@ -80,15 +80,13 @@ describe "Net::HTTP.get" do end end - ruby_version_is "3.0" do # https://bugs.ruby-lang.org/issues/13882#note-6 - it "lets the kill Thread exception goes through and does not replace it with Zlib::BufError" do - socket, client_thread = start_threads - begin - client_thread.kill - client_thread.value.should == nil - ensure - socket.close - end + it "lets the kill Thread exception goes through and does not replace it with Zlib::BufError" do + socket, client_thread = start_threads + begin + client_thread.kill + client_thread.value.should == nil + ensure + socket.close end end end diff --git a/spec/ruby/library/net/http/http/head2_spec.rb b/spec/ruby/library/net-http/http/head2_spec.rb index 6958204ee1..84cfff33d7 100644 --- a/spec/ruby/library/net/http/http/head2_spec.rb +++ b/spec/ruby/library/net-http/http/head2_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' require_relative 'shared/request_head' diff --git a/spec/ruby/library/net/http/http/head_spec.rb b/spec/ruby/library/net-http/http/head_spec.rb index 925a8e6043..64621fa87b 100644 --- a/spec/ruby/library/net/http/http/head_spec.rb +++ b/spec/ruby/library/net-http/http/head_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' diff --git a/spec/ruby/library/net/http/http/http_default_port_spec.rb b/spec/ruby/library/net-http/http/http_default_port_spec.rb index cf7f73e630..3b17bcd0a5 100644 --- a/spec/ruby/library/net/http/http/http_default_port_spec.rb +++ b/spec/ruby/library/net-http/http/http_default_port_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTP.http_default_port" do diff --git a/spec/ruby/library/net/http/http/https_default_port_spec.rb b/spec/ruby/library/net-http/http/https_default_port_spec.rb index fbf0bd1abc..8c24e1d97c 100644 --- a/spec/ruby/library/net/http/http/https_default_port_spec.rb +++ b/spec/ruby/library/net-http/http/https_default_port_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTP.https_default_port" do diff --git a/spec/ruby/library/net/http/http/initialize_spec.rb b/spec/ruby/library/net-http/http/initialize_spec.rb index 7683713a0e..78aa01e1aa 100644 --- a/spec/ruby/library/net/http/http/initialize_spec.rb +++ b/spec/ruby/library/net-http/http/initialize_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTP#initialize" do diff --git a/spec/ruby/library/net/http/http/inspect_spec.rb b/spec/ruby/library/net-http/http/inspect_spec.rb index b1e799ca34..b8f650809e 100644 --- a/spec/ruby/library/net/http/http/inspect_spec.rb +++ b/spec/ruby/library/net-http/http/inspect_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' diff --git a/spec/ruby/library/net/http/http/is_version_1_1_spec.rb b/spec/ruby/library/net-http/http/is_version_1_1_spec.rb index f37695b777..bdb343f9e0 100644 --- a/spec/ruby/library/net/http/http/is_version_1_1_spec.rb +++ b/spec/ruby/library/net-http/http/is_version_1_1_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'shared/version_1_1' diff --git a/spec/ruby/library/net/http/http/is_version_1_2_spec.rb b/spec/ruby/library/net-http/http/is_version_1_2_spec.rb index 82dbdc87aa..555bb205dd 100644 --- a/spec/ruby/library/net/http/http/is_version_1_2_spec.rb +++ b/spec/ruby/library/net-http/http/is_version_1_2_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'shared/version_1_2' diff --git a/spec/ruby/library/net/http/http/lock_spec.rb b/spec/ruby/library/net-http/http/lock_spec.rb index bb76607a8b..aa1f944196 100644 --- a/spec/ruby/library/net/http/http/lock_spec.rb +++ b/spec/ruby/library/net-http/http/lock_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' diff --git a/spec/ruby/library/net/http/http/mkcol_spec.rb b/spec/ruby/library/net-http/http/mkcol_spec.rb index 33017625e2..f8009f9059 100644 --- a/spec/ruby/library/net/http/http/mkcol_spec.rb +++ b/spec/ruby/library/net-http/http/mkcol_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' diff --git a/spec/ruby/library/net/http/http/move_spec.rb b/spec/ruby/library/net-http/http/move_spec.rb index 4d6b828150..ae43016a2c 100644 --- a/spec/ruby/library/net/http/http/move_spec.rb +++ b/spec/ruby/library/net-http/http/move_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' diff --git a/spec/ruby/library/net/http/http/new_spec.rb b/spec/ruby/library/net-http/http/new_spec.rb index 491d1d01fd..1ec6bbd0c0 100644 --- a/spec/ruby/library/net/http/http/new_spec.rb +++ b/spec/ruby/library/net-http/http/new_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTP.new" do diff --git a/spec/ruby/library/net/http/http/newobj_spec.rb b/spec/ruby/library/net-http/http/newobj_spec.rb index b261dcc5db..e19b30fca9 100644 --- a/spec/ruby/library/net/http/http/newobj_spec.rb +++ b/spec/ruby/library/net-http/http/newobj_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTP.newobj" do diff --git a/spec/ruby/library/net/http/http/open_timeout_spec.rb b/spec/ruby/library/net-http/http/open_timeout_spec.rb index 44b33615e6..0d93752271 100644 --- a/spec/ruby/library/net/http/http/open_timeout_spec.rb +++ b/spec/ruby/library/net-http/http/open_timeout_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTP#open_timeout" do diff --git a/spec/ruby/library/net/http/http/options_spec.rb b/spec/ruby/library/net-http/http/options_spec.rb index d798e69197..3d9887a557 100644 --- a/spec/ruby/library/net/http/http/options_spec.rb +++ b/spec/ruby/library/net-http/http/options_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' diff --git a/spec/ruby/library/net/http/http/port_spec.rb b/spec/ruby/library/net-http/http/port_spec.rb index 7de295ca75..0984d5e6ce 100644 --- a/spec/ruby/library/net/http/http/port_spec.rb +++ b/spec/ruby/library/net-http/http/port_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTP#port" do diff --git a/spec/ruby/library/net/http/http/post2_spec.rb b/spec/ruby/library/net-http/http/post2_spec.rb index ccc95068fb..abc998709f 100644 --- a/spec/ruby/library/net/http/http/post2_spec.rb +++ b/spec/ruby/library/net-http/http/post2_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' require_relative 'shared/request_post' diff --git a/spec/ruby/library/net/http/http/post_form_spec.rb b/spec/ruby/library/net-http/http/post_form_spec.rb index 891e05e7af..de64a25bae 100644 --- a/spec/ruby/library/net/http/http/post_form_spec.rb +++ b/spec/ruby/library/net-http/http/post_form_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' diff --git a/spec/ruby/library/net/http/http/post_spec.rb b/spec/ruby/library/net-http/http/post_spec.rb index 891e20aaca..b8b8d16ad1 100644 --- a/spec/ruby/library/net/http/http/post_spec.rb +++ b/spec/ruby/library/net-http/http/post_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require 'uri' require_relative 'fixtures/http_server' @@ -25,9 +25,11 @@ describe "Net::HTTP.post" do response.should be_kind_of(Net::HTTPResponse) end - it "sends Content-Type: application/x-www-form-urlencoded by default" do - response = Net::HTTP.post(URI("http://localhost:#{NetHTTPSpecs.port}/request/header"), "test=test") - response.body.should include('"Content-Type"=>"application/x-www-form-urlencoded"') + ruby_version_is ""..."4.0" do + it "sends Content-Type: application/x-www-form-urlencoded by default" do + response = Net::HTTP.post(URI("http://localhost:#{NetHTTPSpecs.port}/request/header"), "test=test") + response.body.should include({ "Content-Type" => "application/x-www-form-urlencoded" }.inspect.delete("{}")) + end end it "does not support HTTP Basic Auth" do @@ -60,7 +62,7 @@ describe "Net::HTTP#post" do describe "when passed a block" do it "yields fragments of the response body to the passed block" do - str = "" + str = +"" @http.post("/request", "test=test") do |res| str << res end diff --git a/spec/ruby/library/net/http/http/propfind_spec.rb b/spec/ruby/library/net-http/http/propfind_spec.rb index 5240171618..f3742d1b1a 100644 --- a/spec/ruby/library/net/http/http/propfind_spec.rb +++ b/spec/ruby/library/net-http/http/propfind_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' diff --git a/spec/ruby/library/net/http/http/proppatch_spec.rb b/spec/ruby/library/net-http/http/proppatch_spec.rb index 7a761a9f23..0163d24d46 100644 --- a/spec/ruby/library/net/http/http/proppatch_spec.rb +++ b/spec/ruby/library/net-http/http/proppatch_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' diff --git a/spec/ruby/library/net/http/http/proxy_address_spec.rb b/spec/ruby/library/net-http/http/proxy_address_spec.rb index 8d152b8d44..5b5efb7ac0 100644 --- a/spec/ruby/library/net/http/http/proxy_address_spec.rb +++ b/spec/ruby/library/net-http/http/proxy_address_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTP.proxy_address" do diff --git a/spec/ruby/library/net/http/http/proxy_class_spec.rb b/spec/ruby/library/net-http/http/proxy_class_spec.rb index 2d32a39f01..00975aef4e 100644 --- a/spec/ruby/library/net/http/http/proxy_class_spec.rb +++ b/spec/ruby/library/net-http/http/proxy_class_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTP.proxy_class?" do diff --git a/spec/ruby/library/net/http/http/proxy_pass_spec.rb b/spec/ruby/library/net-http/http/proxy_pass_spec.rb index 94a0034544..4e393a53ff 100644 --- a/spec/ruby/library/net/http/http/proxy_pass_spec.rb +++ b/spec/ruby/library/net-http/http/proxy_pass_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTP.proxy_pass" do diff --git a/spec/ruby/library/net/http/http/proxy_port_spec.rb b/spec/ruby/library/net-http/http/proxy_port_spec.rb index 339f7ee850..d7d37f3927 100644 --- a/spec/ruby/library/net/http/http/proxy_port_spec.rb +++ b/spec/ruby/library/net-http/http/proxy_port_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTP.proxy_port" do diff --git a/spec/ruby/library/net/http/http/proxy_user_spec.rb b/spec/ruby/library/net-http/http/proxy_user_spec.rb index 01fda400e9..ef7654425d 100644 --- a/spec/ruby/library/net/http/http/proxy_user_spec.rb +++ b/spec/ruby/library/net-http/http/proxy_user_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTP.proxy_user" do diff --git a/spec/ruby/library/net/http/http/put2_spec.rb b/spec/ruby/library/net-http/http/put2_spec.rb index 99329a5fd9..7b03a39d0b 100644 --- a/spec/ruby/library/net/http/http/put2_spec.rb +++ b/spec/ruby/library/net-http/http/put2_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' require_relative 'shared/request_put' diff --git a/spec/ruby/library/net/http/http/put_spec.rb b/spec/ruby/library/net-http/http/put_spec.rb index 3ca0d0963e..75f3c243d4 100644 --- a/spec/ruby/library/net/http/http/put_spec.rb +++ b/spec/ruby/library/net-http/http/put_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' diff --git a/spec/ruby/library/net/http/http/read_timeout_spec.rb b/spec/ruby/library/net-http/http/read_timeout_spec.rb index e23ee76025..7a0d2f1d72 100644 --- a/spec/ruby/library/net/http/http/read_timeout_spec.rb +++ b/spec/ruby/library/net-http/http/read_timeout_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTP#read_timeout" do diff --git a/spec/ruby/library/net/http/http/request_get_spec.rb b/spec/ruby/library/net-http/http/request_get_spec.rb index 9932ef0beb..98025a14a1 100644 --- a/spec/ruby/library/net/http/http/request_get_spec.rb +++ b/spec/ruby/library/net-http/http/request_get_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' require_relative 'shared/request_get' diff --git a/spec/ruby/library/net/http/http/request_head_spec.rb b/spec/ruby/library/net-http/http/request_head_spec.rb index 788101c951..8f514d4eee 100644 --- a/spec/ruby/library/net/http/http/request_head_spec.rb +++ b/spec/ruby/library/net-http/http/request_head_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' require_relative 'shared/request_head' diff --git a/spec/ruby/library/net/http/http/request_post_spec.rb b/spec/ruby/library/net-http/http/request_post_spec.rb index 7ac67cf95d..719bd5a7ee 100644 --- a/spec/ruby/library/net/http/http/request_post_spec.rb +++ b/spec/ruby/library/net-http/http/request_post_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' require_relative 'shared/request_post' diff --git a/spec/ruby/library/net/http/http/request_put_spec.rb b/spec/ruby/library/net-http/http/request_put_spec.rb index 110ac43ca6..9fcf3a98d6 100644 --- a/spec/ruby/library/net/http/http/request_put_spec.rb +++ b/spec/ruby/library/net-http/http/request_put_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' require_relative 'shared/request_put' diff --git a/spec/ruby/library/net/http/http/request_spec.rb b/spec/ruby/library/net-http/http/request_spec.rb index e63dde9c8d..356e605b3b 100644 --- a/spec/ruby/library/net/http/http/request_spec.rb +++ b/spec/ruby/library/net-http/http/request_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' diff --git a/spec/ruby/library/net/http/http/request_types_spec.rb b/spec/ruby/library/net-http/http/request_types_spec.rb index 99d754d3d1..53aef1ee58 100644 --- a/spec/ruby/library/net/http/http/request_types_spec.rb +++ b/spec/ruby/library/net-http/http/request_types_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTP::Get" do diff --git a/spec/ruby/library/net/http/http/send_request_spec.rb b/spec/ruby/library/net-http/http/send_request_spec.rb index 83e9448b8b..af35c068ce 100644 --- a/spec/ruby/library/net/http/http/send_request_spec.rb +++ b/spec/ruby/library/net-http/http/send_request_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' @@ -54,7 +54,7 @@ describe "Net::HTTP#send_request" do @methods.each do |method| response = @http.send_request(method, "/request/header", "test=test", "referer" => referer) - response.body.should include('"Referer"=>"' + referer + '"') + response.body.should include({ "Referer" => referer }.inspect.delete("{}")) end end end diff --git a/spec/ruby/library/net/http/http/set_debug_output_spec.rb b/spec/ruby/library/net-http/http/set_debug_output_spec.rb index 94b6f4499d..5ceecb39fb 100644 --- a/spec/ruby/library/net/http/http/set_debug_output_spec.rb +++ b/spec/ruby/library/net-http/http/set_debug_output_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require "stringio" require_relative 'fixtures/http_server' diff --git a/spec/ruby/library/net/http/http/shared/request_get.rb b/spec/ruby/library/net-http/http/shared/request_get.rb index d25f32049b..d25f32049b 100644 --- a/spec/ruby/library/net/http/http/shared/request_get.rb +++ b/spec/ruby/library/net-http/http/shared/request_get.rb diff --git a/spec/ruby/library/net/http/http/shared/request_head.rb b/spec/ruby/library/net-http/http/shared/request_head.rb index 78b555884b..78b555884b 100644 --- a/spec/ruby/library/net/http/http/shared/request_head.rb +++ b/spec/ruby/library/net-http/http/shared/request_head.rb diff --git a/spec/ruby/library/net/http/http/shared/request_post.rb b/spec/ruby/library/net-http/http/shared/request_post.rb index e832411c48..e832411c48 100644 --- a/spec/ruby/library/net/http/http/shared/request_post.rb +++ b/spec/ruby/library/net-http/http/shared/request_post.rb diff --git a/spec/ruby/library/net/http/http/shared/request_put.rb b/spec/ruby/library/net-http/http/shared/request_put.rb index 3b902f4957..3b902f4957 100644 --- a/spec/ruby/library/net/http/http/shared/request_put.rb +++ b/spec/ruby/library/net-http/http/shared/request_put.rb diff --git a/spec/ruby/library/net/http/http/shared/started.rb b/spec/ruby/library/net-http/http/shared/started.rb index 9ff6272c31..9ff6272c31 100644 --- a/spec/ruby/library/net/http/http/shared/started.rb +++ b/spec/ruby/library/net-http/http/shared/started.rb diff --git a/spec/ruby/library/net/http/http/shared/version_1_1.rb b/spec/ruby/library/net-http/http/shared/version_1_1.rb index db3d6a986d..db3d6a986d 100644 --- a/spec/ruby/library/net/http/http/shared/version_1_1.rb +++ b/spec/ruby/library/net-http/http/shared/version_1_1.rb diff --git a/spec/ruby/library/net/http/http/shared/version_1_2.rb b/spec/ruby/library/net-http/http/shared/version_1_2.rb index b044182c60..b044182c60 100644 --- a/spec/ruby/library/net/http/http/shared/version_1_2.rb +++ b/spec/ruby/library/net-http/http/shared/version_1_2.rb diff --git a/spec/ruby/library/net/http/http/socket_type_spec.rb b/spec/ruby/library/net-http/http/socket_type_spec.rb index 5c844ddf94..f6826777b0 100644 --- a/spec/ruby/library/net/http/http/socket_type_spec.rb +++ b/spec/ruby/library/net-http/http/socket_type_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTP.socket_type" do diff --git a/spec/ruby/library/net/http/http/start_spec.rb b/spec/ruby/library/net-http/http/start_spec.rb index a2768eed18..0ce3e79269 100644 --- a/spec/ruby/library/net/http/http/start_spec.rb +++ b/spec/ruby/library/net-http/http/start_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' diff --git a/spec/ruby/library/net/http/http/started_spec.rb b/spec/ruby/library/net-http/http/started_spec.rb index ea441ed16a..cbb82ceefa 100644 --- a/spec/ruby/library/net/http/http/started_spec.rb +++ b/spec/ruby/library/net-http/http/started_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' require_relative 'shared/started' diff --git a/spec/ruby/library/net/http/http/trace_spec.rb b/spec/ruby/library/net-http/http/trace_spec.rb index 94a1bf6655..9809d537c5 100644 --- a/spec/ruby/library/net/http/http/trace_spec.rb +++ b/spec/ruby/library/net-http/http/trace_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' diff --git a/spec/ruby/library/net/http/http/unlock_spec.rb b/spec/ruby/library/net-http/http/unlock_spec.rb index a4f1b7a1d1..adf0b49f65 100644 --- a/spec/ruby/library/net/http/http/unlock_spec.rb +++ b/spec/ruby/library/net-http/http/unlock_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' diff --git a/spec/ruby/library/net/http/http/use_ssl_spec.rb b/spec/ruby/library/net-http/http/use_ssl_spec.rb index be1ec7fa25..912a62a8ba 100644 --- a/spec/ruby/library/net/http/http/use_ssl_spec.rb +++ b/spec/ruby/library/net-http/http/use_ssl_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTP#use_ssl?" do diff --git a/spec/ruby/library/net/http/http/version_1_1_spec.rb b/spec/ruby/library/net-http/http/version_1_1_spec.rb index 1c069e9ea6..34a4ac8a6b 100644 --- a/spec/ruby/library/net/http/http/version_1_1_spec.rb +++ b/spec/ruby/library/net-http/http/version_1_1_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'shared/version_1_1' diff --git a/spec/ruby/library/net/http/http/version_1_2_spec.rb b/spec/ruby/library/net-http/http/version_1_2_spec.rb index 4e601462c9..e994511aea 100644 --- a/spec/ruby/library/net/http/http/version_1_2_spec.rb +++ b/spec/ruby/library/net-http/http/version_1_2_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'shared/version_1_2' diff --git a/spec/ruby/library/net/http/httpexceptions/fixtures/classes.rb b/spec/ruby/library/net-http/httpexceptions/fixtures/classes.rb index abe8855eff..abe8855eff 100644 --- a/spec/ruby/library/net/http/httpexceptions/fixtures/classes.rb +++ b/spec/ruby/library/net-http/httpexceptions/fixtures/classes.rb diff --git a/spec/ruby/library/net/http/httpexceptions/initialize_spec.rb b/spec/ruby/library/net-http/httpexceptions/initialize_spec.rb index 8e3fd8cc02..5316cca69d 100644 --- a/spec/ruby/library/net/http/httpexceptions/initialize_spec.rb +++ b/spec/ruby/library/net-http/httpexceptions/initialize_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' diff --git a/spec/ruby/library/net/http/httpexceptions/response_spec.rb b/spec/ruby/library/net-http/httpexceptions/response_spec.rb index 205b2bc212..d718b1ae21 100644 --- a/spec/ruby/library/net/http/httpexceptions/response_spec.rb +++ b/spec/ruby/library/net-http/httpexceptions/response_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' diff --git a/spec/ruby/library/net/http/httpgenericrequest/body_exist_spec.rb b/spec/ruby/library/net-http/httpgenericrequest/body_exist_spec.rb index 7d081939b8..6c886499ca 100644 --- a/spec/ruby/library/net/http/httpgenericrequest/body_exist_spec.rb +++ b/spec/ruby/library/net-http/httpgenericrequest/body_exist_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTPGenericRequest#body_exist?" do diff --git a/spec/ruby/library/net/http/httpgenericrequest/body_spec.rb b/spec/ruby/library/net-http/httpgenericrequest/body_spec.rb index a215895b57..5f7315f303 100644 --- a/spec/ruby/library/net/http/httpgenericrequest/body_spec.rb +++ b/spec/ruby/library/net-http/httpgenericrequest/body_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require "stringio" diff --git a/spec/ruby/library/net/http/httpgenericrequest/body_stream_spec.rb b/spec/ruby/library/net-http/httpgenericrequest/body_stream_spec.rb index c2a60e6836..dea1c8c883 100644 --- a/spec/ruby/library/net/http/httpgenericrequest/body_stream_spec.rb +++ b/spec/ruby/library/net-http/httpgenericrequest/body_stream_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require "stringio" diff --git a/spec/ruby/library/net/http/httpgenericrequest/exec_spec.rb b/spec/ruby/library/net-http/httpgenericrequest/exec_spec.rb index da5b1a63be..a09f9d5bec 100644 --- a/spec/ruby/library/net/http/httpgenericrequest/exec_spec.rb +++ b/spec/ruby/library/net-http/httpgenericrequest/exec_spec.rb @@ -1,10 +1,10 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require "stringio" describe "Net::HTTPGenericRequest#exec when passed socket, version, path" do before :each do - @socket = StringIO.new("") + @socket = StringIO.new(+"") @buffered_socket = Net::BufferedIO.new(@socket) end @@ -31,18 +31,20 @@ describe "Net::HTTPGenericRequest#exec when passed socket, version, path" do end describe "when a request body is set" do - it "sets the 'Content-Type' header to 'application/x-www-form-urlencoded' unless the 'Content-Type' header is supplied" do - request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path") - request.body = "Some Content" - - request.exec(@buffered_socket, "1.1", "/some/other/path") - str = @socket.string - - str.should =~ %r[POST /some/other/path HTTP/1.1\r\n] - str.should =~ %r[Accept: \*/\*\r\n] - str.should =~ %r[Content-Type: application/x-www-form-urlencoded\r\n] - str.should =~ %r[Content-Length: 12\r\n] - str[-16..-1].should == "\r\n\r\nSome Content" + ruby_version_is ""..."4.0" do + it "sets the 'Content-Type' header to 'application/x-www-form-urlencoded' unless the 'Content-Type' header is supplied" do + request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path") + request.body = "Some Content" + + request.exec(@buffered_socket, "1.1", "/some/other/path") + str = @socket.string + + str.should =~ %r[POST /some/other/path HTTP/1.1\r\n] + str.should =~ %r[Accept: \*/\*\r\n] + str.should =~ %r[Content-Type: application/x-www-form-urlencoded\r\n] + str.should =~ %r[Content-Length: 12\r\n] + str[-16..-1].should == "\r\n\r\nSome Content" + end end it "correctly sets the 'Content-Length' header and includes the body" do @@ -62,19 +64,21 @@ describe "Net::HTTPGenericRequest#exec when passed socket, version, path" do end describe "when a body stream is set" do - it "sets the 'Content-Type' header to 'application/x-www-form-urlencoded' unless the 'Content-Type' header is supplied" do - request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path", - "Content-Length" => "10") - request.body_stream = StringIO.new("a" * 20) - - request.exec(@buffered_socket, "1.1", "/some/other/path") - str = @socket.string - - str.should =~ %r[POST /some/other/path HTTP/1.1\r\n] - str.should =~ %r[Accept: \*/\*\r\n] - str.should =~ %r[Content-Type: application/x-www-form-urlencoded\r\n] - str.should =~ %r[Content-Length: 10\r\n] - str[-24..-1].should == "\r\n\r\naaaaaaaaaaaaaaaaaaaa" + ruby_version_is ""..."4.0" do + it "sets the 'Content-Type' header to 'application/x-www-form-urlencoded' unless the 'Content-Type' header is supplied" do + request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path", + "Content-Length" => "10") + request.body_stream = StringIO.new("a" * 20) + + request.exec(@buffered_socket, "1.1", "/some/other/path") + str = @socket.string + + str.should =~ %r[POST /some/other/path HTTP/1.1\r\n] + str.should =~ %r[Accept: \*/\*\r\n] + str.should =~ %r[Content-Type: application/x-www-form-urlencoded\r\n] + str.should =~ %r[Content-Length: 10\r\n] + str[-24..-1].should == "\r\n\r\naaaaaaaaaaaaaaaaaaaa" + end end it "sends the whole stream, regardless of the 'Content-Length' header" do diff --git a/spec/ruby/library/net/http/httpgenericrequest/inspect_spec.rb b/spec/ruby/library/net-http/httpgenericrequest/inspect_spec.rb index 36240949c3..d03b6e6953 100644 --- a/spec/ruby/library/net/http/httpgenericrequest/inspect_spec.rb +++ b/spec/ruby/library/net-http/httpgenericrequest/inspect_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTPGenericRequest#inspect" do diff --git a/spec/ruby/library/net/http/httpgenericrequest/method_spec.rb b/spec/ruby/library/net-http/httpgenericrequest/method_spec.rb index 3f7c2cbf2b..794bd328cd 100644 --- a/spec/ruby/library/net/http/httpgenericrequest/method_spec.rb +++ b/spec/ruby/library/net-http/httpgenericrequest/method_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTPGenericRequest#method" do diff --git a/spec/ruby/library/net/http/httpgenericrequest/path_spec.rb b/spec/ruby/library/net-http/httpgenericrequest/path_spec.rb index fc4cf9af53..a9fac3f67e 100644 --- a/spec/ruby/library/net/http/httpgenericrequest/path_spec.rb +++ b/spec/ruby/library/net-http/httpgenericrequest/path_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTPGenericRequest#path" do diff --git a/spec/ruby/library/net/http/httpgenericrequest/request_body_permitted_spec.rb b/spec/ruby/library/net-http/httpgenericrequest/request_body_permitted_spec.rb index 50cd1ff637..1713b59baf 100644 --- a/spec/ruby/library/net/http/httpgenericrequest/request_body_permitted_spec.rb +++ b/spec/ruby/library/net-http/httpgenericrequest/request_body_permitted_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTPGenericRequest#request_body_permitted?" do diff --git a/spec/ruby/library/net/http/httpgenericrequest/response_body_permitted_spec.rb b/spec/ruby/library/net-http/httpgenericrequest/response_body_permitted_spec.rb index 0c4165d0ab..2f0751c344 100644 --- a/spec/ruby/library/net/http/httpgenericrequest/response_body_permitted_spec.rb +++ b/spec/ruby/library/net-http/httpgenericrequest/response_body_permitted_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTPGenericRequest#response_body_permitted?" do diff --git a/spec/ruby/library/net/http/httpgenericrequest/set_body_internal_spec.rb b/spec/ruby/library/net-http/httpgenericrequest/set_body_internal_spec.rb index 7494c69173..358aa6cde3 100644 --- a/spec/ruby/library/net/http/httpgenericrequest/set_body_internal_spec.rb +++ b/spec/ruby/library/net-http/httpgenericrequest/set_body_internal_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTPGenericRequest#set_body_internal when passed string" do diff --git a/spec/ruby/library/net/http/httpheader/add_field_spec.rb b/spec/ruby/library/net-http/httpheader/add_field_spec.rb index 882d5ac5bb..8cd3d33517 100644 --- a/spec/ruby/library/net/http/httpheader/add_field_spec.rb +++ b/spec/ruby/library/net-http/httpheader/add_field_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' diff --git a/spec/ruby/library/net/http/httpheader/basic_auth_spec.rb b/spec/ruby/library/net-http/httpheader/basic_auth_spec.rb index fa2a710fe1..db7ca84d13 100644 --- a/spec/ruby/library/net/http/httpheader/basic_auth_spec.rb +++ b/spec/ruby/library/net-http/httpheader/basic_auth_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' diff --git a/spec/ruby/library/net/http/httpheader/canonical_each_spec.rb b/spec/ruby/library/net-http/httpheader/canonical_each_spec.rb index 0dddd3049b..64a5cae89e 100644 --- a/spec/ruby/library/net/http/httpheader/canonical_each_spec.rb +++ b/spec/ruby/library/net-http/httpheader/canonical_each_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' require_relative 'shared/each_capitalized' diff --git a/spec/ruby/library/net/http/httpheader/chunked_spec.rb b/spec/ruby/library/net-http/httpheader/chunked_spec.rb index 96b758981b..b32a0aab38 100644 --- a/spec/ruby/library/net/http/httpheader/chunked_spec.rb +++ b/spec/ruby/library/net-http/httpheader/chunked_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' diff --git a/spec/ruby/library/net/http/httpheader/content_length_spec.rb b/spec/ruby/library/net-http/httpheader/content_length_spec.rb index e344817e82..f05c5f8d8b 100644 --- a/spec/ruby/library/net/http/httpheader/content_length_spec.rb +++ b/spec/ruby/library/net-http/httpheader/content_length_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' diff --git a/spec/ruby/library/net/http/httpheader/content_range_spec.rb b/spec/ruby/library/net-http/httpheader/content_range_spec.rb index ba75f9a9a1..09737141a5 100644 --- a/spec/ruby/library/net/http/httpheader/content_range_spec.rb +++ b/spec/ruby/library/net-http/httpheader/content_range_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' diff --git a/spec/ruby/library/net/http/httpheader/content_type_spec.rb b/spec/ruby/library/net-http/httpheader/content_type_spec.rb index 1f8b4ba326..a6e1ae1093 100644 --- a/spec/ruby/library/net/http/httpheader/content_type_spec.rb +++ b/spec/ruby/library/net-http/httpheader/content_type_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' require_relative 'shared/set_content_type' diff --git a/spec/ruby/library/net/http/httpheader/delete_spec.rb b/spec/ruby/library/net-http/httpheader/delete_spec.rb index 603ae198de..8d929dbd86 100644 --- a/spec/ruby/library/net/http/httpheader/delete_spec.rb +++ b/spec/ruby/library/net-http/httpheader/delete_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' diff --git a/spec/ruby/library/net/http/httpheader/each_capitalized_name_spec.rb b/spec/ruby/library/net-http/httpheader/each_capitalized_name_spec.rb index 1af2c6939c..27713577f9 100644 --- a/spec/ruby/library/net/http/httpheader/each_capitalized_name_spec.rb +++ b/spec/ruby/library/net-http/httpheader/each_capitalized_name_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' diff --git a/spec/ruby/library/net/http/httpheader/each_capitalized_spec.rb b/spec/ruby/library/net-http/httpheader/each_capitalized_spec.rb index 961a2d051f..1e853995ea 100644 --- a/spec/ruby/library/net/http/httpheader/each_capitalized_spec.rb +++ b/spec/ruby/library/net-http/httpheader/each_capitalized_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' require_relative 'shared/each_capitalized' diff --git a/spec/ruby/library/net/http/httpheader/each_header_spec.rb b/spec/ruby/library/net-http/httpheader/each_header_spec.rb index 19634a001b..869feebacf 100644 --- a/spec/ruby/library/net/http/httpheader/each_header_spec.rb +++ b/spec/ruby/library/net-http/httpheader/each_header_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' require_relative 'shared/each_header' diff --git a/spec/ruby/library/net/http/httpheader/each_key_spec.rb b/spec/ruby/library/net-http/httpheader/each_key_spec.rb index ebb17d2eac..1ad145629f 100644 --- a/spec/ruby/library/net/http/httpheader/each_key_spec.rb +++ b/spec/ruby/library/net-http/httpheader/each_key_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' require_relative 'shared/each_name' diff --git a/spec/ruby/library/net/http/httpheader/each_name_spec.rb b/spec/ruby/library/net-http/httpheader/each_name_spec.rb index f4533ebcfb..f819bd989d 100644 --- a/spec/ruby/library/net/http/httpheader/each_name_spec.rb +++ b/spec/ruby/library/net-http/httpheader/each_name_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' require_relative 'shared/each_name' diff --git a/spec/ruby/library/net/http/httpheader/each_spec.rb b/spec/ruby/library/net-http/httpheader/each_spec.rb index 7ba8434f75..ff37249d0a 100644 --- a/spec/ruby/library/net/http/httpheader/each_spec.rb +++ b/spec/ruby/library/net-http/httpheader/each_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' require_relative 'shared/each_header' diff --git a/spec/ruby/library/net/http/httpheader/each_value_spec.rb b/spec/ruby/library/net-http/httpheader/each_value_spec.rb index 3224de7703..b71df58c65 100644 --- a/spec/ruby/library/net/http/httpheader/each_value_spec.rb +++ b/spec/ruby/library/net-http/httpheader/each_value_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' diff --git a/spec/ruby/library/net/http/httpheader/element_reference_spec.rb b/spec/ruby/library/net-http/httpheader/element_reference_spec.rb index 4a35e20d20..1003c41af9 100644 --- a/spec/ruby/library/net/http/httpheader/element_reference_spec.rb +++ b/spec/ruby/library/net-http/httpheader/element_reference_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' diff --git a/spec/ruby/library/net/http/httpheader/element_set_spec.rb b/spec/ruby/library/net-http/httpheader/element_set_spec.rb index e9ad64fafc..376df2f977 100644 --- a/spec/ruby/library/net/http/httpheader/element_set_spec.rb +++ b/spec/ruby/library/net-http/httpheader/element_set_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' diff --git a/spec/ruby/library/net/http/httpheader/fetch_spec.rb b/spec/ruby/library/net-http/httpheader/fetch_spec.rb index ea15679acb..58c69c0377 100644 --- a/spec/ruby/library/net/http/httpheader/fetch_spec.rb +++ b/spec/ruby/library/net-http/httpheader/fetch_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' diff --git a/spec/ruby/library/net/http/httpheader/fixtures/classes.rb b/spec/ruby/library/net-http/httpheader/fixtures/classes.rb index b5ec6abd75..b5ec6abd75 100644 --- a/spec/ruby/library/net/http/httpheader/fixtures/classes.rb +++ b/spec/ruby/library/net-http/httpheader/fixtures/classes.rb diff --git a/spec/ruby/library/net/http/httpheader/form_data_spec.rb b/spec/ruby/library/net-http/httpheader/form_data_spec.rb index 9b29a03159..acd913f53a 100644 --- a/spec/ruby/library/net/http/httpheader/form_data_spec.rb +++ b/spec/ruby/library/net-http/httpheader/form_data_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' require_relative 'shared/set_form_data' diff --git a/spec/ruby/library/net/http/httpheader/get_fields_spec.rb b/spec/ruby/library/net-http/httpheader/get_fields_spec.rb index 1b623bf2a3..0278bcede2 100644 --- a/spec/ruby/library/net/http/httpheader/get_fields_spec.rb +++ b/spec/ruby/library/net-http/httpheader/get_fields_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' diff --git a/spec/ruby/library/net/http/httpheader/initialize_http_header_spec.rb b/spec/ruby/library/net-http/httpheader/initialize_http_header_spec.rb index efc5e7d0b2..f9e6d208e5 100644 --- a/spec/ruby/library/net/http/httpheader/initialize_http_header_spec.rb +++ b/spec/ruby/library/net-http/httpheader/initialize_http_header_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' diff --git a/spec/ruby/library/net/http/httpheader/key_spec.rb b/spec/ruby/library/net-http/httpheader/key_spec.rb index 9099024229..2b7aeb9c2a 100644 --- a/spec/ruby/library/net/http/httpheader/key_spec.rb +++ b/spec/ruby/library/net-http/httpheader/key_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' diff --git a/spec/ruby/library/net/http/httpheader/length_spec.rb b/spec/ruby/library/net-http/httpheader/length_spec.rb index 0d1da149f4..57e32742e4 100644 --- a/spec/ruby/library/net/http/httpheader/length_spec.rb +++ b/spec/ruby/library/net-http/httpheader/length_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' require_relative 'shared/size' diff --git a/spec/ruby/library/net/http/httpheader/main_type_spec.rb b/spec/ruby/library/net-http/httpheader/main_type_spec.rb index 3e18de6b5b..4dd551d8f4 100644 --- a/spec/ruby/library/net/http/httpheader/main_type_spec.rb +++ b/spec/ruby/library/net-http/httpheader/main_type_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' diff --git a/spec/ruby/library/net/http/httpheader/proxy_basic_auth_spec.rb b/spec/ruby/library/net-http/httpheader/proxy_basic_auth_spec.rb index 8b576ee164..d9f6afc5a7 100644 --- a/spec/ruby/library/net/http/httpheader/proxy_basic_auth_spec.rb +++ b/spec/ruby/library/net-http/httpheader/proxy_basic_auth_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' diff --git a/spec/ruby/library/net/http/httpheader/range_length_spec.rb b/spec/ruby/library/net-http/httpheader/range_length_spec.rb index b8fce4f690..77323ac872 100644 --- a/spec/ruby/library/net/http/httpheader/range_length_spec.rb +++ b/spec/ruby/library/net-http/httpheader/range_length_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' diff --git a/spec/ruby/library/net/http/httpheader/range_spec.rb b/spec/ruby/library/net-http/httpheader/range_spec.rb index 005177f6be..2de80a825e 100644 --- a/spec/ruby/library/net/http/httpheader/range_spec.rb +++ b/spec/ruby/library/net-http/httpheader/range_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' require_relative 'shared/set_range' diff --git a/spec/ruby/library/net/http/httpheader/set_content_type_spec.rb b/spec/ruby/library/net-http/httpheader/set_content_type_spec.rb index 125f7a7e0d..7ec4f90b8e 100644 --- a/spec/ruby/library/net/http/httpheader/set_content_type_spec.rb +++ b/spec/ruby/library/net-http/httpheader/set_content_type_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' require_relative 'shared/set_content_type' diff --git a/spec/ruby/library/net/http/httpheader/set_form_data_spec.rb b/spec/ruby/library/net-http/httpheader/set_form_data_spec.rb index 14c66ae01c..7aac19f045 100644 --- a/spec/ruby/library/net/http/httpheader/set_form_data_spec.rb +++ b/spec/ruby/library/net-http/httpheader/set_form_data_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' require_relative 'shared/set_form_data' diff --git a/spec/ruby/library/net/http/httpheader/set_range_spec.rb b/spec/ruby/library/net-http/httpheader/set_range_spec.rb index 85b9c50422..0f98de55e6 100644 --- a/spec/ruby/library/net/http/httpheader/set_range_spec.rb +++ b/spec/ruby/library/net-http/httpheader/set_range_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' require_relative 'shared/set_range' diff --git a/spec/ruby/library/net/http/httpheader/shared/each_capitalized.rb b/spec/ruby/library/net-http/httpheader/shared/each_capitalized.rb index 3bac409876..3bac409876 100644 --- a/spec/ruby/library/net/http/httpheader/shared/each_capitalized.rb +++ b/spec/ruby/library/net-http/httpheader/shared/each_capitalized.rb diff --git a/spec/ruby/library/net/http/httpheader/shared/each_header.rb b/spec/ruby/library/net-http/httpheader/shared/each_header.rb index 6bf3a6ddfe..6bf3a6ddfe 100644 --- a/spec/ruby/library/net/http/httpheader/shared/each_header.rb +++ b/spec/ruby/library/net-http/httpheader/shared/each_header.rb diff --git a/spec/ruby/library/net/http/httpheader/shared/each_name.rb b/spec/ruby/library/net-http/httpheader/shared/each_name.rb index efc6a09dfd..efc6a09dfd 100644 --- a/spec/ruby/library/net/http/httpheader/shared/each_name.rb +++ b/spec/ruby/library/net-http/httpheader/shared/each_name.rb diff --git a/spec/ruby/library/net/http/httpheader/shared/set_content_type.rb b/spec/ruby/library/net-http/httpheader/shared/set_content_type.rb index b7359bdca6..b7359bdca6 100644 --- a/spec/ruby/library/net/http/httpheader/shared/set_content_type.rb +++ b/spec/ruby/library/net-http/httpheader/shared/set_content_type.rb diff --git a/spec/ruby/library/net/http/httpheader/shared/set_form_data.rb b/spec/ruby/library/net-http/httpheader/shared/set_form_data.rb index db20b18803..db20b18803 100644 --- a/spec/ruby/library/net/http/httpheader/shared/set_form_data.rb +++ b/spec/ruby/library/net-http/httpheader/shared/set_form_data.rb diff --git a/spec/ruby/library/net/http/httpheader/shared/set_range.rb b/spec/ruby/library/net-http/httpheader/shared/set_range.rb index 87f51d46f3..87f51d46f3 100644 --- a/spec/ruby/library/net/http/httpheader/shared/set_range.rb +++ b/spec/ruby/library/net-http/httpheader/shared/set_range.rb diff --git a/spec/ruby/library/net/http/httpheader/shared/size.rb b/spec/ruby/library/net-http/httpheader/shared/size.rb index e2b1e4c22b..e2b1e4c22b 100644 --- a/spec/ruby/library/net/http/httpheader/shared/size.rb +++ b/spec/ruby/library/net-http/httpheader/shared/size.rb diff --git a/spec/ruby/library/net/http/httpheader/size_spec.rb b/spec/ruby/library/net-http/httpheader/size_spec.rb index a7d78f96e0..210060ce21 100644 --- a/spec/ruby/library/net/http/httpheader/size_spec.rb +++ b/spec/ruby/library/net-http/httpheader/size_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' require_relative 'shared/size' diff --git a/spec/ruby/library/net/http/httpheader/sub_type_spec.rb b/spec/ruby/library/net-http/httpheader/sub_type_spec.rb index 3c73ca0027..b39b57fe8d 100644 --- a/spec/ruby/library/net/http/httpheader/sub_type_spec.rb +++ b/spec/ruby/library/net-http/httpheader/sub_type_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' diff --git a/spec/ruby/library/net/http/httpheader/to_hash_spec.rb b/spec/ruby/library/net-http/httpheader/to_hash_spec.rb index 8c1d36c30a..3cebc519a6 100644 --- a/spec/ruby/library/net/http/httpheader/to_hash_spec.rb +++ b/spec/ruby/library/net-http/httpheader/to_hash_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' diff --git a/spec/ruby/library/net/http/httpheader/type_params_spec.rb b/spec/ruby/library/net-http/httpheader/type_params_spec.rb index e77be7ea85..ac97e2b48c 100644 --- a/spec/ruby/library/net/http/httpheader/type_params_spec.rb +++ b/spec/ruby/library/net-http/httpheader/type_params_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' diff --git a/spec/ruby/library/net/http/httprequest/initialize_spec.rb b/spec/ruby/library/net-http/httprequest/initialize_spec.rb index 88e9fb1c77..d009a00ed2 100644 --- a/spec/ruby/library/net/http/httprequest/initialize_spec.rb +++ b/spec/ruby/library/net-http/httprequest/initialize_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' module NetHTTPRequestSpecs diff --git a/spec/ruby/library/net/http/httpresponse/body_permitted_spec.rb b/spec/ruby/library/net-http/httpresponse/body_permitted_spec.rb index 8ade46689f..68965de4a1 100644 --- a/spec/ruby/library/net/http/httpresponse/body_permitted_spec.rb +++ b/spec/ruby/library/net-http/httpresponse/body_permitted_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTPResponse.body_permitted?" do diff --git a/spec/ruby/library/net/http/httpresponse/body_spec.rb b/spec/ruby/library/net-http/httpresponse/body_spec.rb index 79569441f1..ddfcd834c4 100644 --- a/spec/ruby/library/net/http/httpresponse/body_spec.rb +++ b/spec/ruby/library/net-http/httpresponse/body_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'shared/body' diff --git a/spec/ruby/library/net/http/httpresponse/code_spec.rb b/spec/ruby/library/net-http/httpresponse/code_spec.rb index 114277cb43..699062ad97 100644 --- a/spec/ruby/library/net/http/httpresponse/code_spec.rb +++ b/spec/ruby/library/net-http/httpresponse/code_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTPResponse#code" do diff --git a/spec/ruby/library/net/http/httpresponse/code_type_spec.rb b/spec/ruby/library/net-http/httpresponse/code_type_spec.rb index fa2d572e9a..beb661cbbe 100644 --- a/spec/ruby/library/net/http/httpresponse/code_type_spec.rb +++ b/spec/ruby/library/net-http/httpresponse/code_type_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTPResponse#code_type" do diff --git a/spec/ruby/library/net/http/httpresponse/entity_spec.rb b/spec/ruby/library/net-http/httpresponse/entity_spec.rb index f1639042c1..ca8c4b29c0 100644 --- a/spec/ruby/library/net/http/httpresponse/entity_spec.rb +++ b/spec/ruby/library/net-http/httpresponse/entity_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'shared/body' diff --git a/spec/ruby/library/net/http/httpresponse/error_spec.rb b/spec/ruby/library/net-http/httpresponse/error_spec.rb index 89f4a47f60..6ced90fa23 100644 --- a/spec/ruby/library/net/http/httpresponse/error_spec.rb +++ b/spec/ruby/library/net-http/httpresponse/error_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTPResponse#error!" do diff --git a/spec/ruby/library/net/http/httpresponse/error_type_spec.rb b/spec/ruby/library/net-http/httpresponse/error_type_spec.rb index 8885b7706b..3969621a5e 100644 --- a/spec/ruby/library/net/http/httpresponse/error_type_spec.rb +++ b/spec/ruby/library/net-http/httpresponse/error_type_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTPResponse#error_type" do diff --git a/spec/ruby/library/net/http/httpresponse/exception_type_spec.rb b/spec/ruby/library/net-http/httpresponse/exception_type_spec.rb index 0c9c11291f..dd2761a744 100644 --- a/spec/ruby/library/net/http/httpresponse/exception_type_spec.rb +++ b/spec/ruby/library/net-http/httpresponse/exception_type_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTPResponse.exception_type" do diff --git a/spec/ruby/library/net/http/httpresponse/header_spec.rb b/spec/ruby/library/net-http/httpresponse/header_spec.rb index a9615feda8..a403dbd2c3 100644 --- a/spec/ruby/library/net/http/httpresponse/header_spec.rb +++ b/spec/ruby/library/net-http/httpresponse/header_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTPResponse#header" do diff --git a/spec/ruby/library/net/http/httpresponse/http_version_spec.rb b/spec/ruby/library/net-http/httpresponse/http_version_spec.rb index db85696d77..a3e413a360 100644 --- a/spec/ruby/library/net/http/httpresponse/http_version_spec.rb +++ b/spec/ruby/library/net-http/httpresponse/http_version_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTPResponse#http_version" do diff --git a/spec/ruby/library/net/http/httpresponse/initialize_spec.rb b/spec/ruby/library/net-http/httpresponse/initialize_spec.rb index eb77e2e277..673c11a245 100644 --- a/spec/ruby/library/net/http/httpresponse/initialize_spec.rb +++ b/spec/ruby/library/net-http/httpresponse/initialize_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTPResponse#initialize when passed http_version, response_code, response_message" do diff --git a/spec/ruby/library/net/http/httpresponse/inspect_spec.rb b/spec/ruby/library/net-http/httpresponse/inspect_spec.rb index 1e1a2c7cc7..43071ec8cd 100644 --- a/spec/ruby/library/net/http/httpresponse/inspect_spec.rb +++ b/spec/ruby/library/net-http/httpresponse/inspect_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require "stringio" diff --git a/spec/ruby/library/net/http/httpresponse/message_spec.rb b/spec/ruby/library/net-http/httpresponse/message_spec.rb index ae8e3678a1..5ba73bb449 100644 --- a/spec/ruby/library/net/http/httpresponse/message_spec.rb +++ b/spec/ruby/library/net-http/httpresponse/message_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTPResponse#message" do diff --git a/spec/ruby/library/net/http/httpresponse/msg_spec.rb b/spec/ruby/library/net-http/httpresponse/msg_spec.rb index 0e5e7eb4aa..04f5836d7a 100644 --- a/spec/ruby/library/net/http/httpresponse/msg_spec.rb +++ b/spec/ruby/library/net-http/httpresponse/msg_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTPResponse#msg" do diff --git a/spec/ruby/library/net/http/httpresponse/read_body_spec.rb b/spec/ruby/library/net-http/httpresponse/read_body_spec.rb index ec9b42f919..4530a26bfc 100644 --- a/spec/ruby/library/net/http/httpresponse/read_body_spec.rb +++ b/spec/ruby/library/net-http/httpresponse/read_body_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require 'stringio' @@ -25,7 +25,7 @@ describe "Net::HTTPResponse#read_body" do describe "when passed a buffer" do it "reads the body to the passed buffer" do @res.reading_body(@socket, true) do - buffer = "" + buffer = +"" @res.read_body(buffer) buffer.should == "test body" end @@ -33,15 +33,15 @@ describe "Net::HTTPResponse#read_body" do it "returns the passed buffer" do @res.reading_body(@socket, true) do - buffer = "" + buffer = +"" @res.read_body(buffer).should equal(buffer) end end it "raises an IOError if called a second time" do @res.reading_body(@socket, true) do - @res.read_body("") - -> { @res.read_body("") }.should raise_error(IOError) + @res.read_body(+"") + -> { @res.read_body(+"") }.should raise_error(IOError) end end end @@ -51,7 +51,7 @@ describe "Net::HTTPResponse#read_body" do @res.reading_body(@socket, true) do yielded = false - buffer = "" + buffer = +"" @res.read_body do |body| yielded = true buffer << body @@ -79,7 +79,7 @@ describe "Net::HTTPResponse#read_body" do describe "when passed buffer and block" do it "raises an ArgumentError" do @res.reading_body(@socket, true) do - -> { @res.read_body("") {} }.should raise_error(ArgumentError) + -> { @res.read_body(+"") {} }.should raise_error(ArgumentError) end end end diff --git a/spec/ruby/library/net/http/httpresponse/read_header_spec.rb b/spec/ruby/library/net-http/httpresponse/read_header_spec.rb index 6af8c6bd6a..3ea4ee834b 100644 --- a/spec/ruby/library/net/http/httpresponse/read_header_spec.rb +++ b/spec/ruby/library/net-http/httpresponse/read_header_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTPResponse#read_header" do diff --git a/spec/ruby/library/net/http/httpresponse/read_new_spec.rb b/spec/ruby/library/net-http/httpresponse/read_new_spec.rb index dc2cdc9621..82f7a47ce8 100644 --- a/spec/ruby/library/net/http/httpresponse/read_new_spec.rb +++ b/spec/ruby/library/net-http/httpresponse/read_new_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require 'stringio' diff --git a/spec/ruby/library/net/http/httpresponse/reading_body_spec.rb b/spec/ruby/library/net-http/httpresponse/reading_body_spec.rb index ebdab891e1..637a2806f8 100644 --- a/spec/ruby/library/net/http/httpresponse/reading_body_spec.rb +++ b/spec/ruby/library/net-http/httpresponse/reading_body_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require "stringio" diff --git a/spec/ruby/library/net/http/httpresponse/response_spec.rb b/spec/ruby/library/net-http/httpresponse/response_spec.rb index f6035f3695..caa0ca2d19 100644 --- a/spec/ruby/library/net/http/httpresponse/response_spec.rb +++ b/spec/ruby/library/net-http/httpresponse/response_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTPResponse#response" do diff --git a/spec/ruby/library/net/http/httpresponse/shared/body.rb b/spec/ruby/library/net-http/httpresponse/shared/body.rb index 618e3936fb..618e3936fb 100644 --- a/spec/ruby/library/net/http/httpresponse/shared/body.rb +++ b/spec/ruby/library/net-http/httpresponse/shared/body.rb diff --git a/spec/ruby/library/net/http/httpresponse/value_spec.rb b/spec/ruby/library/net-http/httpresponse/value_spec.rb index 5cd58316ef..2df8beaa10 100644 --- a/spec/ruby/library/net/http/httpresponse/value_spec.rb +++ b/spec/ruby/library/net-http/httpresponse/value_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTPResponse#value" do diff --git a/spec/ruby/library/net/FTPError_spec.rb b/spec/ruby/library/net/FTPError_spec.rb deleted file mode 100644 index 84128511db..0000000000 --- a/spec/ruby/library/net/FTPError_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require_relative '../../spec_helper' - -ruby_version_is ""..."3.1" do - require 'net/ftp' - - describe "Net::FTPError" do - it "is an Exception" do - Net::FTPError.should < Exception - end - end -end diff --git a/spec/ruby/library/net/FTPPermError_spec.rb b/spec/ruby/library/net/FTPPermError_spec.rb deleted file mode 100644 index 0da35e7d82..0000000000 --- a/spec/ruby/library/net/FTPPermError_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require_relative '../../spec_helper' - -ruby_version_is ""..."3.1" do - require 'net/ftp' - - describe "Net::FTPPermError" do - it "is an Exception" do - Net::FTPPermError.should < Exception - end - - it "is a subclass of Net::FTPError" do - Net::FTPPermError.should < Net::FTPError - end - end -end diff --git a/spec/ruby/library/net/FTPProtoError_spec.rb b/spec/ruby/library/net/FTPProtoError_spec.rb deleted file mode 100644 index 20e30dd2dd..0000000000 --- a/spec/ruby/library/net/FTPProtoError_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require_relative '../../spec_helper' - -ruby_version_is ""..."3.1" do - require 'net/ftp' - - describe "Net::FTPProtoError" do - it "is an Exception" do - Net::FTPProtoError.should < Exception - end - - it "is a subclass of Net::FTPError" do - Net::FTPPermError.should < Net::FTPError - end - end -end diff --git a/spec/ruby/library/net/FTPReplyError_spec.rb b/spec/ruby/library/net/FTPReplyError_spec.rb deleted file mode 100644 index cc774aabe5..0000000000 --- a/spec/ruby/library/net/FTPReplyError_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require_relative '../../spec_helper' - -ruby_version_is ""..."3.1" do - require 'net/ftp' - - describe "Net::FTPReplyError" do - it "is an Exception" do - Net::FTPReplyError.should < Exception - end - - it "is a subclass of Net::FTPError" do - Net::FTPPermError.should < Net::FTPError - end - end -end diff --git a/spec/ruby/library/net/FTPTempError_spec.rb b/spec/ruby/library/net/FTPTempError_spec.rb deleted file mode 100644 index e2fbdfd842..0000000000 --- a/spec/ruby/library/net/FTPTempError_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require_relative '../../spec_helper' - -ruby_version_is ""..."3.1" do - require 'net/ftp' - - describe "Net::FTPTempError" do - it "is an Exception" do - Net::FTPTempError.should < Exception - end - - it "is a subclass of Net::FTPError" do - Net::FTPPermError.should < Net::FTPError - end - end -end diff --git a/spec/ruby/library/net/ftp/abort_spec.rb b/spec/ruby/library/net/ftp/abort_spec.rb deleted file mode 100644 index ebdfed4b16..0000000000 --- a/spec/ruby/library/net/ftp/abort_spec.rb +++ /dev/null @@ -1,65 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - require_relative 'fixtures/server' - - describe "Net::FTP#abort" do - before :each do - @server = NetFTPSpecs::DummyFTP.new - @server.serve_once - - @ftp = Net::FTP.new - @ftp.connect(@server.hostname, @server.server_port) - end - - after :each do - @ftp.quit rescue nil - @ftp.close - @server.stop - end - - it "sends the ABOR command to the server" do - -> { @ftp.abort }.should_not raise_error - end - - it "ignores the response" do - @ftp.abort - @ftp.last_response.should == "220 Dummy FTP Server ready!\n" - end - - it "returns the full response" do - @ftp.abort.should == "226 Closing data connection. (ABOR)\n" - end - - it "does not raise any error when the response code is 225" do - @server.should_receive(:abor).and_respond("225 Data connection open; no transfer in progress.") - -> { @ftp.abort }.should_not raise_error - end - - it "does not raise any error when the response code is 226" do - @server.should_receive(:abor).and_respond("226 Closing data connection.") - -> { @ftp.abort }.should_not raise_error - end - - it "raises a Net::FTPProtoError when the response code is 500" do - @server.should_receive(:abor).and_respond("500 Syntax error, command unrecognized.") - -> { @ftp.abort }.should raise_error(Net::FTPProtoError) - end - - it "raises a Net::FTPProtoError when the response code is 501" do - @server.should_receive(:abor).and_respond("501 Syntax error in parameters or arguments.") - -> { @ftp.abort }.should raise_error(Net::FTPProtoError) - end - - it "raises a Net::FTPProtoError when the response code is 502" do - @server.should_receive(:abor).and_respond("502 Command not implemented.") - -> { @ftp.abort }.should raise_error(Net::FTPProtoError) - end - - it "raises a Net::FTPProtoError when the response code is 421" do - @server.should_receive(:abor).and_respond("421 Service not available, closing control connection.") - -> { @ftp.abort }.should raise_error(Net::FTPProtoError) - end - end -end diff --git a/spec/ruby/library/net/ftp/acct_spec.rb b/spec/ruby/library/net/ftp/acct_spec.rb deleted file mode 100644 index a960ae20a4..0000000000 --- a/spec/ruby/library/net/ftp/acct_spec.rb +++ /dev/null @@ -1,61 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - require_relative 'fixtures/server' - - describe "Net::FTP#acct" do - before :each do - @server = NetFTPSpecs::DummyFTP.new - @server.serve_once - - @ftp = Net::FTP.new - @ftp.connect(@server.hostname, @server.server_port) - end - - after :each do - @ftp.quit rescue nil - @ftp.close - @server.stop - end - - it "writes the ACCT command to the server" do - @ftp.acct("my_account") - @ftp.last_response.should == "230 User 'my_account' logged in, proceed. (ACCT)\n" - end - - it "returns nil" do - @ftp.acct("my_account").should == nil - end - - it "does not raise any error when the response code is 230" do - @server.should_receive(:acct).and_respond("230 User logged in, proceed.") - -> { @ftp.acct("my_account") }.should_not raise_error - end - - it "raises a Net::FTPPermError when the response code is 530" do - @server.should_receive(:acct).and_respond("530 Not logged in.") - -> { @ftp.acct("my_account") }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPPermError when the response code is 500" do - @server.should_receive(:acct).and_respond("500 Syntax error, command unrecognized.") - -> { @ftp.acct("my_account") }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPPermError when the response code is 501" do - @server.should_receive(:acct).and_respond("501 Syntax error in parameters or arguments.") - -> { @ftp.acct("my_account") }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPPermError when the response code is 503" do - @server.should_receive(:acct).and_respond("503 Bad sequence of commands.") - -> { @ftp.acct("my_account") }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPTempError when the response code is 421" do - @server.should_receive(:acct).and_respond("421 Service not available, closing control connection.") - -> { @ftp.acct("my_account") }.should raise_error(Net::FTPTempError) - end - end -end diff --git a/spec/ruby/library/net/ftp/binary_spec.rb b/spec/ruby/library/net/ftp/binary_spec.rb deleted file mode 100644 index da7e2d6c14..0000000000 --- a/spec/ruby/library/net/ftp/binary_spec.rb +++ /dev/null @@ -1,27 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - - describe "Net::FTP#binary" do - it "returns true when self is in binary mode" do - ftp = Net::FTP.new - ftp.binary.should be_true - - ftp.binary = false - ftp.binary.should be_false - end - end - - describe "Net::FTP#binary=" do - it "sets self to binary mode when passed true" do - ftp = Net::FTP.new - - ftp.binary = true - ftp.binary.should be_true - - ftp.binary = false - ftp.binary.should be_false - end - end -end diff --git a/spec/ruby/library/net/ftp/chdir_spec.rb b/spec/ruby/library/net/ftp/chdir_spec.rb deleted file mode 100644 index 741c3c845e..0000000000 --- a/spec/ruby/library/net/ftp/chdir_spec.rb +++ /dev/null @@ -1,102 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - require_relative 'fixtures/server' - - describe "Net::FTP#chdir" do - before :each do - @server = NetFTPSpecs::DummyFTP.new - @server.serve_once - - @ftp = Net::FTP.new - @ftp.connect(@server.hostname, @server.server_port) - end - - after :each do - @ftp.quit rescue nil - @ftp.close - @server.stop - end - - describe "when switching to the parent directory" do - it "sends the 'CDUP' command to the server" do - @ftp.chdir("..") - @ftp.last_response.should == "200 Command okay. (CDUP)\n" - end - - it "returns nil" do - @ftp.chdir("..").should be_nil - end - - it "does not raise a Net::FTPPermError when the response code is 500" do - @server.should_receive(:cdup).and_respond("500 Syntax error, command unrecognized.") - -> { @ftp.chdir("..") }.should_not raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPPermError when the response code is 501" do - @server.should_receive(:cdup).and_respond("501 Syntax error in parameters or arguments.") - -> { @ftp.chdir("..") }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPPermError when the response code is 502" do - @server.should_receive(:cdup).and_respond("502 Command not implemented.") - -> { @ftp.chdir("..") }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPTempError when the response code is 421" do - @server.should_receive(:cdup).and_respond("421 Service not available, closing control connection.") - -> { @ftp.chdir("..") }.should raise_error(Net::FTPTempError) - end - - it "raises a Net::FTPPermError when the response code is 530" do - @server.should_receive(:cdup).and_respond("530 Not logged in.") - -> { @ftp.chdir("..") }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPPermError when the response code is 550" do - @server.should_receive(:cdup).and_respond("550 Requested action not taken.") - -> { @ftp.chdir("..") }.should raise_error(Net::FTPPermError) - end - end - - it "writes the 'CWD' command with the passed directory to the socket" do - @ftp.chdir("test") - @ftp.last_response.should == "200 Command okay. (CWD test)\n" - end - - it "returns nil" do - @ftp.chdir("test").should be_nil - end - - it "raises a Net::FTPPermError when the response code is 500" do - @server.should_receive(:cwd).and_respond("500 Syntax error, command unrecognized.") - -> { @ftp.chdir("test") }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPPermError when the response code is 501" do - @server.should_receive(:cwd).and_respond("501 Syntax error in parameters or arguments.") - -> { @ftp.chdir("test") }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPPermError when the response code is 502" do - @server.should_receive(:cwd).and_respond("502 Command not implemented.") - -> { @ftp.chdir("test") }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPTempError when the response code is 421" do - @server.should_receive(:cwd).and_respond("421 Service not available, closing control connection.") - -> { @ftp.chdir("test") }.should raise_error(Net::FTPTempError) - end - - it "raises a Net::FTPPermError when the response code is 530" do - @server.should_receive(:cwd).and_respond("530 Not logged in.") - -> { @ftp.chdir("test") }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPPermError when the response code is 550" do - @server.should_receive(:cwd).and_respond("550 Requested action not taken.") - -> { @ftp.chdir("test") }.should raise_error(Net::FTPPermError) - end - end -end diff --git a/spec/ruby/library/net/ftp/close_spec.rb b/spec/ruby/library/net/ftp/close_spec.rb deleted file mode 100644 index 49cdf4dea7..0000000000 --- a/spec/ruby/library/net/ftp/close_spec.rb +++ /dev/null @@ -1,33 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - - describe "Net::FTP#close" do - before :each do - @socket = mock("Socket") - @socket.stub!(:closed?).and_return(false) - @socket.stub!(:read_timeout).and_return(60) - @socket.stub!(:read_timeout=).and_return(3) - - @ftp = Net::FTP.new - @ftp.instance_variable_set(:@sock, @socket) - end - - it "closes the socket" do - @socket.should_receive(:close) - @ftp.close.should be_nil - end - - it "does not try to close the socket if it has already been closed" do - @socket.should_receive(:closed?).and_return(true) - @socket.should_not_receive(:close) - @ftp.close.should be_nil - end - - it "does not try to close the socket if it is nil" do - @ftp.instance_variable_set(:@sock, nil) - @ftp.close.should be_nil - end - end -end diff --git a/spec/ruby/library/net/ftp/closed_spec.rb b/spec/ruby/library/net/ftp/closed_spec.rb deleted file mode 100644 index a81917090a..0000000000 --- a/spec/ruby/library/net/ftp/closed_spec.rb +++ /dev/null @@ -1,24 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - - describe "Net::FTP#closed?" do - before :each do - @socket = mock("Socket") - - @ftp = Net::FTP.new - @ftp.instance_variable_set(:@sock, @socket) - end - - it "returns true when the socket is closed" do - @socket.should_receive(:closed?).and_return(true) - @ftp.closed?.should be_true - end - - it "returns true when the socket is nil" do - @ftp.instance_variable_set(:@sock, nil) - @ftp.closed?.should be_true - end - end -end diff --git a/spec/ruby/library/net/ftp/connect_spec.rb b/spec/ruby/library/net/ftp/connect_spec.rb deleted file mode 100644 index b45e46c530..0000000000 --- a/spec/ruby/library/net/ftp/connect_spec.rb +++ /dev/null @@ -1,52 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - require_relative 'fixtures/server' - - # TODO: Add specs for using the SOCKSSocket - describe "Net::FTP#connect" do - before :each do - @server = NetFTPSpecs::DummyFTP.new - @server.serve_once - - @ftp = Net::FTP.new - end - - after :each do - @server.connect_message = nil - @ftp.quit rescue nil - @ftp.close - @server.stop - end - - it "tries to connect to the FTP Server on the given host and port" do - -> { @ftp.connect(@server.hostname, @server.server_port) }.should_not raise_error - end - - it "returns nil" do - @ftp.connect(@server.hostname, @server.server_port).should be_nil - end - - it "prints a small debug line when in debug mode" do - @ftp.debug_mode = true - -> { @ftp.connect(@server.hostname, @server.server_port) }.should output(/#{"connect: "}#{@server.hostname}#{", "}#{@server.server_port}#{"\\nget: 220 Dummy FTP Server ready!"}/) - @ftp.debug_mode = false - end - - it "does not raise any error when the response code is 220" do - @server.connect_message = "220 Dummy FTP Server ready!" - -> { @ftp.connect(@server.hostname, @server.server_port) }.should_not raise_error - end - - it "raises a Net::FTPReplyError when the response code is 120" do - @server.connect_message = "120 Service ready in nnn minutes." - -> { @ftp.connect(@server.hostname, @server.server_port) }.should raise_error(Net::FTPReplyError) - end - - it "raises a Net::FTPTempError when the response code is 421" do - @server.connect_message = "421 Service not available, closing control connection." - -> { @ftp.connect(@server.hostname, @server.server_port) }.should raise_error(Net::FTPTempError) - end - end -end diff --git a/spec/ruby/library/net/ftp/debug_mode_spec.rb b/spec/ruby/library/net/ftp/debug_mode_spec.rb deleted file mode 100644 index 46d207bbea..0000000000 --- a/spec/ruby/library/net/ftp/debug_mode_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - - describe "Net::FTP#debug_mode" do - it "returns true when self is in debug mode" do - ftp = Net::FTP.new - ftp.debug_mode.should be_false - - ftp.debug_mode = true - ftp.debug_mode.should be_true - end - end - - describe "Net::FTP#debug_mode=" do - it "sets self into debug mode when passed true" do - ftp = Net::FTP.new - ftp.debug_mode = true - ftp.debug_mode.should be_true - - ftp.debug_mode = false - ftp.debug_mode.should be_false - end - end -end diff --git a/spec/ruby/library/net/ftp/default_passive_spec.rb b/spec/ruby/library/net/ftp/default_passive_spec.rb deleted file mode 100644 index 9348d3294d..0000000000 --- a/spec/ruby/library/net/ftp/default_passive_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - - describe "Net::FTP#default_passive" do - it "is true by default" do - ruby_exe(fixture(__FILE__, "default_passive.rb")).should == "true\ntrue\n" - end - end -end diff --git a/spec/ruby/library/net/ftp/delete_spec.rb b/spec/ruby/library/net/ftp/delete_spec.rb deleted file mode 100644 index 43bfcc1541..0000000000 --- a/spec/ruby/library/net/ftp/delete_spec.rb +++ /dev/null @@ -1,62 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - require_relative 'fixtures/server' - - describe "Net::FTP#delete" do - before :each do - @server = NetFTPSpecs::DummyFTP.new - @server.serve_once - - @ftp = Net::FTP.new - @ftp.connect(@server.hostname, @server.server_port) - end - - after :each do - @ftp.quit rescue nil - @ftp.close - @server.stop - end - - it "sends the DELE command with the passed filename to the server" do - @ftp.delete("test.file") - @ftp.last_response.should == "250 Requested file action okay, completed. (DELE test.file)\n" - end - - it "raises a Net::FTPTempError when the response code is 450" do - @server.should_receive(:dele).and_respond("450 Requested file action not taken.") - -> { @ftp.delete("test.file") }.should raise_error(Net::FTPTempError) - end - - it "raises a Net::FTPPermError when the response code is 550" do - @server.should_receive(:dele).and_respond("550 Requested action not taken.") - -> { @ftp.delete("test.file") }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPPermError when the response code is 500" do - @server.should_receive(:dele).and_respond("500 Syntax error, command unrecognized.") - -> { @ftp.delete("test.file") }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPPermError when the response code is 501" do - @server.should_receive(:dele).and_respond("501 Syntax error in parameters or arguments.") - -> { @ftp.delete("test.file") }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPPermError when the response code is 502" do - @server.should_receive(:dele).and_respond("502 Command not implemented.") - -> { @ftp.delete("test.file") }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPTempError when the response code is 421" do - @server.should_receive(:dele).and_respond("421 Service not available, closing control connection.") - -> { @ftp.delete("test.file") }.should raise_error(Net::FTPTempError) - end - - it "raises a Net::FTPPermError when the response code is 530" do - @server.should_receive(:dele).and_respond("530 Not logged in.") - -> { @ftp.delete("test.file") }.should raise_error(Net::FTPPermError) - end - end -end diff --git a/spec/ruby/library/net/ftp/dir_spec.rb b/spec/ruby/library/net/ftp/dir_spec.rb deleted file mode 100644 index dce50a5ac5..0000000000 --- a/spec/ruby/library/net/ftp/dir_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - require_relative 'fixtures/server' - require_relative 'shared/list' - - describe "Net::FTP#dir" do - it_behaves_like :net_ftp_list, :dir - end -end diff --git a/spec/ruby/library/net/ftp/get_spec.rb b/spec/ruby/library/net/ftp/get_spec.rb deleted file mode 100644 index 892b30061c..0000000000 --- a/spec/ruby/library/net/ftp/get_spec.rb +++ /dev/null @@ -1,24 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - require_relative 'fixtures/server' - require_relative 'shared/gettextfile' - require_relative 'shared/getbinaryfile' - - describe "Net::FTP#get (binary mode)" do - before :each do - @binary_mode = true - end - - it_behaves_like :net_ftp_getbinaryfile, :get - end - - describe "Net::FTP#get (text mode)" do - before :each do - @binary_mode = false - end - - it_behaves_like :net_ftp_gettextfile, :get - end -end diff --git a/spec/ruby/library/net/ftp/getbinaryfile_spec.rb b/spec/ruby/library/net/ftp/getbinaryfile_spec.rb deleted file mode 100644 index c5abdd67e7..0000000000 --- a/spec/ruby/library/net/ftp/getbinaryfile_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - require_relative 'fixtures/server' - require_relative 'shared/getbinaryfile' - - describe "Net::FTP#getbinaryfile" do - it_behaves_like :net_ftp_getbinaryfile, :getbinaryfile - end -end diff --git a/spec/ruby/library/net/ftp/getdir_spec.rb b/spec/ruby/library/net/ftp/getdir_spec.rb deleted file mode 100644 index 8f6fca5bfb..0000000000 --- a/spec/ruby/library/net/ftp/getdir_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - require_relative 'shared/pwd' - - describe "Net::FTP#getdir" do - it_behaves_like :net_ftp_pwd, :getdir - end -end diff --git a/spec/ruby/library/net/ftp/gettextfile_spec.rb b/spec/ruby/library/net/ftp/gettextfile_spec.rb deleted file mode 100644 index e272ae73b1..0000000000 --- a/spec/ruby/library/net/ftp/gettextfile_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - require_relative 'fixtures/server' - require_relative 'shared/gettextfile' - - describe "Net::FTP#gettextfile" do - it_behaves_like :net_ftp_gettextfile, :gettextfile - end -end diff --git a/spec/ruby/library/net/ftp/help_spec.rb b/spec/ruby/library/net/ftp/help_spec.rb deleted file mode 100644 index 9b15f42ede..0000000000 --- a/spec/ruby/library/net/ftp/help_spec.rb +++ /dev/null @@ -1,69 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - require_relative 'fixtures/server' - - describe "Net::FTP#help" do - def with_connection - yield - end - - before :each do - @server = NetFTPSpecs::DummyFTP.new - @server.serve_once - - @ftp = Net::FTP.new - @ftp.connect(@server.hostname, @server.server_port) - end - - after :each do - @ftp.quit rescue nil - @ftp.close - @server.stop - end - - it "writes the HELP command to the server" do - @ftp.help - @ftp.last_response.should == "211 System status, or system help reply. (HELP)\n" - end - - it "returns the server's response" do - @ftp.help.should == "211 System status, or system help reply. (HELP)\n" - end - - it "writes the HELP command with an optional parameter to the socket" do - @ftp.help("some parameter").should == "211 System status, or system help reply. (HELP some parameter)\n" - end - - it "does not raise any error when the response code is 211" do - @server.should_receive(:help).and_respond("211 System status, or system help reply.") - -> { @ftp.help }.should_not raise_error - end - - it "does not raise any error when the response code is 214" do - @server.should_receive(:help).and_respond("214 Help message.") - -> { @ftp.help }.should_not raise_error - end - - it "raises a Net::FTPPermError when the response code is 500" do - @server.should_receive(:help).and_respond("500 Syntax error, command unrecognized.") - -> { @ftp.help }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPPermError when the response code is 501" do - @server.should_receive(:help).and_respond("501 Syntax error in parameters or arguments.") - -> { @ftp.help }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPPermError when the response code is 502" do - @server.should_receive(:help).and_respond("502 Command not implemented.") - -> { @ftp.help }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPTempError when the response code is 421" do - @server.should_receive(:help).and_respond("421 Service not available, closing control connection.") - -> { @ftp.help }.should raise_error(Net::FTPTempError) - end - end -end diff --git a/spec/ruby/library/net/ftp/initialize_spec.rb b/spec/ruby/library/net/ftp/initialize_spec.rb deleted file mode 100644 index 80f71a9161..0000000000 --- a/spec/ruby/library/net/ftp/initialize_spec.rb +++ /dev/null @@ -1,408 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - - describe "Net::FTP#initialize" do - before :each do - @ftp = Net::FTP.allocate - @ftp.stub!(:connect) - @port_args = [] - @port_args << 21 - end - - it "is private" do - Net::FTP.should have_private_instance_method(:initialize) - end - - it "sets self into binary mode" do - @ftp.binary.should be_nil - @ftp.send(:initialize) - @ftp.binary.should be_true - end - - it "sets self into active mode" do - @ftp.passive.should be_nil - @ftp.send(:initialize) - @ftp.passive.should be_false - end - - it "sets self into non-debug mode" do - @ftp.debug_mode.should be_nil - @ftp.send(:initialize) - @ftp.debug_mode.should be_false - end - - it "sets self to not resume file uploads/downloads" do - @ftp.resume.should be_nil - @ftp.send(:initialize) - @ftp.resume.should be_false - end - - describe "when passed no arguments" do - it "does not try to connect" do - @ftp.should_not_receive(:connect) - @ftp.send(:initialize) - end - end - - describe "when passed host" do - it "tries to connect to the passed host" do - @ftp.should_receive(:connect).with("localhost", *@port_args) - @ftp.send(:initialize, "localhost") - end - end - - describe "when passed host, user" do - it "tries to connect to the passed host" do - @ftp.should_receive(:connect).with("localhost", *@port_args) - @ftp.send(:initialize, "localhost") - end - - it "tries to login with the passed username" do - @ftp.should_receive(:login).with("rubyspec", nil, nil) - @ftp.send(:initialize, "localhost", "rubyspec") - end - end - - describe "when passed host, user, password" do - it "tries to connect to the passed host" do - @ftp.should_receive(:connect).with("localhost", *@port_args) - @ftp.send(:initialize, "localhost") - end - - it "tries to login with the passed username and password" do - @ftp.should_receive(:login).with("rubyspec", "rocks", nil) - @ftp.send(:initialize, "localhost", "rubyspec", "rocks") - end - end - - describe "when passed host, user" do - it "tries to connect to the passed host" do - @ftp.should_receive(:connect).with("localhost", *@port_args) - @ftp.send(:initialize, "localhost") - end - - it "tries to login with the passed username, password and account" do - @ftp.should_receive(:login).with("rubyspec", "rocks", "account") - @ftp.send(:initialize, "localhost", "rubyspec", "rocks", "account") - end - end - - before :each do - @ftp.stub!(:login) - end - - describe 'when the host' do - describe 'is set' do - describe 'and port option' do - describe 'is set' do - it 'tries to connect to the host on the specified port' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ port: 8080 }) - @ftp.should_receive(:connect).with('localhost', 8080) - - @ftp.send(:initialize, 'localhost', options) - end - end - - describe 'is not set' do - it 'tries to connect to the host without a port' do - @ftp.should_receive(:connect).with("localhost", *@port_args) - - @ftp.send(:initialize, 'localhost') - end - end - end - - describe 'when the username option' do - describe 'is set' do - describe 'and the password option' do - describe 'is set' do - describe 'and the account option' do - describe 'is set' do - it 'tries to log in with the supplied parameters' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ username: 'a', password: 'topsecret', account: 'b' }) - @ftp.should_receive(:login).with('a', 'topsecret', 'b') - - @ftp.send(:initialize, 'localhost', options) - end - end - - describe 'is unset' do - it 'tries to log in with the supplied parameters' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ username: 'a', password: 'topsecret' }) - @ftp.should_receive(:login).with('a', 'topsecret', nil) - - @ftp.send(:initialize, 'localhost', options) - end - end - end - end - - describe 'is unset' do - describe 'and the account option' do - describe 'is set' do - it 'tries to log in with the supplied parameters' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ username: 'a', account: 'b' }) - @ftp.should_receive(:login).with('a', nil, 'b') - - @ftp.send(:initialize, 'localhost', options) - end - end - - describe 'is unset' do - it 'tries to log in with the supplied parameters' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ username: 'a'}) - @ftp.should_receive(:login).with('a', nil, nil) - - @ftp.send(:initialize, 'localhost', options) - end - end - end - end - end - end - - describe 'is not set' do - it 'does not try to log in' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({}) - @ftp.should_not_receive(:login) - - @ftp.send(:initialize, 'localhost', options) - end - end - end - end - - describe 'is unset' do - it 'does not try to connect' do - @ftp.should_not_receive(:connect) - - @ftp.send(:initialize) - end - - it 'does not try to log in' do - @ftp.should_not_receive(:login) - - @ftp.send(:initialize) - end - end - end - - describe 'when the passive option' do - describe 'is set' do - describe 'to true' do - it 'sets passive to true' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ passive: true }) - - @ftp.send(:initialize, nil, options) - @ftp.passive.should == true - end - end - - describe 'to false' do - it 'sets passive to false' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ passive: false }) - - @ftp.send(:initialize, nil, options) - @ftp.passive.should == false - end - end - end - - describe 'is unset' do - it 'sets passive to false' do - @ftp.send(:initialize) - @ftp.passive.should == false - end - end - end - - describe 'when the debug_mode option' do - describe 'is set' do - describe 'to true' do - it 'sets debug_mode to true' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ debug_mode: true }) - - @ftp.send(:initialize, nil, options) - @ftp.debug_mode.should == true - end - end - - describe 'to false' do - it 'sets debug_mode to false' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ debug_mode: false }) - - @ftp.send(:initialize, nil, options) - @ftp.debug_mode.should == false - end - end - end - - describe 'is unset' do - it 'sets debug_mode to false' do - @ftp.send(:initialize) - @ftp.debug_mode.should == false - end - end - end - - describe 'when the open_timeout option' do - describe 'is set' do - it 'sets open_timeout to the specified value' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ open_timeout: 42 }) - - @ftp.send(:initialize, nil, options) - @ftp.open_timeout.should == 42 - end - end - - describe 'is not set' do - it 'sets open_timeout to nil' do - @ftp.send(:initialize) - @ftp.open_timeout.should == nil - end - end - end - - describe 'when the read_timeout option' do - describe 'is set' do - it 'sets read_timeout to the specified value' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ read_timeout: 100 }) - - @ftp.send(:initialize, nil, options) - @ftp.read_timeout.should == 100 - end - end - - describe 'is not set' do - it 'sets read_timeout to the default value' do - @ftp.send(:initialize) - @ftp.read_timeout.should == 60 - end - end - end - - describe 'when the ssl_handshake_timeout option' do - describe 'is set' do - it 'sets ssl_handshake_timeout to the specified value' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ ssl_handshake_timeout: 23 }) - - @ftp.send(:initialize, nil, options) - @ftp.ssl_handshake_timeout.should == 23 - end - end - - describe 'is not set' do - it 'sets ssl_handshake_timeout to nil' do - @ftp.send(:initialize) - @ftp.ssl_handshake_timeout.should == nil - end - end - end - - describe 'when the ssl option' do - describe 'is set' do - describe "and the ssl option's value is true" do - it 'initializes ssl_context to a blank SSLContext object' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ ssl: true }) - - ssl_context = OpenSSL::SSL::SSLContext.allocate - ssl_context.stub!(:set_params) - - OpenSSL::SSL::SSLContext.should_receive(:new).and_return(ssl_context) - ssl_context.should_receive(:set_params).with({}) - - @ftp.send(:initialize, nil, options) - @ftp.instance_variable_get(:@ssl_context).should == ssl_context - end - end - - describe "and the ssl option's value is a hash" do - it 'initializes ssl_context to a configured SSLContext object' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ ssl: {key: 'value'} }) - - ssl_context = OpenSSL::SSL::SSLContext.allocate - ssl_context.stub!(:set_params) - - OpenSSL::SSL::SSLContext.should_receive(:new).and_return(ssl_context) - ssl_context.should_receive(:set_params).with({key: 'value'}) - - @ftp.send(:initialize, nil, options) - @ftp.instance_variable_get(:@ssl_context).should == ssl_context - end - end - - describe 'and private_data_connection' do - describe 'is set' do - it 'sets private_data_connection to that value' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ ssl: true, private_data_connection: 'true' }) - - @ftp.send(:initialize, nil, options) - @ftp.instance_variable_get(:@private_data_connection).should == 'true' - end - end - - describe 'is not set' do - it 'sets private_data_connection to nil' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ ssl: true }) - - @ftp.send(:initialize, nil, options) - @ftp.instance_variable_get(:@private_data_connection).should == true - end - end - end - end - - describe 'is not set' do - it 'sets ssl_context to nil' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({}) - - @ftp.send(:initialize, nil, options) - @ftp.instance_variable_get(:@ssl_context).should == nil - end - - describe 'private_data_connection' do - describe 'is set' do - it 'raises an ArgumentError' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ private_data_connection: true }) - - -> { - @ftp.send(:initialize, nil, options) - }.should raise_error(ArgumentError, /private_data_connection can be set to true only when ssl is enabled/) - end - end - - describe 'is not set' do - it 'sets private_data_connection to false' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({}) - - @ftp.send(:initialize, nil, options) - @ftp.instance_variable_get(:@private_data_connection).should == false - end - end - end - end - end - end -end diff --git a/spec/ruby/library/net/ftp/last_response_code_spec.rb b/spec/ruby/library/net/ftp/last_response_code_spec.rb deleted file mode 100644 index 86f2b9a695..0000000000 --- a/spec/ruby/library/net/ftp/last_response_code_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - require_relative 'shared/last_response_code' - require_relative 'fixtures/server' - - describe "Net::FTP#last_response_code" do - it_behaves_like :net_ftp_last_response_code, :last_response_code - end -end diff --git a/spec/ruby/library/net/ftp/last_response_spec.rb b/spec/ruby/library/net/ftp/last_response_spec.rb deleted file mode 100644 index 1d29b9b73f..0000000000 --- a/spec/ruby/library/net/ftp/last_response_spec.rb +++ /dev/null @@ -1,28 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - require_relative 'fixtures/server' - - describe "Net::FTP#last_response" do - before :each do - @server = NetFTPSpecs::DummyFTP.new - @server.serve_once - - @ftp = Net::FTP.new - @ftp.connect(@server.hostname, @server.server_port) - end - - after :each do - @ftp.quit rescue nil - @ftp.close - @server.stop - end - - it "returns the last response" do - @ftp.last_response.should == "220 Dummy FTP Server ready!\n" - @ftp.help - @ftp.last_response.should == "211 System status, or system help reply. (HELP)\n" - end - end -end diff --git a/spec/ruby/library/net/ftp/lastresp_spec.rb b/spec/ruby/library/net/ftp/lastresp_spec.rb deleted file mode 100644 index 9d26efb8f8..0000000000 --- a/spec/ruby/library/net/ftp/lastresp_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - require_relative 'shared/last_response_code' - require_relative 'fixtures/server' - - describe "Net::FTP#lastresp" do - it_behaves_like :net_ftp_last_response_code, :lastresp - end -end diff --git a/spec/ruby/library/net/ftp/list_spec.rb b/spec/ruby/library/net/ftp/list_spec.rb deleted file mode 100644 index 6cffafeb4f..0000000000 --- a/spec/ruby/library/net/ftp/list_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - require_relative 'fixtures/server' - require_relative 'shared/list' - - describe "Net::FTP#list" do - it_behaves_like :net_ftp_list, :list - end -end diff --git a/spec/ruby/library/net/ftp/login_spec.rb b/spec/ruby/library/net/ftp/login_spec.rb deleted file mode 100644 index 981b439082..0000000000 --- a/spec/ruby/library/net/ftp/login_spec.rb +++ /dev/null @@ -1,198 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - require_relative 'fixtures/server' - - describe "Net::FTP#login" do - before :each do - @server = NetFTPSpecs::DummyFTP.new - @server.serve_once - - @ftp = Net::FTP.new - @ftp.connect(@server.hostname, @server.server_port) - end - - after :each do - @ftp.quit rescue nil - @ftp.close - @server.stop - end - - describe "when passed no arguments" do - it "sends the USER command with 'anonymous' as name to the server" do - @ftp.login - @server.login_user.should == "anonymous" - end - - it "sends 'anonymous@' as a password when required" do - @server.should_receive(:user).and_respond("331 User name okay, need password.") - @ftp.login - @server.login_pass.should == "anonymous@" - end - - it "raises a Net::FTPReplyError when the server requests an account" do - @server.should_receive(:user).and_respond("331 User name okay, need password.") - @server.should_receive(:pass).and_respond("332 Need account for login.") - -> { @ftp.login }.should raise_error(Net::FTPReplyError) - end - end - - describe "when passed name" do - it "sends the USER command with the passed name to the server" do - @ftp.login("rubyspec") - @server.login_user.should == "rubyspec" - end - - it "raises a Net::FTPReplyError when the server requests a password, but none was given" do - @server.should_receive(:user).and_respond("331 User name okay, need password.") - -> { @ftp.login("rubyspec") }.should raise_error(Net::FTPReplyError) - end - - it "raises a Net::FTPReplyError when the server requests an account, but none was given" do - @server.should_receive(:user).and_respond("331 User name okay, need password.") - @server.should_receive(:pass).and_respond("332 Need account for login.") - -> { @ftp.login("rubyspec") }.should raise_error(Net::FTPReplyError) - end - end - - describe "when passed name, password" do - it "sends the USER command with the passed name to the server" do - @ftp.login("rubyspec", "rocks") - @server.login_user.should == "rubyspec" - end - - it "sends the passed password when required" do - @server.should_receive(:user).and_respond("331 User name okay, need password.") - @ftp.login("rubyspec", "rocks") - @server.login_pass.should == "rocks" - end - - it "raises a Net::FTPReplyError when the server requests an account" do - @server.should_receive(:user).and_respond("331 User name okay, need password.") - @server.should_receive(:pass).and_respond("332 Need account for login.") - -> { @ftp.login("rubyspec", "rocks") }.should raise_error(Net::FTPReplyError) - end - end - - describe "when passed name, password, account" do - it "sends the USER command with the passed name to the server" do - @ftp.login("rubyspec", "rocks", "account") - @server.login_user.should == "rubyspec" - end - - it "sends the passed password when required" do - @server.should_receive(:user).and_respond("331 User name okay, need password.") - @ftp.login("rubyspec", "rocks", "account") - @server.login_pass.should == "rocks" - end - - it "sends the passed account when required" do - @server.should_receive(:user).and_respond("331 User name okay, need password.") - @server.should_receive(:pass).and_respond("332 Need account for login.") - @ftp.login("rubyspec", "rocks", "account") - @server.login_acct.should == "account" - end - end - - describe "when the USER command fails" do - it "raises a Net::FTPPermError when the response code is 500" do - @server.should_receive(:user).and_respond("500 Syntax error, command unrecognized.") - -> { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPPermError when the response code is 501" do - @server.should_receive(:user).and_respond("501 Syntax error in parameters or arguments.") - -> { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPPermError when the response code is 502" do - @server.should_receive(:user).and_respond("502 Command not implemented.") - -> { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPTempError when the response code is 421" do - @server.should_receive(:user).and_respond("421 Service not available, closing control connection.") - -> { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPTempError) - end - - it "raises a Net::FTPPermError when the response code is 530" do - @server.should_receive(:user).and_respond("530 Not logged in.") - -> { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError) - end - end - - describe "when the PASS command fails" do - before :each do - @server.should_receive(:user).and_respond("331 User name okay, need password.") - end - - it "does not raise an Error when the response code is 202" do - @server.should_receive(:pass).and_respond("202 Command not implemented, superfluous at this site.") - -> { @ftp.login("rubyspec", "rocks", "account") }.should_not raise_error - end - - it "raises a Net::FTPPermError when the response code is 500" do - @server.should_receive(:pass).and_respond("500 Syntax error, command unrecognized.") - -> { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPPermError when the response code is 501" do - @server.should_receive(:pass).and_respond("501 Syntax error in parameters or arguments.") - -> { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPPermError when the response code is 502" do - @server.should_receive(:pass).and_respond("502 Command not implemented.") - -> { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPTempError when the response code is 421" do - @server.should_receive(:pass).and_respond("421 Service not available, closing control connection.") - -> { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPTempError) - end - - it "raises a Net::FTPPermError when the response code is 530" do - @server.should_receive(:pass).and_respond("530 Not logged in.") - -> { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError) - end - end - - describe "when the ACCT command fails" do - before :each do - @server.should_receive(:user).and_respond("331 User name okay, need password.") - @server.should_receive(:pass).and_respond("332 Need account for login.") - end - - it "does not raise an Error when the response code is 202" do - @server.should_receive(:acct).and_respond("202 Command not implemented, superfluous at this site.") - -> { @ftp.login("rubyspec", "rocks", "account") }.should_not raise_error - end - - it "raises a Net::FTPPermError when the response code is 500" do - @server.should_receive(:acct).and_respond("500 Syntax error, command unrecognized.") - -> { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPPermError when the response code is 501" do - @server.should_receive(:acct).and_respond("501 Syntax error in parameters or arguments.") - -> { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPPermError when the response code is 502" do - @server.should_receive(:acct).and_respond("502 Command not implemented.") - -> { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPTempError when the response code is 421" do - @server.should_receive(:acct).and_respond("421 Service not available, closing control connection.") - -> { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPTempError) - end - - it "raises a Net::FTPPermError when the response code is 530" do - @server.should_receive(:acct).and_respond("530 Not logged in.") - -> { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError) - end - end - end -end diff --git a/spec/ruby/library/net/ftp/ls_spec.rb b/spec/ruby/library/net/ftp/ls_spec.rb deleted file mode 100644 index f262515865..0000000000 --- a/spec/ruby/library/net/ftp/ls_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - require_relative 'fixtures/server' - require_relative 'shared/list' - - describe "Net::FTP#ls" do - it_behaves_like :net_ftp_list, :ls - end -end diff --git a/spec/ruby/library/net/ftp/mdtm_spec.rb b/spec/ruby/library/net/ftp/mdtm_spec.rb deleted file mode 100644 index ea55533c43..0000000000 --- a/spec/ruby/library/net/ftp/mdtm_spec.rb +++ /dev/null @@ -1,41 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - require_relative 'fixtures/server' - - describe "Net::FTP#mdtm" do - before :each do - @server = NetFTPSpecs::DummyFTP.new - @server.serve_once - - @ftp = Net::FTP.new - @ftp.connect(@server.hostname, @server.server_port) - end - - after :each do - @ftp.quit rescue nil - @ftp.close - @server.stop - end - - it "sends the MDTM with the passed filename command to the server" do - @ftp.mdtm("test.file") - @ftp.last_response.should == "213 19980705132316\n" - end - - it "returns the last modification time of the passed file" do - @ftp.mdtm("test.file").should == "19980705132316" - end - - it "raises a Net::FTPPermError when the response code is 550" do - @server.should_receive(:mdtm).and_respond("550 Requested action not taken.") - -> { @ftp.mdtm("test.file") }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPTempError when the response code is 421" do - @server.should_receive(:mdtm).and_respond("421 Service not available, closing control connection.") - -> { @ftp.mdtm("test.file") }.should raise_error(Net::FTPTempError) - end - end -end diff --git a/spec/ruby/library/net/ftp/mkdir_spec.rb b/spec/ruby/library/net/ftp/mkdir_spec.rb deleted file mode 100644 index 2cb437a076..0000000000 --- a/spec/ruby/library/net/ftp/mkdir_spec.rb +++ /dev/null @@ -1,64 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - require_relative 'fixtures/server' - - describe "Net::FTP#mkdir" do - before :each do - @server = NetFTPSpecs::DummyFTP.new - @server.serve_once - - @ftp = Net::FTP.new - @ftp.connect(@server.hostname, @server.server_port) - end - - after :each do - @ftp.quit rescue nil - @ftp.close - @server.stop - end - - it "sends the MKD command with the passed pathname to the server" do - @ftp.mkdir("test.folder") - @ftp.last_response.should == %{257 "test.folder" created.\n} - end - - it "returns the path to the newly created directory" do - @ftp.mkdir("test.folder").should == "test.folder" - @ftp.mkdir("/absolute/path/to/test.folder").should == "/absolute/path/to/test.folder" - @ftp.mkdir("relative/path/to/test.folder").should == "relative/path/to/test.folder" - @ftp.mkdir('/usr/dm/foo"bar').should == '/usr/dm/foo"bar' - end - - it "raises a Net::FTPPermError when the response code is 500" do - @server.should_receive(:mkd).and_respond("500 Syntax error, command unrecognized.") - -> { @ftp.mkdir("test.folder") }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPPermError when the response code is 501" do - @server.should_receive(:mkd).and_respond("501 Syntax error in parameters or arguments.") - -> { @ftp.mkdir("test.folder") }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPPermError when the response code is 502" do - @server.should_receive(:mkd).and_respond("502 Command not implemented.") - -> { @ftp.mkdir("test.folder") }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPTempError when the response code is 421" do - @server.should_receive(:mkd).and_respond("421 Service not available, closing control connection.") - -> { @ftp.mkdir("test.folder") }.should raise_error(Net::FTPTempError) - end - - it "raises a Net::FTPPermError when the response code is 530" do - @server.should_receive(:mkd).and_respond("530 Not logged in.") - -> { @ftp.mkdir("test.folder") }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPPermError when the response code is 550" do - @server.should_receive(:mkd).and_respond("550 Requested action not taken.") - -> { @ftp.mkdir("test.folder") }.should raise_error(Net::FTPPermError) - end - end -end diff --git a/spec/ruby/library/net/ftp/mtime_spec.rb b/spec/ruby/library/net/ftp/mtime_spec.rb deleted file mode 100644 index 7265667a52..0000000000 --- a/spec/ruby/library/net/ftp/mtime_spec.rb +++ /dev/null @@ -1,53 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - require_relative 'fixtures/server' - - describe "Net::FTP#mtime" do - before :each do - @server = NetFTPSpecs::DummyFTP.new - @server.serve_once - - @ftp = Net::FTP.new - @ftp.connect(@server.hostname, @server.server_port) - end - - after :each do - @ftp.quit rescue nil - @ftp.close - @server.stop - end - - it "sends the MDTM with the passed filename command to the server" do - @ftp.mtime("test.file") - @ftp.last_response.should == "213 19980705132316\n" - end - - describe "when passed filename" do - it "returns the last modification time of the passed file as a Time object in the local time" do - @ftp.mtime("test.file").should == Time.gm("1998", "07", "05", "13", "23", "16") - end - end - - describe "when passed filename, local_time" do - it "returns the last modification time as a Time object in UTC when local_time is true" do - @ftp.mtime("test.file", true).should == Time.local("1998", "07", "05", "13", "23", "16") - end - - it "returns the last modification time as a Time object in the local time when local_time is false" do - @ftp.mtime("test.file", false).should == Time.gm("1998", "07", "05", "13", "23", "16") - end - end - - it "raises a Net::FTPPermError when the response code is 550" do - @server.should_receive(:mdtm).and_respond("550 Requested action not taken.") - -> { @ftp.mtime("test.file") }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPTempError when the response code is 421" do - @server.should_receive(:mdtm).and_respond("421 Service not available, closing control connection.") - -> { @ftp.mtime("test.file") }.should raise_error(Net::FTPTempError) - end - end -end diff --git a/spec/ruby/library/net/ftp/nlst_spec.rb b/spec/ruby/library/net/ftp/nlst_spec.rb deleted file mode 100644 index 0de84b3a76..0000000000 --- a/spec/ruby/library/net/ftp/nlst_spec.rb +++ /dev/null @@ -1,95 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - require_relative 'fixtures/server' - - describe "Net::FTP#nlst" do - before :each do - @server = NetFTPSpecs::DummyFTP.new - @server.serve_once - - @ftp = Net::FTP.new - @ftp.passive = false - @ftp.connect(@server.hostname, @server.server_port) - end - - after :each do - @ftp.quit rescue nil - @ftp.close - @server.stop - end - - describe "when passed no arguments" do - it "returns an Array containing a list of files in the current dir" do - @ftp.nlst.should == ["last_response_code.rb", "list.rb", "pwd.rb"] - @ftp.last_response.should == "226 transfer complete (NLST)\n" - end - end - - describe "when passed dir" do - it "returns an Array containing a list of files in the passed dir" do - @ftp.nlst("test.folder").should == ["last_response_code.rb", "list.rb", "pwd.rb"] - @ftp.last_response.should == "226 transfer complete (NLST test.folder)\n" - end - end - - describe "when the NLST command fails" do - it "raises a Net::FTPTempError when the response code is 450" do - @server.should_receive(:nlst).and_respond("450 Requested file action not taken..") - -> { @ftp.nlst }.should raise_error(Net::FTPTempError) - end - - it "raises a Net::FTPPermError when the response code is 500" do - @server.should_receive(:nlst).and_respond("500 Syntax error, command unrecognized.") - -> { @ftp.nlst }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPPermError when the response code is 501" do - @server.should_receive(:nlst).and_respond("501 Syntax error, command unrecognized.") - -> { @ftp.nlst }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPPermError when the response code is 502" do - @server.should_receive(:nlst).and_respond("502 Command not implemented.") - -> { @ftp.nlst }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPTempError when the response code is 421" do - @server.should_receive(:nlst).and_respond("421 Service not available, closing control connection.") - -> { @ftp.nlst }.should raise_error(Net::FTPTempError) - end - - it "raises a Net::FTPPermError when the response code is 530" do - @server.should_receive(:nlst).and_respond("530 Not logged in.") - -> { @ftp.nlst }.should raise_error(Net::FTPPermError) - end - end - - describe "when opening the data port fails" do - it "raises a Net::FTPPermError when the response code is 500" do - @server.should_receive(:eprt).and_respond("500 Syntax error, command unrecognized.") - @server.should_receive(:port).and_respond("500 Syntax error, command unrecognized.") - -> { @ftp.nlst }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPPermError when the response code is 501" do - @server.should_receive(:eprt).and_respond("501 Syntax error in parameters or arguments.") - @server.should_receive(:port).and_respond("501 Syntax error in parameters or arguments.") - -> { @ftp.nlst }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPTempError when the response code is 421" do - @server.should_receive(:eprt).and_respond("421 Service not available, closing control connection.") - @server.should_receive(:port).and_respond("421 Service not available, closing control connection.") - -> { @ftp.nlst }.should raise_error(Net::FTPTempError) - end - - it "raises a Net::FTPPermError when the response code is 530" do - @server.should_receive(:eprt).and_respond("530 Not logged in.") - @server.should_receive(:port).and_respond("530 Not logged in.") - -> { @ftp.nlst }.should raise_error(Net::FTPPermError) - end - end - end -end diff --git a/spec/ruby/library/net/ftp/noop_spec.rb b/spec/ruby/library/net/ftp/noop_spec.rb deleted file mode 100644 index 71011d4af7..0000000000 --- a/spec/ruby/library/net/ftp/noop_spec.rb +++ /dev/null @@ -1,41 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - require_relative 'fixtures/server' - - describe "Net::FTP#noop" do - before :each do - @server = NetFTPSpecs::DummyFTP.new - @server.serve_once - - @ftp = Net::FTP.new - @ftp.connect(@server.hostname, @server.server_port) - end - - after :each do - @ftp.quit rescue nil - @ftp.close - @server.stop - end - - it "sends the NOOP command to the server" do - @ftp.noop - @ftp.last_response.should == "200 Command okay. (NOOP)\n" - end - - it "returns nil" do - @ftp.noop.should be_nil - end - - it "raises a Net::FTPPermError when the response code is 500" do - @server.should_receive(:noop).and_respond("500 Syntax error, command unrecognized.") - -> { @ftp.noop }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPTempError when the response code is 421" do - @server.should_receive(:noop).and_respond("421 Service not available, closing control connection.") - -> { @ftp.noop }.should raise_error(Net::FTPTempError) - end - end -end diff --git a/spec/ruby/library/net/ftp/open_spec.rb b/spec/ruby/library/net/ftp/open_spec.rb deleted file mode 100644 index 89187b9802..0000000000 --- a/spec/ruby/library/net/ftp/open_spec.rb +++ /dev/null @@ -1,58 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - - describe "Net::FTP.open" do - before :each do - @ftp = mock("Net::FTP instance") - Net::FTP.stub!(:new).and_return(@ftp) - end - - describe "when passed no block" do - it "returns a new Net::FTP instance" do - Net::FTP.open("localhost").should equal(@ftp) - end - - it "passes the passed arguments down to Net::FTP.new" do - Net::FTP.should_receive(:new).with("localhost", "user", "password", "account") - Net::FTP.open("localhost", "user", "password", "account") - end - end - - describe "when passed a block" do - before :each do - @ftp.stub!(:close) - end - - it "yields a new Net::FTP instance to the passed block" do - yielded = false - Net::FTP.open("localhost") do |ftp| - yielded = true - ftp.should equal(@ftp) - end - yielded.should be_true - end - - it "closes the Net::FTP instance after yielding" do - Net::FTP.open("localhost") do |ftp| - ftp.should_receive(:close) - end - end - - it "closes the Net::FTP instance even if an exception is raised while yielding" do - begin - Net::FTP.open("localhost") do |ftp| - ftp.should_receive(:close) - raise ArgumentError, "some exception" - end - rescue ArgumentError - end - end - - it "returns the block's return value" do - Net::FTP.open("localhost") { :test }.should == :test - end - end - end -end diff --git a/spec/ruby/library/net/ftp/passive_spec.rb b/spec/ruby/library/net/ftp/passive_spec.rb deleted file mode 100644 index f9c34efb7d..0000000000 --- a/spec/ruby/library/net/ftp/passive_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - - describe "Net::FTP#passive" do - it "returns true when self is in passive mode" do - ftp = Net::FTP.new - ftp.passive.should be_false - - ftp.passive = true - ftp.passive.should be_true - end - - it "is the value of Net::FTP.default_value by default" do - ruby_exe(fixture(__FILE__, "passive.rb")).should == "true" - end - end - - describe "Net::FTP#passive=" do - it "sets self to passive mode when passed true" do - ftp = Net::FTP.new - - ftp.passive = true - ftp.passive.should be_true - - ftp.passive = false - ftp.passive.should be_false - end - end -end diff --git a/spec/ruby/library/net/ftp/put_spec.rb b/spec/ruby/library/net/ftp/put_spec.rb deleted file mode 100644 index 36ba6c1963..0000000000 --- a/spec/ruby/library/net/ftp/put_spec.rb +++ /dev/null @@ -1,24 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - require_relative 'fixtures/server' - require_relative 'shared/puttextfile' - require_relative 'shared/putbinaryfile' - - describe "Net::FTP#put (binary mode)" do - before :each do - @binary_mode = true - end - - it_behaves_like :net_ftp_putbinaryfile, :put - end - - describe "Net::FTP#put (text mode)" do - before :each do - @binary_mode = false - end - - it_behaves_like :net_ftp_puttextfile, :put - end -end diff --git a/spec/ruby/library/net/ftp/putbinaryfile_spec.rb b/spec/ruby/library/net/ftp/putbinaryfile_spec.rb deleted file mode 100644 index 6ced5246fe..0000000000 --- a/spec/ruby/library/net/ftp/putbinaryfile_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - require_relative 'fixtures/server' - require_relative 'shared/putbinaryfile' - - describe "Net::FTP#putbinaryfile" do - it_behaves_like :net_ftp_putbinaryfile, :putbinaryfile - end -end diff --git a/spec/ruby/library/net/ftp/puttextfile_spec.rb b/spec/ruby/library/net/ftp/puttextfile_spec.rb deleted file mode 100644 index 0cab6bd3c3..0000000000 --- a/spec/ruby/library/net/ftp/puttextfile_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - require_relative 'fixtures/server' - require_relative 'shared/puttextfile' - - describe "Net::FTP#puttextfile" do - it_behaves_like :net_ftp_puttextfile, :puttextfile - end -end diff --git a/spec/ruby/library/net/ftp/pwd_spec.rb b/spec/ruby/library/net/ftp/pwd_spec.rb deleted file mode 100644 index 856ff5ff9b..0000000000 --- a/spec/ruby/library/net/ftp/pwd_spec.rb +++ /dev/null @@ -1,56 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - require_relative 'fixtures/server' - - describe "Net::FTP#pwd" do - before :each do - @server = NetFTPSpecs::DummyFTP.new - @server.serve_once - - @ftp = Net::FTP.new - @ftp.connect(@server.hostname, @server.server_port) - end - - after :each do - @ftp.quit rescue nil - @ftp.close - @server.stop - end - - it "sends the PWD command to the server" do - @ftp.pwd - @ftp.last_response.should == "257 \"/some/dir/\" - current directory\n" - end - - it "returns the current directory" do - @ftp.pwd.should == "/some/dir/" - end - - it "raises a Net::FTPPermError when the response code is 500" do - @server.should_receive(:pwd).and_respond("500 Syntax error, command unrecognized.") - -> { @ftp.pwd }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPPermError when the response code is 501" do - @server.should_receive(:pwd).and_respond("501 Syntax error in parameters or arguments.") - -> { @ftp.pwd }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPPermError when the response code is 502" do - @server.should_receive(:pwd).and_respond("502 Command not implemented.") - -> { @ftp.pwd }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPTempError when the response code is 421" do - @server.should_receive(:pwd).and_respond("421 Service not available, closing control connection.") - -> { @ftp.pwd }.should raise_error(Net::FTPTempError) - end - - it "raises a Net::FTPPermError when the response code is 550" do - @server.should_receive(:pwd).and_respond("550 Requested action not taken.") - -> { @ftp.pwd }.should raise_error(Net::FTPPermError) - end - end -end diff --git a/spec/ruby/library/net/ftp/quit_spec.rb b/spec/ruby/library/net/ftp/quit_spec.rb deleted file mode 100644 index 12b9fd3cee..0000000000 --- a/spec/ruby/library/net/ftp/quit_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - require_relative 'fixtures/server' - - describe "Net::FTP#quit" do - before :each do - @server = NetFTPSpecs::DummyFTP.new - @server.serve_once - - @ftp = Net::FTP.new - @ftp.connect(@server.hostname, @server.server_port) - end - - after :each do - @ftp.quit rescue nil - @ftp.close - @server.stop - end - - it "sends the QUIT command to the server" do - @ftp.quit - @ftp.last_response.should == "221 OK, bye\n" - end - - it "does not close the socket automatically" do - @ftp.quit - @ftp.closed?.should be_false - end - - it "returns nil" do - @ftp.quit.should be_nil - end - end -end diff --git a/spec/ruby/library/net/ftp/rename_spec.rb b/spec/ruby/library/net/ftp/rename_spec.rb deleted file mode 100644 index aa7c1360b5..0000000000 --- a/spec/ruby/library/net/ftp/rename_spec.rb +++ /dev/null @@ -1,97 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - require_relative 'fixtures/server' - - describe "Net::FTP#rename" do - before :each do - @server = NetFTPSpecs::DummyFTP.new - @server.serve_once - - @ftp = Net::FTP.new - @ftp.connect(@server.hostname, @server.server_port) - end - - after :each do - @ftp.quit rescue nil - @ftp.close - @server.stop - end - - describe "when passed from_name, to_name" do - it "sends the RNFR command with the passed from_name and the RNTO command with the passed to_name to the server" do - @ftp.rename("from.file", "to.file") - @ftp.last_response.should == "250 Requested file action okay, completed. (Renamed from.file to to.file)\n" - end - - it "returns something" do - @ftp.rename("from.file", "to.file").should be_nil - end - end - - describe "when the RNFR command fails" do - it "raises a Net::FTPTempError when the response code is 450" do - @server.should_receive(:rnfr).and_respond("450 Requested file action not taken.") - -> { @ftp.rename("from.file", "to.file") }.should raise_error(Net::FTPTempError) - end - - it "raises a Net::FTPPermError when the response code is 550" do - @server.should_receive(:rnfr).and_respond("550 Requested action not taken.") - -> { @ftp.rename("from.file", "to.file") }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPPermError when the response code is 501" do - @server.should_receive(:rnfr).and_respond("501 Syntax error in parameters or arguments.") - -> { @ftp.rename("from.file", "to.file") }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPPermError when the response code is 502" do - @server.should_receive(:rnfr).and_respond("502 Command not implemented.") - -> { @ftp.rename("from.file", "to.file") }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPTempError when the response code is 421" do - @server.should_receive(:rnfr).and_respond("421 Service not available, closing control connection.") - -> { @ftp.rename("from.file", "to.file") }.should raise_error(Net::FTPTempError) - end - - it "raises a Net::FTPPermError when the response code is 530" do - @server.should_receive(:rnfr).and_respond("530 Not logged in.") - -> { @ftp.rename("from.file", "to.file") }.should raise_error(Net::FTPPermError) - end - end - - describe "when the RNTO command fails" do - it "raises a Net::FTPPermError when the response code is 532" do - @server.should_receive(:rnfr).and_respond("532 Need account for storing files.") - -> { @ftp.rename("from.file", "to.file") }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPPermError when the response code is 553" do - @server.should_receive(:rnto).and_respond("553 Requested action not taken.") - -> { @ftp.rename("from.file", "to.file") }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPPermError when the response code is 501" do - @server.should_receive(:rnto).and_respond("501 Syntax error in parameters or arguments.") - -> { @ftp.rename("from.file", "to.file") }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPPermError when the response code is 502" do - @server.should_receive(:rnto).and_respond("502 Command not implemented.") - -> { @ftp.rename("from.file", "to.file") }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPTempError when the response code is 421" do - @server.should_receive(:rnto).and_respond("421 Service not available, closing control connection.") - -> { @ftp.rename("from.file", "to.file") }.should raise_error(Net::FTPTempError) - end - - it "raises a Net::FTPPermError when the response code is 530" do - @server.should_receive(:rnto).and_respond("530 Not logged in.") - -> { @ftp.rename("from.file", "to.file") }.should raise_error(Net::FTPPermError) - end - end - end -end diff --git a/spec/ruby/library/net/ftp/resume_spec.rb b/spec/ruby/library/net/ftp/resume_spec.rb deleted file mode 100644 index 1b575c29f1..0000000000 --- a/spec/ruby/library/net/ftp/resume_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - - describe "Net::FTP#resume" do - it "returns true when self is set to resume uploads/downloads" do - ftp = Net::FTP.new - ftp.resume.should be_false - - ftp.resume = true - ftp.resume.should be_true - end - end - - describe "Net::FTP#resume=" do - it "sets self to resume uploads/downloads when set to true" do - ftp = Net::FTP.new - ftp.resume = true - ftp.resume.should be_true - - ftp.resume = false - ftp.resume.should be_false - end - end -end diff --git a/spec/ruby/library/net/ftp/retrbinary_spec.rb b/spec/ruby/library/net/ftp/retrbinary_spec.rb deleted file mode 100644 index 1f89f0d454..0000000000 --- a/spec/ruby/library/net/ftp/retrbinary_spec.rb +++ /dev/null @@ -1,33 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - require_relative 'fixtures/server' - - describe "Net::FTP#retrbinary" do - before :each do - @server = NetFTPSpecs::DummyFTP.new - @server.serve_once - - @ftp = Net::FTP.new - @ftp.connect(@server.hostname, @server.server_port) - end - - after :each do - @ftp.quit rescue nil - @ftp.close - @server.stop - end - - it "sends the passed command to the server" do - @ftp.retrbinary("RETR test", 4096) {} - @ftp.last_response.should == "226 Closing data connection. (RETR test)\n" - end - - it "yields the received content as binary blocks of the passed size" do - res = [] - @ftp.retrbinary("RETR test", 10) { |bin| res << bin } - res.should == [ "This is th", "e content\n", "of the fil", "e named 't", "est'.\n" ] - end - end -end diff --git a/spec/ruby/library/net/ftp/retrlines_spec.rb b/spec/ruby/library/net/ftp/retrlines_spec.rb deleted file mode 100644 index f26b008680..0000000000 --- a/spec/ruby/library/net/ftp/retrlines_spec.rb +++ /dev/null @@ -1,37 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - require_relative 'fixtures/server' - - describe "Net::FTP#retrlines" do - before :each do - @server = NetFTPSpecs::DummyFTP.new - @server.serve_once - - @ftp = Net::FTP.new - @ftp.connect(@server.hostname, @server.server_port) - end - - after :each do - @ftp.quit rescue nil - @ftp.close - @server.stop - end - - it "sends the passed command over the socket" do - @ftp.retrlines("LIST test.dir") {} - @ftp.last_response.should == "226 transfer complete (LIST test.dir)\n" - end - - it "yields each received line to the passed block" do - res = [] - @ftp.retrlines("LIST test.dir") { |x| res << x } - res.should == [ - "-rw-r--r-- 1 spec staff 507 17 Jul 18:41 last_response_code.rb", - "-rw-r--r-- 1 spec staff 50 17 Jul 18:41 list.rb", - "-rw-r--r-- 1 spec staff 48 17 Jul 18:41 pwd.rb" - ] - end - end -end diff --git a/spec/ruby/library/net/ftp/return_code_spec.rb b/spec/ruby/library/net/ftp/return_code_spec.rb deleted file mode 100644 index 67fc9d3b19..0000000000 --- a/spec/ruby/library/net/ftp/return_code_spec.rb +++ /dev/null @@ -1,27 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - - describe "Net::FTP#return_code" do - before :each do - @ftp = Net::FTP.new - end - - it "outputs a warning and returns a newline" do - -> do - @ftp.return_code.should == "\n" - end.should complain(/warning: Net::FTP#return_code is obsolete and do nothing/) - end - end - - describe "Net::FTP#return_code=" do - before :each do - @ftp = Net::FTP.new - end - - it "outputs a warning" do - -> { @ftp.return_code = 123 }.should complain(/warning: Net::FTP#return_code= is obsolete and do nothing/) - end - end -end diff --git a/spec/ruby/library/net/ftp/rmdir_spec.rb b/spec/ruby/library/net/ftp/rmdir_spec.rb deleted file mode 100644 index 5b9586c6f0..0000000000 --- a/spec/ruby/library/net/ftp/rmdir_spec.rb +++ /dev/null @@ -1,61 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - require_relative 'fixtures/server' - - describe "Net::FTP#rmdir" do - before :each do - @server = NetFTPSpecs::DummyFTP.new - @server.serve_once - - @ftp = Net::FTP.new - @ftp.connect(@server.hostname, @server.server_port) - end - - after :each do - @ftp.quit rescue nil - @ftp.close - @server.stop - end - - it "sends the RMD command with the passed pathname to the server" do - @ftp.rmdir("test.folder") - @ftp.last_response.should == "250 Requested file action okay, completed. (RMD test.folder)\n" - end - - it "returns nil" do - @ftp.rmdir("test.folder").should be_nil - end - - it "raises a Net::FTPPermError when the response code is 500" do - @server.should_receive(:rmd).and_respond("500 Syntax error, command unrecognized.") - -> { @ftp.rmdir("test.folder") }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPPermError when the response code is 501" do - @server.should_receive(:rmd).and_respond("501 Syntax error in parameters or arguments.") - -> { @ftp.rmdir("test.folder") }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPPermError when the response code is 502" do - @server.should_receive(:rmd).and_respond("502 Command not implemented.") - -> { @ftp.rmdir("test.folder") }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPTempError when the response code is 421" do - @server.should_receive(:rmd).and_respond("421 Service not available, closing control connection.") - -> { @ftp.rmdir("test.folder") }.should raise_error(Net::FTPTempError) - end - - it "raises a Net::FTPPermError when the response code is 530" do - @server.should_receive(:rmd).and_respond("530 Not logged in.") - -> { @ftp.rmdir("test.folder") }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPPermError when the response code is 550" do - @server.should_receive(:rmd).and_respond("550 Requested action not taken.") - -> { @ftp.rmdir("test.folder") }.should raise_error(Net::FTPPermError) - end - end -end diff --git a/spec/ruby/library/net/ftp/sendcmd_spec.rb b/spec/ruby/library/net/ftp/sendcmd_spec.rb deleted file mode 100644 index fefb89ae0b..0000000000 --- a/spec/ruby/library/net/ftp/sendcmd_spec.rb +++ /dev/null @@ -1,57 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - require_relative 'fixtures/server' - - describe "Net::FTP#sendcmd" do - before :each do - @server = NetFTPSpecs::DummyFTP.new - @server.serve_once - - @ftp = Net::FTP.new - @ftp.connect(@server.hostname, @server.server_port) - end - - after :each do - @ftp.quit rescue nil - @ftp.close - @server.stop - end - - it "sends the passed command to the server" do - @ftp.sendcmd("HELP") - @ftp.last_response.should == "211 System status, or system help reply. (HELP)\n" - end - - it "returns the server's response" do - @ftp.sendcmd("HELP").should == "211 System status, or system help reply. (HELP)\n" - end - - it "raises no error when the response code is 1xx, 2xx or 3xx" do - @server.should_receive(:help).and_respond("120 Service ready in nnn minutes.") - -> { @ftp.sendcmd("HELP") }.should_not raise_error - - @server.should_receive(:help).and_respond("200 Command okay.") - -> { @ftp.sendcmd("HELP") }.should_not raise_error - - @server.should_receive(:help).and_respond("350 Requested file action pending further information.") - -> { @ftp.sendcmd("HELP") }.should_not raise_error - end - - it "raises a Net::FTPTempError when the response code is 4xx" do - @server.should_receive(:help).and_respond("421 Service not available, closing control connection.") - -> { @ftp.sendcmd("HELP") }.should raise_error(Net::FTPTempError) - end - - it "raises a Net::FTPPermError when the response code is 5xx" do - @server.should_receive(:help).and_respond("500 Syntax error, command unrecognized.") - -> { @ftp.sendcmd("HELP") }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPProtoError when the response code is not between 1xx-5xx" do - @server.should_receive(:help).and_respond("999 Invalid response.") - -> { @ftp.sendcmd("HELP") }.should raise_error(Net::FTPProtoError) - end - end -end diff --git a/spec/ruby/library/net/ftp/set_socket_spec.rb b/spec/ruby/library/net/ftp/set_socket_spec.rb deleted file mode 100644 index 6c8b58fb79..0000000000 --- a/spec/ruby/library/net/ftp/set_socket_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - - describe "Net::FTP#set_socket" do - # TODO: I won't spec this method, as it is not used - # anywhere and it should be private anyway. - it "needs to be reviewed for spec completeness" - end -end diff --git a/spec/ruby/library/net/ftp/site_spec.rb b/spec/ruby/library/net/ftp/site_spec.rb deleted file mode 100644 index ca4f499112..0000000000 --- a/spec/ruby/library/net/ftp/site_spec.rb +++ /dev/null @@ -1,56 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - require_relative 'fixtures/server' - - describe "Net::FTP#site" do - before :each do - @server = NetFTPSpecs::DummyFTP.new - @server.serve_once - - @ftp = Net::FTP.new - @ftp.connect(@server.hostname, @server.server_port) - end - - after :each do - @ftp.quit rescue nil - @ftp.close - @server.stop - end - - it "sends the SITE command with the passed argument to the server" do - @ftp.site("param") - @ftp.last_response.should == "200 Command okay. (SITE param)\n" - end - - it "returns nil" do - @ftp.site("param").should be_nil - end - - it "does not raise an error when the response code is 202" do - @server.should_receive(:site).and_respond("202 Command not implemented, superfluous at this site.") - -> { @ftp.site("param") }.should_not raise_error - end - - it "raises a Net::FTPPermError when the response code is 500" do - @server.should_receive(:site).and_respond("500 Syntax error, command unrecognized.") - -> { @ftp.site("param") }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPPermError when the response code is 501" do - @server.should_receive(:site).and_respond("501 Syntax error in parameters or arguments.") - -> { @ftp.site("param") }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPTempError when the response code is 421" do - @server.should_receive(:site).and_respond("421 Service not available, closing control connection.") - -> { @ftp.site("param") }.should raise_error(Net::FTPTempError) - end - - it "raises a Net::FTPPermError when the response code is 530" do - @server.should_receive(:site).and_respond("530 Requested action not taken.") - -> { @ftp.site("param") }.should raise_error(Net::FTPPermError) - end - end -end diff --git a/spec/ruby/library/net/ftp/size_spec.rb b/spec/ruby/library/net/ftp/size_spec.rb deleted file mode 100644 index 0c20b10549..0000000000 --- a/spec/ruby/library/net/ftp/size_spec.rb +++ /dev/null @@ -1,51 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - require_relative 'fixtures/server' - - describe "Net::FTP#size" do - before :each do - @server = NetFTPSpecs::DummyFTP.new - @server.serve_once - - @ftp = Net::FTP.new - @ftp.connect(@server.hostname, @server.server_port) - end - - after :each do - @ftp.quit rescue nil - @ftp.close - @server.stop - end - - it "sends the SIZE command to the server" do - @ftp.size("test.file") - @ftp.last_response.should == "213 1024\n" - end - - it "returns the size of the passed file as Integer" do - @ftp.size("test.file").should eql(1024) - end - - it "raises a Net::FTPPermError when the response code is 500" do - @server.should_receive(:size).and_respond("500 Syntax error, command unrecognized.") - -> { @ftp.size("test.file") }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPPermError when the response code is 501" do - @server.should_receive(:size).and_respond("501 Syntax error in parameters or arguments.") - -> { @ftp.size("test.file") }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPTempError when the response code is 421" do - @server.should_receive(:size).and_respond("421 Service not available, closing control connection.") - -> { @ftp.size("test.file") }.should raise_error(Net::FTPTempError) - end - - it "raises a Net::FTPPermError when the response code is 550" do - @server.should_receive(:size).and_respond("550 Requested action not taken.") - -> { @ftp.size("test.file") }.should raise_error(Net::FTPPermError) - end - end -end diff --git a/spec/ruby/library/net/ftp/status_spec.rb b/spec/ruby/library/net/ftp/status_spec.rb deleted file mode 100644 index 03bc5d6e05..0000000000 --- a/spec/ruby/library/net/ftp/status_spec.rb +++ /dev/null @@ -1,70 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - require_relative 'fixtures/server' - - describe "Net::FTP#status" do - before :each do - @server = NetFTPSpecs::DummyFTP.new - @server.serve_once - - @ftp = Net::FTP.new - @ftp.connect(@server.hostname, @server.server_port) - end - - after :each do - @ftp.quit rescue nil - @ftp.close - @server.stop - end - - it "sends the STAT command to the server" do - @ftp.status - @ftp.last_response.should == "211 System status, or system help reply. (STAT)\n" - end - - it "sends the STAT command with an optional parameter to the server" do - @ftp.status("/pub").should == "211 System status, or system help reply. (STAT /pub)\n" - end - - it "returns the received information" do - @ftp.status.should == "211 System status, or system help reply. (STAT)\n" - end - - it "does not raise an error when the response code is 212" do - @server.should_receive(:stat).and_respond("212 Directory status.") - -> { @ftp.status }.should_not raise_error - end - - it "does not raise an error when the response code is 213" do - @server.should_receive(:stat).and_respond("213 File status.") - -> { @ftp.status }.should_not raise_error - end - - it "raises a Net::FTPPermError when the response code is 500" do - @server.should_receive(:stat).and_respond("500 Syntax error, command unrecognized.") - -> { @ftp.status }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPPermError when the response code is 501" do - @server.should_receive(:stat).and_respond("501 Syntax error in parameters or arguments.") - -> { @ftp.status }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPPermError when the response code is 502" do - @server.should_receive(:stat).and_respond("502 Command not implemented.") - -> { @ftp.status }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPTempError when the response code is 421" do - @server.should_receive(:stat).and_respond("421 Service not available, closing control connection.") - -> { @ftp.status }.should raise_error(Net::FTPTempError) - end - - it "raises a Net::FTPPermError when the response code is 530" do - @server.should_receive(:stat).and_respond("530 Requested action not taken.") - -> { @ftp.status }.should raise_error(Net::FTPPermError) - end - end -end diff --git a/spec/ruby/library/net/ftp/storbinary_spec.rb b/spec/ruby/library/net/ftp/storbinary_spec.rb deleted file mode 100644 index 64c9090760..0000000000 --- a/spec/ruby/library/net/ftp/storbinary_spec.rb +++ /dev/null @@ -1,51 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - require_relative 'fixtures/server' - - describe "Net::FTP#storbinary" do - before :each do - @server = NetFTPSpecs::DummyFTP.new - @server.serve_once - - @local_fixture_file = File.dirname(__FILE__) + "/fixtures/putbinaryfile" - @tmp_file = tmp("binaryfile", false) - - @ftp = Net::FTP.new - @ftp.connect(@server.hostname, @server.server_port) - end - - after :each do - @ftp.quit rescue nil - @ftp.close - @server.stop - - rm_r @tmp_file - end - - it "sends the passed command and the passed File object's content to the server" do - File.open(@local_fixture_file) do |f| - f.binmode - - @ftp.storbinary("STOR binary", f, 4096) {} - @ftp.last_response.should == "200 OK, Data received. (STOR binary)\n" - end - end - - it "yields the transmitted content as binary blocks of the passed size" do - File.open(@local_fixture_file) do |f| - f.binmode - - res = [] - @ftp.storbinary("STOR binary", f, 10) { |x| res << x } - res.should == [ - "This is an", " example f", - "ile\nwhich ", "is going t", - "o be trans", "mitted\nusi", - "ng #putbin", "aryfile.\n" - ] - end - end - end -end diff --git a/spec/ruby/library/net/ftp/storlines_spec.rb b/spec/ruby/library/net/ftp/storlines_spec.rb deleted file mode 100644 index a4bb7af799..0000000000 --- a/spec/ruby/library/net/ftp/storlines_spec.rb +++ /dev/null @@ -1,46 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - require_relative 'fixtures/server' - - describe "Net::FTP#storlines" do - before :each do - @server = NetFTPSpecs::DummyFTP.new - @server.serve_once - - @local_fixture_file = File.dirname(__FILE__) + "/fixtures/puttextfile" - @tmp_file = tmp("textfile", false) - - @ftp = Net::FTP.new - @ftp.connect(@server.hostname, @server.server_port) - end - - after :each do - @ftp.quit rescue nil - @ftp.close - @server.stop - - rm_r @tmp_file - end - - it "sends the passed command and the passed File object's content to the server" do - File.open(@local_fixture_file) do |f| - @ftp.storlines("STOR text", f) {} - @ftp.last_response.should == "200 OK, Data received. (STOR text)\n" - end - end - - it "yields each line of the transmitted content" do - File.open(@local_fixture_file) do |f| - res = [] - @ftp.storlines("STOR text", f) { |x| res << x } - res.should == [ - "This is an example file\r\n", - "which is going to be transmitted\r\n", - "using #puttextfile.\r\n" - ] - end - end - end -end diff --git a/spec/ruby/library/net/ftp/system_spec.rb b/spec/ruby/library/net/ftp/system_spec.rb deleted file mode 100644 index 0630bbe1f6..0000000000 --- a/spec/ruby/library/net/ftp/system_spec.rb +++ /dev/null @@ -1,51 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - require_relative 'fixtures/server' - - describe "Net::FTP#system" do - before :each do - @server = NetFTPSpecs::DummyFTP.new - @server.serve_once - - @ftp = Net::FTP.new - @ftp.connect(@server.hostname, @server.server_port) - end - - after :each do - @ftp.quit rescue nil - @ftp.close - @server.stop - end - - it "sends the SYST command to the server" do - @ftp.system - @ftp.last_response.should =~ /\A215 FTP Dummy Server \(SYST\)\Z/ - end - - it "returns the received information" do - @ftp.system.should =~ /\AFTP Dummy Server \(SYST\)\Z/ - end - - it "raises a Net::FTPPermError when the response code is 500" do - @server.should_receive(:syst).and_respond("500 Syntax error, command unrecognized.") - -> { @ftp.system }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPPermError when the response code is 501" do - @server.should_receive(:syst).and_respond("501 Syntax error in parameters or arguments.") - -> { @ftp.system }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPPermError when the response code is 502" do - @server.should_receive(:syst).and_respond("502 Command not implemented.") - -> { @ftp.system }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPTempError when the response code is 421" do - @server.should_receive(:syst).and_respond("421 Service not available, closing control connection.") - -> { @ftp.system }.should raise_error(Net::FTPTempError) - end - end -end diff --git a/spec/ruby/library/net/ftp/voidcmd_spec.rb b/spec/ruby/library/net/ftp/voidcmd_spec.rb deleted file mode 100644 index ee74455d63..0000000000 --- a/spec/ruby/library/net/ftp/voidcmd_spec.rb +++ /dev/null @@ -1,57 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - require_relative 'fixtures/server' - - describe "Net::FTP#voidcmd" do - before :each do - @server = NetFTPSpecs::DummyFTP.new - @server.serve_once - - @ftp = Net::FTP.new - @ftp.connect(@server.hostname, @server.server_port) - end - - after :each do - @ftp.quit rescue nil - @ftp.close - @server.stop - end - - it "sends the passed command to the server" do - @server.should_receive(:help).and_respond("2xx Does not raise.") - -> { @ftp.voidcmd("HELP") }.should_not raise_error - end - - it "returns nil" do - @server.should_receive(:help).and_respond("2xx Does not raise.") - @ftp.voidcmd("HELP").should be_nil - end - - it "raises a Net::FTPReplyError when the response code is 1xx" do - @server.should_receive(:help).and_respond("1xx Does raise a Net::FTPReplyError.") - -> { @ftp.voidcmd("HELP") }.should raise_error(Net::FTPReplyError) - end - - it "raises a Net::FTPReplyError when the response code is 3xx" do - @server.should_receive(:help).and_respond("3xx Does raise a Net::FTPReplyError.") - -> { @ftp.voidcmd("HELP") }.should raise_error(Net::FTPReplyError) - end - - it "raises a Net::FTPTempError when the response code is 4xx" do - @server.should_receive(:help).and_respond("4xx Does raise a Net::FTPTempError.") - -> { @ftp.voidcmd("HELP") }.should raise_error(Net::FTPTempError) - end - - it "raises a Net::FTPPermError when the response code is 5xx" do - @server.should_receive(:help).and_respond("5xx Does raise a Net::FTPPermError.") - -> { @ftp.voidcmd("HELP") }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPProtoError when the response code is not valid" do - @server.should_receive(:help).and_respond("999 Does raise a Net::FTPProtoError.") - -> { @ftp.voidcmd("HELP") }.should raise_error(Net::FTPProtoError) - end - end -end diff --git a/spec/ruby/library/net/ftp/welcome_spec.rb b/spec/ruby/library/net/ftp/welcome_spec.rb deleted file mode 100644 index e5414ef607..0000000000 --- a/spec/ruby/library/net/ftp/welcome_spec.rb +++ /dev/null @@ -1,28 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - require_relative 'fixtures/server' - - describe "Net::FTP#welcome" do - before :each do - @server = NetFTPSpecs::DummyFTP.new - @server.serve_once - - @ftp = Net::FTP.new - @ftp.connect(@server.hostname, @server.server_port) - end - - after :each do - @ftp.quit rescue nil - @ftp.close - @server.stop - end - - it "returns the server's welcome message" do - @ftp.welcome.should be_nil - @ftp.login - @ftp.welcome.should == "230 User logged in, proceed. (USER anonymous)\n" - end - end -end diff --git a/spec/ruby/library/net/http/HTTPServerException_spec.rb b/spec/ruby/library/net/http/HTTPServerException_spec.rb deleted file mode 100644 index 23b0657364..0000000000 --- a/spec/ruby/library/net/http/HTTPServerException_spec.rb +++ /dev/null @@ -1,12 +0,0 @@ -require_relative '../../../spec_helper' -require 'net/http' - -describe "Net::HTTPServerException" do - it "is a subclass of Net::ProtoServerError and is warned as deprecated" do - -> { Net::HTTPServerException.should < Net::ProtoServerError }.should complain(/warning: constant Net::HTTPServerException is deprecated/) - end - - it "includes the Net::HTTPExceptions module and is warned as deprecated" do - -> { Net::HTTPServerException.should < Net::HTTPExceptions }.should complain(/warning: constant Net::HTTPServerException is deprecated/) - end -end diff --git a/spec/ruby/library/objectspace/dump_all_spec.rb b/spec/ruby/library/objectspace/dump_all_spec.rb new file mode 100644 index 0000000000..e9b449a905 --- /dev/null +++ b/spec/ruby/library/objectspace/dump_all_spec.rb @@ -0,0 +1,112 @@ +require_relative '../../spec_helper' +require 'objspace' + +describe "ObjectSpace.dump_all" do + it "dumps Ruby heap to string when passed output: :string" do + stdout = ruby_exe(<<~RUBY, options: "-robjspace") + string = "abc" + dump = ObjectSpace.dump_all(output: :string) + puts dump.class + puts dump.include?('"value":"abc"') + RUBY + + stdout.should == "String\ntrue\n" + end + + it "dumps Ruby heap to a temporary file when passed output: :file" do + stdout = ruby_exe(<<~RUBY, options: "-robjspace") + string = "abc" + file = ObjectSpace.dump_all(output: :file) + + begin + file.flush + file.rewind + content = file.read + + puts file.class + puts content.include?('"value":"abc"') + ensure + file.close + File.unlink file.path + end + RUBY + + stdout.should == "File\ntrue\n" + end + + it "dumps Ruby heap to a temporary file when :output not specified" do + stdout = ruby_exe(<<~RUBY, options: "-robjspace") + string = "abc" + file = ObjectSpace.dump_all + + begin + file.flush + file.rewind + content = file.read + + puts file.class + puts content.include?('"value":"abc"') + ensure + file.close + File.unlink file.path + end + RUBY + + stdout.should == "File\ntrue\n" + end + + it "dumps Ruby heap to a temporary file when passed output: :nil" do + stdout = ruby_exe(<<~RUBY, options: "-robjspace") + string = "abc" + file = ObjectSpace.dump_all(output: nil) + + begin + file.flush + file.rewind + content = file.read + + puts file.class + puts content.include?('"value":"abc"') + ensure + file.close + File.unlink file.path + end + RUBY + + stdout.should == "File\ntrue\n" + end + + it "dumps Ruby heap to stdout when passed output: :stdout" do + stdout = ruby_exe(<<~RUBY, options: "-robjspace") + string = "abc" + ObjectSpace.dump_all(output: :stdout) + RUBY + + stdout.should include('"value":"abc"') + end + + it "dumps Ruby heap to provided IO when passed output: IO" do + stdout = ruby_exe(<<~RUBY, options: "-robjspace -rtempfile") + string = "abc" + io = Tempfile.create("object_space_dump_all") + + begin + result = ObjectSpace.dump_all(output: io) + io.rewind + content = io.read + + puts result.equal?(io) + puts content.include?('"value":"abc"') + ensure + io.close + File.unlink io.path + end + RUBY + + stdout.should == "true\ntrue\n" + end + + it "raises ArgumentError when passed not supported :output value" do + -> { ObjectSpace.dump_all(output: Object.new) }.should raise_error(ArgumentError, /wrong output option/) + end +end diff --git a/spec/ruby/library/objectspace/dump_spec.rb b/spec/ruby/library/objectspace/dump_spec.rb new file mode 100644 index 0000000000..e22ee3df1e --- /dev/null +++ b/spec/ruby/library/objectspace/dump_spec.rb @@ -0,0 +1,70 @@ +require_relative '../../spec_helper' +require 'objspace' + +describe "ObjectSpace.dump" do + it "dumps the content of object as JSON" do + require 'json' + string = ObjectSpace.dump("abc") + dump = JSON.parse(string) + + dump['type'].should == "STRING" + dump['value'].should == "abc" + end + + it "dumps to string when passed output: :string" do + string = ObjectSpace.dump("abc", output: :string) + string.should be_kind_of(String) + string.should include('"value":"abc"') + end + + it "dumps to string when :output not specified" do + string = ObjectSpace.dump("abc") + string.should be_kind_of(String) + string.should include('"value":"abc"') + end + + it "dumps to a temporary file when passed output: :file" do + file = ObjectSpace.dump("abc", output: :file) + file.should be_kind_of(File) + + file.rewind + content = file.read + content.should include('"value":"abc"') + ensure + file.close + File.unlink file.path + end + + it "dumps to a temporary file when passed output: :nil" do + file = ObjectSpace.dump("abc", output: nil) + file.should be_kind_of(File) + + file.rewind + file.read.should include('"value":"abc"') + ensure + file.close + File.unlink file.path + end + + it "dumps to stdout when passed output: :stdout" do + stdout = ruby_exe('ObjectSpace.dump("abc", output: :stdout)', options: "-robjspace").chomp + stdout.should include('"value":"abc"') + end + + it "dumps to provided IO when passed output: IO" do + filename = tmp("io_read.txt") + io = File.open(filename, "w+") + result = ObjectSpace.dump("abc", output: io) + result.should.equal? io + + io.rewind + io.read.should include('"value":"abc"') + ensure + io.close + rm_r filename + end + + it "raises ArgumentError when passed not supported :output value" do + -> { ObjectSpace.dump("abc", output: Object.new) }.should raise_error(ArgumentError, /wrong output option/) + end +end diff --git a/spec/ruby/library/objectspace/fixtures/trace.rb b/spec/ruby/library/objectspace/fixtures/trace.rb index fd4524b0ba..e53a7a0cac 100644 --- a/spec/ruby/library/objectspace/fixtures/trace.rb +++ b/spec/ruby/library/objectspace/fixtures/trace.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false require "objspace/trace" a = "foo" b = "b" + "a" + "r" diff --git a/spec/ruby/library/objectspace/memsize_of_spec.rb b/spec/ruby/library/objectspace/memsize_of_spec.rb index eefafbb334..cbb5a07d54 100644 --- a/spec/ruby/library/objectspace/memsize_of_spec.rb +++ b/spec/ruby/library/objectspace/memsize_of_spec.rb @@ -13,7 +13,7 @@ describe "ObjectSpace.memsize_of" do end it "returns 0 for literal Symbols" do - ObjectSpace.memsize_of(:abc).should == 0 + ObjectSpace.memsize_of(:object_space_memsize_spec_static_sym).should == 0 end it "returns a positive Integer for an Object" do diff --git a/spec/ruby/library/objectspace/reachable_objects_from_spec.rb b/spec/ruby/library/objectspace/reachable_objects_from_spec.rb index 7e70bc8569..dee5961663 100644 --- a/spec/ruby/library/objectspace/reachable_objects_from_spec.rb +++ b/spec/ruby/library/objectspace/reachable_objects_from_spec.rb @@ -38,7 +38,6 @@ describe "ObjectSpace.reachable_objects_from" do end it "finds an object stored in a Queue" do - require 'thread' o = Object.new q = Queue.new q << o @@ -49,7 +48,6 @@ describe "ObjectSpace.reachable_objects_from" do end it "finds an object stored in a SizedQueue" do - require 'thread' o = Object.new q = SizedQueue.new(3) q << o diff --git a/spec/ruby/library/objectspace/trace_object_allocations_spec.rb b/spec/ruby/library/objectspace/trace_object_allocations_spec.rb index 612430e067..0f1e2aa8b9 100644 --- a/spec/ruby/library/objectspace/trace_object_allocations_spec.rb +++ b/spec/ruby/library/objectspace/trace_object_allocations_spec.rb @@ -2,6 +2,20 @@ require_relative '../../spec_helper' require 'objspace' describe "ObjectSpace.trace_object_allocations" do + def has_class_frame? + Class.new { + attr_reader :c + + def initialize + @c = caller_locations.first.label =~ /new/ + end + }.new.c + end + + def obj_class_path + has_class_frame? ? "Class" : nil + end + it "runs a block" do ScratchPad.clear ObjectSpace.trace_object_allocations do @@ -13,7 +27,7 @@ describe "ObjectSpace.trace_object_allocations" do it "records info for allocation_class_path" do ObjectSpace.trace_object_allocations do o = Object.new - ObjectSpace.allocation_class_path(o).should == "Class" + ObjectSpace.allocation_class_path(o).should == obj_class_path a = [1, 2, 3] ObjectSpace.allocation_class_path(a).should == nil end @@ -31,7 +45,7 @@ describe "ObjectSpace.trace_object_allocations" do it "records info for allocation_method_id" do ObjectSpace.trace_object_allocations do o = Object.new - ObjectSpace.allocation_method_id(o).should == :new + ObjectSpace.allocation_method_id(o).should == (has_class_frame? ? :new : nil) a = [1, 2, 3] ObjectSpace.allocation_method_id(a).should == nil end @@ -58,7 +72,7 @@ describe "ObjectSpace.trace_object_allocations" do it "can be cleared using trace_object_allocations_clear" do ObjectSpace.trace_object_allocations do o = Object.new - ObjectSpace.allocation_class_path(o).should == "Class" + ObjectSpace.allocation_class_path(o).should == obj_class_path ObjectSpace.trace_object_allocations_clear ObjectSpace.allocation_class_path(o).should be_nil end @@ -69,14 +83,14 @@ describe "ObjectSpace.trace_object_allocations" do ObjectSpace.trace_object_allocations do o = Object.new end - ObjectSpace.allocation_class_path(o).should == "Class" + ObjectSpace.allocation_class_path(o).should == obj_class_path end it "can be used without a block using trace_object_allocations_start and _stop" do ObjectSpace.trace_object_allocations_start begin o = Object.new - ObjectSpace.allocation_class_path(o).should == "Class" + ObjectSpace.allocation_class_path(o).should == obj_class_path a = [1, 2, 3] ObjectSpace.allocation_class_path(a).should == nil ensure @@ -91,14 +105,14 @@ describe "ObjectSpace.trace_object_allocations" do ensure ObjectSpace.trace_object_allocations_stop end - ObjectSpace.allocation_class_path(o).should == "Class" + ObjectSpace.allocation_class_path(o).should == obj_class_path end it "can be nested" do ObjectSpace.trace_object_allocations do ObjectSpace.trace_object_allocations do o = Object.new - ObjectSpace.allocation_class_path(o).should == "Class" + ObjectSpace.allocation_class_path(o).should == obj_class_path end end end @@ -109,7 +123,7 @@ describe "ObjectSpace.trace_object_allocations" do ObjectSpace.trace_object_allocations_start begin o = Object.new - ObjectSpace.allocation_class_path(o).should == "Class" + ObjectSpace.allocation_class_path(o).should == obj_class_path ensure ObjectSpace.trace_object_allocations_stop end @@ -122,7 +136,7 @@ describe "ObjectSpace.trace_object_allocations" do ObjectSpace.trace_object_allocations_start begin o = Object.new - ObjectSpace.allocation_class_path(o).should == "Class" + ObjectSpace.allocation_class_path(o).should == obj_class_path ObjectSpace.trace_object_allocations_stop ensure ObjectSpace.trace_object_allocations_stop diff --git a/spec/ruby/library/objectspace/trace_spec.rb b/spec/ruby/library/objectspace/trace_spec.rb index 59952a006c..3957dc930d 100644 --- a/spec/ruby/library/objectspace/trace_spec.rb +++ b/spec/ruby/library/objectspace/trace_spec.rb @@ -1,15 +1,13 @@ require_relative '../../spec_helper' -ruby_version_is "3.1" do - describe 'require "objspace/trace"' do - it "shows object allocation sites" do - file = fixture(__FILE__ , "trace.rb") - ruby_exe(file, args: "2>&1").lines(chomp: true).should == [ - "objspace/trace is enabled", - "\"foo\" @ #{file}:2", - "\"bar\" @ #{file}:3", - "42" - ] - end +describe 'require "objspace/trace"' do + it "shows object allocation sites" do + file = fixture(__FILE__ , "trace.rb") + ruby_exe(file, args: "2>&1").lines(chomp: true).should == [ + "objspace/trace is enabled", + "\"foo\" @ #{file}:3", + "\"bar\" @ #{file}:4", + "42" + ] end end diff --git a/spec/ruby/library/openssl/config/freeze_spec.rb b/spec/ruby/library/openssl/config/freeze_spec.rb deleted file mode 100644 index c814341b86..0000000000 --- a/spec/ruby/library/openssl/config/freeze_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -require_relative '../../../spec_helper' -require_relative '../shared/constants' - -require 'openssl' - -version_is(OpenSSL::VERSION, ""..."2.2") do - describe "OpenSSL::Config#freeze" do - it "needs to be reviewed for completeness" - - it "freezes" do - c = OpenSSL::Config.new - -> { - c['foo'] = [ ['key', 'value'] ] - }.should_not raise_error - c.freeze - c.frozen?.should be_true - -> { - c['foo'] = [ ['key', 'value'] ] - }.should raise_error(TypeError) - end - end -end diff --git a/spec/ruby/library/openssl/digest/append_spec.rb b/spec/ruby/library/openssl/digest/append_spec.rb new file mode 100644 index 0000000000..08802b7253 --- /dev/null +++ b/spec/ruby/library/openssl/digest/append_spec.rb @@ -0,0 +1,6 @@ +require_relative '../../../spec_helper' +require_relative 'shared/update' + +describe "OpenSSL::Digest#<<" do + it_behaves_like :openssl_digest_update, :<< +end diff --git a/spec/ruby/library/openssl/digest/block_length_spec.rb b/spec/ruby/library/openssl/digest/block_length_spec.rb new file mode 100644 index 0000000000..444ed9d20d --- /dev/null +++ b/spec/ruby/library/openssl/digest/block_length_spec.rb @@ -0,0 +1,44 @@ +require_relative '../../../spec_helper' +require_relative '../../../library/digest/sha1/shared/constants' +require_relative '../../../library/digest/sha256/shared/constants' +require_relative '../../../library/digest/sha384/shared/constants' +require_relative '../../../library/digest/sha512/shared/constants' +require 'openssl' + +describe "OpenSSL::Digest#block_length" do + context "when the digest object is created via a name argument" do + it "returns a SHA1 block length" do + OpenSSL::Digest.new('sha1').block_length.should == SHA1Constants::BlockLength + end + + it "returns a SHA256 block length" do + OpenSSL::Digest.new('sha256').block_length.should == SHA256Constants::BlockLength + end + + it "returns a SHA384 block length" do + OpenSSL::Digest.new('sha384').block_length.should == SHA384Constants::BlockLength + end + + it "returns a SHA512 block length" do + OpenSSL::Digest.new('sha512').block_length.should == SHA512Constants::BlockLength + end + end + + context "when the digest object is created via a subclass" do + it "returns a SHA1 block length" do + OpenSSL::Digest::SHA1.new.block_length.should == SHA1Constants::BlockLength + end + + it "returns a SHA256 block length" do + OpenSSL::Digest::SHA256.new.block_length.should == SHA256Constants::BlockLength + end + + it "returns a SHA384 block length" do + OpenSSL::Digest::SHA384.new.block_length.should == SHA384Constants::BlockLength + end + + it "returns a SHA512 block length" do + OpenSSL::Digest::SHA512.new.block_length.should == SHA512Constants::BlockLength + end + end +end diff --git a/spec/ruby/library/openssl/digest/digest_length_spec.rb b/spec/ruby/library/openssl/digest/digest_length_spec.rb new file mode 100644 index 0000000000..37d1cba9a7 --- /dev/null +++ b/spec/ruby/library/openssl/digest/digest_length_spec.rb @@ -0,0 +1,44 @@ +require_relative '../../../spec_helper' +require_relative '../../../library/digest/sha1/shared/constants' +require_relative '../../../library/digest/sha256/shared/constants' +require_relative '../../../library/digest/sha384/shared/constants' +require_relative '../../../library/digest/sha512/shared/constants' +require 'openssl' + +describe "OpenSSL::Digest#digest_length" do + context "when the digest object is created via a name argument" do + it "returns a SHA1 digest length" do + OpenSSL::Digest.new('sha1').digest_length.should == SHA1Constants::DigestLength + end + + it "returns a SHA256 digest length" do + OpenSSL::Digest.new('sha256').digest_length.should == SHA256Constants::DigestLength + end + + it "returns a SHA384 digest length" do + OpenSSL::Digest.new('sha384').digest_length.should == SHA384Constants::DigestLength + end + + it "returns a SHA512 digest length" do + OpenSSL::Digest.new('sha512').digest_length.should == SHA512Constants::DigestLength + end + end + + context "when the digest object is created via a subclass" do + it "returns a SHA1 digest length" do + OpenSSL::Digest::SHA1.new.digest_length.should == SHA1Constants::DigestLength + end + + it "returns a SHA256 digest length" do + OpenSSL::Digest::SHA256.new.digest_length.should == SHA256Constants::DigestLength + end + + it "returns a SHA384 digest length" do + OpenSSL::Digest::SHA384.new.digest_length.should == SHA384Constants::DigestLength + end + + it "returns a SHA512 digest length" do + OpenSSL::Digest::SHA512.new.digest_length.should == SHA512Constants::DigestLength + end + end +end diff --git a/spec/ruby/library/openssl/digest_spec.rb b/spec/ruby/library/openssl/digest/digest_spec.rb index b8e82d073f..cf27d01b6d 100644 --- a/spec/ruby/library/openssl/digest_spec.rb +++ b/spec/ruby/library/openssl/digest/digest_spec.rb @@ -1,12 +1,11 @@ -require_relative '../../spec_helper' -require_relative '../../library/digest/sha1/shared/constants' -require_relative '../../library/digest/sha256/shared/constants' -require_relative '../../library/digest/sha384/shared/constants' -require_relative '../../library/digest/sha512/shared/constants' +require_relative '../../../spec_helper' +require_relative '../../../library/digest/sha1/shared/constants' +require_relative '../../../library/digest/sha256/shared/constants' +require_relative '../../../library/digest/sha384/shared/constants' +require_relative '../../../library/digest/sha512/shared/constants' require 'openssl' -describe "OpenSSL::Digest" do - +describe "OpenSSL::Digest class methods" do describe ".digest" do it "returns a SHA1 digest" do OpenSSL::Digest.digest('sha1', SHA1Constants::Contents).should == SHA1Constants::Digest diff --git a/spec/ruby/library/openssl/digest/initialize_spec.rb b/spec/ruby/library/openssl/digest/initialize_spec.rb new file mode 100644 index 0000000000..b5911716ca --- /dev/null +++ b/spec/ruby/library/openssl/digest/initialize_spec.rb @@ -0,0 +1,137 @@ +require_relative '../../../spec_helper' +require_relative '../../../library/digest/sha1/shared/constants' +require_relative '../../../library/digest/sha256/shared/constants' +require_relative '../../../library/digest/sha384/shared/constants' +require_relative '../../../library/digest/sha512/shared/constants' +require 'openssl' + +describe "OpenSSL::Digest#initialize" do + describe "can be called with a digest name" do + it "returns a SHA1 object" do + OpenSSL::Digest.new("sha1").name.should == "SHA1" + end + + it "returns a SHA256 object" do + OpenSSL::Digest.new("sha256").name.should == "SHA256" + end + + it "returns a SHA384 object" do + OpenSSL::Digest.new("sha384").name.should == "SHA384" + end + + it "returns a SHA512 object" do + OpenSSL::Digest.new("sha512").name.should == "SHA512" + end + + version_is OpenSSL::VERSION, "4.0.0" do + it "throws an error when called with an unknown digest" do + -> { OpenSSL::Digest.new("wd40") }.should raise_error(OpenSSL::Digest::DigestError, /wd40/) + end + end + + it "cannot be called with a symbol" do + -> { OpenSSL::Digest.new(:SHA1) }.should raise_error(TypeError) + end + end + + describe "can be called with a digest object" do + it "returns a SHA1 object" do + OpenSSL::Digest.new(OpenSSL::Digest::SHA1.new).name.should == "SHA1" + end + + it "returns a SHA256 object" do + OpenSSL::Digest.new(OpenSSL::Digest::SHA256.new).name.should == "SHA256" + end + + it "returns a SHA384 object" do + OpenSSL::Digest.new(OpenSSL::Digest::SHA384.new).name.should == "SHA384" + end + + it "returns a SHA512 object" do + OpenSSL::Digest.new(OpenSSL::Digest::SHA512.new).name.should == "SHA512" + end + + it "ignores the state of the digest object" do + sha1 = OpenSSL::Digest.new('sha1', SHA1Constants::Contents) + OpenSSL::Digest.new(sha1).digest.should == SHA1Constants::BlankDigest + end + end + + it "cannot be called with a digest class" do + -> { OpenSSL::Digest.new(OpenSSL::Digest::SHA1) }.should raise_error(TypeError) + end + + context "when called without an initial String argument" do + it "returns a SHA1 digest" do + OpenSSL::Digest.new("sha1").digest.should == SHA1Constants::BlankDigest + end + + it "returns a SHA256 digest" do + OpenSSL::Digest.new("sha256").digest.should == SHA256Constants::BlankDigest + end + + it "returns a SHA384 digest" do + OpenSSL::Digest.new("sha384").digest.should == SHA384Constants::BlankDigest + end + + it "returns a SHA512 digest" do + OpenSSL::Digest.new("sha512").digest.should == SHA512Constants::BlankDigest + end + end + + context "when called with an initial String argument" do + it "returns a SHA1 digest of that argument" do + OpenSSL::Digest.new("sha1", SHA1Constants::Contents).digest.should == SHA1Constants::Digest + end + + it "returns a SHA256 digest of that argument" do + OpenSSL::Digest.new("sha256", SHA256Constants::Contents).digest.should == SHA256Constants::Digest + end + + it "returns a SHA384 digest of that argument" do + OpenSSL::Digest.new("sha384", SHA384Constants::Contents).digest.should == SHA384Constants::Digest + end + + it "returns a SHA512 digest of that argument" do + OpenSSL::Digest.new("sha512", SHA512Constants::Contents).digest.should == SHA512Constants::Digest + end + end + + context "can be called on subclasses" do + describe "can be called without an initial String argument on subclasses" do + it "returns a SHA1 digest" do + OpenSSL::Digest::SHA1.new.digest.should == SHA1Constants::BlankDigest + end + + it "returns a SHA256 digest" do + OpenSSL::Digest::SHA256.new.digest.should == SHA256Constants::BlankDigest + end + + it "returns a SHA384 digest" do + OpenSSL::Digest::SHA384.new.digest.should == SHA384Constants::BlankDigest + end + + it "returns a SHA512 digest" do + OpenSSL::Digest::SHA512.new.digest.should == SHA512Constants::BlankDigest + end + end + + describe "can be called with an initial String argument on subclasses" do + it "returns a SHA1 digest" do + OpenSSL::Digest::SHA1.new(SHA1Constants::Contents).digest.should == SHA1Constants::Digest + end + + it "returns a SHA256 digest" do + OpenSSL::Digest::SHA256.new(SHA256Constants::Contents).digest.should == SHA256Constants::Digest + end + + it "returns a SHA384 digest" do + OpenSSL::Digest::SHA384.new(SHA384Constants::Contents).digest.should == SHA384Constants::Digest + end + + it "returns a SHA512 digest" do + OpenSSL::Digest::SHA512.new(SHA512Constants::Contents).digest.should == SHA512Constants::Digest + end + end + end +end diff --git a/spec/ruby/library/openssl/digest/name_spec.rb b/spec/ruby/library/openssl/digest/name_spec.rb new file mode 100644 index 0000000000..b379f35c1c --- /dev/null +++ b/spec/ruby/library/openssl/digest/name_spec.rb @@ -0,0 +1,16 @@ +require_relative '../../../spec_helper' +require 'openssl' + +describe "OpenSSL::Digest#name" do + it "returns the name of digest" do + OpenSSL::Digest.new('SHA1').name.should == 'SHA1' + end + + it "converts the name to the internal representation of OpenSSL" do + OpenSSL::Digest.new('sha1').name.should == 'SHA1' + end + + it "works on subclasses too" do + OpenSSL::Digest::SHA1.new.name.should == 'SHA1' + end +end diff --git a/spec/ruby/library/openssl/digest/reset_spec.rb b/spec/ruby/library/openssl/digest/reset_spec.rb new file mode 100644 index 0000000000..c19bf46633 --- /dev/null +++ b/spec/ruby/library/openssl/digest/reset_spec.rb @@ -0,0 +1,36 @@ +require_relative '../../../spec_helper' +require_relative '../../../library/digest/sha1/shared/constants' +require_relative '../../../library/digest/sha256/shared/constants' +require_relative '../../../library/digest/sha384/shared/constants' +require_relative '../../../library/digest/sha512/shared/constants' +require 'openssl' + +describe "OpenSSL::Digest#reset" do + it "works for a SHA1 digest" do + digest = OpenSSL::Digest.new('sha1', SHA1Constants::Contents) + digest.reset + digest.update(SHA1Constants::Contents) + digest.digest.should == SHA1Constants::Digest + end + + it "works for a SHA256 digest" do + digest = OpenSSL::Digest.new('sha256', SHA256Constants::Contents) + digest.reset + digest.update(SHA256Constants::Contents) + digest.digest.should == SHA256Constants::Digest + end + + it "works for a SHA384 digest" do + digest = OpenSSL::Digest.new('sha384', SHA384Constants::Contents) + digest.reset + digest.update(SHA384Constants::Contents) + digest.digest.should == SHA384Constants::Digest + end + + it "works for a SHA512 digest" do + digest = OpenSSL::Digest.new('sha512', SHA512Constants::Contents) + digest.reset + digest.update(SHA512Constants::Contents) + digest.digest.should == SHA512Constants::Digest + end +end diff --git a/spec/ruby/library/openssl/digest/shared/update.rb b/spec/ruby/library/openssl/digest/shared/update.rb new file mode 100644 index 0000000000..e5ff9dcb16 --- /dev/null +++ b/spec/ruby/library/openssl/digest/shared/update.rb @@ -0,0 +1,123 @@ +require_relative '../../../../library/digest/sha1/shared/constants' +require_relative '../../../../library/digest/sha256/shared/constants' +require_relative '../../../../library/digest/sha384/shared/constants' +require_relative '../../../../library/digest/sha512/shared/constants' +require 'openssl' + +describe :openssl_digest_update, shared: true do + context "when given input as a single string" do + it "returns a SHA1 digest" do + digest = OpenSSL::Digest.new('sha1') + digest.send(@method, SHA1Constants::Contents) + digest.digest.should == SHA1Constants::Digest + end + + it "returns a SHA256 digest" do + digest = OpenSSL::Digest.new('sha256') + digest.send(@method, SHA256Constants::Contents) + digest.digest.should == SHA256Constants::Digest + end + + it "returns a SHA384 digest" do + digest = OpenSSL::Digest.new('sha384') + digest.send(@method, SHA384Constants::Contents) + digest.digest.should == SHA384Constants::Digest + end + + it "returns a SHA512 digest" do + digest = OpenSSL::Digest.new('sha512') + digest.send(@method, SHA512Constants::Contents) + digest.digest.should == SHA512Constants::Digest + end + end + + context "when given input as multiple smaller substrings" do + it "returns a SHA1 digest" do + digest = OpenSSL::Digest.new('sha1') + SHA1Constants::Contents.each_char { |b| digest.send(@method, b) } + digest.digest.should == SHA1Constants::Digest + end + + it "returns a SHA256 digest" do + digest = OpenSSL::Digest.new('sha256') + SHA256Constants::Contents.each_char { |b| digest.send(@method, b) } + digest.digest.should == SHA256Constants::Digest + end + + it "returns a SHA384 digest" do + digest = OpenSSL::Digest.new('sha384') + SHA384Constants::Contents.each_char { |b| digest.send(@method, b) } + digest.digest.should == SHA384Constants::Digest + end + + it "returns a SHA512 digest" do + digest = OpenSSL::Digest.new('sha512') + SHA512Constants::Contents.each_char { |b| digest.send(@method, b) } + digest.digest.should == SHA512Constants::Digest + end + end + + context "when input is not a String and responds to #to_str" do + it "returns a SHA1 digest" do + str = mock('str') + str.should_receive(:to_str).and_return(SHA1Constants::Contents) + digest = OpenSSL::Digest.new('sha1') + digest.send(@method, str) + digest.digest.should == SHA1Constants::Digest + end + + it "returns a SHA256 digest" do + str = mock('str') + str.should_receive(:to_str).and_return(SHA256Constants::Contents) + digest = OpenSSL::Digest.new('sha256') + digest.send(@method, str) + digest.digest.should == SHA256Constants::Digest + end + + it "returns a SHA384 digest" do + str = mock('str') + str.should_receive(:to_str).and_return(SHA384Constants::Contents) + digest = OpenSSL::Digest.new('sha384') + digest.send(@method, str) + digest.digest.should == SHA384Constants::Digest + end + + it "returns a SHA512 digest" do + str = mock('str') + str.should_receive(:to_str).and_return(SHA512Constants::Contents) + digest = OpenSSL::Digest.new('sha512') + digest.send(@method, str) + digest.digest.should == SHA512Constants::Digest + end + end + + context "when input is not a String and does not respond to #to_str" do + it "raises a TypeError with SHA1" do + digest = OpenSSL::Digest.new('sha1') + -> { + digest.send(@method, Object.new) + }.should raise_error(TypeError, 'no implicit conversion of Object into String') + end + + it "raises a TypeError with SHA256" do + digest = OpenSSL::Digest.new('sha256') + -> { + digest.send(@method, Object.new) + }.should raise_error(TypeError, 'no implicit conversion of Object into String') + end + + it "raises a TypeError with SHA384" do + digest = OpenSSL::Digest.new('sha384') + -> { + digest.send(@method, Object.new) + }.should raise_error(TypeError, 'no implicit conversion of Object into String') + end + + it "raises a TypeError with SHA512" do + digest = OpenSSL::Digest.new('sha512') + -> { + digest.send(@method, Object.new) + }.should raise_error(TypeError, 'no implicit conversion of Object into String') + end + end +end diff --git a/spec/ruby/library/openssl/digest/update_spec.rb b/spec/ruby/library/openssl/digest/update_spec.rb new file mode 100644 index 0000000000..3a90b06c6b --- /dev/null +++ b/spec/ruby/library/openssl/digest/update_spec.rb @@ -0,0 +1,6 @@ +require_relative '../../../spec_helper' +require_relative 'shared/update' + +describe "OpenSSL::Digest#update" do + it_behaves_like :openssl_digest_update, :update +end diff --git a/spec/ruby/library/openssl/fixed_length_secure_compare_spec.rb b/spec/ruby/library/openssl/fixed_length_secure_compare_spec.rb new file mode 100644 index 0000000000..5a2ca168b5 --- /dev/null +++ b/spec/ruby/library/openssl/fixed_length_secure_compare_spec.rb @@ -0,0 +1,42 @@ +require_relative '../../spec_helper' +require 'openssl' + +describe "OpenSSL.fixed_length_secure_compare" do + it "returns true for two strings with the same content" do + input1 = "the quick brown fox jumps over the lazy dog" + input2 = "the quick brown fox jumps over the lazy dog" + OpenSSL.fixed_length_secure_compare(input1, input2).should be_true + end + + it "returns false for two strings of equal size with different content" do + input1 = "the quick brown fox jumps over the lazy dog" + input2 = "the lazy dog jumps over the quick brown fox" + OpenSSL.fixed_length_secure_compare(input1, input2).should be_false + end + + it "converts both arguments to strings using #to_str" do + input1 = mock("input1") + input1.should_receive(:to_str).and_return("the quick brown fox jumps over the lazy dog") + input2 = mock("input2") + input2.should_receive(:to_str).and_return("the quick brown fox jumps over the lazy dog") + OpenSSL.fixed_length_secure_compare(input1, input2).should be_true + end + + it "does not accept arguments that are not string and cannot be coerced into strings" do + -> { + OpenSSL.fixed_length_secure_compare("input1", :input2) + }.should raise_error(TypeError, 'no implicit conversion of Symbol into String') + + -> { + OpenSSL.fixed_length_secure_compare(Object.new, "input2") + }.should raise_error(TypeError, 'no implicit conversion of Object into String') + end + + it "raises an ArgumentError for two strings of different size" do + input1 = "the quick brown fox jumps over the lazy dog" + input2 = "the quick brown fox" + -> { + OpenSSL.fixed_length_secure_compare(input1, input2) + }.should raise_error(ArgumentError, 'inputs must be of equal length') + end +end diff --git a/spec/ruby/library/openssl/kdf/pbkdf2_hmac_spec.rb b/spec/ruby/library/openssl/kdf/pbkdf2_hmac_spec.rb new file mode 100644 index 0000000000..1112972060 --- /dev/null +++ b/spec/ruby/library/openssl/kdf/pbkdf2_hmac_spec.rb @@ -0,0 +1,162 @@ +require_relative '../../../spec_helper' +require 'openssl' + +describe "OpenSSL::KDF.pbkdf2_hmac" do + before :each do + @defaults = { + salt: "\x00".b * 16, + iterations: 20_000, + length: 16, + hash: "sha1" + } + end + + it "creates the same value with the same input" do + key = OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults) + key.should == "!\x99+\xF0^\xD0\x8BM\x158\xC4\xAC\x9C\xF1\xF0\xE0".b + end + + it "supports nullbytes embedded in the password" do + key = OpenSSL::KDF.pbkdf2_hmac("sec\x00ret".b, **@defaults) + key.should == "\xB9\x7F\xB0\xC2\th\xC8<\x86\xF3\x94Ij7\xEF\xF1".b + end + + it "coerces the password into a String using #to_str" do + pass = mock("pass") + pass.should_receive(:to_str).and_return("secret") + key = OpenSSL::KDF.pbkdf2_hmac(pass, **@defaults) + key.should == "!\x99+\xF0^\xD0\x8BM\x158\xC4\xAC\x9C\xF1\xF0\xE0".b + end + + it "coerces the salt into a String using #to_str" do + salt = mock("salt") + salt.should_receive(:to_str).and_return("\x00".b * 16) + key = OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults, salt: salt) + key.should == "!\x99+\xF0^\xD0\x8BM\x158\xC4\xAC\x9C\xF1\xF0\xE0".b + end + + it "coerces the iterations into an Integer using #to_int" do + iterations = mock("iterations") + iterations.should_receive(:to_int).and_return(20_000) + key = OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults, iterations: iterations) + key.should == "!\x99+\xF0^\xD0\x8BM\x158\xC4\xAC\x9C\xF1\xF0\xE0".b + end + + it "coerces the length into an Integer using #to_int" do + length = mock("length") + length.should_receive(:to_int).and_return(16) + key = OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults, length: length) + key.should == "!\x99+\xF0^\xD0\x8BM\x158\xC4\xAC\x9C\xF1\xF0\xE0".b + end + + it "accepts a OpenSSL::Digest object as hash" do + hash = OpenSSL::Digest.new("sha1") + key = OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults, hash: hash) + key.should == "!\x99+\xF0^\xD0\x8BM\x158\xC4\xAC\x9C\xF1\xF0\xE0".b + end + + it "accepts an empty password" do + key = OpenSSL::KDF.pbkdf2_hmac("", **@defaults) + key.should == "k\x9F-\xB1\xF7\x9A\v\xA1(C\xF9\x85!P\xEF\x8C".b + end + + it "accepts an empty salt" do + key = OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults, salt: "") + key.should == "\xD5f\xE5\xEA\xF91\x1D\xD3evD\xED\xDB\xE80\x80".b + end + + it "accepts an empty length" do + key = OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults, length: 0) + key.should.empty? + end + + it "accepts an arbitrary length" do + key = OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults, length: 19) + key.should == "!\x99+\xF0^\xD0\x8BM\x158\xC4\xAC\x9C\xF1\xF0\xE0\xCF\xBB\x7F".b + end + + it "accepts any hash function known to OpenSSL" do + key = OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults, hash: "sha512") + key.should == "N\x12}D\xCE\x99\xDBC\x8E\xEC\xAAr\xEA1\xDF\xFF".b + end + + it "raises a TypeError when password is not a String and does not respond to #to_str" do + -> { + OpenSSL::KDF.pbkdf2_hmac(Object.new, **@defaults) + }.should raise_error(TypeError, "no implicit conversion of Object into String") + end + + it "raises a TypeError when salt is not a String and does not respond to #to_str" do + -> { + OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults, salt: Object.new) + }.should raise_error(TypeError, "no implicit conversion of Object into String") + end + + it "raises a TypeError when iterations is not an Integer and does not respond to #to_int" do + -> { + OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults, iterations: Object.new) + }.should raise_error(TypeError, "no implicit conversion of Object into Integer") + end + + it "raises a TypeError when length is not an Integer and does not respond to #to_int" do + -> { + OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults, length: Object.new) + }.should raise_error(TypeError, "no implicit conversion of Object into Integer") + end + + it "raises a TypeError when hash is neither a String nor an OpenSSL::Digest" do + -> { + OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults, hash: Object.new) + }.should raise_error(TypeError) + end + + version_is OpenSSL::VERSION, "4.0.0" do + it "raises a OpenSSL::Digest::DigestError for unknown digest algorithms" do + -> { + OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults, hash: "wd40") + }.should raise_error(OpenSSL::Digest::DigestError, /wd40/) + end + end + + it "treats salt as a required keyword" do + -> { + OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults.except(:salt)) + }.should raise_error(ArgumentError, 'missing keyword: :salt') + end + + it "treats iterations as a required keyword" do + -> { + OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults.except(:iterations)) + }.should raise_error(ArgumentError, 'missing keyword: :iterations') + end + + it "treats length as a required keyword" do + -> { + OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults.except(:length)) + }.should raise_error(ArgumentError, 'missing keyword: :length') + end + + it "treats hash as a required keyword" do + -> { + OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults.except(:hash)) + }.should raise_error(ArgumentError, 'missing keyword: :hash') + end + + it "treats all keywords as required" do + -> { + OpenSSL::KDF.pbkdf2_hmac("secret") + }.should raise_error(ArgumentError, 'missing keywords: :salt, :iterations, :length, :hash') + end + + guard -> { OpenSSL::OPENSSL_VERSION_NUMBER >= 0x30000000 } do + it "raises an OpenSSL::KDF::KDFError for 0 or less iterations" do + -> { + OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults, iterations: 0) + }.should raise_error(OpenSSL::KDF::KDFError, "PKCS5_PBKDF2_HMAC: invalid iteration count") + + -> { + OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults, iterations: -1) + }.should raise_error(OpenSSL::KDF::KDFError, /PKCS5_PBKDF2_HMAC/) + end + end +end diff --git a/spec/ruby/library/openssl/kdf/scrypt_spec.rb b/spec/ruby/library/openssl/kdf/scrypt_spec.rb new file mode 100644 index 0000000000..e01b8bca8a --- /dev/null +++ b/spec/ruby/library/openssl/kdf/scrypt_spec.rb @@ -0,0 +1,210 @@ +require_relative '../../../spec_helper' +require 'openssl' + +# LibreSSL seems not to support scrypt +guard -> { OpenSSL::OPENSSL_VERSION.start_with?('OpenSSL') and OpenSSL::OPENSSL_VERSION_NUMBER >= 0x10100000 } do + describe "OpenSSL::KDF.scrypt" do + before :each do + @defaults = { + salt: "\x00".b * 16, + N: 2**14, + r: 8, + p: 1, + length: 32 + } + end + + it "creates the same value with the same input" do + key = OpenSSL::KDF.scrypt("secret", **@defaults) + key.should == "h\xB2k\xDF]\xDA\xE1.-(\xCF\xAC\x91D\x8F\xC2a\x9C\x9D\x17}\xF2\x84T\xD4)\xC2>\xFE\x93\xE3\xF4".b + end + + it "supports nullbytes embedded into the password" do + key = OpenSSL::KDF.scrypt("sec\x00ret".b, **@defaults) + key.should == "\xF9\xA4\xA0\xF1p\xF4\xF0\xCAT\xB4v\xEB\r7\x88N\xF7\x15]Ns\xFCwt4a\xC9\xC6\xA7\x13\x81&".b + end + + it "coerces the password into a String using #to_str" do + pass = mock("pass") + pass.should_receive(:to_str).and_return("secret") + key = OpenSSL::KDF.scrypt(pass, **@defaults) + key.should == "h\xB2k\xDF]\xDA\xE1.-(\xCF\xAC\x91D\x8F\xC2a\x9C\x9D\x17}\xF2\x84T\xD4)\xC2>\xFE\x93\xE3\xF4".b + end + + it "coerces the salt into a String using #to_str" do + salt = mock("salt") + salt.should_receive(:to_str).and_return("\x00".b * 16) + key = OpenSSL::KDF.scrypt("secret", **@defaults, salt: salt) + key.should == "h\xB2k\xDF]\xDA\xE1.-(\xCF\xAC\x91D\x8F\xC2a\x9C\x9D\x17}\xF2\x84T\xD4)\xC2>\xFE\x93\xE3\xF4".b + end + + it "coerces the N into an Integer using #to_int" do + n = mock("N") + n.should_receive(:to_int).and_return(2**14) + key = OpenSSL::KDF.scrypt("secret", **@defaults, N: n) + key.should == "h\xB2k\xDF]\xDA\xE1.-(\xCF\xAC\x91D\x8F\xC2a\x9C\x9D\x17}\xF2\x84T\xD4)\xC2>\xFE\x93\xE3\xF4".b + end + + it "coerces the r into an Integer using #to_int" do + r = mock("r") + r.should_receive(:to_int).and_return(8) + key = OpenSSL::KDF.scrypt("secret", **@defaults, r: r) + key.should == "h\xB2k\xDF]\xDA\xE1.-(\xCF\xAC\x91D\x8F\xC2a\x9C\x9D\x17}\xF2\x84T\xD4)\xC2>\xFE\x93\xE3\xF4".b + end + + it "coerces the p into an Integer using #to_int" do + p = mock("p") + p.should_receive(:to_int).and_return(1) + key = OpenSSL::KDF.scrypt("secret", **@defaults, p: p) + key.should == "h\xB2k\xDF]\xDA\xE1.-(\xCF\xAC\x91D\x8F\xC2a\x9C\x9D\x17}\xF2\x84T\xD4)\xC2>\xFE\x93\xE3\xF4".b + end + + it "coerces the length into an Integer using #to_int" do + length = mock("length") + length.should_receive(:to_int).and_return(32) + key = OpenSSL::KDF.scrypt("secret", **@defaults, length: length) + key.should == "h\xB2k\xDF]\xDA\xE1.-(\xCF\xAC\x91D\x8F\xC2a\x9C\x9D\x17}\xF2\x84T\xD4)\xC2>\xFE\x93\xE3\xF4".b + end + + it "accepts an empty password" do + key = OpenSSL::KDF.scrypt("", **@defaults) + key.should == "\xAA\xFC\xF5^E\x94v\xFFk\xE6\xF0vR\xE7\x13\xA7\xF5\x15'\x9A\xE4C\x9Dn\x18F_E\xD2\v\e\xB3".b + end + + it "accepts an empty salt" do + key = OpenSSL::KDF.scrypt("secret", **@defaults, salt: "") + key.should == "\x96\xACDl\xCB3/aN\xB0F\x8A#\xD7\x92\xD2O\x1E\v\xBB\xCE\xC0\xAA\xB9\x0F]\xB09\xEA8\xDD\e".b + end + + it "accepts a zero length" do + key = OpenSSL::KDF.scrypt("secret", **@defaults, length: 0) + key.should.empty? + end + + it "accepts an arbitrary length" do + key = OpenSSL::KDF.scrypt("secret", **@defaults, length: 19) + key.should == "h\xB2k\xDF]\xDA\xE1.-(\xCF\xAC\x91D\x8F\xC2a\x9C\x9D".b + end + + it "raises a TypeError when password is not a String and does not respond to #to_str" do + -> { + OpenSSL::KDF.scrypt(Object.new, **@defaults) + }.should raise_error(TypeError, "no implicit conversion of Object into String") + end + + it "raises a TypeError when salt is not a String and does not respond to #to_str" do + -> { + OpenSSL::KDF.scrypt("secret", **@defaults, salt: Object.new) + }.should raise_error(TypeError, "no implicit conversion of Object into String") + end + + it "raises a TypeError when N is not an Integer and does not respond to #to_int" do + -> { + OpenSSL::KDF.scrypt("secret", **@defaults, N: Object.new) + }.should raise_error(TypeError, "no implicit conversion of Object into Integer") + end + + it "raises a TypeError when r is not an Integer and does not respond to #to_int" do + -> { + OpenSSL::KDF.scrypt("secret", **@defaults, r: Object.new) + }.should raise_error(TypeError, "no implicit conversion of Object into Integer") + end + + it "raises a TypeError when p is not an Integer and does not respond to #to_int" do + -> { + OpenSSL::KDF.scrypt("secret", **@defaults, p: Object.new) + }.should raise_error(TypeError, "no implicit conversion of Object into Integer") + end + + it "raises a TypeError when length is not an Integer and does not respond to #to_int" do + -> { + OpenSSL::KDF.scrypt("secret", **@defaults, length: Object.new) + }.should raise_error(TypeError, "no implicit conversion of Object into Integer") + end + + it "treats salt as a required keyword" do + -> { + OpenSSL::KDF.scrypt("secret", **@defaults.except(:salt)) + }.should raise_error(ArgumentError, 'missing keyword: :salt') + end + + it "treats N as a required keyword" do + -> { + OpenSSL::KDF.scrypt("secret", **@defaults.except(:N)) + }.should raise_error(ArgumentError, 'missing keyword: :N') + end + + it "treats r as a required keyword" do + -> { + OpenSSL::KDF.scrypt("secret", **@defaults.except(:r)) + }.should raise_error(ArgumentError, 'missing keyword: :r') + end + + it "treats p as a required keyword" do + -> { + OpenSSL::KDF.scrypt("secret", **@defaults.except(:p)) + }.should raise_error(ArgumentError, 'missing keyword: :p') + end + + it "treats length as a required keyword" do + -> { + OpenSSL::KDF.scrypt("secret", **@defaults.except(:length)) + }.should raise_error(ArgumentError, 'missing keyword: :length') + end + + it "treats all keywords as required" do + -> { + OpenSSL::KDF.scrypt("secret") + }.should raise_error(ArgumentError, 'missing keywords: :salt, :N, :r, :p, :length') + end + + it "requires N to be a power of 2" do + -> { + OpenSSL::KDF.scrypt("secret", **@defaults, N: 2**14 - 1) + }.should raise_error(OpenSSL::KDF::KDFError, /EVP_PBE_scrypt/) + end + + it "requires N to be at least 2" do + key = OpenSSL::KDF.scrypt("secret", **@defaults, N: 2) + key.should == "\x06A$a\xA9!\xBE\x01\x85\xA7\x18\xBCEa\x82\xC5\xFEl\x93\xAB\xBD\xF7\x8B\x84\v\xFC\eN\xEBQ\xE6\xD2".b + + -> { + OpenSSL::KDF.scrypt("secret", **@defaults, N: 1) + }.should raise_error(OpenSSL::KDF::KDFError, /EVP_PBE_scrypt/) + + -> { + OpenSSL::KDF.scrypt("secret", **@defaults, N: 0) + }.should raise_error(OpenSSL::KDF::KDFError, /EVP_PBE_scrypt/) + + -> { + OpenSSL::KDF.scrypt("secret", **@defaults, N: -1) + }.should raise_error(OpenSSL::KDF::KDFError, /EVP_PBE_scrypt/) + end + + it "requires r to be positive" do + -> { + OpenSSL::KDF.scrypt("secret", **@defaults, r: 0) + }.should raise_error(OpenSSL::KDF::KDFError, /EVP_PBE_scrypt/) + + -> { + OpenSSL::KDF.scrypt("secret", **@defaults, r: -1) + }.should raise_error(OpenSSL::KDF::KDFError, /EVP_PBE_scrypt/) + end + + it "requires p to be positive" do + -> { + OpenSSL::KDF.scrypt("secret", **@defaults, p: 0) + }.should raise_error(OpenSSL::KDF::KDFError, /EVP_PBE_scrypt/) + + -> { + OpenSSL::KDF.scrypt("secret", **@defaults, p: -1) + }.should raise_error(OpenSSL::KDF::KDFError, /EVP_PBE_scrypt/) + end + + it "requires length to be not negative" do + -> { + OpenSSL::KDF.scrypt("secret", **@defaults, length: -1) + }.should raise_error(ArgumentError, "negative string size (or size too big)") + end + end +end diff --git a/spec/ruby/library/openssl/random/shared/random_bytes.rb b/spec/ruby/library/openssl/random/shared/random_bytes.rb index 037f10d409..f97ccd9974 100644 --- a/spec/ruby/library/openssl/random/shared/random_bytes.rb +++ b/spec/ruby/library/openssl/random/shared/random_bytes.rb @@ -1,7 +1,7 @@ require_relative '../../../../spec_helper' require 'openssl' -describe :openssl_random_bytes, shared: true do |cmd| +describe :openssl_random_bytes, shared: true do it "generates a random binary string of specified length" do (1..64).each do |idx| bytes = OpenSSL::Random.send(@method, idx) diff --git a/spec/ruby/library/openssl/secure_compare_spec.rb b/spec/ruby/library/openssl/secure_compare_spec.rb new file mode 100644 index 0000000000..cec48e01e7 --- /dev/null +++ b/spec/ruby/library/openssl/secure_compare_spec.rb @@ -0,0 +1,38 @@ +require_relative '../../spec_helper' +require 'openssl' + +describe "OpenSSL.secure_compare" do + it "returns true for two strings with the same content" do + input1 = "the quick brown fox jumps over the lazy dog" + input2 = "the quick brown fox jumps over the lazy dog" + OpenSSL.secure_compare(input1, input2).should be_true + end + + it "returns false for two strings with different content" do + input1 = "the quick brown fox jumps over the lazy dog" + input2 = "the lazy dog jumps over the quick brown fox" + OpenSSL.secure_compare(input1, input2).should be_false + end + + it "converts both arguments to strings using #to_str, but adds equality check for the original objects" do + input1 = mock("input1") + input1.should_receive(:to_str).and_return("the quick brown fox jumps over the lazy dog") + input2 = mock("input2") + input2.should_receive(:to_str).and_return("the quick brown fox jumps over the lazy dog") + OpenSSL.secure_compare(input1, input2).should be_false + + input = mock("input") + input.should_receive(:to_str).twice.and_return("the quick brown fox jumps over the lazy dog") + OpenSSL.secure_compare(input, input).should be_true + end + + it "does not accept arguments that are not string and cannot be coerced into strings" do + -> { + OpenSSL.secure_compare("input1", :input2) + }.should raise_error(TypeError, 'no implicit conversion of Symbol into String') + + -> { + OpenSSL.secure_compare(Object.new, "input2") + }.should raise_error(TypeError, 'no implicit conversion of Object into String') + end +end diff --git a/spec/ruby/library/openssl/shared/constants.rb b/spec/ruby/library/openssl/shared/constants.rb index 0bed4156a1..836f75011b 100644 --- a/spec/ruby/library/openssl/shared/constants.rb +++ b/spec/ruby/library/openssl/shared/constants.rb @@ -1,4 +1,4 @@ -# -*- encoding: binary -*- +# encoding: binary module HMACConstants Contents = "Ipsum is simply dummy text of the printing and typesetting industry. \nLorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. \nIt has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. \nIt was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum." diff --git a/spec/ruby/library/openssl/x509/name/verify_spec.rb b/spec/ruby/library/openssl/x509/store/verify_spec.rb index 6dcfc99466..6a6a53d992 100644 --- a/spec/ruby/library/openssl/x509/name/verify_spec.rb +++ b/spec/ruby/library/openssl/x509/store/verify_spec.rb @@ -1,7 +1,7 @@ require_relative '../../../../spec_helper' require 'openssl' -describe "OpenSSL::X509::Name.verify" do +describe "OpenSSL::X509::Store#verify" do it "returns true for valid certificate" do key = OpenSSL::PKey::RSA.new 2048 cert = OpenSSL::X509::Certificate.new diff --git a/spec/ruby/library/pathname/glob_spec.rb b/spec/ruby/library/pathname/glob_spec.rb index ced810fa90..de322bab47 100644 --- a/spec/ruby/library/pathname/glob_spec.rb +++ b/spec/ruby/library/pathname/glob_spec.rb @@ -21,6 +21,10 @@ describe 'Pathname.glob' do Pathname.glob(@dir + 'lib/*.js').should == [] end + it 'returns [] when the pathname does not exist' do + Pathname.glob('i_dont_exist/lib/*.js').should == [] + end + it 'returns matching file paths' do Pathname.glob(@dir + 'lib/*i*.rb').sort.should == [Pathname.new(@file_1), Pathname.new(@file_2)].sort end @@ -67,6 +71,10 @@ describe 'Pathname#glob' do Pathname.new(@dir).glob('lib/*.js').should == [] end + it 'returns [] when the pathname does not exist' do + Pathname.new('./i_dont_exist').glob('lib/*.js').should == [] + end + it 'returns matching file paths' do Pathname.new(@dir).glob('lib/*i*.rb').sort.should == [Pathname.new(@file_1), Pathname.new(@file_2)].sort end diff --git a/spec/ruby/library/pathname/relative_path_from_spec.rb b/spec/ruby/library/pathname/relative_path_from_spec.rb index abe9c80a45..133a149849 100644 --- a/spec/ruby/library/pathname/relative_path_from_spec.rb +++ b/spec/ruby/library/pathname/relative_path_from_spec.rb @@ -48,4 +48,8 @@ describe "Pathname#relative_path_from" do relative_path_str('..', '..').should == '.' relative_path_str('..', '.').should == '..' end + + it 'converts string argument to Pathname' do + Pathname.new('/usr/bin/ls').relative_path_from('/usr').to_s.should == 'bin/ls' + end end diff --git a/spec/ruby/library/pp/pp_spec.rb b/spec/ruby/library/pp/pp_spec.rb index 243478efd9..e45a6bb94f 100644 --- a/spec/ruby/library/pp/pp_spec.rb +++ b/spec/ruby/library/pp/pp_spec.rb @@ -25,6 +25,6 @@ describe "PP.pp" do hash = { 'key' => 42 } -> { PP.pp hash - }.should output('{"key"=>42}' + "\n") + }.should output("#{hash.inspect}\n") end end diff --git a/spec/ruby/library/prime/each_spec.rb b/spec/ruby/library/prime/each_spec.rb index c89e871582..b99cf7cf0e 100644 --- a/spec/ruby/library/prime/each_spec.rb +++ b/spec/ruby/library/prime/each_spec.rb @@ -1,170 +1,167 @@ require_relative '../../spec_helper' +require 'prime' -ruby_version_is ""..."3.1" do - require 'prime' - - describe :prime_each, shared: true do - before :each do - ScratchPad.record [] - end +describe :prime_each, shared: true do + before :each do + ScratchPad.record [] + end - it "enumerates primes" do - primes = Prime.instance - result = [] + it "enumerates primes" do + primes = Prime.instance + result = [] - primes.each { |p| - result << p - break if p > 10 - } + primes.each { |p| + result << p + break if p > 10 + } - result.should == [2, 3, 5, 7, 11] - end + result.should == [2, 3, 5, 7, 11] + end - it "yields ascending primes to the block" do - previous = 1 - @object.each do |prime| - break if prime > 1000 - ScratchPad << prime - prime.should > previous - previous = prime - end - - all_prime = true - ScratchPad.recorded.all? do |prime| - all_prime &&= (2..Math.sqrt(prime)).all? { |d| prime % d != 0 } - end - - all_prime.should be_true + it "yields ascending primes to the block" do + previous = 1 + @object.each do |prime| + break if prime > 1000 + ScratchPad << prime + prime.should > previous + previous = prime end - it "returns the last evaluated expression in the passed block" do - @object.each { break :value }.should equal(:value) + all_prime = true + ScratchPad.recorded.all? do |prime| + all_prime &&= (2..Math.sqrt(prime)).all? { |d| prime % d != 0 } end - describe "when not passed a block" do - before :each do - @prime_enum = @object.each - end - - it "returns an object that is Enumerable" do - @prime_enum.each.should be_kind_of(Enumerable) - end - - it "returns an object that responds to #with_index" do - @prime_enum.should respond_to(:with_index) - end + all_prime.should be_true + end - it "returns an object that responds to #with_object" do - @prime_enum.should respond_to(:with_object) - end + it "returns the last evaluated expression in the passed block" do + @object.each { break :value }.should equal(:value) + end - it "returns an object that responds to #next" do - @prime_enum.should respond_to(:next) - end + describe "when not passed a block" do + before :each do + @prime_enum = @object.each + end - it "returns an object that responds to #rewind" do - @prime_enum.should respond_to(:rewind) - end + it "returns an object that is Enumerable" do + @prime_enum.each.should be_kind_of(Enumerable) + end - it "yields primes starting at 2 independent of prior enumerators" do - @prime_enum.next.should == 2 - @prime_enum.next.should == 3 + it "returns an object that responds to #with_index" do + @prime_enum.should respond_to(:with_index) + end - @object.each { |prime| break prime }.should == 2 - end + it "returns an object that responds to #with_object" do + @prime_enum.should respond_to(:with_object) + end - it "returns an enumerator that yields previous primes when #rewind is called" do - @prime_enum.next.should == 2 - @prime_enum.next.should == 3 - @prime_enum.rewind - @prime_enum.next.should == 2 - end + it "returns an object that responds to #next" do + @prime_enum.should respond_to(:next) + end - it "returns independent enumerators" do - enum = @object.each - enum.next.should == 2 - enum.next.should == 3 + it "returns an object that responds to #rewind" do + @prime_enum.should respond_to(:rewind) + end - @prime_enum.next.should == 2 + it "yields primes starting at 2 independent of prior enumerators" do + @prime_enum.next.should == 2 + @prime_enum.next.should == 3 - enum.next.should == 5 - end + @object.each { |prime| break prime }.should == 2 end - end - describe :prime_each_with_arguments, shared: true do - before :each do - ScratchPad.record [] + it "returns an enumerator that yields previous primes when #rewind is called" do + @prime_enum.next.should == 2 + @prime_enum.next.should == 3 + @prime_enum.rewind + @prime_enum.next.should == 2 end - it "yields ascending primes less than or equal to the argument" do - bound = 1000 - previous = 1 - @object.each(bound) do |prime| - ScratchPad << prime - prime.should > previous - previous = prime - end + it "returns independent enumerators" do + enum = @object.each + enum.next.should == 2 + enum.next.should == 3 - ScratchPad.recorded.all? do |prime| - (2..Math.sqrt(prime)).all? { |d| prime % d != 0 } - end.should be_true + @prime_enum.next.should == 2 - ScratchPad.recorded.all? { |prime| prime <= bound }.should be_true + enum.next.should == 5 end + end +end - it "returns nil when no prime is generated" do - @object.each(1) { :value }.should be_nil - end +describe :prime_each_with_arguments, shared: true do + before :each do + ScratchPad.record [] + end - it "yields primes starting at 2 independent of prior enumeration" do - @object.each(10) { |prime| prime }.should == 7 - @object.each(10) { |prime| break prime }.should == 2 + it "yields ascending primes less than or equal to the argument" do + bound = 1000 + previous = 1 + @object.each(bound) do |prime| + ScratchPad << prime + prime.should > previous + previous = prime end - it "accepts a pseudo-prime generator as the second argument" do - generator = mock('very bad pseudo-prime generator') - generator.should_receive(:upper_bound=).with(100) - generator.should_receive(:each).and_yield(2).and_yield(3).and_yield(4) - - @object.each(100, generator) { |prime| ScratchPad << prime } - ScratchPad.recorded.should == [2, 3, 4] - end + ScratchPad.recorded.all? do |prime| + (2..Math.sqrt(prime)).all? { |d| prime % d != 0 } + end.should be_true - describe "when not passed a block" do - it "returns an object that returns primes less than or equal to the bound" do - bound = 100 - @object.each(bound).all? { |prime| prime <= bound }.should be_true - end - end + ScratchPad.recorded.all? { |prime| prime <= bound }.should be_true end - describe "Prime.each" do - it_behaves_like :prime_each, :each, Prime + it "returns nil when no prime is generated" do + @object.each(1) { :value }.should be_nil end - describe "Prime.each" do - it_behaves_like :prime_each_with_arguments, :each, Prime + it "yields primes starting at 2 independent of prior enumeration" do + @object.each(10) { |prime| prime }.should == 7 + @object.each(10) { |prime| break prime }.should == 2 end - describe "Prime#each with Prime.instance" do - it_behaves_like :prime_each, :each, Prime.instance - end + it "accepts a pseudo-prime generator as the second argument" do + generator = mock('very bad pseudo-prime generator') + generator.should_receive(:upper_bound=).with(100) + generator.should_receive(:each).and_yield(2).and_yield(3).and_yield(4) - describe "Prime#each with Prime.instance" do - it_behaves_like :prime_each_with_arguments, :each, Prime.instance + @object.each(100, generator) { |prime| ScratchPad << prime } + ScratchPad.recorded.should == [2, 3, 4] end - describe "Prime#each with Prime.instance" do - before :each do - @object = Prime.instance + describe "when not passed a block" do + it "returns an object that returns primes less than or equal to the bound" do + bound = 100 + @object.each(bound).all? { |prime| prime <= bound }.should be_true end + end +end - it_behaves_like :prime_each, :each +describe "Prime.each" do + it_behaves_like :prime_each, :each, Prime +end - it "resets the enumerator with each call" do - @object.each { |prime| break if prime > 10 } - @object.each { |prime| break prime }.should == 2 - end +describe "Prime.each" do + it_behaves_like :prime_each_with_arguments, :each, Prime +end + +describe "Prime#each with Prime.instance" do + it_behaves_like :prime_each, :each, Prime.instance +end + +describe "Prime#each with Prime.instance" do + it_behaves_like :prime_each_with_arguments, :each, Prime.instance +end + +describe "Prime#each with Prime.instance" do + before :each do + @object = Prime.instance + end + + it_behaves_like :prime_each, :each + + it "resets the enumerator with each call" do + @object.each { |prime| break if prime > 10 } + @object.each { |prime| break prime }.should == 2 end end diff --git a/spec/ruby/library/prime/instance_spec.rb b/spec/ruby/library/prime/instance_spec.rb index 82f21913b7..5183f36901 100644 --- a/spec/ruby/library/prime/instance_spec.rb +++ b/spec/ruby/library/prime/instance_spec.rb @@ -1,24 +1,21 @@ require_relative '../../spec_helper' +require 'prime' -ruby_version_is ""..."3.1" do - require 'prime' - - describe "Prime.instance" do - it "returns a object representing the set of prime numbers" do - Prime.instance.should be_kind_of(Prime) - end +describe "Prime.instance" do + it "returns a object representing the set of prime numbers" do + Prime.instance.should be_kind_of(Prime) + end - it "returns a object with no obsolete features" do - Prime.instance.should_not respond_to(:succ) - Prime.instance.should_not respond_to(:next) - end + it "returns a object with no obsolete features" do + Prime.instance.should_not respond_to(:succ) + Prime.instance.should_not respond_to(:next) + end - it "does not complain anything" do - -> { Prime.instance }.should_not complain - end + it "does not complain anything" do + -> { Prime.instance }.should_not complain + end - it "raises a ArgumentError when is called with some arguments" do - -> { Prime.instance(1) }.should raise_error(ArgumentError) - end + it "raises a ArgumentError when is called with some arguments" do + -> { Prime.instance(1) }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/library/prime/int_from_prime_division_spec.rb b/spec/ruby/library/prime/int_from_prime_division_spec.rb index 5c881aefa1..5abb7221df 100644 --- a/spec/ruby/library/prime/int_from_prime_division_spec.rb +++ b/spec/ruby/library/prime/int_from_prime_division_spec.rb @@ -1,16 +1,13 @@ require_relative '../../spec_helper' +require 'prime' -ruby_version_is ""..."3.1" do - require 'prime' - - describe "Prime.int_from_prime_division" do - it "returns the product of the given factorization" do - Prime.int_from_prime_division([[2,3], [3,3], [5,3], [7,3], [11,3], [13,3], [17,3]]). - should == 2**3 * 3**3 * 5**3 * 7**3 * 11**3 * 13**3 * 17**3 - end +describe "Prime.int_from_prime_division" do + it "returns the product of the given factorization" do + Prime.int_from_prime_division([[2,3], [3,3], [5,3], [7,3], [11,3], [13,3], [17,3]]). + should == 2**3 * 3**3 * 5**3 * 7**3 * 11**3 * 13**3 * 17**3 + end - it "returns 1 for an empty factorization" do - Prime.int_from_prime_division([]).should == 1 - end + it "returns 1 for an empty factorization" do + Prime.int_from_prime_division([]).should == 1 end end diff --git a/spec/ruby/library/prime/integer/each_prime_spec.rb b/spec/ruby/library/prime/integer/each_prime_spec.rb index 6034802e73..a71296b0df 100644 --- a/spec/ruby/library/prime/integer/each_prime_spec.rb +++ b/spec/ruby/library/prime/integer/each_prime_spec.rb @@ -1,16 +1,13 @@ require_relative '../../../spec_helper' +require 'prime' -ruby_version_is ""..."3.1" do - require 'prime' - - describe "Integer.each_prime" do - it "is transferred to Prime.each" do - Prime.should_receive(:each).with(100).and_yield(2).and_yield(3).and_yield(5) - yielded = [] - Integer.each_prime(100) do |prime| - yielded << prime - end - yielded.should == [2,3,5] +describe "Integer.each_prime" do + it "is transferred to Prime.each" do + Prime.should_receive(:each).with(100).and_yield(2).and_yield(3).and_yield(5) + yielded = [] + Integer.each_prime(100) do |prime| + yielded << prime end + yielded.should == [2,3,5] end end diff --git a/spec/ruby/library/prime/integer/from_prime_division_spec.rb b/spec/ruby/library/prime/integer/from_prime_division_spec.rb index 5422bc651c..e0e74fb336 100644 --- a/spec/ruby/library/prime/integer/from_prime_division_spec.rb +++ b/spec/ruby/library/prime/integer/from_prime_division_spec.rb @@ -1,16 +1,13 @@ require_relative '../../../spec_helper' +require 'prime' -ruby_version_is ""..."3.1" do - require 'prime' - - describe "Integer.from_prime_division" do - it "returns the product of the given factorization" do - Integer.from_prime_division([[2,3], [3,3], [5,3], [7,3], [11,3], [13,3], [17,3]]). - should == 2**3 * 3**3 * 5**3 * 7**3 * 11**3 * 13**3 * 17**3 - end +describe "Integer.from_prime_division" do + it "returns the product of the given factorization" do + Integer.from_prime_division([[2,3], [3,3], [5,3], [7,3], [11,3], [13,3], [17,3]]). + should == 2**3 * 3**3 * 5**3 * 7**3 * 11**3 * 13**3 * 17**3 + end - it "returns 1 for an empty factorization" do - Integer.from_prime_division([]).should == 1 - end + it "returns 1 for an empty factorization" do + Integer.from_prime_division([]).should == 1 end end diff --git a/spec/ruby/library/prime/integer/prime_division_spec.rb b/spec/ruby/library/prime/integer/prime_division_spec.rb index 03be0be27b..be03438a6f 100644 --- a/spec/ruby/library/prime/integer/prime_division_spec.rb +++ b/spec/ruby/library/prime/integer/prime_division_spec.rb @@ -1,22 +1,19 @@ require_relative '../../../spec_helper' +require 'prime' -ruby_version_is ""..."3.1" do - require 'prime' - - describe "Integer#prime_division" do - it "returns an array of a prime factor and a corresponding exponent" do - (2*3*5*7*11*13*17).prime_division.should == - [[2,1], [3,1], [5,1], [7,1], [11,1], [13,1], [17,1]] - end +describe "Integer#prime_division" do + it "returns an array of a prime factor and a corresponding exponent" do + (2*3*5*7*11*13*17).prime_division.should == + [[2,1], [3,1], [5,1], [7,1], [11,1], [13,1], [17,1]] + end - it "returns an empty array for 1" do - 1.prime_division.should == [] - end - it "returns an empty array for -1" do - -1.prime_division.should == [[-1, 1]] - end - it "raises ZeroDivisionError for 0" do - -> { 0.prime_division }.should raise_error(ZeroDivisionError) - end + it "returns an empty array for 1" do + 1.prime_division.should == [] + end + it "returns an empty array for -1" do + -1.prime_division.should == [[-1, 1]] + end + it "raises ZeroDivisionError for 0" do + -> { 0.prime_division }.should raise_error(ZeroDivisionError) end end diff --git a/spec/ruby/library/prime/integer/prime_spec.rb b/spec/ruby/library/prime/integer/prime_spec.rb index 65b779e319..53de76d5ab 100644 --- a/spec/ruby/library/prime/integer/prime_spec.rb +++ b/spec/ruby/library/prime/integer/prime_spec.rb @@ -1,20 +1,17 @@ require_relative '../../../spec_helper' +require 'prime' -ruby_version_is ""..."3.1" do - require 'prime' - - describe "Integer#prime?" do - it "returns a true value for prime numbers" do - 2.prime?.should be_true - 3.prime?.should be_true - (2**31-1).prime?.should be_true # 8th Mersenne prime (M8) - end +describe "Integer#prime?" do + it "returns a true value for prime numbers" do + 2.prime?.should be_true + 3.prime?.should be_true + (2**31-1).prime?.should be_true # 8th Mersenne prime (M8) + end - it "returns a false value for composite numbers" do - 4.prime?.should be_false - 15.prime?.should be_false - (2**32-1).prime?.should be_false - ( (2**17-1)*(2**19-1) ).prime?.should be_false # M6*M7 - end + it "returns a false value for composite numbers" do + 4.prime?.should be_false + 15.prime?.should be_false + (2**32-1).prime?.should be_false + ( (2**17-1)*(2**19-1) ).prime?.should be_false # M6*M7 end end diff --git a/spec/ruby/library/prime/next_spec.rb b/spec/ruby/library/prime/next_spec.rb index 8e805ed044..39c4ae16ae 100644 --- a/spec/ruby/library/prime/next_spec.rb +++ b/spec/ruby/library/prime/next_spec.rb @@ -1,10 +1,7 @@ require_relative '../../spec_helper' +require_relative 'shared/next' +require 'prime' -ruby_version_is ""..."3.1" do - require_relative 'shared/next' - require 'prime' - - describe "Prime#next" do - it_behaves_like :prime_next, :next - end +describe "Prime#next" do + it_behaves_like :prime_next, :next end diff --git a/spec/ruby/library/prime/prime_division_spec.rb b/spec/ruby/library/prime/prime_division_spec.rb index 4c93d5936a..6293478f59 100644 --- a/spec/ruby/library/prime/prime_division_spec.rb +++ b/spec/ruby/library/prime/prime_division_spec.rb @@ -1,28 +1,25 @@ require_relative '../../spec_helper' +require 'prime' -ruby_version_is ""..."3.1" do - require 'prime' - - describe "Prime.prime_division" do - it "returns an array of a prime factor and a corresponding exponent" do - Prime.prime_division(2*3*5*7*11*13*17).should == - [[2,1], [3,1], [5,1], [7,1], [11,1], [13,1], [17,1]] - end +describe "Prime.prime_division" do + it "returns an array of a prime factor and a corresponding exponent" do + Prime.prime_division(2*3*5*7*11*13*17).should == + [[2,1], [3,1], [5,1], [7,1], [11,1], [13,1], [17,1]] + end - it "returns an empty array for 1" do - Prime.prime_division(1).should == [] - end + it "returns an empty array for 1" do + Prime.prime_division(1).should == [] + end - it "returns [[-1, 1]] for -1" do - Prime.prime_division(-1).should == [[-1, 1]] - end + it "returns [[-1, 1]] for -1" do + Prime.prime_division(-1).should == [[-1, 1]] + end - it "includes [[-1, 1]] in the divisors of a negative number" do - Prime.prime_division(-10).should include([-1, 1]) - end + it "includes [[-1, 1]] in the divisors of a negative number" do + Prime.prime_division(-10).should include([-1, 1]) + end - it "raises ZeroDivisionError for 0" do - -> { Prime.prime_division(0) }.should raise_error(ZeroDivisionError) - end + it "raises ZeroDivisionError for 0" do + -> { Prime.prime_division(0) }.should raise_error(ZeroDivisionError) end end diff --git a/spec/ruby/library/prime/prime_spec.rb b/spec/ruby/library/prime/prime_spec.rb index e2afddd5b2..0896c7f0f3 100644 --- a/spec/ruby/library/prime/prime_spec.rb +++ b/spec/ruby/library/prime/prime_spec.rb @@ -1,20 +1,17 @@ require_relative '../../spec_helper' +require 'prime' -ruby_version_is ""..."3.1" do - require 'prime' - - describe "Prime#prime?" do - it "returns a true value for prime numbers" do - Prime.prime?(2).should be_true - Prime.prime?(3).should be_true - Prime.prime?(2**31-1).should be_true # 8th Mersenne prime (M8) - end +describe "Prime#prime?" do + it "returns a true value for prime numbers" do + Prime.prime?(2).should be_true + Prime.prime?(3).should be_true + Prime.prime?(2**31-1).should be_true # 8th Mersenne prime (M8) + end - it "returns a false value for composite numbers" do - Prime.prime?(4).should be_false - Prime.prime?(15).should be_false - Prime.prime?(2**32-1).should be_false - Prime.prime?( (2**17-1)*(2**19-1) ).should be_false # M6*M7 - end + it "returns a false value for composite numbers" do + Prime.prime?(4).should be_false + Prime.prime?(15).should be_false + Prime.prime?(2**32-1).should be_false + Prime.prime?( (2**17-1)*(2**19-1) ).should be_false # M6*M7 end end diff --git a/spec/ruby/library/prime/succ_spec.rb b/spec/ruby/library/prime/succ_spec.rb index 9843dae25d..34c18d2ba0 100644 --- a/spec/ruby/library/prime/succ_spec.rb +++ b/spec/ruby/library/prime/succ_spec.rb @@ -1,10 +1,7 @@ require_relative '../../spec_helper' +require_relative 'shared/next' +require 'prime' -ruby_version_is ""..."3.1" do - require_relative 'shared/next' - require 'prime' - - describe "Prime#succ" do - it_behaves_like :prime_next, :succ - end +describe "Prime#succ" do + it_behaves_like :prime_next, :succ end diff --git a/spec/ruby/library/random/formatter/alphanumeric_spec.rb b/spec/ruby/library/random/formatter/alphanumeric_spec.rb new file mode 100644 index 0000000000..9bd325e1d0 --- /dev/null +++ b/spec/ruby/library/random/formatter/alphanumeric_spec.rb @@ -0,0 +1,56 @@ +require_relative '../../../spec_helper' + +require 'random/formatter' + +describe "Random::Formatter#alphanumeric" do + before :each do + @object = Object.new + @object.extend(Random::Formatter) + @object.define_singleton_method(:bytes) do |n| + "\x00".b * n + end + end + + it "generates a random alphanumeric string" do + @object.alphanumeric.should =~ /\A[A-Za-z0-9]+\z/ + end + + it "has a default size of 16 characters" do + @object.alphanumeric.size.should == 16 + end + + it "accepts a 'size' argument" do + @object.alphanumeric(10).size.should == 10 + end + + it "uses the default size if 'nil' is given as size argument" do + @object.alphanumeric(nil).size.should == 16 + end + + it "raises an ArgumentError if the size is not numeric" do + -> { + @object.alphanumeric("10") + }.should raise_error(ArgumentError) + end + + it "does not coerce the size argument with #to_int" do + size = mock("size") + size.should_not_receive(:to_int) + -> { + @object.alphanumeric(size) + }.should raise_error(ArgumentError) + end + + ruby_version_is "3.3" do + it "accepts a 'chars' argument with the output alphabet" do + @object.alphanumeric(chars: ['a', 'b']).should =~ /\A[ab]+\z/ + end + + it "converts the elements of chars using #to_s" do + to_s = mock("to_s") + to_s.should_receive(:to_s).and_return("[mock to_s]") + # Using 1 value in chars results in an infinite loop + @object.alphanumeric(1, chars: [to_s, to_s]).should == "[mock to_s]" + end + end +end diff --git a/spec/ruby/library/rbconfig/rbconfig_spec.rb b/spec/ruby/library/rbconfig/rbconfig_spec.rb index b90cc90970..b9a4588bf0 100644 --- a/spec/ruby/library/rbconfig/rbconfig_spec.rb +++ b/spec/ruby/library/rbconfig/rbconfig_spec.rb @@ -9,6 +9,13 @@ describe 'RbConfig::CONFIG' do end end + it 'has MAJOR, MINOR, TEENY, and PATCHLEVEL matching RUBY_VERSION and RUBY_PATCHLEVEL' do + major, minor, teeny = RUBY_VERSION.split('.') + RbConfig::CONFIG.values_at("MAJOR", "MINOR", "TEENY", "PATCHLEVEL").should == [ + major, minor, teeny, RUBY_PATCHLEVEL.to_s + ] + end + # These directories have no meanings before the installation. guard -> { RbConfig::TOPDIR } do it "['rubylibdir'] returns the directory containing Ruby standard libraries" do @@ -88,6 +95,30 @@ describe 'RbConfig::CONFIG' do end end end + + guard -> { %w[aarch64 arm64].include? RbConfig::CONFIG['host_cpu'] } do + it "['host_cpu'] returns CPU architecture properly for AArch64" do + platform_is :darwin do + RbConfig::CONFIG['host_cpu'].should == 'arm64' + end + + platform_is_not :darwin do + RbConfig::CONFIG['host_cpu'].should == 'aarch64' + end + end + end + + guard -> { platform_is(:linux) || platform_is(:darwin) } do + it "['host_os'] returns a proper OS name or platform" do + platform_is :darwin do + RbConfig::CONFIG['host_os'].should.match?(/darwin/) + end + + platform_is :linux do + RbConfig::CONFIG['host_os'].should.match?(/linux/) + end + end + end end describe "RbConfig::TOPDIR" do @@ -99,3 +130,34 @@ describe "RbConfig::TOPDIR" do end end end + +describe "RUBY_PLATFORM" do + it "RUBY_PLATFORM contains a proper CPU architecture" do + RUBY_PLATFORM.should.include? RbConfig::CONFIG['host_cpu'] + end + + guard -> { platform_is(:linux) || platform_is(:darwin) } do + it "RUBY_PLATFORM contains OS name" do + # don't use RbConfig::CONFIG['host_os'] as far as it could be slightly different, e.g. linux-gnu + platform_is(:linux) do + RUBY_PLATFORM.should.include? 'linux' + end + + platform_is(:darwin) do + RUBY_PLATFORM.should.include? 'darwin' + end + end + end +end + +describe "RUBY_DESCRIPTION" do + guard_not -> { RUBY_ENGINE == "ruby" && !RbConfig::TOPDIR } do + it "contains version" do + RUBY_DESCRIPTION.should.include? RUBY_VERSION + end + + it "contains RUBY_PLATFORM" do + RUBY_DESCRIPTION.should.include? RUBY_PLATFORM + end + end +end diff --git a/spec/ruby/library/rbconfig/unicode_emoji_version_spec.rb b/spec/ruby/library/rbconfig/unicode_emoji_version_spec.rb index 3dc9900127..521a750bf7 100644 --- a/spec/ruby/library/rbconfig/unicode_emoji_version_spec.rb +++ b/spec/ruby/library/rbconfig/unicode_emoji_version_spec.rb @@ -2,22 +2,16 @@ require_relative '../../spec_helper' require 'rbconfig' describe "RbConfig::CONFIG['UNICODE_EMOJI_VERSION']" do - ruby_version_is ""..."3.1" do - it "is 12.1" do - RbConfig::CONFIG['UNICODE_EMOJI_VERSION'].should == "12.1" - end - end - - ruby_version_is "3.1"..."3.2" do - it "is 13.1" do - RbConfig::CONFIG['UNICODE_EMOJI_VERSION'].should == "13.1" + ruby_version_is ""..."3.4" do + it "is 15.0" do + RbConfig::CONFIG['UNICODE_EMOJI_VERSION'].should == "15.0" end end # Caution: ruby_version_is means is_or_later - ruby_version_is "3.2" do - it "is 15.0" do - RbConfig::CONFIG['UNICODE_EMOJI_VERSION'].should == "15.0" + ruby_version_is "4.0" do + it "is 17.0" do + RbConfig::CONFIG['UNICODE_EMOJI_VERSION'].should == "17.0" end end end diff --git a/spec/ruby/library/rbconfig/unicode_version_spec.rb b/spec/ruby/library/rbconfig/unicode_version_spec.rb index 458f13bf03..5cdde74f79 100644 --- a/spec/ruby/library/rbconfig/unicode_version_spec.rb +++ b/spec/ruby/library/rbconfig/unicode_version_spec.rb @@ -2,22 +2,16 @@ require_relative '../../spec_helper' require 'rbconfig' describe "RbConfig::CONFIG['UNICODE_VERSION']" do - ruby_version_is ""..."3.1" do - it "is 12.1.0" do - RbConfig::CONFIG['UNICODE_VERSION'].should == "12.1.0" - end - end - - ruby_version_is "3.1"..."3.2" do - it "is 13.0.0" do - RbConfig::CONFIG['UNICODE_VERSION'].should == "13.0.0" + ruby_version_is ""..."3.4" do + it "is 15.0.0" do + RbConfig::CONFIG['UNICODE_VERSION'].should == "15.0.0" end end # Caution: ruby_version_is means is_or_later - ruby_version_is "3.2" do - it "is 15.0.0" do - RbConfig::CONFIG['UNICODE_VERSION'].should == "15.0.0" + ruby_version_is "4.0" do + it "is 17.0.0" do + RbConfig::CONFIG['UNICODE_VERSION'].should == "17.0.0" end end end diff --git a/spec/ruby/library/rexml/attribute/clone_spec.rb b/spec/ruby/library/rexml/attribute/clone_spec.rb deleted file mode 100644 index 5c86468d45..0000000000 --- a/spec/ruby/library/rexml/attribute/clone_spec.rb +++ /dev/null @@ -1,14 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attribute#clone" do - it "returns a copy of this Attribute" do - orig = REXML::Attribute.new("name", "value&&") - orig.should == orig.clone - orig.clone.to_s.should == orig.to_s - orig.clone.to_string.should == orig.to_string - end - end -end diff --git a/spec/ruby/library/rexml/attribute/element_spec.rb b/spec/ruby/library/rexml/attribute/element_spec.rb deleted file mode 100644 index 0e4ce46a4f..0000000000 --- a/spec/ruby/library/rexml/attribute/element_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attribute#element" do - it "returns the parent element" do - e = REXML::Element.new "root" - - REXML::Attribute.new("name", "value", e).element.should == e - REXML::Attribute.new("name", "default_constructor").element.should == nil - end - end - - describe "REXML::Attribute#element=" do - it "sets the parent element" do - e = REXML::Element.new "root" - f = REXML::Element.new "temp" - a = REXML::Attribute.new("name", "value", e) - a.element.should == e - - a.element = f - a.element.should == f - end - end -end diff --git a/spec/ruby/library/rexml/attribute/equal_value_spec.rb b/spec/ruby/library/rexml/attribute/equal_value_spec.rb deleted file mode 100644 index 1498bae624..0000000000 --- a/spec/ruby/library/rexml/attribute/equal_value_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attribute#==" do - it "returns true if other has equal name and value" do - a1 = REXML::Attribute.new("foo", "bar") - a1.should == a1.clone - - a2 = REXML::Attribute.new("foo", "bar") - a1.should == a2 - - a3 = REXML::Attribute.new("foo", "bla") - a1.should_not == a3 - - a4 = REXML::Attribute.new("baz", "bar") - a1.should_not == a4 - end - end -end diff --git a/spec/ruby/library/rexml/attribute/hash_spec.rb b/spec/ruby/library/rexml/attribute/hash_spec.rb deleted file mode 100644 index 7e0cbcc1ea..0000000000 --- a/spec/ruby/library/rexml/attribute/hash_spec.rb +++ /dev/null @@ -1,16 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attribute#hash" do - # These are not really complete, any idea on how to make them more - # "testable" will be appreciated. - it "returns a hashcode made of the name and value of self" do - a = REXML::Attribute.new("name", "value") - a.hash.should be_kind_of(Numeric) - b = REXML::Attribute.new(a) - a.hash.should == b.hash - end - end -end diff --git a/spec/ruby/library/rexml/attribute/initialize_spec.rb b/spec/ruby/library/rexml/attribute/initialize_spec.rb deleted file mode 100644 index 35b87b0733..0000000000 --- a/spec/ruby/library/rexml/attribute/initialize_spec.rb +++ /dev/null @@ -1,32 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attribute#initialize" do - before :each do - @e = REXML::Element.new "root" - @name = REXML::Attribute.new("name", "Nicko") - @e.add_attribute @name - end - - it "receives two strings for name and value" do - @e.attributes["name"].should == "Nicko" - @e.add_attribute REXML::Attribute.new("last_name", nil) - @e.attributes["last_name"].should == "" - end - - it "receives an Attribute and clones it" do - copy = REXML::Attribute.new(@name) - copy.should == @name - end - - it "receives a parent node" do - last_name = REXML::Attribute.new("last_name", "McBrain", @e) - last_name.element.should == @e - - last_name = REXML::Attribute.new(@name, @e) - last_name.element.should == @e - end - end -end diff --git a/spec/ruby/library/rexml/attribute/inspect_spec.rb b/spec/ruby/library/rexml/attribute/inspect_spec.rb deleted file mode 100644 index ee5236b98e..0000000000 --- a/spec/ruby/library/rexml/attribute/inspect_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attribute#inspect" do - it "returns the name and value as a string" do - a = REXML::Attribute.new("my_name", "my_value") - a.inspect.should == "my_name='my_value'" - end - - it "accepts attributes with no value" do - a = REXML::Attribute.new("my_name") - a.inspect.should == "my_name=''" - end - - it "does not escape text" do - a = REXML::Attribute.new("name", "<>") - a.inspect.should == "name='<>'" - end - end -end diff --git a/spec/ruby/library/rexml/attribute/namespace_spec.rb b/spec/ruby/library/rexml/attribute/namespace_spec.rb deleted file mode 100644 index 645b3cd1b1..0000000000 --- a/spec/ruby/library/rexml/attribute/namespace_spec.rb +++ /dev/null @@ -1,27 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attribute#namespace" do - it "returns the namespace url" do - e = REXML::Element.new("root") - e.add_attribute REXML::Attribute.new("xmlns:ns", "http://some_uri") - e.namespace("ns").should == "http://some_uri" - end - - it "returns nil if namespace is not defined" do - e = REXML::Element.new("root") - e.add_attribute REXML::Attribute.new("test", "value") - e.namespace("test").should == nil - e.namespace("ns").should == nil - end - - it "defaults arg to nil" do - e = REXML::Element.new("root") - e.add_attribute REXML::Attribute.new("xmlns:ns", "http://some_uri") - e.namespace.should == "" - e.namespace("ns").should == "http://some_uri" - end - end -end diff --git a/spec/ruby/library/rexml/attribute/node_type_spec.rb b/spec/ruby/library/rexml/attribute/node_type_spec.rb deleted file mode 100644 index da055ae8f0..0000000000 --- a/spec/ruby/library/rexml/attribute/node_type_spec.rb +++ /dev/null @@ -1,13 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attribute#node_type" do - it "always returns :attribute" do - attr = REXML::Attribute.new("foo", "bar") - attr.node_type.should == :attribute - REXML::Attribute.new(attr).node_type.should == :attribute - end - end -end diff --git a/spec/ruby/library/rexml/attribute/prefix_spec.rb b/spec/ruby/library/rexml/attribute/prefix_spec.rb deleted file mode 100644 index 87bff4822b..0000000000 --- a/spec/ruby/library/rexml/attribute/prefix_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attribute#prefix" do - it "returns the namespace of the Attribute" do - ans = REXML::Attribute.new("ns:someattr", "some_value") - out = REXML::Attribute.new("out:something", "some_other_value") - - ans.prefix.should == "ns" - out.prefix.should == "out" - end - - it "returns an empty string for Attributes with no prefixes" do - attr = REXML::Attribute.new("foo", "bar") - - attr.prefix.should == "" - end - end -end diff --git a/spec/ruby/library/rexml/attribute/remove_spec.rb b/spec/ruby/library/rexml/attribute/remove_spec.rb deleted file mode 100644 index 5f928b1286..0000000000 --- a/spec/ruby/library/rexml/attribute/remove_spec.rb +++ /dev/null @@ -1,23 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attribute#remove" do - before :each do - @e = REXML::Element.new "Root" - @attr = REXML::Attribute.new("foo", "bar") - end - - it "deletes this Attribute from parent" do - @e.add_attribute(@attr) - @e.attributes["foo"].should_not == nil - @attr.remove - @e.attributes["foo"].should == nil - end - - it "does not anything if element has no parent" do - -> {@attr.remove}.should_not raise_error(Exception) - end - end -end diff --git a/spec/ruby/library/rexml/attribute/to_s_spec.rb b/spec/ruby/library/rexml/attribute/to_s_spec.rb deleted file mode 100644 index e362cee8f1..0000000000 --- a/spec/ruby/library/rexml/attribute/to_s_spec.rb +++ /dev/null @@ -1,17 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attribute#to_s" do - it "returns the value of the Attribute" do - REXML::Attribute.new("name", "some_value").to_s.should == "some_value" - end - - it "returns the escaped value if it was created from Attribute" do - orig = REXML::Attribute.new("name", "<&>") - copy = REXML::Attribute.new(orig) - copy.to_s.should == "<&>" - end - end -end diff --git a/spec/ruby/library/rexml/attribute/to_string_spec.rb b/spec/ruby/library/rexml/attribute/to_string_spec.rb deleted file mode 100644 index a9d249f5bb..0000000000 --- a/spec/ruby/library/rexml/attribute/to_string_spec.rb +++ /dev/null @@ -1,17 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attribute#to_string" do - it "returns the attribute as XML" do - attr = REXML::Attribute.new("name", "value") - attr_empty = REXML::Attribute.new("name") - attr_ns = REXML::Attribute.new("xmlns:ns", "http://uri") - - attr.to_string.should == "name='value'" - attr_empty.to_string.should == "name=''" - attr_ns.to_string.should == "xmlns:ns='http://uri'" - end - end -end diff --git a/spec/ruby/library/rexml/attribute/value_spec.rb b/spec/ruby/library/rexml/attribute/value_spec.rb deleted file mode 100644 index 77071f6f70..0000000000 --- a/spec/ruby/library/rexml/attribute/value_spec.rb +++ /dev/null @@ -1,17 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attribute#value" do - it "returns the value of the Attribute unnormalized" do - attr = REXML::Attribute.new("name", "value") - attr_ents = REXML::Attribute.new("name", "<&>") - attr_empty = REXML::Attribute.new("name") - - attr.value.should == "value" - attr_ents.value.should == "<&>" - attr_empty.value.should == "" - end - end -end diff --git a/spec/ruby/library/rexml/attribute/write_spec.rb b/spec/ruby/library/rexml/attribute/write_spec.rb deleted file mode 100644 index 0012b3cc77..0000000000 --- a/spec/ruby/library/rexml/attribute/write_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attribute#write" do - before :each do - @attr = REXML::Attribute.new("name", "Charlotte") - @s = "" - end - - it "writes the name and value to output" do - @attr.write(@s) - @s.should == "name='Charlotte'" - end - - it "currently ignores the second argument" do - @attr.write(@s, 3) - @s.should == "name='Charlotte'" - - @s = "" - @attr.write(@s, "foo") - @s.should == "name='Charlotte'" - end - end -end diff --git a/spec/ruby/library/rexml/attribute/xpath_spec.rb b/spec/ruby/library/rexml/attribute/xpath_spec.rb deleted file mode 100644 index 0a09046b01..0000000000 --- a/spec/ruby/library/rexml/attribute/xpath_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attribute#xpath" do - - before :each do - @e = REXML::Element.new "root" - @attr = REXML::Attribute.new("year", "1989") - end - - it "returns the path for Attribute" do - @e.add_attribute @attr - @attr.xpath.should == "root/@year" - end - - it "raises an error if attribute has no parent" do - -> { @attr.xpath }.should raise_error(Exception) - end - end -end diff --git a/spec/ruby/library/rexml/attributes/add_spec.rb b/spec/ruby/library/rexml/attributes/add_spec.rb deleted file mode 100644 index e24e9fabbc..0000000000 --- a/spec/ruby/library/rexml/attributes/add_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require_relative 'shared/add' - require 'rexml/document' - - describe "REXML::Attributes#add" do - it_behaves_like :rexml_attribute_add, :add - end -end diff --git a/spec/ruby/library/rexml/attributes/append_spec.rb b/spec/ruby/library/rexml/attributes/append_spec.rb deleted file mode 100644 index f96a727f47..0000000000 --- a/spec/ruby/library/rexml/attributes/append_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require_relative 'shared/add' - require 'rexml/document' - - describe "REXML::Attributes#<<" do - it_behaves_like :rexml_attribute_add, :<< - end -end diff --git a/spec/ruby/library/rexml/attributes/delete_all_spec.rb b/spec/ruby/library/rexml/attributes/delete_all_spec.rb deleted file mode 100644 index 707baa235b..0000000000 --- a/spec/ruby/library/rexml/attributes/delete_all_spec.rb +++ /dev/null @@ -1,34 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attributes#delete_all" do - before :each do - @e = REXML::Element.new("root") - end - - it "deletes all attributes that match name" do - uri = REXML::Attribute.new("uri", "http://something") - @e.attributes << uri - @e.attributes.delete_all("uri") - @e.attributes.should be_empty - @e.attributes["uri"].should == nil - end - - it "deletes all attributes that match name with a namespace" do - ns_uri = REXML::Attribute.new("xmlns:uri", "http://something_here_too") - @e.attributes << ns_uri - @e.attributes.delete_all("xmlns:uri") - @e.attributes.should be_empty - @e.attributes["xmlns:uri"].should == nil - end - - it "returns the removed attribute" do - uri = REXML::Attribute.new("uri", "http://something_here_too") - @e.attributes << uri - attrs = @e.attributes.delete_all("uri") - attrs.first.should == uri - end - end -end diff --git a/spec/ruby/library/rexml/attributes/delete_spec.rb b/spec/ruby/library/rexml/attributes/delete_spec.rb deleted file mode 100644 index 723fa70751..0000000000 --- a/spec/ruby/library/rexml/attributes/delete_spec.rb +++ /dev/null @@ -1,30 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attributes#delete" do - before :each do - @e = REXML::Element.new("root") - @name = REXML::Attribute.new("name", "Pepe") - end - - it "takes an attribute name and deletes the attribute" do - @e.attributes.delete("name") - @e.attributes["name"].should be_nil - @e.attributes.should be_empty - end - - it "takes an Attribute and deletes it" do - @e.attributes.delete(@name) - @e.attributes["name"].should be_nil - @e.attributes.should be_empty - end - - it "returns the element with the attribute removed" do - ret_val = @e.attributes.delete(@name) - ret_val.should == @e - ret_val.attributes.should be_empty - end - end -end diff --git a/spec/ruby/library/rexml/attributes/each_attribute_spec.rb b/spec/ruby/library/rexml/attributes/each_attribute_spec.rb deleted file mode 100644 index 692cf4f943..0000000000 --- a/spec/ruby/library/rexml/attributes/each_attribute_spec.rb +++ /dev/null @@ -1,25 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attributes#each_attribute" do - it "iterates over the attributes yielding actual Attribute objects" do - e = REXML::Element.new("root") - name = REXML::Attribute.new("name", "Joe") - ns_uri = REXML::Attribute.new("xmlns:ns", "http://some_uri") - e.add_attribute name - e.add_attribute ns_uri - - attributes = [] - - e.attributes.each_attribute do |attr| - attributes << attr - end - - attributes = attributes.sort_by {|a| a.name } - attributes.first.should == name - attributes.last.should == ns_uri - end - end -end diff --git a/spec/ruby/library/rexml/attributes/each_spec.rb b/spec/ruby/library/rexml/attributes/each_spec.rb deleted file mode 100644 index 49add3b77b..0000000000 --- a/spec/ruby/library/rexml/attributes/each_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attributes#each" do - before :each do - @e = REXML::Element.new("root") - @name = REXML::Attribute.new("name", "Joe") - @ns_uri = REXML::Attribute.new("xmlns:ns", "http://some_uri") - @e.add_attribute @name - @e.add_attribute @ns_uri - end - - it "iterates over the attributes yielding expanded-name/value" do - attributes = [] - @e.attributes.each do |attr| - attr.should be_kind_of(Array) - attributes << attr - end - attributes = attributes.sort_by {|a| a.first } - attributes.first.should == ["name", "Joe"] - attributes.last.should == ["xmlns:ns", "http://some_uri"] - end - end -end diff --git a/spec/ruby/library/rexml/attributes/element_reference_spec.rb b/spec/ruby/library/rexml/attributes/element_reference_spec.rb deleted file mode 100644 index 0d089eaab2..0000000000 --- a/spec/ruby/library/rexml/attributes/element_reference_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attributes#[]" do - before :each do - @e = REXML::Element.new("root") - @lang = REXML::Attribute.new("language", "english") - @e.attributes << @lang - end - - it "returns the value of an attribute" do - @e.attributes["language"].should == "english" - end - - it "returns nil if the attribute does not exist" do - @e.attributes["chunky bacon"].should == nil - end - end -end diff --git a/spec/ruby/library/rexml/attributes/element_set_spec.rb b/spec/ruby/library/rexml/attributes/element_set_spec.rb deleted file mode 100644 index 834ad682a6..0000000000 --- a/spec/ruby/library/rexml/attributes/element_set_spec.rb +++ /dev/null @@ -1,28 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attributes#[]=" do - before :each do - @e = REXML::Element.new("song") - @name = REXML::Attribute.new("name", "Holy Smoke!") - @e.attributes << @name - end - - it "sets an attribute" do - @e.attributes["author"] = "_why's foxes" - @e.attributes["author"].should == "_why's foxes" - end - - it "overwrites an existing attribute" do - @e.attributes["name"] = "Chunky Bacon" - @e.attributes["name"].should == "Chunky Bacon" - end - - it "deletes an attribute is value is nil" do - @e.attributes["name"] = nil - @e.attributes.length.should == 0 - end - end -end diff --git a/spec/ruby/library/rexml/attributes/get_attribute_ns_spec.rb b/spec/ruby/library/rexml/attributes/get_attribute_ns_spec.rb deleted file mode 100644 index 1109ff519c..0000000000 --- a/spec/ruby/library/rexml/attributes/get_attribute_ns_spec.rb +++ /dev/null @@ -1,17 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attributes#get_attribute_ns" do - it "returns an attribute by name and namespace" do - e = REXML::Element.new("root") - attr = REXML::Attribute.new("xmlns:ns", "http://some_url") - e.attributes << attr - attr.prefix.should == "xmlns" - # This might be a bug in Attribute, commenting until those specs - # are ready - # e.attributes.get_attribute_ns(attr.prefix, "name").should == "http://some_url" - end - end -end diff --git a/spec/ruby/library/rexml/attributes/get_attribute_spec.rb b/spec/ruby/library/rexml/attributes/get_attribute_spec.rb deleted file mode 100644 index cc94191729..0000000000 --- a/spec/ruby/library/rexml/attributes/get_attribute_spec.rb +++ /dev/null @@ -1,32 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attributes#get_attribute" do - before :each do - @e = REXML::Element.new("root") - @name = REXML::Attribute.new("name", "Dave") - @e.attributes << @name - end - - it "fetches an attributes" do - @e.attributes.get_attribute("name").should == @name - end - - it "fetches an namespaced attribute" do - ns_name = REXML::Attribute.new("im:name", "Murray") - @e.attributes << ns_name - @e.attributes.get_attribute("name").should == @name - @e.attributes.get_attribute("im:name").should == ns_name - end - - it "returns an Attribute" do - @e.attributes.get_attribute("name").should be_kind_of(REXML::Attribute) - end - - it "returns nil if it attribute does not exist" do - @e.attributes.get_attribute("fake").should be_nil - end - end -end diff --git a/spec/ruby/library/rexml/attributes/initialize_spec.rb b/spec/ruby/library/rexml/attributes/initialize_spec.rb deleted file mode 100644 index 42ec742e60..0000000000 --- a/spec/ruby/library/rexml/attributes/initialize_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attributes#initialize" do - it "is auto initialized by Element" do - e = REXML::Element.new "root" - e.attributes.should be_kind_of(REXML::Attributes) - - e.attributes << REXML::Attribute.new("name", "Paul") - e.attributes["name"].should == "Paul" - end - - it "receives a parent node" do - e = REXML::Element.new "root" - e.attributes << REXML::Attribute.new("name", "Vic") - e.attributes["name"].should == "Vic" - end - end -end diff --git a/spec/ruby/library/rexml/attributes/length_spec.rb b/spec/ruby/library/rexml/attributes/length_spec.rb deleted file mode 100644 index 81733b4a96..0000000000 --- a/spec/ruby/library/rexml/attributes/length_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require_relative 'shared/length' - require 'rexml/document' - - describe "REXML::Attributes#length" do - it_behaves_like :rexml_attribute_length, :length - end -end diff --git a/spec/ruby/library/rexml/attributes/namespaces_spec.rb b/spec/ruby/library/rexml/attributes/namespaces_spec.rb deleted file mode 100644 index b88346854f..0000000000 --- a/spec/ruby/library/rexml/attributes/namespaces_spec.rb +++ /dev/null @@ -1,9 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attributes#namespaces" do - it "needs to be reviewed for spec completeness" - end -end diff --git a/spec/ruby/library/rexml/attributes/prefixes_spec.rb b/spec/ruby/library/rexml/attributes/prefixes_spec.rb deleted file mode 100644 index 574b7ffbaf..0000000000 --- a/spec/ruby/library/rexml/attributes/prefixes_spec.rb +++ /dev/null @@ -1,27 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attributes#prefixes" do - before :each do - @e = REXML::Element.new("root") - a1 = REXML::Attribute.new("xmlns:a", "bar") - a2 = REXML::Attribute.new("xmlns:b", "bla") - a3 = REXML::Attribute.new("xmlns:c", "baz") - @e.attributes << a1 - @e.attributes << a2 - @e.attributes << a3 - - @e.attributes << REXML::Attribute.new("xmlns", "foo") - end - - it "returns an array with the prefixes of each attribute" do - @e.attributes.prefixes.sort.should == ["a", "b", "c"] - end - - it "does not include the default namespace" do - @e.attributes.prefixes.include?("xmlns").should == false - end - end -end diff --git a/spec/ruby/library/rexml/attributes/shared/add.rb b/spec/ruby/library/rexml/attributes/shared/add.rb deleted file mode 100644 index 872f149f45..0000000000 --- a/spec/ruby/library/rexml/attributes/shared/add.rb +++ /dev/null @@ -1,17 +0,0 @@ -describe :rexml_attribute_add, shared: true do - before :each do - @e = REXML::Element.new("root") - @attr = REXML::Attributes.new(@e) - @name = REXML::Attribute.new("name", "Joe") - end - - it "adds an attribute" do - @attr.send(@method, @name) - @attr["name"].should == "Joe" - end - - it "replaces an existing attribute" do - @attr.send(@method, REXML::Attribute.new("name", "Bruce")) - @attr["name"].should == "Bruce" - end -end diff --git a/spec/ruby/library/rexml/attributes/shared/length.rb b/spec/ruby/library/rexml/attributes/shared/length.rb deleted file mode 100644 index 7848f9bf33..0000000000 --- a/spec/ruby/library/rexml/attributes/shared/length.rb +++ /dev/null @@ -1,13 +0,0 @@ -require_relative '../../../../spec_helper' -require 'rexml/document' - -describe :rexml_attribute_length, shared: true do - it "returns the number of attributes" do - e = REXML::Element.new("root") - e.attributes.send(@method).should == 0 - - e.attributes << REXML::Attribute.new("name", "John") - e.attributes << REXML::Attribute.new("another_name", "Leo") - e.attributes.send(@method).should == 2 - end -end diff --git a/spec/ruby/library/rexml/attributes/size_spec.rb b/spec/ruby/library/rexml/attributes/size_spec.rb deleted file mode 100644 index 13ef08f644..0000000000 --- a/spec/ruby/library/rexml/attributes/size_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require_relative 'shared/length' - require 'rexml/document' - - describe "REXML::Attributes#size" do - it_behaves_like :rexml_attribute_length, :size - end -end diff --git a/spec/ruby/library/rexml/attributes/to_a_spec.rb b/spec/ruby/library/rexml/attributes/to_a_spec.rb deleted file mode 100644 index 902cd86a29..0000000000 --- a/spec/ruby/library/rexml/attributes/to_a_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attributes#to_a" do - it "returns an array with the attributes" do - e = REXML::Element.new("root") - name = REXML::Attribute.new("name", "Dave") - last = REXML::Attribute.new("last_name", "Murray") - - e.attributes << name - e.attributes << last - - e.attributes.to_a.sort{|a,b|a.to_s<=>b.to_s}.should == [name, last] - end - - it "returns an empty array if it has no attributes" do - REXML::Element.new("root").attributes.to_a.should == [] - end - end -end diff --git a/spec/ruby/library/rexml/cdata/clone_spec.rb b/spec/ruby/library/rexml/cdata/clone_spec.rb deleted file mode 100644 index abe1a0b062..0000000000 --- a/spec/ruby/library/rexml/cdata/clone_spec.rb +++ /dev/null @@ -1,13 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::CData#clone" do - it "makes a copy of itself" do - c = REXML::CData.new("some text") - c.clone.to_s.should == c.to_s - c.clone.should == c - end - end -end diff --git a/spec/ruby/library/rexml/cdata/initialize_spec.rb b/spec/ruby/library/rexml/cdata/initialize_spec.rb deleted file mode 100644 index 1393d97f4a..0000000000 --- a/spec/ruby/library/rexml/cdata/initialize_spec.rb +++ /dev/null @@ -1,27 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::CData#initialize" do - it "creates a new CData object" do - c = REXML::CData.new("some text") - c.should be_kind_of(REXML::CData) - c.should be_kind_of(REXML::Text) - end - - it "respects whitespace if whitespace is true" do - c = REXML::CData.new("whitespace test", true) - c1 = REXML::CData.new("whitespace test", false) - - c.to_s.should == "whitespace test" - c1.to_s.should == "whitespace test" - end - - it "receives parent as third argument" do - e = REXML::Element.new("root") - REXML::CData.new("test", true, e) - e.to_s.should == "<root><![CDATA[test]]></root>" - end - end -end diff --git a/spec/ruby/library/rexml/cdata/shared/to_s.rb b/spec/ruby/library/rexml/cdata/shared/to_s.rb deleted file mode 100644 index f8c4951c95..0000000000 --- a/spec/ruby/library/rexml/cdata/shared/to_s.rb +++ /dev/null @@ -1,11 +0,0 @@ -describe :rexml_cdata_to_s, shared: true do - it "returns the contents of the CData" do - c = REXML::CData.new("some text") - c.send(@method).should == "some text" - end - - it "does not escape text" do - c1 = REXML::CData.new("some& text\n") - c1.send(@method).should == "some& text\n" - end -end diff --git a/spec/ruby/library/rexml/cdata/to_s_spec.rb b/spec/ruby/library/rexml/cdata/to_s_spec.rb deleted file mode 100644 index a5c061f116..0000000000 --- a/spec/ruby/library/rexml/cdata/to_s_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require_relative 'shared/to_s' - require 'rexml/document' - - describe "REXML::CData#to_s" do - it_behaves_like :rexml_cdata_to_s, :to_s - end -end diff --git a/spec/ruby/library/rexml/cdata/value_spec.rb b/spec/ruby/library/rexml/cdata/value_spec.rb deleted file mode 100644 index 9f36226976..0000000000 --- a/spec/ruby/library/rexml/cdata/value_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require_relative 'shared/to_s' - require 'rexml/document' - - describe "REXML::CData#value" do - it_behaves_like :rexml_cdata_to_s, :value - end -end diff --git a/spec/ruby/library/rexml/document/add_element_spec.rb b/spec/ruby/library/rexml/document/add_element_spec.rb deleted file mode 100644 index 29dec0b24e..0000000000 --- a/spec/ruby/library/rexml/document/add_element_spec.rb +++ /dev/null @@ -1,34 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Document#add_element" do - it "adds arg1 with attributes arg2 as root node" do - d = REXML::Document.new - e = REXML::Element.new("root") - d.add_element e - d.root.should == e - end - - it "sets arg2 as arg1's attributes" do - d = REXML::Document.new - e = REXML::Element.new("root") - attr = {"foo" => "bar"} - d.add_element(e,attr) - d.root.attributes["foo"].should == attr["foo"] - end - - it "accepts a node name as arg1 and adds it as root" do - d = REXML::Document.new - d.add_element "foo" - d.root.name.should == "foo" - end - - it "sets arg1's context to the root's context" do - d = REXML::Document.new("", {"foo" => "bar"}) - d.add_element "foo" - d.root.context.should == d.context - end - end -end diff --git a/spec/ruby/library/rexml/document/add_spec.rb b/spec/ruby/library/rexml/document/add_spec.rb deleted file mode 100644 index 8666d3dbf9..0000000000 --- a/spec/ruby/library/rexml/document/add_spec.rb +++ /dev/null @@ -1,60 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - # This spec defines Document#add and Document#<< - - describe :rexml_document_add, shared: true do - before :each do - @doc = REXML::Document.new("<root/>") - @decl = REXML::XMLDecl.new("1.0") - end - - it "sets document's XML declaration" do - @doc.send(@method, @decl) - @doc.xml_decl.should == @decl - end - - it "inserts XML declaration as first node" do - @doc.send(@method, @decl) - @doc.children[0].version.should == "1.0" - end - - it "overwrites existing XML declaration" do - @doc.send(@method, @decl) - @doc.send(@method, REXML::XMLDecl.new("2.0")) - @doc.xml_decl.version.should == "2.0" - end - - it "sets document DocType" do - @doc.send(@method, REXML::DocType.new("transitional")) - @doc.doctype.name.should == "transitional" - end - - it "overwrites existing DocType" do - @doc.send(@method, REXML::DocType.new("transitional")) - @doc.send(@method, REXML::DocType.new("strict")) - @doc.doctype.name.should == "strict" - end - - it "adds root node unless it exists" do - d = REXML::Document.new("") - elem = REXML::Element.new "root" - d.send(@method, elem) - d.root.should == elem - end - - it "refuses to add second root" do - -> { @doc.send(@method, REXML::Element.new("foo")) }.should raise_error(RuntimeError) - end - end - - describe "REXML::Document#add" do - it_behaves_like :rexml_document_add, :add - end - - describe "REXML::Document#<<" do - it_behaves_like :rexml_document_add, :<< - end -end diff --git a/spec/ruby/library/rexml/document/clone_spec.rb b/spec/ruby/library/rexml/document/clone_spec.rb deleted file mode 100644 index 137fe8a073..0000000000 --- a/spec/ruby/library/rexml/document/clone_spec.rb +++ /dev/null @@ -1,23 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - # According to the MRI documentation (http://www.ruby-doc.org/stdlib/libdoc/rexml/rdoc/index.html), - # clone's behavior "should be obvious". Apparently "obvious" means cloning - # only the attributes and the context of the document, not its children. - describe "REXML::Document#clone" do - it "clones document attributes" do - d = REXML::Document.new("foo") - d.attributes["foo"] = "bar" - e = d.clone - e.attributes.should == d.attributes - end - - it "clones document context" do - d = REXML::Document.new("foo", {"foo" => "bar"}) - e = d.clone - e.context.should == d.context - end - end -end diff --git a/spec/ruby/library/rexml/document/doctype_spec.rb b/spec/ruby/library/rexml/document/doctype_spec.rb deleted file mode 100644 index e1b7ba4916..0000000000 --- a/spec/ruby/library/rexml/document/doctype_spec.rb +++ /dev/null @@ -1,18 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Document#doctype" do - it "returns the doctype" do - d = REXML::Document.new - dt = REXML::DocType.new("foo") - d.add dt - d.doctype.should == dt - end - - it "returns nil if there's no doctype" do - REXML::Document.new.doctype.should == nil - end - end -end diff --git a/spec/ruby/library/rexml/document/encoding_spec.rb b/spec/ruby/library/rexml/document/encoding_spec.rb deleted file mode 100644 index 2cc947f06a..0000000000 --- a/spec/ruby/library/rexml/document/encoding_spec.rb +++ /dev/null @@ -1,25 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Document#encoding" do - before :each do - @doc = REXML::Document.new - end - - it "returns encoding from XML declaration" do - @doc.add REXML::XMLDecl.new(nil, "UTF-16", nil) - @doc.encoding.should == "UTF-16" - end - - it "returns encoding from XML declaration (for UTF-16 as well)" do - @doc.add REXML::XMLDecl.new("1.0", "UTF-8", nil) - @doc.encoding.should == "UTF-8" - end - - it "uses UTF-8 as default encoding" do - @doc.encoding.should == "UTF-8" - end - end -end diff --git a/spec/ruby/library/rexml/document/expanded_name_spec.rb b/spec/ruby/library/rexml/document/expanded_name_spec.rb deleted file mode 100644 index 9d1025b5e0..0000000000 --- a/spec/ruby/library/rexml/document/expanded_name_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe :document_expanded_name, shared: true do - it "returns an empty string for root" do # root nodes have no expanded name - REXML::Document.new.send(@method).should == "" - end - end - - describe "REXML::Document#expanded_name" do - it_behaves_like :document_expanded_name, :expanded_name - end - - describe "REXML::Document#name" do - it_behaves_like :document_expanded_name, :name - end -end diff --git a/spec/ruby/library/rexml/document/new_spec.rb b/spec/ruby/library/rexml/document/new_spec.rb deleted file mode 100644 index 4e24b6f5a1..0000000000 --- a/spec/ruby/library/rexml/document/new_spec.rb +++ /dev/null @@ -1,39 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Document#new" do - - it "initializes context of {} unless specified" do - d = REXML::Document.new("<foo />") - d.context.should == {} - end - - it "has empty attributes if source is nil" do - d = REXML::Document.new(nil) - d.elements.should be_empty - end - - it "can use other document context" do - s = REXML::Document.new("") - d = REXML::Document.new(s) - d.context.should == s.context - end - - it "clones source attributes" do - s = REXML::Document.new("<root />") - s.attributes["some_attr"] = "some_val" - d = REXML::Document.new(s) - d.attributes.should == s.attributes - end - - it "raises an error if source is not a Document, String or IO" do - -> {REXML::Document.new(3)}.should raise_error(RuntimeError) - end - - it "does not perform XML validation" do - REXML::Document.new("Invalid document").should be_kind_of(REXML::Document) - end - end -end diff --git a/spec/ruby/library/rexml/document/node_type_spec.rb b/spec/ruby/library/rexml/document/node_type_spec.rb deleted file mode 100644 index b6d7e7a7da..0000000000 --- a/spec/ruby/library/rexml/document/node_type_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Document#node_type" do - it "returns :document" do - REXML::Document.new.node_type.should == :document - end - end -end diff --git a/spec/ruby/library/rexml/document/root_spec.rb b/spec/ruby/library/rexml/document/root_spec.rb deleted file mode 100644 index 1a584a720b..0000000000 --- a/spec/ruby/library/rexml/document/root_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Document#root" do - it "returns document root tag name" do - REXML::Document.new("<foo/>").root.name.should == "foo" - end - - it "returns nil if there is not root" do - REXML::Document.new.root.should == nil - end - end -end diff --git a/spec/ruby/library/rexml/document/stand_alone_spec.rb b/spec/ruby/library/rexml/document/stand_alone_spec.rb deleted file mode 100644 index e1c721e782..0000000000 --- a/spec/ruby/library/rexml/document/stand_alone_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Document#stand_alone?" do - it "returns the XMLDecl standalone value" do - d = REXML::Document.new - decl = REXML::XMLDecl.new("1.0", "UTF-8", "yes") - d.add decl - d.stand_alone?.should == "yes" - end - - # According to the docs this should return the default XMLDecl but that - # will carry some more problems when printing the document. Currently, it - # returns nil. See http://www.ruby-forum.com/topic/146812#650061 - it "returns the default value when no XML declaration present" do - REXML::Document.new.stand_alone?.should == nil - end - - end -end diff --git a/spec/ruby/library/rexml/document/version_spec.rb b/spec/ruby/library/rexml/document/version_spec.rb deleted file mode 100644 index 4f6b40551b..0000000000 --- a/spec/ruby/library/rexml/document/version_spec.rb +++ /dev/null @@ -1,17 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Document#version" do - it "returns XML version from declaration" do - d = REXML::Document.new - d.add REXML::XMLDecl.new("1.1") - d.version.should == "1.1" - end - - it "returns the default version when declaration is not present" do - REXML::Document.new.version.should == REXML::XMLDecl::DEFAULT_VERSION - end - end -end diff --git a/spec/ruby/library/rexml/document/write_spec.rb b/spec/ruby/library/rexml/document/write_spec.rb deleted file mode 100644 index 00c22141b3..0000000000 --- a/spec/ruby/library/rexml/document/write_spec.rb +++ /dev/null @@ -1,38 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - require 'rexml/formatters/transitive' - - # Maybe this can be cleaned - describe "REXML::Document#write" do - before :each do - @d = REXML::Document.new - city = REXML::Element.new "Springfield" - street = REXML::Element.new "EvergreenTerrace" - address = REXML::Element.new "House742" - @d << city << street << address - @str = "" - end - - it "returns document source as string" do - @d.write(@str) - @str.should == "<Springfield><EvergreenTerrace><House742/></EvergreenTerrace></Springfield>" - end - - it "returns document indented" do - @d.write(@str, 2) - @str.should =~ /\s*<Springfield>\s*<EvergreenTerrace>\s*<House742\/>\s*<\/EvergreenTerrace>\s*<\/Springfield>/ - end - - it "returns document with transitive support" do - @d.write(@str, 2, true) - @str.should =~ /\s*<Springfield\s*><EvergreenTerrace\s*><House742\s*\/><\/EvergreenTerrace\s*><\/Springfield\s*>/ - end - - it "returns document with support for IE" do - @d.write(@str, -1, false, true) - @str.should == "<Springfield><EvergreenTerrace><House742 /></EvergreenTerrace></Springfield>" - end - end -end diff --git a/spec/ruby/library/rexml/document/xml_decl_spec.rb b/spec/ruby/library/rexml/document/xml_decl_spec.rb deleted file mode 100644 index 8ac47510b0..0000000000 --- a/spec/ruby/library/rexml/document/xml_decl_spec.rb +++ /dev/null @@ -1,18 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Document#xml_decl" do - it "returns XML declaration of the document" do - d = REXML::Document.new - decl = REXML::XMLDecl.new("1.0", "UTF-16", "yes") - d.add decl - d.xml_decl.should == decl - end - - it "returns default XML declaration unless present" do - REXML::Document.new.xml_decl.should == REXML::XMLDecl.new - end - end -end diff --git a/spec/ruby/library/rexml/element/add_attribute_spec.rb b/spec/ruby/library/rexml/element/add_attribute_spec.rb deleted file mode 100644 index 64f2ec84a3..0000000000 --- a/spec/ruby/library/rexml/element/add_attribute_spec.rb +++ /dev/null @@ -1,44 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#add_attribute" do - before :each do - @person = REXML::Element.new "person" - @person.attributes["name"] = "Bill" - end - - it "adds a new attribute" do - @person.add_attribute("age", "17") - @person.attributes["age"].should == "17" - end - - it "overwrites an existing attribute" do - @person.add_attribute("name", "Bill") - @person.attributes["name"].should == "Bill" - end - - it "accepts a pair of strings" do - @person.add_attribute("male", "true") - @person.attributes["male"].should == "true" - end - - it "accepts an Attribute for key" do - attr = REXML::Attribute.new("male", "true") - @person.add_attribute attr - @person.attributes["male"].should == "true" - end - - it "ignores value if key is an Attribute" do - attr = REXML::Attribute.new("male", "true") - @person.add_attribute(attr, "false") - @person.attributes["male"].should == "true" - end - - it "returns the attribute added" do - attr = REXML::Attribute.new("name", "Tony") - @person.add_attribute(attr).should == attr - end - end -end diff --git a/spec/ruby/library/rexml/element/add_attributes_spec.rb b/spec/ruby/library/rexml/element/add_attributes_spec.rb deleted file mode 100644 index f331803dd8..0000000000 --- a/spec/ruby/library/rexml/element/add_attributes_spec.rb +++ /dev/null @@ -1,25 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#add_attributes" do - before :each do - @person = REXML::Element.new "person" - @person.attributes["name"] = "Bill" - end - - it "adds multiple attributes from a hash" do - @person.add_attributes({"name" => "Joe", "age" => "27"}) - @person.attributes["name"].should == "Joe" - @person.attributes["age"].should == "27" - end - - it "adds multiple attributes from an array" do - attrs = { "name" => "Joe", "age" => "27"} - @person.add_attributes attrs.to_a - @person.attributes["name"].should == "Joe" - @person.attributes["age"].should == "27" - end - end -end diff --git a/spec/ruby/library/rexml/element/add_element_spec.rb b/spec/ruby/library/rexml/element/add_element_spec.rb deleted file mode 100644 index 8ba023f2c7..0000000000 --- a/spec/ruby/library/rexml/element/add_element_spec.rb +++ /dev/null @@ -1,41 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#add_element" do - before :each do - @root = REXML::Element.new("root") - end - - it "adds a child without attributes" do - name = REXML::Element.new("name") - @root.add_element name - @root.elements["name"].name.should == name.name - @root.elements["name"].attributes.should == name.attributes - @root.elements["name"].context.should == name.context - end - - it "adds a child with attributes" do - person = REXML::Element.new("person") - @root.add_element(person, {"name" => "Madonna"}) - @root.elements["person"].name.should == person.name - @root.elements["person"].attributes.should == person.attributes - @root.elements["person"].context.should == person.context - end - - it "adds a child with name" do - @root.add_element "name" - @root.elements["name"].name.should == "name" - @root.elements["name"].attributes.should == {} - @root.elements["name"].context.should == nil - end - - it "returns the added child" do - name = @root.add_element "name" - @root.elements["name"].name.should == name.name - @root.elements["name"].attributes.should == name.attributes - @root.elements["name"].context.should == name.context - end - end -end diff --git a/spec/ruby/library/rexml/element/add_namespace_spec.rb b/spec/ruby/library/rexml/element/add_namespace_spec.rb deleted file mode 100644 index 44b074bac7..0000000000 --- a/spec/ruby/library/rexml/element/add_namespace_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#add_namespace" do - before :each do - @elem = REXML::Element.new("person") - end - - it "adds a namespace to element" do - @elem.add_namespace("foo", "bar") - @elem.namespace("foo").should == "bar" - end - - it "accepts a prefix string as prefix" do - @elem.add_namespace("xmlns:foo", "bar") - @elem.namespace("foo").should == "bar" - end - - it "uses prefix as URI if uri is nil" do - @elem.add_namespace("some_uri", nil) - @elem.namespace.should == "some_uri" - end - end -end diff --git a/spec/ruby/library/rexml/element/add_text_spec.rb b/spec/ruby/library/rexml/element/add_text_spec.rb deleted file mode 100644 index 3a0531ad42..0000000000 --- a/spec/ruby/library/rexml/element/add_text_spec.rb +++ /dev/null @@ -1,27 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#add_text" do - before :each do - @name = REXML::Element.new "Name" - end - - it "adds text to an element" do - @name.add_text "Ringo" - @name.to_s.should == "<Name>Ringo</Name>" - end - - it "accepts a Text" do - @name.add_text(REXML::Text.new("Ringo")) - @name.to_s.should == "<Name>Ringo</Name>" - end - - it "joins the new text with the old one" do - @name.add_text "Ringo" - @name.add_text " Starr" - @name.to_s.should == "<Name>Ringo Starr</Name>" - end - end -end diff --git a/spec/ruby/library/rexml/element/attribute_spec.rb b/spec/ruby/library/rexml/element/attribute_spec.rb deleted file mode 100644 index b223d3440c..0000000000 --- a/spec/ruby/library/rexml/element/attribute_spec.rb +++ /dev/null @@ -1,20 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#attribute" do - it "returns an attribute by name" do - person = REXML::Element.new "Person" - attribute = REXML::Attribute.new("drink", "coffee") - person.add_attribute(attribute) - person.attribute("drink").should == attribute - end - - it "supports attributes inside namespaces" do - e = REXML::Element.new("element") - e.add_attributes({"xmlns:ns" => "http://some_uri"}) - e.attribute("ns", "ns").to_s.should == "http://some_uri" - end - end -end diff --git a/spec/ruby/library/rexml/element/attributes_spec.rb b/spec/ruby/library/rexml/element/attributes_spec.rb deleted file mode 100644 index 92bcecc40a..0000000000 --- a/spec/ruby/library/rexml/element/attributes_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#attributes" do - it "returns element's Attributes" do - p = REXML::Element.new "Person" - - name = REXML::Attribute.new("name", "John") - attrs = REXML::Attributes.new(p) - attrs.add name - - p.add_attribute name - p.attributes.should == attrs - end - - it "returns an empty hash if element has no attributes" do - REXML::Element.new("Person").attributes.should == {} - end - end -end diff --git a/spec/ruby/library/rexml/element/cdatas_spec.rb b/spec/ruby/library/rexml/element/cdatas_spec.rb deleted file mode 100644 index 988b2cb422..0000000000 --- a/spec/ruby/library/rexml/element/cdatas_spec.rb +++ /dev/null @@ -1,27 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#cdatas" do - before :each do - @e = REXML::Element.new("Root") - end - - it "returns the array of children cdatas" do - c = REXML::CData.new("Primary") - d = REXML::CData.new("Secondary") - @e << c - @e << d - @e.cdatas.should == [c, d] - end - - it "freezes the returned array" do - @e.cdatas.should.frozen? - end - - it "returns an empty array if element has no cdata" do - @e.cdatas.should == [] - end - end -end diff --git a/spec/ruby/library/rexml/element/clone_spec.rb b/spec/ruby/library/rexml/element/clone_spec.rb deleted file mode 100644 index 490e43181f..0000000000 --- a/spec/ruby/library/rexml/element/clone_spec.rb +++ /dev/null @@ -1,32 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#clone" do - before :each do - @e = REXML::Element.new "a" - end - it "creates a copy of element" do - @e.clone.to_s.should == @e.to_s - end - - it "copies the attributes" do - @e.add_attribute("foo", "bar") - @e.clone.to_s.should == @e.to_s - end - - it "does not copy the text" do - @e.add_text "some text..." - @e.clone.to_s.should_not == @e - @e.clone.to_s.should == "<a/>" - end - - it "does not copy the child elements" do - b = REXML::Element.new "b" - @e << b - @e.clone.should_not == @e - @e.clone.to_s.should == "<a/>" - end - end -end diff --git a/spec/ruby/library/rexml/element/comments_spec.rb b/spec/ruby/library/rexml/element/comments_spec.rb deleted file mode 100644 index 84ab9a7469..0000000000 --- a/spec/ruby/library/rexml/element/comments_spec.rb +++ /dev/null @@ -1,23 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#comments" do - before :each do - @e = REXML::Element.new "root" - @c1 = REXML::Comment.new "this is a comment" - @c2 = REXML::Comment.new "this is another comment" - @e << @c1 - @e << @c2 - end - - it "returns the array of comments" do - @e.comments.should == [@c1, @c2] - end - - it "returns a frozen object" do - @e.comments.should.frozen? - end - end -end diff --git a/spec/ruby/library/rexml/element/delete_attribute_spec.rb b/spec/ruby/library/rexml/element/delete_attribute_spec.rb deleted file mode 100644 index e2ba81eb0d..0000000000 --- a/spec/ruby/library/rexml/element/delete_attribute_spec.rb +++ /dev/null @@ -1,42 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#delete_attribute" do - before :each do - @e = REXML::Element.new("Person") - @attr = REXML::Attribute.new("name", "Sean") - @e.add_attribute(@attr) - end - - it "deletes an attribute from the element" do - @e.delete_attribute("name") - @e.attributes["name"].should be_nil - end - - # Bug was filled with a patch in Ruby's tracker #20298 - quarantine! do - it "receives an Attribute" do - @e.add_attribute(@attr) - @e.delete_attribute(@attr) - @e.attributes["name"].should be_nil - end - end - - # Docs say that it returns the removed attribute but then examples - # show it returns the element with the attribute removed. - # Also fixed in #20298 - it "returns the element with the attribute removed" do - elem = @e.delete_attribute("name") - elem.attributes.should be_empty - elem.to_s.should eql("<Person/>") - end - - it "returns nil if the attribute does not exist" do - @e.delete_attribute("name") - at = @e.delete_attribute("name") - at.should be_nil - end - end -end diff --git a/spec/ruby/library/rexml/element/delete_element_spec.rb b/spec/ruby/library/rexml/element/delete_element_spec.rb deleted file mode 100644 index c0b486a6f7..0000000000 --- a/spec/ruby/library/rexml/element/delete_element_spec.rb +++ /dev/null @@ -1,52 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#delete_element" do - before :each do - @root = REXML::Element.new("root") - end - - it "deletes the child element" do - node = REXML::Element.new("some_node") - @root.add_element node - @root.delete_element node - @root.elements.size.should == 0 - end - - it "deletes a child via XPath" do - @root.add_element "some_node" - @root.delete_element "some_node" - @root.elements.size.should == 0 - end - - it "deletes the child at index" do - @root.add_element "some_node" - @root.delete_element 1 - @root.elements.size.should == 0 - end - - # According to the docs this should return the deleted element - # but it won't if it's an Element. - it "deletes Element and returns it" do - node = REXML::Element.new("some_node") - @root.add_element node - del_node = @root.delete_element node - del_node.should == node - end - - # Note how passing the string will return the removed element - # but passing the Element as above won't. - it "deletes an element and returns it" do - node = REXML::Element.new("some_node") - @root.add_element node - del_node = @root.delete_element "some_node" - del_node.should == node - end - - it "returns nil unless element exists" do - @root.delete_element("something").should == nil - end - end -end diff --git a/spec/ruby/library/rexml/element/delete_namespace_spec.rb b/spec/ruby/library/rexml/element/delete_namespace_spec.rb deleted file mode 100644 index a7763d51e8..0000000000 --- a/spec/ruby/library/rexml/element/delete_namespace_spec.rb +++ /dev/null @@ -1,28 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#delete_namespace" do - - before :each do - @doc = REXML::Document.new "<a xmlns:foo='bar' xmlns='twiddle'/>" - end - - it "deletes a namespace from the element" do - @doc.root.delete_namespace 'foo' - @doc.root.namespace("foo").should be_nil - @doc.root.to_s.should == "<a xmlns='twiddle'/>" - end - - it "deletes default namespace when called with no args" do - @doc.root.delete_namespace - @doc.root.namespace.should be_empty - @doc.root.to_s.should == "<a xmlns:foo='bar'/>" - end - - it "returns the element" do - @doc.root.delete_namespace.should == @doc.root - end - end -end diff --git a/spec/ruby/library/rexml/element/document_spec.rb b/spec/ruby/library/rexml/element/document_spec.rb deleted file mode 100644 index 754f27d8a0..0000000000 --- a/spec/ruby/library/rexml/element/document_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#document" do - - it "returns the element's document" do - d = REXML::Document.new("<root><elem/></root>") - d << REXML::XMLDecl.new - d.root.document.should == d - d.root.document.to_s.should == d.to_s - end - - it "returns nil if it belongs to no document" do - REXML::Element.new("standalone").document.should be_nil - end - end -end diff --git a/spec/ruby/library/rexml/element/each_element_with_attribute_spec.rb b/spec/ruby/library/rexml/element/each_element_with_attribute_spec.rb deleted file mode 100644 index dcc6dbbf17..0000000000 --- a/spec/ruby/library/rexml/element/each_element_with_attribute_spec.rb +++ /dev/null @@ -1,38 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#each_element_with_attributes" do - before :each do - @document = REXML::Element.new("people") - @father = REXML::Element.new("Person") - @father.attributes["name"] = "Joe" - @son = REXML::Element.new("Child") - @son.attributes["name"] = "Fred" - @document.root << @father - @document.root << @son - @children = [] - end - - it "returns children with attribute" do - @document.each_element_with_attribute("name") { |elem| @children << elem } - @children[0].should == @father - @children[1].should == @son - end - - it "takes attribute value as second argument" do - @document.each_element_with_attribute("name", "Fred"){ |elem| elem.should == @son } - end - - it "takes max number of children as third argument" do - @document.each_element_with_attribute("name", nil, 1) { |elem| @children << elem } - @children.size.should == 1 - @children[0].should == @father - end - - it "takes XPath filter as fourth argument" do - @document.each_element_with_attribute("name", nil, 0, "Child"){ |elem| elem.should == @son} - end - end -end diff --git a/spec/ruby/library/rexml/element/each_element_with_text_spec.rb b/spec/ruby/library/rexml/element/each_element_with_text_spec.rb deleted file mode 100644 index a4a200d237..0000000000 --- a/spec/ruby/library/rexml/element/each_element_with_text_spec.rb +++ /dev/null @@ -1,34 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#each_element_with_text" do - before :each do - @document = REXML::Element.new("people") - - @joe = REXML::Element.new("Person") - @joe.text = "Joe" - @fred = REXML::Element.new("Person") - @fred.text = "Fred" - @another = REXML::Element.new("AnotherPerson") - @another.text = "Fred" - @document.root << @joe - @document.root << @fred - @document.root << @another - @children = [] - end - - it "returns children with text" do - @document.each_element_with_text("Joe"){|c| c.should == @joe} - end - - it "takes max as second argument" do - @document.each_element_with_text("Fred", 1){ |c| c.should == @fred} - end - - it "takes XPath filter as third argument" do - @document.each_element_with_text("Fred", 0, "Person"){ |c| c.should == @fred} - end - end -end diff --git a/spec/ruby/library/rexml/element/element_reference_spec.rb b/spec/ruby/library/rexml/element/element_reference_spec.rb deleted file mode 100644 index 9e5d371ce4..0000000000 --- a/spec/ruby/library/rexml/element/element_reference_spec.rb +++ /dev/null @@ -1,23 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#[]" do - - before :each do - @doc = REXML::Document.new("<root foo='bar'></root>") - @child = REXML::Element.new("child") - @doc.root.add_element @child - end - - it "return attribute value if argument is string or symbol" do - @doc.root[:foo].should == 'bar' - @doc.root['foo'].should == 'bar' - end - - it "return nth element if argument is int" do - @doc.root[0].should == @child - end - end -end diff --git a/spec/ruby/library/rexml/element/get_text_spec.rb b/spec/ruby/library/rexml/element/get_text_spec.rb deleted file mode 100644 index 0fa8d7cb3f..0000000000 --- a/spec/ruby/library/rexml/element/get_text_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#get_text" do - before :each do - @doc = REXML::Document.new "<p>some text<b>this is bold!</b> more text</p>" - end - - it "returns the first text child node" do - @doc.root.get_text.value.should == "some text" - @doc.root.get_text.should be_kind_of(REXML::Text) - end - - it "returns text from an element matching path" do - @doc.root.get_text("b").value.should == "this is bold!" - @doc.root.get_text("b").should be_kind_of(REXML::Text) - end - end -end diff --git a/spec/ruby/library/rexml/element/has_attributes_spec.rb b/spec/ruby/library/rexml/element/has_attributes_spec.rb deleted file mode 100644 index af3ce8ce1b..0000000000 --- a/spec/ruby/library/rexml/element/has_attributes_spec.rb +++ /dev/null @@ -1,20 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#has_attributes?" do - before :each do - @e = REXML::Element.new("test_elem") - end - - it "returns true when element has any attributes" do - @e.add_attribute("name", "Joe") - @e.has_attributes?.should be_true - end - - it "returns false if element has no attributes" do - @e.has_attributes?.should be_false - end - end -end diff --git a/spec/ruby/library/rexml/element/has_elements_spec.rb b/spec/ruby/library/rexml/element/has_elements_spec.rb deleted file mode 100644 index 04c7fe01a5..0000000000 --- a/spec/ruby/library/rexml/element/has_elements_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#has_elements?" do - before :each do - @e = REXML::Element.new("root") - end - - it "returns true if element has child elements" do - child = REXML::Element.new("child") - @e << child - @e.has_elements?.should be_true - end - - it "returns false if element doesn't have child elements" do - @e.has_elements?.should be_false - end - end -end diff --git a/spec/ruby/library/rexml/element/has_text_spec.rb b/spec/ruby/library/rexml/element/has_text_spec.rb deleted file mode 100644 index 206c167ae6..0000000000 --- a/spec/ruby/library/rexml/element/has_text_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#has_text?" do - - it "returns true if element has a Text child" do - e = REXML::Element.new("Person") - e.text = "My text" - e.has_text?.should be_true - end - - it "returns false if it has no Text children" do - e = REXML::Element.new("Person") - e.has_text?.should be_false - end - end -end diff --git a/spec/ruby/library/rexml/element/inspect_spec.rb b/spec/ruby/library/rexml/element/inspect_spec.rb deleted file mode 100644 index ec16c136ee..0000000000 --- a/spec/ruby/library/rexml/element/inspect_spec.rb +++ /dev/null @@ -1,30 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#inspect" do - - before :each do - @name = REXML::Element.new "name" - end - - it "returns the node as a string" do - @name.inspect.should == "<name/>" - end - - it "inserts '...' if the node has children" do - e = REXML::Element.new "last_name" - @name << e - @name.inspect.should == "<name> ... </>" - # This might make more sense but differs from MRI's default behavior - # @name.inspect.should == "<name> ... </name>" - end - - it "inserts the attributes in the string" do - @name.add_attribute "language" - @name.attributes["language"] = "english" - @name.inspect.should == "<name language='english'/>" - end - end -end diff --git a/spec/ruby/library/rexml/element/instructions_spec.rb b/spec/ruby/library/rexml/element/instructions_spec.rb deleted file mode 100644 index 11f1396df0..0000000000 --- a/spec/ruby/library/rexml/element/instructions_spec.rb +++ /dev/null @@ -1,24 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#instructions" do - before :each do - @elem = REXML::Element.new("root") - end - it "returns the Instruction children nodes" do - inst = REXML::Instruction.new("xml-stylesheet", "href='headlines.css'") - @elem << inst - @elem.instructions.first.should == inst - end - - it "returns an empty array if it has no Instruction children" do - @elem.instructions.should be_empty - end - - it "freezes the returned array" do - @elem.instructions.frozen?.should be_true - end - end -end diff --git a/spec/ruby/library/rexml/element/namespace_spec.rb b/spec/ruby/library/rexml/element/namespace_spec.rb deleted file mode 100644 index 28966289c5..0000000000 --- a/spec/ruby/library/rexml/element/namespace_spec.rb +++ /dev/null @@ -1,30 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#namespace" do - before :each do - @doc = REXML::Document.new("<a xmlns='1' xmlns:y='2'><b/><c xmlns:z='3'/></a>") - @elem = @doc.elements["//b"] - end - - it "returns the default namespace" do - @elem.namespace.should == "1" - end - - it "accepts a namespace prefix" do - @elem.namespace("y").should == "2" - @doc.elements["//c"].namespace("z").should == "3" - end - - it "returns an empty String if default namespace is not defined" do - e = REXML::Document.new("<a/>") - e.root.namespace.should be_empty - end - - it "returns nil if namespace is not defined" do - @elem.namespace("z").should be_nil - end - end -end diff --git a/spec/ruby/library/rexml/element/namespaces_spec.rb b/spec/ruby/library/rexml/element/namespaces_spec.rb deleted file mode 100644 index 4544540173..0000000000 --- a/spec/ruby/library/rexml/element/namespaces_spec.rb +++ /dev/null @@ -1,35 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#namespaces" do - before :each do - doc = REXML::Document.new("<a xmlns='1' xmlns:y='2'><b/><c xmlns:z='3'/></a>") - @elem = doc.elements["//c"] - end - - it "returns a hash of the namespaces" do - ns = {"y"=>"2", "z"=>"3", "xmlns"=>"1"} - @elem.namespaces.keys.sort.should == ns.keys.sort - @elem.namespaces.values.sort.should == ns.values.sort - end - - it "returns an empty hash if no namespaces exist" do - e = REXML::Element.new "element" - e.namespaces.kind_of?(Hash).should == true - e.namespaces.should be_empty - end - - it "uses namespace prefixes as keys" do - prefixes = ["y", "z", "xmlns"] - @elem.namespaces.keys.sort.should == prefixes.sort - end - - it "uses namespace values as the hash values" do - values = ["2", "3", "1"] - @elem.namespaces.values.sort.should == values.sort - end - - end -end diff --git a/spec/ruby/library/rexml/element/new_spec.rb b/spec/ruby/library/rexml/element/new_spec.rb deleted file mode 100644 index c6ab289476..0000000000 --- a/spec/ruby/library/rexml/element/new_spec.rb +++ /dev/null @@ -1,38 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#new" do - - it "creates element from tag name" do - REXML::Element.new("foo").name.should == "foo" - end - - it "creates element with default attributes" do - e = REXML::Element.new - e.name.should == REXML::Element::UNDEFINED - e.context.should == nil - e.parent.should == nil - end - - it "creates element from another element" do - e = REXML::Element.new "foo" - f = REXML::Element.new e - e.name.should == f.name - e.context.should == f.context - e.parent.should == f.parent - end - - it "takes parent as second argument" do - parent = REXML::Element.new "foo" - child = REXML::Element.new "bar", parent - child.parent.should == parent - end - - it "takes context as third argument" do - context = {"some_key" => "some_value"} - REXML::Element.new("foo", nil, context).context.should == context - end - end -end diff --git a/spec/ruby/library/rexml/element/next_element_spec.rb b/spec/ruby/library/rexml/element/next_element_spec.rb deleted file mode 100644 index 46d8f74760..0000000000 --- a/spec/ruby/library/rexml/element/next_element_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#next_element" do - before :each do - @a = REXML::Element.new "a" - @b = REXML::Element.new "b" - @c = REXML::Element.new "c" - @a.root << @b - @a.root << @c - end - it "returns next existing element" do - @a.elements["b"].next_element.should == @c - end - - it "returns nil on last element" do - @a.elements["c"].next_element.should == nil - end - end -end diff --git a/spec/ruby/library/rexml/element/node_type_spec.rb b/spec/ruby/library/rexml/element/node_type_spec.rb deleted file mode 100644 index a39c2deca5..0000000000 --- a/spec/ruby/library/rexml/element/node_type_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#node_type" do - it "returns :element" do - REXML::Element.new("MyElem").node_type.should == :element - end - end -end diff --git a/spec/ruby/library/rexml/element/prefixes_spec.rb b/spec/ruby/library/rexml/element/prefixes_spec.rb deleted file mode 100644 index ea4caab4bc..0000000000 --- a/spec/ruby/library/rexml/element/prefixes_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#prefixes" do - before :each do - doc = REXML::Document.new("<a xmlns='1' xmlns:y='2'><b/><c xmlns:z='3'/></a>") - @elem = doc.elements["//c"] - end - - it "returns an array of the prefixes of the namespaces" do - @elem.prefixes.should == ["y", "z"] - end - - it "does not include the default namespace" do - @elem.prefixes.include?("xmlns").should == false - end - - it "returns an empty array if no namespace was defined" do - doc = REXML::Document.new "<root><something/></root>" - root = doc.elements["//root"] - root.prefixes.should == [] - end - end -end diff --git a/spec/ruby/library/rexml/element/previous_element_spec.rb b/spec/ruby/library/rexml/element/previous_element_spec.rb deleted file mode 100644 index a43b1ddd10..0000000000 --- a/spec/ruby/library/rexml/element/previous_element_spec.rb +++ /dev/null @@ -1,23 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#previous_element" do - before :each do - @a = REXML::Element.new "a" - @b = REXML::Element.new "b" - @c = REXML::Element.new "c" - @a.root << @b - @a.root << @c - end - - it "returns previous element" do - @a.elements["c"].previous_element.should == @b - end - - it "returns nil on first element" do - @a.elements["b"].previous_element.should == nil - end - end -end diff --git a/spec/ruby/library/rexml/element/raw_spec.rb b/spec/ruby/library/rexml/element/raw_spec.rb deleted file mode 100644 index 200a99d194..0000000000 --- a/spec/ruby/library/rexml/element/raw_spec.rb +++ /dev/null @@ -1,27 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#raw" do - it "returns true if raw mode is set to all" do - REXML::Element.new("MyElem", nil, {raw: :all}).raw.should == true - end - - it "returns true if raw mode is set to expanded_name" do - REXML::Element.new("MyElem", nil, {raw: "MyElem"}).raw.should == true - end - - it "returns false if raw mode is not set" do - REXML::Element.new("MyElem", nil, {raw: ""}).raw.should == false - end - - it "returns false if raw is not :all or expanded_name" do - REXML::Element.new("MyElem", nil, {raw: "Something"}).raw.should == false - end - - it "returns nil if context is not set" do - REXML::Element.new("MyElem").raw.should == nil - end - end -end diff --git a/spec/ruby/library/rexml/element/root_spec.rb b/spec/ruby/library/rexml/element/root_spec.rb deleted file mode 100644 index 52aa4571b9..0000000000 --- a/spec/ruby/library/rexml/element/root_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#root" do - before :each do - @doc = REXML::Document.new - @root = REXML::Element.new "root" - @node = REXML::Element.new "node" - @doc << @root << @node - end - - it "returns first child on documents" do - @doc.root.should == @root - end - - it "returns self on root nodes" do - @root.root.should == @root - end - - it "returns parent's root on child nodes" do - @node.root.should == @root - end - - it "returns self on standalone nodes" do - e = REXML::Element.new "Elem" # Note that it doesn't have a parent node - e.root.should == e - end - end -end diff --git a/spec/ruby/library/rexml/element/text_spec.rb b/spec/ruby/library/rexml/element/text_spec.rb deleted file mode 100644 index 3234bba153..0000000000 --- a/spec/ruby/library/rexml/element/text_spec.rb +++ /dev/null @@ -1,49 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#text" do - before :each do - @e = REXML::Element.new "name" - @e.text = "John" - end - - it "returns the text node of element" do - @e.text.should == "John" - end - - it "returns the text node value" do - t = REXML::Text.new "Joe" - @e.text = t - @e.text.should == "Joe" - @e.text.should_not == t - end - - it "returns nil if no text is attached" do - elem = REXML::Element.new "name" - elem.text.should == nil - end - end - - describe "REXML::Element#text=" do - before :each do - @e = REXML::Element.new "name" - @e.text = "John" - end - - it "sets the text node" do - @e.to_s.should == "<name>John</name>" - end - - it "replaces existing text" do - @e.text = "Joe" - @e.to_s.should == "<name>Joe</name>" - end - - it "receives nil as an argument" do - @e.text = nil - @e.to_s.should == "<name/>" - end - end -end diff --git a/spec/ruby/library/rexml/element/texts_spec.rb b/spec/ruby/library/rexml/element/texts_spec.rb deleted file mode 100644 index 2d374d5e66..0000000000 --- a/spec/ruby/library/rexml/element/texts_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#texts" do - - it "returns an array of the Text children" do - e = REXML::Element.new("root") - e.add_text "First" - e.add_text "Second" - e.texts.should == ["FirstSecond"] - end - - it "returns an empty array if it has no Text children" do - REXML::Element.new("root").texts.should == [] - end - end -end diff --git a/spec/ruby/library/rexml/element/whitespace_spec.rb b/spec/ruby/library/rexml/element/whitespace_spec.rb deleted file mode 100644 index f455067922..0000000000 --- a/spec/ruby/library/rexml/element/whitespace_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#whitespace" do - it "returns true if whitespace is respected in the element" do - e = REXML::Element.new("root") - e.whitespace.should be_true - - e = REXML::Element.new("root", nil, respect_whitespace: :all) - e.whitespace.should be_true - - e = REXML::Element.new("root", nil, respect_whitespace: ["root"]) - e.whitespace.should be_true - end - - it "returns false if whitespace is ignored inside element" do - e = REXML::Element.new("root", nil, compress_whitespace: :all) - e.whitespace.should be_false - - e = REXML::Element.new("root", nil, compress_whitespace: ["root"]) - e.whitespace.should be_false - end - end -end diff --git a/spec/ruby/library/rexml/node/each_recursive_spec.rb b/spec/ruby/library/rexml/node/each_recursive_spec.rb deleted file mode 100644 index da347b1389..0000000000 --- a/spec/ruby/library/rexml/node/each_recursive_spec.rb +++ /dev/null @@ -1,24 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Node#each_recursive" do - before :each do - @doc = REXML::Document.new - @doc << REXML::XMLDecl.new - @root = REXML::Element.new "root" - @child1 = REXML::Element.new "child1" - @child2 = REXML::Element.new "child2" - @root << @child1 - @root << @child2 - @doc << @root - end - - it "visits all subnodes of self" do - nodes = [] - @doc.each_recursive { |node| nodes << node} - nodes.should == [@root, @child1, @child2] - end - end -end diff --git a/spec/ruby/library/rexml/node/find_first_recursive_spec.rb b/spec/ruby/library/rexml/node/find_first_recursive_spec.rb deleted file mode 100644 index 2a4f1097ae..0000000000 --- a/spec/ruby/library/rexml/node/find_first_recursive_spec.rb +++ /dev/null @@ -1,28 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Node#find_first_recursive" do - before :each do - @e = REXML::Element.new("root") - @node1 = REXML::Element.new("node") - @node2 = REXML::Element.new("another node") - @subnode = REXML::Element.new("another node") - @node1 << @subnode - @e << @node1 - @e << @node2 - end - - it "finds the first element that matches block" do - found = @e.find_first_recursive { |n| n.to_s == "<node><another node/></node>"} - found.should == @node1 - end - - it "visits the nodes in preorder" do - found = @e.find_first_recursive { |n| n.to_s == "<another node/>"} - found.should == @subnode - found.should_not == @node2 - end - end -end diff --git a/spec/ruby/library/rexml/node/index_in_parent_spec.rb b/spec/ruby/library/rexml/node/index_in_parent_spec.rb deleted file mode 100644 index 55909f86d6..0000000000 --- a/spec/ruby/library/rexml/node/index_in_parent_spec.rb +++ /dev/null @@ -1,18 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Node#index_in_parent" do - it "returns the index (starting from 1) of self in parent" do - e = REXML::Element.new("root") - node1 = REXML::Element.new("node") - node2 = REXML::Element.new("another node") - e << node1 - e << node2 - - node1.index_in_parent.should == 1 - node2.index_in_parent.should == 2 - end - end -end diff --git a/spec/ruby/library/rexml/node/next_sibling_node_spec.rb b/spec/ruby/library/rexml/node/next_sibling_node_spec.rb deleted file mode 100644 index 7aae861d75..0000000000 --- a/spec/ruby/library/rexml/node/next_sibling_node_spec.rb +++ /dev/null @@ -1,24 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Node#next_sibling_node" do - before :each do - @e = REXML::Element.new("root") - @node1 = REXML::Element.new("node") - @node2 = REXML::Element.new("another node") - @e << @node1 - @e << @node2 - end - - it "returns the next child node in parent" do - @node1.next_sibling_node.should == @node2 - end - - it "returns nil if there are no more child nodes next" do - @node2.next_sibling_node.should == nil - @e.next_sibling_node.should == nil - end - end -end diff --git a/spec/ruby/library/rexml/node/parent_spec.rb b/spec/ruby/library/rexml/node/parent_spec.rb deleted file mode 100644 index 43c3a747e0..0000000000 --- a/spec/ruby/library/rexml/node/parent_spec.rb +++ /dev/null @@ -1,23 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Node#parent?" do - it "returns true for Elements" do - e = REXML::Element.new("foo") - e.should.parent? - end - - it "returns true for Documents" do - e = REXML::Document.new - e.should.parent? - end - - # This includes attributes, CData and declarations. - it "returns false for Texts" do - e = REXML::Text.new("foo") - e.should_not.parent? - end - end -end diff --git a/spec/ruby/library/rexml/node/previous_sibling_node_spec.rb b/spec/ruby/library/rexml/node/previous_sibling_node_spec.rb deleted file mode 100644 index 11263968a7..0000000000 --- a/spec/ruby/library/rexml/node/previous_sibling_node_spec.rb +++ /dev/null @@ -1,24 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Node#previous_sibling_node" do - before :each do - @e = REXML::Element.new("root") - @node1 = REXML::Element.new("node") - @node2 = REXML::Element.new("another node") - @e << @node1 - @e << @node2 - end - - it "returns the previous child node in parent" do - @node2.previous_sibling_node.should == @node1 - end - - it "returns nil if there are no more child nodes before" do - @node1.previous_sibling_node.should == nil - @e.previous_sibling_node.should == nil - end - end -end diff --git a/spec/ruby/library/rexml/shared/each_element.rb b/spec/ruby/library/rexml/shared/each_element.rb deleted file mode 100644 index 2e0871161d..0000000000 --- a/spec/ruby/library/rexml/shared/each_element.rb +++ /dev/null @@ -1,36 +0,0 @@ -require 'rexml/document' -require_relative '../../../spec_helper' - -describe :rexml_each_element, shared: true do - before :each do - @e = REXML::Element.new "root" - s1 = REXML::Element.new "node1" - s2 = REXML::Element.new "node2" - s3 = REXML::Element.new "node3" - s4 = REXML::Element.new "sub_node" - @e << s1 - @e << s2 - @e << s3 - @e << s4 - end - - it "iterates through element" do - str = "" - @e.send(@method) { |elem| str << elem.name << " " } - str.should == "node1 node2 node3 sub_node " - end - - it "iterates through element filtering with XPath" do - str = "" - @e.send(@method, "/*"){ |e| str << e.name << " "} - str.should == "node1 node2 node3 sub_node " - end -end - -describe "REXML::Element#each_element" do - it_behaves_like :rexml_each_element, :each_element -end - -describe "REXML::Elements#each" do - it_behaves_like :rexml_each_element, :each -end diff --git a/spec/ruby/library/rexml/shared/elements_to_a.rb b/spec/ruby/library/rexml/shared/elements_to_a.rb deleted file mode 100644 index b7169f0b2e..0000000000 --- a/spec/ruby/library/rexml/shared/elements_to_a.rb +++ /dev/null @@ -1,34 +0,0 @@ -require 'rexml/document' -require_relative '../../../spec_helper' - -describe :rexml_elements_to_a, shared: true do - before :each do - @e = REXML::Element.new "root" - @first = REXML::Element.new("FirstChild") - @second = REXML::Element.new("SecondChild") - @e << @first - @e << @second - end - - it "returns elements that match xpath" do - @e.elements.send(@method, "FirstChild").first.should == @first - end - - # According to the docs REXML::Element#get_elements is an alias for - # REXML::Elements.to_a. Implementation wise there's a difference, get_elements - # always needs the first param (even if it's nil). - # A patch was submitted: - # http://rubyforge.org/tracker/index.php?func=detail&aid=19354&group_id=426&atid=1698 - it "returns all children if xpath is nil" do - @e.elements.send(@method).should == [@first, @second] - end - -end - -describe "REXML::REXML::Elements#to_a" do - it_behaves_like :rexml_elements_to_a, :to_a -end - -describe "REXML::REXML::Element#get_elements" do - it_behaves_like :rexml_elements_to_a, :get_elements -end diff --git a/spec/ruby/library/rexml/text/append_spec.rb b/spec/ruby/library/rexml/text/append_spec.rb deleted file mode 100644 index 5e7a5bae7c..0000000000 --- a/spec/ruby/library/rexml/text/append_spec.rb +++ /dev/null @@ -1,13 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Text#<<" do - it "appends a string to this text node" do - text = REXML::Text.new("foo") - text << "bar" - text.should == "foobar" - end - end -end diff --git a/spec/ruby/library/rexml/text/clone_spec.rb b/spec/ruby/library/rexml/text/clone_spec.rb deleted file mode 100644 index 7801782ff5..0000000000 --- a/spec/ruby/library/rexml/text/clone_spec.rb +++ /dev/null @@ -1,13 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Text#clone" do - it "creates a copy of this node" do - text = REXML::Text.new("foo") - text.clone.should == "foo" - text.clone.should == text - end - end -end diff --git a/spec/ruby/library/rexml/text/comparison_spec.rb b/spec/ruby/library/rexml/text/comparison_spec.rb deleted file mode 100644 index 119dd050a6..0000000000 --- a/spec/ruby/library/rexml/text/comparison_spec.rb +++ /dev/null @@ -1,28 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Text#<=>" do - before :each do - @first = REXML::Text.new("abc") - @last = REXML::Text.new("def") - end - - it "returns -1 if lvalue is less than rvalue" do - val = @first <=> @last - val.should == -1 - end - - it "returns -1 if lvalue is greater than rvalue" do - val = @last <=> @first - val.should == 1 - end - - it "returns 0 if both values are equal" do - tmp = REXML::Text.new("tmp") - val = tmp <=> tmp - val.should == 0 - end - end -end diff --git a/spec/ruby/library/rexml/text/empty_spec.rb b/spec/ruby/library/rexml/text/empty_spec.rb deleted file mode 100644 index 4c9c899bcb..0000000000 --- a/spec/ruby/library/rexml/text/empty_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Text#empty?" do - it "returns true if the text is empty" do - REXML::Text.new("").should.empty? - end - - it "returns false if the text is not empty" do - REXML::Text.new("some_text").should_not.empty? - end - end -end diff --git a/spec/ruby/library/rexml/text/indent_text_spec.rb b/spec/ruby/library/rexml/text/indent_text_spec.rb deleted file mode 100644 index 73065c37da..0000000000 --- a/spec/ruby/library/rexml/text/indent_text_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Text#indent_text" do - before :each do - @t = REXML::Text.new("") - end - it "indents a string with default parameters" do - @t.indent_text("foo").should == "\tfoo" - end - - it "accepts a custom indentation level as second argument" do - @t.indent_text("foo", 2, "\t", true).should == "\t\tfoo" - end - - it "accepts a custom separator as third argument" do - @t.indent_text("foo", 1, "\n", true).should == "\nfoo" - end - - it "accepts a fourth parameter to skip the first line" do - @t.indent_text("foo", 1, "\t", false).should == "foo" - end - end -end diff --git a/spec/ruby/library/rexml/text/inspect_spec.rb b/spec/ruby/library/rexml/text/inspect_spec.rb deleted file mode 100644 index af389890ee..0000000000 --- a/spec/ruby/library/rexml/text/inspect_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Text#inspect" do - it "inspects the string attribute as a string" do - REXML::Text.new("a text").inspect.should == "a text".inspect - end - end -end diff --git a/spec/ruby/library/rexml/text/new_spec.rb b/spec/ruby/library/rexml/text/new_spec.rb deleted file mode 100644 index 8b33da9294..0000000000 --- a/spec/ruby/library/rexml/text/new_spec.rb +++ /dev/null @@ -1,51 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Text.new" do - - it "creates a Text child node with no parent" do - t = REXML::Text.new("test") - t.should be_kind_of(REXML::Child) - t.should == "test" - t.parent.should == nil - end - - it "respects whitespace if second argument is true" do - t = REXML::Text.new("testing whitespace", true) - t.should == "testing whitespace" - t = REXML::Text.new(" ", true) - t.should == " " - end - - it "receives a parent as third argument" do - e = REXML::Element.new("root") - t = REXML::Text.new("test", false, e) - t.parent.should == e - e.to_s.should == "<root>test</root>" - end - - it "expects escaped text if raw is true" do - t = REXML::Text.new("<&>", false, nil, true) - t.should == "<&>" - - ->{ REXML::Text.new("<&>", false, nil, true)}.should raise_error(Exception) - end - - it "uses raw value of the parent if raw is nil" do - e1 = REXML::Element.new("root", nil, { raw: :all}) - -> {REXML::Text.new("<&>", false, e1)}.should raise_error(Exception) - - e2 = REXML::Element.new("root", nil, { raw: []}) - e2.raw.should be_false - t1 = REXML::Text.new("<&>", false, e2) - t1.should == "<&>" - end - - it "escapes the values if raw is false" do - t = REXML::Text.new("<&>", false, nil, false) - t.should == "<&>" - end - end -end diff --git a/spec/ruby/library/rexml/text/node_type_spec.rb b/spec/ruby/library/rexml/text/node_type_spec.rb deleted file mode 100644 index f44a1ede3e..0000000000 --- a/spec/ruby/library/rexml/text/node_type_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Text#node_type" do - it "returns :text" do - REXML::Text.new("test").node_type.should == :text - end - end -end diff --git a/spec/ruby/library/rexml/text/normalize_spec.rb b/spec/ruby/library/rexml/text/normalize_spec.rb deleted file mode 100644 index cde11ec3c9..0000000000 --- a/spec/ruby/library/rexml/text/normalize_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Text.normalize" do - it "escapes a string with <, >, &, ' and \" " do - REXML::Text.normalize("< > & \" '").should == "< > & " '" - end - end -end diff --git a/spec/ruby/library/rexml/text/read_with_substitution_spec.rb b/spec/ruby/library/rexml/text/read_with_substitution_spec.rb deleted file mode 100644 index 7ff26f4d53..0000000000 --- a/spec/ruby/library/rexml/text/read_with_substitution_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Text.read_with_substitution" do - it "reads a text and escapes entities" do - REXML::Text.read_with_substitution("< > & " '").should == "< > & \" '" - end - - it "accepts an regex for invalid expressions and raises an error if text matches" do - -> {REXML::Text.read_with_substitution("this is illegal", /illegal/)}.should raise_error(Exception) - end - end -end diff --git a/spec/ruby/library/rexml/text/to_s_spec.rb b/spec/ruby/library/rexml/text/to_s_spec.rb deleted file mode 100644 index e67632c9a1..0000000000 --- a/spec/ruby/library/rexml/text/to_s_spec.rb +++ /dev/null @@ -1,20 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Text#to_s" do - it "returns the string of this Text node" do - u = REXML::Text.new("sean russell", false, nil, true) - u.to_s.should == "sean russell" - - t = REXML::Text.new("some test text") - t.to_s.should == "some test text" - end - - it "escapes the text" do - t = REXML::Text.new("& < >") - t.to_s.should == "& < >" - end - end -end diff --git a/spec/ruby/library/rexml/text/unnormalize_spec.rb b/spec/ruby/library/rexml/text/unnormalize_spec.rb deleted file mode 100644 index 7b507194d0..0000000000 --- a/spec/ruby/library/rexml/text/unnormalize_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Text.unnormalize" do - it "unescapes a string with the values defined in SETUTITSBUS" do - REXML::Text.unnormalize("< > & " '").should == "< > & \" '" - end - end -end diff --git a/spec/ruby/library/rexml/text/value_spec.rb b/spec/ruby/library/rexml/text/value_spec.rb deleted file mode 100644 index 53d40c765f..0000000000 --- a/spec/ruby/library/rexml/text/value_spec.rb +++ /dev/null @@ -1,40 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Text#value" do - it "returns the text value of this node" do - REXML::Text.new("test").value.should == "test" - end - - it "does not escape entities" do - REXML::Text.new("& \"").value.should == "& \"" - end - - it "follows the respect_whitespace attribute" do - REXML::Text.new("test bar", false).value.should == "test bar" - REXML::Text.new("test bar", true).value.should == "test bar" - end - - it "ignores the raw attribute" do - REXML::Text.new("sean russell", false, nil, true).value.should == "sean russell" - end - end - - describe "REXML::Text#value=" do - before :each do - @t = REXML::Text.new("new") - end - - it "sets the text of the node" do - @t.value = "another text" - @t.to_s.should == "another text" - end - - it "escapes entities" do - @t.value = "<a>" - @t.to_s.should == "<a>" - end - end -end diff --git a/spec/ruby/library/rexml/text/wrap_spec.rb b/spec/ruby/library/rexml/text/wrap_spec.rb deleted file mode 100644 index 331a8439e2..0000000000 --- a/spec/ruby/library/rexml/text/wrap_spec.rb +++ /dev/null @@ -1,23 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Text#wrap" do - before :each do - @t = REXML::Text.new("abc def") - end - - it "wraps the text at width" do - @t.wrap("abc def", 3, false).should == "abc\ndef" - end - - it "returns the string if width is greater than the size of the string" do - @t.wrap("abc def", 10, false).should == "abc def" - end - - it "takes a newline at the beginning option as the third parameter" do - @t.wrap("abc def", 3, true).should == "\nabc\ndef" - end - end -end diff --git a/spec/ruby/library/rexml/text/write_with_substitution_spec.rb b/spec/ruby/library/rexml/text/write_with_substitution_spec.rb deleted file mode 100644 index 840f141e3d..0000000000 --- a/spec/ruby/library/rexml/text/write_with_substitution_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Text#write_with_substitution" do - before :each do - @t = REXML::Text.new("test") - @f = tmp("rexml_spec") - @file = File.open(@f, "w+") - end - - after :each do - @file.close - rm_r @f - end - - it "writes out the input to a String" do - s = "" - @t.write_with_substitution(s, "some text") - s.should == "some text" - end - - it "writes out the input to an IO" do - @t.write_with_substitution(@file, "some text") - @file.rewind - @file.gets.should == "some text" - end - - it "escapes characters" do - @t.write_with_substitution(@file, "& < >") - @file.rewind - @file.gets.should == "& < >" - end - end -end diff --git a/spec/ruby/library/rubygems/gem/bin_path_spec.rb b/spec/ruby/library/rubygems/gem/bin_path_spec.rb index 67b3e042c2..0b8c4db08b 100644 --- a/spec/ruby/library/rubygems/gem/bin_path_spec.rb +++ b/spec/ruby/library/rubygems/gem/bin_path_spec.rb @@ -22,6 +22,7 @@ describe "Gem.bin_path" do end skip "Could not find the default gemspecs" unless Dir.exist?(default_specifications_dir) + skip "default_specifications_dir mismatch with GEM_HOME" if ENV["GEM_HOME"] && !default_specifications_dir.start_with?(ENV['GEM_HOME']) Gem::Specification.each_spec([default_specifications_dir]) do |spec| spec.executables.each do |exe| diff --git a/spec/ruby/library/securerandom/random_number_spec.rb b/spec/ruby/library/securerandom/random_number_spec.rb index 03781f4901..bb25bc496e 100644 --- a/spec/ruby/library/securerandom/random_number_spec.rb +++ b/spec/ruby/library/securerandom/random_number_spec.rb @@ -11,8 +11,8 @@ describe "SecureRandom.random_number" do (1..64).each do |idx| num = SecureRandom.random_number(idx) num.should be_kind_of(Integer) - (0 <= num).should == true - (num < idx).should == true + 0.should <= num + num.should < idx end end @@ -21,8 +21,8 @@ describe "SecureRandom.random_number" do 11.times do num = SecureRandom.random_number max num.should be_kind_of(Integer) - (0 <= num).should == true - (num < max).should == true + 0.should <= num + num.should < max end end @@ -30,8 +30,8 @@ describe "SecureRandom.random_number" do 64.times do num = SecureRandom.random_number num.should be_kind_of(Float) - (0.0 <= num).should == true - (num < 1.0).should == true + 0.0.should <= num + num.should < 1.0 end end @@ -39,8 +39,8 @@ describe "SecureRandom.random_number" do 64.times do num = SecureRandom.random_number 11...13 num.should be_kind_of(Integer) - (11 <= num).should == true - (num < 13).should == true + 11.should <= num + num.should < 13 end end @@ -50,8 +50,8 @@ describe "SecureRandom.random_number" do 32.times do num = SecureRandom.random_number lower..upper num.should be_kind_of(Integer) - (lower <= num).should == true - (num <= upper).should == true + lower.should <= num + num.should <= upper end end @@ -59,23 +59,23 @@ describe "SecureRandom.random_number" do 64.times do num = SecureRandom.random_number 0.6..0.9 num.should be_kind_of(Float) - (0.6 <= num).should == true - (num <= 0.9).should == true + 0.6.should <= num + num.should <= 0.9 end end it "generates a random float number between 0.0 and 1.0 if argument is negative" do num = SecureRandom.random_number(-10) num.should be_kind_of(Float) - (0.0 <= num).should == true - (num < 1.0).should == true + 0.0.should <= num + num.should < 1.0 end it "generates a random float number between 0.0 and 1.0 if argument is negative float" do num = SecureRandom.random_number(-11.1) num.should be_kind_of(Float) - (0.0 <= num).should == true - (num < 1.0).should == true + 0.0.should <= num + num.should < 1.0 end it "generates different float numbers with subsequent invocations" do @@ -84,7 +84,7 @@ describe "SecureRandom.random_number" do 256.times do val = SecureRandom.random_number # make sure the random values are not repeating - values.include?(val).should == false + values.should_not include(val) values << val end end diff --git a/spec/ruby/library/set/add_spec.rb b/spec/ruby/library/set/add_spec.rb deleted file mode 100644 index 68356cc111..0000000000 --- a/spec/ruby/library/set/add_spec.rb +++ /dev/null @@ -1,27 +0,0 @@ -require_relative '../../spec_helper' -require 'set' -require_relative 'shared/add' - -describe "Set#add" do - it_behaves_like :set_add, :add -end - -describe "Set#add?" do - before :each do - @set = Set.new - end - - it "adds the passed Object to self" do - @set.add?("cat") - @set.should include("cat") - end - - it "returns self when the Object has not yet been added to self" do - @set.add?("cat").should equal(@set) - end - - it "returns nil when the Object has already been added to self" do - @set.add?("cat") - @set.add?("cat").should be_nil - end -end diff --git a/spec/ruby/library/set/append_spec.rb b/spec/ruby/library/set/append_spec.rb deleted file mode 100644 index 8b3498b779..0000000000 --- a/spec/ruby/library/set/append_spec.rb +++ /dev/null @@ -1,7 +0,0 @@ -require_relative '../../spec_helper' -require 'set' -require_relative 'shared/add' - -describe "Set#<<" do - it_behaves_like :set_add, :<< -end diff --git a/spec/ruby/library/set/case_compare_spec.rb b/spec/ruby/library/set/case_compare_spec.rb deleted file mode 100644 index 70d392a27d..0000000000 --- a/spec/ruby/library/set/case_compare_spec.rb +++ /dev/null @@ -1,12 +0,0 @@ -require_relative '../../spec_helper' -require_relative 'shared/include' -require 'set' - -describe "Set#===" do - it_behaves_like :set_include, :=== - - it "is an alias for include?" do - set = Set.new - set.method(:===).should == set.method(:include?) - end -end diff --git a/spec/ruby/library/set/case_equality_spec.rb b/spec/ruby/library/set/case_equality_spec.rb deleted file mode 100644 index 10cbfd380a..0000000000 --- a/spec/ruby/library/set/case_equality_spec.rb +++ /dev/null @@ -1,7 +0,0 @@ -require_relative '../../spec_helper' -require_relative 'shared/include' -require 'set' - -describe "Set#===" do - it_behaves_like :set_include, :=== -end diff --git a/spec/ruby/library/set/classify_spec.rb b/spec/ruby/library/set/classify_spec.rb deleted file mode 100644 index ec600c91d6..0000000000 --- a/spec/ruby/library/set/classify_spec.rb +++ /dev/null @@ -1,27 +0,0 @@ -require_relative '../../spec_helper' -require 'set' - -describe "Set#classify" do - before :each do - @set = Set["one", "two", "three", "four"] - end - - it "yields each Object in self" do - res = [] - @set.classify { |x| res << x } - res.sort.should == ["one", "two", "three", "four"].sort - end - - it "returns an Enumerator when passed no block" do - enum = @set.classify - enum.should be_an_instance_of(Enumerator) - - classified = enum.each { |x| x.length } - classified.should == { 3 => Set["one", "two"], 4 => Set["four"], 5 => Set["three"] } - end - - it "classifies the Objects in self based on the block's return value" do - classified = @set.classify { |x| x.length } - classified.should == { 3 => Set["one", "two"], 4 => Set["four"], 5 => Set["three"] } - end -end diff --git a/spec/ruby/library/set/clear_spec.rb b/spec/ruby/library/set/clear_spec.rb deleted file mode 100644 index 2b1c9c5b5a..0000000000 --- a/spec/ruby/library/set/clear_spec.rb +++ /dev/null @@ -1,17 +0,0 @@ -require_relative '../../spec_helper' -require 'set' - -describe "Set#clear" do - before :each do - @set = Set["one", "two", "three", "four"] - end - - it "removes all elements from self" do - @set.clear - @set.should be_empty - end - - it "returns self" do - @set.clear.should equal(@set) - end -end diff --git a/spec/ruby/library/set/collect_spec.rb b/spec/ruby/library/set/collect_spec.rb deleted file mode 100644 index f8813a9331..0000000000 --- a/spec/ruby/library/set/collect_spec.rb +++ /dev/null @@ -1,7 +0,0 @@ -require_relative '../../spec_helper' -require 'set' -require_relative 'shared/collect' - -describe "Set#collect!" do - it_behaves_like :set_collect_bang, :collect! -end diff --git a/spec/ruby/library/set/compare_by_identity_spec.rb b/spec/ruby/library/set/compare_by_identity_spec.rb deleted file mode 100644 index 9ed1602189..0000000000 --- a/spec/ruby/library/set/compare_by_identity_spec.rb +++ /dev/null @@ -1,143 +0,0 @@ -require_relative '../../spec_helper' -require 'set' - -describe "Set#compare_by_identity" do - it "compares its members by identity" do - a = "a" - b1 = "b" - b2 = "b" - - set = Set.new - set.compare_by_identity - set.merge([a, a, b1, b2]) - set.to_a.sort.should == [a, b1, b2].sort - end - - it "causes future comparisons on the receiver to be made by identity" do - elt = [1] - set = Set.new - set << elt - set.member?(elt.dup).should be_true - set.compare_by_identity - set.member?(elt.dup).should be_false - end - - it "rehashes internally so that old members can be looked up" do - set = Set.new - (1..10).each { |k| set << k } - o = Object.new - def o.hash; 123; end - set << o - set.compare_by_identity - set.member?(o).should be_true - end - - it "returns self" do - set = Set.new - result = set.compare_by_identity - result.should equal(set) - end - - it "is idempotent and has no effect on an already compare_by_identity set" do - set = Set.new.compare_by_identity - set << :foo - set.compare_by_identity.should equal(set) - set.should.compare_by_identity? - set.to_a.should == [:foo] - end - - it "uses the semantics of BasicObject#equal? to determine members identity" do - :a.equal?(:a).should == true - Set.new.compare_by_identity.merge([:a, :a]).to_a.should == [:a] - - ary1 = [1] - ary2 = [1] - ary1.equal?(ary2).should == false - Set.new.compare_by_identity.merge([ary1, ary2]).to_a.sort.should == [ary1, ary2].sort - end - - it "uses #equal? semantics, but doesn't actually call #equal? to determine identity" do - set = Set.new.compare_by_identity - obj = mock("equal") - obj.should_not_receive(:equal?) - set << :foo - set << obj - set.to_a.should == [:foo, obj] - end - - it "does not call #hash on members" do - elt = mock("element") - elt.should_not_receive(:hash) - set = Set.new.compare_by_identity - set << elt - set.member?(elt).should be_true - end - - it "regards #dup'd objects as having different identities" do - a1 = "a" - a2 = a1.dup - - set = Set.new.compare_by_identity - set.merge([a1, a2]) - set.to_a.sort.should == [a1, a2].sort - end - - it "regards #clone'd objects as having different identities" do - a1 = "a" - a2 = a1.clone - - set = Set.new.compare_by_identity - set.merge([a1, a2]) - set.to_a.sort.should == [a1, a2].sort - end - - it "raises a FrozenError on frozen sets" do - set = Set.new.freeze - -> { - set.compare_by_identity - }.should raise_error(FrozenError, /frozen Hash/) - end - - it "persists over #dups" do - set = Set.new.compare_by_identity - set << :a - set_dup = set.dup - set_dup.should == set - set_dup << :a - set_dup.to_a.should == [:a] - end - - it "persists over #clones" do - set = Set.new.compare_by_identity - set << :a - set_clone = set.clone - set_clone.should == set - set_clone << :a - set_clone.to_a.should == [:a] - end - - it "is not equal to set what does not compare by identity" do - Set.new([1, 2]).should == Set.new([1, 2]) - Set.new([1, 2]).should_not == Set.new([1, 2]).compare_by_identity - end -end - -describe "Set#compare_by_identity?" do - it "returns false by default" do - Set.new.should_not.compare_by_identity? - end - - it "returns true once #compare_by_identity has been invoked on self" do - set = Set.new - set.compare_by_identity - set.should.compare_by_identity? - end - - it "returns true when called multiple times on the same set" do - set = Set.new - set.compare_by_identity - set.should.compare_by_identity? - set.should.compare_by_identity? - set.should.compare_by_identity? - end -end diff --git a/spec/ruby/library/set/comparison_spec.rb b/spec/ruby/library/set/comparison_spec.rb deleted file mode 100644 index 6b7a71e659..0000000000 --- a/spec/ruby/library/set/comparison_spec.rb +++ /dev/null @@ -1,29 +0,0 @@ -require_relative '../../spec_helper' -require 'set' - -ruby_version_is "3.0" do - describe "Set#<=>" do - it "returns 0 if the sets are equal" do - (Set[] <=> Set[]).should == 0 - (Set[:a, :b, :c] <=> Set[:a, :b, :c]).should == 0 - end - - it "returns -1 if the set is a proper subset of the other set" do - (Set[] <=> Set[1]).should == -1 - (Set[1, 2] <=> Set[1, 2, 3]).should == -1 - end - - it "returns +1 if the set is a proper superset of other set" do - (Set[1] <=> Set[]).should == +1 - (Set[1, 2, 3] <=> Set[1, 2]).should == +1 - end - - it "returns nil if the set has unique elements" do - (Set[1, 2, 3] <=> Set[:a, :b, :c]).should be_nil - end - - it "returns nil when the argument is not set-like" do - (Set[] <=> false).should be_nil - end - end -end diff --git a/spec/ruby/library/set/constructor_spec.rb b/spec/ruby/library/set/constructor_spec.rb deleted file mode 100644 index bb84861514..0000000000 --- a/spec/ruby/library/set/constructor_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require_relative '../../spec_helper' -require 'set' - -describe "Set[]" do - it "returns a new Set populated with the passed Objects" do - set = Set[1, 2, 3] - - set.instance_of?(Set).should be_true - set.size.should eql(3) - - set.should include(1) - set.should include(2) - set.should include(3) - end -end diff --git a/spec/ruby/library/set/delete_if_spec.rb b/spec/ruby/library/set/delete_if_spec.rb deleted file mode 100644 index 33caeeaab7..0000000000 --- a/spec/ruby/library/set/delete_if_spec.rb +++ /dev/null @@ -1,38 +0,0 @@ -require_relative '../../spec_helper' -require 'set' - -describe "Set#delete_if" do - before :each do - @set = Set["one", "two", "three"] - end - - it "yields every element of self" do - ret = [] - @set.delete_if { |x| ret << x } - ret.sort.should == ["one", "two", "three"].sort - end - - it "deletes every element from self for which the passed block returns true" do - @set.delete_if { |x| x.size == 3 } - @set.size.should eql(1) - - @set.should_not include("one") - @set.should_not include("two") - @set.should include("three") - end - - it "returns self" do - @set.delete_if { |x| x }.should equal(@set) - end - - it "returns an Enumerator when passed no block" do - enum = @set.delete_if - enum.should be_an_instance_of(Enumerator) - - enum.each { |x| x.size == 3 } - - @set.should_not include("one") - @set.should_not include("two") - @set.should include("three") - end -end diff --git a/spec/ruby/library/set/delete_spec.rb b/spec/ruby/library/set/delete_spec.rb deleted file mode 100644 index b12524384a..0000000000 --- a/spec/ruby/library/set/delete_spec.rb +++ /dev/null @@ -1,37 +0,0 @@ -require_relative '../../spec_helper' -require 'set' - -describe "Set#delete" do - before :each do - @set = Set["a", "b", "c"] - end - - it "deletes the passed Object from self" do - @set.delete("a") - @set.should_not include("a") - end - - it "returns self" do - @set.delete("a").should equal(@set) - @set.delete("x").should equal(@set) - end -end - -describe "Set#delete?" do - before :each do - @set = Set["a", "b", "c"] - end - - it "deletes the passed Object from self" do - @set.delete?("a") - @set.should_not include("a") - end - - it "returns self when the passed Object is in self" do - @set.delete?("a").should equal(@set) - end - - it "returns nil when the passed Object is not in self" do - @set.delete?("x").should be_nil - end -end diff --git a/spec/ruby/library/set/difference_spec.rb b/spec/ruby/library/set/difference_spec.rb deleted file mode 100644 index 422f2ed3c7..0000000000 --- a/spec/ruby/library/set/difference_spec.rb +++ /dev/null @@ -1,7 +0,0 @@ -require_relative '../../spec_helper' -require 'set' -require_relative 'shared/difference' - -describe "Set#difference" do - it_behaves_like :set_difference, :difference -end diff --git a/spec/ruby/library/set/disjoint_spec.rb b/spec/ruby/library/set/disjoint_spec.rb deleted file mode 100644 index ea3b141455..0000000000 --- a/spec/ruby/library/set/disjoint_spec.rb +++ /dev/null @@ -1,23 +0,0 @@ -require_relative '../../spec_helper' -require_relative 'fixtures/set_like' -require 'set' - -describe "Set#disjoint?" do - it "returns false when two Sets have at least one element in common" do - Set[1, 2].disjoint?(Set[2, 3]).should == false - end - - it "returns true when two Sets have no element in common" do - Set[1, 2].disjoint?(Set[3, 4]).should == true - end - - context "when comparing to a Set-like object" do - it "returns false when a Set has at least one element in common with a Set-like object" do - Set[1, 2].disjoint?(SetSpecs::SetLike.new([2, 3])).should be_false - end - - it "returns true when a Set has no element in common with a Set-like object" do - Set[1, 2].disjoint?(SetSpecs::SetLike.new([3, 4])).should be_true - end - end -end diff --git a/spec/ruby/library/set/divide_spec.rb b/spec/ruby/library/set/divide_spec.rb deleted file mode 100644 index fdd8cd9622..0000000000 --- a/spec/ruby/library/set/divide_spec.rb +++ /dev/null @@ -1,34 +0,0 @@ -require_relative '../../spec_helper' -require 'set' - -describe "Set#divide" do - it "divides self into a set of subsets based on the blocks return values" do - set = Set["one", "two", "three", "four", "five"].divide { |x| x.length } - set.map { |x| x.to_a.sort }.sort.should == [["five", "four"], ["one", "two"], ["three"]] - end - - it "yields each Object to the block" do - ret = [] - Set["one", "two", "three", "four", "five"].divide { |x| ret << x } - ret.sort.should == ["five", "four", "one", "three", "two"] - end - - # BUG: Does not raise a LocalJumpError, but a NoMethodError - # - # it "raises a LocalJumpError when not passed a block" do - # lambda { Set[1].divide }.should raise_error(LocalJumpError) - # end -end - -describe "Set#divide when passed a block with an arity of 2" do - it "divides self into a set of subsets based on the blocks return values" do - set = Set[1, 3, 4, 6, 9, 10, 11].divide { |x, y| (x - y).abs == 1 } - set.map{ |x| x.to_a.sort }.sort.should == [[1], [3, 4], [6], [9, 10, 11]] - end - - it "yields each two Object to the block" do - ret = [] - Set[1, 2].divide { |x, y| ret << [x, y] } - ret.sort.should == [[1, 1], [1, 2], [2, 1], [2, 2]] - end -end diff --git a/spec/ruby/library/set/each_spec.rb b/spec/ruby/library/set/each_spec.rb deleted file mode 100644 index 44e185a4da..0000000000 --- a/spec/ruby/library/set/each_spec.rb +++ /dev/null @@ -1,27 +0,0 @@ -require_relative '../../spec_helper' -require 'set' - -describe "Set#each" do - before :each do - @set = Set[1, 2, 3] - end - - it "yields each Object in self" do - ret = [] - @set.each { |x| ret << x } - ret.sort.should == [1, 2, 3] - end - - it "returns self" do - @set.each { |x| x }.should equal(@set) - end - - it "returns an Enumerator when not passed a block" do - enum = @set.each - enum.should be_an_instance_of(Enumerator) - - ret = [] - enum.each { |x| ret << x } - ret.sort.should == [1, 2, 3] - end -end diff --git a/spec/ruby/library/set/empty_spec.rb b/spec/ruby/library/set/empty_spec.rb deleted file mode 100644 index 1789a664c7..0000000000 --- a/spec/ruby/library/set/empty_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require_relative '../../spec_helper' -require 'set' - -describe "Set#empty?" do - it "returns true if self is empty" do - Set[].empty?.should be_true - Set[1].empty?.should be_false - Set[1,2,3].empty?.should be_false - end -end diff --git a/spec/ruby/library/set/enumerable/to_set_spec.rb b/spec/ruby/library/set/enumerable/to_set_spec.rb deleted file mode 100644 index 3790d8deee..0000000000 --- a/spec/ruby/library/set/enumerable/to_set_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -require_relative '../../../spec_helper' -require 'set' - -describe "Enumerable#to_set" do - it "returns a new Set created from self" do - [1, 2, 3].to_set.should == Set[1, 2, 3] - {a: 1, b: 2}.to_set.should == Set[[:b, 2], [:a, 1]] - end - - ruby_version_is ''...'3.0' do - it "allows passing an alternate class for Set" do - sorted_set = [1, 2, 3].to_set(SortedSet) - sorted_set.should == SortedSet[1, 2, 3] - sorted_set.instance_of?(SortedSet).should == true - end - end - - it "passes down passed blocks" do - [1, 2, 3].to_set { |x| x * x }.should == Set[1, 4, 9] - end -end diff --git a/spec/ruby/library/set/eql_spec.rb b/spec/ruby/library/set/eql_spec.rb deleted file mode 100644 index dd8e633775..0000000000 --- a/spec/ruby/library/set/eql_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require_relative '../../spec_helper' -require 'set' - -describe "Set#eql?" do - it "returns true when the passed argument is a Set and contains the same elements" do - Set[].should eql(Set[]) - Set[1, 2, 3].should eql(Set[1, 2, 3]) - Set[1, 2, 3].should eql(Set[3, 2, 1]) - Set["a", :b, ?c].should eql(Set[?c, :b, "a"]) - - Set[1, 2, 3].should_not eql(Set[1.0, 2, 3]) - Set[1, 2, 3].should_not eql(Set[2, 3]) - Set[1, 2, 3].should_not eql(Set[]) - end -end diff --git a/spec/ruby/library/set/equal_value_spec.rb b/spec/ruby/library/set/equal_value_spec.rb deleted file mode 100644 index f5b5f790c0..0000000000 --- a/spec/ruby/library/set/equal_value_spec.rb +++ /dev/null @@ -1,33 +0,0 @@ -require_relative '../../spec_helper' -require_relative 'fixtures/set_like' -require 'set' - -describe "Set#==" do - it "returns true when the passed Object is a Set and self and the Object contain the same elements" do - Set[].should == Set[] - Set[1, 2, 3].should == Set[1, 2, 3] - Set["1", "2", "3"].should == Set["1", "2", "3"] - - Set[1, 2, 3].should_not == Set[1.0, 2, 3] - Set[1, 2, 3].should_not == [1, 2, 3] - end - - it "does not depend on the order of the elements" do - Set[1, 2, 3].should == Set[3, 2, 1] - Set[:a, "b", ?c].should == Set[?c, "b", :a] - end - - it "does not depend on the order of nested Sets" do - Set[Set[1], Set[2], Set[3]].should == Set[Set[3], Set[2], Set[1]] - - set1 = Set[Set["a", "b"], Set["c", "d"], Set["e", "f"]] - set2 = Set[Set["c", "d"], Set["a", "b"], Set["e", "f"]] - set1.should == set2 - end - - context "when comparing to a Set-like object" do - it "returns true when a Set and a Set-like object contain the same elements" do - Set[1, 2, 3].should == SetSpecs::SetLike.new([1, 2, 3]) - end - end -end diff --git a/spec/ruby/library/set/exclusion_spec.rb b/spec/ruby/library/set/exclusion_spec.rb deleted file mode 100644 index 5bc4b5a2bf..0000000000 --- a/spec/ruby/library/set/exclusion_spec.rb +++ /dev/null @@ -1,18 +0,0 @@ -require_relative '../../spec_helper' -require 'set' - -describe "Set#^" do - before :each do - @set = Set[1, 2, 3, 4] - end - - it "returns a new Set containing elements that are not in both self and the passed Enumerable" do - (@set ^ Set[3, 4, 5]).should == Set[1, 2, 5] - (@set ^ [3, 4, 5]).should == Set[1, 2, 5] - end - - it "raises an ArgumentError when passed a non-Enumerable" do - -> { @set ^ 3 }.should raise_error(ArgumentError) - -> { @set ^ Object.new }.should raise_error(ArgumentError) - end -end diff --git a/spec/ruby/library/set/filter_spec.rb b/spec/ruby/library/set/filter_spec.rb deleted file mode 100644 index 779254ad68..0000000000 --- a/spec/ruby/library/set/filter_spec.rb +++ /dev/null @@ -1,6 +0,0 @@ -require_relative '../../spec_helper' -require_relative 'shared/select' - -describe "Set#filter!" do - it_behaves_like :set_select_bang, :filter! -end diff --git a/spec/ruby/library/set/fixtures/set_like.rb b/spec/ruby/library/set/fixtures/set_like.rb deleted file mode 100644 index 46f61a451e..0000000000 --- a/spec/ruby/library/set/fixtures/set_like.rb +++ /dev/null @@ -1,31 +0,0 @@ -require 'set' - -module SetSpecs - # This class is used to test the interaction of "Set-like" objects with real Sets - # - # These "Set-like" objects reply to is_a?(Set) with true and thus real Set objects are able to transparently - # interoperate with them in a duck-typing manner. - class SetLike - include Enumerable - - def is_a?(klass) - super || klass == ::Set - end - - def initialize(entries) - @entries = entries - end - - def each(&block) - @entries.each(&block) - end - - def inspect - "#<#{self.class}: {#{map(&:inspect).join(", ")}}>" - end - - def size - @entries.size - end - end -end diff --git a/spec/ruby/library/set/flatten_merge_spec.rb b/spec/ruby/library/set/flatten_merge_spec.rb deleted file mode 100644 index f2c99a9481..0000000000 --- a/spec/ruby/library/set/flatten_merge_spec.rb +++ /dev/null @@ -1,23 +0,0 @@ -require_relative '../../spec_helper' -require 'set' - -describe "Set#flatten_merge" do - it "is protected" do - Set.should have_protected_instance_method("flatten_merge") - end - - it "flattens the passed Set and merges it into self" do - set1 = Set[1, 2] - set2 = Set[3, 4, Set[5, 6]] - - set1.send(:flatten_merge, set2).should == Set[1, 2, 3, 4, 5, 6] - end - - it "raises an ArgumentError when trying to flatten a recursive Set" do - set1 = Set[1, 2, 3] - set2 = Set[5, 6, 7] - set2 << set2 - - -> { set1.send(:flatten_merge, set2) }.should raise_error(ArgumentError) - end -end diff --git a/spec/ruby/library/set/flatten_spec.rb b/spec/ruby/library/set/flatten_spec.rb deleted file mode 100644 index 4ac83ea825..0000000000 --- a/spec/ruby/library/set/flatten_spec.rb +++ /dev/null @@ -1,53 +0,0 @@ -require_relative '../../spec_helper' -require_relative 'fixtures/set_like' -require 'set' - -describe "Set#flatten" do - it "returns a copy of self with each included Set flattened" do - set = Set[1, 2, Set[3, 4, Set[5, 6, Set[7, 8]]], 9, 10] - flattened_set = set.flatten - - flattened_set.should_not equal(set) - flattened_set.should == Set[1, 2, 3, 4, 5, 6, 7, 8, 9, 10] - end - - it "raises an ArgumentError when self is recursive" do - (set = Set[]) << set - -> { set.flatten }.should raise_error(ArgumentError) - end - - context "when Set contains a Set-like object" do - it "returns a copy of self with each included Set-like object flattened" do - Set[SetSpecs::SetLike.new([1])].flatten.should == Set[1] - end - end -end - -describe "Set#flatten!" do - it "flattens self" do - set = Set[1, 2, Set[3, 4, Set[5, 6, Set[7, 8]]], 9, 10] - set.flatten! - set.should == Set[1, 2, 3, 4, 5, 6, 7, 8, 9, 10] - end - - it "returns self when self was modified" do - set = Set[1, 2, Set[3, 4]] - set.flatten!.should equal(set) - end - - it "returns nil when self was not modified" do - set = Set[1, 2, 3, 4] - set.flatten!.should be_nil - end - - it "raises an ArgumentError when self is recursive" do - (set = Set[]) << set - -> { set.flatten! }.should raise_error(ArgumentError) - end - - context "when Set contains a Set-like object" do - it "flattens self, including Set-like objects" do - Set[SetSpecs::SetLike.new([1])].flatten!.should == Set[1] - end - end -end diff --git a/spec/ruby/library/set/hash_spec.rb b/spec/ruby/library/set/hash_spec.rb deleted file mode 100644 index 47c43c05f1..0000000000 --- a/spec/ruby/library/set/hash_spec.rb +++ /dev/null @@ -1,13 +0,0 @@ -require_relative '../../spec_helper' -require 'set' - -describe "Set#hash" do - it "is static" do - Set[].hash.should == Set[].hash - Set[1, 2, 3].hash.should == Set[1, 2, 3].hash - Set[:a, "b", ?c].hash.should == Set[?c, "b", :a].hash - - Set[].hash.should_not == Set[1, 2, 3].hash - Set[1, 2, 3].hash.should_not == Set[:a, "b", ?c].hash - end -end diff --git a/spec/ruby/library/set/include_spec.rb b/spec/ruby/library/set/include_spec.rb deleted file mode 100644 index 68532d9a04..0000000000 --- a/spec/ruby/library/set/include_spec.rb +++ /dev/null @@ -1,7 +0,0 @@ -require_relative '../../spec_helper' -require_relative 'shared/include' -require 'set' - -describe "Set#include?" do - it_behaves_like :set_include, :include? -end diff --git a/spec/ruby/library/set/initialize_clone_spec.rb b/spec/ruby/library/set/initialize_clone_spec.rb deleted file mode 100644 index 62985987fa..0000000000 --- a/spec/ruby/library/set/initialize_clone_spec.rb +++ /dev/null @@ -1,18 +0,0 @@ -require_relative '../../spec_helper' -require 'set' - -describe "Set#initialize_clone" do - ruby_version_is "3.0" do - # See https://bugs.ruby-lang.org/issues/14266 - it "does not freeze the new Set when called from clone(freeze: false)" do - set1 = Set[1, 2] - set1.freeze - set2 = set1.clone(freeze: false) - set1.frozen?.should == true - set2.frozen?.should == false - set2.add 3 - set1.should == Set[1, 2] - set2.should == Set[1, 2, 3] - end - end -end diff --git a/spec/ruby/library/set/initialize_spec.rb b/spec/ruby/library/set/initialize_spec.rb deleted file mode 100644 index 76ebc0a20a..0000000000 --- a/spec/ruby/library/set/initialize_spec.rb +++ /dev/null @@ -1,73 +0,0 @@ -require_relative '../../spec_helper' -require 'set' - -describe "Set#initialize" do - it "is private" do - Set.should have_private_instance_method(:initialize) - end - - it "adds all elements of the passed Enumerable to self" do - s = Set.new([1, 2, 3]) - s.size.should eql(3) - s.should include(1) - s.should include(2) - s.should include(3) - end - - it "uses #each_entry on the provided Enumerable" do - enumerable = MockObject.new('mock-enumerable') - enumerable.should_receive(:each_entry).and_yield(1).and_yield(2).and_yield(3) - s = Set.new(enumerable) - s.size.should eql(3) - s.should include(1) - s.should include(2) - s.should include(3) - end - - it "uses #each on the provided Enumerable if it does not respond to #each_entry" do - enumerable = MockObject.new('mock-enumerable') - enumerable.should_receive(:each).and_yield(1).and_yield(2).and_yield(3) - s = Set.new(enumerable) - s.size.should eql(3) - s.should include(1) - s.should include(2) - s.should include(3) - end - - it "raises if the provided Enumerable does not respond to #each_entry or #each" do - enumerable = MockObject.new('mock-enumerable') - -> { Set.new(enumerable) }.should raise_error(ArgumentError, "value must be enumerable") - end - - it "should initialize with empty array and set" do - s = Set.new([]) - s.size.should eql(0) - - s = Set.new({}) - s.size.should eql(0) - end - - it "preprocesses all elements by a passed block before adding to self" do - s = Set.new([1, 2, 3]) { |x| x * x } - s.size.should eql(3) - s.should include(1) - s.should include(4) - s.should include(9) - end - - it "should initialize with empty array and block" do - s = Set.new([]) { |x| x * x } - s.size.should eql(0) - end - - it "should initialize with empty set and block" do - s = Set.new(Set.new) { |x| x * x } - s.size.should eql(0) - end - - it "should initialize with just block" do - s = Set.new { |x| x * x } - s.size.should eql(0) - s.should eql(Set.new) - end -end diff --git a/spec/ruby/library/set/inspect_spec.rb b/spec/ruby/library/set/inspect_spec.rb deleted file mode 100644 index 4060c63b95..0000000000 --- a/spec/ruby/library/set/inspect_spec.rb +++ /dev/null @@ -1,7 +0,0 @@ -require_relative '../../spec_helper' -require_relative 'shared/inspect' -require 'set' - -describe "Set#inspect" do - it_behaves_like :set_inspect, :inspect -end diff --git a/spec/ruby/library/set/intersect_spec.rb b/spec/ruby/library/set/intersect_spec.rb deleted file mode 100644 index e60f06db94..0000000000 --- a/spec/ruby/library/set/intersect_spec.rb +++ /dev/null @@ -1,23 +0,0 @@ -require_relative '../../spec_helper' -require_relative 'fixtures/set_like' -require 'set' - -describe "Set#intersect?" do - it "returns true when two Sets have at least one element in common" do - Set[1, 2].intersect?(Set[2, 3]).should == true - end - - it "returns false when two Sets have no element in common" do - Set[1, 2].intersect?(Set[3, 4]).should == false - end - - context "when comparing to a Set-like object" do - it "returns true when a Set has at least one element in common with a Set-like object" do - Set[1, 2].intersect?(SetSpecs::SetLike.new([2, 3])).should be_true - end - - it "returns false when a Set has no element in common with a Set-like object" do - Set[1, 2].intersect?(SetSpecs::SetLike.new([3, 4])).should be_false - end - end -end diff --git a/spec/ruby/library/set/intersection_spec.rb b/spec/ruby/library/set/intersection_spec.rb deleted file mode 100644 index 792c2d8f07..0000000000 --- a/spec/ruby/library/set/intersection_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require_relative '../../spec_helper' -require_relative 'shared/intersection' -require 'set' - -describe "Set#intersection" do - it_behaves_like :set_intersection, :intersection -end - -describe "Set#&" do - it_behaves_like :set_intersection, :& -end diff --git a/spec/ruby/library/set/join_spec.rb b/spec/ruby/library/set/join_spec.rb deleted file mode 100644 index 7498a91d98..0000000000 --- a/spec/ruby/library/set/join_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -require_relative '../../spec_helper' -require 'set' - -ruby_version_is "3.0" do - describe "Set#join" do - it "returns an empty string if the Set is empty" do - Set[].join.should == '' - end - - it "returns a new string formed by joining elements after conversion" do - set = Set[:a, :b, :c] - set.join.should == "abc" - end - - it "does not separate elements when the passed separator is nil" do - set = Set[:a, :b, :c] - set.join(nil).should == "abc" - end - - it "returns a string formed by concatenating each element separated by the separator" do - set = Set[:a, :b, :c] - set.join(' | ').should == "a | b | c" - end - - it "calls #to_a to convert the Set in to an Array" do - set = Set[:a, :b, :c] - set.should_receive(:to_a).and_return([:a, :b, :c]) - set.join.should == "abc" - end - end -end diff --git a/spec/ruby/library/set/keep_if_spec.rb b/spec/ruby/library/set/keep_if_spec.rb deleted file mode 100644 index 7edc80769f..0000000000 --- a/spec/ruby/library/set/keep_if_spec.rb +++ /dev/null @@ -1,38 +0,0 @@ -require_relative '../../spec_helper' -require 'set' - -describe "Set#keep_if" do - before :each do - @set = Set["one", "two", "three"] - end - - it "yields every element of self" do - ret = [] - @set.keep_if { |x| ret << x } - ret.sort.should == ["one", "two", "three"].sort - end - - it "keeps every element from self for which the passed block returns true" do - @set.keep_if { |x| x.size != 3 } - @set.size.should eql(1) - - @set.should_not include("one") - @set.should_not include("two") - @set.should include("three") - end - - it "returns self" do - @set.keep_if {}.should equal(@set) - end - - it "returns an Enumerator when passed no block" do - enum = @set.keep_if - enum.should be_an_instance_of(Enumerator) - - enum.each { |x| x.size != 3 } - - @set.should_not include("one") - @set.should_not include("two") - @set.should include("three") - end -end diff --git a/spec/ruby/library/set/length_spec.rb b/spec/ruby/library/set/length_spec.rb deleted file mode 100644 index fef63d25a7..0000000000 --- a/spec/ruby/library/set/length_spec.rb +++ /dev/null @@ -1,7 +0,0 @@ -require_relative '../../spec_helper' -require_relative 'shared/length' -require 'set' - -describe "Set#length" do - it_behaves_like :set_length, :length -end diff --git a/spec/ruby/library/set/map_spec.rb b/spec/ruby/library/set/map_spec.rb deleted file mode 100644 index e60e98b179..0000000000 --- a/spec/ruby/library/set/map_spec.rb +++ /dev/null @@ -1,7 +0,0 @@ -require_relative '../../spec_helper' -require 'set' -require_relative 'shared/collect' - -describe "Set#map!" do - it_behaves_like :set_collect_bang, :map! -end diff --git a/spec/ruby/library/set/member_spec.rb b/spec/ruby/library/set/member_spec.rb deleted file mode 100644 index 5b56a38ab9..0000000000 --- a/spec/ruby/library/set/member_spec.rb +++ /dev/null @@ -1,7 +0,0 @@ -require_relative '../../spec_helper' -require_relative 'shared/include' -require 'set' - -describe "Set#member?" do - it_behaves_like :set_include, :member? -end diff --git a/spec/ruby/library/set/merge_spec.rb b/spec/ruby/library/set/merge_spec.rb deleted file mode 100644 index a8e3ffc870..0000000000 --- a/spec/ruby/library/set/merge_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -require_relative '../../spec_helper' -require 'set' - -describe "Set#merge" do - it "adds the elements of the passed Enumerable to self" do - Set[:a, :b].merge(Set[:b, :c, :d]).should == Set[:a, :b, :c, :d] - Set[1, 2].merge([3, 4]).should == Set[1, 2, 3, 4] - end - - it "returns self" do - set = Set[1, 2] - set.merge([3, 4]).should equal(set) - end - - it "raises an ArgumentError when passed a non-Enumerable" do - -> { Set[1, 2].merge(1) }.should raise_error(ArgumentError) - -> { Set[1, 2].merge(Object.new) }.should raise_error(ArgumentError) - end -end diff --git a/spec/ruby/library/set/minus_spec.rb b/spec/ruby/library/set/minus_spec.rb deleted file mode 100644 index 3fe0b6a2cc..0000000000 --- a/spec/ruby/library/set/minus_spec.rb +++ /dev/null @@ -1,7 +0,0 @@ -require_relative '../../spec_helper' -require 'set' -require_relative 'shared/difference' - -describe "Set#-" do - it_behaves_like :set_difference, :- -end diff --git a/spec/ruby/library/set/plus_spec.rb b/spec/ruby/library/set/plus_spec.rb deleted file mode 100644 index 3e70d3269d..0000000000 --- a/spec/ruby/library/set/plus_spec.rb +++ /dev/null @@ -1,7 +0,0 @@ -require_relative '../../spec_helper' -require_relative 'shared/union' -require 'set' - -describe "Set#+" do - it_behaves_like :set_union, :+ -end diff --git a/spec/ruby/library/set/pretty_print_cycle_spec.rb b/spec/ruby/library/set/pretty_print_cycle_spec.rb deleted file mode 100644 index 4f440353e5..0000000000 --- a/spec/ruby/library/set/pretty_print_cycle_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require_relative '../../spec_helper' -require 'set' - -describe "Set#pretty_print_cycle" do - it "passes the 'pretty print' representation of a self-referencing Set to the pretty print writer" do - pp = mock("PrettyPrint") - pp.should_receive(:text).with("#<Set: {...}>") - Set[1, 2, 3].pretty_print_cycle(pp) - end -end diff --git a/spec/ruby/library/set/pretty_print_spec.rb b/spec/ruby/library/set/pretty_print_spec.rb deleted file mode 100644 index ea9ead0df8..0000000000 --- a/spec/ruby/library/set/pretty_print_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -require_relative '../../spec_helper' -require 'set' - -ruby_version_is ""..."3.1" do - describe "Set#pretty_print" do - it "passes the 'pretty print' representation of self to the pretty print writer" do - pp = mock("PrettyPrint") - set = Set[1, 2, 3] - - pp.should_receive(:text).with("#<Set: {") - pp.should_receive(:text).with("}>") - - pp.should_receive(:nest).with(1).and_yield - pp.should_receive(:seplist).with(set) - - set.pretty_print(pp) - end - end -end diff --git a/spec/ruby/library/set/proper_subset_spec.rb b/spec/ruby/library/set/proper_subset_spec.rb deleted file mode 100644 index 1f496a6199..0000000000 --- a/spec/ruby/library/set/proper_subset_spec.rb +++ /dev/null @@ -1,41 +0,0 @@ -require_relative '../../spec_helper' -require_relative 'fixtures/set_like' -require 'set' - -describe "Set#proper_subset?" do - before :each do - @set = Set[1, 2, 3, 4] - end - - it "returns true if passed a Set that self is a proper subset of" do - Set[].proper_subset?(@set).should be_true - Set[].proper_subset?(Set[1, 2, 3]).should be_true - Set[].proper_subset?(Set["a", :b, ?c]).should be_true - - Set[1, 2, 3].proper_subset?(@set).should be_true - Set[1, 3].proper_subset?(@set).should be_true - Set[1, 2].proper_subset?(@set).should be_true - Set[1].proper_subset?(@set).should be_true - - Set[5].proper_subset?(@set).should be_false - Set[1, 5].proper_subset?(@set).should be_false - Set[nil].proper_subset?(@set).should be_false - Set["test"].proper_subset?(@set).should be_false - - @set.proper_subset?(@set).should be_false - Set[].proper_subset?(Set[]).should be_false - end - - it "raises an ArgumentError when passed a non-Set" do - -> { Set[].proper_subset?([]) }.should raise_error(ArgumentError) - -> { Set[].proper_subset?(1) }.should raise_error(ArgumentError) - -> { Set[].proper_subset?("test") }.should raise_error(ArgumentError) - -> { Set[].proper_subset?(Object.new) }.should raise_error(ArgumentError) - end - - context "when comparing to a Set-like object" do - it "returns true if passed a Set-like object that self is a proper subset of" do - Set[1, 2, 3].proper_subset?(SetSpecs::SetLike.new([1, 2, 3, 4])).should be_true - end - end -end diff --git a/spec/ruby/library/set/proper_superset_spec.rb b/spec/ruby/library/set/proper_superset_spec.rb deleted file mode 100644 index a386c8c097..0000000000 --- a/spec/ruby/library/set/proper_superset_spec.rb +++ /dev/null @@ -1,41 +0,0 @@ -require_relative '../../spec_helper' -require_relative 'fixtures/set_like' -require 'set' - -describe "Set#proper_superset?" do - before :each do - @set = Set[1, 2, 3, 4] - end - - it "returns true if passed a Set that self is a proper superset of" do - @set.proper_superset?(Set[]).should be_true - Set[1, 2, 3].proper_superset?(Set[]).should be_true - Set["a", :b, ?c].proper_superset?(Set[]).should be_true - - @set.proper_superset?(Set[1, 2, 3]).should be_true - @set.proper_superset?(Set[1, 3]).should be_true - @set.proper_superset?(Set[1, 2]).should be_true - @set.proper_superset?(Set[1]).should be_true - - @set.proper_superset?(Set[5]).should be_false - @set.proper_superset?(Set[1, 5]).should be_false - @set.proper_superset?(Set[nil]).should be_false - @set.proper_superset?(Set["test"]).should be_false - - @set.proper_superset?(@set).should be_false - Set[].proper_superset?(Set[]).should be_false - end - - it "raises an ArgumentError when passed a non-Set" do - -> { Set[].proper_superset?([]) }.should raise_error(ArgumentError) - -> { Set[].proper_superset?(1) }.should raise_error(ArgumentError) - -> { Set[].proper_superset?("test") }.should raise_error(ArgumentError) - -> { Set[].proper_superset?(Object.new) }.should raise_error(ArgumentError) - end - - context "when comparing to a Set-like object" do - it "returns true if passed a Set-like object that self is a proper superset of" do - Set[1, 2, 3, 4].proper_superset?(SetSpecs::SetLike.new([1, 2, 3])).should be_true - end - end -end diff --git a/spec/ruby/library/set/reject_spec.rb b/spec/ruby/library/set/reject_spec.rb deleted file mode 100644 index 9131f960ad..0000000000 --- a/spec/ruby/library/set/reject_spec.rb +++ /dev/null @@ -1,42 +0,0 @@ -require_relative '../../spec_helper' -require 'set' - -describe "Set#reject!" do - before :each do - @set = Set["one", "two", "three"] - end - - it "yields every element of self" do - ret = [] - @set.reject! { |x| ret << x } - ret.sort.should == ["one", "two", "three"].sort - end - - it "deletes every element from self for which the passed block returns true" do - @set.reject! { |x| x.size == 3 } - @set.size.should eql(1) - - @set.should_not include("one") - @set.should_not include("two") - @set.should include("three") - end - - it "returns self when self was modified" do - @set.reject! { |x| true }.should equal(@set) - end - - it "returns nil when self was not modified" do - @set.reject! { |x| false }.should be_nil - end - - it "returns an Enumerator when passed no block" do - enum = @set.reject! - enum.should be_an_instance_of(Enumerator) - - enum.each { |x| x.size == 3 } - - @set.should_not include("one") - @set.should_not include("two") - @set.should include("three") - end -end diff --git a/spec/ruby/library/set/replace_spec.rb b/spec/ruby/library/set/replace_spec.rb deleted file mode 100644 index 7511066c9c..0000000000 --- a/spec/ruby/library/set/replace_spec.rb +++ /dev/null @@ -1,17 +0,0 @@ -require_relative '../../spec_helper' -require 'set' - -describe "Set#replace" do - before :each do - @set = Set[:a, :b, :c] - end - - it "replaces the contents with other and returns self" do - @set.replace(Set[1, 2, 3]).should == @set - @set.should == Set[1, 2, 3] - end - - it "accepts any enumerable as other" do - @set.replace([1, 2, 3]).should == Set[1, 2, 3] - end -end diff --git a/spec/ruby/library/set/select_spec.rb b/spec/ruby/library/set/select_spec.rb deleted file mode 100644 index b458ffacaa..0000000000 --- a/spec/ruby/library/set/select_spec.rb +++ /dev/null @@ -1,6 +0,0 @@ -require_relative '../../spec_helper' -require_relative 'shared/select' - -describe "Set#select!" do - it_behaves_like :set_select_bang, :select! -end diff --git a/spec/ruby/library/set/shared/add.rb b/spec/ruby/library/set/shared/add.rb deleted file mode 100644 index 9e797f5df9..0000000000 --- a/spec/ruby/library/set/shared/add.rb +++ /dev/null @@ -1,14 +0,0 @@ -describe :set_add, shared: true do - before :each do - @set = Set.new - end - - it "adds the passed Object to self" do - @set.send(@method, "dog") - @set.should include("dog") - end - - it "returns self" do - @set.send(@method, "dog").should equal(@set) - end -end diff --git a/spec/ruby/library/set/shared/collect.rb b/spec/ruby/library/set/shared/collect.rb deleted file mode 100644 index bc58c231be..0000000000 --- a/spec/ruby/library/set/shared/collect.rb +++ /dev/null @@ -1,20 +0,0 @@ -describe :set_collect_bang, shared: true do - before :each do - @set = Set[1, 2, 3, 4, 5] - end - - it "yields each Object in self" do - res = [] - @set.send(@method) { |x| res << x } - res.sort.should == [1, 2, 3, 4, 5].sort - end - - it "returns self" do - @set.send(@method) { |x| x }.should equal(@set) - end - - it "replaces self with the return values of the block" do - @set.send(@method) { |x| x * 2 } - @set.should == Set[2, 4, 6, 8, 10] - end -end diff --git a/spec/ruby/library/set/shared/difference.rb b/spec/ruby/library/set/shared/difference.rb deleted file mode 100644 index f88987ed2a..0000000000 --- a/spec/ruby/library/set/shared/difference.rb +++ /dev/null @@ -1,15 +0,0 @@ -describe :set_difference, shared: true do - before :each do - @set = Set[:a, :b, :c] - end - - it "returns a new Set containing self's elements excluding the elements in the passed Enumerable" do - @set.send(@method, Set[:a, :b]).should == Set[:c] - @set.send(@method, [:b, :c]).should == Set[:a] - end - - it "raises an ArgumentError when passed a non-Enumerable" do - -> { @set.send(@method, 1) }.should raise_error(ArgumentError) - -> { @set.send(@method, Object.new) }.should raise_error(ArgumentError) - end -end diff --git a/spec/ruby/library/set/shared/include.rb b/spec/ruby/library/set/shared/include.rb deleted file mode 100644 index b4d95cde24..0000000000 --- a/spec/ruby/library/set/shared/include.rb +++ /dev/null @@ -1,29 +0,0 @@ -describe :set_include, shared: true do - it "returns true when self contains the passed Object" do - set = Set[:a, :b, :c] - set.send(@method, :a).should be_true - set.send(@method, :e).should be_false - end - - describe "member equality" do - it "is checked using both #hash and #eql?" do - obj = Object.new - obj_another = Object.new - - def obj.hash; 42 end - def obj_another.hash; 42 end - def obj_another.eql?(o) hash == o.hash end - - set = Set["a", "b", "c", obj] - set.send(@method, obj_another).should == true - end - - it "is not checked using #==" do - obj = Object.new - set = Set["a", "b", "c"] - - obj.should_not_receive(:==) - set.send(@method, obj) - end - end -end diff --git a/spec/ruby/library/set/shared/inspect.rb b/spec/ruby/library/set/shared/inspect.rb deleted file mode 100644 index 69fbdd12f6..0000000000 --- a/spec/ruby/library/set/shared/inspect.rb +++ /dev/null @@ -1,15 +0,0 @@ -describe "set_inspect", shared: true do - it "returns a String representation of self" do - Set[].send(@method).should be_kind_of(String) - Set[nil, false, true].send(@method).should be_kind_of(String) - Set[1, 2, 3].send(@method).should be_kind_of(String) - Set["1", "2", "3"].send(@method).should be_kind_of(String) - Set[:a, "b", Set[?c]].send(@method).should be_kind_of(String) - end - - it "correctly handles self-references" do - (set = Set[]) << set - set.send(@method).should be_kind_of(String) - set.send(@method).should include("#<Set: {...}>") - end -end diff --git a/spec/ruby/library/set/shared/intersection.rb b/spec/ruby/library/set/shared/intersection.rb deleted file mode 100644 index 5ae4199c94..0000000000 --- a/spec/ruby/library/set/shared/intersection.rb +++ /dev/null @@ -1,15 +0,0 @@ -describe :set_intersection, shared: true do - before :each do - @set = Set[:a, :b, :c] - end - - it "returns a new Set containing only elements shared by self and the passed Enumerable" do - @set.send(@method, Set[:b, :c, :d, :e]).should == Set[:b, :c] - @set.send(@method, [:b, :c, :d]).should == Set[:b, :c] - end - - it "raises an ArgumentError when passed a non-Enumerable" do - -> { @set.send(@method, 1) }.should raise_error(ArgumentError) - -> { @set.send(@method, Object.new) }.should raise_error(ArgumentError) - end -end diff --git a/spec/ruby/library/set/shared/length.rb b/spec/ruby/library/set/shared/length.rb deleted file mode 100644 index a8fcee9f39..0000000000 --- a/spec/ruby/library/set/shared/length.rb +++ /dev/null @@ -1,6 +0,0 @@ -describe :set_length, shared: true do - it "returns the number of elements in the set" do - set = Set[:a, :b, :c] - set.send(@method).should == 3 - end -end diff --git a/spec/ruby/library/set/shared/select.rb b/spec/ruby/library/set/shared/select.rb deleted file mode 100644 index 2108d398b4..0000000000 --- a/spec/ruby/library/set/shared/select.rb +++ /dev/null @@ -1,42 +0,0 @@ -require_relative '../../../spec_helper' -require 'set' - -describe :set_select_bang, shared: true do - before :each do - @set = Set["one", "two", "three"] - end - - it "yields every element of self" do - ret = [] - @set.send(@method) { |x| ret << x } - ret.sort.should == ["one", "two", "three"].sort - end - - it "keeps every element from self for which the passed block returns true" do - @set.send(@method) { |x| x.size != 3 } - @set.size.should eql(1) - - @set.should_not include("one") - @set.should_not include("two") - @set.should include("three") - end - - it "returns self when self was modified" do - @set.send(@method) { false }.should equal(@set) - end - - it "returns nil when self was not modified" do - @set.send(@method) { true }.should be_nil - end - - it "returns an Enumerator when passed no block" do - enum = @set.send(@method) - enum.should be_an_instance_of(Enumerator) - - enum.each { |x| x.size != 3 } - - @set.should_not include("one") - @set.should_not include("two") - @set.should include("three") - end -end diff --git a/spec/ruby/library/set/shared/union.rb b/spec/ruby/library/set/shared/union.rb deleted file mode 100644 index 314f0e852d..0000000000 --- a/spec/ruby/library/set/shared/union.rb +++ /dev/null @@ -1,15 +0,0 @@ -describe :set_union, shared: true do - before :each do - @set = Set[:a, :b, :c] - end - - it "returns a new Set containing all elements of self and the passed Enumerable" do - @set.send(@method, Set[:b, :d, :e]).should == Set[:a, :b, :c, :d, :e] - @set.send(@method, [:b, :e]).should == Set[:a, :b, :c, :e] - end - - it "raises an ArgumentError when passed a non-Enumerable" do - -> { @set.send(@method, 1) }.should raise_error(ArgumentError) - -> { @set.send(@method, Object.new) }.should raise_error(ArgumentError) - end -end diff --git a/spec/ruby/library/set/size_spec.rb b/spec/ruby/library/set/size_spec.rb deleted file mode 100644 index 3c8cb38517..0000000000 --- a/spec/ruby/library/set/size_spec.rb +++ /dev/null @@ -1,7 +0,0 @@ -require_relative '../../spec_helper' -require_relative 'shared/length' -require 'set' - -describe "Set#size" do - it_behaves_like :set_length, :size -end diff --git a/spec/ruby/library/set/sortedset/add_spec.rb b/spec/ruby/library/set/sortedset/add_spec.rb deleted file mode 100644 index 4f3bb252e1..0000000000 --- a/spec/ruby/library/set/sortedset/add_spec.rb +++ /dev/null @@ -1,42 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - require_relative 'shared/add' - - describe "SortedSet#add" do - it_behaves_like :sorted_set_add, :add - - it "takes only values which responds <=>" do - obj = mock('no_comparison_operator') - obj.stub!(:respond_to?).with(:<=>).and_return(false) - -> { SortedSet["hello"].add(obj) }.should raise_error(ArgumentError) - end - - it "raises on incompatible <=> comparison" do - # Use #to_a here as elements are sorted only when needed. - # Therefore the <=> incompatibility is only noticed on sorting. - -> { SortedSet['1', '2'].add(3).to_a }.should raise_error(ArgumentError) - end - end - - describe "SortedSet#add?" do - before :each do - @set = SortedSet.new - end - - it "adds the passed Object to self" do - @set.add?("cat") - @set.should include("cat") - end - - it "returns self when the Object has not yet been added to self" do - @set.add?("cat").should equal(@set) - end - - it "returns nil when the Object has already been added to self" do - @set.add?("cat") - @set.add?("cat").should be_nil - end - end -end diff --git a/spec/ruby/library/set/sortedset/append_spec.rb b/spec/ruby/library/set/sortedset/append_spec.rb deleted file mode 100644 index d72d70b21f..0000000000 --- a/spec/ruby/library/set/sortedset/append_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - require_relative 'shared/add' - - describe "SortedSet#<<" do - it_behaves_like :sorted_set_add, :<< - end -end diff --git a/spec/ruby/library/set/sortedset/case_equality_spec.rb b/spec/ruby/library/set/sortedset/case_equality_spec.rb deleted file mode 100644 index d7c296b626..0000000000 --- a/spec/ruby/library/set/sortedset/case_equality_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require_relative 'shared/include' - require 'set' - - describe "SortedSet#===" do - it_behaves_like :sorted_set_include, :=== - end -end diff --git a/spec/ruby/library/set/sortedset/classify_spec.rb b/spec/ruby/library/set/sortedset/classify_spec.rb deleted file mode 100644 index 4011e58b82..0000000000 --- a/spec/ruby/library/set/sortedset/classify_spec.rb +++ /dev/null @@ -1,30 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#classify" do - before :each do - @set = SortedSet["one", "two", "three", "four"] - end - - it "yields each Object in self in sorted order" do - res = [] - @set.classify { |x| res << x } - res.should == ["one", "two", "three", "four"].sort - end - - it "returns an Enumerator when passed no block" do - enum = @set.classify - enum.should be_an_instance_of(Enumerator) - - classified = enum.each { |x| x.length } - classified.should == { 3 => SortedSet["one", "two"], 4 => SortedSet["four"], 5 => SortedSet["three"] } - end - - it "classifies the Objects in self based on the block's return value" do - classified = @set.classify { |x| x.length } - classified.should == { 3 => SortedSet["one", "two"], 4 => SortedSet["four"], 5 => SortedSet["three"] } - end - end -end diff --git a/spec/ruby/library/set/sortedset/clear_spec.rb b/spec/ruby/library/set/sortedset/clear_spec.rb deleted file mode 100644 index 879aa824d8..0000000000 --- a/spec/ruby/library/set/sortedset/clear_spec.rb +++ /dev/null @@ -1,20 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#clear" do - before :each do - @set = SortedSet["one", "two", "three", "four"] - end - - it "removes all elements from self" do - @set.clear - @set.should be_empty - end - - it "returns self" do - @set.clear.should equal(@set) - end - end -end diff --git a/spec/ruby/library/set/sortedset/collect_spec.rb b/spec/ruby/library/set/sortedset/collect_spec.rb deleted file mode 100644 index 0674f0d130..0000000000 --- a/spec/ruby/library/set/sortedset/collect_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - require_relative 'shared/collect' - - describe "SortedSet#collect!" do - it_behaves_like :sorted_set_collect_bang, :collect! - end -end diff --git a/spec/ruby/library/set/sortedset/constructor_spec.rb b/spec/ruby/library/set/sortedset/constructor_spec.rb deleted file mode 100644 index 31f30fd892..0000000000 --- a/spec/ruby/library/set/sortedset/constructor_spec.rb +++ /dev/null @@ -1,18 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet[]" do - it "returns a new SortedSet populated with the passed Objects" do - set = SortedSet[1, 2, 3] - - set.instance_of?(SortedSet).should be_true - set.size.should eql(3) - - set.should include(1) - set.should include(2) - set.should include(3) - end - end -end diff --git a/spec/ruby/library/set/sortedset/delete_if_spec.rb b/spec/ruby/library/set/sortedset/delete_if_spec.rb deleted file mode 100644 index 787639ae12..0000000000 --- a/spec/ruby/library/set/sortedset/delete_if_spec.rb +++ /dev/null @@ -1,41 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#delete_if" do - before :each do - @set = SortedSet["one", "two", "three"] - end - - it "yields each Object in self in sorted order" do - ret = [] - @set.delete_if { |x| ret << x } - ret.should == ["one", "two", "three"].sort - end - - it "deletes every element from self for which the passed block returns true" do - @set.delete_if { |x| x.size == 3 } - @set.size.should eql(1) - - @set.should_not include("one") - @set.should_not include("two") - @set.should include("three") - end - - it "returns self" do - @set.delete_if { |x| x }.should equal(@set) - end - - it "returns an Enumerator when passed no block" do - enum = @set.delete_if - enum.should be_an_instance_of(Enumerator) - - enum.each { |x| x.size == 3 } - - @set.should_not include("one") - @set.should_not include("two") - @set.should include("three") - end - end -end diff --git a/spec/ruby/library/set/sortedset/delete_spec.rb b/spec/ruby/library/set/sortedset/delete_spec.rb deleted file mode 100644 index 0e2a6accf3..0000000000 --- a/spec/ruby/library/set/sortedset/delete_spec.rb +++ /dev/null @@ -1,40 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#delete" do - before :each do - @set = SortedSet["a", "b", "c"] - end - - it "deletes the passed Object from self" do - @set.delete("a") - @set.should_not include("a") - end - - it "returns self" do - @set.delete("a").should equal(@set) - @set.delete("x").should equal(@set) - end - end - - describe "SortedSet#delete?" do - before :each do - @set = SortedSet["a", "b", "c"] - end - - it "deletes the passed Object from self" do - @set.delete?("a") - @set.should_not include("a") - end - - it "returns self when the passed Object is in self" do - @set.delete?("a").should equal(@set) - end - - it "returns nil when the passed Object is not in self" do - @set.delete?("x").should be_nil - end - end -end diff --git a/spec/ruby/library/set/sortedset/difference_spec.rb b/spec/ruby/library/set/sortedset/difference_spec.rb deleted file mode 100644 index fb064bdff9..0000000000 --- a/spec/ruby/library/set/sortedset/difference_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - require_relative 'shared/difference' - - describe "SortedSet#difference" do - it_behaves_like :sorted_set_difference, :difference - end -end diff --git a/spec/ruby/library/set/sortedset/divide_spec.rb b/spec/ruby/library/set/sortedset/divide_spec.rb deleted file mode 100644 index 31ab6037e4..0000000000 --- a/spec/ruby/library/set/sortedset/divide_spec.rb +++ /dev/null @@ -1,37 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#divide" do - it "divides self into a set of subsets based on the blocks return values" do - set = SortedSet["one", "two", "three", "four", "five"].divide { |x| x.length } - set.map { |x| x.to_a }.to_a.sort.should == [["five", "four"], ["one", "two"], ["three"]] - end - - it "yields each Object in self in sorted order" do - ret = [] - SortedSet["one", "two", "three", "four", "five"].divide { |x| ret << x } - ret.should == ["one", "two", "three", "four", "five"].sort - end - - # BUG: Does not raise a LocalJumpError, but a NoMethodError - # - # it "raises a LocalJumpError when not passed a block" do - # lambda { SortedSet[1].divide }.should raise_error(LocalJumpError) - # end - end - - describe "SortedSet#divide when passed a block with an arity of 2" do - it "divides self into a set of subsets based on the blocks return values" do - set = SortedSet[1, 3, 4, 6, 9, 10, 11].divide { |x, y| (x - y).abs == 1 } - set.map { |x| x.to_a }.to_a.sort.should == [[1], [3, 4], [6], [9, 10, 11]] - end - - it "yields each two Objects to the block" do - ret = [] - SortedSet[1, 2].divide { |x, y| ret << [x, y] } - ret.should == [[1, 1], [1, 2], [2, 1], [2, 2]] - end - end -end diff --git a/spec/ruby/library/set/sortedset/each_spec.rb b/spec/ruby/library/set/sortedset/each_spec.rb deleted file mode 100644 index 79d8aee223..0000000000 --- a/spec/ruby/library/set/sortedset/each_spec.rb +++ /dev/null @@ -1,29 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#each" do - before :each do - @set = SortedSet[1, 2, 3] - end - - it "yields each Object in self in sorted order" do - ret = [] - SortedSet["one", "two", "three"].each { |x| ret << x } - ret.should == ["one", "two", "three"].sort - end - - it "returns self" do - @set.each { |x| x }.should equal(@set) - end - - it "returns an Enumerator when not passed a block" do - enum = @set.each - - ret = [] - enum.each { |x| ret << x } - ret.sort.should == [1, 2, 3] - end - end -end diff --git a/spec/ruby/library/set/sortedset/empty_spec.rb b/spec/ruby/library/set/sortedset/empty_spec.rb deleted file mode 100644 index 2e52c3e81a..0000000000 --- a/spec/ruby/library/set/sortedset/empty_spec.rb +++ /dev/null @@ -1,13 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#empty?" do - it "returns true if self is empty" do - SortedSet[].empty?.should be_true - SortedSet[1].empty?.should be_false - SortedSet[1,2,3].empty?.should be_false - end - end -end diff --git a/spec/ruby/library/set/sortedset/eql_spec.rb b/spec/ruby/library/set/sortedset/eql_spec.rb deleted file mode 100644 index 050464994b..0000000000 --- a/spec/ruby/library/set/sortedset/eql_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#eql?" do - it "returns true when the passed argument is a SortedSet and contains the same elements" do - SortedSet[].should eql(SortedSet[]) - SortedSet[1, 2, 3].should eql(SortedSet[1, 2, 3]) - SortedSet[1, 2, 3].should eql(SortedSet[3, 2, 1]) - - # SortedSet["a", :b, ?c].should eql(SortedSet[?c, :b, "a"]) - - SortedSet[1, 2, 3].should_not eql(SortedSet[1.0, 2, 3]) - SortedSet[1, 2, 3].should_not eql(SortedSet[2, 3]) - SortedSet[1, 2, 3].should_not eql(SortedSet[]) - end - end -end diff --git a/spec/ruby/library/set/sortedset/equal_value_spec.rb b/spec/ruby/library/set/sortedset/equal_value_spec.rb deleted file mode 100644 index 30422f5b95..0000000000 --- a/spec/ruby/library/set/sortedset/equal_value_spec.rb +++ /dev/null @@ -1,16 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#==" do - it "returns true when the passed Object is a SortedSet and self and the Object contain the same elements" do - SortedSet[].should == SortedSet[] - SortedSet[1, 2, 3].should == SortedSet[1, 2, 3] - SortedSet["1", "2", "3"].should == SortedSet["1", "2", "3"] - - SortedSet[1, 2, 3].should_not == SortedSet[1.0, 2, 3] - SortedSet[1, 2, 3].should_not == [1, 2, 3] - end - end -end diff --git a/spec/ruby/library/set/sortedset/exclusion_spec.rb b/spec/ruby/library/set/sortedset/exclusion_spec.rb deleted file mode 100644 index 1967dfbfa6..0000000000 --- a/spec/ruby/library/set/sortedset/exclusion_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#^" do - before :each do - @set = SortedSet[1, 2, 3, 4] - end - - it "returns a new SortedSet containing elements that are not in both self and the passed Enumerable" do - (@set ^ SortedSet[3, 4, 5]).should == SortedSet[1, 2, 5] - (@set ^ [3, 4, 5]).should == SortedSet[1, 2, 5] - end - - it "raises an ArgumentError when passed a non-Enumerable" do - -> { @set ^ 3 }.should raise_error(ArgumentError) - -> { @set ^ Object.new }.should raise_error(ArgumentError) - end - end -end diff --git a/spec/ruby/library/set/sortedset/filter_spec.rb b/spec/ruby/library/set/sortedset/filter_spec.rb deleted file mode 100644 index 3b9dcb63c9..0000000000 --- a/spec/ruby/library/set/sortedset/filter_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require_relative 'shared/select' - require 'set' - - describe "SortedSet#filter!" do - it_behaves_like :sorted_set_select_bang, :filter! - end -end diff --git a/spec/ruby/library/set/sortedset/flatten_merge_spec.rb b/spec/ruby/library/set/sortedset/flatten_merge_spec.rb deleted file mode 100644 index 0d67cb331e..0000000000 --- a/spec/ruby/library/set/sortedset/flatten_merge_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#flatten_merge" do - it "is protected" do - SortedSet.should have_protected_instance_method("flatten_merge") - end - end -end diff --git a/spec/ruby/library/set/sortedset/flatten_spec.rb b/spec/ruby/library/set/sortedset/flatten_spec.rb deleted file mode 100644 index e83ad1044a..0000000000 --- a/spec/ruby/library/set/sortedset/flatten_spec.rb +++ /dev/null @@ -1,47 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - # Note: Flatten make little sens on sorted sets, because SortedSets are not (by default) - # comparable. For a SortedSet to be both valid and nested, we need to define a comparison operator: - module SortedSet_FlattenSpecs - class ComparableSortedSet < SortedSet - def <=>(other) - return puts "#{other} vs #{self}" unless other.is_a?(ComparableSortedSet) - to_a <=> other.to_a - end - end - end - - describe "SortedSet#flatten" do - it "returns a copy of self with each included SortedSet flattened" do - klass = SortedSet_FlattenSpecs::ComparableSortedSet - set = klass[klass[1,2], klass[3,4], klass[5,6,7], klass[8]] - flattened_set = set.flatten - - flattened_set.should_not equal(set) - flattened_set.should == klass[1, 2, 3, 4, 5, 6, 7, 8] - end - end - - describe "SortedSet#flatten!" do - it "flattens self" do - klass = SortedSet_FlattenSpecs::ComparableSortedSet - set = klass[klass[1,2], klass[3,4], klass[5,6,7], klass[8]] - set.flatten! - set.should == klass[1, 2, 3, 4, 5, 6, 7, 8] - end - - it "returns self when self was modified" do - klass = SortedSet_FlattenSpecs::ComparableSortedSet - set = klass[klass[1,2], klass[3,4]] - set.flatten!.should equal(set) - end - - it "returns nil when self was not modified" do - set = SortedSet[1, 2, 3, 4] - set.flatten!.should be_nil - end - end -end diff --git a/spec/ruby/library/set/sortedset/hash_spec.rb b/spec/ruby/library/set/sortedset/hash_spec.rb deleted file mode 100644 index 40676de7fc..0000000000 --- a/spec/ruby/library/set/sortedset/hash_spec.rb +++ /dev/null @@ -1,16 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#hash" do - it "is static" do - SortedSet[].hash.should == SortedSet[].hash - SortedSet[1, 2, 3].hash.should == SortedSet[1, 2, 3].hash - SortedSet["a", "b", "c"].hash.should == SortedSet["c", "b", "a"].hash - - SortedSet[].hash.should_not == SortedSet[1, 2, 3].hash - SortedSet[1, 2, 3].hash.should_not == SortedSet["a", "b", "c"].hash - end - end -end diff --git a/spec/ruby/library/set/sortedset/include_spec.rb b/spec/ruby/library/set/sortedset/include_spec.rb deleted file mode 100644 index ec2ad987d5..0000000000 --- a/spec/ruby/library/set/sortedset/include_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require_relative 'shared/include' - require 'set' - - describe "SortedSet#include?" do - it_behaves_like :sorted_set_include, :include? - end -end diff --git a/spec/ruby/library/set/sortedset/initialize_spec.rb b/spec/ruby/library/set/sortedset/initialize_spec.rb deleted file mode 100644 index 4d1707b72a..0000000000 --- a/spec/ruby/library/set/sortedset/initialize_spec.rb +++ /dev/null @@ -1,33 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#initialize" do - it "is private" do - SortedSet.should have_private_instance_method("initialize") - end - - it "adds all elements of the passed Enumerable to self" do - s = SortedSet.new([1, 2, 3]) - s.size.should eql(3) - s.should include(1) - s.should include(2) - s.should include(3) - end - - it "preprocesses all elements by a passed block before adding to self" do - s = SortedSet.new([1, 2, 3]) { |x| x * x } - s.size.should eql(3) - s.should include(1) - s.should include(4) - s.should include(9) - end - - it "raises on incompatible <=> comparison" do - # Use #to_a here as elements are sorted only when needed. - # Therefore the <=> incompatibility is only noticed on sorting. - -> { SortedSet.new(['00', nil]).to_a }.should raise_error(ArgumentError) - end - end -end diff --git a/spec/ruby/library/set/sortedset/inspect_spec.rb b/spec/ruby/library/set/sortedset/inspect_spec.rb deleted file mode 100644 index 1c4dd9e6e2..0000000000 --- a/spec/ruby/library/set/sortedset/inspect_spec.rb +++ /dev/null @@ -1,13 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#inspect" do - it "returns a String representation of self" do - SortedSet[].inspect.should be_kind_of(String) - SortedSet[1, 2, 3].inspect.should be_kind_of(String) - SortedSet["1", "2", "3"].inspect.should be_kind_of(String) - end - end -end diff --git a/spec/ruby/library/set/sortedset/intersection_spec.rb b/spec/ruby/library/set/sortedset/intersection_spec.rb deleted file mode 100644 index 6daa271b73..0000000000 --- a/spec/ruby/library/set/sortedset/intersection_spec.rb +++ /dev/null @@ -1,14 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require_relative 'shared/intersection' - require 'set' - - describe "SortedSet#intersection" do - it_behaves_like :sorted_set_intersection, :intersection - end - - describe "SortedSet#&" do - it_behaves_like :sorted_set_intersection, :& - end -end diff --git a/spec/ruby/library/set/sortedset/keep_if_spec.rb b/spec/ruby/library/set/sortedset/keep_if_spec.rb deleted file mode 100644 index 3e5f3bbc47..0000000000 --- a/spec/ruby/library/set/sortedset/keep_if_spec.rb +++ /dev/null @@ -1,34 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#keep_if" do - before :each do - @set = SortedSet["one", "two", "three"] - end - - it "yields each Object in self in sorted order" do - ret = [] - @set.keep_if { |x| ret << x } - ret.should == ["one", "two", "three"].sort - end - - it "keeps every element from self for which the passed block returns true" do - @set.keep_if { |x| x.size != 3 } - @set.to_a.should == ["three"] - end - - it "returns self" do - @set.keep_if {}.should equal(@set) - end - - it "returns an Enumerator when passed no block" do - enum = @set.keep_if - enum.should be_an_instance_of(Enumerator) - - enum.each { |x| x.size != 3 } - @set.to_a.should == ["three"] - end - end -end diff --git a/spec/ruby/library/set/sortedset/length_spec.rb b/spec/ruby/library/set/sortedset/length_spec.rb deleted file mode 100644 index de6791f6bb..0000000000 --- a/spec/ruby/library/set/sortedset/length_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require_relative 'shared/length' - require 'set' - - describe "SortedSet#length" do - it_behaves_like :sorted_set_length, :length - end -end diff --git a/spec/ruby/library/set/sortedset/map_spec.rb b/spec/ruby/library/set/sortedset/map_spec.rb deleted file mode 100644 index 4971b9529b..0000000000 --- a/spec/ruby/library/set/sortedset/map_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - require_relative 'shared/collect' - - describe "SortedSet#map!" do - it_behaves_like :sorted_set_collect_bang, :map! - end -end diff --git a/spec/ruby/library/set/sortedset/member_spec.rb b/spec/ruby/library/set/sortedset/member_spec.rb deleted file mode 100644 index 142b09b651..0000000000 --- a/spec/ruby/library/set/sortedset/member_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require_relative 'shared/include' - require 'set' - - describe "SortedSet#member?" do - it_behaves_like :sorted_set_include, :member? - end -end diff --git a/spec/ruby/library/set/sortedset/merge_spec.rb b/spec/ruby/library/set/sortedset/merge_spec.rb deleted file mode 100644 index c4cbc6d2b4..0000000000 --- a/spec/ruby/library/set/sortedset/merge_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#merge" do - it "adds the elements of the passed Enumerable to self" do - SortedSet["a", "b"].merge(SortedSet["b", "c", "d"]).should == SortedSet["a", "b", "c", "d"] - SortedSet[1, 2].merge([3, 4]).should == SortedSet[1, 2, 3, 4] - end - - it "returns self" do - set = SortedSet[1, 2] - set.merge([3, 4]).should equal(set) - end - - it "raises an ArgumentError when passed a non-Enumerable" do - -> { SortedSet[1, 2].merge(1) }.should raise_error(ArgumentError) - -> { SortedSet[1, 2].merge(Object.new) }.should raise_error(ArgumentError) - end - end -end diff --git a/spec/ruby/library/set/sortedset/minus_spec.rb b/spec/ruby/library/set/sortedset/minus_spec.rb deleted file mode 100644 index d6abc5e204..0000000000 --- a/spec/ruby/library/set/sortedset/minus_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - require_relative 'shared/difference' - - describe "SortedSet#-" do - it_behaves_like :sorted_set_difference, :- - end -end diff --git a/spec/ruby/library/set/sortedset/plus_spec.rb b/spec/ruby/library/set/sortedset/plus_spec.rb deleted file mode 100644 index 13fc873ad1..0000000000 --- a/spec/ruby/library/set/sortedset/plus_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require_relative 'shared/union' - require 'set' - - describe "SortedSet#+" do - it_behaves_like :sorted_set_union, :+ - end -end diff --git a/spec/ruby/library/set/sortedset/pretty_print_cycle_spec.rb b/spec/ruby/library/set/sortedset/pretty_print_cycle_spec.rb deleted file mode 100644 index e97f509406..0000000000 --- a/spec/ruby/library/set/sortedset/pretty_print_cycle_spec.rb +++ /dev/null @@ -1,13 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#pretty_print_cycle" do - it "passes the 'pretty print' representation of a self-referencing SortedSet to the pretty print writer" do - pp = mock("PrettyPrint") - pp.should_receive(:text).with("#<SortedSet: {...}>") - SortedSet[1, 2, 3].pretty_print_cycle(pp) - end - end -end diff --git a/spec/ruby/library/set/sortedset/pretty_print_spec.rb b/spec/ruby/library/set/sortedset/pretty_print_spec.rb deleted file mode 100644 index a8088bf797..0000000000 --- a/spec/ruby/library/set/sortedset/pretty_print_spec.rb +++ /dev/null @@ -1,20 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#pretty_print" do - it "passes the 'pretty print' representation of self to the pretty print writer" do - pp = mock("PrettyPrint") - set = SortedSet[1, 2, 3] - - pp.should_receive(:text).with("#<SortedSet: {") - pp.should_receive(:text).with("}>") - - pp.should_receive(:nest).with(1).and_yield - pp.should_receive(:seplist).with(set) - - set.pretty_print(pp) - end - end -end diff --git a/spec/ruby/library/set/sortedset/proper_subset_spec.rb b/spec/ruby/library/set/sortedset/proper_subset_spec.rb deleted file mode 100644 index 34fb89d13d..0000000000 --- a/spec/ruby/library/set/sortedset/proper_subset_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#proper_subset?" do - before :each do - @set = SortedSet[1, 2, 3, 4] - end - - it "returns true if passed a SortedSet that self is a proper subset of" do - SortedSet[].proper_subset?(@set).should be_true - SortedSet[].proper_subset?(SortedSet[1, 2, 3]).should be_true - SortedSet[].proper_subset?(SortedSet["a", "b", "c"]).should be_true - - SortedSet[1, 2, 3].proper_subset?(@set).should be_true - SortedSet[1, 3].proper_subset?(@set).should be_true - SortedSet[1, 2].proper_subset?(@set).should be_true - SortedSet[1].proper_subset?(@set).should be_true - - SortedSet[5].proper_subset?(@set).should be_false - SortedSet[1, 5].proper_subset?(@set).should be_false - SortedSet["test"].proper_subset?(@set).should be_false - - @set.proper_subset?(@set).should be_false - SortedSet[].proper_subset?(SortedSet[]).should be_false - end - - it "raises an ArgumentError when passed a non-SortedSet" do - -> { SortedSet[].proper_subset?([]) }.should raise_error(ArgumentError) - -> { SortedSet[].proper_subset?(1) }.should raise_error(ArgumentError) - -> { SortedSet[].proper_subset?("test") }.should raise_error(ArgumentError) - -> { SortedSet[].proper_subset?(Object.new) }.should raise_error(ArgumentError) - end - end -end diff --git a/spec/ruby/library/set/sortedset/proper_superset_spec.rb b/spec/ruby/library/set/sortedset/proper_superset_spec.rb deleted file mode 100644 index 8b92444f72..0000000000 --- a/spec/ruby/library/set/sortedset/proper_superset_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#proper_superset?" do - before :each do - @set = SortedSet[1, 2, 3, 4] - end - - it "returns true if passed a SortedSet that self is a proper superset of" do - @set.proper_superset?(SortedSet[]).should be_true - SortedSet[1, 2, 3].proper_superset?(SortedSet[]).should be_true - SortedSet["a", "b", "c"].proper_superset?(SortedSet[]).should be_true - - @set.proper_superset?(SortedSet[1, 2, 3]).should be_true - @set.proper_superset?(SortedSet[1, 3]).should be_true - @set.proper_superset?(SortedSet[1, 2]).should be_true - @set.proper_superset?(SortedSet[1]).should be_true - - @set.proper_superset?(SortedSet[5]).should be_false - @set.proper_superset?(SortedSet[1, 5]).should be_false - @set.proper_superset?(SortedSet["test"]).should be_false - - @set.proper_superset?(@set).should be_false - SortedSet[].proper_superset?(SortedSet[]).should be_false - end - - it "raises an ArgumentError when passed a non-SortedSet" do - -> { SortedSet[].proper_superset?([]) }.should raise_error(ArgumentError) - -> { SortedSet[].proper_superset?(1) }.should raise_error(ArgumentError) - -> { SortedSet[].proper_superset?("test") }.should raise_error(ArgumentError) - -> { SortedSet[].proper_superset?(Object.new) }.should raise_error(ArgumentError) - end - end -end diff --git a/spec/ruby/library/set/sortedset/reject_spec.rb b/spec/ruby/library/set/sortedset/reject_spec.rb deleted file mode 100644 index 396b864cc5..0000000000 --- a/spec/ruby/library/set/sortedset/reject_spec.rb +++ /dev/null @@ -1,45 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#reject!" do - before :each do - @set = SortedSet["one", "two", "three"] - end - - it "yields each Object in self in sorted order" do - res = [] - @set.reject! { |x| res << x } - res.should == ["one", "two", "three"].sort - end - - it "deletes every element from self for which the passed block returns true" do - @set.reject! { |x| x.size == 3 } - @set.size.should eql(1) - - @set.should_not include("one") - @set.should_not include("two") - @set.should include("three") - end - - it "returns self when self was modified" do - @set.reject! { |x| true }.should equal(@set) - end - - it "returns nil when self was not modified" do - @set.reject! { |x| false }.should be_nil - end - - it "returns an Enumerator when passed no block" do - enum = @set.reject! - enum.should be_an_instance_of(Enumerator) - - enum.each { |x| x.size == 3 } - - @set.should_not include("one") - @set.should_not include("two") - @set.should include("three") - end - end -end diff --git a/spec/ruby/library/set/sortedset/replace_spec.rb b/spec/ruby/library/set/sortedset/replace_spec.rb deleted file mode 100644 index 2900221c01..0000000000 --- a/spec/ruby/library/set/sortedset/replace_spec.rb +++ /dev/null @@ -1,20 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#replace" do - before :each do - @set = SortedSet["a", "b", "c"] - end - - it "replaces the contents with other and returns self" do - @set.replace(SortedSet[1, 2, 3]).should == @set - @set.should == SortedSet[1, 2, 3] - end - - it "accepts any enumerable as other" do - @set.replace([1, 2, 3]).should == SortedSet[1, 2, 3] - end - end -end diff --git a/spec/ruby/library/set/sortedset/select_spec.rb b/spec/ruby/library/set/sortedset/select_spec.rb deleted file mode 100644 index fc4c15ee4d..0000000000 --- a/spec/ruby/library/set/sortedset/select_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require_relative 'shared/select' - require 'set' - - describe "SortedSet#select!" do - it_behaves_like :sorted_set_select_bang, :select! - end -end diff --git a/spec/ruby/library/set/sortedset/shared/add.rb b/spec/ruby/library/set/sortedset/shared/add.rb deleted file mode 100644 index 95ef1b090e..0000000000 --- a/spec/ruby/library/set/sortedset/shared/add.rb +++ /dev/null @@ -1,14 +0,0 @@ -describe :sorted_set_add, shared: true do - before :each do - @set = SortedSet.new - end - - it "adds the passed Object to self" do - @set.send(@method, "dog") - @set.should include("dog") - end - - it "returns self" do - @set.send(@method, "dog").should equal(@set) - end -end diff --git a/spec/ruby/library/set/sortedset/shared/collect.rb b/spec/ruby/library/set/sortedset/shared/collect.rb deleted file mode 100644 index e53304d427..0000000000 --- a/spec/ruby/library/set/sortedset/shared/collect.rb +++ /dev/null @@ -1,20 +0,0 @@ -describe :sorted_set_collect_bang, shared: true do - before :each do - @set = SortedSet[1, 2, 3, 4, 5] - end - - it "yields each Object in self in sorted order" do - res = [] - SortedSet["one", "two", "three"].send(@method) { |x| res << x; x } - res.should == ["one", "two", "three"].sort - end - - it "returns self" do - @set.send(@method) { |x| x }.should equal(@set) - end - - it "replaces self with the return values of the block" do - @set.send(@method) { |x| x * 2 } - @set.should == SortedSet[2, 4, 6, 8, 10] - end -end diff --git a/spec/ruby/library/set/sortedset/shared/difference.rb b/spec/ruby/library/set/sortedset/shared/difference.rb deleted file mode 100644 index 688e23a7a7..0000000000 --- a/spec/ruby/library/set/sortedset/shared/difference.rb +++ /dev/null @@ -1,15 +0,0 @@ -describe :sorted_set_difference, shared: true do - before :each do - @set = SortedSet["a", "b", "c"] - end - - it "returns a new SortedSet containing self's elements excluding the elements in the passed Enumerable" do - @set.send(@method, SortedSet["a", "b"]).should == SortedSet["c"] - @set.send(@method, ["b", "c"]).should == SortedSet["a"] - end - - it "raises an ArgumentError when passed a non-Enumerable" do - -> { @set.send(@method, 1) }.should raise_error(ArgumentError) - -> { @set.send(@method, Object.new) }.should raise_error(ArgumentError) - end -end diff --git a/spec/ruby/library/set/sortedset/shared/include.rb b/spec/ruby/library/set/sortedset/shared/include.rb deleted file mode 100644 index cd1758819d..0000000000 --- a/spec/ruby/library/set/sortedset/shared/include.rb +++ /dev/null @@ -1,7 +0,0 @@ -describe :sorted_set_include, shared: true do - it "returns true when self contains the passed Object" do - set = SortedSet["a", "b", "c"] - set.send(@method, "a").should be_true - set.send(@method, "e").should be_false - end -end diff --git a/spec/ruby/library/set/sortedset/shared/intersection.rb b/spec/ruby/library/set/sortedset/shared/intersection.rb deleted file mode 100644 index 045716ad05..0000000000 --- a/spec/ruby/library/set/sortedset/shared/intersection.rb +++ /dev/null @@ -1,15 +0,0 @@ -describe :sorted_set_intersection, shared: true do - before :each do - @set = SortedSet["a", "b", "c"] - end - - it "returns a new SortedSet containing only elements shared by self and the passed Enumerable" do - @set.send(@method, SortedSet["b", "c", "d", "e"]).should == SortedSet["b", "c"] - @set.send(@method, ["b", "c", "d"]).should == SortedSet["b", "c"] - end - - it "raises an ArgumentError when passed a non-Enumerable" do - -> { @set.send(@method, 1) }.should raise_error(ArgumentError) - -> { @set.send(@method, Object.new) }.should raise_error(ArgumentError) - end -end diff --git a/spec/ruby/library/set/sortedset/shared/length.rb b/spec/ruby/library/set/sortedset/shared/length.rb deleted file mode 100644 index d1dfee1cff..0000000000 --- a/spec/ruby/library/set/sortedset/shared/length.rb +++ /dev/null @@ -1,6 +0,0 @@ -describe :sorted_set_length, shared: true do - it "returns the number of elements in the set" do - set = SortedSet["a", "b", "c"] - set.send(@method).should == 3 - end -end diff --git a/spec/ruby/library/set/sortedset/shared/select.rb b/spec/ruby/library/set/sortedset/shared/select.rb deleted file mode 100644 index e13311eda5..0000000000 --- a/spec/ruby/library/set/sortedset/shared/select.rb +++ /dev/null @@ -1,35 +0,0 @@ -require_relative '../../../../spec_helper' -require 'set' - -describe :sorted_set_select_bang, shared: true do - before :each do - @set = SortedSet["one", "two", "three"] - end - - it "yields each Object in self in sorted order" do - res = [] - @set.send(@method) { |x| res << x } - res.should == ["one", "two", "three"].sort - end - - it "keeps every element from self for which the passed block returns true" do - @set.send(@method) { |x| x.size != 3 } - @set.to_a.should == ["three"] - end - - it "returns self when self was modified" do - @set.send(@method) { false }.should equal(@set) - end - - it "returns nil when self was not modified" do - @set.send(@method) { true }.should be_nil - end - - it "returns an Enumerator when passed no block" do - enum = @set.send(@method) - enum.should be_an_instance_of(Enumerator) - - enum.each { |x| x.size != 3 } - @set.to_a.should == ["three"] - end -end diff --git a/spec/ruby/library/set/sortedset/shared/union.rb b/spec/ruby/library/set/sortedset/shared/union.rb deleted file mode 100644 index 9015bdc8e3..0000000000 --- a/spec/ruby/library/set/sortedset/shared/union.rb +++ /dev/null @@ -1,15 +0,0 @@ -describe :sorted_set_union, shared: true do - before :each do - @set = SortedSet["a", "b", "c"] - end - - it "returns a new SortedSet containing all elements of self and the passed Enumerable" do - @set.send(@method, SortedSet["b", "d", "e"]).should == SortedSet["a", "b", "c", "d", "e"] - @set.send(@method, ["b", "e"]).should == SortedSet["a", "b", "c", "e"] - end - - it "raises an ArgumentError when passed a non-Enumerable" do - -> { @set.send(@method, 1) }.should raise_error(ArgumentError) - -> { @set.send(@method, Object.new) }.should raise_error(ArgumentError) - end -end diff --git a/spec/ruby/library/set/sortedset/size_spec.rb b/spec/ruby/library/set/sortedset/size_spec.rb deleted file mode 100644 index d908b33b53..0000000000 --- a/spec/ruby/library/set/sortedset/size_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require_relative 'shared/length' - require 'set' - - describe "SortedSet#size" do - it_behaves_like :sorted_set_length, :size - end -end diff --git a/spec/ruby/library/set/sortedset/sortedset_spec.rb b/spec/ruby/library/set/sortedset/sortedset_spec.rb deleted file mode 100644 index 3ead5495fc..0000000000 --- a/spec/ruby/library/set/sortedset/sortedset_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -require_relative '../../../spec_helper' -require 'set' - -ruby_version_is "3.0" do - describe "SortedSet" do - it "raises error including message that it has been extracted from the set stdlib" do - -> { - SortedSet - }.should raise_error(RuntimeError) { |e| - e.message.should.include?("The `SortedSet` class has been extracted from the `set` library") - } - end - end -end - -ruby_version_is ""..."3.0" do - describe "SortedSet" do - it "is part of the set stdlib" do - SortedSet.superclass.should == Set - end - end -end diff --git a/spec/ruby/library/set/sortedset/subset_spec.rb b/spec/ruby/library/set/sortedset/subset_spec.rb deleted file mode 100644 index 272e3f985e..0000000000 --- a/spec/ruby/library/set/sortedset/subset_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#subset?" do - before :each do - @set = SortedSet[1, 2, 3, 4] - end - - it "returns true if passed a SortedSet that is equal to self or self is a subset of" do - @set.subset?(@set).should be_true - SortedSet[].subset?(SortedSet[]).should be_true - - SortedSet[].subset?(@set).should be_true - SortedSet[].subset?(SortedSet[1, 2, 3]).should be_true - SortedSet[].subset?(SortedSet["a", "b", "c"]).should be_true - - SortedSet[1, 2, 3].subset?(@set).should be_true - SortedSet[1, 3].subset?(@set).should be_true - SortedSet[1, 2].subset?(@set).should be_true - SortedSet[1].subset?(@set).should be_true - - SortedSet[5].subset?(@set).should be_false - SortedSet[1, 5].subset?(@set).should be_false - SortedSet["test"].subset?(@set).should be_false - end - - it "raises an ArgumentError when passed a non-SortedSet" do - -> { SortedSet[].subset?([]) }.should raise_error(ArgumentError) - -> { SortedSet[].subset?(1) }.should raise_error(ArgumentError) - -> { SortedSet[].subset?("test") }.should raise_error(ArgumentError) - -> { SortedSet[].subset?(Object.new) }.should raise_error(ArgumentError) - end - end -end diff --git a/spec/ruby/library/set/sortedset/subtract_spec.rb b/spec/ruby/library/set/sortedset/subtract_spec.rb deleted file mode 100644 index b2af127f89..0000000000 --- a/spec/ruby/library/set/sortedset/subtract_spec.rb +++ /dev/null @@ -1,20 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#subtract" do - before :each do - @set = SortedSet["a", "b", "c"] - end - - it "deletes any elements contained in other and returns self" do - @set.subtract(SortedSet["b", "c"]).should == @set - @set.should == SortedSet["a"] - end - - it "accepts any enumerable as other" do - @set.subtract(["c"]).should == SortedSet["a", "b"] - end - end -end diff --git a/spec/ruby/library/set/sortedset/superset_spec.rb b/spec/ruby/library/set/sortedset/superset_spec.rb deleted file mode 100644 index a1bbacb966..0000000000 --- a/spec/ruby/library/set/sortedset/superset_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#superset?" do - before :each do - @set = SortedSet[1, 2, 3, 4] - end - - it "returns true if passed a SortedSet that equals self or self is a proper superset of" do - @set.superset?(@set).should be_true - SortedSet[].superset?(SortedSet[]).should be_true - - @set.superset?(SortedSet[]).should be_true - SortedSet[1, 2, 3].superset?(SortedSet[]).should be_true - SortedSet["a", "b", "c"].superset?(SortedSet[]).should be_true - - @set.superset?(SortedSet[1, 2, 3]).should be_true - @set.superset?(SortedSet[1, 3]).should be_true - @set.superset?(SortedSet[1, 2]).should be_true - @set.superset?(SortedSet[1]).should be_true - - @set.superset?(SortedSet[5]).should be_false - @set.superset?(SortedSet[1, 5]).should be_false - @set.superset?(SortedSet["test"]).should be_false - end - - it "raises an ArgumentError when passed a non-SortedSet" do - -> { SortedSet[].superset?([]) }.should raise_error(ArgumentError) - -> { SortedSet[].superset?(1) }.should raise_error(ArgumentError) - -> { SortedSet[].superset?("test") }.should raise_error(ArgumentError) - -> { SortedSet[].superset?(Object.new) }.should raise_error(ArgumentError) - end - end -end diff --git a/spec/ruby/library/set/sortedset/to_a_spec.rb b/spec/ruby/library/set/sortedset/to_a_spec.rb deleted file mode 100644 index bb54cd7cdb..0000000000 --- a/spec/ruby/library/set/sortedset/to_a_spec.rb +++ /dev/null @@ -1,20 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#to_a" do - it "returns an array containing elements" do - set = SortedSet.new [1, 2, 3] - set.to_a.should == [1, 2, 3] - end - - it "returns a sorted array containing elements" do - set = SortedSet[2, 3, 1] - set.to_a.should == [1, 2, 3] - - set = SortedSet.new [5, 6, 4, 4] - set.to_a.should == [4, 5, 6] - end - end -end diff --git a/spec/ruby/library/set/sortedset/union_spec.rb b/spec/ruby/library/set/sortedset/union_spec.rb deleted file mode 100644 index c942f20d3e..0000000000 --- a/spec/ruby/library/set/sortedset/union_spec.rb +++ /dev/null @@ -1,14 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require_relative 'shared/union' - require 'set' - - describe "SortedSet#union" do - it_behaves_like :sorted_set_union, :union - end - - describe "SortedSet#|" do - it_behaves_like :sorted_set_union, :| - end -end diff --git a/spec/ruby/library/set/subset_spec.rb b/spec/ruby/library/set/subset_spec.rb deleted file mode 100644 index f375efa6df..0000000000 --- a/spec/ruby/library/set/subset_spec.rb +++ /dev/null @@ -1,41 +0,0 @@ -require_relative '../../spec_helper' -require_relative 'fixtures/set_like' -require 'set' - -describe "Set#subset?" do - before :each do - @set = Set[1, 2, 3, 4] - end - - it "returns true if passed a Set that is equal to self or self is a subset of" do - @set.subset?(@set).should be_true - Set[].subset?(Set[]).should be_true - - Set[].subset?(@set).should be_true - Set[].subset?(Set[1, 2, 3]).should be_true - Set[].subset?(Set["a", :b, ?c]).should be_true - - Set[1, 2, 3].subset?(@set).should be_true - Set[1, 3].subset?(@set).should be_true - Set[1, 2].subset?(@set).should be_true - Set[1].subset?(@set).should be_true - - Set[5].subset?(@set).should be_false - Set[1, 5].subset?(@set).should be_false - Set[nil].subset?(@set).should be_false - Set["test"].subset?(@set).should be_false - end - - it "raises an ArgumentError when passed a non-Set" do - -> { Set[].subset?([]) }.should raise_error(ArgumentError) - -> { Set[].subset?(1) }.should raise_error(ArgumentError) - -> { Set[].subset?("test") }.should raise_error(ArgumentError) - -> { Set[].subset?(Object.new) }.should raise_error(ArgumentError) - end - - context "when comparing to a Set-like object" do - it "returns true if passed a Set-like object that self is a subset of" do - Set[1, 2, 3].subset?(SetSpecs::SetLike.new([1, 2, 3, 4])).should be_true - end - end -end diff --git a/spec/ruby/library/set/subtract_spec.rb b/spec/ruby/library/set/subtract_spec.rb deleted file mode 100644 index 56713de8b3..0000000000 --- a/spec/ruby/library/set/subtract_spec.rb +++ /dev/null @@ -1,17 +0,0 @@ -require_relative '../../spec_helper' -require 'set' - -describe "Set#subtract" do - before :each do - @set = Set[:a, :b, :c] - end - - it "deletes any elements contained in other and returns self" do - @set.subtract(Set[:b, :c]).should == @set - @set.should == Set[:a] - end - - it "accepts any enumerable as other" do - @set.subtract([:c]).should == Set[:a, :b] - end -end diff --git a/spec/ruby/library/set/superset_spec.rb b/spec/ruby/library/set/superset_spec.rb deleted file mode 100644 index bd9d2f3eee..0000000000 --- a/spec/ruby/library/set/superset_spec.rb +++ /dev/null @@ -1,41 +0,0 @@ -require_relative '../../spec_helper' -require_relative 'fixtures/set_like' -require 'set' - -describe "Set#superset?" do - before :each do - @set = Set[1, 2, 3, 4] - end - - it "returns true if passed a Set that equals self or self is a proper superset of" do - @set.superset?(@set).should be_true - Set[].superset?(Set[]).should be_true - - @set.superset?(Set[]).should be_true - Set[1, 2, 3].superset?(Set[]).should be_true - Set["a", :b, ?c].superset?(Set[]).should be_true - - @set.superset?(Set[1, 2, 3]).should be_true - @set.superset?(Set[1, 3]).should be_true - @set.superset?(Set[1, 2]).should be_true - @set.superset?(Set[1]).should be_true - - @set.superset?(Set[5]).should be_false - @set.superset?(Set[1, 5]).should be_false - @set.superset?(Set[nil]).should be_false - @set.superset?(Set["test"]).should be_false - end - - it "raises an ArgumentError when passed a non-Set" do - -> { Set[].superset?([]) }.should raise_error(ArgumentError) - -> { Set[].superset?(1) }.should raise_error(ArgumentError) - -> { Set[].superset?("test") }.should raise_error(ArgumentError) - -> { Set[].superset?(Object.new) }.should raise_error(ArgumentError) - end - - context "when comparing to a Set-like object" do - it "returns true if passed a Set-like object that self is a superset of" do - Set[1, 2, 3, 4].superset?(SetSpecs::SetLike.new([1, 2, 3])).should be_true - end - end -end diff --git a/spec/ruby/library/set/to_a_spec.rb b/spec/ruby/library/set/to_a_spec.rb deleted file mode 100644 index 689e44f38a..0000000000 --- a/spec/ruby/library/set/to_a_spec.rb +++ /dev/null @@ -1,8 +0,0 @@ -require_relative '../../spec_helper' -require 'set' - -describe "Set#to_a" do - it "returns an array containing elements of self" do - Set[1, 2, 3].to_a.sort.should == [1, 2, 3] - end -end diff --git a/spec/ruby/library/set/to_s_spec.rb b/spec/ruby/library/set/to_s_spec.rb deleted file mode 100644 index 3c26ae9346..0000000000 --- a/spec/ruby/library/set/to_s_spec.rb +++ /dev/null @@ -1,12 +0,0 @@ -require_relative "../../spec_helper" -require_relative 'shared/inspect' -require 'set' - -describe "Set#to_s" do - it_behaves_like :set_inspect, :to_s - - it "is an alias of inspect" do - set = Set.new - set.method(:to_s).should == set.method(:inspect) - end -end diff --git a/spec/ruby/library/set/union_spec.rb b/spec/ruby/library/set/union_spec.rb deleted file mode 100644 index 20fe0ddca3..0000000000 --- a/spec/ruby/library/set/union_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require_relative '../../spec_helper' -require_relative 'shared/union' -require 'set' - -describe "Set#union" do - it_behaves_like :set_union, :union -end - -describe "Set#|" do - it_behaves_like :set_union, :| -end diff --git a/spec/ruby/library/shellwords/shellwords_spec.rb b/spec/ruby/library/shellwords/shellwords_spec.rb index 2975fd9974..fe86b6faab 100644 --- a/spec/ruby/library/shellwords/shellwords_spec.rb +++ b/spec/ruby/library/shellwords/shellwords_spec.rb @@ -1,34 +1,33 @@ require_relative '../../spec_helper' require 'shellwords' -include Shellwords describe "Shellwords#shellwords" do it "honors quoted strings" do - shellwords('a "b b" a').should == ['a', 'b b', 'a'] + Shellwords.shellwords('a "b b" a').should == ['a', 'b b', 'a'] end it "honors escaped double quotes" do - shellwords('a "\"b\" c" d').should == ['a', '"b" c', 'd'] + Shellwords.shellwords('a "\"b\" c" d').should == ['a', '"b" c', 'd'] end it "honors escaped single quotes" do - shellwords("a \"'b' c\" d").should == ['a', "'b' c", 'd'] + Shellwords.shellwords("a \"'b' c\" d").should == ['a', "'b' c", 'd'] end it "honors escaped spaces" do - shellwords('a b\ c d').should == ['a', 'b c', 'd'] + Shellwords.shellwords('a b\ c d').should == ['a', 'b c', 'd'] end it "raises ArgumentError when double quoted strings are misquoted" do - -> { shellwords('a "b c d e') }.should raise_error(ArgumentError) + -> { Shellwords.shellwords('a "b c d e') }.should raise_error(ArgumentError) end it "raises ArgumentError when single quoted strings are misquoted" do - -> { shellwords("a 'b c d e") }.should raise_error(ArgumentError) + -> { Shellwords.shellwords("a 'b c d e") }.should raise_error(ArgumentError) end # https://bugs.ruby-lang.org/issues/10055 it "matches POSIX sh behavior for backslashes within double quoted strings" do - shellsplit('printf "%s\n"').should == ['printf', '%s\n'] + Shellwords.shellsplit('printf "%s\n"').should == ['printf', '%s\n'] end end diff --git a/spec/ruby/library/socket/addrinfo/afamily_spec.rb b/spec/ruby/library/socket/addrinfo/afamily_spec.rb index 7229dab9de..5d075be057 100644 --- a/spec/ruby/library/socket/addrinfo/afamily_spec.rb +++ b/spec/ruby/library/socket/addrinfo/afamily_spec.rb @@ -23,15 +23,13 @@ describe "Addrinfo#afamily" do end end - with_feature :unix_socket do - describe "for a unix socket" do - before :each do - @addrinfo = Addrinfo.unix("/tmp/sock") - end - - it "returns Socket::AF_UNIX" do - @addrinfo.afamily.should == Socket::AF_UNIX - end + describe "for a unix socket" do + before :each do + @addrinfo = Addrinfo.unix("/tmp/sock") + end + + it "returns Socket::AF_UNIX" do + @addrinfo.afamily.should == Socket::AF_UNIX end end end diff --git a/spec/ruby/library/socket/addrinfo/family_addrinfo_spec.rb b/spec/ruby/library/socket/addrinfo/family_addrinfo_spec.rb index 2bc3b6a2e3..3c2f9f73d8 100644 --- a/spec/ruby/library/socket/addrinfo/family_addrinfo_spec.rb +++ b/spec/ruby/library/socket/addrinfo/family_addrinfo_spec.rb @@ -50,38 +50,36 @@ describe 'Addrinfo#family_addrinfo' do end end - with_feature :unix_socket do - describe 'with a UNIX Addrinfo' do - before do - @source = Addrinfo.unix('cats') - end + describe 'with a UNIX Addrinfo' do + before do + @source = Addrinfo.unix('cats') + end - it 'raises ArgumentError if more than 1 argument is given' do - -> { @source.family_addrinfo('foo', 'bar') }.should raise_error(ArgumentError) - end + it 'raises ArgumentError if more than 1 argument is given' do + -> { @source.family_addrinfo('foo', 'bar') }.should raise_error(ArgumentError) + end - it 'returns an Addrinfo when a UNIX socket path is given' do - addr = @source.family_addrinfo('dogs') + it 'returns an Addrinfo when a UNIX socket path is given' do + addr = @source.family_addrinfo('dogs') - addr.should be_an_instance_of(Addrinfo) - end + addr.should be_an_instance_of(Addrinfo) + end - describe 'the returned Addrinfo' do - before do - @addr = @source.family_addrinfo('dogs') - end + describe 'the returned Addrinfo' do + before do + @addr = @source.family_addrinfo('dogs') + end - it 'uses AF_UNIX as the address family' do - @addr.afamily.should == Socket::AF_UNIX - end + it 'uses AF_UNIX as the address family' do + @addr.afamily.should == Socket::AF_UNIX + end - it 'uses PF_UNIX as the protocol family' do - @addr.pfamily.should == Socket::PF_UNIX - end + it 'uses PF_UNIX as the protocol family' do + @addr.pfamily.should == Socket::PF_UNIX + end - it 'uses the given socket path' do - @addr.unix_path.should == 'dogs' - end + it 'uses the given socket path' do + @addr.unix_path.should == 'dogs' end end end diff --git a/spec/ruby/library/socket/addrinfo/getaddrinfo_spec.rb b/spec/ruby/library/socket/addrinfo/getaddrinfo_spec.rb index 67fad73815..e05fe9967a 100644 --- a/spec/ruby/library/socket/addrinfo/getaddrinfo_spec.rb +++ b/spec/ruby/library/socket/addrinfo/getaddrinfo_spec.rb @@ -73,19 +73,15 @@ describe 'Addrinfo.getaddrinfo' do end end - platform_is_not :'solaris2.10' do # i386-solaris - it 'sets a custom socket protocol of the Addrinfo instances' do - array = Addrinfo.getaddrinfo('127.0.0.1', 80, nil, nil, Socket::IPPROTO_UDP) + it 'sets a custom socket protocol of the Addrinfo instances' do + array = Addrinfo.getaddrinfo('127.0.0.1', 80, nil, nil, Socket::IPPROTO_UDP) - array[0].protocol.should == Socket::IPPROTO_UDP - end + array[0].protocol.should == Socket::IPPROTO_UDP end - platform_is_not :solaris do - it 'sets the canonical name when AI_CANONNAME is given as a flag' do - array = Addrinfo.getaddrinfo('localhost', 80, nil, nil, nil, Socket::AI_CANONNAME) + it 'sets the canonical name when AI_CANONNAME is given as a flag' do + array = Addrinfo.getaddrinfo('localhost', 80, nil, nil, nil, Socket::AI_CANONNAME) - array[0].canonname.should be_an_instance_of(String) - end + array[0].canonname.should be_an_instance_of(String) end end diff --git a/spec/ruby/library/socket/addrinfo/getnameinfo_spec.rb b/spec/ruby/library/socket/addrinfo/getnameinfo_spec.rb index 76579de74c..43b5a2000a 100644 --- a/spec/ruby/library/socket/addrinfo/getnameinfo_spec.rb +++ b/spec/ruby/library/socket/addrinfo/getnameinfo_spec.rb @@ -22,19 +22,17 @@ describe 'Addrinfo#getnameinfo' do platform_is :linux do platform_is_not :android do - with_feature :unix_socket do - describe 'using a UNIX Addrinfo' do - before do - @addr = Addrinfo.unix('cats') - @host = Socket.gethostname - end + describe 'using a UNIX Addrinfo' do + before do + @addr = Addrinfo.unix('cats') + @host = Socket.gethostname + end - it 'returns the hostname and UNIX socket path' do - host, path = @addr.getnameinfo + it 'returns the hostname and UNIX socket path' do + host, path = @addr.getnameinfo - host.should == @host - path.should == 'cats' - end + host.should == @host + path.should == 'cats' end end end diff --git a/spec/ruby/library/socket/addrinfo/initialize_spec.rb b/spec/ruby/library/socket/addrinfo/initialize_spec.rb index 83b204b575..1f16531aaa 100644 --- a/spec/ruby/library/socket/addrinfo/initialize_spec.rb +++ b/spec/ruby/library/socket/addrinfo/initialize_spec.rb @@ -17,7 +17,7 @@ describe "Addrinfo#initialize" do @addrinfo.ip_port.should == 25 end - it "returns the Socket::UNSPEC pfamily" do + it "returns the UNSPEC pfamily" do @addrinfo.pfamily.should == Socket::PF_UNSPEC end @@ -53,7 +53,7 @@ describe "Addrinfo#initialize" do @addrinfo.ip_port.should == 25 end - it "returns the Socket::UNSPEC pfamily" do + it "returns the INET6 pfamily" do @addrinfo.pfamily.should == Socket::PF_INET6 end @@ -83,7 +83,7 @@ describe "Addrinfo#initialize" do @addrinfo.ip_port.should == 25 end - it "returns the Socket::UNSPEC pfamily" do + it "returns the INET6 pfamily" do @addrinfo.pfamily.should == Socket::PF_INET6 end @@ -113,7 +113,7 @@ describe "Addrinfo#initialize" do @addrinfo.ip_port.should == 25 end - it "returns the Socket::UNSPEC pfamily" do + it "returns the INET6 pfamily" do @addrinfo.pfamily.should == Socket::PF_INET6 end @@ -147,11 +147,11 @@ describe "Addrinfo#initialize" do @addrinfo.ip_port.should == 46102 end - it "returns the Socket::PF_INET pfamily" do + it "returns the INET pfamily" do @addrinfo.pfamily.should == Socket::PF_INET end - it "returns the INET6 afamily" do + it "returns the INET afamily" do @addrinfo.afamily.should == Socket::AF_INET end @@ -217,11 +217,11 @@ describe "Addrinfo#initialize" do @addrinfo.ip_port.should == 46102 end - it "returns the Socket::UNSPEC pfamily" do + it "returns the INET pfamily" do @addrinfo.pfamily.should == Socket::PF_INET end - it "returns the INET6 afamily" do + it "returns the INET afamily" do @addrinfo.afamily.should == Socket::AF_INET end @@ -247,11 +247,11 @@ describe "Addrinfo#initialize" do @addrinfo.ip_port.should == 46102 end - it "returns the Socket::UNSPEC pfamily" do + it "returns the INET pfamily" do @addrinfo.pfamily.should == Socket::PF_INET end - it "returns the INET6 afamily" do + it "returns the INET afamily" do @addrinfo.afamily.should == Socket::AF_INET end @@ -311,11 +311,11 @@ describe "Addrinfo#initialize" do @addrinfo.ip_port.should == 46102 end - it "returns the Socket::UNSPEC pfamily" do + it "returns the INET pfamily" do @addrinfo.pfamily.should == Socket::PF_INET end - it "returns the INET6 afamily" do + it "returns the INET afamily" do @addrinfo.afamily.should == Socket::AF_INET end @@ -335,7 +335,7 @@ describe "Addrinfo#initialize" do @sockaddr = ['AF_INET6', 80, 'hostname', '127.0.0.1'] end - it "raises SocketError when using any Socket constant except except AF_INET(6)/PF_INET(6)" do + it "raises SocketError when using any Socket constant except AF_INET(6)/PF_INET(6)" do Socket.constants.grep(/(^AF_|^PF_)(?!INET)/).each do |constant| value = Socket.const_get(constant) -> { @@ -362,7 +362,7 @@ describe "Addrinfo#initialize" do end end - platform_is_not :windows, :aix, :solaris do + platform_is_not :windows, :aix do (Socket.constants.grep(/^IPPROTO/) - valid).each do |type| it "raises SocketError when using #{type}" do value = Socket.const_get(type) @@ -390,7 +390,7 @@ describe "Addrinfo#initialize" do end end - platform_is_not :windows, :aix, :solaris do + platform_is_not :windows, :aix do (Socket.constants.grep(/^IPPROTO/) - valid).each do |type| it "raises SocketError when using #{type}" do value = Socket.const_get(type) @@ -495,7 +495,7 @@ describe "Addrinfo#initialize" do end end - platform_is_not :windows, :aix, :solaris do + platform_is_not :windows, :aix do (Socket.constants.grep(/^IPPROTO/) - valid).each do |type| it "raises SocketError when using #{type}" do value = Socket.const_get(type) @@ -514,13 +514,13 @@ describe "Addrinfo#initialize" do @sockaddr = Socket.sockaddr_in(80, '127.0.0.1') end - it 'returns an Addrinfo with :PF_INET family' do + it 'returns an Addrinfo with :PF_INET family' do addr = Addrinfo.new(@sockaddr, :PF_INET) addr.pfamily.should == Socket::PF_INET end - it 'returns an Addrinfo with :INET family' do + it 'returns an Addrinfo with :INET family' do addr = Addrinfo.new(@sockaddr, :INET) addr.pfamily.should == Socket::PF_INET @@ -544,13 +544,13 @@ describe "Addrinfo#initialize" do @sockaddr = Socket.sockaddr_in(80, '127.0.0.1') end - it 'returns an Addrinfo with "PF_INET" family' do + it 'returns an Addrinfo with "PF_INET" family' do addr = Addrinfo.new(@sockaddr, 'PF_INET') addr.pfamily.should == Socket::PF_INET end - it 'returns an Addrinfo with "INET" family' do + it 'returns an Addrinfo with "INET" family' do addr = Addrinfo.new(@sockaddr, 'INET') addr.pfamily.should == Socket::PF_INET @@ -569,23 +569,21 @@ describe "Addrinfo#initialize" do end end - with_feature :unix_socket do - describe 'using separate arguments for a Unix socket' do - before do - @sockaddr = Socket.pack_sockaddr_un('socket') - end + describe 'using separate arguments for a Unix socket' do + before do + @sockaddr = Socket.pack_sockaddr_un('socket') + end - it 'returns an Addrinfo with the correct unix path' do - Addrinfo.new(@sockaddr).unix_path.should == 'socket' - end + it 'returns an Addrinfo with the correct unix path' do + Addrinfo.new(@sockaddr).unix_path.should == 'socket' + end - it 'returns an Addrinfo with the correct protocol family' do - Addrinfo.new(@sockaddr).pfamily.should == Socket::PF_UNSPEC - end + it 'returns an Addrinfo with the correct protocol family' do + Addrinfo.new(@sockaddr).pfamily.should == Socket::PF_UNSPEC + end - it 'returns an Addrinfo with the correct address family' do - Addrinfo.new(@sockaddr).afamily.should == Socket::AF_UNIX - end + it 'returns an Addrinfo with the correct address family' do + Addrinfo.new(@sockaddr).afamily.should == Socket::AF_UNIX end end end diff --git a/spec/ruby/library/socket/addrinfo/inspect_sockaddr_spec.rb b/spec/ruby/library/socket/addrinfo/inspect_sockaddr_spec.rb index 70ca4dd4d7..6b18c79469 100644 --- a/spec/ruby/library/socket/addrinfo/inspect_sockaddr_spec.rb +++ b/spec/ruby/library/socket/addrinfo/inspect_sockaddr_spec.rb @@ -32,19 +32,17 @@ describe 'Addrinfo#inspect_sockaddr' do end end - with_feature :unix_socket do - describe 'using a UNIX path' do - it 'returns a String containing the UNIX path' do - addr = Addrinfo.unix('/foo/bar') + describe 'using a UNIX path' do + it 'returns a String containing the UNIX path' do + addr = Addrinfo.unix('/foo/bar') - addr.inspect_sockaddr.should == '/foo/bar' - end + addr.inspect_sockaddr.should == '/foo/bar' + end - it 'returns a String containing the UNIX path when using a relative path' do - addr = Addrinfo.unix('foo') + it 'returns a String containing the UNIX path when using a relative path' do + addr = Addrinfo.unix('foo') - addr.inspect_sockaddr.should == 'UNIX foo' - end + addr.inspect_sockaddr.should == 'UNIX foo' end end end diff --git a/spec/ruby/library/socket/addrinfo/inspect_spec.rb b/spec/ruby/library/socket/addrinfo/inspect_spec.rb index 98e1e83ffa..1442af6162 100644 --- a/spec/ruby/library/socket/addrinfo/inspect_spec.rb +++ b/spec/ruby/library/socket/addrinfo/inspect_spec.rb @@ -41,25 +41,23 @@ describe 'Addrinfo#inspect' do end end - with_feature :unix_socket do - describe 'using a UNIX Addrinfo' do - it 'returns a String' do - addr = Addrinfo.unix('/foo') + describe 'using a UNIX Addrinfo' do + it 'returns a String' do + addr = Addrinfo.unix('/foo') - addr.inspect.should == '#<Addrinfo: /foo SOCK_STREAM>' - end + addr.inspect.should == '#<Addrinfo: /foo SOCK_STREAM>' + end - it 'returns a String when using a relative UNIX path' do - addr = Addrinfo.unix('foo') + it 'returns a String when using a relative UNIX path' do + addr = Addrinfo.unix('foo') - addr.inspect.should == '#<Addrinfo: UNIX foo SOCK_STREAM>' - end + addr.inspect.should == '#<Addrinfo: UNIX foo SOCK_STREAM>' + end - it 'returns a String when using a DGRAM socket' do - addr = Addrinfo.unix('/foo', Socket::SOCK_DGRAM) + it 'returns a String when using a DGRAM socket' do + addr = Addrinfo.unix('/foo', Socket::SOCK_DGRAM) - addr.inspect.should == '#<Addrinfo: /foo SOCK_DGRAM>' - end + addr.inspect.should == '#<Addrinfo: /foo SOCK_DGRAM>' end end end diff --git a/spec/ruby/library/socket/addrinfo/ip_address_spec.rb b/spec/ruby/library/socket/addrinfo/ip_address_spec.rb index 4522cf5cfd..193432e861 100644 --- a/spec/ruby/library/socket/addrinfo/ip_address_spec.rb +++ b/spec/ruby/library/socket/addrinfo/ip_address_spec.rb @@ -21,15 +21,13 @@ describe "Addrinfo#ip_address" do end end - with_feature :unix_socket do - describe "for a unix socket" do - before :each do - @addrinfo = Addrinfo.unix("/tmp/sock") - end + describe "for a unix socket" do + before :each do + @addrinfo = Addrinfo.unix("/tmp/sock") + end - it "raises an exception" do - -> { @addrinfo.ip_address }.should raise_error(SocketError) - end + it "raises an exception" do + -> { @addrinfo.ip_address }.should raise_error(SocketError) end end diff --git a/spec/ruby/library/socket/addrinfo/ip_port_spec.rb b/spec/ruby/library/socket/addrinfo/ip_port_spec.rb index 4118607db0..f10ce35143 100644 --- a/spec/ruby/library/socket/addrinfo/ip_port_spec.rb +++ b/spec/ruby/library/socket/addrinfo/ip_port_spec.rb @@ -21,15 +21,13 @@ describe "Addrinfo#ip_port" do end end - with_feature :unix_socket do - describe "for a unix socket" do - before :each do - @addrinfo = Addrinfo.unix("/tmp/sock") - end + describe "for a unix socket" do + before :each do + @addrinfo = Addrinfo.unix("/tmp/sock") + end - it "raises an exception" do - -> { @addrinfo.ip_port }.should raise_error(SocketError) - end + it "raises an exception" do + -> { @addrinfo.ip_port }.should raise_error(SocketError) end end end diff --git a/spec/ruby/library/socket/addrinfo/ip_spec.rb b/spec/ruby/library/socket/addrinfo/ip_spec.rb index 80e7a62df7..09b9341605 100644 --- a/spec/ruby/library/socket/addrinfo/ip_spec.rb +++ b/spec/ruby/library/socket/addrinfo/ip_spec.rb @@ -22,15 +22,13 @@ describe "Addrinfo#ip?" do end end - with_feature :unix_socket do - describe "for a unix socket" do - before :each do - @addrinfo = Addrinfo.unix("/tmp/sock") - end + describe "for a unix socket" do + before :each do + @addrinfo = Addrinfo.unix("/tmp/sock") + end - it "returns false" do - @addrinfo.ip?.should be_false - end + it "returns false" do + @addrinfo.ip?.should be_false end end end diff --git a/spec/ruby/library/socket/addrinfo/ip_unpack_spec.rb b/spec/ruby/library/socket/addrinfo/ip_unpack_spec.rb index 6c81c48d1c..58260c4557 100644 --- a/spec/ruby/library/socket/addrinfo/ip_unpack_spec.rb +++ b/spec/ruby/library/socket/addrinfo/ip_unpack_spec.rb @@ -21,15 +21,13 @@ describe "Addrinfo#ip_unpack" do end end - with_feature :unix_socket do - describe "for a unix socket" do - before :each do - @addrinfo = Addrinfo.unix("/tmp/sock") - end + describe "for a unix socket" do + before :each do + @addrinfo = Addrinfo.unix("/tmp/sock") + end - it "raises an exception" do - -> { @addrinfo.ip_unpack }.should raise_error(SocketError) - end + it "raises an exception" do + -> { @addrinfo.ip_unpack }.should raise_error(SocketError) end end end diff --git a/spec/ruby/library/socket/addrinfo/ipv4_loopback_spec.rb b/spec/ruby/library/socket/addrinfo/ipv4_loopback_spec.rb index 10ad084fc9..3a584d4f52 100644 --- a/spec/ruby/library/socket/addrinfo/ipv4_loopback_spec.rb +++ b/spec/ruby/library/socket/addrinfo/ipv4_loopback_spec.rb @@ -29,15 +29,13 @@ describe "Addrinfo#ipv4_loopback?" do end end - with_feature :unix_socket do - describe "for a unix socket" do - before :each do - @addrinfo = Addrinfo.unix("/tmp/sock") - end + describe "for a unix socket" do + before :each do + @addrinfo = Addrinfo.unix("/tmp/sock") + end - it "returns false" do - @addrinfo.ipv4_loopback?.should be_false - end + it "returns false" do + @addrinfo.ipv4_loopback?.should be_false end end end diff --git a/spec/ruby/library/socket/addrinfo/ipv4_multicast_spec.rb b/spec/ruby/library/socket/addrinfo/ipv4_multicast_spec.rb index f7fead8640..e4b4cfcc84 100644 --- a/spec/ruby/library/socket/addrinfo/ipv4_multicast_spec.rb +++ b/spec/ruby/library/socket/addrinfo/ipv4_multicast_spec.rb @@ -15,15 +15,13 @@ describe "Addrinfo#ipv4_multicast?" do Addrinfo.ip('::1').should_not.ipv4_multicast? end - with_feature :unix_socket do - describe "for a unix socket" do - before :each do - @addrinfo = Addrinfo.unix("/tmp/sock") - end + describe "for a unix socket" do + before :each do + @addrinfo = Addrinfo.unix("/tmp/sock") + end - it "returns false" do - @addrinfo.ipv4_multicast?.should be_false - end + it "returns false" do + @addrinfo.ipv4_multicast?.should be_false end end end diff --git a/spec/ruby/library/socket/addrinfo/ipv4_private_spec.rb b/spec/ruby/library/socket/addrinfo/ipv4_private_spec.rb index e5a33b4953..97218b5ba3 100644 --- a/spec/ruby/library/socket/addrinfo/ipv4_private_spec.rb +++ b/spec/ruby/library/socket/addrinfo/ipv4_private_spec.rb @@ -33,15 +33,13 @@ describe "Addrinfo#ipv4_private?" do end end - with_feature :unix_socket do - describe "for a unix socket" do - before :each do - @addrinfo = Addrinfo.unix("/tmp/sock") - end - - it "returns false" do - @addrinfo.ipv4_private?.should be_false - end + describe "for a unix socket" do + before :each do + @addrinfo = Addrinfo.unix("/tmp/sock") + end + + it "returns false" do + @addrinfo.ipv4_private?.should be_false end end end diff --git a/spec/ruby/library/socket/addrinfo/ipv4_spec.rb b/spec/ruby/library/socket/addrinfo/ipv4_spec.rb index 7cba8209b6..61f7759b10 100644 --- a/spec/ruby/library/socket/addrinfo/ipv4_spec.rb +++ b/spec/ruby/library/socket/addrinfo/ipv4_spec.rb @@ -21,15 +21,13 @@ describe "Addrinfo#ipv4?" do end end - with_feature :unix_socket do - describe "for a unix socket" do - before :each do - @addrinfo = Addrinfo.unix("/tmp/sock") - end + describe "for a unix socket" do + before :each do + @addrinfo = Addrinfo.unix("/tmp/sock") + end - it "returns false" do - @addrinfo.ipv4?.should be_false - end + it "returns false" do + @addrinfo.ipv4?.should be_false end end end diff --git a/spec/ruby/library/socket/addrinfo/ipv6_loopback_spec.rb b/spec/ruby/library/socket/addrinfo/ipv6_loopback_spec.rb index 9ff8f107bf..ffc75185ea 100644 --- a/spec/ruby/library/socket/addrinfo/ipv6_loopback_spec.rb +++ b/spec/ruby/library/socket/addrinfo/ipv6_loopback_spec.rb @@ -31,15 +31,13 @@ describe "Addrinfo#ipv6_loopback?" do end end - with_feature :unix_socket do - describe "for a unix socket" do - before :each do - @addrinfo = Addrinfo.unix("/tmp/sock") - end - - it "returns false" do - @addrinfo.ipv6_loopback?.should be_false - end + describe "for a unix socket" do + before :each do + @addrinfo = Addrinfo.unix("/tmp/sock") + end + + it "returns false" do + @addrinfo.ipv6_loopback?.should be_false end end end diff --git a/spec/ruby/library/socket/addrinfo/ipv6_multicast_spec.rb b/spec/ruby/library/socket/addrinfo/ipv6_multicast_spec.rb index 2c987b5921..99d4e8cf4d 100644 --- a/spec/ruby/library/socket/addrinfo/ipv6_multicast_spec.rb +++ b/spec/ruby/library/socket/addrinfo/ipv6_multicast_spec.rb @@ -34,15 +34,13 @@ describe "Addrinfo#ipv6_multicast?" do end end - with_feature :unix_socket do - describe "for a unix socket" do - before :each do - @addrinfo = Addrinfo.unix("/tmp/sock") - end - - it "returns false" do - @addrinfo.ipv6_multicast?.should be_false - end + describe "for a unix socket" do + before :each do + @addrinfo = Addrinfo.unix("/tmp/sock") + end + + it "returns false" do + @addrinfo.ipv6_multicast?.should be_false end end end diff --git a/spec/ruby/library/socket/addrinfo/ipv6_spec.rb b/spec/ruby/library/socket/addrinfo/ipv6_spec.rb index 131e38849c..436d5e930b 100644 --- a/spec/ruby/library/socket/addrinfo/ipv6_spec.rb +++ b/spec/ruby/library/socket/addrinfo/ipv6_spec.rb @@ -21,15 +21,13 @@ describe "Addrinfo#ipv6?" do end end - with_feature :unix_socket do - describe "for a unix socket" do - before :each do - @addrinfo = Addrinfo.unix("/tmp/sock") - end + describe "for a unix socket" do + before :each do + @addrinfo = Addrinfo.unix("/tmp/sock") + end - it "returns false" do - @addrinfo.ipv6?.should be_false - end + it "returns false" do + @addrinfo.ipv6?.should be_false end end end diff --git a/spec/ruby/library/socket/addrinfo/ipv6_to_ipv4_spec.rb b/spec/ruby/library/socket/addrinfo/ipv6_to_ipv4_spec.rb index 6dfaf531ae..29050bec20 100644 --- a/spec/ruby/library/socket/addrinfo/ipv6_to_ipv4_spec.rb +++ b/spec/ruby/library/socket/addrinfo/ipv6_to_ipv4_spec.rb @@ -62,7 +62,7 @@ guard -> { SocketSpecs.ipv6_available? } do Addrinfo.ip('192.168.1.1').ipv6_to_ipv4.should be_nil end - with_feature :unix_socket do + describe 'for a unix socket' do it 'returns nil for a UNIX Addrinfo' do Addrinfo.unix('foo').ipv6_to_ipv4.should be_nil end diff --git a/spec/ruby/library/socket/addrinfo/marshal_dump_spec.rb b/spec/ruby/library/socket/addrinfo/marshal_dump_spec.rb index c4220a6f3e..e2c3497f7f 100644 --- a/spec/ruby/library/socket/addrinfo/marshal_dump_spec.rb +++ b/spec/ruby/library/socket/addrinfo/marshal_dump_spec.rb @@ -32,10 +32,8 @@ describe 'Addrinfo#marshal_dump' do @array[3].should == 'SOCK_STREAM' end - platform_is_not :'solaris2.10' do # i386-solaris - it 'includes the protocol as the 5th value' do - @array[4].should == 'IPPROTO_TCP' - end + it 'includes the protocol as the 5th value' do + @array[4].should == 'IPPROTO_TCP' end it 'includes the canonical name as the 6th value' do @@ -44,40 +42,38 @@ describe 'Addrinfo#marshal_dump' do end end - with_feature :unix_socket do - describe 'using a UNIX Addrinfo' do + describe 'using a UNIX Addrinfo' do + before do + @addr = Addrinfo.unix('foo') + end + + it 'returns an Array' do + @addr.marshal_dump.should be_an_instance_of(Array) + end + + describe 'the returned Array' do before do - @addr = Addrinfo.unix('foo') + @array = @addr.marshal_dump end - it 'returns an Array' do - @addr.marshal_dump.should be_an_instance_of(Array) + it 'includes the address family as the 1st value' do + @array[0].should == 'AF_UNIX' end - describe 'the returned Array' do - before do - @array = @addr.marshal_dump - end - - it 'includes the address family as the 1st value' do - @array[0].should == 'AF_UNIX' - end - - it 'includes the UNIX path as the 2nd value' do - @array[1].should == @addr.unix_path - end + it 'includes the UNIX path as the 2nd value' do + @array[1].should == @addr.unix_path + end - it 'includes the protocol family as the 3rd value' do - @array[2].should == 'PF_UNIX' - end + it 'includes the protocol family as the 3rd value' do + @array[2].should == 'PF_UNIX' + end - it 'includes the socket type as the 4th value' do - @array[3].should == 'SOCK_STREAM' - end + it 'includes the socket type as the 4th value' do + @array[3].should == 'SOCK_STREAM' + end - it 'includes the protocol as the 5th value' do - @array[4].should == 0 - end + it 'includes the protocol as the 5th value' do + @array[4].should == 0 end end end diff --git a/spec/ruby/library/socket/addrinfo/marshal_load_spec.rb b/spec/ruby/library/socket/addrinfo/marshal_load_spec.rb index aa20865224..02cef90115 100644 --- a/spec/ruby/library/socket/addrinfo/marshal_load_spec.rb +++ b/spec/ruby/library/socket/addrinfo/marshal_load_spec.rb @@ -18,18 +18,16 @@ describe 'Addrinfo#marshal_load' do end end - with_feature :unix_socket do - describe 'using a UNIX socket' do - it 'returns a new Addrinfo' do - source = Addrinfo.unix('foo') - addr = Marshal.load(Marshal.dump(source)) + describe 'using a UNIX socket' do + it 'returns a new Addrinfo' do + source = Addrinfo.unix('foo') + addr = Marshal.load(Marshal.dump(source)) - addr.afamily.should == source.afamily - addr.pfamily.should == source.pfamily - addr.socktype.should == source.socktype - addr.protocol.should == source.protocol - addr.unix_path.should == source.unix_path - end + addr.afamily.should == source.afamily + addr.pfamily.should == source.pfamily + addr.socktype.should == source.socktype + addr.protocol.should == source.protocol + addr.unix_path.should == source.unix_path end end end diff --git a/spec/ruby/library/socket/addrinfo/pfamily_spec.rb b/spec/ruby/library/socket/addrinfo/pfamily_spec.rb index 984744a964..da530b7fdc 100644 --- a/spec/ruby/library/socket/addrinfo/pfamily_spec.rb +++ b/spec/ruby/library/socket/addrinfo/pfamily_spec.rb @@ -29,15 +29,13 @@ describe "Addrinfo#pfamily" do end end - with_feature :unix_socket do - describe "for a unix socket" do - before :each do - @addrinfo = Addrinfo.unix("/tmp/sock") - end - - it "returns Socket::PF_UNIX" do - @addrinfo.pfamily.should == Socket::PF_UNIX - end + describe "for a unix socket" do + before :each do + @addrinfo = Addrinfo.unix("/tmp/sock") + end + + it "returns Socket::PF_UNIX" do + @addrinfo.pfamily.should == Socket::PF_UNIX end end end diff --git a/spec/ruby/library/socket/addrinfo/protocol_spec.rb b/spec/ruby/library/socket/addrinfo/protocol_spec.rb index ea143fc4a8..f6ffc9acf9 100644 --- a/spec/ruby/library/socket/addrinfo/protocol_spec.rb +++ b/spec/ruby/library/socket/addrinfo/protocol_spec.rb @@ -10,15 +10,13 @@ describe "Addrinfo#protocol" do Addrinfo.tcp('::1', 80).protocol.should == Socket::IPPROTO_TCP end - with_feature :unix_socket do - describe "for a unix socket" do - before :each do - @addrinfo = Addrinfo.unix("/tmp/sock") - end + describe "for a unix socket" do + before :each do + @addrinfo = Addrinfo.unix("/tmp/sock") + end - it "returns 0" do - @addrinfo.protocol.should == 0 - end + it "returns 0" do + @addrinfo.protocol.should == 0 end end end diff --git a/spec/ruby/library/socket/addrinfo/shared/to_sockaddr.rb b/spec/ruby/library/socket/addrinfo/shared/to_sockaddr.rb index c32da5986d..70d6bfbbfe 100644 --- a/spec/ruby/library/socket/addrinfo/shared/to_sockaddr.rb +++ b/spec/ruby/library/socket/addrinfo/shared/to_sockaddr.rb @@ -1,5 +1,4 @@ -describe :socket_addrinfo_to_sockaddr, :shared => true do - +describe :socket_addrinfo_to_sockaddr, shared: true do describe "for an ipv4 socket" do before :each do @addrinfo = Addrinfo.tcp("127.0.0.1", 80) @@ -20,15 +19,13 @@ describe :socket_addrinfo_to_sockaddr, :shared => true do end end - with_feature :unix_socket do - describe "for a unix socket" do - before :each do - @addrinfo = Addrinfo.unix("/tmp/sock") - end + describe "for a unix socket" do + before :each do + @addrinfo = Addrinfo.unix("/tmp/sock") + end - it "returns a sockaddr packed structure" do - @addrinfo.send(@method).should == Socket.sockaddr_un('/tmp/sock') - end + it "returns a sockaddr packed structure" do + @addrinfo.send(@method).should == Socket.sockaddr_un('/tmp/sock') end end @@ -47,5 +44,4 @@ describe :socket_addrinfo_to_sockaddr, :shared => true do addr.send(@method).should == Socket.sockaddr_in(0, '') end end - end diff --git a/spec/ruby/library/socket/addrinfo/socktype_spec.rb b/spec/ruby/library/socket/addrinfo/socktype_spec.rb index b994bea140..e5f02cd759 100644 --- a/spec/ruby/library/socket/addrinfo/socktype_spec.rb +++ b/spec/ruby/library/socket/addrinfo/socktype_spec.rb @@ -9,15 +9,13 @@ describe "Addrinfo#socktype" do Addrinfo.tcp('127.0.0.1', 80).socktype.should == Socket::SOCK_STREAM end - with_feature :unix_socket do - describe "for a unix socket" do - before :each do - @addrinfo = Addrinfo.unix("/tmp/sock") - end + describe "for a unix socket" do + before :each do + @addrinfo = Addrinfo.unix("/tmp/sock") + end - it "returns Socket::SOCK_STREAM" do - @addrinfo.socktype.should == Socket::SOCK_STREAM - end + it "returns Socket::SOCK_STREAM" do + @addrinfo.socktype.should == Socket::SOCK_STREAM end end end diff --git a/spec/ruby/library/socket/addrinfo/udp_spec.rb b/spec/ruby/library/socket/addrinfo/udp_spec.rb index b05cbf9b0b..ac02e76ef5 100644 --- a/spec/ruby/library/socket/addrinfo/udp_spec.rb +++ b/spec/ruby/library/socket/addrinfo/udp_spec.rb @@ -27,10 +27,8 @@ describe 'Addrinfo.udp' do Addrinfo.udp(ip_address, 80).socktype.should == Socket::SOCK_DGRAM end - platform_is_not :solaris do - it 'sets the socket protocol' do - Addrinfo.udp(ip_address, 80).protocol.should == Socket::IPPROTO_UDP - end + it 'sets the socket protocol' do + Addrinfo.udp(ip_address, 80).protocol.should == Socket::IPPROTO_UDP end end end diff --git a/spec/ruby/library/socket/addrinfo/unix_path_spec.rb b/spec/ruby/library/socket/addrinfo/unix_path_spec.rb index 6bfb56a4ac..2a9076a354 100644 --- a/spec/ruby/library/socket/addrinfo/unix_path_spec.rb +++ b/spec/ruby/library/socket/addrinfo/unix_path_spec.rb @@ -1,37 +1,35 @@ require_relative '../spec_helper' -with_feature :unix_socket do - describe "Addrinfo#unix_path" do - describe "for an ipv4 socket" do +describe "Addrinfo#unix_path" do + describe "for an ipv4 socket" do - before :each do - @addrinfo = Addrinfo.tcp("127.0.0.1", 80) - end - - it "raises an exception" do - -> { @addrinfo.unix_path }.should raise_error(SocketError) - end + before :each do + @addrinfo = Addrinfo.tcp("127.0.0.1", 80) + end + it "raises an exception" do + -> { @addrinfo.unix_path }.should raise_error(SocketError) end - describe "for an ipv6 socket" do - before :each do - @addrinfo = Addrinfo.tcp("::1", 80) - end + end - it "raises an exception" do - -> { @addrinfo.unix_path }.should raise_error(SocketError) - end + describe "for an ipv6 socket" do + before :each do + @addrinfo = Addrinfo.tcp("::1", 80) end - describe "for a unix socket" do - before :each do - @addrinfo = Addrinfo.unix("/tmp/sock") - end + it "raises an exception" do + -> { @addrinfo.unix_path }.should raise_error(SocketError) + end + end + + describe "for a unix socket" do + before :each do + @addrinfo = Addrinfo.unix("/tmp/sock") + end - it "returns the socket path" do - @addrinfo.unix_path.should == "/tmp/sock" - end + it "returns the socket path" do + @addrinfo.unix_path.should == "/tmp/sock" end end end diff --git a/spec/ruby/library/socket/addrinfo/unix_spec.rb b/spec/ruby/library/socket/addrinfo/unix_spec.rb index 4596ece17e..7597533a76 100644 --- a/spec/ruby/library/socket/addrinfo/unix_spec.rb +++ b/spec/ruby/library/socket/addrinfo/unix_spec.rb @@ -1,36 +1,34 @@ require_relative '../spec_helper' -with_feature :unix_socket do - describe 'Addrinfo.unix' do - it 'returns an Addrinfo instance' do - Addrinfo.unix('socket').should be_an_instance_of(Addrinfo) - end +describe 'Addrinfo.unix' do + it 'returns an Addrinfo instance' do + Addrinfo.unix('socket').should be_an_instance_of(Addrinfo) + end - it 'sets the IP address' do - Addrinfo.unix('socket').unix_path.should == 'socket' - end + it 'sets the IP address' do + Addrinfo.unix('socket').unix_path.should == 'socket' + end - it 'sets the address family' do - Addrinfo.unix('socket').afamily.should == Socket::AF_UNIX - end + it 'sets the address family' do + Addrinfo.unix('socket').afamily.should == Socket::AF_UNIX + end - it 'sets the protocol family' do - Addrinfo.unix('socket').pfamily.should == Socket::PF_UNIX - end + it 'sets the protocol family' do + Addrinfo.unix('socket').pfamily.should == Socket::PF_UNIX + end - it 'sets the socket type' do - Addrinfo.unix('socket').socktype.should == Socket::SOCK_STREAM - end + it 'sets the socket type' do + Addrinfo.unix('socket').socktype.should == Socket::SOCK_STREAM + end - it 'sets a custom socket type' do - addr = Addrinfo.unix('socket', Socket::SOCK_DGRAM) + it 'sets a custom socket type' do + addr = Addrinfo.unix('socket', Socket::SOCK_DGRAM) - addr.socktype.should == Socket::SOCK_DGRAM - end + addr.socktype.should == Socket::SOCK_DGRAM + end - it 'sets the socket protocol to 0' do - Addrinfo.unix('socket').protocol.should == 0 - end + it 'sets the socket protocol to 0' do + Addrinfo.unix('socket').protocol.should == 0 end end diff --git a/spec/ruby/library/socket/ancillarydata/initialize_spec.rb b/spec/ruby/library/socket/ancillarydata/initialize_spec.rb index 344d1485c5..eca45599d7 100644 --- a/spec/ruby/library/socket/ancillarydata/initialize_spec.rb +++ b/spec/ruby/library/socket/ancillarydata/initialize_spec.rb @@ -106,7 +106,7 @@ with_feature :ancillary_data do Socket::AncillaryData.new(:INET, :SOCKET, :RIGHTS, '').type.should == Socket::SCM_RIGHTS end - platform_is_not :"solaris2.10", :aix do + platform_is_not :aix do it 'sets the type to SCM_TIMESTAMP when using :TIMESTAMP as the type argument' do Socket::AncillaryData.new(:INET, :SOCKET, :TIMESTAMP, '').type.should == Socket::SCM_TIMESTAMP end diff --git a/spec/ruby/library/socket/ancillarydata/unix_rights_spec.rb b/spec/ruby/library/socket/ancillarydata/unix_rights_spec.rb index 65ffcb01af..95052fd91c 100644 --- a/spec/ruby/library/socket/ancillarydata/unix_rights_spec.rb +++ b/spec/ruby/library/socket/ancillarydata/unix_rights_spec.rb @@ -50,7 +50,7 @@ with_feature :ancillary_data do -> { data.unix_rights }.should raise_error(TypeError) end - platform_is_not :"solaris2.10", :aix do + platform_is_not :aix do it 'raises TypeError when the type is not SCM_RIGHTS' do data = Socket::AncillaryData.new(:INET, :SOCKET, :TIMESTAMP, '') diff --git a/spec/ruby/library/socket/basicsocket/connect_address_spec.rb b/spec/ruby/library/socket/basicsocket/connect_address_spec.rb index 1a1c9982d9..2e318fcb85 100644 --- a/spec/ruby/library/socket/basicsocket/connect_address_spec.rb +++ b/spec/ruby/library/socket/basicsocket/connect_address_spec.rb @@ -94,61 +94,59 @@ describe 'Socket#connect_address' do end end - with_feature :unix_socket do - platform_is_not :aix do - describe 'using an unbound UNIX socket' do - before do - @path = SocketSpecs.socket_path - @server = UNIXServer.new(@path) - @client = UNIXSocket.new(@path) - end - - after do - @client.close - @server.close - rm_r(@path) - end - - it 'raises SocketError' do - -> { @client.connect_address }.should raise_error(SocketError) - end - end - end - - describe 'using a bound UNIX socket' do + platform_is_not :aix do + describe 'using an unbound UNIX socket' do before do @path = SocketSpecs.socket_path - @sock = UNIXServer.new(@path) + @server = UNIXServer.new(@path) + @client = UNIXSocket.new(@path) end after do - @sock.close + @client.close + @server.close rm_r(@path) end - it 'returns an Addrinfo' do - @sock.connect_address.should be_an_instance_of(Addrinfo) + it 'raises SocketError' do + -> { @client.connect_address }.should raise_error(SocketError) end + end + end - it 'uses the correct socket path' do - @sock.connect_address.unix_path.should == @path - end + describe 'using a bound UNIX socket' do + before do + @path = SocketSpecs.socket_path + @sock = UNIXServer.new(@path) + end - it 'uses AF_UNIX as the address family' do - @sock.connect_address.afamily.should == Socket::AF_UNIX - end + after do + @sock.close + rm_r(@path) + end - it 'uses PF_UNIX as the protocol family' do - @sock.connect_address.pfamily.should == Socket::PF_UNIX - end + it 'returns an Addrinfo' do + @sock.connect_address.should be_an_instance_of(Addrinfo) + end - it 'uses SOCK_STREAM as the socket type' do - @sock.connect_address.socktype.should == Socket::SOCK_STREAM - end + it 'uses the correct socket path' do + @sock.connect_address.unix_path.should == @path + end - it 'uses 0 as the protocol' do - @sock.connect_address.protocol.should == 0 - end + it 'uses AF_UNIX as the address family' do + @sock.connect_address.afamily.should == Socket::AF_UNIX + end + + it 'uses PF_UNIX as the protocol family' do + @sock.connect_address.pfamily.should == Socket::PF_UNIX + end + + it 'uses SOCK_STREAM as the socket type' do + @sock.connect_address.socktype.should == Socket::SOCK_STREAM + end + + it 'uses 0 as the protocol' do + @sock.connect_address.protocol.should == 0 end end end diff --git a/spec/ruby/library/socket/basicsocket/getpeereid_spec.rb b/spec/ruby/library/socket/basicsocket/getpeereid_spec.rb index 6179211d96..2e03cd3684 100644 --- a/spec/ruby/library/socket/basicsocket/getpeereid_spec.rb +++ b/spec/ruby/library/socket/basicsocket/getpeereid_spec.rb @@ -2,7 +2,7 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' describe 'BasicSocket#getpeereid' do - with_feature :unix_socket do + platform_is_not :windows do describe 'using a UNIXSocket' do before do @path = SocketSpecs.socket_path diff --git a/spec/ruby/library/socket/basicsocket/read_nonblock_spec.rb b/spec/ruby/library/socket/basicsocket/read_nonblock_spec.rb index df44a50afa..ea5e65da5c 100644 --- a/spec/ruby/library/socket/basicsocket/read_nonblock_spec.rb +++ b/spec/ruby/library/socket/basicsocket/read_nonblock_spec.rb @@ -18,7 +18,37 @@ describe "BasicSocket#read_nonblock" do it "receives data after it's ready" do IO.select([@r], nil, nil, 2) - @r.recv_nonblock(5).should == "aaa" + @r.read_nonblock(5).should == "aaa" + end + + platform_is_not :windows do + it 'returned data is binary encoded regardless of the external encoding' do + IO.select([@r], nil, nil, 2) + @r.read_nonblock(1).encoding.should == Encoding::BINARY + + @w.send("bbb", 0, @r.getsockname) + @r.set_encoding(Encoding::ISO_8859_1) + IO.select([@r], nil, nil, 2) + buffer = @r.read_nonblock(3) + buffer.should == "bbb" + buffer.encoding.should == Encoding::BINARY + end + end + + it 'replaces the content of the provided buffer without changing its encoding' do + buffer = "initial data".dup.force_encoding(Encoding::UTF_8) + + IO.select([@r], nil, nil, 2) + @r.read_nonblock(3, buffer) + buffer.should == "aaa" + buffer.encoding.should == Encoding::UTF_8 + + @w.send("bbb", 0, @r.getsockname) + @r.set_encoding(Encoding::ISO_8859_1) + IO.select([@r], nil, nil, 2) + @r.read_nonblock(3, buffer) + buffer.should == "bbb" + buffer.encoding.should == Encoding::UTF_8 end platform_is :linux do diff --git a/spec/ruby/library/socket/basicsocket/read_spec.rb b/spec/ruby/library/socket/basicsocket/read_spec.rb new file mode 100644 index 0000000000..ba9de7d5cf --- /dev/null +++ b/spec/ruby/library/socket/basicsocket/read_spec.rb @@ -0,0 +1,47 @@ +require_relative '../spec_helper' +require_relative '../fixtures/classes' + +describe "BasicSocket#read" do + SocketSpecs.each_ip_protocol do |family, ip_address| + before :each do + @r = Socket.new(family, :DGRAM) + @w = Socket.new(family, :DGRAM) + + @r.bind(Socket.pack_sockaddr_in(0, ip_address)) + @w.send("aaa", 0, @r.getsockname) + end + + after :each do + @r.close unless @r.closed? + @w.close unless @w.closed? + end + + it "receives data after it's ready" do + @r.read(3).should == "aaa" + end + + it 'returned data is binary encoded regardless of the external encoding' do + @r.read(3).encoding.should == Encoding::BINARY + + @w.send("bbb", 0, @r.getsockname) + @r.set_encoding(Encoding::UTF_8) + buffer = @r.read(3) + buffer.should == "bbb" + buffer.encoding.should == Encoding::BINARY + end + + it 'replaces the content of the provided buffer without changing its encoding' do + buffer = "initial data".dup.force_encoding(Encoding::UTF_8) + + @r.read(3, buffer) + buffer.should == "aaa" + buffer.encoding.should == Encoding::UTF_8 + + @w.send("bbb", 0, @r.getsockname) + @r.set_encoding(Encoding::ISO_8859_1) + @r.read(3, buffer) + buffer.should == "bbb" + buffer.encoding.should == Encoding::UTF_8 + end + end +end diff --git a/spec/ruby/library/socket/basicsocket/recv_nonblock_spec.rb b/spec/ruby/library/socket/basicsocket/recv_nonblock_spec.rb index b6ab8a9cea..f2a6682f12 100644 --- a/spec/ruby/library/socket/basicsocket/recv_nonblock_spec.rb +++ b/spec/ruby/library/socket/basicsocket/recv_nonblock_spec.rb @@ -52,9 +52,19 @@ describe "Socket::BasicSocket#recv_nonblock" do @s2.send("data", 0, @s1.getsockname) IO.select([@s1], nil, nil, 2) - buf = "foo" - @s1.recv_nonblock(5, 0, buf) - buf.should == "data" + buffer = +"foo" + @s1.recv_nonblock(5, 0, buffer).should.equal?(buffer) + buffer.should == "data" + end + + it "preserves the encoding of the given buffer" do + @s1.bind(Socket.pack_sockaddr_in(0, ip_address)) + @s2.send("data", 0, @s1.getsockname) + IO.select([@s1], nil, nil, 2) + + buffer = ''.encode(Encoding::ISO_8859_1) + @s1.recv_nonblock(5, 0, buffer) + buffer.encoding.should == Encoding::ISO_8859_1 end it "does not block if there's no data available" do @@ -89,3 +99,74 @@ describe "Socket::BasicSocket#recv_nonblock" do end end end + +describe "Socket::BasicSocket#recv_nonblock" do + context "when recvfrom(2) returns 0 (if no messages are available to be received and the peer has performed an orderly shutdown)" do + describe "stream socket" do + before :each do + @server = TCPServer.new('127.0.0.1', 0) + @port = @server.addr[1] + end + + after :each do + @server.close unless @server.closed? + end + + ruby_version_is ""..."3.3" do + it "returns an empty String on a closed stream socket" do + ready = false + + t = Thread.new do + client = @server.accept + + Thread.pass while !ready + begin + client.recv_nonblock(10) + rescue IO::EAGAINWaitReadable + retry + end + ensure + client.close if client + end + + Thread.pass while t.status and t.status != "sleep" + t.status.should_not be_nil + + socket = TCPSocket.new('127.0.0.1', @port) + socket.close + ready = true + + t.value.should == "" + end + end + + ruby_version_is "3.3" do + it "returns nil on a closed stream socket" do + ready = false + + t = Thread.new do + client = @server.accept + + Thread.pass while !ready + begin + client.recv_nonblock(10) + rescue IO::EAGAINWaitReadable + retry + end + ensure + client.close if client + end + + Thread.pass while t.status and t.status != "sleep" + t.status.should_not be_nil + + socket = TCPSocket.new('127.0.0.1', @port) + socket.close + ready = true + + t.value.should be_nil + end + end + end + end +end diff --git a/spec/ruby/library/socket/basicsocket/recv_spec.rb b/spec/ruby/library/socket/basicsocket/recv_spec.rb index b6ccda5d00..a51920f52a 100644 --- a/spec/ruby/library/socket/basicsocket/recv_spec.rb +++ b/spec/ruby/library/socket/basicsocket/recv_spec.rb @@ -1,4 +1,4 @@ -# -*- encoding: binary -*- +# encoding: binary require_relative '../spec_helper' require_relative '../fixtures/classes' @@ -32,28 +32,26 @@ describe "BasicSocket#recv" do ScratchPad.recorded.should == 'hello' end - platform_is_not :solaris do - it "accepts flags to specify unusual receiving behaviour" do - t = Thread.new do - client = @server.accept + it "accepts flags to specify unusual receiving behaviour" do + t = Thread.new do + client = @server.accept - # in-band data (TCP), doesn't receive the flag. - ScratchPad.record client.recv(10) + # in-band data (TCP), doesn't receive the flag. + ScratchPad.record client.recv(10) - # this recv is important (TODO: explain) - client.recv(10) - client.close - end - Thread.pass while t.status and t.status != "sleep" - t.status.should_not be_nil - - socket = TCPSocket.new('127.0.0.1', @port) - socket.send('helloU', Socket::MSG_OOB) - socket.shutdown(1) - t.join - socket.close - ScratchPad.recorded.should == 'hello' + # this recv is important (TODO: explain) + client.recv(10) + client.close end + Thread.pass while t.status and t.status != "sleep" + t.status.should_not be_nil + + socket = TCPSocket.new('127.0.0.1', @port) + socket.send('helloU', Socket::MSG_OOB) + socket.shutdown(1) + t.join + socket.close + ScratchPad.recorded.should == 'hello' end it "gets lines delimited with a custom separator" do @@ -81,13 +79,29 @@ describe "BasicSocket#recv" do socket.write("data") client = @server.accept - buf = "foo" + buffer = +"foo" begin - client.recv(4, 0, buf) + client.recv(4, 0, buffer).should.equal?(buffer) ensure client.close end - buf.should == "data" + buffer.should == "data" + + socket.close + end + + it "preserves the encoding of the given buffer" do + socket = TCPSocket.new('127.0.0.1', @port) + socket.write("data") + + client = @server.accept + buffer = ''.encode(Encoding::ISO_8859_1) + begin + client.recv(4, 0, buffer) + ensure + client.close + end + buffer.encoding.should == Encoding::ISO_8859_1 socket.close end @@ -157,3 +171,80 @@ describe 'BasicSocket#recv' do end end end + +describe "BasicSocket#recv" do + context "when recvfrom(2) returns 0 (if no messages are available to be received and the peer has performed an orderly shutdown)" do + describe "stream socket" do + before :each do + @server = TCPServer.new('127.0.0.1', 0) + @port = @server.addr[1] + end + + after :each do + @server.close unless @server.closed? + end + + ruby_version_is ""..."3.3" do + it "returns an empty String on a closed stream socket" do + t = Thread.new do + client = @server.accept + client.recv(10) + ensure + client.close if client + end + + Thread.pass while t.status and t.status != "sleep" + t.status.should_not be_nil + + socket = TCPSocket.new('127.0.0.1', @port) + socket.close + + t.value.should == "" + end + end + + ruby_version_is "3.3" do + it "returns nil on a closed stream socket" do + t = Thread.new do + client = @server.accept + client.recv(10) + ensure + client.close if client + end + + Thread.pass while t.status and t.status != "sleep" + t.status.should_not be_nil + + socket = TCPSocket.new('127.0.0.1', @port) + socket.close + + t.value.should be_nil + end + end + end + + describe "datagram socket" do + SocketSpecs.each_ip_protocol do |family, ip_address| + before :each do + @server = UDPSocket.new(family) + @client = UDPSocket.new(family) + end + + after :each do + @server.close unless @server.closed? + @client.close unless @client.closed? + end + + it "returns empty String" do + @server.bind(ip_address, 0) + addr = @server.connect_address + @client.connect(addr.ip_address, addr.ip_port) + + @client.send('', 0) + + @server.recv(1).should == "" + end + end + end + end +end diff --git a/spec/ruby/library/socket/basicsocket/recvmsg_nonblock_spec.rb b/spec/ruby/library/socket/basicsocket/recvmsg_nonblock_spec.rb index cc4275c417..b5fdd7c93b 100644 --- a/spec/ruby/library/socket/basicsocket/recvmsg_nonblock_spec.rb +++ b/spec/ruby/library/socket/basicsocket/recvmsg_nonblock_spec.rb @@ -222,3 +222,79 @@ describe 'BasicSocket#recvmsg_nonblock' do end end end + +describe 'BasicSocket#recvmsg_nonblock' do + context "when recvfrom(2) returns 0 (if no messages are available to be received and the peer has performed an orderly shutdown)" do + describe "stream socket" do + before :each do + @server = TCPServer.new('127.0.0.1', 0) + @port = @server.addr[1] + end + + after :each do + @server.close unless @server.closed? + end + + ruby_version_is ""..."3.3" do + platform_is_not :windows do # #recvmsg_nonblock() raises 'Errno::EINVAL: Invalid argument - recvmsg(2)' + it "returns an empty String as received data on a closed stream socket" do + ready = false + + t = Thread.new do + client = @server.accept + + Thread.pass while !ready + begin + client.recvmsg_nonblock(10) + rescue IO::EAGAINWaitReadable + retry + end + ensure + client.close if client + end + + Thread.pass while t.status and t.status != "sleep" + t.status.should_not be_nil + + socket = TCPSocket.new('127.0.0.1', @port) + socket.close + ready = true + + t.value.should.is_a? Array + t.value[0].should == "" + end + end + end + + ruby_version_is "3.3" do + platform_is_not :windows do + it "returns nil on a closed stream socket" do + ready = false + + t = Thread.new do + client = @server.accept + + Thread.pass while !ready + begin + client.recvmsg_nonblock(10) + rescue IO::EAGAINWaitReadable + retry + end + ensure + client.close if client + end + + Thread.pass while t.status and t.status != "sleep" + t.status.should_not be_nil + + socket = TCPSocket.new('127.0.0.1', @port) + socket.close + ready = true + + t.value.should be_nil + end + end + end + end + end +end diff --git a/spec/ruby/library/socket/basicsocket/recvmsg_spec.rb b/spec/ruby/library/socket/basicsocket/recvmsg_spec.rb index 8063723701..04ba1d74c7 100644 --- a/spec/ruby/library/socket/basicsocket/recvmsg_spec.rb +++ b/spec/ruby/library/socket/basicsocket/recvmsg_spec.rb @@ -195,3 +195,87 @@ describe 'BasicSocket#recvmsg' do end end end + +describe 'BasicSocket#recvmsg' do + context "when recvfrom(2) returns 0 (if no messages are available to be received and the peer has performed an orderly shutdown)" do + describe "stream socket" do + before :each do + @server = TCPServer.new('127.0.0.1', 0) + @port = @server.addr[1] + end + + after :each do + @server.close unless @server.closed? + end + + ruby_version_is ""..."3.3" do + platform_is_not :windows do + it "returns an empty String as received data on a closed stream socket" do + t = Thread.new do + client = @server.accept + client.recvmsg(10) + ensure + client.close if client + end + + Thread.pass while t.status and t.status != "sleep" + t.status.should_not be_nil + + socket = TCPSocket.new('127.0.0.1', @port) + socket.close + + t.value.should.is_a? Array + t.value[0].should == "" + end + end + end + + ruby_version_is "3.3" do + platform_is_not :windows do + it "returns nil on a closed stream socket" do + t = Thread.new do + client = @server.accept + client.recvmsg(10) + ensure + client.close if client + end + + Thread.pass while t.status and t.status != "sleep" + t.status.should_not be_nil + + socket = TCPSocket.new('127.0.0.1', @port) + socket.close + + t.value.should be_nil + end + end + end + end + + describe "datagram socket" do + SocketSpecs.each_ip_protocol do |family, ip_address| + before :each do + @server = UDPSocket.new(family) + @client = UDPSocket.new(family) + end + + after :each do + @server.close unless @server.closed? + @client.close unless @client.closed? + end + + it "returns an empty String as received data" do + @server.bind(ip_address, 0) + addr = @server.connect_address + @client.connect(addr.ip_address, addr.ip_port) + + @client.send('', 0) + message = @server.recvmsg(1) + + message.should.is_a? Array + message[0].should == "" + end + end + end + end +end diff --git a/spec/ruby/library/socket/basicsocket/send_spec.rb b/spec/ruby/library/socket/basicsocket/send_spec.rb index 868801df30..25ba3f5655 100644 --- a/spec/ruby/library/socket/basicsocket/send_spec.rb +++ b/spec/ruby/library/socket/basicsocket/send_spec.rb @@ -16,29 +16,29 @@ describe "BasicSocket#send" do @socket.close end - it "sends a message to another socket and returns the number of bytes sent" do - data = "" - t = Thread.new do - client = @server.accept - loop do - got = client.recv(5) - break if got.empty? - data << got - end - client.close - end - Thread.pass while t.status and t.status != "sleep" - t.status.should_not be_nil - - @socket.send('hello', 0).should == 5 - @socket.shutdown(1) # indicate, that we are done sending - @socket.recv(10) - - t.join - data.should == 'hello' - end - - platform_is_not :solaris, :windows do + it "sends a message to another socket and returns the number of bytes sent" do + data = +"" + t = Thread.new do + client = @server.accept + loop do + got = client.recv(5) + break if got.nil? || got.empty? + data << got + end + client.close + end + Thread.pass while t.status and t.status != "sleep" + t.status.should_not be_nil + + @socket.send('hello', 0).should == 5 + @socket.shutdown(1) # indicate, that we are done sending + @socket.recv(10) + + t.join + data.should == 'hello' + end + + platform_is_not :windows do it "accepts flags to specify unusual sending behaviour" do data = nil peek_data = nil @@ -62,25 +62,25 @@ describe "BasicSocket#send" do end it "accepts a sockaddr as recipient address" do - data = "" - t = Thread.new do - client = @server.accept - loop do - got = client.recv(5) - break if got.empty? - data << got - end - client.close - end - Thread.pass while t.status and t.status != "sleep" - t.status.should_not be_nil - - sockaddr = Socket.pack_sockaddr_in(@port, "127.0.0.1") - @socket.send('hello', 0, sockaddr).should == 5 - @socket.shutdown # indicate, that we are done sending - - t.join - data.should == 'hello' + data = +"" + t = Thread.new do + client = @server.accept + loop do + got = client.recv(5) + break if got.nil? || got.empty? + data << got + end + client.close + end + Thread.pass while t.status and t.status != "sleep" + t.status.should_not be_nil + + sockaddr = Socket.pack_sockaddr_in(@port, "127.0.0.1") + @socket.send('hello', 0, sockaddr).should == 5 + @socket.shutdown # indicate, that we are done sending + + t.join + data.should == 'hello' end end diff --git a/spec/ruby/library/socket/basicsocket/setsockopt_spec.rb b/spec/ruby/library/socket/basicsocket/setsockopt_spec.rb index 1e8d84e1c9..f686e67326 100644 --- a/spec/ruby/library/socket/basicsocket/setsockopt_spec.rb +++ b/spec/ruby/library/socket/basicsocket/setsockopt_spec.rb @@ -315,22 +315,20 @@ describe 'BasicSocket#setsockopt' do end end - with_feature :unix_socket do - describe 'using a UNIX socket' do - before do - @path = SocketSpecs.socket_path - @server = UNIXServer.new(@path) - end + describe 'using a UNIX socket' do + before do + @path = SocketSpecs.socket_path + @server = UNIXServer.new(@path) + end - after do - @server.close - rm_r @path - end + after do + @server.close + rm_r @path + end - it 'sets a boolean option' do - @server.setsockopt(:SOCKET, :REUSEADDR, true) - @server.getsockopt(:SOCKET, :REUSEADDR).bool.should == true - end + it 'sets a boolean option' do + @server.setsockopt(:SOCKET, :REUSEADDR, true) + @server.getsockopt(:SOCKET, :REUSEADDR).bool.should == true end end end diff --git a/spec/ruby/library/socket/basicsocket/shutdown_spec.rb b/spec/ruby/library/socket/basicsocket/shutdown_spec.rb index 41d9581bde..c78b32de38 100644 --- a/spec/ruby/library/socket/basicsocket/shutdown_spec.rb +++ b/spec/ruby/library/socket/basicsocket/shutdown_spec.rb @@ -23,7 +23,7 @@ platform_is_not :windows do # hangs it 'shuts down a socket for reading' do @client.shutdown(Socket::SHUT_RD) - @client.recv(1).should be_empty + @client.recv(1).to_s.should be_empty end it 'shuts down a socket for writing' do @@ -35,7 +35,7 @@ platform_is_not :windows do # hangs it 'shuts down a socket for reading and writing' do @client.shutdown(Socket::SHUT_RDWR) - @client.recv(1).should be_empty + @client.recv(1).to_s.should be_empty -> { @client.write('hello') }.should raise_error(Errno::EPIPE) end @@ -49,13 +49,13 @@ platform_is_not :windows do # hangs it 'shuts down a socket for reading using :RD' do @client.shutdown(:RD) - @client.recv(1).should be_empty + @client.recv(1).to_s.should be_empty end it 'shuts down a socket for reading using :SHUT_RD' do @client.shutdown(:SHUT_RD) - @client.recv(1).should be_empty + @client.recv(1).to_s.should be_empty end it 'shuts down a socket for writing using :WR' do @@ -73,7 +73,7 @@ platform_is_not :windows do # hangs it 'shuts down a socket for reading and writing' do @client.shutdown(:RDWR) - @client.recv(1).should be_empty + @client.recv(1).to_s.should be_empty -> { @client.write('hello') }.should raise_error(Errno::EPIPE) end @@ -87,13 +87,13 @@ platform_is_not :windows do # hangs it 'shuts down a socket for reading using "RD"' do @client.shutdown('RD') - @client.recv(1).should be_empty + @client.recv(1).to_s.should be_empty end it 'shuts down a socket for reading using "SHUT_RD"' do @client.shutdown('SHUT_RD') - @client.recv(1).should be_empty + @client.recv(1).to_s.should be_empty end it 'shuts down a socket for writing using "WR"' do @@ -123,7 +123,7 @@ platform_is_not :windows do # hangs @client.shutdown(@dummy) - @client.recv(1).should be_empty + @client.recv(1).to_s.should be_empty end it 'shuts down a socket for reading using "SHUT_RD"' do @@ -131,7 +131,7 @@ platform_is_not :windows do # hangs @client.shutdown(@dummy) - @client.recv(1).should be_empty + @client.recv(1).to_s.should be_empty end it 'shuts down a socket for reading and writing' do @@ -139,7 +139,7 @@ platform_is_not :windows do # hangs @client.shutdown(@dummy) - @client.recv(1).should be_empty + @client.recv(1).to_s.should be_empty -> { @client.write('hello') }.should raise_error(Errno::EPIPE) end diff --git a/spec/ruby/library/socket/constants/constants_spec.rb b/spec/ruby/library/socket/constants/constants_spec.rb index 637bc6740a..b9a9d42725 100644 --- a/spec/ruby/library/socket/constants/constants_spec.rb +++ b/spec/ruby/library/socket/constants/constants_spec.rb @@ -68,7 +68,7 @@ describe "Socket::Constants" do end end - platform_is_not :solaris, :windows, :aix, :android do + platform_is_not :windows, :aix, :android do it "defines multicast options" do consts = ["IP_MAX_MEMBERSHIPS"] consts.each do |c| diff --git a/spec/ruby/library/socket/fixtures/classes.rb b/spec/ruby/library/socket/fixtures/classes.rb index 4a590502ca..786629d2ef 100644 --- a/spec/ruby/library/socket/fixtures/classes.rb +++ b/spec/ruby/library/socket/fixtures/classes.rb @@ -37,7 +37,9 @@ module SocketSpecs # Check for too long unix socket path (max 104 bytes on macOS) # Note that Linux accepts not null-terminated paths but the man page advises against it. if path.bytesize > 104 - path = "/tmp/unix_server_spec.socket" + # rm_r in spec/mspec/lib/mspec/helpers/fs.rb fails against + # "/tmp/unix_server_spec.socket" + skip "too long unix socket path: #{path}" end rm_socket(path) path @@ -111,7 +113,7 @@ module SocketSpecs begin data = socket.recv(1024) - return if data.empty? + return if data.nil? || data.empty? log "SpecTCPServer received: #{data.inspect}" return if data == "QUIT" diff --git a/spec/ruby/library/socket/ipsocket/getaddress_spec.rb b/spec/ruby/library/socket/ipsocket/getaddress_spec.rb index 746d2ab86b..329f8267d3 100644 --- a/spec/ruby/library/socket/ipsocket/getaddress_spec.rb +++ b/spec/ruby/library/socket/ipsocket/getaddress_spec.rb @@ -2,7 +2,6 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' describe "Socket::IPSocket#getaddress" do - it "returns the IP address of hostname" do addr_local = IPSocket.getaddress(SocketSpecs.hostname) ["127.0.0.1", "::1"].include?(addr_local).should == true @@ -14,12 +13,16 @@ describe "Socket::IPSocket#getaddress" do IPSocket.getaddress('::1').should == '::1' end + it 'returns IPv4 compatible IPv6 addresses' do + IPSocket.getaddress('::ffff:192.168.1.1').should == '::ffff:192.168.1.1' + end + # There is no way to make this fail-proof on all machines, because # DNS servers like opendns return A records for ANY host, including # traditionally invalidly named ones. it "raises an error on unknown hostnames" do -> { - IPSocket.getaddress("rubyspecdoesntexist.fallingsnow.net") + IPSocket.getaddress("rubyspecdoesntexist.ruby-lang.org") }.should raise_error(SocketError) end end diff --git a/spec/ruby/library/socket/ipsocket/recvfrom_spec.rb b/spec/ruby/library/socket/ipsocket/recvfrom_spec.rb index 2af86ea70d..b58903df23 100644 --- a/spec/ruby/library/socket/ipsocket/recvfrom_spec.rb +++ b/spec/ruby/library/socket/ipsocket/recvfrom_spec.rb @@ -69,6 +69,88 @@ describe "Socket::IPSocket#recvfrom" do end end +describe "Socket::IPSocket#recvfrom" do + context "when recvfrom(2) returns 0 (if no messages are available to be received and the peer has performed an orderly shutdown)" do + describe "stream socket" do + before :each do + @server = TCPServer.new("127.0.0.1", 0) + port = @server.addr[1] + @client = TCPSocket.new("127.0.0.1", port) + end + + after :each do + @server.close unless @server.closed? + @client.close unless @client.closed? + end + + ruby_version_is ""..."3.3" do + it "returns an empty String as received data on a closed stream socket" do + t = Thread.new do + client = @server.accept + message = client.recvfrom(10) + message + ensure + client.close if client + end + + Thread.pass while t.status and t.status != "sleep" + t.status.should_not be_nil + + @client.close + + t.value.should.is_a? Array + t.value[0].should == "" + end + end + + ruby_version_is "3.3" do + it "returns nil on a closed stream socket" do + t = Thread.new do + client = @server.accept + message = client.recvfrom(10) + message + ensure + client.close if client + end + + Thread.pass while t.status and t.status != "sleep" + t.status.should_not be_nil + + @client.close + + t.value.should be_nil + end + end + end + + describe "datagram socket" do + SocketSpecs.each_ip_protocol do |family, ip_address| + before :each do + @server = UDPSocket.new(family) + @client = UDPSocket.new(family) + end + + after :each do + @server.close unless @server.closed? + @client.close unless @client.closed? + end + + it "returns an empty String as received data" do + @server.bind(ip_address, 0) + addr = @server.connect_address + @client.connect(addr.ip_address, addr.ip_port) + + @client.send('', 0) + message = @server.recvfrom(1) + + message.should.is_a? Array + message[0].should == "" + end + end + end + end +end + describe 'Socket::IPSocket#recvfrom' do SocketSpecs.each_ip_protocol do |family, ip_address, family_name| before do diff --git a/spec/ruby/library/socket/shared/address.rb b/spec/ruby/library/socket/shared/address.rb index f3be9cfb99..49ba17c400 100644 --- a/spec/ruby/library/socket/shared/address.rb +++ b/spec/ruby/library/socket/shared/address.rb @@ -129,41 +129,51 @@ describe :socket_local_remote_address, shared: true do end end - with_feature :unix_socket do - describe 'using UNIXSocket' do - before :each do - @path = SocketSpecs.socket_path - @s = UNIXServer.new(@path) - @a = UNIXSocket.new(@path) - @b = @s.accept - @addr = @object.call(@a) - end + describe 'using UNIXSocket' do + before :each do + @path = SocketSpecs.socket_path + @s = UNIXServer.new(@path) + @a = UNIXSocket.new(@path) + @b = @s.accept + @addr = @object.call(@a) + end - after :each do - [@b, @a, @s].each(&:close) - rm_r(@path) - end + after :each do + [@b, @a, @s].each(&:close) + rm_r(@path) + end - it 'uses AF_UNIX as the address family' do - @addr.afamily.should == Socket::AF_UNIX - end + it 'uses AF_UNIX as the address family' do + @addr.afamily.should == Socket::AF_UNIX + end - it 'uses PF_UNIX as the protocol family' do - @addr.pfamily.should == Socket::PF_UNIX - end + it 'uses PF_UNIX as the protocol family' do + @addr.pfamily.should == Socket::PF_UNIX + end - it 'uses SOCK_STREAM as the socket type' do - @addr.socktype.should == Socket::SOCK_STREAM + it 'uses SOCK_STREAM as the socket type' do + @addr.socktype.should == Socket::SOCK_STREAM + end + + it 'uses the correct socket path' do + if @method == :local_address + @addr.unix_path.should == "" + else + @addr.unix_path.should == @path end + end - it 'uses the correct socket path' do + platform_is_not :windows do + it 'equals address of peer socket' do if @method == :local_address - @addr.unix_path.should == "" + @addr.to_s.should == @b.remote_address.to_s else - @addr.unix_path.should == @path + @addr.to_s.should == @b.local_address.to_s end end + end + guard -> { platform_is :windows and ruby_bug "#21702", ""..."4.2" } do it 'equals address of peer socket' do if @method == :local_address @addr.to_s.should == @b.remote_address.to_s @@ -171,23 +181,23 @@ describe :socket_local_remote_address, shared: true do @addr.to_s.should == @b.local_address.to_s end end + end - it 'returns an Addrinfo' do - @addr.should be_an_instance_of(Addrinfo) - end + it 'returns an Addrinfo' do + @addr.should be_an_instance_of(Addrinfo) + end - it 'uses 0 as the protocol' do - @addr.protocol.should == 0 - end + it 'uses 0 as the protocol' do + @addr.protocol.should == 0 + end - it 'can be used to connect to the server' do - skip if @method == :local_address - b = @addr.connect - begin - b.remote_address.to_s.should == @addr.to_s - ensure - b.close - end + it 'can be used to connect to the server' do + skip if @method == :local_address + b = @addr.connect + begin + b.remote_address.to_s.should == @addr.to_s + ensure + b.close end end end diff --git a/spec/ruby/library/socket/shared/pack_sockaddr.rb b/spec/ruby/library/socket/shared/pack_sockaddr.rb index 9f6238e7bc..4bfcf4edb9 100644 --- a/spec/ruby/library/socket/shared/pack_sockaddr.rb +++ b/spec/ruby/library/socket/shared/pack_sockaddr.rb @@ -17,13 +17,14 @@ describe :socket_pack_sockaddr_in, shared: true do sockaddr_in = Socket.public_send(@method, nil, '127.0.0.1') Socket.unpack_sockaddr_in(sockaddr_in).should == [0, '127.0.0.1'] + + sockaddr_in = Socket.public_send(@method, 80, Socket::INADDR_ANY) + Socket.unpack_sockaddr_in(sockaddr_in).should == [80, '0.0.0.0'] end - platform_is_not :solaris do - it 'resolves the service name to a port' do - sockaddr_in = Socket.public_send(@method, 'http', '127.0.0.1') - Socket.unpack_sockaddr_in(sockaddr_in).should == [80, '127.0.0.1'] - end + it 'resolves the service name to a port' do + sockaddr_in = Socket.public_send(@method, 'http', '127.0.0.1') + Socket.unpack_sockaddr_in(sockaddr_in).should == [80, '127.0.0.1'] end describe 'using an IPv4 address' do @@ -35,47 +36,32 @@ describe :socket_pack_sockaddr_in, shared: true do end end - platform_is_not :solaris do - describe 'using an IPv6 address' do - it 'returns a String of 28 bytes' do - str = Socket.public_send(@method, 80, '::1') - - str.should be_an_instance_of(String) - str.bytesize.should == 28 - end - end - end - - platform_is :solaris do - describe 'using an IPv6 address' do - it 'returns a String of 32 bytes' do - str = Socket.public_send(@method, 80, '::1') + describe 'using an IPv6 address' do + it 'returns a String of 28 bytes' do + str = Socket.public_send(@method, 80, '::1') - str.should be_an_instance_of(String) - str.bytesize.should == 32 - end + str.should be_an_instance_of(String) + str.bytesize.should == 28 end end end describe :socket_pack_sockaddr_un, shared: true do - with_feature :unix_socket do - it 'should be idempotent' do - bytes = Socket.public_send(@method, '/tmp/foo').bytes - bytes[2..9].should == [47, 116, 109, 112, 47, 102, 111, 111] - bytes[10..-1].all?(&:zero?).should == true - end + it 'should be idempotent' do + bytes = Socket.public_send(@method, '/tmp/foo').bytes + bytes[2..9].should == [47, 116, 109, 112, 47, 102, 111, 111] + bytes[10..-1].all?(&:zero?).should == true + end - it "packs and unpacks" do - sockaddr_un = Socket.public_send(@method, '/tmp/s') - Socket.unpack_sockaddr_un(sockaddr_un).should == '/tmp/s' - end + it "packs and unpacks" do + sockaddr_un = Socket.public_send(@method, '/tmp/s') + Socket.unpack_sockaddr_un(sockaddr_un).should == '/tmp/s' + end - it "handles correctly paths with multibyte chars" do - sockaddr_un = Socket.public_send(@method, '/home/вася/sock') - path = Socket.unpack_sockaddr_un(sockaddr_un).encode('UTF-8', 'UTF-8') - path.should == '/home/вася/sock' - end + it "handles correctly paths with multibyte chars" do + sockaddr_un = Socket.public_send(@method, '/home/вася/sock') + path = Socket.unpack_sockaddr_un(sockaddr_un).encode('UTF-8', 'UTF-8') + path.should == '/home/вася/sock' end platform_is :linux do @@ -96,7 +82,7 @@ describe :socket_pack_sockaddr_un, shared: true do end end - platform_is_not :windows, :aix do + platform_is_not :aix do it "raises ArgumentError for paths that are too long" do # AIX doesn't raise error long_path = 'a' * 110 diff --git a/spec/ruby/library/socket/shared/partially_closable_sockets.rb b/spec/ruby/library/socket/shared/partially_closable_sockets.rb index 1bdff08bf6..b1c2ebabe1 100644 --- a/spec/ruby/library/socket/shared/partially_closable_sockets.rb +++ b/spec/ruby/library/socket/shared/partially_closable_sockets.rb @@ -1,4 +1,4 @@ -describe "partially closable sockets", shared: true do +describe :partially_closable_sockets, shared: true do it "if the write end is closed then the other side can read past EOF without blocking" do @s1.write("foo") @s1.close_write diff --git a/spec/ruby/library/socket/socket/bind_spec.rb b/spec/ruby/library/socket/socket/bind_spec.rb index 4465a3dafa..e76336eafa 100644 --- a/spec/ruby/library/socket/socket/bind_spec.rb +++ b/spec/ruby/library/socket/socket/bind_spec.rb @@ -122,7 +122,7 @@ describe 'Socket#bind' do -> { @socket.bind(sockaddr1) }.should raise_error(Errno::EACCES) end - end + end end end diff --git a/spec/ruby/library/socket/socket/connect_nonblock_spec.rb b/spec/ruby/library/socket/socket/connect_nonblock_spec.rb index 3cf667fc4a..359b8719fb 100644 --- a/spec/ruby/library/socket/socket/connect_nonblock_spec.rb +++ b/spec/ruby/library/socket/socket/connect_nonblock_spec.rb @@ -16,42 +16,40 @@ describe "Socket#connect_nonblock" do @thread.join if @thread end - platform_is_not :solaris do - it "connects the socket to the remote side" do - port = nil - accept = false - @thread = Thread.new do - server = TCPServer.new(@hostname, 0) - port = server.addr[1] - Thread.pass until accept - conn = server.accept - conn << "hello!" - conn.close - server.close - end - - Thread.pass until port + it "connects the socket to the remote side" do + port = nil + accept = false + @thread = Thread.new do + server = TCPServer.new(@hostname, 0) + port = server.addr[1] + Thread.pass until accept + conn = server.accept + conn << "hello!" + conn.close + server.close + end - addr = Socket.sockaddr_in(port, @hostname) - begin - @socket.connect_nonblock(addr) - rescue Errno::EINPROGRESS - end + Thread.pass until port - accept = true - IO.select nil, [@socket] + addr = Socket.sockaddr_in(port, @hostname) + begin + @socket.connect_nonblock(addr) + rescue Errno::EINPROGRESS + end - begin - @socket.connect_nonblock(addr) - rescue Errno::EISCONN - # Not all OS's use this errno, so we trap and ignore it - end + accept = true + IO.select nil, [@socket] - @socket.read(6).should == "hello!" + begin + @socket.connect_nonblock(addr) + rescue Errno::EISCONN + # Not all OS's use this errno, so we trap and ignore it end + + @socket.read(6).should == "hello!" end - platform_is_not :freebsd, :solaris, :aix do + platform_is_not :freebsd, :aix do it "raises Errno::EINPROGRESS when the connect would block" do -> do @socket.connect_nonblock(@addr) @@ -135,7 +133,7 @@ describe 'Socket#connect_nonblock' do end end - platform_is_not :freebsd, :solaris do + platform_is_not :freebsd do it 'raises IO:EINPROGRESSWaitWritable when the connection would block' do @server.bind(@sockaddr) diff --git a/spec/ruby/library/socket/socket/connect_spec.rb b/spec/ruby/library/socket/socket/connect_spec.rb index 8653fba552..130379ce2b 100644 --- a/spec/ruby/library/socket/socket/connect_spec.rb +++ b/spec/ruby/library/socket/socket/connect_spec.rb @@ -53,4 +53,26 @@ describe 'Socket#connect' do end end end + + ruby_version_is "3.4" do + it "fails with timeout" do + # TEST-NET-1 IP address are reserved for documentation and example purposes. + address = Socket.pack_sockaddr_in(1, "192.0.2.1") + + client = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM) + client.timeout = 0 + + -> { + begin + client.connect(address) + rescue Errno::ECONNREFUSED + skip "Outgoing packets may be filtered" + rescue Errno::ENETUNREACH + skip "Off line" + end + }.should raise_error(IO::TimeoutError) + ensure + client.close + end + end end diff --git a/spec/ruby/library/socket/socket/getaddrinfo_spec.rb b/spec/ruby/library/socket/socket/getaddrinfo_spec.rb index e0eff3cef4..6576af52ee 100644 --- a/spec/ruby/library/socket/socket/getaddrinfo_spec.rb +++ b/spec/ruby/library/socket/socket/getaddrinfo_spec.rb @@ -11,7 +11,7 @@ describe "Socket.getaddrinfo" do BasicSocket.do_not_reverse_lookup = @do_not_reverse_lookup end - platform_is_not :solaris, :windows do + platform_is_not :windows do it "gets the address information" do expected = [] # The check for AP_INET6's class is needed because ipaddr.rb adds @@ -106,6 +106,24 @@ describe "Socket.getaddrinfo" do ] res.each { |a| expected.should include(a) } end + + ruby_version_is ""..."3.3" do + it "raises SocketError when fails to resolve address" do + -> { + Socket.getaddrinfo("www.kame.net", 80, "AF_UNIX") + }.should raise_error(SocketError) + end + end + + ruby_version_is "3.3" do + it "raises ResolutionError when fails to resolve address" do + -> { + Socket.getaddrinfo("www.kame.net", 80, "AF_UNIX") + }.should raise_error(Socket::ResolutionError) { |e| + [Socket::EAI_FAMILY, Socket::EAI_FAIL].should.include?(e.error_code) + } + end + end end end diff --git a/spec/ruby/library/socket/socket/gethostbyaddr_spec.rb b/spec/ruby/library/socket/socket/gethostbyaddr_spec.rb index a4c8355520..5d936046f5 100644 --- a/spec/ruby/library/socket/socket/gethostbyaddr_spec.rb +++ b/spec/ruby/library/socket/socket/gethostbyaddr_spec.rb @@ -18,11 +18,8 @@ describe 'Socket.gethostbyaddr' do @array = suppress_warning { Socket.gethostbyaddr(@addr) } end - # RubyCI Solaris 11x defines 127.0.0.1 as unstable11x - platform_is_not :"solaris2.11" do - it 'includes the hostname as the first value' do - @array[0].should == SocketSpecs.hostname_reverse_lookup - end + it 'includes the hostname as the first value' do + @array[0].should == SocketSpecs.hostname_reverse_lookup end it 'includes the aliases as the 2nd value' do diff --git a/spec/ruby/library/socket/socket/gethostbyname_spec.rb b/spec/ruby/library/socket/socket/gethostbyname_spec.rb index 0858e255e4..618ef85387 100644 --- a/spec/ruby/library/socket/socket/gethostbyname_spec.rb +++ b/spec/ruby/library/socket/socket/gethostbyname_spec.rb @@ -1,4 +1,4 @@ -# -*- encoding: binary -*- +# encoding: binary require_relative '../spec_helper' require_relative '../fixtures/classes' diff --git a/spec/ruby/library/socket/socket/gethostname_spec.rb b/spec/ruby/library/socket/socket/gethostname_spec.rb index 4b79747b27..dfca7cf5cd 100644 --- a/spec/ruby/library/socket/socket/gethostname_spec.rb +++ b/spec/ruby/library/socket/socket/gethostname_spec.rb @@ -2,7 +2,17 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' describe "Socket.gethostname" do + def system_hostname + if platform_is_not :windows + # `uname -n` is the most portable way to get the hostname, as it is a POSIX standard: + `uname -n`.strip + else + # Windows does not have uname, so we use hostname instead: + `hostname`.strip + end + end + it "returns the host name" do - Socket.gethostname.should == `hostname`.strip + Socket.gethostname.should == system_hostname end end diff --git a/spec/ruby/library/socket/socket/getifaddrs_spec.rb b/spec/ruby/library/socket/socket/getifaddrs_spec.rb index 7df542abe6..839854ea27 100644 --- a/spec/ruby/library/socket/socket/getifaddrs_spec.rb +++ b/spec/ruby/library/socket/socket/getifaddrs_spec.rb @@ -1,6 +1,6 @@ require_relative '../spec_helper' -platform_is_not :aix, :"solaris2.10" do +platform_is_not :aix do describe 'Socket.getifaddrs' do before do @ifaddrs = Socket.getifaddrs diff --git a/spec/ruby/library/socket/socket/getnameinfo_spec.rb b/spec/ruby/library/socket/socket/getnameinfo_spec.rb index b406348aa8..af4a10c9c2 100644 --- a/spec/ruby/library/socket/socket/getnameinfo_spec.rb +++ b/spec/ruby/library/socket/socket/getnameinfo_spec.rb @@ -60,6 +60,24 @@ describe "Socket.getnameinfo" do name_info = Socket.getnameinfo ["AF_INET", 9, 'foo', '127.0.0.1'] name_info[1].should == 'discard' end + + ruby_version_is ""..."3.3" do + it "raises SocketError when fails to resolve address" do + -> { + Socket.getnameinfo(["AF_UNIX", 80, "0.0.0.0"]) + }.should raise_error(SocketError) + end + end + + ruby_version_is "3.3" do + it "raises ResolutionError when fails to resolve address" do + -> { + Socket.getnameinfo(["AF_UNIX", 80, "0.0.0.0"]) + }.should raise_error(Socket::ResolutionError) { |e| + [Socket::EAI_FAMILY, Socket::EAI_FAIL].should.include?(e.error_code) + } + end + end end describe 'Socket.getnameinfo' do @@ -70,7 +88,7 @@ describe 'Socket.getnameinfo' do it 'raises SocketError or TypeError when using an invalid String' do -> { Socket.getnameinfo('cats') }.should raise_error(Exception) { |e| - [SocketError, TypeError].should include(e.class) + (e.is_a?(SocketError) || e.is_a?(TypeError)).should == true } end diff --git a/spec/ruby/library/socket/socket/new_spec.rb b/spec/ruby/library/socket/socket/new_spec.rb deleted file mode 100644 index b2ec607f6a..0000000000 --- a/spec/ruby/library/socket/socket/new_spec.rb +++ /dev/null @@ -1,2 +0,0 @@ -require_relative '../spec_helper' -require_relative '../fixtures/classes' diff --git a/spec/ruby/library/socket/socket/pack_sockaddr_in_spec.rb b/spec/ruby/library/socket/socket/pack_sockaddr_in_spec.rb index 63d4724453..ef2a2d4ba9 100644 --- a/spec/ruby/library/socket/socket/pack_sockaddr_in_spec.rb +++ b/spec/ruby/library/socket/socket/pack_sockaddr_in_spec.rb @@ -2,6 +2,6 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' require_relative '../shared/pack_sockaddr' -describe "Socket#pack_sockaddr_in" do +describe "Socket.pack_sockaddr_in" do it_behaves_like :socket_pack_sockaddr_in, :pack_sockaddr_in end diff --git a/spec/ruby/library/socket/socket/pair_spec.rb b/spec/ruby/library/socket/socket/pair_spec.rb index 292eacd38d..8dd470a95e 100644 --- a/spec/ruby/library/socket/socket/pair_spec.rb +++ b/spec/ruby/library/socket/socket/pair_spec.rb @@ -2,6 +2,6 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' require_relative '../shared/socketpair' -describe "Socket#pair" do +describe "Socket.pair" do it_behaves_like :socket_socketpair, :pair end diff --git a/spec/ruby/library/socket/socket/recvfrom_nonblock_spec.rb b/spec/ruby/library/socket/socket/recvfrom_nonblock_spec.rb index 94f58ac49f..01b42bcc52 100644 --- a/spec/ruby/library/socket/socket/recvfrom_nonblock_spec.rb +++ b/spec/ruby/library/socket/socket/recvfrom_nonblock_spec.rb @@ -52,6 +52,27 @@ describe 'Socket#recvfrom_nonblock' do end end + it "allows an output buffer as third argument" do + @client.write('hello') + + IO.select([@server]) + buffer = +'' + message, = @server.recvfrom_nonblock(5, 0, buffer) + + message.should.equal?(buffer) + buffer.should == 'hello' + end + + it "preserves the encoding of the given buffer" do + @client.write('hello') + + IO.select([@server]) + buffer = ''.encode(Encoding::ISO_8859_1) + @server.recvfrom_nonblock(5, 0, buffer) + + buffer.encoding.should == Encoding::ISO_8859_1 + end + describe 'the returned data' do it 'is the same as the sent data' do 5.times do @@ -116,3 +137,83 @@ describe 'Socket#recvfrom_nonblock' do end end end + +describe 'Socket#recvfrom_nonblock' do + context "when recvfrom(2) returns 0 (if no messages are available to be received and the peer has performed an orderly shutdown)" do + describe "stream socket" do + before :each do + @server = Socket.new Socket::AF_INET, :STREAM, 0 + @sockaddr = Socket.sockaddr_in(0, "127.0.0.1") + @server.bind(@sockaddr) + @server.listen(1) + + server_ip = @server.local_address.ip_port + @server_addr = Socket.sockaddr_in(server_ip, "127.0.0.1") + + @client = Socket.new(Socket::AF_INET, :STREAM, 0) + end + + after :each do + @server.close unless @server.closed? + @client.close unless @client.closed? + end + + ruby_version_is ""..."3.3" do + it "returns an empty String as received data on a closed stream socket" do + ready = false + + t = Thread.new do + client, _ = @server.accept + + Thread.pass while !ready + begin + client.recvfrom_nonblock(10) + rescue IO::EAGAINWaitReadable + retry + end + ensure + client.close if client + end + + Thread.pass while t.status and t.status != "sleep" + t.status.should_not be_nil + + @client.connect(@server_addr) + @client.close + ready = true + + t.value.should.is_a? Array + t.value[0].should == "" + end + end + + ruby_version_is "3.3" do + it "returns nil on a closed stream socket" do + ready = false + + t = Thread.new do + client, _ = @server.accept + + Thread.pass while !ready + begin + client.recvfrom_nonblock(10) + rescue IO::EAGAINWaitReadable + retry + end + ensure + client.close if client + end + + Thread.pass while t.status and t.status != "sleep" + t.status.should_not be_nil + + @client.connect(@server_addr) + @client.close + ready = true + + t.value.should be_nil + end + end + end + end +end diff --git a/spec/ruby/library/socket/socket/recvfrom_spec.rb b/spec/ruby/library/socket/socket/recvfrom_spec.rb index faf161e4a5..6ba39ffcaf 100644 --- a/spec/ruby/library/socket/socket/recvfrom_spec.rb +++ b/spec/ruby/library/socket/socket/recvfrom_spec.rb @@ -90,3 +90,90 @@ describe 'Socket#recvfrom' do end end end + +describe 'Socket#recvfrom' do + context "when recvfrom(2) returns 0 (if no messages are available to be received and the peer has performed an orderly shutdown)" do + describe "stream socket" do + before :each do + @server = Socket.new Socket::AF_INET, :STREAM, 0 + sockaddr = Socket.sockaddr_in(0, "127.0.0.1") + @server.bind(sockaddr) + @server.listen(1) + + server_ip = @server.local_address.ip_port + @server_addr = Socket.sockaddr_in(server_ip, "127.0.0.1") + + @client = Socket.new(Socket::AF_INET, :STREAM, 0) + end + + after :each do + @server.close unless @server.closed? + @client.close unless @client.closed? + end + + ruby_version_is ""..."3.3" do + it "returns an empty String as received data on a closed stream socket" do + t = Thread.new do + client, _ = @server.accept + client.recvfrom(10) + ensure + client.close if client + end + + Thread.pass while t.status and t.status != "sleep" + t.status.should_not be_nil + + @client.connect(@server_addr) + @client.close + + t.value.should.is_a? Array + t.value[0].should == "" + end + end + + ruby_version_is "3.3" do + it "returns nil on a closed stream socket" do + t = Thread.new do + client, _ = @server.accept + client.recvfrom(10) + ensure + client.close if client + end + + Thread.pass while t.status and t.status != "sleep" + t.status.should_not be_nil + + @client.connect(@server_addr) + @client.close + + t.value.should be_nil + end + end + end + + describe "datagram socket" do + SocketSpecs.each_ip_protocol do |family, ip_address| + before :each do + @server = Socket.new(family, :DGRAM) + @client = Socket.new(family, :DGRAM) + end + + after :each do + @server.close unless @server.closed? + @client.close unless @client.closed? + end + + it "returns an empty String as received data" do + @server.bind(Socket.sockaddr_in(0, ip_address)) + @client.connect(@server.getsockname) + + @client.send('', 0) + message = @server.recvfrom(1) + + message.should.is_a? Array + message[0].should == "" + end + end + end + end +end diff --git a/spec/ruby/library/socket/socket/socketpair_spec.rb b/spec/ruby/library/socket/socket/socketpair_spec.rb index 5b8311124e..551c376d49 100644 --- a/spec/ruby/library/socket/socket/socketpair_spec.rb +++ b/spec/ruby/library/socket/socket/socketpair_spec.rb @@ -2,6 +2,6 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' require_relative '../shared/socketpair' -describe "Socket#socketpair" do +describe "Socket.socketpair" do it_behaves_like :socket_socketpair, :socketpair end diff --git a/spec/ruby/library/socket/socket/udp_server_loop_spec.rb b/spec/ruby/library/socket/socket/udp_server_loop_spec.rb index fc030e75b9..cd22ea56cf 100644 --- a/spec/ruby/library/socket/socket/udp_server_loop_spec.rb +++ b/spec/ruby/library/socket/socket/udp_server_loop_spec.rb @@ -50,10 +50,10 @@ describe 'Socket.udp_server_loop' do end end + thread.join + msg.should == 'hello' src.should be_an_instance_of(Socket::UDPSource) - - thread.join end end end diff --git a/spec/ruby/library/socket/socket/unix_server_loop_spec.rb b/spec/ruby/library/socket/socket/unix_server_loop_spec.rb index 0f34d4a50b..6192bc8bf6 100644 --- a/spec/ruby/library/socket/socket/unix_server_loop_spec.rb +++ b/spec/ruby/library/socket/socket/unix_server_loop_spec.rb @@ -1,58 +1,56 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -with_feature :unix_socket do - describe 'Socket.unix_server_loop' do - before do - @path = SocketSpecs.socket_path - end +describe 'Socket.unix_server_loop' do + before do + @path = SocketSpecs.socket_path + end - after do - rm_r(@path) if File.file?(@path) - end + after do + rm_r(@path) if File.file?(@path) + end - describe 'when no connections are available' do - it 'blocks the caller' do - -> { Socket.unix_server_loop(@path) }.should block_caller - end + describe 'when no connections are available' do + it 'blocks the caller' do + -> { Socket.unix_server_loop(@path) }.should block_caller end + end - describe 'when a connection is available' do - before do - @client = nil - end + describe 'when a connection is available' do + before do + @client = nil + end - after do - @sock.close if @sock - @client.close if @client - end + after do + @sock.close if @sock + @client.close if @client + end - it 'yields a Socket and an Addrinfo' do - @sock, addr = nil + it 'yields a Socket and an Addrinfo' do + @sock, addr = nil - thread = Thread.new do - Socket.unix_server_loop(@path) do |socket, addrinfo| - @sock = socket - addr = addrinfo + thread = Thread.new do + Socket.unix_server_loop(@path) do |socket, addrinfo| + @sock = socket + addr = addrinfo - break - end + break end + end - SocketSpecs.loop_with_timeout do - begin - @client = Socket.unix(@path) - rescue SystemCallError - sleep 0.01 - :retry - end + SocketSpecs.loop_with_timeout do + begin + @client = Socket.unix(@path) + rescue SystemCallError + sleep 0.01 + :retry end + end - thread.join + thread.join - @sock.should be_an_instance_of(Socket) - addr.should be_an_instance_of(Addrinfo) - end + @sock.should be_an_instance_of(Socket) + addr.should be_an_instance_of(Addrinfo) end end end diff --git a/spec/ruby/library/socket/socket/unix_server_socket_spec.rb b/spec/ruby/library/socket/socket/unix_server_socket_spec.rb index fc357740fa..34c3b96d07 100644 --- a/spec/ruby/library/socket/socket/unix_server_socket_spec.rb +++ b/spec/ruby/library/socket/socket/unix_server_socket_spec.rb @@ -1,48 +1,46 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -with_feature :unix_socket do - describe 'Socket.unix_server_socket' do +describe 'Socket.unix_server_socket' do + before do + @path = SocketSpecs.socket_path + end + + after do + rm_r(@path) + end + + describe 'when no block is given' do before do - @path = SocketSpecs.socket_path + @socket = nil end after do - rm_r(@path) + @socket.close end - describe 'when no block is given' do - before do - @socket = nil - end - - after do - @socket.close - end + it 'returns a Socket' do + @socket = Socket.unix_server_socket(@path) - it 'returns a Socket' do - @socket = Socket.unix_server_socket(@path) - - @socket.should be_an_instance_of(Socket) - end + @socket.should be_an_instance_of(Socket) end + end - describe 'when a block is given' do - it 'yields a Socket' do - Socket.unix_server_socket(@path) do |sock| - sock.should be_an_instance_of(Socket) - end + describe 'when a block is given' do + it 'yields a Socket' do + Socket.unix_server_socket(@path) do |sock| + sock.should be_an_instance_of(Socket) end + end - it 'closes the Socket when the block returns' do - socket = nil - - Socket.unix_server_socket(@path) do |sock| - socket = sock - end + it 'closes the Socket when the block returns' do + socket = nil - socket.should be_an_instance_of(Socket) + Socket.unix_server_socket(@path) do |sock| + socket = sock end + + socket.should be_an_instance_of(Socket) end end end diff --git a/spec/ruby/library/socket/socket/unix_spec.rb b/spec/ruby/library/socket/socket/unix_spec.rb index 4bff59bd4b..2a5d77f96f 100644 --- a/spec/ruby/library/socket/socket/unix_spec.rb +++ b/spec/ruby/library/socket/socket/unix_spec.rb @@ -1,45 +1,43 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -with_feature :unix_socket do - describe 'Socket.unix' do - before do - @path = SocketSpecs.socket_path - @server = UNIXServer.new(@path) - @socket = nil - end +describe 'Socket.unix' do + before do + @path = SocketSpecs.socket_path + @server = UNIXServer.new(@path) + @socket = nil + end - after do - @server.close - @socket.close if @socket + after do + @server.close + @socket.close if @socket - rm_r(@path) - end + rm_r(@path) + end - describe 'when no block is given' do - it 'returns a Socket' do - @socket = Socket.unix(@path) + describe 'when no block is given' do + it 'returns a Socket' do + @socket = Socket.unix(@path) - @socket.should be_an_instance_of(Socket) - end + @socket.should be_an_instance_of(Socket) end + end - describe 'when a block is given' do - it 'yields a Socket' do - Socket.unix(@path) do |sock| - sock.should be_an_instance_of(Socket) - end + describe 'when a block is given' do + it 'yields a Socket' do + Socket.unix(@path) do |sock| + sock.should be_an_instance_of(Socket) end + end - it 'closes the Socket when the block returns' do - socket = nil - - Socket.unix(@path) do |sock| - socket = sock - end + it 'closes the Socket when the block returns' do + socket = nil - socket.should.closed? + Socket.unix(@path) do |sock| + socket = sock end + + socket.should.closed? end end end diff --git a/spec/ruby/library/socket/socket/unpack_sockaddr_in_spec.rb b/spec/ruby/library/socket/socket/unpack_sockaddr_in_spec.rb index 79ec68cd18..935b5cb543 100644 --- a/spec/ruby/library/socket/socket/unpack_sockaddr_in_spec.rb +++ b/spec/ruby/library/socket/socket/unpack_sockaddr_in_spec.rb @@ -32,15 +32,13 @@ describe "Socket.unpack_sockaddr_in" do end end - with_feature :unix_socket do - it "raises an ArgumentError when the sin_family is not AF_INET" do - sockaddr = Socket.sockaddr_un '/tmp/x' - -> { Socket.unpack_sockaddr_in sockaddr }.should raise_error(ArgumentError) - end + it "raises an ArgumentError when the sin_family is not AF_INET" do + sockaddr = Socket.sockaddr_un '/tmp/x' + -> { Socket.unpack_sockaddr_in sockaddr }.should raise_error(ArgumentError) + end - it "raises an ArgumentError when passed addrinfo is not AF_INET/AF_INET6" do - addrinfo = Addrinfo.unix('/tmp/sock') - -> { Socket.unpack_sockaddr_in(addrinfo) }.should raise_error(ArgumentError) - end + it "raises an ArgumentError when passed addrinfo is not AF_INET/AF_INET6" do + addrinfo = Addrinfo.unix('/tmp/sock') + -> { Socket.unpack_sockaddr_in(addrinfo) }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/library/socket/socket/unpack_sockaddr_un_spec.rb b/spec/ruby/library/socket/socket/unpack_sockaddr_un_spec.rb index 12f970f89b..6e0f11de3d 100644 --- a/spec/ruby/library/socket/socket/unpack_sockaddr_un_spec.rb +++ b/spec/ruby/library/socket/socket/unpack_sockaddr_un_spec.rb @@ -1,26 +1,24 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -with_feature :unix_socket do - describe 'Socket.unpack_sockaddr_un' do - it 'decodes sockaddr to unix path' do - sockaddr = Socket.sockaddr_un('/tmp/sock') - Socket.unpack_sockaddr_un(sockaddr).should == '/tmp/sock' - end +describe 'Socket.unpack_sockaddr_un' do + it 'decodes sockaddr to unix path' do + sockaddr = Socket.sockaddr_un('/tmp/sock') + Socket.unpack_sockaddr_un(sockaddr).should == '/tmp/sock' + end - it 'returns unix path from a passed Addrinfo' do - addrinfo = Addrinfo.unix('/tmp/sock') - Socket.unpack_sockaddr_un(addrinfo).should == '/tmp/sock' - end + it 'returns unix path from a passed Addrinfo' do + addrinfo = Addrinfo.unix('/tmp/sock') + Socket.unpack_sockaddr_un(addrinfo).should == '/tmp/sock' + end - it 'raises an ArgumentError when the sa_family is not AF_UNIX' do - sockaddr = Socket.sockaddr_in(0, '127.0.0.1') - -> { Socket.unpack_sockaddr_un(sockaddr) }.should raise_error(ArgumentError) - end + it 'raises an ArgumentError when the sa_family is not AF_UNIX' do + sockaddr = Socket.sockaddr_in(0, '127.0.0.1') + -> { Socket.unpack_sockaddr_un(sockaddr) }.should raise_error(ArgumentError) + end - it 'raises an ArgumentError when passed addrinfo is not AF_UNIX' do - addrinfo = Addrinfo.tcp('127.0.0.1', 0) - -> { Socket.unpack_sockaddr_un(addrinfo) }.should raise_error(ArgumentError) - end + it 'raises an ArgumentError when passed addrinfo is not AF_UNIX' do + addrinfo = Addrinfo.tcp('127.0.0.1', 0) + -> { Socket.unpack_sockaddr_un(addrinfo) }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/library/socket/spec_helper.rb b/spec/ruby/library/socket/spec_helper.rb index 1121542dd5..b33663e02d 100644 --- a/spec/ruby/library/socket/spec_helper.rb +++ b/spec/ruby/library/socket/spec_helper.rb @@ -2,7 +2,6 @@ require_relative '../../spec_helper' require 'socket' MSpec.enable_feature :sock_packet if Socket.const_defined?(:SOCK_PACKET) -MSpec.enable_feature :unix_socket unless PlatformGuard.windows? MSpec.enable_feature :udp_cork if Socket.const_defined?(:UDP_CORK) MSpec.enable_feature :tcp_cork if Socket.const_defined?(:TCP_CORK) MSpec.enable_feature :pktinfo if Socket.const_defined?(:IP_PKTINFO) diff --git a/spec/ruby/library/socket/tcpserver/accept_spec.rb b/spec/ruby/library/socket/tcpserver/accept_spec.rb index d38d95e0e1..d8892cd5f0 100644 --- a/spec/ruby/library/socket/tcpserver/accept_spec.rb +++ b/spec/ruby/library/socket/tcpserver/accept_spec.rb @@ -69,7 +69,7 @@ describe "TCPServer#accept" do Thread.pass while t.status and t.status != "sleep" # Thread#backtrace uses SIGVTALRM on TruffleRuby and potentially other implementations. # Sending a signal to a thread is not possible with Ruby APIs. - t.backtrace.join("\n").should.include?("in `accept'") + t.backtrace.join("\n").should =~ /in [`'](?:TCPServer#)?accept'/ socket = TCPSocket.new('127.0.0.1', @port) socket.write("OK") @@ -114,6 +114,19 @@ describe 'TCPServer#accept' do @socket = @server.accept @socket.should be_an_instance_of(TCPSocket) end + + platform_is_not :windows do + it "returns a TCPSocket which is set to nonblocking" do + require 'io/nonblock' + @socket = @server.accept + @socket.should.nonblock? + end + end + + it "returns a TCPSocket which is set to close on exec" do + @socket = @server.accept + @socket.should.close_on_exec? + end end end end diff --git a/spec/ruby/library/socket/tcpserver/new_spec.rb b/spec/ruby/library/socket/tcpserver/new_spec.rb index 8d9696c9d8..dd1ba676bd 100644 --- a/spec/ruby/library/socket/tcpserver/new_spec.rb +++ b/spec/ruby/library/socket/tcpserver/new_spec.rb @@ -97,6 +97,12 @@ describe "TCPServer.new" do addr[1].should be_kind_of(Integer) end + it "does not use the given block and warns to use TCPServer::open" do + -> { + @server = TCPServer.new(0) { raise } + }.should complain(/warning: TCPServer::new\(\) does not take block; use TCPServer::open\(\) instead/) + end + it "raises Errno::EADDRNOTAVAIL when the address is unknown" do -> { TCPServer.new("1.2.3.4", 0) }.should raise_error(Errno::EADDRNOTAVAIL) end diff --git a/spec/ruby/library/socket/tcpsocket/gethostbyname_spec.rb b/spec/ruby/library/socket/tcpsocket/gethostbyname_spec.rb index f0e98778f5..5a2c704f35 100644 --- a/spec/ruby/library/socket/tcpsocket/gethostbyname_spec.rb +++ b/spec/ruby/library/socket/tcpsocket/gethostbyname_spec.rb @@ -2,7 +2,7 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' # TODO: verify these for windows -describe "TCPSocket#gethostbyname" do +describe "TCPSocket.gethostbyname" do before :each do suppress_warning do @host_info = TCPSocket.gethostbyname(SocketSpecs.hostname) @@ -52,7 +52,7 @@ describe "TCPSocket#gethostbyname" do end end -describe 'TCPSocket#gethostbyname' do +describe 'TCPSocket.gethostbyname' do it 'returns an Array' do suppress_warning do TCPSocket.gethostbyname('127.0.0.1').should be_an_instance_of(Array) diff --git a/spec/ruby/library/socket/tcpsocket/initialize_spec.rb b/spec/ruby/library/socket/tcpsocket/initialize_spec.rb index 065c8f4190..d7feb9751b 100644 --- a/spec/ruby/library/socket/tcpsocket/initialize_spec.rb +++ b/spec/ruby/library/socket/tcpsocket/initialize_spec.rb @@ -4,6 +4,27 @@ require_relative 'shared/new' describe 'TCPSocket#initialize' do it_behaves_like :tcpsocket_new, :new + + describe "with a running server" do + before :each do + @server = SocketSpecs::SpecTCPServer.new + @hostname = @server.hostname + end + + after :each do + if @socket + @socket.write "QUIT" + @socket.close + end + @server.shutdown + end + + it "does not use the given block and warns to use TCPSocket::open" do + -> { + @socket = TCPSocket.new(@hostname, @server.port, nil) { raise } + }.should complain(/warning: TCPSocket::new\(\) does not take block; use TCPSocket::open\(\) instead/) + end + end end describe 'TCPSocket#initialize' do @@ -51,6 +72,19 @@ describe 'TCPSocket#initialize' do @client.remote_address.ip_port.should == @server.local_address.ip_port end + platform_is_not :windows do + it "creates a socket which is set to nonblocking" do + require 'io/nonblock' + @client = TCPSocket.new(ip_address, @port) + @client.should.nonblock? + end + end + + it "creates a socket which is set to close on exec" do + @client = TCPSocket.new(ip_address, @port) + @client.should.close_on_exec? + end + describe 'using a local address and service' do it 'binds the client socket to the local address and service' do @client = TCPSocket.new(ip_address, @port, ip_address, 0) diff --git a/spec/ruby/library/socket/tcpsocket/partially_closable_spec.rb b/spec/ruby/library/socket/tcpsocket/partially_closable_spec.rb index a381627a39..d365ecd335 100644 --- a/spec/ruby/library/socket/tcpsocket/partially_closable_spec.rb +++ b/spec/ruby/library/socket/tcpsocket/partially_closable_spec.rb @@ -16,6 +16,6 @@ describe "TCPSocket partial closability" do @s2.close end - it_should_behave_like "partially closable sockets" + it_should_behave_like :partially_closable_sockets end diff --git a/spec/ruby/library/socket/tcpsocket/shared/new.rb b/spec/ruby/library/socket/tcpsocket/shared/new.rb index e7eb2f3c13..0e405253c8 100644 --- a/spec/ruby/library/socket/tcpsocket/shared/new.rb +++ b/spec/ruby/library/socket/tcpsocket/shared/new.rb @@ -14,20 +14,13 @@ describe :tcpsocket_new, shared: true do } end - ruby_version_is "3.0"..."3.1" do - it 'raises Errno::ETIMEDOUT with :connect_timeout when no server is listening on the given address' do - -> { - TCPSocket.send(@method, "192.0.2.1", 80, connect_timeout: 0) - }.should raise_error(Errno::ETIMEDOUT) - end - end - - ruby_version_is "3.2" do - it 'raises IO::TimeoutError with :connect_timeout when no server is listening on the given address' do - -> { - TCPSocket.send(@method, "192.0.2.1", 80, connect_timeout: 0) - }.should raise_error(IO::TimeoutError) - end + it 'raises IO::TimeoutError with :connect_timeout when no server is listening on the given address' do + -> { + TCPSocket.send(@method, "192.0.2.1", 80, connect_timeout: 0) + }.should raise_error(IO::TimeoutError) + rescue Errno::ENETUNREACH + # In the case all network interfaces down. + # raise_error cannot deal with multiple expected exceptions end describe "with a running server" do @@ -60,14 +53,23 @@ describe :tcpsocket_new, shared: true do end it "connects to a server when passed local_host and local_port arguments" do - server = TCPServer.new(SocketSpecs.hostname, 0) + retries = 0 + max_retries = 3 + begin - available_port = server.addr[1] - ensure - server.close + retries += 1 + server = TCPServer.new(SocketSpecs.hostname, 0) + begin + available_port = server.addr[1] + ensure + server.close + end + @socket = TCPSocket.send(@method, @hostname, @server.port, + @hostname, available_port) + rescue Errno::EADDRINUSE + raise if retries >= max_retries + retry end - @socket = TCPSocket.send(@method, @hostname, @server.port, - @hostname, available_port) @socket.should be_an_instance_of(TCPSocket) end @@ -92,11 +94,9 @@ describe :tcpsocket_new, shared: true do @socket.addr[2].should =~ /^#{@hostname}/ end - ruby_version_is "3.0" do - it "connects to a server when passed connect_timeout argument" do - @socket = TCPSocket.send(@method, @hostname, @server.port, connect_timeout: 1) - @socket.should be_an_instance_of(TCPSocket) - end + it "connects to a server when passed connect_timeout argument" do + @socket = TCPSocket.send(@method, @hostname, @server.port, connect_timeout: 1) + @socket.should be_an_instance_of(TCPSocket) end end end diff --git a/spec/ruby/library/socket/udpsocket/initialize_spec.rb b/spec/ruby/library/socket/udpsocket/initialize_spec.rb index 1d635149f7..ecf0043c10 100644 --- a/spec/ruby/library/socket/udpsocket/initialize_spec.rb +++ b/spec/ruby/library/socket/udpsocket/initialize_spec.rb @@ -30,6 +30,19 @@ describe 'UDPSocket#initialize' do @socket.binmode?.should be_true end + platform_is_not :windows do + it 'sets the socket to nonblock' do + require 'io/nonblock' + @socket = UDPSocket.new(:INET) + @socket.should.nonblock? + end + end + + it 'sets the socket to close on exec' do + @socket = UDPSocket.new(:INET) + @socket.should.close_on_exec? + end + it 'raises Errno::EAFNOSUPPORT or Errno::EPROTONOSUPPORT when given an invalid address family' do -> { UDPSocket.new(666) diff --git a/spec/ruby/library/socket/udpsocket/new_spec.rb b/spec/ruby/library/socket/udpsocket/new_spec.rb index 6cc0cadbcb..79bfcb624d 100644 --- a/spec/ruby/library/socket/udpsocket/new_spec.rb +++ b/spec/ruby/library/socket/udpsocket/new_spec.rb @@ -26,6 +26,12 @@ describe 'UDPSocket.new' do @socket.should be_an_instance_of(UDPSocket) end + it "does not use the given block and warns to use UDPSocket::open" do + -> { + @socket = UDPSocket.new { raise } + }.should complain(/warning: UDPSocket::new\(\) does not take block; use UDPSocket::open\(\) instead/) + end + it 'raises Errno::EAFNOSUPPORT or Errno::EPROTONOSUPPORT if unsupported family passed' do -> { UDPSocket.new(-1) }.should raise_error(SystemCallError) { |e| [Errno::EAFNOSUPPORT, Errno::EPROTONOSUPPORT].should include(e.class) diff --git a/spec/ruby/library/socket/udpsocket/recvfrom_nonblock_spec.rb b/spec/ruby/library/socket/udpsocket/recvfrom_nonblock_spec.rb index 650a061221..b804099589 100644 --- a/spec/ruby/library/socket/udpsocket/recvfrom_nonblock_spec.rb +++ b/spec/ruby/library/socket/udpsocket/recvfrom_nonblock_spec.rb @@ -58,6 +58,15 @@ describe 'UDPSocket#recvfrom_nonblock' do buffer.should == 'h' end + it "preserves the encoding of the given buffer" do + buffer = ''.encode(Encoding::ISO_8859_1) + IO.select([@server]) + message, = @server.recvfrom_nonblock(1, 0, buffer) + + message.should.equal?(buffer) + buffer.encoding.should == Encoding::ISO_8859_1 + end + describe 'the returned Array' do before do IO.select([@server]) diff --git a/spec/ruby/library/socket/udpsocket/send_spec.rb b/spec/ruby/library/socket/udpsocket/send_spec.rb index 5d5de684af..6dd5f67bea 100644 --- a/spec/ruby/library/socket/udpsocket/send_spec.rb +++ b/spec/ruby/library/socket/udpsocket/send_spec.rb @@ -63,7 +63,7 @@ describe "UDPSocket#send" do @msg[1][3].should == "127.0.0.1" end - it "raises EMSGSIZE if data is too too big" do + it "raises EMSGSIZE if data is too big" do @socket = UDPSocket.open begin -> do diff --git a/spec/ruby/library/socket/unixserver/accept_nonblock_spec.rb b/spec/ruby/library/socket/unixserver/accept_nonblock_spec.rb index 30688b46b6..f67941b296 100644 --- a/spec/ruby/library/socket/unixserver/accept_nonblock_spec.rb +++ b/spec/ruby/library/socket/unixserver/accept_nonblock_spec.rb @@ -2,89 +2,84 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' describe "UNIXServer#accept_nonblock" do + before :each do + @path = SocketSpecs.socket_path + @server = UNIXServer.open(@path) + @client = UNIXSocket.open(@path) - platform_is_not :windows do - before :each do - @path = SocketSpecs.socket_path - @server = UNIXServer.open(@path) - @client = UNIXSocket.open(@path) + @socket = @server.accept_nonblock + @client.send("foobar", 0) + end - @socket = @server.accept_nonblock - @client.send("foobar", 0) - end + after :each do + @socket.close + @client.close + @server.close + SocketSpecs.rm_socket @path + end - after :each do - @socket.close - @client.close - @server.close - SocketSpecs.rm_socket @path - end + it "accepts a connection in a non-blocking way" do + data = @socket.recvfrom(6).first + data.should == "foobar" + end - it "accepts a connection in a non-blocking way" do - data = @socket.recvfrom(6).first - data.should == "foobar" - end + it "returns a UNIXSocket" do + @socket.should be_kind_of(UNIXSocket) + end - it "returns a UNIXSocket" do - @socket.should be_kind_of(UNIXSocket) - end + it 'returns :wait_readable in exceptionless mode' do + @server.accept_nonblock(exception: false).should == :wait_readable + end +end + +describe 'UNIXServer#accept_nonblock' do + before do + @path = SocketSpecs.socket_path + @server = UNIXServer.new(@path) + end - it 'returns :wait_readable in exceptionless mode' do - @server.accept_nonblock(exception: false).should == :wait_readable + after do + @server.close + rm_r(@path) + end + + describe 'without a client' do + it 'raises IO::WaitReadable' do + -> { @server.accept_nonblock }.should raise_error(IO::WaitReadable) end end -end -with_feature :unix_socket do - describe 'UNIXServer#accept_nonblock' do + describe 'with a client' do before do - @path = SocketSpecs.socket_path - @server = UNIXServer.new(@path) + @client = UNIXSocket.new(@path) end after do - @server.close - rm_r(@path) + @client.close + @socket.close if @socket end - describe 'without a client' do - it 'raises IO::WaitReadable' do - -> { @server.accept_nonblock }.should raise_error(IO::WaitReadable) + describe 'without any data' do + it 'returns a UNIXSocket' do + @socket = @server.accept_nonblock + @socket.should be_an_instance_of(UNIXSocket) end end - describe 'with a client' do + describe 'with data available' do before do - @client = UNIXSocket.new(@path) - end - - after do - @client.close - @socket.close if @socket + @client.write('hello') end - describe 'without any data' do - it 'returns a UNIXSocket' do - @socket = @server.accept_nonblock - @socket.should be_an_instance_of(UNIXSocket) - end + it 'returns a UNIXSocket' do + @socket = @server.accept_nonblock + @socket.should be_an_instance_of(UNIXSocket) end - describe 'with data available' do - before do - @client.write('hello') - end - - it 'returns a UNIXSocket' do + describe 'the returned UNIXSocket' do + it 'can read the data written' do @socket = @server.accept_nonblock - @socket.should be_an_instance_of(UNIXSocket) - end - - describe 'the returned UNIXSocket' do - it 'can read the data written' do - @socket = @server.accept_nonblock - @socket.recv(5).should == 'hello' - end + @socket.recv(5).should == 'hello' end end end diff --git a/spec/ruby/library/socket/unixserver/accept_spec.rb b/spec/ruby/library/socket/unixserver/accept_spec.rb index c05fbe7f22..cc2c922b6f 100644 --- a/spec/ruby/library/socket/unixserver/accept_spec.rb +++ b/spec/ruby/library/socket/unixserver/accept_spec.rb @@ -1,115 +1,124 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -platform_is_not :windows do - describe "UNIXServer#accept" do - before :each do - @path = SocketSpecs.socket_path - @server = UNIXServer.open(@path) - end +describe "UNIXServer#accept" do + before :each do + @path = SocketSpecs.socket_path + @server = UNIXServer.open(@path) + end - after :each do - @server.close if @server - SocketSpecs.rm_socket @path - end + after :each do + @server.close if @server + SocketSpecs.rm_socket @path + end - it "accepts what is written by the client" do - client = UNIXSocket.open(@path) + it "accepts what is written by the client" do + client = UNIXSocket.open(@path) - client.send('hello', 0) + client.send('hello', 0) - sock = @server.accept - begin - data, info = sock.recvfrom(5) + sock = @server.accept + begin + data, info = sock.recvfrom(5) - data.should == 'hello' - info.should_not be_empty - ensure - sock.close - client.close - end + data.should == 'hello' + info.should_not be_empty + ensure + sock.close + client.close end + end - it "can be interrupted by Thread#kill" do - t = Thread.new { - @server.accept - } - Thread.pass while t.status and t.status != "sleep" - - # kill thread, ensure it dies in a reasonable amount of time - t.kill - a = 0 - while t.alive? and a < 5000 - sleep 0.001 - a += 1 - end - a.should < 5000 + it "can be interrupted by Thread#kill" do + t = Thread.new { + @server.accept + } + Thread.pass while t.status and t.status != "sleep" + + # kill thread, ensure it dies in a reasonable amount of time + t.kill + a = 0 + while t.alive? and a < 5000 + sleep 0.001 + a += 1 end + a.should < 5000 + end - it "can be interrupted by Thread#raise" do - t = Thread.new { - -> { - @server.accept - }.should raise_error(Exception, "interrupted") - } + it "can be interrupted by Thread#raise" do + t = Thread.new { + -> { + @server.accept + }.should raise_error(Exception, "interrupted") + } - Thread.pass while t.status and t.status != "sleep" - t.raise Exception, "interrupted" - t.join - end + Thread.pass while t.status and t.status != "sleep" + t.raise Exception, "interrupted" + t.join end end -with_feature :unix_socket do - describe 'UNIXServer#accept' do +describe 'UNIXServer#accept' do + before do + @path = SocketSpecs.socket_path + @server = UNIXServer.new(@path) + end + + after do + @server.close + rm_r(@path) + end + + describe 'without a client' do + it 'blocks the calling thread' do + -> { @server.accept }.should block_caller + end + end + + describe 'with a client' do before do - @path = SocketSpecs.socket_path - @server = UNIXServer.new(@path) + @client = UNIXSocket.new(@path) end after do - @server.close - rm_r(@path) + @client.close + @socket.close if @socket end - describe 'without a client' do - it 'blocks the calling thread' do - -> { @server.accept }.should block_caller + describe 'without any data' do + it 'returns a UNIXSocket' do + @socket = @server.accept + @socket.should be_an_instance_of(UNIXSocket) end end - describe 'with a client' do + describe 'with data available' do before do - @client = UNIXSocket.new(@path) + @client.write('hello') end - after do - @client.close - @socket.close if @socket + it 'returns a UNIXSocket' do + @socket = @server.accept + @socket.should be_an_instance_of(UNIXSocket) end - describe 'without any data' do - it 'returns a UNIXSocket' do + describe 'the returned UNIXSocket' do + it 'can read the data written' do @socket = @server.accept - @socket.should be_an_instance_of(UNIXSocket) + @socket.recv(5).should == 'hello' end - end - describe 'with data available' do - before do - @client.write('hello') + platform_is_not :windows do + it "is set to nonblocking" do + require 'io/nonblock' + @socket = @server.accept + @socket.should.nonblock? + end end - it 'returns a UNIXSocket' do + it "is set to close on exec" do @socket = @server.accept - @socket.should be_an_instance_of(UNIXSocket) - end - - describe 'the returned UNIXSocket' do - it 'can read the data written' do - @socket = @server.accept - @socket.recv(5).should == 'hello' - end + @socket.should.close_on_exec? end end end diff --git a/spec/ruby/library/socket/unixserver/for_fd_spec.rb b/spec/ruby/library/socket/unixserver/for_fd_spec.rb index 4f3816ad37..be1c2df4d7 100644 --- a/spec/ruby/library/socket/unixserver/for_fd_spec.rb +++ b/spec/ruby/library/socket/unixserver/for_fd_spec.rb @@ -1,23 +1,21 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -platform_is_not :windows do - describe "UNIXServer#for_fd" do - before :each do - @unix_path = SocketSpecs.socket_path - @unix = UNIXServer.new(@unix_path) - end +describe "UNIXServer.for_fd" do + before :each do + @unix_path = SocketSpecs.socket_path + @unix = UNIXServer.new(@unix_path) + end - after :each do - @unix.close if @unix - SocketSpecs.rm_socket @unix_path - end + after :each do + @unix.close if @unix + SocketSpecs.rm_socket @unix_path + end - it "can calculate the path" do - b = UNIXServer.for_fd(@unix.fileno) - b.autoclose = false + it "can calculate the path" do + b = UNIXServer.for_fd(@unix.fileno) + b.autoclose = false - b.path.should == @unix_path - end + b.path.should == @unix_path end end diff --git a/spec/ruby/library/socket/unixserver/initialize_spec.rb b/spec/ruby/library/socket/unixserver/initialize_spec.rb index 0cc49ef1eb..3728a307b0 100644 --- a/spec/ruby/library/socket/unixserver/initialize_spec.rb +++ b/spec/ruby/library/socket/unixserver/initialize_spec.rb @@ -1,28 +1,26 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -with_feature :unix_socket do - describe 'UNIXServer#initialize' do - before do - @path = SocketSpecs.socket_path - @server = UNIXServer.new(@path) - end +describe 'UNIXServer#initialize' do + before do + @path = SocketSpecs.socket_path + @server = UNIXServer.new(@path) + end - after do - @server.close if @server - rm_r @path - end + after do + @server.close if @server + rm_r @path + end - it 'returns a new UNIXServer' do - @server.should be_an_instance_of(UNIXServer) - end + it 'returns a new UNIXServer' do + @server.should be_an_instance_of(UNIXServer) + end - it 'sets the socket to binmode' do - @server.binmode?.should be_true - end + it 'sets the socket to binmode' do + @server.binmode?.should be_true + end - it 'raises Errno::EADDRINUSE when the socket is already in use' do - -> { UNIXServer.new(@path) }.should raise_error(Errno::EADDRINUSE) - end + it 'raises Errno::EADDRINUSE when the socket is already in use' do + -> { UNIXServer.new(@path) }.should raise_error(Errno::EADDRINUSE) end end diff --git a/spec/ruby/library/socket/unixserver/listen_spec.rb b/spec/ruby/library/socket/unixserver/listen_spec.rb index b90b3bbb09..7938d648c4 100644 --- a/spec/ruby/library/socket/unixserver/listen_spec.rb +++ b/spec/ruby/library/socket/unixserver/listen_spec.rb @@ -1,21 +1,19 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -with_feature :unix_socket do - describe 'UNIXServer#listen' do - before do - @path = SocketSpecs.socket_path - @server = UNIXServer.new(@path) - end +describe 'UNIXServer#listen' do + before do + @path = SocketSpecs.socket_path + @server = UNIXServer.new(@path) + end - after do - @server.close + after do + @server.close - rm_r(@path) - end + rm_r(@path) + end - it 'returns 0' do - @server.listen(1).should == 0 - end + it 'returns 0' do + @server.listen(1).should == 0 end end diff --git a/spec/ruby/library/socket/unixserver/new_spec.rb b/spec/ruby/library/socket/unixserver/new_spec.rb index f831f40bc6..7d0c7bf76e 100644 --- a/spec/ruby/library/socket/unixserver/new_spec.rb +++ b/spec/ruby/library/socket/unixserver/new_spec.rb @@ -3,4 +3,10 @@ require_relative 'shared/new' describe "UNIXServer.new" do it_behaves_like :unixserver_new, :new + + it "does not use the given block and warns to use UNIXServer::open" do + -> { + @server = UNIXServer.new(@path) { raise } + }.should complain(/warning: UNIXServer::new\(\) does not take block; use UNIXServer::open\(\) instead/) + end end diff --git a/spec/ruby/library/socket/unixserver/open_spec.rb b/spec/ruby/library/socket/unixserver/open_spec.rb index f2506d9f6f..c49df802d0 100644 --- a/spec/ruby/library/socket/unixserver/open_spec.rb +++ b/spec/ruby/library/socket/unixserver/open_spec.rb @@ -5,22 +5,20 @@ require_relative 'shared/new' describe "UNIXServer.open" do it_behaves_like :unixserver_new, :open - platform_is_not :windows do - before :each do - @path = SocketSpecs.socket_path - end + before :each do + @path = SocketSpecs.socket_path + end - after :each do - @server.close if @server - @server = nil - SocketSpecs.rm_socket @path - end + after :each do + @server.close if @server + @server = nil + SocketSpecs.rm_socket @path + end - it "yields the new UNIXServer object to the block, if given" do - UNIXServer.open(@path) do |unix| - unix.path.should == @path - unix.addr.should == ["AF_UNIX", @path] - end + it "yields the new UNIXServer object to the block, if given" do + UNIXServer.open(@path) do |unix| + unix.path.should == @path + unix.addr.should == ["AF_UNIX", @path] end end end diff --git a/spec/ruby/library/socket/unixserver/shared/new.rb b/spec/ruby/library/socket/unixserver/shared/new.rb index 35395826c9..b537f2a871 100644 --- a/spec/ruby/library/socket/unixserver/shared/new.rb +++ b/spec/ruby/library/socket/unixserver/shared/new.rb @@ -2,21 +2,19 @@ require_relative '../../spec_helper' require_relative '../../fixtures/classes' describe :unixserver_new, shared: true do - platform_is_not :windows do - before :each do - @path = SocketSpecs.socket_path - end + before :each do + @path = SocketSpecs.socket_path + end - after :each do - @server.close if @server - @server = nil - SocketSpecs.rm_socket @path - end + after :each do + @server.close if @server + @server = nil + SocketSpecs.rm_socket @path + end - it "creates a new UNIXServer" do - @server = UNIXServer.send(@method, @path) - @server.path.should == @path - @server.addr.should == ["AF_UNIX", @path] - end + it "creates a new UNIXServer" do + @server = UNIXServer.send(@method, @path) + @server.path.should == @path + @server.addr.should == ["AF_UNIX", @path] end end diff --git a/spec/ruby/library/socket/unixserver/sysaccept_spec.rb b/spec/ruby/library/socket/unixserver/sysaccept_spec.rb index e59731878a..c4a4ecc824 100644 --- a/spec/ruby/library/socket/unixserver/sysaccept_spec.rb +++ b/spec/ruby/library/socket/unixserver/sysaccept_spec.rb @@ -1,51 +1,49 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -with_feature :unix_socket do - describe 'UNIXServer#sysaccept' do +describe 'UNIXServer#sysaccept' do + before do + @path = SocketSpecs.socket_path + @server = UNIXServer.new(@path) + end + + after do + @server.close + + rm_r(@path) + end + + describe 'without a client' do + it 'blocks the calling thread' do + -> { @server.sysaccept }.should block_caller + end + end + + describe 'with a client' do before do - @path = SocketSpecs.socket_path - @server = UNIXServer.new(@path) + @client = UNIXSocket.new(@path) end after do - @server.close - - rm_r(@path) + Socket.for_fd(@fd).close if @fd + @client.close end - describe 'without a client' do - it 'blocks the calling thread' do - -> { @server.sysaccept }.should block_caller + describe 'without any data' do + it 'returns an Integer' do + @fd = @server.sysaccept + @fd.should be_kind_of(Integer) end end - describe 'with a client' do + describe 'with data available' do before do - @client = UNIXSocket.new(@path) - end - - after do - Socket.for_fd(@fd).close if @fd - @client.close + @client.write('hello') end - describe 'without any data' do - it 'returns an Integer' do - @fd = @server.sysaccept - @fd.should be_kind_of(Integer) - end - end - - describe 'with data available' do - before do - @client.write('hello') - end - - it 'returns an Integer' do - @fd = @server.sysaccept - @fd.should be_kind_of(Integer) - end + it 'returns an Integer' do + @fd = @server.sysaccept + @fd.should be_kind_of(Integer) end end end diff --git a/spec/ruby/library/socket/unixsocket/addr_spec.rb b/spec/ruby/library/socket/unixsocket/addr_spec.rb index e8431bea16..1afe9b12dc 100644 --- a/spec/ruby/library/socket/unixsocket/addr_spec.rb +++ b/spec/ruby/library/socket/unixsocket/addr_spec.rb @@ -2,35 +2,32 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' describe "UNIXSocket#addr" do + before :each do + @path = SocketSpecs.socket_path + @server = UNIXServer.open(@path) + @client = UNIXSocket.open(@path) + end - platform_is_not :windows do - before :each do - @path = SocketSpecs.socket_path - @server = UNIXServer.open(@path) - @client = UNIXSocket.open(@path) - end - - after :each do - @client.close - @server.close - SocketSpecs.rm_socket @path - end + after :each do + @client.close + @server.close + SocketSpecs.rm_socket @path + end - it "returns an array" do - @client.addr.should be_kind_of(Array) - end + it "returns an array" do + @client.addr.should be_kind_of(Array) + end - it "returns the address family of this socket in an array" do - @client.addr[0].should == "AF_UNIX" - @server.addr[0].should == "AF_UNIX" - end + it "returns the address family of this socket in an array" do + @client.addr[0].should == "AF_UNIX" + @server.addr[0].should == "AF_UNIX" + end - it "returns the path of the socket in an array if it's a server" do - @server.addr[1].should == @path - end + it "returns the path of the socket in an array if it's a server" do + @server.addr[1].should == @path + end - it "returns an empty string for path if it's a client" do - @client.addr[1].should == "" - end + it "returns an empty string for path if it's a client" do + @client.addr[1].should == "" end end diff --git a/spec/ruby/library/socket/unixsocket/initialize_spec.rb b/spec/ruby/library/socket/unixsocket/initialize_spec.rb index 13b6972f03..5dccfcc745 100644 --- a/spec/ruby/library/socket/unixsocket/initialize_spec.rb +++ b/spec/ruby/library/socket/unixsocket/initialize_spec.rb @@ -1,38 +1,56 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -with_feature :unix_socket do - describe 'UNIXSocket#initialize' do - describe 'using a non existing path' do +describe 'UNIXSocket#initialize' do + describe 'using a non existing path' do + platform_is_not :windows do it 'raises Errno::ENOENT' do -> { UNIXSocket.new(SocketSpecs.socket_path) }.should raise_error(Errno::ENOENT) end end - describe 'using an existing socket path' do - before do - @path = SocketSpecs.socket_path - @server = UNIXServer.new(@path) - @socket = UNIXSocket.new(@path) + platform_is :windows do + # Why, Windows, why? + it 'raises Errno::ECONNREFUSED' do + -> { UNIXSocket.new(SocketSpecs.socket_path) }.should raise_error(Errno::ECONNREFUSED) end + end + end - after do - @socket.close - @server.close - rm_r(@path) - end + describe 'using an existing socket path' do + before do + @path = SocketSpecs.socket_path + @server = UNIXServer.new(@path) + @socket = UNIXSocket.new(@path) + end - it 'returns a new UNIXSocket' do - @socket.should be_an_instance_of(UNIXSocket) - end + after do + @socket.close + @server.close + rm_r(@path) + end - it 'sets the socket path to an empty String' do - @socket.path.should == '' - end + it 'returns a new UNIXSocket' do + @socket.should be_an_instance_of(UNIXSocket) + end + + it 'sets the socket path to an empty String' do + @socket.path.should == '' + end - it 'sets the socket to binmode' do - @socket.binmode?.should be_true + it 'sets the socket to binmode' do + @socket.binmode?.should be_true + end + + platform_is_not :windows do + it 'sets the socket to nonblock' do + require 'io/nonblock' + @socket.should.nonblock? end end + + it 'sets the socket to close on exec' do + @socket.should.close_on_exec? + end end end diff --git a/spec/ruby/library/socket/unixsocket/inspect_spec.rb b/spec/ruby/library/socket/unixsocket/inspect_spec.rb index d2e3cabbd3..77bb521069 100644 --- a/spec/ruby/library/socket/unixsocket/inspect_spec.rb +++ b/spec/ruby/library/socket/unixsocket/inspect_spec.rb @@ -2,16 +2,14 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' describe "UNIXSocket#inspect" do - platform_is_not :windows do - it "returns sockets fd for unnamed sockets" do - begin - s1, s2 = UNIXSocket.socketpair - s1.inspect.should == "#<UNIXSocket:fd #{s1.fileno}>" - s2.inspect.should == "#<UNIXSocket:fd #{s2.fileno}>" - ensure - s1.close - s2.close - end + it "returns sockets fd for unnamed sockets" do + begin + s1, s2 = UNIXSocket.socketpair + s1.inspect.should == "#<UNIXSocket:fd #{s1.fileno}>" + s2.inspect.should == "#<UNIXSocket:fd #{s2.fileno}>" + ensure + s1.close + s2.close end end end diff --git a/spec/ruby/library/socket/unixsocket/local_address_spec.rb b/spec/ruby/library/socket/unixsocket/local_address_spec.rb index cbf315f9f4..0fdec38293 100644 --- a/spec/ruby/library/socket/unixsocket/local_address_spec.rb +++ b/spec/ruby/library/socket/unixsocket/local_address_spec.rb @@ -1,96 +1,92 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -with_feature :unix_socket do - describe 'UNIXSocket#local_address' do - before do - @path = SocketSpecs.socket_path - @server = UNIXServer.new(@path) - @client = UNIXSocket.new(@path) - end +describe 'UNIXSocket#local_address' do + before do + @path = SocketSpecs.socket_path + @server = UNIXServer.new(@path) + @client = UNIXSocket.new(@path) + end - after do - @client.close - @server.close + after do + @client.close + @server.close - rm_r(@path) - end - - it 'returns an Addrinfo' do - @client.local_address.should be_an_instance_of(Addrinfo) - end + rm_r(@path) + end - describe 'the returned Addrinfo' do - platform_is_not :aix do - it 'uses AF_UNIX as the address family' do - @client.local_address.afamily.should == Socket::AF_UNIX - end + it 'returns an Addrinfo' do + @client.local_address.should be_an_instance_of(Addrinfo) + end - it 'uses PF_UNIX as the protocol family' do - @client.local_address.pfamily.should == Socket::PF_UNIX - end + describe 'the returned Addrinfo' do + platform_is_not :aix do + it 'uses AF_UNIX as the address family' do + @client.local_address.afamily.should == Socket::AF_UNIX end - it 'uses SOCK_STREAM as the socket type' do - @client.local_address.socktype.should == Socket::SOCK_STREAM + it 'uses PF_UNIX as the protocol family' do + @client.local_address.pfamily.should == Socket::PF_UNIX end + end - platform_is_not :aix do - it 'uses an empty socket path' do - @client.local_address.unix_path.should == '' - end - end + it 'uses SOCK_STREAM as the socket type' do + @client.local_address.socktype.should == Socket::SOCK_STREAM + end - it 'uses 0 as the protocol' do - @client.local_address.protocol.should == 0 + platform_is_not :aix do + it 'uses an empty socket path' do + @client.local_address.unix_path.should == '' end end + + it 'uses 0 as the protocol' do + @client.local_address.protocol.should == 0 + end end end -with_feature :unix_socket do - describe 'UNIXSocket#local_address with a UNIX socket pair' do - before :each do - @sock, @sock2 = Socket.pair(Socket::AF_UNIX, Socket::SOCK_STREAM) - end +describe 'UNIXSocket#local_address with a UNIX socket pair' do + before :each do + @sock, @sock2 = Socket.pair(Socket::AF_UNIX, Socket::SOCK_STREAM) + end - after :each do - @sock.close - @sock2.close - end + after :each do + @sock.close + @sock2.close + end - it 'returns an Addrinfo' do - @sock.local_address.should be_an_instance_of(Addrinfo) - end + it 'returns an Addrinfo' do + @sock.local_address.should be_an_instance_of(Addrinfo) + end - describe 'the returned Addrinfo' do - it 'uses AF_UNIX as the address family' do - @sock.local_address.afamily.should == Socket::AF_UNIX - end + describe 'the returned Addrinfo' do + it 'uses AF_UNIX as the address family' do + @sock.local_address.afamily.should == Socket::AF_UNIX + end - it 'uses PF_UNIX as the protocol family' do - @sock.local_address.pfamily.should == Socket::PF_UNIX - end + it 'uses PF_UNIX as the protocol family' do + @sock.local_address.pfamily.should == Socket::PF_UNIX + end - it 'uses SOCK_STREAM as the socket type' do - @sock.local_address.socktype.should == Socket::SOCK_STREAM - end + it 'uses SOCK_STREAM as the socket type' do + @sock.local_address.socktype.should == Socket::SOCK_STREAM + end - it 'raises SocketError for #ip_address' do - -> { - @sock.local_address.ip_address - }.should raise_error(SocketError, "need IPv4 or IPv6 address") - end + it 'raises SocketError for #ip_address' do + -> { + @sock.local_address.ip_address + }.should raise_error(SocketError, "need IPv4 or IPv6 address") + end - it 'raises SocketError for #ip_port' do - -> { - @sock.local_address.ip_port - }.should raise_error(SocketError, "need IPv4 or IPv6 address") - end + it 'raises SocketError for #ip_port' do + -> { + @sock.local_address.ip_port + }.should raise_error(SocketError, "need IPv4 or IPv6 address") + end - it 'uses 0 as the protocol' do - @sock.local_address.protocol.should == 0 - end + it 'uses 0 as the protocol' do + @sock.local_address.protocol.should == 0 end end end diff --git a/spec/ruby/library/socket/unixsocket/new_spec.rb b/spec/ruby/library/socket/unixsocket/new_spec.rb index 05a6b3eda2..fea2c1e2b7 100644 --- a/spec/ruby/library/socket/unixsocket/new_spec.rb +++ b/spec/ruby/library/socket/unixsocket/new_spec.rb @@ -3,4 +3,10 @@ require_relative 'shared/new' describe "UNIXSocket.new" do it_behaves_like :unixsocket_new, :new + + it "does not use the given block and warns to use UNIXSocket::open" do + -> { + @client = UNIXSocket.new(@path) { raise } + }.should complain(/warning: UNIXSocket::new\(\) does not take block; use UNIXSocket::open\(\) instead/) + end end diff --git a/spec/ruby/library/socket/unixsocket/open_spec.rb b/spec/ruby/library/socket/unixsocket/open_spec.rb index 99ad151bb8..b5e8c6c23a 100644 --- a/spec/ruby/library/socket/unixsocket/open_spec.rb +++ b/spec/ruby/library/socket/unixsocket/open_spec.rb @@ -7,22 +7,20 @@ describe "UNIXSocket.open" do end describe "UNIXSocket.open" do - platform_is_not :windows do - before :each do - @path = SocketSpecs.socket_path - @server = UNIXServer.open(@path) - end + before :each do + @path = SocketSpecs.socket_path + @server = UNIXServer.open(@path) + end - after :each do - @server.close - SocketSpecs.rm_socket @path - end + after :each do + @server.close + SocketSpecs.rm_socket @path + end - it "opens a unix socket on the specified file and yields it to the block" do - UNIXSocket.open(@path) do |client| - client.addr[0].should == "AF_UNIX" - client.should_not.closed? - end + it "opens a unix socket on the specified file and yields it to the block" do + UNIXSocket.open(@path) do |client| + client.addr[0].should == "AF_UNIX" + client.should_not.closed? end end end diff --git a/spec/ruby/library/socket/unixsocket/pair_spec.rb b/spec/ruby/library/socket/unixsocket/pair_spec.rb index 845ff76ecc..9690142668 100644 --- a/spec/ruby/library/socket/unixsocket/pair_spec.rb +++ b/spec/ruby/library/socket/unixsocket/pair_spec.rb @@ -1,39 +1,18 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' require_relative '../shared/partially_closable_sockets' +require_relative 'shared/pair' -describe "UNIXSocket#pair" do - platform_is_not :windows do +describe "UNIXSocket.pair" do + it_should_behave_like :unixsocket_pair + it_should_behave_like :partially_closable_sockets - it_should_behave_like "partially closable sockets" - - before :each do - @s1, @s2 = UNIXSocket.pair - end - - after :each do - @s1.close - @s2.close - end - - it "returns a pair of connected sockets" do - @s1.puts "foo" - @s2.gets.should == "foo\n" - end - - it "returns sockets with no name" do - @s1.path.should == @s2.path - @s1.path.should == "" - end - - it "returns sockets with no address" do - @s1.addr.should == ["AF_UNIX", ""] - @s2.addr.should == ["AF_UNIX", ""] - end + before :each do + @s1, @s2 = UNIXSocket.pair + end - it "returns sockets with no peeraddr" do - @s1.peeraddr.should == ["AF_UNIX", ""] - @s2.peeraddr.should == ["AF_UNIX", ""] - end + after :each do + @s1.close + @s2.close end end diff --git a/spec/ruby/library/socket/unixsocket/partially_closable_spec.rb b/spec/ruby/library/socket/unixsocket/partially_closable_spec.rb index 78a64fe6be..108a6c3063 100644 --- a/spec/ruby/library/socket/unixsocket/partially_closable_spec.rb +++ b/spec/ruby/library/socket/unixsocket/partially_closable_spec.rb @@ -2,24 +2,20 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' require_relative '../shared/partially_closable_sockets' -platform_is_not :windows do - describe "UNIXSocket partial closability" do - - before :each do - @path = SocketSpecs.socket_path - @server = UNIXServer.open(@path) - @s1 = UNIXSocket.new(@path) - @s2 = @server.accept - end - - after :each do - @server.close - @s1.close - @s2.close - SocketSpecs.rm_socket @path - end - - it_should_behave_like "partially closable sockets" +describe "UNIXSocket partial closability" do + before :each do + @path = SocketSpecs.socket_path + @server = UNIXServer.open(@path) + @s1 = UNIXSocket.new(@path) + @s2 = @server.accept + end + after :each do + @server.close + @s1.close + @s2.close + SocketSpecs.rm_socket @path end + + it_should_behave_like :partially_closable_sockets end diff --git a/spec/ruby/library/socket/unixsocket/path_spec.rb b/spec/ruby/library/socket/unixsocket/path_spec.rb index 317ffc0975..ffe7e4bea2 100644 --- a/spec/ruby/library/socket/unixsocket/path_spec.rb +++ b/spec/ruby/library/socket/unixsocket/path_spec.rb @@ -2,27 +2,23 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' describe "UNIXSocket#path" do + before :each do + @path = SocketSpecs.socket_path + @server = UNIXServer.open(@path) + @client = UNIXSocket.open(@path) + end - platform_is_not :windows do - before :each do - @path = SocketSpecs.socket_path - @server = UNIXServer.open(@path) - @client = UNIXSocket.open(@path) - end - - after :each do - @client.close - @server.close - SocketSpecs.rm_socket @path - end - - it "returns the path of the socket if it's a server" do - @server.path.should == @path - end + after :each do + @client.close + @server.close + SocketSpecs.rm_socket @path + end - it "returns an empty string for path if it's a client" do - @client.path.should == "" - end + it "returns the path of the socket if it's a server" do + @server.path.should == @path end + it "returns an empty string for path if it's a client" do + @client.path.should == "" + end end diff --git a/spec/ruby/library/socket/unixsocket/peeraddr_spec.rb b/spec/ruby/library/socket/unixsocket/peeraddr_spec.rb index 0b6b1ccf04..10cab13b42 100644 --- a/spec/ruby/library/socket/unixsocket/peeraddr_spec.rb +++ b/spec/ruby/library/socket/unixsocket/peeraddr_spec.rb @@ -2,29 +2,25 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' describe "UNIXSocket#peeraddr" do + before :each do + @path = SocketSpecs.socket_path + @server = UNIXServer.open(@path) + @client = UNIXSocket.open(@path) + end - platform_is_not :windows do - before :each do - @path = SocketSpecs.socket_path - @server = UNIXServer.open(@path) - @client = UNIXSocket.open(@path) - end - - after :each do - @client.close - @server.close - SocketSpecs.rm_socket @path - end - - it "returns the address family and path of the server end of the connection" do - @client.peeraddr.should == ["AF_UNIX", @path] - end + after :each do + @client.close + @server.close + SocketSpecs.rm_socket @path + end - it "raises an error in server sockets" do - -> { - @server.peeraddr - }.should raise_error(Errno::ENOTCONN) - end + it "returns the address family and path of the server end of the connection" do + @client.peeraddr.should == ["AF_UNIX", @path] end + it "raises an error in server sockets" do + -> { + @server.peeraddr + }.should raise_error(Errno::ENOTCONN) + end end diff --git a/spec/ruby/library/socket/unixsocket/recv_io_spec.rb b/spec/ruby/library/socket/unixsocket/recv_io_spec.rb index 533f02a0fa..f0b408f309 100644 --- a/spec/ruby/library/socket/unixsocket/recv_io_spec.rb +++ b/spec/ruby/library/socket/unixsocket/recv_io_spec.rb @@ -1,9 +1,8 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -describe "UNIXSocket#recv_io" do - - platform_is_not :windows do +platform_is_not :windows do + describe "UNIXSocket#recv_io" do before :each do @path = SocketSpecs.socket_path @server = UNIXServer.open(@path) @@ -41,9 +40,7 @@ describe "UNIXSocket#recv_io" do @io.should be_an_instance_of(File) end end -end -with_feature :unix_socket do describe 'UNIXSocket#recv_io' do before do @file = File.open('/dev/null', 'w') diff --git a/spec/ruby/library/socket/unixsocket/recvfrom_spec.rb b/spec/ruby/library/socket/unixsocket/recvfrom_spec.rb index c0e1cf670b..9ae3777961 100644 --- a/spec/ruby/library/socket/unixsocket/recvfrom_spec.rb +++ b/spec/ruby/library/socket/unixsocket/recvfrom_spec.rb @@ -2,35 +2,104 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' describe "UNIXSocket#recvfrom" do - platform_is_not :windows do - before :each do - @path = SocketSpecs.socket_path - @server = UNIXServer.open(@path) - @client = UNIXSocket.open(@path) + before :each do + @path = SocketSpecs.socket_path + @server = UNIXServer.open(@path) + @client = UNIXSocket.open(@path) + end + + after :each do + @client.close + @server.close + SocketSpecs.rm_socket @path + end + + it "receives len bytes from sock, returning an array containing sent data as first element" do + @client.send("foobar", 0) + sock = @server.accept + sock.recvfrom(6).first.should == "foobar" + sock.close + end + + context "when called on a server's socket" do + platform_is_not :windows do + it "returns an array containing basic information on the client as second element" do + @client.send("foobar", 0) + sock = @server.accept + data = sock.recvfrom(6) + data.last.should == ["AF_UNIX", ""] + sock.close + end end - after :each do - @client.close - @server.close - SocketSpecs.rm_socket @path + guard -> { platform_is :windows and ruby_bug "#21702", ""..."4.2" } do + it "returns an array containing basic information on the client as second element" do + @client.send("foobar", 0) + sock = @server.accept + data = sock.recvfrom(6) + data.last.should == ["AF_UNIX", ""] + sock.close + end end + end - it "receives len bytes from sock" do - @client.send("foobar", 0) - sock = @server.accept - sock.recvfrom(6).first.should == "foobar" - sock.close + context "when called on a client's socket" do + platform_is :linux do + it "returns an array containing server's address as second element" do + @client.send("", 0) + sock = @server.accept + sock.send("barfoo", 0) + @client.recvfrom(6).last.should == ["AF_UNIX", @server.local_address.unix_path] + sock.close + end end - it "returns an array with data and information on the sender" do - @client.send("foobar", 0) - sock = @server.accept - data = sock.recvfrom(6) - data.first.should == "foobar" - data.last.should == ["AF_UNIX", ""] - sock.close + guard -> { platform_is :windows and ruby_bug "#21702", ""..."4.2" } do + it "returns an array containing server's address as second element" do + @client.send("", 0) + sock = @server.accept + sock.send("barfoo", 0) + # This may not be correct, depends on what underlying recvfrom actually returns. + @client.recvfrom(6).last.should == ["AF_UNIX", @server.local_address.unix_path] + sock.close + end end + platform_is :darwin do + it "returns an array containing basic information on the server as second element" do + @client.send("", 0) + sock = @server.accept + sock.send("barfoo", 0) + @client.recvfrom(6).last.should == ["AF_UNIX", ""] + sock.close + end + end + end + + it "allows an output buffer as third argument" do + buffer = +'' + + @client.send("foobar", 0) + sock = @server.accept + message, = sock.recvfrom(6, 0, buffer) + sock.close + + message.should.equal?(buffer) + buffer.should == "foobar" + end + + it "preserves the encoding of the given buffer" do + buffer = ''.encode(Encoding::ISO_8859_1) + + @client.send("foobar", 0) + sock = @server.accept + sock.recvfrom(6, 0, buffer) + sock.close + + buffer.encoding.should == Encoding::ISO_8859_1 + end + + platform_is_not :windows do it "uses different message options" do @client.send("foobar", Socket::MSG_PEEK) sock = @server.accept @@ -44,25 +113,32 @@ describe "UNIXSocket#recvfrom" do end end +describe 'UNIXSocket#recvfrom' do + describe 'using a socket pair' do + before do + @client, @server = UNIXSocket.socketpair + @client.write('hello') + end -with_feature :unix_socket do - describe 'UNIXSocket#recvfrom' do - describe 'using a socket pair' do - before do - @client, @server = UNIXSocket.socketpair - @client.write('hello') - end + after do + @client.close + @server.close + end - after do - @client.close - @server.close + platform_is_not :windows do + it 'returns an Array containing the data and address information' do + @server.recvfrom(5).should == ['hello', ['AF_UNIX', '']] end + end + guard -> { platform_is :windows and ruby_bug "#21702", ""..."4.2" } do it 'returns an Array containing the data and address information' do @server.recvfrom(5).should == ['hello', ['AF_UNIX', '']] end end + end + platform_is_not :windows do # These specs are taken from the rdoc examples on UNIXSocket#recvfrom. describe 'using a UNIX socket constructed using UNIXSocket.for_fd' do before do diff --git a/spec/ruby/library/socket/unixsocket/remote_address_spec.rb b/spec/ruby/library/socket/unixsocket/remote_address_spec.rb index 0b416254d0..84bdff0a6a 100644 --- a/spec/ruby/library/socket/unixsocket/remote_address_spec.rb +++ b/spec/ruby/library/socket/unixsocket/remote_address_spec.rb @@ -1,45 +1,43 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -with_feature :unix_socket do - describe 'UNIXSocket#remote_address' do - before do - @path = SocketSpecs.socket_path - @server = UNIXServer.new(@path) - @client = UNIXSocket.new(@path) - end +describe 'UNIXSocket#remote_address' do + before do + @path = SocketSpecs.socket_path + @server = UNIXServer.new(@path) + @client = UNIXSocket.new(@path) + end - after do - @client.close - @server.close + after do + @client.close + @server.close - rm_r(@path) - end + rm_r(@path) + end - it 'returns an Addrinfo' do - @client.remote_address.should be_an_instance_of(Addrinfo) - end + it 'returns an Addrinfo' do + @client.remote_address.should be_an_instance_of(Addrinfo) + end - describe 'the returned Addrinfo' do - it 'uses AF_UNIX as the address family' do - @client.remote_address.afamily.should == Socket::AF_UNIX - end + describe 'the returned Addrinfo' do + it 'uses AF_UNIX as the address family' do + @client.remote_address.afamily.should == Socket::AF_UNIX + end - it 'uses PF_UNIX as the protocol family' do - @client.remote_address.pfamily.should == Socket::PF_UNIX - end + it 'uses PF_UNIX as the protocol family' do + @client.remote_address.pfamily.should == Socket::PF_UNIX + end - it 'uses SOCK_STREAM as the socket type' do - @client.remote_address.socktype.should == Socket::SOCK_STREAM - end + it 'uses SOCK_STREAM as the socket type' do + @client.remote_address.socktype.should == Socket::SOCK_STREAM + end - it 'uses the correct socket path' do - @client.remote_address.unix_path.should == @path - end + it 'uses the correct socket path' do + @client.remote_address.unix_path.should == @path + end - it 'uses 0 as the protocol' do - @client.remote_address.protocol.should == 0 - end + it 'uses 0 as the protocol' do + @client.remote_address.protocol.should == 0 end end end diff --git a/spec/ruby/library/socket/unixsocket/send_io_spec.rb b/spec/ruby/library/socket/unixsocket/send_io_spec.rb index a2a7d26539..52186ec3cf 100644 --- a/spec/ruby/library/socket/unixsocket/send_io_spec.rb +++ b/spec/ruby/library/socket/unixsocket/send_io_spec.rb @@ -1,9 +1,8 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -describe "UNIXSocket#send_io" do - - platform_is_not :windows do +platform_is_not :windows do + describe "UNIXSocket#send_io" do before :each do @path = SocketSpecs.socket_path @server = UNIXServer.open(@path) @@ -32,9 +31,7 @@ describe "UNIXSocket#send_io" do @io.read.should == File.read(@send_io_path) end end -end -with_feature :unix_socket do describe 'UNIXSocket#send_io' do before do @file = File.open('/dev/null', 'w') diff --git a/spec/ruby/library/socket/unixsocket/shared/new.rb b/spec/ruby/library/socket/unixsocket/shared/new.rb index bfb7ed3886..f075b03c5e 100644 --- a/spec/ruby/library/socket/unixsocket/shared/new.rb +++ b/spec/ruby/library/socket/unixsocket/shared/new.rb @@ -2,23 +2,21 @@ require_relative '../../spec_helper' require_relative '../../fixtures/classes' describe :unixsocket_new, shared: true do - platform_is_not :windows do - before :each do - @path = SocketSpecs.socket_path - @server = UNIXServer.open(@path) - end + before :each do + @path = SocketSpecs.socket_path + @server = UNIXServer.open(@path) + end - after :each do - @client.close if @client - @server.close - SocketSpecs.rm_socket @path - end + after :each do + @client.close if @client + @server.close + SocketSpecs.rm_socket @path + end - it "opens a unix socket on the specified file" do - @client = UNIXSocket.send(@method, @path) + it "opens a unix socket on the specified file" do + @client = UNIXSocket.send(@method, @path) - @client.addr[0].should == "AF_UNIX" - @client.should_not.closed? - end + @client.addr[0].should == "AF_UNIX" + @client.should_not.closed? end end diff --git a/spec/ruby/library/socket/unixsocket/shared/pair.rb b/spec/ruby/library/socket/unixsocket/shared/pair.rb new file mode 100644 index 0000000000..d68ee466bf --- /dev/null +++ b/spec/ruby/library/socket/unixsocket/shared/pair.rb @@ -0,0 +1,47 @@ +require_relative '../../spec_helper' +require_relative '../../fixtures/classes' + +describe :unixsocket_pair, shared: true do + it "returns two UNIXSockets" do + @s1.should be_an_instance_of(UNIXSocket) + @s2.should be_an_instance_of(UNIXSocket) + end + + it "returns a pair of connected sockets" do + @s1.puts "foo" + @s2.gets.should == "foo\n" + end + + platform_is_not :windows do + it "sets the socket paths to empty Strings" do + @s1.path.should == "" + @s2.path.should == "" + end + + it "sets the socket addresses to empty Strings" do + @s1.addr.should == ["AF_UNIX", ""] + @s2.addr.should == ["AF_UNIX", ""] + end + + it "sets the socket peer addresses to empty Strings" do + @s1.peeraddr.should == ["AF_UNIX", ""] + @s2.peeraddr.should == ["AF_UNIX", ""] + end + end + + platform_is :windows do + it "emulates unnamed sockets with a temporary file with a path" do + @s1.addr.should == ["AF_UNIX", @s1.path] + @s2.peeraddr.should == ["AF_UNIX", @s1.path] + end + + it "sets the peer address of first socket to an empty string" do + @s1.peeraddr.should == ["AF_UNIX", ""] + end + + it "sets the address and path of second socket to an empty string" do + @s2.addr.should == ["AF_UNIX", ""] + @s2.path.should == "" + end + end +end diff --git a/spec/ruby/library/socket/unixsocket/socketpair_spec.rb b/spec/ruby/library/socket/unixsocket/socketpair_spec.rb index 3e9646f76b..c61fc00be4 100644 --- a/spec/ruby/library/socket/unixsocket/socketpair_spec.rb +++ b/spec/ruby/library/socket/unixsocket/socketpair_spec.rb @@ -1,40 +1,18 @@ require_relative '../spec_helper' +require_relative '../fixtures/classes' +require_relative '../shared/partially_closable_sockets' +require_relative 'shared/pair' -with_feature :unix_socket do - describe 'UNIXSocket.socketpair' do - before do - @s1, @s2 = UNIXSocket.socketpair - end +describe "UNIXSocket.socketpair" do + it_should_behave_like :unixsocket_pair + it_should_behave_like :partially_closable_sockets - after do - @s1.close - @s2.close - end - - it 'returns two UNIXSockets' do - @s1.should be_an_instance_of(UNIXSocket) - @s2.should be_an_instance_of(UNIXSocket) - end - - it 'connects the sockets to each other' do - @s1.write('hello') - - @s2.recv(5).should == 'hello' - end - - it 'sets the socket paths to empty Strings' do - @s1.path.should == '' - @s2.path.should == '' - end - - it 'sets the socket addresses to empty Strings' do - @s1.addr.should == ['AF_UNIX', ''] - @s2.addr.should == ['AF_UNIX', ''] - end + before :each do + @s1, @s2 = UNIXSocket.socketpair + end - it 'sets the socket peer addresses to empty Strings' do - @s1.peeraddr.should == ['AF_UNIX', ''] - @s2.peeraddr.should == ['AF_UNIX', ''] - end + after :each do + @s1.close + @s2.close end end diff --git a/spec/ruby/library/stringio/append_spec.rb b/spec/ruby/library/stringio/append_spec.rb index 981229fc10..cb50d73d1b 100644 --- a/spec/ruby/library/stringio/append_spec.rb +++ b/spec/ruby/library/stringio/append_spec.rb @@ -3,7 +3,7 @@ require_relative 'fixtures/classes' describe "StringIO#<< when passed [Object]" do before :each do - @io = StringIO.new("example") + @io = StringIO.new(+"example") end it "returns self" do @@ -29,13 +29,6 @@ describe "StringIO#<< when passed [Object]" do @io.string.should == "example\000\000\000\000\000\000\000\000just testing" end - ruby_version_is ""..."3.0" do - it "does not taint self when the passed argument is tainted" do - (@io << "test".taint) - @io.tainted?.should be_false - end - end - it "updates self's position" do @io << "test" @io.pos.should eql(4) @@ -51,10 +44,10 @@ end describe "StringIO#<< when self is not writable" do it "raises an IOError" do - io = StringIO.new("test", "r") + io = StringIO.new(+"test", "r") -> { io << "test" }.should raise_error(IOError) - io = StringIO.new("test") + io = StringIO.new(+"test") io.close_write -> { io << "test" }.should raise_error(IOError) end @@ -62,7 +55,7 @@ end describe "StringIO#<< when in append mode" do before :each do - @io = StringIO.new("example", "a") + @io = StringIO.new(+"example", "a") end it "appends the passed argument to the end of self, ignoring current position" do diff --git a/spec/ruby/library/stringio/binmode_spec.rb b/spec/ruby/library/stringio/binmode_spec.rb index 853d9c9bd6..9e92c63814 100644 --- a/spec/ruby/library/stringio/binmode_spec.rb +++ b/spec/ruby/library/stringio/binmode_spec.rb @@ -3,7 +3,7 @@ require_relative 'fixtures/classes' describe "StringIO#binmode" do it "returns self" do - io = StringIO.new("example") + io = StringIO.new(+"example") io.binmode.should equal(io) end diff --git a/spec/ruby/library/stringio/bytes_spec.rb b/spec/ruby/library/stringio/bytes_spec.rb deleted file mode 100644 index 4ef7a490a5..0000000000 --- a/spec/ruby/library/stringio/bytes_spec.rb +++ /dev/null @@ -1,29 +0,0 @@ -require_relative '../../spec_helper' -require 'stringio' -require_relative 'shared/each_byte' - -ruby_version_is ''...'3.0' do - describe "StringIO#bytes" do - before :each do - @verbose, $VERBOSE = $VERBOSE, nil - end - - after :each do - $VERBOSE = @verbose - end - - it_behaves_like :stringio_each_byte, :bytes - end - - describe "StringIO#bytes when self is not readable" do - before :each do - @verbose, $VERBOSE = $VERBOSE, nil - end - - after :each do - $VERBOSE = @verbose - end - - it_behaves_like :stringio_each_byte_not_readable, :bytes - end -end diff --git a/spec/ruby/library/stringio/chars_spec.rb b/spec/ruby/library/stringio/chars_spec.rb deleted file mode 100644 index 58cba77634..0000000000 --- a/spec/ruby/library/stringio/chars_spec.rb +++ /dev/null @@ -1,29 +0,0 @@ -require_relative '../../spec_helper' -require 'stringio' -require_relative 'shared/each_char' - -ruby_version_is ''...'3.0' do - describe "StringIO#chars" do - before :each do - @verbose, $VERBOSE = $VERBOSE, nil - end - - after :each do - $VERBOSE = @verbose - end - - it_behaves_like :stringio_each_char, :chars - end - - describe "StringIO#chars when self is not readable" do - before :each do - @verbose, $VERBOSE = $VERBOSE, nil - end - - after :each do - $VERBOSE = @verbose - end - - it_behaves_like :stringio_each_char_not_readable, :chars - end -end diff --git a/spec/ruby/library/stringio/close_read_spec.rb b/spec/ruby/library/stringio/close_read_spec.rb index 80bd547e85..0f08e1ff2e 100644 --- a/spec/ruby/library/stringio/close_read_spec.rb +++ b/spec/ruby/library/stringio/close_read_spec.rb @@ -3,7 +3,7 @@ require_relative 'fixtures/classes' describe "StringIO#close_read" do before :each do - @io = StringIO.new("example") + @io = StringIO.new(+"example") end it "returns nil" do @@ -21,7 +21,7 @@ describe "StringIO#close_read" do end it "raises an IOError when in write-only mode" do - io = StringIO.new("example", "w") + io = StringIO.new(+"example", "w") -> { io.close_read }.should raise_error(IOError) io = StringIO.new("example") diff --git a/spec/ruby/library/stringio/close_write_spec.rb b/spec/ruby/library/stringio/close_write_spec.rb index 1a4cfa113e..c86c3f9826 100644 --- a/spec/ruby/library/stringio/close_write_spec.rb +++ b/spec/ruby/library/stringio/close_write_spec.rb @@ -3,7 +3,7 @@ require_relative 'fixtures/classes' describe "StringIO#close_write" do before :each do - @io = StringIO.new("example") + @io = StringIO.new(+"example") end it "returns nil" do @@ -21,10 +21,10 @@ describe "StringIO#close_write" do end it "raises an IOError when in read-only mode" do - io = StringIO.new("example", "r") + io = StringIO.new(+"example", "r") -> { io.close_write }.should raise_error(IOError) - io = StringIO.new("example") + io = StringIO.new(+"example") io.close_write io.close_write.should == nil end diff --git a/spec/ruby/library/stringio/closed_read_spec.rb b/spec/ruby/library/stringio/closed_read_spec.rb index cb4267ac98..b4dcadc3a4 100644 --- a/spec/ruby/library/stringio/closed_read_spec.rb +++ b/spec/ruby/library/stringio/closed_read_spec.rb @@ -3,7 +3,7 @@ require_relative 'fixtures/classes' describe "StringIO#closed_read?" do it "returns true if self is not readable" do - io = StringIO.new("example", "r+") + io = StringIO.new(+"example", "r+") io.close_write io.closed_read?.should be_false io.close_read diff --git a/spec/ruby/library/stringio/closed_spec.rb b/spec/ruby/library/stringio/closed_spec.rb index ca8a2232a8..bf7ba63184 100644 --- a/spec/ruby/library/stringio/closed_spec.rb +++ b/spec/ruby/library/stringio/closed_spec.rb @@ -3,13 +3,13 @@ require_relative 'fixtures/classes' describe "StringIO#closed?" do it "returns true if self is completely closed" do - io = StringIO.new("example", "r+") + io = StringIO.new(+"example", "r+") io.close_read io.closed?.should be_false io.close_write io.closed?.should be_true - io = StringIO.new("example", "r+") + io = StringIO.new(+"example", "r+") io.close io.closed?.should be_true end diff --git a/spec/ruby/library/stringio/closed_write_spec.rb b/spec/ruby/library/stringio/closed_write_spec.rb index 5c111affd8..2bd3e6fa8b 100644 --- a/spec/ruby/library/stringio/closed_write_spec.rb +++ b/spec/ruby/library/stringio/closed_write_spec.rb @@ -3,7 +3,7 @@ require_relative 'fixtures/classes' describe "StringIO#closed_write?" do it "returns true if self is not writable" do - io = StringIO.new("example", "r+") + io = StringIO.new(+"example", "r+") io.close_read io.closed_write?.should be_false io.close_write diff --git a/spec/ruby/library/stringio/codepoints_spec.rb b/spec/ruby/library/stringio/codepoints_spec.rb deleted file mode 100644 index ceaadefc32..0000000000 --- a/spec/ruby/library/stringio/codepoints_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -# -*- encoding: utf-8 -*- -require_relative '../../spec_helper' -require_relative 'fixtures/classes' -require_relative 'shared/codepoints' - -ruby_version_is ''...'3.0' do - # See redmine #1667 - describe "StringIO#codepoints" do - before :each do - @verbose, $VERBOSE = $VERBOSE, nil - end - - after :each do - $VERBOSE = @verbose - end - - it_behaves_like :stringio_codepoints, :codepoints - end -end diff --git a/spec/ruby/library/stringio/each_line_spec.rb b/spec/ruby/library/stringio/each_line_spec.rb index c68f7dae82..4ac0db7c45 100644 --- a/spec/ruby/library/stringio/each_line_spec.rb +++ b/spec/ruby/library/stringio/each_line_spec.rb @@ -21,3 +21,7 @@ end describe "StringIO#each_line when passed limit" do it_behaves_like :stringio_each_limit, :each_line end + +describe "StringIO#each when passed separator and limit" do + it_behaves_like :stringio_each_separator_and_limit, :each_line +end diff --git a/spec/ruby/library/stringio/each_spec.rb b/spec/ruby/library/stringio/each_spec.rb index 2c30ed5cda..7eb322f3ff 100644 --- a/spec/ruby/library/stringio/each_spec.rb +++ b/spec/ruby/library/stringio/each_spec.rb @@ -25,3 +25,7 @@ end describe "StringIO#each when passed limit" do it_behaves_like :stringio_each_limit, :each end + +describe "StringIO#each when passed separator and limit" do + it_behaves_like :stringio_each_separator_and_limit, :each +end diff --git a/spec/ruby/library/stringio/fileno_spec.rb b/spec/ruby/library/stringio/fileno_spec.rb index eea03a5af3..5a9f440a0f 100644 --- a/spec/ruby/library/stringio/fileno_spec.rb +++ b/spec/ruby/library/stringio/fileno_spec.rb @@ -1,6 +1,5 @@ require_relative '../../spec_helper' -require_relative 'fixtures/classes' -require_relative 'shared/each' +require 'stringio' describe "StringIO#fileno" do it "returns nil" do diff --git a/spec/ruby/library/stringio/fixtures/classes.rb b/spec/ruby/library/stringio/fixtures/classes.rb index bb8dc354cc..832c5457d7 100644 --- a/spec/ruby/library/stringio/fixtures/classes.rb +++ b/spec/ruby/library/stringio/fixtures/classes.rb @@ -4,12 +4,12 @@ class StringSubclass < String; end module StringIOSpecs def self.build - str = <<-EOS + str = <<-EOS each peach pear plum - EOS + EOS StringIO.new(str) end end diff --git a/spec/ruby/library/stringio/flush_spec.rb b/spec/ruby/library/stringio/flush_spec.rb index 17a16dfdd5..4dc58b1d48 100644 --- a/spec/ruby/library/stringio/flush_spec.rb +++ b/spec/ruby/library/stringio/flush_spec.rb @@ -3,7 +3,7 @@ require_relative 'fixtures/classes' describe "StringIO#flush" do it "returns self" do - io = StringIO.new("flush") + io = StringIO.new(+"flush") io.flush.should equal(io) end end diff --git a/spec/ruby/library/stringio/fsync_spec.rb b/spec/ruby/library/stringio/fsync_spec.rb index 8fb2b59a24..85053cb2e5 100644 --- a/spec/ruby/library/stringio/fsync_spec.rb +++ b/spec/ruby/library/stringio/fsync_spec.rb @@ -3,7 +3,7 @@ require_relative 'fixtures/classes' describe "StringIO#fsync" do it "returns zero" do - io = StringIO.new("fsync") + io = StringIO.new(+"fsync") io.fsync.should eql(0) end end diff --git a/spec/ruby/library/stringio/gets_spec.rb b/spec/ruby/library/stringio/gets_spec.rb index d597ec0e45..ac876f0b4f 100644 --- a/spec/ruby/library/stringio/gets_spec.rb +++ b/spec/ruby/library/stringio/gets_spec.rb @@ -1,250 +1,61 @@ require_relative '../../spec_helper' require "stringio" +require_relative "shared/gets" -describe "StringIO#gets when passed [separator]" do - before :each do - @io = StringIO.new("this>is>an>example") - end - - it "returns the data read till the next occurrence of the passed separator" do - @io.gets(">").should == "this>" - @io.gets(">").should == "is>" - @io.gets(">").should == "an>" - @io.gets(">").should == "example" - end - - it "sets $_ to the read content" do - @io.gets(">") - $_.should == "this>" - @io.gets(">") - $_.should == "is>" - @io.gets(">") - $_.should == "an>" - @io.gets(">") - $_.should == "example" - @io.gets(">") - $_.should be_nil - end - - it "accepts string as separator" do - @io.gets("is>") - $_.should == "this>" - @io.gets("an>") - $_.should == "is>an>" - @io.gets("example") - $_.should == "example" - @io.gets("ple") - $_.should be_nil - end - - it "updates self's lineno by one" do - @io.gets(">") - @io.lineno.should eql(1) - - @io.gets(">") - @io.lineno.should eql(2) - - @io.gets(">") - @io.lineno.should eql(3) - end - - it "returns the next paragraph when the passed separator is an empty String" do - io = StringIO.new("this is\n\nan example") - io.gets("").should == "this is\n\n" - io.gets("").should == "an example" - end - - it "returns the remaining content starting at the current position when passed nil" do - io = StringIO.new("this is\n\nan example") - io.pos = 5 - io.gets(nil).should == "is\n\nan example" - end +describe "StringIO#gets" do + describe "when passed [separator]" do + it_behaves_like :stringio_gets_separator, :gets - it "tries to convert the passed separator to a String using #to_str" do - obj = mock('to_str') - obj.should_receive(:to_str).and_return(">") - @io.gets(obj).should == "this>" - end -end - -describe "StringIO#gets when passed no argument" do - before :each do - @io = StringIO.new("this is\nan example\nfor StringIO#gets") - end + it "returns nil if self is at the end" do + @io = StringIO.new("this>is>an>example") - it "returns the data read till the next occurrence of $/ or till eof" do - @io.gets.should == "this is\n" - - begin - old_sep = $/ - suppress_warning {$/ = " "} - @io.gets.should == "an " - @io.gets.should == "example\nfor " - @io.gets.should == "StringIO#gets" - ensure - suppress_warning {$/ = old_sep} + @io.pos = 36 + @io.gets(">").should be_nil + @io.gets(">").should be_nil end end - it "sets $_ to the read content" do - @io.gets - $_.should == "this is\n" - @io.gets - $_.should == "an example\n" - @io.gets - $_.should == "for StringIO#gets" - @io.gets - $_.should be_nil - end - - it "updates self's position" do - @io.gets - @io.pos.should eql(8) - - @io.gets - @io.pos.should eql(19) - - @io.gets - @io.pos.should eql(36) - end - - it "updates self's lineno" do - @io.gets - @io.lineno.should eql(1) - - @io.gets - @io.lineno.should eql(2) - - @io.gets - @io.lineno.should eql(3) - end - - it "returns nil if self is at the end" do - @io.pos = 36 - @io.gets.should be_nil - @io.gets.should be_nil - end -end - -describe "StringIO#gets when passed [limit]" do - before :each do - @io = StringIO.new("this>is>an>example") - end - - it "returns the data read until the limit is met" do - @io.gets(4).should == "this" - @io.gets(3).should == ">is" - @io.gets(5).should == ">an>e" - @io.gets(6).should == "xample" - end - - it "sets $_ to the read content" do - @io.gets(4) - $_.should == "this" - @io.gets(3) - $_.should == ">is" - @io.gets(5) - $_.should == ">an>e" - @io.gets(6) - $_.should == "xample" - @io.gets(3) - $_.should be_nil - end - - it "updates self's lineno by one" do - @io.gets(3) - @io.lineno.should eql(1) - - @io.gets(3) - @io.lineno.should eql(2) - - @io.gets(3) - @io.lineno.should eql(3) - end - - it "tries to convert the passed limit to an Integer using #to_int" do - obj = mock('to_int') - obj.should_receive(:to_int).and_return(4) - @io.gets(obj).should == "this" - end - - it "returns a blank string when passed a limit of 0" do - @io.gets(0).should == "" - end - - it "ignores it when passed a negative limit" do - @io.gets(-4).should == "this>is>an>example" - end -end + describe "when passed [limit]" do + it_behaves_like :stringio_gets_limit, :gets -describe "StringIO#gets when passed [separator] and [limit]" do - before :each do - @io = StringIO.new("this>is>an>example") - end - - it "returns the data read until the limit is consumed or the separator is met" do - @io.gets('>', 8).should == "this>" - @io.gets('>', 2).should == "is" - @io.gets('>', 10).should == ">" - @io.gets('>', 6).should == "an>" - @io.gets('>', 5).should == "examp" - end + it "returns nil if self is at the end" do + @io = StringIO.new("this>is>an>example") - it "sets $_ to the read content" do - @io.gets('>', 8) - $_.should == "this>" - @io.gets('>', 2) - $_.should == "is" - @io.gets('>', 10) - $_.should == ">" - @io.gets('>', 6) - $_.should == "an>" - @io.gets('>', 5) - $_.should == "examp" + @io.pos = 36 + @io.gets(3).should be_nil + @io.gets(3).should be_nil + end end - it "updates self's lineno by one" do - @io.gets('>', 3) - @io.lineno.should eql(1) + describe "when passed [separator] and [limit]" do + it_behaves_like :stringio_gets_separator_and_limit, :gets - @io.gets('>', 3) - @io.lineno.should eql(2) + it "returns nil if self is at the end" do + @io = StringIO.new("this>is>an>example") - @io.gets('>', 3) - @io.lineno.should eql(3) + @io.pos = 36 + @io.gets(">", 3).should be_nil + @io.gets(">", 3).should be_nil + end end - it "tries to convert the passed separator to a String using #to_str" do - obj = mock('to_str') - obj.should_receive(:to_str).and_return('>') - @io.gets(obj, 5).should == "this>" - end + describe "when passed no argument" do + it_behaves_like :stringio_gets_no_argument, :gets - it "does not raise TypeError if passed separator is nil" do - @io.gets(nil, 5).should == "this>" - end + it "returns nil if self is at the end" do + @io = StringIO.new("this>is>an>example") - it "tries to convert the passed limit to an Integer using #to_int" do - obj = mock('to_int') - obj.should_receive(:to_int).and_return(5) - @io.gets('>', obj).should == "this>" + @io.pos = 36 + @io.gets.should be_nil + @io.gets.should be_nil + end end -end - -describe "StringIO#gets when in write-only mode" do - it "raises an IOError" do - io = StringIO.new("xyz", "w") - -> { io.gets }.should raise_error(IOError) - io = StringIO.new("xyz") - io.close_read - -> { io.gets }.should raise_error(IOError) + describe "when passed [chomp]" do + it_behaves_like :stringio_gets_chomp, :gets end -end -describe "StringIO#gets when passed [chomp]" do - it "returns the data read without a trailing newline character" do - io = StringIO.new("this>is>an>example\n") - io.gets(chomp: true).should == "this>is>an>example" + describe "when in write-only mode" do + it_behaves_like :stringio_gets_write_only, :gets end end diff --git a/spec/ruby/library/stringio/initialize_spec.rb b/spec/ruby/library/stringio/initialize_spec.rb index c597e328d3..6f4d2e456c 100644 --- a/spec/ruby/library/stringio/initialize_spec.rb +++ b/spec/ruby/library/stringio/initialize_spec.rb @@ -13,99 +13,99 @@ describe "StringIO#initialize when passed [Object, mode]" do it "sets the mode based on the passed mode" do io = StringIO.allocate - io.send(:initialize, "example", "r") + io.send(:initialize, +"example", "r") io.closed_read?.should be_false io.closed_write?.should be_true io = StringIO.allocate - io.send(:initialize, "example", "rb") + io.send(:initialize, +"example", "rb") io.closed_read?.should be_false io.closed_write?.should be_true io = StringIO.allocate - io.send(:initialize, "example", "r+") + io.send(:initialize, +"example", "r+") io.closed_read?.should be_false io.closed_write?.should be_false io = StringIO.allocate - io.send(:initialize, "example", "rb+") + io.send(:initialize, +"example", "rb+") io.closed_read?.should be_false io.closed_write?.should be_false io = StringIO.allocate - io.send(:initialize, "example", "w") + io.send(:initialize, +"example", "w") io.closed_read?.should be_true io.closed_write?.should be_false io = StringIO.allocate - io.send(:initialize, "example", "wb") + io.send(:initialize, +"example", "wb") io.closed_read?.should be_true io.closed_write?.should be_false io = StringIO.allocate - io.send(:initialize, "example", "w+") + io.send(:initialize, +"example", "w+") io.closed_read?.should be_false io.closed_write?.should be_false io = StringIO.allocate - io.send(:initialize, "example", "wb+") + io.send(:initialize, +"example", "wb+") io.closed_read?.should be_false io.closed_write?.should be_false io = StringIO.allocate - io.send(:initialize, "example", "a") + io.send(:initialize, +"example", "a") io.closed_read?.should be_true io.closed_write?.should be_false io = StringIO.allocate - io.send(:initialize, "example", "ab") + io.send(:initialize, +"example", "ab") io.closed_read?.should be_true io.closed_write?.should be_false io = StringIO.allocate - io.send(:initialize, "example", "a+") + io.send(:initialize, +"example", "a+") io.closed_read?.should be_false io.closed_write?.should be_false io = StringIO.allocate - io.send(:initialize, "example", "ab+") + io.send(:initialize, +"example", "ab+") io.closed_read?.should be_false io.closed_write?.should be_false end it "allows passing the mode as an Integer" do io = StringIO.allocate - io.send(:initialize, "example", IO::RDONLY) + io.send(:initialize, +"example", IO::RDONLY) io.closed_read?.should be_false io.closed_write?.should be_true io = StringIO.allocate - io.send(:initialize, "example", IO::RDWR) + io.send(:initialize, +"example", IO::RDWR) io.closed_read?.should be_false io.closed_write?.should be_false io = StringIO.allocate - io.send(:initialize, "example", IO::WRONLY) + io.send(:initialize, +"example", IO::WRONLY) io.closed_read?.should be_true io.closed_write?.should be_false io = StringIO.allocate - io.send(:initialize, "example", IO::WRONLY | IO::TRUNC) + io.send(:initialize, +"example", IO::WRONLY | IO::TRUNC) io.closed_read?.should be_true io.closed_write?.should be_false io = StringIO.allocate - io.send(:initialize, "example", IO::RDWR | IO::TRUNC) + io.send(:initialize, +"example", IO::RDWR | IO::TRUNC) io.closed_read?.should be_false io.closed_write?.should be_false io = StringIO.allocate - io.send(:initialize, "example", IO::WRONLY | IO::APPEND) + io.send(:initialize, +"example", IO::WRONLY | IO::APPEND) io.closed_read?.should be_true io.closed_write?.should be_false io = StringIO.allocate - io.send(:initialize, "example", IO::RDWR | IO::APPEND) + io.send(:initialize, +"example", IO::RDWR | IO::APPEND) io.closed_read?.should be_false io.closed_write?.should be_false end @@ -118,7 +118,7 @@ describe "StringIO#initialize when passed [Object, mode]" do it "tries to convert the passed mode to a String using #to_str" do obj = mock('to_str') obj.should_receive(:to_str).and_return("r") - @io.send(:initialize, "example", obj) + @io.send(:initialize, +"example", obj) @io.closed_read?.should be_false @io.closed_write?.should be_true @@ -130,6 +130,26 @@ describe "StringIO#initialize when passed [Object, mode]" do -> { @io.send(:initialize, str, "w") }.should raise_error(Errno::EACCES) -> { @io.send(:initialize, str, "a") }.should raise_error(Errno::EACCES) end + + it "truncates all the content if passed w mode" do + io = StringIO.allocate + source = +"example".encode(Encoding::ISO_8859_1); + + io.send(:initialize, source, "w") + + io.string.should.empty? + io.string.encoding.should == Encoding::ISO_8859_1 + end + + it "truncates all the content if passed IO::TRUNC mode" do + io = StringIO.allocate + source = +"example".encode(Encoding::ISO_8859_1); + + io.send(:initialize, source, IO::TRUNC) + + io.string.should.empty? + io.string.encoding.should == Encoding::ISO_8859_1 + end end describe "StringIO#initialize when passed [Object]" do @@ -142,12 +162,18 @@ describe "StringIO#initialize when passed [Object]" do @io.string.should equal(str) end - it "sets the mode to read-write" do - @io.send(:initialize, "example") + it "sets the mode to read-write if the string is mutable" do + @io.send(:initialize, +"example") @io.closed_read?.should be_false @io.closed_write?.should be_false end + it "sets the mode to read if the string is frozen" do + @io.send(:initialize, -"example") + @io.closed_read?.should be_false + @io.closed_write?.should be_true + end + it "tries to convert the passed Object to a String using #to_str" do obj = mock('to_str') obj.should_receive(:to_str).and_return("example") @@ -166,28 +192,28 @@ end # NOTE: Synchronise with core/io/new_spec.rb (core/io/shared/new.rb) describe "StringIO#initialize when passed keyword arguments" do it "sets the mode based on the passed :mode option" do - io = StringIO.new("example", "r") + io = StringIO.new("example", mode: "r") io.closed_read?.should be_false io.closed_write?.should be_true end it "accepts a mode argument set to nil with a valid :mode option" do - @io = StringIO.new('', nil, mode: "w") + @io = StringIO.new(+'', nil, mode: "w") @io.write("foo").should == 3 end it "accepts a mode argument with a :mode option set to nil" do - @io = StringIO.new('', "w", mode: nil) + @io = StringIO.new(+'', "w", mode: nil) @io.write("foo").should == 3 end it "sets binmode from :binmode option" do - @io = StringIO.new('', 'w', binmode: true) + @io = StringIO.new(+'', 'w', binmode: true) @io.external_encoding.to_s.should == "ASCII-8BIT" # #binmode? isn't implemented in StringIO end it "does not set binmode from false :binmode" do - @io = StringIO.new('', 'w', binmode: false) + @io = StringIO.new(+'', 'w', binmode: false) @io.external_encoding.to_s.should == "UTF-8" # #binmode? isn't implemented in StringIO end end @@ -196,54 +222,54 @@ end describe "StringIO#initialize when passed keyword arguments and error happens" do it "raises an error if passed encodings two ways" do -> { - @io = StringIO.new('', 'w:ISO-8859-1', encoding: 'ISO-8859-1') + @io = StringIO.new(+'', 'w:ISO-8859-1', encoding: 'ISO-8859-1') }.should raise_error(ArgumentError) -> { - @io = StringIO.new('', 'w:ISO-8859-1', external_encoding: 'ISO-8859-1') + @io = StringIO.new(+'', 'w:ISO-8859-1', external_encoding: 'ISO-8859-1') }.should raise_error(ArgumentError) -> { - @io = StringIO.new('', 'w:ISO-8859-1:UTF-8', internal_encoding: 'ISO-8859-1') + @io = StringIO.new(+'', 'w:ISO-8859-1:UTF-8', internal_encoding: 'ISO-8859-1') }.should raise_error(ArgumentError) end it "raises an error if passed matching binary/text mode two ways" do -> { - @io = StringIO.new('', "wb", binmode: true) + @io = StringIO.new(+'', "wb", binmode: true) }.should raise_error(ArgumentError) -> { - @io = StringIO.new('', "wt", textmode: true) + @io = StringIO.new(+'', "wt", textmode: true) }.should raise_error(ArgumentError) -> { - @io = StringIO.new('', "wb", textmode: false) + @io = StringIO.new(+'', "wb", textmode: false) }.should raise_error(ArgumentError) -> { - @io = StringIO.new('', "wt", binmode: false) + @io = StringIO.new(+'', "wt", binmode: false) }.should raise_error(ArgumentError) end it "raises an error if passed conflicting binary/text mode two ways" do -> { - @io = StringIO.new('', "wb", binmode: false) + @io = StringIO.new(+'', "wb", binmode: false) }.should raise_error(ArgumentError) -> { - @io = StringIO.new('', "wt", textmode: false) + @io = StringIO.new(+'', "wt", textmode: false) }.should raise_error(ArgumentError) -> { - @io = StringIO.new('', "wb", textmode: true) + @io = StringIO.new(+'', "wb", textmode: true) }.should raise_error(ArgumentError) -> { - @io = StringIO.new('', "wt", binmode: true) + @io = StringIO.new(+'', "wt", binmode: true) }.should raise_error(ArgumentError) end it "raises an error when trying to set both binmode and textmode" do -> { - @io = StringIO.new('', "w", textmode: true, binmode: true) + @io = StringIO.new(+'', "w", textmode: true, binmode: true) }.should raise_error(ArgumentError) -> { - @io = StringIO.new('', File::Constants::WRONLY, textmode: true, binmode: true) + @io = StringIO.new(+'', File::Constants::WRONLY, textmode: true, binmode: true) }.should raise_error(ArgumentError) end end @@ -258,7 +284,7 @@ describe "StringIO#initialize when passed no arguments" do end it "sets the mode to read-write" do - @io.send(:initialize, "example") + @io.send(:initialize) @io.closed_read?.should be_false @io.closed_write?.should be_false end @@ -289,19 +315,14 @@ describe "StringIO#initialize sets" do end it "the encoding to the encoding of the String when passed a String" do - s = ''.force_encoding(Encoding::EUC_JP) + s = ''.dup.force_encoding(Encoding::EUC_JP) io = StringIO.new(s) io.string.encoding.should == Encoding::EUC_JP end - guard_not -> { # [Bug #16497] - stringio_version = StringIO.const_defined?(:VERSION) ? StringIO::VERSION : "0.0.2" - version_is(stringio_version, "0.0.3"..."0.1.1") - } do - it "the #external_encoding to the encoding of the String when passed a String" do - s = ''.force_encoding(Encoding::EUC_JP) - io = StringIO.new(s) - io.external_encoding.should == Encoding::EUC_JP - end + it "the #external_encoding to the encoding of the String when passed a String" do + s = ''.dup.force_encoding(Encoding::EUC_JP) + io = StringIO.new(s) + io.external_encoding.should == Encoding::EUC_JP end end diff --git a/spec/ruby/library/stringio/lines_spec.rb b/spec/ruby/library/stringio/lines_spec.rb deleted file mode 100644 index 42d11772ae..0000000000 --- a/spec/ruby/library/stringio/lines_spec.rb +++ /dev/null @@ -1,53 +0,0 @@ -require_relative '../../spec_helper' -require 'stringio' -require_relative 'shared/each' - -ruby_version_is ''...'3.0' do - describe "StringIO#lines when passed a separator" do - before :each do - @verbose, $VERBOSE = $VERBOSE, nil - end - - after :each do - $VERBOSE = @verbose - end - - it_behaves_like :stringio_each_separator, :lines - end - - describe "StringIO#lines when passed no arguments" do - before :each do - @verbose, $VERBOSE = $VERBOSE, nil - end - - after :each do - $VERBOSE = @verbose - end - - it_behaves_like :stringio_each_no_arguments, :lines - end - - describe "StringIO#lines when self is not readable" do - before :each do - @verbose, $VERBOSE = $VERBOSE, nil - end - - after :each do - $VERBOSE = @verbose - end - - it_behaves_like :stringio_each_not_readable, :lines - end - - describe "StringIO#lines when passed chomp" do - before :each do - @verbose, $VERBOSE = $VERBOSE, nil - end - - after :each do - $VERBOSE = @verbose - end - - it_behaves_like :stringio_each_chomp, :lines - end -end diff --git a/spec/ruby/library/stringio/new_spec.rb b/spec/ruby/library/stringio/new_spec.rb index 328455134e..ec4b32aa11 100644 --- a/spec/ruby/library/stringio/new_spec.rb +++ b/spec/ruby/library/stringio/new_spec.rb @@ -2,7 +2,9 @@ require_relative '../../spec_helper' require 'stringio' describe "StringIO.new" do - it "warns when called with a block" do - -> { eval("StringIO.new {}") }.should complain(/StringIO::new\(\) does not take block; use StringIO::open\(\) instead/) + it "does not use the given block and warns to use StringIO::open" do + -> { + StringIO.new { raise } + }.should complain(/warning: StringIO::new\(\) does not take block; use StringIO::open\(\) instead/) end end diff --git a/spec/ruby/library/stringio/open_spec.rb b/spec/ruby/library/stringio/open_spec.rb index 3068e19435..b7c90661f9 100644 --- a/spec/ruby/library/stringio/open_spec.rb +++ b/spec/ruby/library/stringio/open_spec.rb @@ -8,26 +8,26 @@ describe "StringIO.open when passed [Object, mode]" do end it "returns the blocks return value when yielding" do - ret = StringIO.open("example", "r") { :test } + ret = StringIO.open(+"example", "r") { :test } ret.should equal(:test) end it "yields self to the passed block" do io = nil - StringIO.open("example", "r") { |strio| io = strio } + StringIO.open(+"example", "r") { |strio| io = strio } io.should be_kind_of(StringIO) end it "closes self after yielding" do io = nil - StringIO.open("example", "r") { |strio| io = strio } + StringIO.open(+"example", "r") { |strio| io = strio } io.closed?.should be_true end it "even closes self when an exception is raised while yielding" do io = nil begin - StringIO.open("example", "r") do |strio| + StringIO.open(+"example", "r") do |strio| io = strio raise "Error" end @@ -38,14 +38,14 @@ describe "StringIO.open when passed [Object, mode]" do it "sets self's string to nil after yielding" do io = nil - StringIO.open("example", "r") { |strio| io = strio } + StringIO.open(+"example", "r") { |strio| io = strio } io.string.should be_nil end it "even sets self's string to nil when an exception is raised while yielding" do io = nil begin - StringIO.open("example", "r") do |strio| + StringIO.open(+"example", "r") do |strio| io = strio raise "Error" end @@ -55,81 +55,81 @@ describe "StringIO.open when passed [Object, mode]" do end it "sets the mode based on the passed mode" do - io = StringIO.open("example", "r") + io = StringIO.open(+"example", "r") io.closed_read?.should be_false io.closed_write?.should be_true - io = StringIO.open("example", "rb") + io = StringIO.open(+"example", "rb") io.closed_read?.should be_false io.closed_write?.should be_true - io = StringIO.open("example", "r+") + io = StringIO.open(+"example", "r+") io.closed_read?.should be_false io.closed_write?.should be_false - io = StringIO.open("example", "rb+") + io = StringIO.open(+"example", "rb+") io.closed_read?.should be_false io.closed_write?.should be_false - io = StringIO.open("example", "w") + io = StringIO.open(+"example", "w") io.closed_read?.should be_true io.closed_write?.should be_false - io = StringIO.open("example", "wb") + io = StringIO.open(+"example", "wb") io.closed_read?.should be_true io.closed_write?.should be_false - io = StringIO.open("example", "w+") + io = StringIO.open(+"example", "w+") io.closed_read?.should be_false io.closed_write?.should be_false - io = StringIO.open("example", "wb+") + io = StringIO.open(+"example", "wb+") io.closed_read?.should be_false io.closed_write?.should be_false - io = StringIO.open("example", "a") + io = StringIO.open(+"example", "a") io.closed_read?.should be_true io.closed_write?.should be_false - io = StringIO.open("example", "ab") + io = StringIO.open(+"example", "ab") io.closed_read?.should be_true io.closed_write?.should be_false - io = StringIO.open("example", "a+") + io = StringIO.open(+"example", "a+") io.closed_read?.should be_false io.closed_write?.should be_false - io = StringIO.open("example", "ab+") + io = StringIO.open(+"example", "ab+") io.closed_read?.should be_false io.closed_write?.should be_false end it "allows passing the mode as an Integer" do - io = StringIO.open("example", IO::RDONLY) + io = StringIO.open(+"example", IO::RDONLY) io.closed_read?.should be_false io.closed_write?.should be_true - io = StringIO.open("example", IO::RDWR) + io = StringIO.open(+"example", IO::RDWR) io.closed_read?.should be_false io.closed_write?.should be_false - io = StringIO.open("example", IO::WRONLY) + io = StringIO.open(+"example", IO::WRONLY) io.closed_read?.should be_true io.closed_write?.should be_false - io = StringIO.open("example", IO::WRONLY | IO::TRUNC) + io = StringIO.open(+"example", IO::WRONLY | IO::TRUNC) io.closed_read?.should be_true io.closed_write?.should be_false - io = StringIO.open("example", IO::RDWR | IO::TRUNC) + io = StringIO.open(+"example", IO::RDWR | IO::TRUNC) io.closed_read?.should be_false io.closed_write?.should be_false - io = StringIO.open("example", IO::WRONLY | IO::APPEND) + io = StringIO.open(+"example", IO::WRONLY | IO::APPEND) io.closed_read?.should be_true io.closed_write?.should be_false - io = StringIO.open("example", IO::RDWR | IO::APPEND) + io = StringIO.open(+"example", IO::RDWR | IO::APPEND) io.closed_read?.should be_false io.closed_write?.should be_false end @@ -141,7 +141,7 @@ describe "StringIO.open when passed [Object, mode]" do it "tries to convert the passed mode to a String using #to_str" do obj = mock('to_str') obj.should_receive(:to_str).and_return("r") - io = StringIO.open("example", obj) + io = StringIO.open(+"example", obj) io.closed_read?.should be_false io.closed_write?.should be_true @@ -163,16 +163,16 @@ describe "StringIO.open when passed [Object]" do it "yields self to the passed block" do io = nil - ret = StringIO.open("example") { |strio| io = strio } + ret = StringIO.open(+"example") { |strio| io = strio } io.should equal(ret) end it "sets the mode to read-write (r+)" do - io = StringIO.open("example") + io = StringIO.open(+"example") io.closed_read?.should be_false io.closed_write?.should be_false - io = StringIO.new("example") + io = StringIO.new(+"example") io.printf("%d", 123) io.string.should == "123mple" end @@ -204,7 +204,7 @@ describe "StringIO.open when passed no arguments" do io.closed_read?.should be_false io.closed_write?.should be_false - io = StringIO.new("example") + io = StringIO.new(+"example") io.printf("%d", 123) io.string.should == "123mple" end diff --git a/spec/ruby/library/stringio/print_spec.rb b/spec/ruby/library/stringio/print_spec.rb index 6ac6430900..00c33367dc 100644 --- a/spec/ruby/library/stringio/print_spec.rb +++ b/spec/ruby/library/stringio/print_spec.rb @@ -3,7 +3,7 @@ require_relative 'fixtures/classes' describe "StringIO#print" do before :each do - @io = StringIO.new('example') + @io = StringIO.new(+'example') end it "prints $_ when passed no arguments" do @@ -73,7 +73,7 @@ end describe "StringIO#print when in append mode" do before :each do - @io = StringIO.new("example", "a") + @io = StringIO.new(+"example", "a") end it "appends the passed argument to the end of self" do @@ -92,10 +92,10 @@ end describe "StringIO#print when self is not writable" do it "raises an IOError" do - io = StringIO.new("test", "r") + io = StringIO.new(+"test", "r") -> { io.print("test") }.should raise_error(IOError) - io = StringIO.new("test") + io = StringIO.new(+"test") io.close_write -> { io.print("test") }.should raise_error(IOError) end diff --git a/spec/ruby/library/stringio/printf_spec.rb b/spec/ruby/library/stringio/printf_spec.rb index f3f669a185..ca82e84757 100644 --- a/spec/ruby/library/stringio/printf_spec.rb +++ b/spec/ruby/library/stringio/printf_spec.rb @@ -41,7 +41,7 @@ end describe "StringIO#printf when in read-write mode" do before :each do - @io = StringIO.new("example", "r+") + @io = StringIO.new(+"example", "r+") end it "starts from the beginning" do @@ -62,7 +62,7 @@ end describe "StringIO#printf when in append mode" do before :each do - @io = StringIO.new("example", "a") + @io = StringIO.new(+"example", "a") end it "appends the passed argument to the end of self" do @@ -81,10 +81,10 @@ end describe "StringIO#printf when self is not writable" do it "raises an IOError" do - io = StringIO.new("test", "r") + io = StringIO.new(+"test", "r") -> { io.printf("test") }.should raise_error(IOError) - io = StringIO.new("test") + io = StringIO.new(+"test") io.close_write -> { io.printf("test") }.should raise_error(IOError) end diff --git a/spec/ruby/library/stringio/putc_spec.rb b/spec/ruby/library/stringio/putc_spec.rb index 1ce53b7ef2..9f1ac8ffb2 100644 --- a/spec/ruby/library/stringio/putc_spec.rb +++ b/spec/ruby/library/stringio/putc_spec.rb @@ -3,7 +3,7 @@ require_relative 'fixtures/classes' describe "StringIO#putc when passed [String]" do before :each do - @io = StringIO.new('example') + @io = StringIO.new(+'example') end it "overwrites the character at the current position" do @@ -54,7 +54,7 @@ end describe "StringIO#putc when passed [Object]" do before :each do - @io = StringIO.new('example') + @io = StringIO.new(+'example') end it "it writes the passed Integer % 256 to self" do @@ -85,7 +85,7 @@ end describe "StringIO#putc when in append mode" do it "appends to the end of self" do - io = StringIO.new("test", "a") + io = StringIO.new(+"test", "a") io.putc(?t) io.string.should == "testt" end @@ -93,10 +93,10 @@ end describe "StringIO#putc when self is not writable" do it "raises an IOError" do - io = StringIO.new("test", "r") + io = StringIO.new(+"test", "r") -> { io.putc(?a) }.should raise_error(IOError) - io = StringIO.new("test") + io = StringIO.new(+"test") io.close_write -> { io.putc("t") }.should raise_error(IOError) end diff --git a/spec/ruby/library/stringio/puts_spec.rb b/spec/ruby/library/stringio/puts_spec.rb index 9c890262dd..054ec8227f 100644 --- a/spec/ruby/library/stringio/puts_spec.rb +++ b/spec/ruby/library/stringio/puts_spec.rb @@ -145,7 +145,7 @@ end describe "StringIO#puts when in append mode" do before :each do - @io = StringIO.new("example", "a") + @io = StringIO.new(+"example", "a") end it "appends the passed argument to the end of self" do @@ -164,10 +164,10 @@ end describe "StringIO#puts when self is not writable" do it "raises an IOError" do - io = StringIO.new("test", "r") + io = StringIO.new(+"test", "r") -> { io.puts }.should raise_error(IOError) - io = StringIO.new("test") + io = StringIO.new(+"test") io.close_write -> { io.puts }.should raise_error(IOError) end @@ -175,7 +175,7 @@ end describe "StringIO#puts when passed an encoded string" do it "stores the bytes unmodified" do - io = StringIO.new("") + io = StringIO.new(+"") io.puts "\x00\x01\x02" io.puts "æåø" diff --git a/spec/ruby/library/stringio/read_nonblock_spec.rb b/spec/ruby/library/stringio/read_nonblock_spec.rb index d4ec56d9aa..74736f7792 100644 --- a/spec/ruby/library/stringio/read_nonblock_spec.rb +++ b/spec/ruby/library/stringio/read_nonblock_spec.rb @@ -8,7 +8,7 @@ describe "StringIO#read_nonblock when passed length, buffer" do it "accepts :exception option" do io = StringIO.new("example") - io.read_nonblock(3, buffer = "", exception: true) + io.read_nonblock(3, buffer = +"", exception: true) buffer.should == "exa" end end @@ -40,7 +40,7 @@ describe "StringIO#read_nonblock" do context "when exception option is set to false" do context "when the end is reached" do it "returns nil" do - stringio = StringIO.new('') + stringio = StringIO.new(+'') stringio << "hello" stringio.rewind diff --git a/spec/ruby/library/stringio/read_spec.rb b/spec/ruby/library/stringio/read_spec.rb index 52ab3dcf47..e49f262127 100644 --- a/spec/ruby/library/stringio/read_spec.rb +++ b/spec/ruby/library/stringio/read_spec.rb @@ -53,7 +53,7 @@ describe "StringIO#read when passed length and a buffer" do end it "reads [length] characters into the buffer" do - buf = "foo" + buf = +"foo" result = @io.read(10, buf) buf.should == "abcdefghij" diff --git a/spec/ruby/library/stringio/readline_spec.rb b/spec/ruby/library/stringio/readline_spec.rb index b794e5fade..085360707f 100644 --- a/spec/ruby/library/stringio/readline_spec.rb +++ b/spec/ruby/library/stringio/readline_spec.rb @@ -1,150 +1,58 @@ require_relative '../../spec_helper' +require "stringio" require_relative 'fixtures/classes' +require_relative "shared/gets" +describe "StringIO#readline" do + describe "when passed [separator]" do + it_behaves_like :stringio_gets_separator, :readline -describe "StringIO#readline when passed [separator]" do - before :each do - @io = StringIO.new("this>is>an>example") - end - - it "returns the data read till the next occurrence of the passed separator" do - @io.readline(">").should == "this>" - @io.readline(">").should == "is>" - @io.readline(">").should == "an>" - @io.readline(">").should == "example" - end - - it "sets $_ to the read content" do - @io.readline(">") - $_.should == "this>" - @io.readline(">") - $_.should == "is>" - @io.readline(">") - $_.should == "an>" - @io.readline(">") - $_.should == "example" - end - - it "updates self's lineno by one" do - @io.readline(">") - @io.lineno.should eql(1) - - @io.readline(">") - @io.lineno.should eql(2) - - @io.readline(">") - @io.lineno.should eql(3) - end - - it "returns the next paragraph when the passed separator is an empty String" do - io = StringIO.new("this is\n\nan example") - io.readline("").should == "this is\n\n" - io.readline("").should == "an example" - end - - it "returns the remaining content starting at the current position when passed nil" do - io = StringIO.new("this is\n\nan example") - io.pos = 5 - io.readline(nil).should == "is\n\nan example" - end - - it "tries to convert the passed separator to a String using #to_str" do - obj = mock('to_str') - obj.should_receive(:to_str).and_return(">") - @io.readline(obj).should == "this>" - end -end - -describe "StringIO#readline when passed no argument" do - before :each do - @io = StringIO.new("this is\nan example\nfor StringIO#readline") - end - - it "returns the data read till the next occurrence of $/ or till eof" do - @io.readline.should == "this is\n" + it "raises an IOError if self is at the end" do + @io = StringIO.new("this>is>an>example") - begin - old_sep = $/ - suppress_warning {$/ = " "} - @io.readline.should == "an " - @io.readline.should == "example\nfor " - @io.readline.should == "StringIO#readline" - ensure - suppress_warning {$/ = old_sep} + @io.pos = 36 + -> { @io.readline(">") }.should raise_error(IOError) end end - it "sets $_ to the read content" do - @io.readline - $_.should == "this is\n" - @io.readline - $_.should == "an example\n" - @io.readline - $_.should == "for StringIO#readline" - end + describe "when passed [limit]" do + it_behaves_like :stringio_gets_limit, :readline - it "updates self's position" do - @io.readline - @io.pos.should eql(8) + it "raises an IOError if self is at the end" do + @io = StringIO.new("this>is>an>example") - @io.readline - @io.pos.should eql(19) - - @io.readline - @io.pos.should eql(40) + @io.pos = 36 + -> { @io.readline(3) }.should raise_error(IOError) + end end - it "updates self's lineno" do - @io.readline - @io.lineno.should eql(1) + describe "when passed [separator] and [limit]" do + it_behaves_like :stringio_gets_separator_and_limit, :readline - @io.readline - @io.lineno.should eql(2) + it "raises an IOError if self is at the end" do + @io = StringIO.new("this>is>an>example") - @io.readline - @io.lineno.should eql(3) - end - - it "raises an IOError if self is at the end" do - @io.pos = 40 - -> { @io.readline }.should raise_error(IOError) - end -end - -describe "StringIO#readline when in write-only mode" do - it "raises an IOError" do - io = StringIO.new("xyz", "w") - -> { io.readline }.should raise_error(IOError) - - io = StringIO.new("xyz") - io.close_read - -> { io.readline }.should raise_error(IOError) + @io.pos = 36 + -> { @io.readline(">", 3) }.should raise_error(IOError) + end end -end -describe "StringIO#readline when passed [chomp]" do - it "returns the data read without a trailing newline character" do - io = StringIO.new("this>is>an>example\n") - io.readline(chomp: true).should == "this>is>an>example" - end -end + describe "when passed no argument" do + it_behaves_like :stringio_gets_no_argument, :readline -describe "StringIO#readline when passed [limit]" do - before :each do - @io = StringIO.new("this>is>an>example") - end + it "raises an IOError if self is at the end" do + @io = StringIO.new("this>is>an>example") - it "returns the data read until the limit is met" do - io = StringIO.new("this>is>an>example\n") - io.readline(3).should == "thi" + @io.pos = 36 + -> { @io.readline }.should raise_error(IOError) + end end - it "returns a blank string when passed a limit of 0" do - @io.readline(0).should == "" + describe "when passed [chomp]" do + it_behaves_like :stringio_gets_chomp, :readline end - it "ignores it when the limit is negative" do - seen = [] - @io.readline(-4).should == "this>is>an>example" + describe "when in write-only mode" do + it_behaves_like :stringio_gets_write_only, :readline end end diff --git a/spec/ruby/library/stringio/readlines_spec.rb b/spec/ruby/library/stringio/readlines_spec.rb index c471d0fd73..ed7cc22b3d 100644 --- a/spec/ruby/library/stringio/readlines_spec.rb +++ b/spec/ruby/library/stringio/readlines_spec.rb @@ -83,7 +83,7 @@ end describe "StringIO#readlines when in write-only mode" do it "raises an IOError" do - io = StringIO.new("xyz", "w") + io = StringIO.new(+"xyz", "w") -> { io.readlines }.should raise_error(IOError) io = StringIO.new("xyz") diff --git a/spec/ruby/library/stringio/readpartial_spec.rb b/spec/ruby/library/stringio/readpartial_spec.rb index 2601fe8c42..dadefb7837 100644 --- a/spec/ruby/library/stringio/readpartial_spec.rb +++ b/spec/ruby/library/stringio/readpartial_spec.rb @@ -3,20 +3,14 @@ require_relative 'fixtures/classes' describe "StringIO#readpartial" do before :each do - @string = StringIO.new('Stop, look, listen') + @string = StringIO.new(+'Stop, look, listen') end after :each do @string.close unless @string.closed? end - it "raises IOError on closed stream" do - @string.close - -> { @string.readpartial(10) }.should raise_error(IOError) - end - it "reads at most the specified number of bytes" do - # buffered read @string.read(1).should == 'S' # return only specified number, not the whole buffer @@ -30,6 +24,14 @@ describe "StringIO#readpartial" do @string.readpartial(3).should == ", l" end + it "reads after ungetc with multibyte characters in the buffer" do + @string = StringIO.new(+"∂φ/∂x = gaîté") + c = @string.getc + @string.ungetc(c) + @string.readpartial(3).should == "\xE2\x88\x82".b + @string.readpartial(3).should == "\xCF\x86/".b + end + it "reads after ungetc without data in the buffer" do @string = StringIO.new @string.write("f").should == 1 @@ -48,7 +50,7 @@ describe "StringIO#readpartial" do end it "discards the existing buffer content upon successful read" do - buffer = "existing" + buffer = +"existing" @string.readpartial(11, buffer) buffer.should == "Stop, look," end @@ -59,7 +61,7 @@ describe "StringIO#readpartial" do end it "discards the existing buffer content upon error" do - buffer = 'hello' + buffer = +'hello' @string.readpartial(100) -> { @string.readpartial(1, buffer) }.should raise_error(EOFError) buffer.should be_empty @@ -67,14 +69,34 @@ describe "StringIO#readpartial" do it "raises IOError if the stream is closed" do @string.close - -> { @string.readpartial(1) }.should raise_error(IOError) + -> { @string.readpartial(1) }.should raise_error(IOError, "not opened for reading") end it "raises ArgumentError if the negative argument is provided" do - -> { @string.readpartial(-1) }.should raise_error(ArgumentError) + -> { @string.readpartial(-1) }.should raise_error(ArgumentError, "negative length -1 given") end it "immediately returns an empty string if the length argument is 0" do @string.readpartial(0).should == "" end + + it "raises IOError if the stream is closed and the length argument is 0" do + @string.close + -> { @string.readpartial(0) }.should raise_error(IOError, "not opened for reading") + end + + it "clears and returns the given buffer if the length argument is 0" do + buffer = +"existing content" + @string.readpartial(0, buffer).should == buffer + buffer.should == "" + end + + version_is StringIO::VERSION, "3.1.2" do # ruby_version_is "3.4" + it "preserves the encoding of the given buffer" do + buffer = ''.encode(Encoding::ISO_8859_1) + @string.readpartial(10, buffer) + + buffer.encoding.should == Encoding::ISO_8859_1 + end + end end diff --git a/spec/ruby/library/stringio/reopen_spec.rb b/spec/ruby/library/stringio/reopen_spec.rb index 4863a5332b..7021ff17e5 100644 --- a/spec/ruby/library/stringio/reopen_spec.rb +++ b/spec/ruby/library/stringio/reopen_spec.rb @@ -12,31 +12,20 @@ describe "StringIO#reopen when passed [Object, Integer]" do @io.closed_write?.should be_true @io.string.should == "reopened" - @io.reopen("reopened, twice", IO::WRONLY) + @io.reopen(+"reopened, twice", IO::WRONLY) @io.closed_read?.should be_true @io.closed_write?.should be_false @io.string.should == "reopened, twice" - @io.reopen("reopened, another time", IO::RDWR) + @io.reopen(+"reopened, another time", IO::RDWR) @io.closed_read?.should be_false @io.closed_write?.should be_false @io.string.should == "reopened, another time" end - ruby_version_is ""..."3.0" do - # NOTE: WEIRD! - it "does not taint self when the passed Object was tainted" do - @io.reopen("reopened".taint, IO::RDONLY) - @io.tainted?.should be_false - - @io.reopen("reopened".taint, IO::WRONLY) - @io.tainted?.should be_false - end - end - it "tries to convert the passed Object to a String using #to_str" do obj = mock("to_str") - obj.should_receive(:to_str).and_return("to_str") + obj.should_receive(:to_str).and_return(+"to_str") @io.reopen(obj, IO::RDWR) @io.string.should == "to_str" end @@ -71,38 +60,27 @@ describe "StringIO#reopen when passed [Object, Object]" do @io.closed_write?.should be_true @io.string.should == "reopened" - @io.reopen("reopened, twice", "r+") + @io.reopen(+"reopened, twice", "r+") @io.closed_read?.should be_false @io.closed_write?.should be_false @io.string.should == "reopened, twice" - @io.reopen("reopened, another", "w+") + @io.reopen(+"reopened, another", "w+") @io.closed_read?.should be_false @io.closed_write?.should be_false @io.string.should == "" - @io.reopen("reopened, another time", "r+") + @io.reopen(+"reopened, another time", "r+") @io.closed_read?.should be_false @io.closed_write?.should be_false @io.string.should == "reopened, another time" end it "truncates the passed String when opened in truncate mode" do - @io.reopen(str = "reopened", "w") + @io.reopen(str = +"reopened", "w") str.should == "" end - ruby_version_is ""..."3.0" do - # NOTE: WEIRD! - it "does not taint self when the passed Object was tainted" do - @io.reopen("reopened".taint, "r") - @io.tainted?.should be_false - - @io.reopen("reopened".taint, "w") - @io.tainted?.should be_false - end - end - it "tries to convert the passed Object to a String using #to_str" do obj = mock("to_str") obj.should_receive(:to_str).and_return("to_str") @@ -116,13 +94,13 @@ describe "StringIO#reopen when passed [Object, Object]" do it "resets self's position to 0" do @io.read(5) - @io.reopen("reopened") + @io.reopen(+"reopened") @io.pos.should eql(0) end it "resets self's line number to 0" do @io.gets - @io.reopen("reopened") + @io.reopen(+"reopened") @io.lineno.should eql(0) end @@ -156,7 +134,7 @@ describe "StringIO#reopen when passed [String]" do it "reopens self with the passed String in read-write mode" do @io.close - @io.reopen("reopened") + @io.reopen(+"reopened") @io.closed_write?.should be_false @io.closed_read?.should be_false @@ -164,23 +142,15 @@ describe "StringIO#reopen when passed [String]" do @io.string.should == "reopened" end - ruby_version_is ""..."3.0" do - # NOTE: WEIRD! - it "does not taint self when the passed Object was tainted" do - @io.reopen("reopened".taint) - @io.tainted?.should be_false - end - end - it "resets self's position to 0" do @io.read(5) - @io.reopen("reopened") + @io.reopen(+"reopened") @io.pos.should eql(0) end it "resets self's line number to 0" do @io.gets - @io.reopen("reopened") + @io.reopen(+"reopened") @io.lineno.should eql(0) end end @@ -202,7 +172,7 @@ describe "StringIO#reopen when passed [Object]" do it "tries to convert the passed Object to a StringIO using #to_strio" do obj = mock("to_strio") - obj.should_receive(:to_strio).and_return(StringIO.new("to_strio")) + obj.should_receive(:to_strio).and_return(StringIO.new(+"to_strio")) @io.reopen(obj) @io.string.should == "to_strio" end @@ -238,40 +208,40 @@ end # for details. describe "StringIO#reopen" do before :each do - @io = StringIO.new('hello','a') + @io = StringIO.new(+'hello', 'a') end # TODO: find out if this is really a bug it "reopens a stream when given a String argument" do - @io.reopen('goodbye').should == @io + @io.reopen(+'goodbye').should == @io @io.string.should == 'goodbye' @io << 'x' @io.string.should == 'xoodbye' end it "reopens a stream in append mode when flagged as such" do - @io.reopen('goodbye', 'a').should == @io + @io.reopen(+'goodbye', 'a').should == @io @io.string.should == 'goodbye' @io << 'x' @io.string.should == 'goodbyex' end it "reopens and truncate when reopened in write mode" do - @io.reopen('goodbye', 'wb').should == @io + @io.reopen(+'goodbye', 'wb').should == @io @io.string.should == '' @io << 'x' @io.string.should == 'x' end it "truncates the given string, not a copy" do - str = 'goodbye' + str = +'goodbye' @io.reopen(str, 'w') @io.string.should == '' str.should == '' end it "does not truncate the content even when the StringIO argument is in the truncate mode" do - orig_io = StringIO.new("Original StringIO", IO::RDWR|IO::TRUNC) + orig_io = StringIO.new(+"Original StringIO", IO::RDWR|IO::TRUNC) orig_io.write("BLAH") # make sure the content is not empty @io.reopen(orig_io) diff --git a/spec/ruby/library/stringio/set_encoding_by_bom_spec.rb b/spec/ruby/library/stringio/set_encoding_by_bom_spec.rb new file mode 100644 index 0000000000..1030aad042 --- /dev/null +++ b/spec/ruby/library/stringio/set_encoding_by_bom_spec.rb @@ -0,0 +1,237 @@ +require 'stringio' +require_relative '../../spec_helper' + +# Should be synced with specs for IO#set_encoding_by_bom +describe "StringIO#set_encoding_by_bom" do + it "returns nil if not readable" do + io = StringIO.new("".b, "wb") + + io.set_encoding_by_bom.should be_nil + io.external_encoding.should == Encoding::ASCII_8BIT + end + + it "returns the result encoding if found BOM UTF-8 sequence" do + io = StringIO.new("\u{FEFF}".b, "rb") + + io.set_encoding_by_bom.should == Encoding::UTF_8 + io.external_encoding.should == Encoding::UTF_8 + io.read.b.should == "".b + + io = StringIO.new("\u{FEFF}abc".b, "rb") + + io.set_encoding_by_bom.should == Encoding::UTF_8 + io.external_encoding.should == Encoding::UTF_8 + io.read.b.should == "abc".b + end + + it "returns the result encoding if found BOM UTF_16LE sequence" do + io = StringIO.new("\xFF\xFE".b, "rb") + + io.set_encoding_by_bom.should == Encoding::UTF_16LE + io.external_encoding.should == Encoding::UTF_16LE + io.read.b.should == "".b + + io = StringIO.new("\xFF\xFEabc".b, "rb") + + io.set_encoding_by_bom.should == Encoding::UTF_16LE + io.external_encoding.should == Encoding::UTF_16LE + io.read.b.should == "abc".b + end + + it "returns the result encoding if found BOM UTF_16BE sequence" do + io = StringIO.new("\xFE\xFF".b, "rb") + + io.set_encoding_by_bom.should == Encoding::UTF_16BE + io.external_encoding.should == Encoding::UTF_16BE + io.read.b.should == "".b + + io = StringIO.new("\xFE\xFFabc".b, "rb") + + io.set_encoding_by_bom.should == Encoding::UTF_16BE + io.external_encoding.should == Encoding::UTF_16BE + io.read.b.should == "abc".b + end + + it "returns the result encoding if found BOM UTF_32LE sequence" do + io = StringIO.new("\xFF\xFE\x00\x00".b, "rb") + + io.set_encoding_by_bom.should == Encoding::UTF_32LE + io.external_encoding.should == Encoding::UTF_32LE + io.read.b.should == "".b + + io = StringIO.new("\xFF\xFE\x00\x00abc".b, "rb") + + io.set_encoding_by_bom.should == Encoding::UTF_32LE + io.external_encoding.should == Encoding::UTF_32LE + io.read.b.should == "abc".b + end + + it "returns the result encoding if found BOM UTF_32BE sequence" do + io = StringIO.new("\x00\x00\xFE\xFF".b, "rb") + + io.set_encoding_by_bom.should == Encoding::UTF_32BE + io.external_encoding.should == Encoding::UTF_32BE + io.read.b.should == "".b + + io = StringIO.new("\x00\x00\xFE\xFFabc".b, "rb") + + io.set_encoding_by_bom.should == Encoding::UTF_32BE + io.external_encoding.should == Encoding::UTF_32BE + io.read.b.should == "abc".b + end + + it "returns nil if io is empty" do + io = StringIO.new("".b, "rb") + io.set_encoding_by_bom.should be_nil + io.external_encoding.should == Encoding::ASCII_8BIT + end + + it "returns nil if UTF-8 BOM sequence is incomplete" do + io = StringIO.new("\xEF".b, "rb") + + io.set_encoding_by_bom.should == nil + io.external_encoding.should == Encoding::ASCII_8BIT + io.read.b.should == "\xEF".b + + io = StringIO.new("\xEFa".b, "rb") + + io.set_encoding_by_bom.should == nil + io.external_encoding.should == Encoding::ASCII_8BIT + io.read.b.should == "\xEFa".b + + io = StringIO.new("\xEF\xBB".b, "rb") + + io.set_encoding_by_bom.should == nil + io.external_encoding.should == Encoding::ASCII_8BIT + io.read.b.should == "\xEF\xBB".b + + io = StringIO.new("\xEF\xBBa".b, "rb") + + io.set_encoding_by_bom.should == nil + io.external_encoding.should == Encoding::ASCII_8BIT + io.read.b.should == "\xEF\xBBa".b + end + + it "returns nil if UTF-16BE BOM sequence is incomplete" do + io = StringIO.new("\xFE".b, "rb") + + io.set_encoding_by_bom.should == nil + io.external_encoding.should == Encoding::ASCII_8BIT + io.read.b.should == "\xFE".b + + io = StringIO.new("\xFEa".b, "rb") + + io.set_encoding_by_bom.should == nil + io.external_encoding.should == Encoding::ASCII_8BIT + io.read.b.should == "\xFEa".b + end + + it "returns nil if UTF-16LE/UTF-32LE BOM sequence is incomplete" do + io = StringIO.new("\xFF".b, "rb") + + io.set_encoding_by_bom.should == nil + io.external_encoding.should == Encoding::ASCII_8BIT + io.read.b.should == "\xFF".b + + io = StringIO.new("\xFFa".b, "rb") + + io.set_encoding_by_bom.should == nil + io.external_encoding.should == Encoding::ASCII_8BIT + io.read.b.should == "\xFFa".b + end + + it "returns UTF-16LE if UTF-32LE BOM sequence is incomplete" do + io = StringIO.new("\xFF\xFE".b, "rb") + + io.set_encoding_by_bom.should == Encoding::UTF_16LE + io.external_encoding.should == Encoding::UTF_16LE + io.read.b.should == "".b + + io = StringIO.new("\xFF\xFE\x00".b, "rb") + + io.set_encoding_by_bom.should == Encoding::UTF_16LE + io.external_encoding.should == Encoding::UTF_16LE + io.read.b.should == "\x00".b + + io = StringIO.new("\xFF\xFE\x00a".b, "rb") + + io.set_encoding_by_bom.should == Encoding::UTF_16LE + io.external_encoding.should == Encoding::UTF_16LE + io.read.b.should == "\x00a".b + end + + it "returns nil if UTF-32BE BOM sequence is incomplete" do + io = StringIO.new("\x00".b, "rb") + + io.set_encoding_by_bom.should == nil + io.external_encoding.should == Encoding::ASCII_8BIT + io.read.b.should == "\x00".b + + io = StringIO.new("\x00a".b, "rb") + + io.set_encoding_by_bom.should == nil + io.external_encoding.should == Encoding::ASCII_8BIT + io.read.b.should == "\x00a".b + + io = StringIO.new("\x00\x00".b, "rb") + + io.set_encoding_by_bom.should == nil + io.external_encoding.should == Encoding::ASCII_8BIT + io.read.b.should == "\x00\x00".b + + io = StringIO.new("\x00\x00a".b, "rb") + + io.set_encoding_by_bom.should == nil + io.external_encoding.should == Encoding::ASCII_8BIT + io.read.b.should == "\x00\x00a".b + + io = StringIO.new("\x00\x00\xFE".b, "rb") + + io.set_encoding_by_bom.should == nil + io.external_encoding.should == Encoding::ASCII_8BIT + io.read.b.should == "\x00\x00\xFE".b + + io = StringIO.new("\x00\x00\xFEa".b, "rb") + + io.set_encoding_by_bom.should == nil + io.external_encoding.should == Encoding::ASCII_8BIT + io.read.b.should == "\x00\x00\xFEa".b + end + + it "returns nil if found BOM sequence not provided" do + io = StringIO.new("abc".b, "rb") + + io.set_encoding_by_bom.should == nil + io.external_encoding.should == Encoding::ASCII_8BIT + io.read(3).should == "abc".b + end + + it "does not raise exception if io not in binary mode" do + io = StringIO.new("", 'r') + io.set_encoding_by_bom.should == nil + end + + it "does not raise exception if encoding already set" do + io = StringIO.new("".b, "rb") + io.set_encoding("utf-8") + io.set_encoding_by_bom.should == nil + end + + it "does not raise exception if encoding conversion is already set" do + io = StringIO.new("".b, "rb") + io.set_encoding(Encoding::UTF_8, Encoding::UTF_16BE) + + io.set_encoding_by_bom.should == nil + end + + it "raises FrozenError when io is frozen" do + io = StringIO.new() + io.freeze + -> { io.set_encoding_by_bom }.should raise_error(FrozenError) + end + + it "does not raise FrozenError when initial string is frozen" do + io = StringIO.new("".freeze) + io.set_encoding_by_bom.should == nil + end +end diff --git a/spec/ruby/library/stringio/set_encoding_spec.rb b/spec/ruby/library/stringio/set_encoding_spec.rb index 21d45750f3..19ca0875bf 100644 --- a/spec/ruby/library/stringio/set_encoding_spec.rb +++ b/spec/ruby/library/stringio/set_encoding_spec.rb @@ -17,4 +17,12 @@ describe "StringIO#set_encoding" do io.set_encoding Encoding::UTF_8 io.string.encoding.should == Encoding::US_ASCII end + + it "accepts a String" do + str = "".encode(Encoding::US_ASCII) + io = StringIO.new(str) + io.set_encoding("ASCII-8BIT") + io.external_encoding.should == Encoding::BINARY + str.encoding.should == Encoding::BINARY + end end diff --git a/spec/ruby/library/stringio/shared/codepoints.rb b/spec/ruby/library/stringio/shared/codepoints.rb index 9d84aa4919..25333bb0fd 100644 --- a/spec/ruby/library/stringio/shared/codepoints.rb +++ b/spec/ruby/library/stringio/shared/codepoints.rb @@ -27,7 +27,7 @@ describe :stringio_codepoints, shared: true do @io.close_read -> { @enum.to_a }.should raise_error(IOError) - io = StringIO.new("xyz", "w") + io = StringIO.new(+"xyz", "w") -> { io.send(@method).to_a }.should raise_error(IOError) end diff --git a/spec/ruby/library/stringio/shared/each.rb b/spec/ruby/library/stringio/shared/each.rb index bf3265ee46..626b41a4d3 100644 --- a/spec/ruby/library/stringio/shared/each.rb +++ b/spec/ruby/library/stringio/shared/each.rb @@ -36,22 +36,11 @@ describe :stringio_each_separator, shared: true do seen.should == ["2 1 2 1 2"] end - ruby_version_is ''..."3.2" do - it "yields each paragraph with two separation characters when passed an empty String as separator" do - seen = [] - io = StringIO.new("para1\n\npara2\n\n\npara3") - io.send(@method, "") {|s| seen << s} - seen.should == ["para1\n\n", "para2\n\n", "para3"] - end - end - - ruby_version_is "3.2" do - it "yields each paragraph with all separation characters when passed an empty String as separator" do - seen = [] - io = StringIO.new("para1\n\npara2\n\n\npara3") - io.send(@method, "") {|s| seen << s} - seen.should == ["para1\n\n", "para2\n\n\n", "para3"] - end + it "yields each paragraph with all separation characters when passed an empty String as separator" do + seen = [] + io = StringIO.new("para1\n\npara2\n\n\npara3") + io.send(@method, "") {|s| seen << s} + seen.should == ["para1\n\n", "para2\n\n\n", "para3"] end end @@ -107,7 +96,7 @@ end describe :stringio_each_not_readable, shared: true do it "raises an IOError" do - io = StringIO.new("a b c d e", "w") + io = StringIO.new(+"a b c d e", "w") -> { io.send(@method) { |b| b } }.should raise_error(IOError) io = StringIO.new("a b c d e") @@ -161,3 +150,60 @@ describe :stringio_each_limit, shared: true do seen.should == ["a b ", "c d ", "e\n", "1 2 ", "3 4 ", "5"] end end + +describe :stringio_each_separator_and_limit, shared: true do + before :each do + @io = StringIO.new("this>is>an>example") + end + + it "returns the data read until the limit is consumed or the separator is met" do + @io.send(@method, '>', 8) { |s| break s }.should == "this>" + @io.send(@method, '>', 2) { |s| break s }.should == "is" + @io.send(@method, '>', 10) { |s| break s }.should == ">" + @io.send(@method, '>', 6) { |s| break s }.should == "an>" + @io.send(@method, '>', 5) { |s| break s }.should == "examp" + end + + it "truncates the multi-character separator at the end to meet the limit" do + @io.send(@method, "is>an", 7) { |s| break s }.should == "this>is" + end + + it "does not change $_" do + $_ = "test" + @io.send(@method, '>', 8) { |s| s } + $_.should == "test" + end + + it "updates self's lineno by one" do + @io.send(@method, '>', 3) { |s| break s } + @io.lineno.should eql(1) + + @io.send(@method, '>', 3) { |s| break s } + @io.lineno.should eql(2) + + @io.send(@method, '>', 3) { |s| break s } + @io.lineno.should eql(3) + end + + it "tries to convert the passed separator to a String using #to_str" do # TODO + obj = mock('to_str') + obj.should_receive(:to_str).and_return('>') + + seen = [] + @io.send(@method, obj, 5) { |s| seen << s } + seen.should == ["this>", "is>", "an>", "examp", "le"] + end + + it "does not raise TypeError if passed separator is nil" do + @io.send(@method, nil, 5) { |s| break s }.should == "this>" + end + + it "tries to convert the passed limit to an Integer using #to_int" do # TODO + obj = mock('to_int') + obj.should_receive(:to_int).and_return(5) + + seen = [] + @io.send(@method, '>', obj) { |s| seen << s } + seen.should == ["this>", "is>", "an>", "examp", "le"] + end +end diff --git a/spec/ruby/library/stringio/shared/each_byte.rb b/spec/ruby/library/stringio/shared/each_byte.rb index 56734ff99d..b51fa38f2f 100644 --- a/spec/ruby/library/stringio/shared/each_byte.rb +++ b/spec/ruby/library/stringio/shared/each_byte.rb @@ -38,7 +38,7 @@ end describe :stringio_each_byte_not_readable, shared: true do it "raises an IOError" do - io = StringIO.new("xyz", "w") + io = StringIO.new(+"xyz", "w") -> { io.send(@method) { |b| b } }.should raise_error(IOError) io = StringIO.new("xyz") diff --git a/spec/ruby/library/stringio/shared/each_char.rb b/spec/ruby/library/stringio/shared/each_char.rb index bcdac53282..197237c1c8 100644 --- a/spec/ruby/library/stringio/shared/each_char.rb +++ b/spec/ruby/library/stringio/shared/each_char.rb @@ -26,7 +26,7 @@ end describe :stringio_each_char_not_readable, shared: true do it "raises an IOError" do - io = StringIO.new("xyz", "w") + io = StringIO.new(+"xyz", "w") -> { io.send(@method) { |b| b } }.should raise_error(IOError) io = StringIO.new("xyz") diff --git a/spec/ruby/library/stringio/shared/getc.rb b/spec/ruby/library/stringio/shared/getc.rb index 6318bcc30f..ba65040bce 100644 --- a/spec/ruby/library/stringio/shared/getc.rb +++ b/spec/ruby/library/stringio/shared/getc.rb @@ -33,7 +33,7 @@ end describe :stringio_getc_not_readable, shared: true do it "raises an IOError" do - io = StringIO.new("xyz", "w") + io = StringIO.new(+"xyz", "w") -> { io.send(@method) }.should raise_error(IOError) io = StringIO.new("xyz") diff --git a/spec/ruby/library/stringio/shared/gets.rb b/spec/ruby/library/stringio/shared/gets.rb new file mode 100644 index 0000000000..8396b161f1 --- /dev/null +++ b/spec/ruby/library/stringio/shared/gets.rb @@ -0,0 +1,249 @@ +describe :stringio_gets_separator, shared: true do + describe "when passed [separator]" do + before :each do + @io = StringIO.new("this>is>an>example") + end + + it "returns the data read till the next occurrence of the passed separator" do + @io.send(@method, ">").should == "this>" + @io.send(@method, ">").should == "is>" + @io.send(@method, ">").should == "an>" + @io.send(@method, ">").should == "example" + end + + it "sets $_ to the read content" do + @io.send(@method, ">") + $_.should == "this>" + @io.send(@method, ">") + $_.should == "is>" + @io.send(@method, ">") + $_.should == "an>" + @io.send(@method, ">") + $_.should == "example" + end + + it "accepts string as separator" do + @io.send(@method, "is>") + $_.should == "this>" + @io.send(@method, "an>") + $_.should == "is>an>" + @io.send(@method, "example") + $_.should == "example" + end + + it "updates self's lineno by one" do + @io.send(@method, ">") + @io.lineno.should eql(1) + + @io.send(@method, ">") + @io.lineno.should eql(2) + + @io.send(@method, ">") + @io.lineno.should eql(3) + end + + it "returns the next paragraph when the passed separator is an empty String" do + io = StringIO.new("this is\n\nan example") + io.send(@method, "").should == "this is\n\n" + io.send(@method, "").should == "an example" + end + + it "returns the remaining content starting at the current position when passed nil" do + io = StringIO.new("this is\n\nan example") + io.pos = 5 + io.send(@method, nil).should == "is\n\nan example" + end + + it "tries to convert the passed separator to a String using #to_str" do + obj = mock('to_str') + obj.should_receive(:to_str).and_return(">") + @io.send(@method, obj).should == "this>" + end + end +end + +describe :stringio_gets_limit, shared: true do + describe "when passed [limit]" do + before :each do + @io = StringIO.new("this>is>an>example") + end + + it "returns the data read until the limit is met" do + @io.send(@method, 4).should == "this" + @io.send(@method, 3).should == ">is" + @io.send(@method, 5).should == ">an>e" + @io.send(@method, 6).should == "xample" + end + + it "sets $_ to the read content" do + @io.send(@method, 4) + $_.should == "this" + @io.send(@method, 3) + $_.should == ">is" + @io.send(@method, 5) + $_.should == ">an>e" + @io.send(@method, 6) + $_.should == "xample" + end + + it "updates self's lineno by one" do + @io.send(@method, 3) + @io.lineno.should eql(1) + + @io.send(@method, 3) + @io.lineno.should eql(2) + + @io.send(@method, 3) + @io.lineno.should eql(3) + end + + it "tries to convert the passed limit to an Integer using #to_int" do + obj = mock('to_int') + obj.should_receive(:to_int).and_return(4) + @io.send(@method, obj).should == "this" + end + + it "returns a blank string when passed a limit of 0" do + @io.send(@method, 0).should == "" + end + + it "ignores it when passed a negative limit" do + @io.send(@method, -4).should == "this>is>an>example" + end + end +end + +describe :stringio_gets_separator_and_limit, shared: true do + describe "when passed [separator] and [limit]" do + before :each do + @io = StringIO.new("this>is>an>example") + end + + it "returns the data read until the limit is consumed or the separator is met" do + @io.send(@method, '>', 8).should == "this>" + @io.send(@method, '>', 2).should == "is" + @io.send(@method, '>', 10).should == ">" + @io.send(@method, '>', 6).should == "an>" + @io.send(@method, '>', 5).should == "examp" + end + + it "truncates the multi-character separator at the end to meet the limit" do + @io.send(@method, "is>an", 7).should == "this>is" + end + + it "sets $_ to the read content" do + @io.send(@method, '>', 8) + $_.should == "this>" + @io.send(@method, '>', 2) + $_.should == "is" + @io.send(@method, '>', 10) + $_.should == ">" + @io.send(@method, '>', 6) + $_.should == "an>" + @io.send(@method, '>', 5) + $_.should == "examp" + end + + it "updates self's lineno by one" do + @io.send(@method, '>', 3) + @io.lineno.should eql(1) + + @io.send(@method, '>', 3) + @io.lineno.should eql(2) + + @io.send(@method, '>', 3) + @io.lineno.should eql(3) + end + + it "tries to convert the passed separator to a String using #to_str" do + obj = mock('to_str') + obj.should_receive(:to_str).and_return('>') + @io.send(@method, obj, 5).should == "this>" + end + + it "does not raise TypeError if passed separator is nil" do + @io.send(@method, nil, 5).should == "this>" + end + + it "tries to convert the passed limit to an Integer using #to_int" do + obj = mock('to_int') + obj.should_receive(:to_int).and_return(5) + @io.send(@method, '>', obj).should == "this>" + end + end +end + +describe :stringio_gets_no_argument, shared: true do + describe "when passed no argument" do + before :each do + @io = StringIO.new("this is\nan example\nfor StringIO#gets") + end + + it "returns the data read till the next occurrence of $/ or till eof" do + @io.send(@method).should == "this is\n" + + begin + old_sep = $/ + suppress_warning {$/ = " "} + @io.send(@method).should == "an " + @io.send(@method).should == "example\nfor " + @io.send(@method).should == "StringIO#gets" + ensure + suppress_warning {$/ = old_sep} + end + end + + it "sets $_ to the read content" do + @io.send(@method) + $_.should == "this is\n" + @io.send(@method) + $_.should == "an example\n" + @io.send(@method) + $_.should == "for StringIO#gets" + end + + it "updates self's position" do + @io.send(@method) + @io.pos.should eql(8) + + @io.send(@method) + @io.pos.should eql(19) + + @io.send(@method) + @io.pos.should eql(36) + end + + it "updates self's lineno" do + @io.send(@method) + @io.lineno.should eql(1) + + @io.send(@method) + @io.lineno.should eql(2) + + @io.send(@method) + @io.lineno.should eql(3) + end + end +end + +describe :stringio_gets_chomp, shared: true do + describe "when passed [chomp]" do + it "returns the data read without a trailing newline character" do + io = StringIO.new("this>is>an>example\n") + io.send(@method, chomp: true).should == "this>is>an>example" + end + end +end + +describe :stringio_gets_write_only, shared: true do + describe "when in write-only mode" do + it "raises an IOError" do + io = StringIO.new(+"xyz", "w") + -> { io.send(@method) }.should raise_error(IOError) + + io = StringIO.new("xyz") + io.close_read + -> { io.send(@method) }.should raise_error(IOError) + end + end +end diff --git a/spec/ruby/library/stringio/shared/isatty.rb b/spec/ruby/library/stringio/shared/isatty.rb index 3da5999953..c9e7ee7321 100644 --- a/spec/ruby/library/stringio/shared/isatty.rb +++ b/spec/ruby/library/stringio/shared/isatty.rb @@ -1,5 +1,5 @@ describe :stringio_isatty, shared: true do it "returns false" do - StringIO.new('tty').send(@method).should be_false + StringIO.new("tty").send(@method).should be_false end end diff --git a/spec/ruby/library/stringio/shared/read.rb b/spec/ruby/library/stringio/shared/read.rb index 252a85d89d..22f76b0fb0 100644 --- a/spec/ruby/library/stringio/shared/read.rb +++ b/spec/ruby/library/stringio/shared/read.rb @@ -5,19 +5,37 @@ describe :stringio_read, shared: true do it "returns the passed buffer String" do # Note: Rubinius bug: - # @io.send(@method, 7, buffer = "").should equal(buffer) - ret = @io.send(@method, 7, buffer = "") + # @io.send(@method, 7, buffer = +"").should equal(buffer) + ret = @io.send(@method, 7, buffer = +"") ret.should equal(buffer) end it "reads length bytes and writes them to the buffer String" do - @io.send(@method, 7, buffer = "") + @io.send(@method, 7, buffer = +"").should.equal?(buffer) buffer.should == "example" end + guard -> { StringIO::VERSION < "3.1.2" } do + it "does not preserve the encoding of the given buffer" do + buffer = ''.encode(Encoding::ISO_8859_1) + @io.send(@method, 7, buffer) + + buffer.encoding.should_not == Encoding::ISO_8859_1 + end + end + + guard -> { StringIO::VERSION >= "3.1.2" } do + it "preserves the encoding of the given buffer" do + buffer = ''.encode(Encoding::ISO_8859_1) + @io.send(@method, 7, buffer) + + buffer.encoding.should == Encoding::ISO_8859_1 + end + end + it "tries to convert the passed buffer Object to a String using #to_str" do obj = mock("to_str") - obj.should_receive(:to_str).and_return(buffer = "") + obj.should_receive(:to_str).and_return(buffer = +"") @io.send(@method, 7, obj) buffer.should == "example" @@ -75,7 +93,7 @@ end describe :stringio_read_no_arguments, shared: true do before :each do - @io = StringIO.new("example") + @io = StringIO.new(+"example") end it "reads the whole content starting from the current position" do @@ -117,7 +135,7 @@ end describe :stringio_read_not_readable, shared: true do it "raises an IOError" do - io = StringIO.new("test", "w") + io = StringIO.new(+"test", "w") -> { io.send(@method) }.should raise_error(IOError) io = StringIO.new("test") diff --git a/spec/ruby/library/stringio/shared/readchar.rb b/spec/ruby/library/stringio/shared/readchar.rb index 4248e75420..72d7446c36 100644 --- a/spec/ruby/library/stringio/shared/readchar.rb +++ b/spec/ruby/library/stringio/shared/readchar.rb @@ -19,7 +19,7 @@ end describe :stringio_readchar_not_readable, shared: true do it "raises an IOError" do - io = StringIO.new("a b c d e", "w") + io = StringIO.new(+"a b c d e", "w") -> { io.send(@method) }.should raise_error(IOError) io = StringIO.new("a b c d e") diff --git a/spec/ruby/library/stringio/shared/sysread.rb b/spec/ruby/library/stringio/shared/sysread.rb index 3376bd9907..3e23fbc233 100644 --- a/spec/ruby/library/stringio/shared/sysread.rb +++ b/spec/ruby/library/stringio/shared/sysread.rb @@ -1,4 +1,4 @@ -describe :stringio_sysread_length, :shared => true do +describe :stringio_sysread_length, shared: true do before :each do @io = StringIO.new("example") end @@ -10,6 +10,6 @@ describe :stringio_sysread_length, :shared => true do it "raises an EOFError when passed length > 0 and no data remains" do @io.read.should == "example" - -> { @io.sysread(1) }.should raise_error(EOFError) + -> { @io.send(@method, 1) }.should raise_error(EOFError) end end diff --git a/spec/ruby/library/stringio/shared/write.rb b/spec/ruby/library/stringio/shared/write.rb index d9c21028e0..4661658baf 100644 --- a/spec/ruby/library/stringio/shared/write.rb +++ b/spec/ruby/library/stringio/shared/write.rb @@ -1,6 +1,6 @@ describe :stringio_write, shared: true do before :each do - @io = StringIO.new('12345') + @io = StringIO.new(+'12345') end it "tries to convert the passed Object to a String using #to_s" do @@ -13,7 +13,7 @@ end describe :stringio_write_string, shared: true do before :each do - @io = StringIO.new('12345') + @io = StringIO.new(+'12345') end # TODO: RDoc says that #write appends at the current position. @@ -60,13 +60,6 @@ describe :stringio_write_string, shared: true do @io.string.size.should == n.times.map(&:to_s).join.size end - ruby_version_is ""..."3.0" do - it "does not taint self when the passed argument is tainted" do - @io.send(@method, "test".taint) - @io.tainted?.should be_false - end - end - it "handles writing non-ASCII UTF-8 after seek" do @io.binmode @io << "\x80" @@ -88,14 +81,35 @@ describe :stringio_write_string, shared: true do @io.write "fghi" @io.string.should == "12fghi" end + + it "transcodes the given string when the external encoding is set and neither is BINARY" do + utf8_str = "hello" + io = StringIO.new.set_encoding(Encoding::UTF_16BE) + io.external_encoding.should == Encoding::UTF_16BE + + io.send(@method, utf8_str) + + expected = [0, 104, 0, 101, 0, 108, 0, 108, 0, 111] # UTF-16BE bytes for "hello" + io.string.bytes.should == expected + end + + it "does not transcode the given string when the external encoding is set and the string encoding is BINARY" do + str = "été_".b + io = StringIO.new.set_encoding(Encoding::UTF_16BE) + io.external_encoding.should == Encoding::UTF_16BE + + io.send(@method, str) + + io.string.bytes.should == str.bytes + end end describe :stringio_write_not_writable, shared: true do it "raises an IOError" do - io = StringIO.new("test", "r") + io = StringIO.new(+"test", "r") -> { io.send(@method, "test") }.should raise_error(IOError) - io = StringIO.new("test") + io = StringIO.new(+"test") io.close_write -> { io.send(@method, "test") }.should raise_error(IOError) end @@ -103,7 +117,7 @@ end describe :stringio_write_append, shared: true do before :each do - @io = StringIO.new("example", "a") + @io = StringIO.new(+"example", "a") end it "appends the passed argument to the end of self" do diff --git a/spec/ruby/library/stringio/sysread_spec.rb b/spec/ruby/library/stringio/sysread_spec.rb index 8f78073f42..fabb06dd9a 100644 --- a/spec/ruby/library/stringio/sysread_spec.rb +++ b/spec/ruby/library/stringio/sysread_spec.rb @@ -1,6 +1,7 @@ require_relative '../../spec_helper' require "stringio" require_relative 'shared/read' +require_relative 'shared/sysread' describe "StringIO#sysread when passed length, buffer" do it_behaves_like :stringio_read, :sysread @@ -32,6 +33,10 @@ describe "StringIO#sysread when passed nil" do end end +describe "StringIO#sysread when passed length" do + it_behaves_like :stringio_sysread_length, :sysread +end + describe "StringIO#sysread when passed [length]" do before :each do @io = StringIO.new("example") diff --git a/spec/ruby/library/stringio/truncate_spec.rb b/spec/ruby/library/stringio/truncate_spec.rb index e8d7f1a15d..592ca5a6e1 100644 --- a/spec/ruby/library/stringio/truncate_spec.rb +++ b/spec/ruby/library/stringio/truncate_spec.rb @@ -3,7 +3,7 @@ require "stringio" describe "StringIO#truncate when passed [length]" do before :each do - @io = StringIO.new('123456789') + @io = StringIO.new(+'123456789') end it "returns an Integer" do @@ -16,7 +16,7 @@ describe "StringIO#truncate when passed [length]" do end it "does not create a copy of the underlying string" do - io = StringIO.new(str = "123456789") + io = StringIO.new(str = +"123456789") io.truncate(4) io.string.should equal(str) end @@ -52,10 +52,10 @@ end describe "StringIO#truncate when self is not writable" do it "raises an IOError" do - io = StringIO.new("test", "r") + io = StringIO.new(+"test", "r") -> { io.truncate(2) }.should raise_error(IOError) - io = StringIO.new("test") + io = StringIO.new(+"test") io.close_write -> { io.truncate(2) }.should raise_error(IOError) end diff --git a/spec/ruby/library/stringio/ungetc_spec.rb b/spec/ruby/library/stringio/ungetc_spec.rb index 91ef2100a1..bceafa79ff 100644 --- a/spec/ruby/library/stringio/ungetc_spec.rb +++ b/spec/ruby/library/stringio/ungetc_spec.rb @@ -3,7 +3,7 @@ require_relative 'fixtures/classes' describe "StringIO#ungetc when passed [char]" do before :each do - @io = StringIO.new('1234') + @io = StringIO.new(+'1234') end it "writes the passed char before the current position" do @@ -45,11 +45,11 @@ end describe "StringIO#ungetc when self is not readable" do it "raises an IOError" do - io = StringIO.new("test", "w") + io = StringIO.new(+"test", "w") io.pos = 1 -> { io.ungetc(?A) }.should raise_error(IOError) - io = StringIO.new("test") + io = StringIO.new(+"test") io.pos = 1 io.close_read -> { io.ungetc(?A) }.should raise_error(IOError) @@ -60,11 +60,11 @@ end # # describe "StringIO#ungetc when self is not writable" do # it "raises an IOError" do -# io = StringIO.new("test", "r") +# io = StringIO.new(+"test", "r") # io.pos = 1 # lambda { io.ungetc(?A) }.should raise_error(IOError) # -# io = StringIO.new("test") +# io = StringIO.new(+"test") # io.pos = 1 # io.close_write # lambda { io.ungetc(?A) }.should raise_error(IOError) diff --git a/spec/ruby/library/stringio/write_nonblock_spec.rb b/spec/ruby/library/stringio/write_nonblock_spec.rb index a457b97667..b48ef6698a 100644 --- a/spec/ruby/library/stringio/write_nonblock_spec.rb +++ b/spec/ruby/library/stringio/write_nonblock_spec.rb @@ -10,7 +10,7 @@ describe "StringIO#write_nonblock when passed [String]" do it_behaves_like :stringio_write_string, :write_nonblock it "accepts :exception option" do - io = StringIO.new("12345", "a") + io = StringIO.new(+"12345", "a") io.write_nonblock("67890", exception: true) io.string.should == "1234567890" end diff --git a/spec/ruby/library/stringscanner/captures_spec.rb b/spec/ruby/library/stringscanner/captures_spec.rb new file mode 100644 index 0000000000..bdfb0e0cc5 --- /dev/null +++ b/spec/ruby/library/stringscanner/captures_spec.rb @@ -0,0 +1,36 @@ +require_relative '../../spec_helper' +require 'strscan' + +describe "StringScanner#captures" do + before do + @s = StringScanner.new('Fri Dec 12 1975 14:39') + end + + it "returns the array of captured values of the most recent matching" do + @s.exist?(/(?<wday>\w+) (?<month>\w+) (?<day>\d+)/) + @s.captures.should == ["Fri", "Dec", "12"] + end + + it "returns nil if the last match fails" do + @s.scan(/nope/) + @s.captures.should == nil + end + + it "returns nil if there is no any match done" do + @s.captures.should == nil + end + + version_is StringScanner::Version, ""..."3.0.8" do # ruby_version_is ""..."3.3.3" + it "returns '' for an optional capturing group if it doesn't match" do + @s.exist?(/(?<wday>\w+) (?<month>\w+) (?<day>\s+)?/) + @s.captures.should == ["Fri", "Dec", ""] + end + end + + version_is StringScanner::Version, "3.0.8" do # ruby_version_is "3.3.3" + it "returns nil for an optional capturing group if it doesn't match" do + @s.exist?(/(?<wday>\w+) (?<month>\w+) (?<day>\s+)?/) + @s.captures.should == ["Fri", "Dec", nil] + end + end +end diff --git a/spec/ruby/library/stringscanner/charpos_spec.rb b/spec/ruby/library/stringscanner/charpos_spec.rb new file mode 100644 index 0000000000..9aa5b00dd9 --- /dev/null +++ b/spec/ruby/library/stringscanner/charpos_spec.rb @@ -0,0 +1,18 @@ +require_relative '../../spec_helper' +require 'strscan' + +describe "StringScanner#charpos" do + it "returns character index corresponding to the current position" do + s = StringScanner.new("abc") + + s.scan_until(/b/) + s.charpos.should == 2 + end + + it "is multi-byte character sensitive" do + s = StringScanner.new("abcädeföghi") + + s.scan_until(/ö/) + s.charpos.should == 8 + end +end diff --git a/spec/ruby/library/stringscanner/check_spec.rb b/spec/ruby/library/stringscanner/check_spec.rb index a97c26af83..5e855e154a 100644 --- a/spec/ruby/library/stringscanner/check_spec.rb +++ b/spec/ruby/library/stringscanner/check_spec.rb @@ -22,4 +22,72 @@ describe "StringScanner#check" do @s.matched.should == nil end + describe "#[] successive call with a capture group name" do + context "when #check was called with a Regexp pattern" do + it "returns matched substring when matching succeeded" do + @s.check(/(?<a>This)/) + @s.should.matched? + @s[:a].should == "This" + end + + it "returns nil when matching failed" do + @s.check(/(?<a>2008)/) + @s.should_not.matched? + @s[:a].should be_nil + end + end + + context "when #check was called with a String pattern" do + # https://github.com/ruby/strscan/issues/139 + version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.0"..."3.4.3" + it "returns nil when matching succeeded" do + @s.check("This") + @s.should.matched? + @s[:a].should be_nil + end + end + version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4" + it "raises IndexError when matching succeeded" do + @s.check("This") + @s.should.matched? + -> { @s[:a] }.should raise_error(IndexError) + end + end + + it "returns nil when matching failed" do + @s.check("2008") + @s.should_not.matched? + @s[:a].should be_nil + end + + it "returns a matching substring when given Integer index" do + @s.check("This") + @s[0].should == "This" + end + + # https://github.com/ruby/strscan/issues/135 + version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.0"..."3.4.3" + it "ignores the previous matching with Regexp" do + @s.exist?(/(?<a>This)/) + @s.should.matched? + @s[:a].should == "This" + + @s.check("This") + @s.should.matched? + @s[:a].should be_nil + end + end + version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4.0"..."3.4.3" + it "ignores the previous matching with Regexp" do + @s.exist?(/(?<a>This)/) + @s.should.matched? + @s[:a].should == "This" + + @s.check("This") + @s.should.matched? + -> { @s[:a] }.should raise_error(IndexError) + end + end + end + end end diff --git a/spec/ruby/library/stringscanner/check_until_spec.rb b/spec/ruby/library/stringscanner/check_until_spec.rb index ad222fd76b..582da66b37 100644 --- a/spec/ruby/library/stringscanner/check_until_spec.rb +++ b/spec/ruby/library/stringscanner/check_until_spec.rb @@ -2,20 +2,128 @@ require_relative '../../spec_helper' require 'strscan' describe "StringScanner#check_until" do - before :each do + before do @s = StringScanner.new("This is a test") end - it "returns the same value of scan_until, but don't advances the scan pointer" do + it "returns the same value of #scan_until, but don't advances the scan pointer" do @s.check_until(/a/).should == "This is a" @s.pos.should == 0 - @s.matched.should == "a" @s.check_until(/test/).should == "This is a test" end - it "raises TypeError if given a String" do - -> { - @s.check_until('T') - }.should raise_error(TypeError, 'wrong argument type String (expected Regexp)') + it "sets the last match result" do + @s.check_until(/a/) + + @s.pre_match.should == "This is " + @s.matched.should == "a" + @s.post_match.should == " test" + end + + version_is StringScanner::Version, ""..."3.1.1" do # ruby_version_is ""..."3.4" + it "raises TypeError if given a String" do + -> { + @s.check_until('T') + }.should raise_error(TypeError, 'wrong argument type String (expected Regexp)') + end + end + + version_is StringScanner::Version, "3.1.1" do # ruby_version_is "3.4" + it "searches a substring in the rest part of a string if given a String" do + @s.check_until("a").should == "This is a" + @s.pos.should == 0 + end + + # https://github.com/ruby/strscan/issues/131 + version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.1" + it "sets the last match result if given a String" do + @s.check_until("a") + + @s.pre_match.should == "" + @s.matched.should == "This is a" + @s.post_match.should == " test" + end + end + + version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4" + it "sets the last match result if given a String" do + @s.check_until("a") + + @s.pre_match.should == "This is " + @s.matched.should == "a" + @s.post_match.should == " test" + end + end + end + + describe "#[] successive call with a capture group name" do + context "when #check_until was called with a Regexp pattern" do + it "returns matched substring when matching succeeded" do + @s.check_until(/(?<a>This)/) + @s.should.matched? + @s[:a].should == "This" + end + + it "returns nil when matching failed" do + @s.check_until(/(?<a>2008)/) + @s.should_not.matched? + @s[:a].should be_nil + end + end + + version_is StringScanner::Version, "3.1.1" do # ruby_version_is "3.4" + context "when #check_until was called with a String pattern" do + # https://github.com/ruby/strscan/issues/139 + version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.0"..."3.4.3" + it "returns nil when matching succeeded" do + @s.check_until("This") + @s.should.matched? + @s[:a].should be_nil + end + end + version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4.3" + it "raises IndexError when matching succeeded" do + @s.check_until("This") + @s.should.matched? + -> { @s[:a] }.should raise_error(IndexError) + end + end + + it "returns nil when matching failed" do + @s.check_until("2008") + @s.should_not.matched? + @s[:a].should be_nil + end + + it "returns a matching substring when given Integer index" do + @s.check_until("This") + @s[0].should == "This" + end + + # https://github.com/ruby/strscan/issues/135 + version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.0"..."3.4.3" + it "ignores the previous matching with Regexp" do + @s.exist?(/(?<a>This)/) + @s.should.matched? + @s[:a].should == "This" + + @s.check_until("This") + @s.should.matched? + @s[:a].should be_nil + end + end + version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4.0"..."3.4.3" + it "ignores the previous matching with Regexp" do + @s.exist?(/(?<a>This)/) + @s.should.matched? + @s[:a].should == "This" + + @s.check_until("This") + @s.should.matched? + -> { @s[:a] }.should raise_error(IndexError) + end + end + end + end end end diff --git a/spec/ruby/library/stringscanner/clear_spec.rb b/spec/ruby/library/stringscanner/clear_spec.rb deleted file mode 100644 index 7ae089704a..0000000000 --- a/spec/ruby/library/stringscanner/clear_spec.rb +++ /dev/null @@ -1,18 +0,0 @@ -require_relative '../../spec_helper' -require_relative 'shared/terminate' -require 'strscan' - -describe "StringScanner#clear" do - it_behaves_like :strscan_terminate, :clear - - it "warns in verbose mode that the method is obsolete" do - s = StringScanner.new("abc") - -> { - s.clear - }.should complain(/clear.*obsolete.*terminate/, verbose: true) - - -> { - s.clear - }.should_not complain(verbose: false) - end -end diff --git a/spec/ruby/library/stringscanner/element_reference_spec.rb b/spec/ruby/library/stringscanner/element_reference_spec.rb index 60fe15d807..91b6d86dc7 100644 --- a/spec/ruby/library/stringscanner/element_reference_spec.rb +++ b/spec/ruby/library/stringscanner/element_reference_spec.rb @@ -8,6 +8,7 @@ describe "StringScanner#[]" do it "returns nil if there is no current match" do @s[0].should be_nil + @s[:wday].should be_nil end it "returns the n-th subgroup in the most recent match" do @@ -42,12 +43,18 @@ describe "StringScanner#[]" do -> { @s[0..2]}.should raise_error(TypeError) end - it "raises a IndexError when there's no named capture" do + it "raises a IndexError when there's no any named capture group in the regexp" do @s.scan(/(\w+) (\w+) (\d+) /) -> { @s["wday"]}.should raise_error(IndexError) -> { @s[:wday]}.should raise_error(IndexError) end + it "raises a IndexError when given a not existing capture group name" do + @s.scan(/(?<a>\w+) (?<b>\w+) (?<c>\d+) /) + -> { @s["wday"]}.should raise_error(IndexError) + -> { @s[:wday]}.should raise_error(IndexError) + end + it "returns named capture" do @s.scan(/(?<wday>\w+) (?<month>\w+) (?<day>\d+) /) @s["wday"].should == "Fri" diff --git a/spec/ruby/library/stringscanner/empty_spec.rb b/spec/ruby/library/stringscanner/empty_spec.rb deleted file mode 100644 index d9449bea6e..0000000000 --- a/spec/ruby/library/stringscanner/empty_spec.rb +++ /dev/null @@ -1,18 +0,0 @@ -require_relative '../../spec_helper' -require_relative 'shared/eos' -require 'strscan' - -describe "StringScanner#empty?" do - it_behaves_like :strscan_eos, :empty? - - it "warns in verbose mode that the method is obsolete" do - s = StringScanner.new("abc") - -> { - s.empty? - }.should complain(/empty?.*obsolete.*eos?/, verbose: true) - - -> { - s.empty? - }.should_not complain(verbose: false) - end -end diff --git a/spec/ruby/library/stringscanner/eos_spec.rb b/spec/ruby/library/stringscanner/eos_spec.rb index b58ee1e473..03c2804e5b 100644 --- a/spec/ruby/library/stringscanner/eos_spec.rb +++ b/spec/ruby/library/stringscanner/eos_spec.rb @@ -1,7 +1,20 @@ require_relative '../../spec_helper' -require_relative 'shared/eos' require 'strscan' describe "StringScanner#eos?" do - it_behaves_like :strscan_eos, :eos? + before :each do + @s = StringScanner.new("This is a test") + end + + it "returns true if the scan pointer is at the end of the string" do + @s.terminate + @s.should.eos? + + s = StringScanner.new('') + s.should.eos? + end + + it "returns false if the scan pointer is not at the end of the string" do + @s.should_not.eos? + end end diff --git a/spec/ruby/library/stringscanner/exist_spec.rb b/spec/ruby/library/stringscanner/exist_spec.rb index ff860a0d3e..a408fd0b8d 100644 --- a/spec/ruby/library/stringscanner/exist_spec.rb +++ b/spec/ruby/library/stringscanner/exist_spec.rb @@ -2,11 +2,11 @@ require_relative '../../spec_helper' require 'strscan' describe "StringScanner#exist?" do - before :each do + before do @s = StringScanner.new("This is a test") end - it "returns the index of the first occurrence of the given pattern" do + it "returns distance in bytes between the current position and the end of the matched substring" do @s.exist?(/s/).should == 4 @s.scan(/This is/) @s.exist?(/s/).should == 6 @@ -22,9 +22,98 @@ describe "StringScanner#exist?" do @s.exist?(/i/).should == nil end - it "raises TypeError if given a String" do - -> { - @s.exist?('T') - }.should raise_error(TypeError, 'wrong argument type String (expected Regexp)') + it "does not modify the current position" do + @s.pos.should == 0 + @s.exist?(/s/).should == 4 + @s.pos.should == 0 + end + + version_is StringScanner::Version, ""..."3.1.1" do # ruby_version_is ""..."3.4" + it "raises TypeError if given a String" do + -> { + @s.exist?('T') + }.should raise_error(TypeError, 'wrong argument type String (expected Regexp)') + end + end + + version_is StringScanner::Version, "3.1.1" do # ruby_version_is "3.4" + it "searches a substring in the rest part of a string if given a String" do + @s.exist?('a').should == 9 + end + + it "returns nil if the pattern isn't found in the string" do + @s.exist?("S").should == nil + end + end + + describe "#[] successive call with a capture group name" do + context "when #exist? was called with a Regexp pattern" do + it "returns matched substring when matching succeeded" do + @s.exist?(/(?<a>This)/) + @s.should.matched? + @s[:a].should == "This" + end + + it "returns nil when matching failed" do + @s.exist?(/(?<a>2008)/) + @s.should_not.matched? + @s[:a].should be_nil + end + end + + version_is StringScanner::Version, "3.1.1" do # ruby_version_is "3.4" + context "when #exist? was called with a String pattern" do + # https://github.com/ruby/strscan/issues/139 + version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.0"..."3.4.3" + it "returns nil when matching succeeded" do + @s.exist?("This") + @s.should.matched? + @s[:a].should be_nil + end + end + version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4.3" + it "raises IndexError when matching succeeded" do + @s.exist?("This") + @s.should.matched? + -> { @s[:a] }.should raise_error(IndexError) + end + end + + it "returns nil when matching failed" do + @s.exist?("2008") + @s.should_not.matched? + @s[:a].should be_nil + end + + it "returns a matching substring when given Integer index" do + @s.exist?("This") + @s[0].should == "This" + end + + # https://github.com/ruby/strscan/issues/135 + version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.0"..."3.4.3" + it "ignores the previous matching with Regexp" do + @s.exist?(/(?<a>This)/) + @s.should.matched? + @s[:a].should == "This" + + @s.exist?("This") + @s.should.matched? + @s[:a].should be_nil + end + end + version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4.0"..."3.4.3" + it "ignores the previous matching with Regexp" do + @s.exist?(/(?<a>This)/) + @s.should.matched? + @s[:a].should == "This" + + @s.exist?("This") + @s.should.matched? + -> { @s[:a] }.should raise_error(IndexError) + end + end + end + end end end diff --git a/spec/ruby/library/stringscanner/fixed_anchor_spec.rb b/spec/ruby/library/stringscanner/fixed_anchor_spec.rb new file mode 100644 index 0000000000..ce0b714fa8 --- /dev/null +++ b/spec/ruby/library/stringscanner/fixed_anchor_spec.rb @@ -0,0 +1,17 @@ +require_relative '../../spec_helper' +require 'strscan' + +describe "StringScanner#fixed_anchor?" do + it "returns whether the fixed-anchor property is set" do + s = StringScanner.new("foo", fixed_anchor: true) + s.should.fixed_anchor? + + s = StringScanner.new("foo", fixed_anchor: false) + s.should_not.fixed_anchor? + end + + it "is set to false by default" do + s = StringScanner.new("foo") + s.should_not.fixed_anchor? + end +end diff --git a/spec/ruby/library/stringscanner/get_byte_spec.rb b/spec/ruby/library/stringscanner/get_byte_spec.rb index 29e2f557de..144859abc9 100644 --- a/spec/ruby/library/stringscanner/get_byte_spec.rb +++ b/spec/ruby/library/stringscanner/get_byte_spec.rb @@ -1,7 +1,84 @@ +# encoding: binary require_relative '../../spec_helper' -require_relative 'shared/get_byte' require 'strscan' describe "StringScanner#get_byte" do - it_behaves_like :strscan_get_byte, :get_byte + it "scans one byte and returns it" do + s = StringScanner.new('abc5.') + s.get_byte.should == 'a' + s.get_byte.should == 'b' + s.get_byte.should == 'c' + s.get_byte.should == '5' + s.get_byte.should == '.' + end + + it "is not multi-byte character sensitive" do + s = StringScanner.new("\244\242") + s.get_byte.should == "\244" + s.get_byte.should == "\242" + end + + it "returns nil at the end of the string" do + # empty string case + s = StringScanner.new('') + s.get_byte.should == nil + s.get_byte.should == nil + + # non-empty string case + s = StringScanner.new('a') + s.get_byte # skip one + s.get_byte.should == nil + end + + describe "#[] successive call with a capture group name" do + # https://github.com/ruby/strscan/issues/139 + version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.0"..."3.4.3" + it "returns nil" do + s = StringScanner.new("This is a test") + s.get_byte + s.should.matched? + s[:a].should be_nil + end + end + version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4.3" + it "raises IndexError" do + s = StringScanner.new("This is a test") + s.get_byte + s.should.matched? + -> { s[:a] }.should raise_error(IndexError) + end + end + + it "returns a matching character when given Integer index" do + s = StringScanner.new("This is a test") + s.get_byte + s[0].should == "T" + end + + # https://github.com/ruby/strscan/issues/135 + version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.0"..."3.4.3" + it "ignores the previous matching with Regexp" do + s = StringScanner.new("This is a test") + s.exist?(/(?<a>This)/) + s.should.matched? + s[:a].should == "This" + + s.get_byte + s.should.matched? + s[:a].should be_nil + end + end + version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4.3" + it "ignores the previous matching with Regexp" do + s = StringScanner.new("This is a test") + s.exist?(/(?<a>This)/) + s.should.matched? + s[:a].should == "This" + + s.get_byte + s.should.matched? + -> { s[:a] }.should raise_error(IndexError) + end + end + end end diff --git a/spec/ruby/library/stringscanner/getbyte_spec.rb b/spec/ruby/library/stringscanner/getbyte_spec.rb deleted file mode 100644 index e0659a5829..0000000000 --- a/spec/ruby/library/stringscanner/getbyte_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -require_relative '../../spec_helper' -require_relative 'shared/get_byte' -require_relative 'shared/extract_range' -require 'strscan' - -describe "StringScanner#getbyte" do - it_behaves_like :strscan_get_byte, :getbyte - - it "warns in verbose mode that the method is obsolete" do - s = StringScanner.new("abc") - -> { - s.getbyte - }.should complain(/getbyte.*obsolete.*get_byte/, verbose: true) - - -> { - s.getbyte - }.should_not complain(verbose: false) - end - - it_behaves_like :extract_range, :getbyte -end diff --git a/spec/ruby/library/stringscanner/getch_spec.rb b/spec/ruby/library/stringscanner/getch_spec.rb index a6be0d4221..d369391b14 100644 --- a/spec/ruby/library/stringscanner/getch_spec.rb +++ b/spec/ruby/library/stringscanner/getch_spec.rb @@ -1,4 +1,4 @@ -# -*- encoding: binary -*- +# encoding: binary require_relative '../../spec_helper' require_relative 'shared/extract_range' require 'strscan' @@ -13,7 +13,7 @@ describe "StringScanner#getch" do it "is multi-byte character sensitive" do # Japanese hiragana "A" in EUC-JP - src = "\244\242".force_encoding("euc-jp") + src = "\244\242".dup.force_encoding("euc-jp") s = StringScanner.new(src) s.getch.should == src @@ -31,5 +31,59 @@ describe "StringScanner#getch" do s.getch.should == nil end + describe "#[] successive call with a capture group name" do + # https://github.com/ruby/strscan/issues/139 + version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.0"..."3.4.3" + it "returns nil" do + s = StringScanner.new("This is a test") + s.getch + s.should.matched? + s[:a].should be_nil + end + end + version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4.3" + it "raises IndexError" do + s = StringScanner.new("This is a test") + s.getch + s.should.matched? + -> { s[:a] }.should raise_error(IndexError) + end + end + + it "returns a matching character when given Integer index" do + s = StringScanner.new("This is a test") + s.getch + s[0].should == "T" + end + + # https://github.com/ruby/strscan/issues/135 + version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.0"..."3.4.3" + it "ignores the previous matching with Regexp" do + s = StringScanner.new("This is a test") + + s.exist?(/(?<a>This)/) + s.should.matched? + s[:a].should == "This" + + s.getch + s.should.matched? + s[:a].should be_nil + end + end + version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4.0"..."3.4.3" + it "ignores the previous matching with Regexp" do + s = StringScanner.new("This is a test") + + s.exist?(/(?<a>This)/) + s.should.matched? + s[:a].should == "This" + + s.getch + s.should.matched? + -> { s[:a] }.should raise_error(IndexError) + end + end + end + it_behaves_like :extract_range, :getch end diff --git a/spec/ruby/library/stringscanner/initialize_spec.rb b/spec/ruby/library/stringscanner/initialize_spec.rb index 047d9d058b..77f6084c1b 100644 --- a/spec/ruby/library/stringscanner/initialize_spec.rb +++ b/spec/ruby/library/stringscanner/initialize_spec.rb @@ -24,4 +24,9 @@ describe "StringScanner#initialize" do scan = StringScanner.new(m) scan.string.should == s end + + it "accepts a fixed_anchor keyword argument" do + s = StringScanner.new("foo", fixed_anchor: true) + s.should.fixed_anchor? + end end diff --git a/spec/ruby/library/stringscanner/match_spec.rb b/spec/ruby/library/stringscanner/match_spec.rb index ec59680914..a27bb51d72 100644 --- a/spec/ruby/library/stringscanner/match_spec.rb +++ b/spec/ruby/library/stringscanner/match_spec.rb @@ -17,6 +17,15 @@ describe "StringScanner#match?" do @s.match?(/\s+/).should == nil end + it "sets the last match result" do + @s.pos = 8 + @s.match?(/a/) + + @s.pre_match.should == "This is " + @s.matched.should == "a" + @s.post_match.should == " test" + end + it "effects pre_match" do @s.scan(/\w+/) @s.scan(/\s/) @@ -25,4 +34,18 @@ describe "StringScanner#match?" do @s.match?(/\w+/) @s.pre_match.should == "This " end + + describe "#[] successive call with a capture group name" do + it "returns matched substring when matching succeeded" do + @s.match?(/(?<a>This)/) + @s.should.matched? + @s[:a].should == "This" + end + + it "returns nil when matching failed" do + @s.match?(/(?<a>2008)/) + @s.should_not.matched? + @s[:a].should be_nil + end + end end diff --git a/spec/ruby/library/stringscanner/must_C_version_spec.rb b/spec/ruby/library/stringscanner/must_C_version_spec.rb index fcc5b596f6..9d6edfe7b6 100644 --- a/spec/ruby/library/stringscanner/must_C_version_spec.rb +++ b/spec/ruby/library/stringscanner/must_C_version_spec.rb @@ -3,6 +3,6 @@ require 'strscan' describe "StringScanner.must_C_version" do it "returns self" do - StringScanner.must_C_version.should == StringScanner + StringScanner.must_C_version.should == StringScanner end end diff --git a/spec/ruby/library/stringscanner/named_captures_spec.rb b/spec/ruby/library/stringscanner/named_captures_spec.rb new file mode 100644 index 0000000000..a68d66c216 --- /dev/null +++ b/spec/ruby/library/stringscanner/named_captures_spec.rb @@ -0,0 +1,30 @@ +require_relative '../../spec_helper' +require 'strscan' + +describe "StringScanner#named_captures" do + before do + @s = StringScanner.new('Fri Dec 12 1975 14:39') + end + + it "returns a hash of names and matched substrings for named capturing groups in a regular expression of the most recent matching" do + @s.exist?(/(?<wday>\w+) (?<month>\w+) (?<day>\d+)/) + @s.named_captures.should == {"wday" => "Fri", "month" => "Dec", "day" => "12"} + end + + it "returns {} if there are no named capturing groups" do + @s.exist?(/(\w+) (\w+) (\d+)/) + @s.named_captures.should == {} + end + + # https://github.com/ruby/strscan/issues/132 + ruby_bug "", ""..."3.3" do # fixed in strscan v3.0.7 + it "returns {} if there is no any matching done" do + @s.named_captures.should == {} + end + end + + it "returns nil for an optional named capturing group if it doesn't match" do + @s.exist?(/(?<wday>\w+) (?<month>\w+) (?<day>\s+)?/) + @s.named_captures.should == {"wday" => "Fri", "month" => "Dec", "day" => nil} + end +end diff --git a/spec/ruby/library/stringscanner/peek_byte_spec.rb b/spec/ruby/library/stringscanner/peek_byte_spec.rb new file mode 100644 index 0000000000..88ef4a2b7c --- /dev/null +++ b/spec/ruby/library/stringscanner/peek_byte_spec.rb @@ -0,0 +1,35 @@ +require_relative '../../spec_helper' +require 'strscan' + +version_is StringScanner::Version, "3.1.1" do # ruby_version_is "3.4" + describe "StringScanner#peek_byte" do + it "returns a byte at the current position as an Integer" do + s = StringScanner.new('This is a test') + s.peek_byte.should == 84 + end + + it "returns nil at the end of the string" do + s = StringScanner.new('a') + s.getch # skip one + s.pos.should == 1 + s.peek_byte.should == nil + end + + it "is not multi-byte character sensitive" do + s = StringScanner.new("∂") # "∂".bytes => [226, 136, 130] + s.peek_byte.should == 226 + s.pos = 1 + s.peek_byte.should == 136 + s.pos = 2 + s.peek_byte.should == 130 + end + + it "doesn't change current position" do + s = StringScanner.new('This is a test') + + s.pos.should == 0 + s.peek_byte.should == 84 + s.pos.should == 0 + end + end +end diff --git a/spec/ruby/library/stringscanner/peek_spec.rb b/spec/ruby/library/stringscanner/peek_spec.rb index cbb5630ff9..d490abecf9 100644 --- a/spec/ruby/library/stringscanner/peek_spec.rb +++ b/spec/ruby/library/stringscanner/peek_spec.rb @@ -1,7 +1,42 @@ require_relative '../../spec_helper' -require_relative 'shared/peek' require 'strscan' describe "StringScanner#peek" do - it_behaves_like :strscan_peek, :peek + before :each do + @s = StringScanner.new('This is a test') + end + + it "returns at most the specified number of bytes from the current position" do + @s.peek(4).should == "This" + @s.pos.should == 0 + @s.pos = 5 + @s.peek(2).should == "is" + @s.peek(1000).should == "is a test" + + s = StringScanner.new("été") + s.peek(2).should == "é" + end + + it "returns an empty string when the passed argument is zero" do + @s.peek(0).should == "" + end + + it "raises a ArgumentError when the passed argument is negative" do + -> { @s.peek(-2) }.should raise_error(ArgumentError) + end + + it "raises a RangeError when the passed argument is a Bignum" do + -> { @s.peek(bignum_value) }.should raise_error(RangeError) + end + + it "returns an instance of String when passed a String subclass" do + cls = Class.new(String) + sub = cls.new("abc") + + s = StringScanner.new(sub) + + ch = s.peek(1) + ch.should_not be_kind_of(cls) + ch.should be_an_instance_of(String) + end end diff --git a/spec/ruby/library/stringscanner/peep_spec.rb b/spec/ruby/library/stringscanner/peep_spec.rb deleted file mode 100644 index bf6d579325..0000000000 --- a/spec/ruby/library/stringscanner/peep_spec.rb +++ /dev/null @@ -1,18 +0,0 @@ -require_relative '../../spec_helper' -require_relative 'shared/peek' -require 'strscan' - -describe "StringScanner#peep" do - it_behaves_like :strscan_peek, :peep - - it "warns in verbose mode that the method is obsolete" do - s = StringScanner.new("abc") - -> { - s.peep(1) - }.should complain(/peep.*obsolete.*peek/, verbose: true) - - -> { - s.peep(1) - }.should_not complain(verbose: false) - end -end diff --git a/spec/ruby/library/stringscanner/rest_size_spec.rb b/spec/ruby/library/stringscanner/rest_size_spec.rb index e62e3a8f8c..a5e971631a 100644 --- a/spec/ruby/library/stringscanner/rest_size_spec.rb +++ b/spec/ruby/library/stringscanner/rest_size_spec.rb @@ -1,7 +1,21 @@ require_relative '../../spec_helper' -require_relative 'shared/rest_size' require 'strscan' describe "StringScanner#rest_size" do - it_behaves_like :strscan_rest_size, :rest_size + before :each do + @s = StringScanner.new('This is a test') + end + + it "returns the length of the rest of the string" do + @s.rest_size.should == 14 + @s.scan(/This/) + @s.rest_size.should == 10 + @s.terminate + @s.rest_size.should == 0 + end + + it "is equivalent to rest.size" do + @s.scan(/This/) + @s.rest_size.should == @s.rest.size + end end diff --git a/spec/ruby/library/stringscanner/restsize_spec.rb b/spec/ruby/library/stringscanner/restsize_spec.rb deleted file mode 100644 index 710520afae..0000000000 --- a/spec/ruby/library/stringscanner/restsize_spec.rb +++ /dev/null @@ -1,18 +0,0 @@ -require_relative '../../spec_helper' -require_relative 'shared/rest_size' -require 'strscan' - -describe "StringScanner#restsize" do - it_behaves_like :strscan_rest_size, :restsize - - it "warns in verbose mode that the method is obsolete" do - s = StringScanner.new("abc") - -> { - s.restsize - }.should complain(/restsize.*obsolete.*rest_size/, verbose: true) - - -> { - s.restsize - }.should_not complain(verbose: false) - end -end diff --git a/spec/ruby/library/stringscanner/scan_byte_spec.rb b/spec/ruby/library/stringscanner/scan_byte_spec.rb new file mode 100644 index 0000000000..aa2decc8f7 --- /dev/null +++ b/spec/ruby/library/stringscanner/scan_byte_spec.rb @@ -0,0 +1,98 @@ +require_relative '../../spec_helper' +require 'strscan' + +version_is StringScanner::Version, "3.1.1" do # ruby_version_is "3.4" + describe "StringScanner#scan_byte" do + it "scans one byte and returns it as on Integer" do + s = StringScanner.new('abc') # "abc".bytes => [97, 98, 99] + s.scan_byte.should == 97 + s.scan_byte.should == 98 + s.scan_byte.should == 99 + end + + it "is not multi-byte character sensitive" do + s = StringScanner.new("あ") # "あ".bytes => [227, 129, 130] + s.scan_byte.should == 227 + s.scan_byte.should == 129 + s.scan_byte.should == 130 + end + + it "returns nil at the end of the string" do + s = StringScanner.new('a') + s.scan_byte # skip one + s.scan_byte.should == nil + s.pos.should == 1 + end + + it "changes current position" do + s = StringScanner.new('abc') + s.pos.should == 0 + s.scan_byte + s.pos.should == 1 + end + + it "sets the last match result" do + s = StringScanner.new('abc') + s.pos = 1 + s.scan_byte + + s.pre_match.should == "a" + s.matched.should == "b" + s.post_match.should == "c" + end + + describe "#[] successive call with a capture group name" do + # https://github.com/ruby/strscan/issues/139 + version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.0"..."3.4.3" + it "returns nil" do + s = StringScanner.new("abc") + s.scan_byte + s.should.matched? + s[:a].should be_nil + end + end + version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4.3" + it "raises IndexError" do + s = StringScanner.new("abc") + s.scan_byte + s.should.matched? + -> { s[:a] }.should raise_error(IndexError) + end + end + + it "returns a matching character when given Integer index" do + s = StringScanner.new("This is a test") + s.scan_byte + s[0].should == "T" + end + + # https://github.com/ruby/strscan/issues/135 + version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.0"..."3.4.3" + it "ignores the previous matching with Regexp" do + s = StringScanner.new("abc") + + s.exist?(/(?<a>a)/) + s.should.matched? + s[:a].should == "a" + + s.scan_byte + s.should.matched? + s[:a].should == nil + end + end + version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4.0"..."3.4.3" + it "ignores the previous matching with Regexp" do + s = StringScanner.new("abc") + + s.exist?(/(?<a>a)/) + s.should.matched? + s[:a].should == "a" + + s.scan_byte + s.should.matched? + -> { s[:a] }.should raise_error(IndexError) + end + end + end + end +end diff --git a/spec/ruby/library/stringscanner/scan_full_spec.rb b/spec/ruby/library/stringscanner/scan_full_spec.rb index ed34d7d3f6..967313f5ca 100644 --- a/spec/ruby/library/stringscanner/scan_full_spec.rb +++ b/spec/ruby/library/stringscanner/scan_full_spec.rb @@ -27,4 +27,18 @@ describe "StringScanner#scan_full" do @s.scan_full(/This/, true, true).should == "This" @s.pos.should == 4 end + + describe "#[] successive call with a capture group name" do + it "returns matched substring when matching succeeded" do + @s.scan_full(/(?<a>This)/, false, false) + @s.should.matched? + @s[:a].should == "This" + end + + it "returns nil when matching failed" do + @s.scan_full(/(?<a>2008)/, false, false) + @s.should_not.matched? + @s[:a].should be_nil + end + end end diff --git a/spec/ruby/library/stringscanner/scan_integer_spec.rb b/spec/ruby/library/stringscanner/scan_integer_spec.rb new file mode 100644 index 0000000000..fe0d26f404 --- /dev/null +++ b/spec/ruby/library/stringscanner/scan_integer_spec.rb @@ -0,0 +1,157 @@ +require_relative '../../spec_helper' +require 'strscan' + +version_is StringScanner::Version, "3.1.1" do # ruby_version_is "3.4" + describe "StringScanner#scan_integer" do + it "returns the matched Integer literal starting from the current position" do + s = StringScanner.new("42") + s.scan_integer.should == 42 + end + + it "returns nil when no Integer literal matched starting from the current position" do + s = StringScanner.new("a42") + s.scan_integer.should == nil + end + + it "supports a sign +/-" do + StringScanner.new("+42").scan_integer.should == 42 + StringScanner.new("-42").scan_integer.should == -42 + end + + it "changes the current position" do + s = StringScanner.new("42abc") + s.scan_integer + s.pos.should == 2 + end + + # https://github.com/ruby/strscan/issues/130 + ruby_bug "", "3.4"..."4.0" do # introduced in strscan v3.1.1 + it "sets the last match result" do + s = StringScanner.new("42abc") + s.scan_integer + + s.should.matched? + s.matched.should == "42" + s.pre_match.should == "" + s.post_match.should == "abc" + s.matched_size.should == 2 + end + end + + it "raises Encoding::CompatibilityError when a scanned string not is ASCII-compatible encoding" do + string = "42".encode(Encoding::UTF_16BE) + s = StringScanner.new(string) + + -> { + s.scan_integer + }.should raise_error(Encoding::CompatibilityError, 'ASCII incompatible encoding: UTF-16BE') + end + + context "given base" do + it "supports base: 10" do + s = StringScanner.new("42") + s.scan_integer(base: 10).should == 42 + end + + it "supports base: 16" do + StringScanner.new("0xff").scan_integer(base: 16).should == 0xff + StringScanner.new("-0xff").scan_integer(base: 16).should == -0xff + StringScanner.new("0xFF").scan_integer(base: 16).should == 0xff + StringScanner.new("-0xFF").scan_integer(base: 16).should == -0xff + StringScanner.new("ff").scan_integer(base: 16).should == 0xff + StringScanner.new("-ff").scan_integer(base: 16).should == -0xff + end + + it "raises ArgumentError when passed not supported base" do + -> { + StringScanner.new("42").scan_integer(base: 5) + }.should raise_error(ArgumentError, "Unsupported integer base: 5, expected 10 or 16") + end + + version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.0"..."3.4.3" + it "does not match '0x' prefix on its own" do + StringScanner.new("0x").scan_integer(base: 16).should == nil + StringScanner.new("-0x").scan_integer(base: 16).should == nil + StringScanner.new("+0x").scan_integer(base: 16).should == nil + end + end + + version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4.3" + it "matches '0' in a '0x' that is followed by non-hex characters" do + StringScanner.new("0x!@#").scan_integer(base: 16).should == 0 + StringScanner.new("-0x!@#").scan_integer(base: 16).should == 0 + StringScanner.new("+0x!@#").scan_integer(base: 16).should == 0 + end + + it "matches '0' in a '0x' located in the end of a string" do + StringScanner.new("0x").scan_integer(base: 16).should == 0 + StringScanner.new("-0x").scan_integer(base: 16).should == 0 + StringScanner.new("+0x").scan_integer(base: 16).should == 0 + end + end + end + end + + describe "#[] successive call with a capture group name" do + # https://github.com/ruby/strscan/issues/139 + version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.0"..."3.4.3" + it "returns nil substring when matching succeeded" do + s = StringScanner.new("42") + s.scan_integer + s.should.matched? + s[:a].should == nil + end + end + version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4.3" + it "raises IndexError when matching succeeded" do + s = StringScanner.new("42") + s.scan_integer + s.should.matched? + -> { s[:a] }.should raise_error(IndexError) + end + end + + it "returns nil when matching failed" do + s = StringScanner.new("a42") + s.scan_integer + s.should_not.matched? + s[:a].should be_nil + end + + version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4" + it "returns a matching substring when given Integer index" do + s = StringScanner.new("42") + s.scan_integer + s[0].should == "42" + end + end + + # https://github.com/ruby/strscan/issues/135 + version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.0"..."3.4.3" + it "does not ignore the previous matching with Regexp" do + s = StringScanner.new("42") + + s.exist?(/(?<a>42)/) + s.should.matched? + s[:a].should == "42" + + s.scan_integer + s.should.matched? + s[:a].should == "42" + end + end + version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4" + it "ignores the previous matching with Regexp" do + s = StringScanner.new("42") + + s.exist?(/(?<a>42)/) + s.should.matched? + s[:a].should == "42" + + s.scan_integer + s.should.matched? + -> { s[:a] }.should raise_error(IndexError) + end + end + end +end diff --git a/spec/ruby/library/stringscanner/scan_spec.rb b/spec/ruby/library/stringscanner/scan_spec.rb index ea711767b9..088c3419fb 100644 --- a/spec/ruby/library/stringscanner/scan_spec.rb +++ b/spec/ruby/library/stringscanner/scan_spec.rb @@ -60,6 +60,20 @@ describe "StringScanner#scan" do -> { @s.scan(:test) }.should raise_error(TypeError) -> { @s.scan(mock('x')) }.should raise_error(TypeError) end + + describe "#[] successive call with a capture group name" do + it "returns matched substring when matching succeeded" do + @s.scan(/(?<a>This)/) + @s.should.matched? + @s[:a].should == "This" + end + + it "returns nil when matching failed" do + @s.scan(/(?<a>2008)/) + @s.should_not.matched? + @s[:a].should be_nil + end + end end describe "StringScanner#scan with fixed_anchor: true" do diff --git a/spec/ruby/library/stringscanner/scan_until_spec.rb b/spec/ruby/library/stringscanner/scan_until_spec.rb index 6b7782572d..610060d6f1 100644 --- a/spec/ruby/library/stringscanner/scan_until_spec.rb +++ b/spec/ruby/library/stringscanner/scan_until_spec.rb @@ -2,14 +2,20 @@ require_relative '../../spec_helper' require 'strscan' describe "StringScanner#scan_until" do - before :each do + before do @s = StringScanner.new("This is a test") end it "returns the substring up to and including the end of the match" do - @s.scan_until(/a/).should == "This is a" - @s.pre_match.should == "This is " - @s.post_match.should == " test" + @s.scan_until(/a/).should == "This is a" + end + + it "sets the last match result" do + @s.scan_until(/a/) + + @s.pre_match.should == "This is " + @s.matched.should == "a" + @s.post_match.should == " test" end it "returns nil if there's no match" do @@ -21,9 +27,109 @@ describe "StringScanner#scan_until" do @s.scan_until(/^h/).should == "h" end - it "raises TypeError if given a String" do - -> { - @s.scan_until('T') - }.should raise_error(TypeError, 'wrong argument type String (expected Regexp)') + version_is StringScanner::Version, ""..."3.1.1" do # ruby_version_is ""..."3.4" + it "raises TypeError if given a String" do + -> { + @s.scan_until('T') + }.should raise_error(TypeError, 'wrong argument type String (expected Regexp)') + end + end + + version_is StringScanner::Version, "3.1.1" do # ruby_version_is "3.4" + it "searches a substring in the rest part of a string if given a String" do + @s.scan_until("a").should == "This is a" + end + + # https://github.com/ruby/strscan/issues/131 + version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.1" + it "sets the last match result if given a String" do + @s.scan_until("a") + + @s.pre_match.should == "" + @s.matched.should == "This is a" + @s.post_match.should == " test" + end + end + + version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4" + it "sets the last match result if given a String" do + @s.scan_until("a") + + @s.pre_match.should == "This is " + @s.matched.should == "a" + @s.post_match.should == " test" + end + end + end + + describe "#[] successive call with a capture group name" do + context "when #scan_until was called with a Regexp pattern" do + it "returns matched substring when matching succeeded" do + @s.scan_until(/(?<a>This)/) + @s.should.matched? + @s[:a].should == "This" + end + + it "returns nil when matching failed" do + @s.scan_until(/(?<a>2008)/) + @s.should_not.matched? + @s[:a].should be_nil + end + end + + version_is StringScanner::Version, "3.1.1" do # ruby_version_is "3.4" + context "when #scan_until was called with a String pattern" do + # https://github.com/ruby/strscan/issues/139 + version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.0"..."3.4.3" + it "returns nil when matching succeeded" do + @s.scan_until("This") + @s.should.matched? + @s[:a].should be_nil + end + end + version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4.3" + it "raises IndexError when matching succeeded" do + @s.scan_until("This") + @s.should.matched? + -> { @s[:a] }.should raise_error(IndexError) + end + end + + it "returns nil when matching failed" do + @s.scan_until("2008") + @s.should_not.matched? + @s[:a].should be_nil + end + + it "returns a matching substring when given Integer index" do + @s.scan_until("This") + @s[0].should == "This" + end + + # https://github.com/ruby/strscan/issues/135 + version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.0"..."3.4.3" + it "ignores the previous matching with Regexp" do + @s.exist?(/(?<a>This)/) + @s.should.matched? + @s[:a].should == "This" + + @s.scan_until("This") + @s.should.matched? + @s[:a].should be_nil + end + end + version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4" + it "ignores the previous matching with Regexp" do + @s.exist?(/(?<a>This)/) + @s.should.matched? + @s[:a].should == "This" + + @s.scan_until("This") + @s.should.matched? + -> { @s[:a] }.should raise_error(IndexError) + end + end + end + end end end diff --git a/spec/ruby/library/stringscanner/search_full_spec.rb b/spec/ruby/library/stringscanner/search_full_spec.rb index 7d2a714fa5..197adfda4d 100644 --- a/spec/ruby/library/stringscanner/search_full_spec.rb +++ b/spec/ruby/library/stringscanner/search_full_spec.rb @@ -2,7 +2,7 @@ require_relative '../../spec_helper' require 'strscan' describe "StringScanner#search_full" do - before :each do + before do @s = StringScanner.new("This is a test") end @@ -28,9 +28,106 @@ describe "StringScanner#search_full" do @s.pos.should == 4 end - it "raises TypeError if given a String" do - -> { - @s.search_full('T', true, true) - }.should raise_error(TypeError, 'wrong argument type String (expected Regexp)') + it "sets the last match result" do + @s.search_full(/is a/, false, false) + + @s.pre_match.should == "This " + @s.matched.should == "is a" + @s.post_match.should == " test" + end + + version_is StringScanner::Version, ""..."3.1.1" do # ruby_version_is ""..."3.4" + it "raises TypeError if given a String" do + -> { + @s.search_full('T', true, true) + }.should raise_error(TypeError, 'wrong argument type String (expected Regexp)') + end + end + + version_is StringScanner::Version, "3.1.1" do # ruby_version_is "3.4" + it "searches a substring in the rest part of a string if given a String" do + @s.search_full("is a", false, false).should == 9 + end + + # https://github.com/ruby/strscan/issues/131 + version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.1" + it "sets the last match result if given a String" do + @s.search_full("is a", false, false) + + @s.pre_match.should == "" + @s.matched.should == "This is a" + @s.post_match.should == " test" + end + end + + version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4" + it "sets the last match result if given a String" do + @s.search_full("is a", false, false) + + @s.pre_match.should == "This " + @s.matched.should == "is a" + @s.post_match.should == " test" + end + end + end + + describe "#[] successive call with a capture group name" do + context "when #search_full was called with a Regexp pattern" do + it "returns matched substring when matching succeeded" do + @s.search_full(/(?<a>This)/, false, false) + @s.should.matched? + @s[:a].should == "This" + end + + it "returns nil when matching failed" do + @s.search_full(/(?<a>2008)/, false, false) + @s.should_not.matched? + @s[:a].should be_nil + end + end + + version_is StringScanner::Version, "3.1.1" do # ruby_version_is "3.4" + context "when #search_full was called with a String pattern" do + # https://github.com/ruby/strscan/issues/139 + version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.0"..."3.4.3" + it "returns nil when matching succeeded" do + @s.search_full("This", false, false) + @s.should.matched? + @s[:a].should be_nil + end + end + version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4.3" + it "raises IndexError when matching succeeded" do + @s.search_full("This", false, false) + @s.should.matched? + -> { @s[:a] }.should raise_error(IndexError) + end + end + + it "returns nil when matching failed" do + @s.search_full("2008", false, false) + @s.should_not.matched? + @s[:a].should be_nil + end + + it "returns a matching substring when given Integer index" do + @s.search_full("This", false, false) + @s[0].should == "This" + end + + # https://github.com/ruby/strscan/issues/135 + version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4" + it "ignores the previous matching with Regexp" do + @s.exist?(/(?<a>This)/) + @s.should.matched? + @s[:a].should == "This" + + @s.search_full("This", false, false) + @s.should.matched? + -> { @s[:a] }.should raise_error(IndexError) + end + end + end + end end end diff --git a/spec/ruby/library/stringscanner/shared/concat.rb b/spec/ruby/library/stringscanner/shared/concat.rb index cb884a5c01..1dbae11f7c 100644 --- a/spec/ruby/library/stringscanner/shared/concat.rb +++ b/spec/ruby/library/stringscanner/shared/concat.rb @@ -1,6 +1,6 @@ describe :strscan_concat, shared: true do it "concatenates the given argument to self and returns self" do - s = StringScanner.new("hello ") + s = StringScanner.new(+"hello ") s.send(@method, 'world').should == s s.string.should == "hello world" s.eos?.should be_false diff --git a/spec/ruby/library/stringscanner/shared/eos.rb b/spec/ruby/library/stringscanner/shared/eos.rb deleted file mode 100644 index ea04c764a2..0000000000 --- a/spec/ruby/library/stringscanner/shared/eos.rb +++ /dev/null @@ -1,17 +0,0 @@ -describe :strscan_eos, shared: true do - before :each do - @s = StringScanner.new("This is a test") - end - - it "returns true if the scan pointer is at the end of the string" do - @s.terminate - @s.send(@method).should be_true - - s = StringScanner.new('') - s.send(@method).should be_true - end - - it "returns false if the scan pointer is not at the end of the string" do - @s.send(@method).should be_false - end -end diff --git a/spec/ruby/library/stringscanner/shared/get_byte.rb b/spec/ruby/library/stringscanner/shared/get_byte.rb deleted file mode 100644 index 763ab6f4a4..0000000000 --- a/spec/ruby/library/stringscanner/shared/get_byte.rb +++ /dev/null @@ -1,29 +0,0 @@ -# -*- encoding: binary -*- -describe :strscan_get_byte, shared: true do - it "scans one byte and returns it" do - s = StringScanner.new('abc5.') - s.send(@method).should == 'a' - s.send(@method).should == 'b' - s.send(@method).should == 'c' - s.send(@method).should == '5' - s.send(@method).should == '.' - end - - it "is not multi-byte character sensitive" do - s = StringScanner.new("\244\242") - s.send(@method).should == "\244" - s.send(@method).should == "\242" - end - - it "returns nil at the end of the string" do - # empty string case - s = StringScanner.new('') - s.send(@method).should == nil - s.send(@method).should == nil - - # non-empty string case - s = StringScanner.new('a') - s.send(@method) # skip one - s.send(@method).should == nil - end -end diff --git a/spec/ruby/library/stringscanner/shared/peek.rb b/spec/ruby/library/stringscanner/shared/peek.rb deleted file mode 100644 index 4c757866c1..0000000000 --- a/spec/ruby/library/stringscanner/shared/peek.rb +++ /dev/null @@ -1,39 +0,0 @@ -describe :strscan_peek, shared: true do - before :each do - @s = StringScanner.new('This is a test') - end - - it "returns at most the specified number of bytes from the current position" do - @s.send(@method, 4).should == "This" - @s.pos.should == 0 - @s.pos = 5 - @s.send(@method, 2).should == "is" - @s.send(@method, 1000).should == "is a test" - - s = StringScanner.new("été") - s.send(@method, 2).should == "é" - end - - it "returns an empty string when the passed argument is zero" do - @s.send(@method, 0).should == "" - end - - it "raises a ArgumentError when the passed argument is negative" do - -> { @s.send(@method, -2) }.should raise_error(ArgumentError) - end - - it "raises a RangeError when the passed argument is a Bignum" do - -> { @s.send(@method, bignum_value) }.should raise_error(RangeError) - end - - it "returns an instance of String when passed a String subclass" do - cls = Class.new(String) - sub = cls.new("abc") - - s = StringScanner.new(sub) - - ch = s.send(@method, 1) - ch.should_not be_kind_of(cls) - ch.should be_an_instance_of(String) - end -end diff --git a/spec/ruby/library/stringscanner/shared/pos.rb b/spec/ruby/library/stringscanner/shared/pos.rb index 6d540881f2..eea7ead6b5 100644 --- a/spec/ruby/library/stringscanner/shared/pos.rb +++ b/spec/ruby/library/stringscanner/shared/pos.rb @@ -22,6 +22,13 @@ describe :strscan_pos, shared: true do @s.terminate @s.send(@method).should == @s.string.length end + + it "is not multi-byte character sensitive" do + s = StringScanner.new("abcädeföghi") + + s.scan_until(/ö/) + s.pos.should == 10 + end end describe :strscan_pos_set, shared: true do diff --git a/spec/ruby/library/stringscanner/shared/rest_size.rb b/spec/ruby/library/stringscanner/shared/rest_size.rb deleted file mode 100644 index 4c4f49e45c..0000000000 --- a/spec/ruby/library/stringscanner/shared/rest_size.rb +++ /dev/null @@ -1,18 +0,0 @@ -describe :strscan_rest_size, shared: true do - before :each do - @s = StringScanner.new('This is a test') - end - - it "returns the length of the rest of the string" do - @s.send(@method).should == 14 - @s.scan(/This/) - @s.send(@method).should == 10 - @s.terminate - @s.send(@method).should == 0 - end - - it "is equivalent to rest.size" do - @s.scan(/This/) - @s.send(@method).should == @s.rest.size - end -end diff --git a/spec/ruby/library/stringscanner/shared/terminate.rb b/spec/ruby/library/stringscanner/shared/terminate.rb deleted file mode 100644 index bf41d097e2..0000000000 --- a/spec/ruby/library/stringscanner/shared/terminate.rb +++ /dev/null @@ -1,8 +0,0 @@ -describe :strscan_terminate, shared: true do - it "set the scan pointer to the end of the string and clear matching data." do - s = StringScanner.new('This is a test') - s.send(@method) - s.bol?.should be_false - s.eos?.should be_true - end -end diff --git a/spec/ruby/library/stringscanner/skip_spec.rb b/spec/ruby/library/stringscanner/skip_spec.rb index 473361782c..12f5b7781c 100644 --- a/spec/ruby/library/stringscanner/skip_spec.rb +++ b/spec/ruby/library/stringscanner/skip_spec.rb @@ -15,4 +15,18 @@ describe "StringScanner#skip" do @s.skip(/\s+/).should == nil @s.skip(/\d+/).should == nil end + + describe "#[] successive call with a capture group name" do + it "returns matched substring when matching succeeded" do + @s.skip(/(?<a>This)/) + @s.should.matched? + @s[:a].should == "This" + end + + it "returns nil when matching failed" do + @s.skip(/(?<a>2008)/) + @s.should_not.matched? + @s[:a].should be_nil + end + end end diff --git a/spec/ruby/library/stringscanner/skip_until_spec.rb b/spec/ruby/library/stringscanner/skip_until_spec.rb index 7b56f13e4f..5d73d8f0b9 100644 --- a/spec/ruby/library/stringscanner/skip_until_spec.rb +++ b/spec/ruby/library/stringscanner/skip_until_spec.rb @@ -2,23 +2,131 @@ require_relative '../../spec_helper' require 'strscan' describe "StringScanner#skip_until" do - before :each do + before do @s = StringScanner.new("This is a test") end it "returns the number of bytes advanced and advances the scan pointer until pattern is matched and consumed" do @s.skip_until(/a/).should == 9 @s.pos.should == 9 + end + + it "sets the last match result" do + @s.skip_until(/a/) + + @s.pre_match.should == "This is " @s.matched.should == "a" + @s.post_match.should == " test" end it "returns nil if no match was found" do @s.skip_until(/d+/).should == nil end - it "raises TypeError if given a String" do - -> { - @s.skip_until('T') - }.should raise_error(TypeError, 'wrong argument type String (expected Regexp)') + version_is StringScanner::Version, ""..."3.1.1" do # ruby_version_is ""..."3.4" + it "raises TypeError if given a String" do + -> { + @s.skip_until('T') + }.should raise_error(TypeError, 'wrong argument type String (expected Regexp)') + end + end + + version_is StringScanner::Version, "3.1.1" do # ruby_version_is "3.4" + it "searches a substring in the rest part of a string if given a String" do + @s.skip_until("a").should == 9 + @s.pos.should == 9 + end + + # https://github.com/ruby/strscan/issues/131 + version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.1" + it "sets the last match result if given a String" do + @s.skip_until("a") + + @s.pre_match.should == "" + @s.matched.should == "This is a" + @s.post_match.should == " test" + end + end + + version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4" + it "sets the last match result if given a String" do + @s.skip_until("a") + + @s.pre_match.should == "This is " + @s.matched.should == "a" + @s.post_match.should == " test" + end + end + end + + describe "#[] successive call with a capture group name" do + context "when #scan_until was called with a Regexp pattern" do + it "returns matched substring when matching succeeded" do + @s.skip_until(/(?<a>This)/) + @s.should.matched? + @s[:a].should == "This" + end + + it "returns nil when matching failed" do + @s.skip_until(/(?<a>2008)/) + @s.should_not.matched? + @s[:a].should be_nil + end + end + + version_is StringScanner::Version, "3.1.1" do # ruby_version_is "3.4" + context "when #skip_until was called with a String pattern" do + # https://github.com/ruby/strscan/issues/139 + version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.0"..."3.4.3" + it "returns nil when matching succeeded" do + @s.skip_until("This") + @s.should.matched? + @s[:a].should be_nil + end + end + version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4.3" + it "raises IndexError when matching succeeded" do + @s.skip_until("This") + @s.should.matched? + -> { @s[:a] }.should raise_error(IndexError) + end + end + + it "returns nil when matching failed" do + @s.skip_until("2008") + @s.should_not.matched? + @s[:a].should be_nil + end + + it "returns a matching substring when given Integer index" do + @s.skip_until("This") + @s[0].should == "This" + end + + # https://github.com/ruby/strscan/issues/135 + version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.0"..."3.4.3" + it "ignores the previous matching with Regexp" do + @s.exist?(/(?<a>This)/) + @s.should.matched? + @s[:a].should == "This" + + @s.skip_until("This") + @s.should.matched? + @s[:a].should be_nil + end + end + version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4" + it "ignores the previous matching with Regexp" do + @s.exist?(/(?<a>This)/) + @s.should.matched? + @s[:a].should == "This" + + @s.skip_until("This") + @s.should.matched? + -> { @s[:a] }.should raise_error(IndexError) + end + end + end + end end end diff --git a/spec/ruby/library/stringscanner/string_spec.rb b/spec/ruby/library/stringscanner/string_spec.rb index 28e2f0ed37..cba6bd51dd 100644 --- a/spec/ruby/library/stringscanner/string_spec.rb +++ b/spec/ruby/library/stringscanner/string_spec.rb @@ -3,7 +3,7 @@ require 'strscan' describe "StringScanner#string" do before :each do - @string = "This is a test" + @string = +"This is a test" @s = StringScanner.new(@string) end diff --git a/spec/ruby/library/stringscanner/terminate_spec.rb b/spec/ruby/library/stringscanner/terminate_spec.rb index 249023f1ab..3cff5c010c 100644 --- a/spec/ruby/library/stringscanner/terminate_spec.rb +++ b/spec/ruby/library/stringscanner/terminate_spec.rb @@ -1,7 +1,11 @@ require_relative '../../spec_helper' -require_relative 'shared/terminate' require 'strscan' describe "StringScanner#terminate" do - it_behaves_like :strscan_terminate, :terminate + it "set the scan pointer to the end of the string and clear matching data." do + s = StringScanner.new('This is a test') + s.terminate + s.should_not.bol? + s.should.eos? + end end diff --git a/spec/ruby/library/stringscanner/unscan_spec.rb b/spec/ruby/library/stringscanner/unscan_spec.rb index df0ea43367..b7b4876b8a 100644 --- a/spec/ruby/library/stringscanner/unscan_spec.rb +++ b/spec/ruby/library/stringscanner/unscan_spec.rb @@ -21,8 +21,8 @@ describe "StringScanner#unscan" do @s.pos.should == pos end - it "raises a ScanError when the previous match had failed" do - -> { @s.unscan }.should raise_error(ScanError) - -> { @s.scan(/\d/); @s.unscan }.should raise_error(ScanError) + it "raises a StringScanner::Error when the previous match had failed" do + -> { @s.unscan }.should raise_error(StringScanner::Error) + -> { @s.scan(/\d/); @s.unscan }.should raise_error(StringScanner::Error) end end diff --git a/spec/ruby/library/stringscanner/values_at_spec.rb b/spec/ruby/library/stringscanner/values_at_spec.rb new file mode 100644 index 0000000000..14d4a5f6a7 --- /dev/null +++ b/spec/ruby/library/stringscanner/values_at_spec.rb @@ -0,0 +1,68 @@ +require_relative '../../spec_helper' +require 'strscan' + +describe "StringScanner#captures" do + before do + @s = StringScanner.new('Fri Dec 12 1975 14:39') + end + + context "when passed a list of Integers" do + it "returns an array containing each value given by one of integers" do + @s.exist?(/(?<wday>\w+) (?<month>\w+) (?<day>\d+)/) + @s.values_at(0, 1, 2, 3).should == ["Fri Dec 12", "Fri", "Dec", "12"] + end + + it "returns nil value for any integer that is out of range" do + @s.exist?(/(?<wday>\w+) (?<month>\w+) (?<day>\d+)/) + @s.values_at(4).should == [nil] + @s.values_at(-5).should == [nil] + end + end + + context "when passed names" do + it 'slices captures with the given names' do + @s.exist?(/(?<wday>\w+) (?<month>\w+) (?<day>\d+)/) + @s.values_at(:wday, :month, :day).should == ["Fri", "Dec", "12"] + end + + it 'slices captures with the given String names' do + @s.exist?(/(?<wday>\w+) (?<month>\w+) (?<day>\d+)/) + @s.values_at("wday", "month", "day").should == ["Fri", "Dec", "12"] + end + + it "raises IndexError when given unknown name" do + @s.exist?(/(?<wday>\w+) (?<month>\w+) (?<day>\d+)/) + + -> { + @s.values_at("foo") + }.should raise_error(IndexError, "undefined group name reference: foo") + end + end + + it 'supports mixing of names and indices' do + @s.exist?(/(?<wday>\w+) (?<month>\w+) (?<day>\d+)/) + @s.values_at(1, "wday", 2, "month", 3, "day").should == ["Fri", "Fri", "Dec", "Dec", "12", "12"] + end + + it "returns a new empty Array if no arguments given" do + @s.exist?(/(?<wday>\w+) (?<month>\w+) (?<day>\d+)/) + @s.values_at().should == [] + end + + it "fails when passed arguments of unsupported types" do + @s.exist?(/(?<wday>\w+) (?<month>\w+) (?<day>\d+)/) + + -> { + @s.values_at([]) + }.should raise_error(TypeError, "no implicit conversion of Array into Integer") + end + + it "returns nil if the most recent matching fails" do + @s.exist?(/(?<wday>\w+) (?<month>\w+) (?<day>\s+)/) + @s.values_at(1, 2, 3).should == nil + end + + it "returns nil if there is no any matching done" do + @s.values_at(1, 2, 3).should == nil + end +end diff --git a/spec/ruby/library/syslog/constants_spec.rb b/spec/ruby/library/syslog/constants_spec.rb index 2b9524c53d..fc9db47dd8 100644 --- a/spec/ruby/library/syslog/constants_spec.rb +++ b/spec/ruby/library/syslog/constants_spec.rb @@ -4,7 +4,7 @@ platform_is_not :windows do require 'syslog' describe "Syslog::Constants" do - platform_is_not :windows, :solaris, :aix do + platform_is_not :windows, :aix do before :all do @constants = %w(LOG_AUTHPRIV LOG_USER LOG_LOCAL2 LOG_NOTICE LOG_NDELAY LOG_SYSLOG LOG_ALERT LOG_FTP LOG_LOCAL5 LOG_ERR LOG_AUTH diff --git a/spec/ruby/library/syslog/log_spec.rb b/spec/ruby/library/syslog/log_spec.rb index 8589fb1f73..0c855b8257 100644 --- a/spec/ruby/library/syslog/log_spec.rb +++ b/spec/ruby/library/syslog/log_spec.rb @@ -4,7 +4,7 @@ platform_is_not :windows do require 'syslog' describe "Syslog.log" do - platform_is_not :windows, :darwin, :solaris, :aix, :android do + platform_is_not :windows, :darwin, :aix, :android do before :each do Syslog.opened?.should be_false diff --git a/spec/ruby/library/syslog/shared/log.rb b/spec/ruby/library/syslog/shared/log.rb index 12e4ea8366..9f9302b214 100644 --- a/spec/ruby/library/syslog/shared/log.rb +++ b/spec/ruby/library/syslog/shared/log.rb @@ -1,5 +1,5 @@ describe :syslog_log, shared: true do - platform_is_not :windows, :darwin, :solaris, :aix, :android do + platform_is_not :windows, :darwin, :aix, :android do before :each do Syslog.opened?.should be_false end diff --git a/spec/ruby/library/tempfile/callback_spec.rb b/spec/ruby/library/tempfile/callback_spec.rb deleted file mode 100644 index c0b1518326..0000000000 --- a/spec/ruby/library/tempfile/callback_spec.rb +++ /dev/null @@ -1,6 +0,0 @@ -require_relative '../../spec_helper' -require 'tempfile' - -describe "Tempfile.callback" do - it "needs to be reviewed for spec completeness" -end diff --git a/spec/ruby/library/tempfile/create_spec.rb b/spec/ruby/library/tempfile/create_spec.rb new file mode 100644 index 0000000000..74c48bf32a --- /dev/null +++ b/spec/ruby/library/tempfile/create_spec.rb @@ -0,0 +1,176 @@ +require_relative '../../spec_helper' +require 'tempfile' + +describe "Tempfile.create" do + after :each do + if @tempfile + @tempfile.close + File.unlink(@tempfile.path) if File.file?(@tempfile.path) + end + end + + it "returns a new, open regular File instance placed in tmpdir" do + @tempfile = Tempfile.create + # Unlike Tempfile.open this returns a true File, + # but `.should be_an_instance_of(File)` would be true either way. + @tempfile.instance_of?(File).should be_true + + @tempfile.should_not.closed? + File.file?(@tempfile.path).should be_true + + @tempfile.path.should.start_with?(Dir.tmpdir) + @tempfile.path.should_not == "#{Dir.tmpdir}/" + end + + it "returns file in w+ mode" do + @tempfile = Tempfile.create + @tempfile << "Test!\nMore test!" + @tempfile.rewind + @tempfile.read.should == "Test!\nMore test!" + + # Not "a+" mode, which would write at the end of the file. + @tempfile.rewind + @tempfile.print "Trust" + @tempfile.rewind + @tempfile.read.should == "Trust\nMore test!" + end + + platform_is_not :windows do + it "returns a private, readable and writable file" do + @tempfile = Tempfile.create + stat = @tempfile.stat + stat.should.readable? + stat.should.writable? + stat.should_not.executable? + stat.should_not.world_readable? + stat.should_not.world_writable? + end + end + + platform_is :windows do + it "returns a public, readable and writable file" do + @tempfile = Tempfile.create + stat = @tempfile.stat + stat.should.readable? + stat.should.writable? + stat.should_not.executable? + stat.should.world_readable? + stat.should.world_writable? + end + end + + context "when called with a block" do + it "returns the value of the block" do + value = Tempfile.create do |tempfile| + tempfile << "Test!" + "return" + end + value.should == "return" + end + + it "closes and unlinks file after block execution" do + Tempfile.create do |tempfile| + @tempfile = tempfile + @tempfile.should_not.closed? + File.exist?(@tempfile.path).should be_true + end + + @tempfile.should.closed? + File.exist?(@tempfile.path).should be_false + end + end + + context "when called with a single positional argument" do + it "uses a String as a prefix for the filename" do + @tempfile = Tempfile.create("create_spec") + @tempfile.path.should.start_with?("#{Dir.tmpdir}/create_spec") + @tempfile.path.should_not == "#{Dir.tmpdir}/create_spec" + end + + it "uses an array of one String as a prefix for the filename" do + @tempfile = Tempfile.create(["create_spec"]) + @tempfile.path.should.start_with?("#{Dir.tmpdir}/create_spec") + @tempfile.path.should_not == "#{Dir.tmpdir}/create_spec" + end + + it "uses an array of two Strings as a prefix and suffix for the filename" do + @tempfile = Tempfile.create(["create_spec", ".temp"]) + @tempfile.path.should.start_with?("#{Dir.tmpdir}/create_spec") + @tempfile.path.should.end_with?(".temp") + end + + it "ignores excessive array elements after the first two" do + @tempfile = Tempfile.create(["create_spec", ".temp", :".txt"]) + @tempfile.path.should.start_with?("#{Dir.tmpdir}/create_spec") + @tempfile.path.should.end_with?(".temp") + end + + it "raises ArgumentError if passed something else than a String or an array of Strings" do + -> { Tempfile.create(:create_spec) }.should raise_error(ArgumentError, "unexpected prefix: :create_spec") + -> { Tempfile.create([:create_spec]) }.should raise_error(ArgumentError, "unexpected prefix: :create_spec") + -> { Tempfile.create(["create_spec", :temp]) }.should raise_error(ArgumentError, "unexpected suffix: :temp") + end + end + + context "when called with a second positional argument" do + it "uses it as a directory for the tempfile" do + @tempfile = Tempfile.create("create_spec", "./") + @tempfile.path.should.start_with?("./create_spec") + end + + it "raises TypeError if argument can not be converted to a String" do + -> { Tempfile.create("create_spec", :temp) }.should raise_error(TypeError, "no implicit conversion of Symbol into String") + end + end + + context "when called with a mode option" do + it "ORs it with the default mode, forcing it to be readable and writable" do + @tempfile = Tempfile.create(mode: File::RDONLY) + @tempfile.puts "test" + @tempfile.rewind + @tempfile.read.should == "test\n" + end + + it "raises NoMethodError if passed a String mode" do + -> { Tempfile.create(mode: "wb") }.should raise_error(NoMethodError, /undefined method ['`]|' for .+String/) + end + end + + ruby_version_is "3.4" do + context "when called with anonymous: true" do + it "returns an already unlinked File without a proper path" do + @tempfile = Tempfile.create(anonymous: true) + @tempfile.should_not.closed? + @tempfile.path.should == "#{Dir.tmpdir}/" + File.file?(@tempfile.path).should be_false + end + + it "unlinks file before calling the block" do + Tempfile.create(anonymous: true) do |tempfile| + @tempfile = tempfile + @tempfile.should_not.closed? + @tempfile.path.should == "#{Dir.tmpdir}/" + File.file?(@tempfile.path).should be_false + end + @tempfile.should.closed? + end + end + + context "when called with anonymous: false" do + it "returns a usual File with a path" do + @tempfile = Tempfile.create(anonymous: false) + @tempfile.should_not.closed? + @tempfile.path.should.start_with?(Dir.tmpdir) + File.file?(@tempfile.path).should be_true + end + end + end + + context "when called with other options" do + it "passes them along to File.open" do + @tempfile = Tempfile.create(encoding: "IBM037:IBM037", binmode: true) + @tempfile.external_encoding.should == Encoding.find("IBM037") + @tempfile.binmode?.should be_true + end + end +end diff --git a/spec/ruby/library/time/iso8601_spec.rb b/spec/ruby/library/time/iso8601_spec.rb index 4a9eb45613..ab35ab25d6 100644 --- a/spec/ruby/library/time/iso8601_spec.rb +++ b/spec/ruby/library/time/iso8601_spec.rb @@ -2,6 +2,6 @@ require_relative '../../spec_helper' require_relative 'shared/xmlschema' require 'time' -describe "Time.xmlschema" do - it_behaves_like :time_xmlschema, :iso8601 +describe "Time.iso8601" do + it_behaves_like :time_library_xmlschema, :iso8601 end diff --git a/spec/ruby/library/time/shared/rfc2822.rb b/spec/ruby/library/time/shared/rfc2822.rb index d99f1f76de..e460d655a6 100644 --- a/spec/ruby/library/time/shared/rfc2822.rb +++ b/spec/ruby/library/time/shared/rfc2822.rb @@ -1,33 +1,33 @@ describe :time_rfc2822, shared: true do it "parses RFC-822 strings" do t1 = (Time.utc(1976, 8, 26, 14, 30) + 4 * 3600) - t2 = Time.rfc2822("26 Aug 76 14:30 EDT") + t2 = Time.send(@method, "26 Aug 76 14:30 EDT") t1.should == t2 t3 = Time.utc(1976, 8, 27, 9, 32) + 7 * 3600 - t4 = Time.rfc2822("27 Aug 76 09:32 PDT") + t4 = Time.send(@method, "27 Aug 76 09:32 PDT") t3.should == t4 end it "parses RFC-2822 strings" do t1 = Time.utc(1997, 11, 21, 9, 55, 6) + 6 * 3600 - t2 = Time.rfc2822("Fri, 21 Nov 1997 09:55:06 -0600") + t2 = Time.send(@method, "Fri, 21 Nov 1997 09:55:06 -0600") t1.should == t2 t3 = Time.utc(2003, 7, 1, 10, 52, 37) - 2 * 3600 - t4 = Time.rfc2822("Tue, 1 Jul 2003 10:52:37 +0200") + t4 = Time.send(@method, "Tue, 1 Jul 2003 10:52:37 +0200") t3.should == t4 t5 = Time.utc(1997, 11, 21, 10, 1, 10) + 6 * 3600 - t6 = Time.rfc2822("Fri, 21 Nov 1997 10:01:10 -0600") + t6 = Time.send(@method, "Fri, 21 Nov 1997 10:01:10 -0600") t5.should == t6 t7 = Time.utc(1997, 11, 21, 11, 0, 0) + 6 * 3600 - t8 = Time.rfc2822("Fri, 21 Nov 1997 11:00:00 -0600") + t8 = Time.send(@method, "Fri, 21 Nov 1997 11:00:00 -0600") t7.should == t8 t9 = Time.utc(1997, 11, 24, 14, 22, 1) + 8 * 3600 - t10 = Time.rfc2822("Mon, 24 Nov 1997 14:22:01 -0800") + t10 = Time.send(@method, "Mon, 24 Nov 1997 14:22:01 -0800") t9.should == t10 begin @@ -36,11 +36,11 @@ describe :time_rfc2822, shared: true do # ignore else t11 = Time.utc(1969, 2, 13, 23, 32, 54) + 3 * 3600 + 30 * 60 - t12 = Time.rfc2822("Thu, 13 Feb 1969 23:32:54 -0330") + t12 = Time.send(@method, "Thu, 13 Feb 1969 23:32:54 -0330") t11.should == t12 t13 = Time.utc(1969, 2, 13, 23, 32, 0) + 3 * 3600 + 30 * 60 - t14 = Time.rfc2822(" Thu, + t14 = Time.send(@method, " Thu, 13 Feb 1969 @@ -50,16 +50,16 @@ describe :time_rfc2822, shared: true do end t15 = Time.utc(1997, 11, 21, 9, 55, 6) - t16 = Time.rfc2822("21 Nov 97 09:55:06 GMT") + t16 = Time.send(@method, "21 Nov 97 09:55:06 GMT") t15.should == t16 t17 = Time.utc(1997, 11, 21, 9, 55, 6) + 6 * 3600 - t18 = Time.rfc2822("Fri, 21 Nov 1997 09 : 55 : 06 -0600") + t18 = Time.send(@method, "Fri, 21 Nov 1997 09 : 55 : 06 -0600") t17.should == t18 -> { # inner comment is not supported. - Time.rfc2822("Fri, 21 Nov 1997 09(comment): 55 : 06 -0600") + Time.send(@method, "Fri, 21 Nov 1997 09(comment): 55 : 06 -0600") }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/library/time/shared/xmlschema.rb b/spec/ruby/library/time/shared/xmlschema.rb index 44d33cda7e..0002886ca5 100644 --- a/spec/ruby/library/time/shared/xmlschema.rb +++ b/spec/ruby/library/time/shared/xmlschema.rb @@ -1,24 +1,24 @@ -describe :time_xmlschema, shared: true do +describe :time_library_xmlschema, shared: true do it "parses ISO-8601 strings" do t = Time.utc(1985, 4, 12, 23, 20, 50, 520000) s = "1985-04-12T23:20:50.52Z" - t.should == Time.xmlschema(s) - #s.should == t.xmlschema(2) + t.should == Time.send(@method, s) + #s.should == t.send(@method, 2) t = Time.utc(1996, 12, 20, 0, 39, 57) s = "1996-12-19T16:39:57-08:00" - t.should == Time.xmlschema(s) + t.should == Time.send(@method, s) # There is no way to generate time string with arbitrary timezone. s = "1996-12-20T00:39:57Z" - t.should == Time.xmlschema(s) - #assert_equal(s, t.xmlschema) + t.should == Time.send(@method, s) + #assert_equal(s, t.send(@method)) t = Time.utc(1990, 12, 31, 23, 59, 60) s = "1990-12-31T23:59:60Z" - t.should == Time.xmlschema(s) + t.should == Time.send(@method, s) # leap second is representable only if timezone file has it. s = "1990-12-31T15:59:60-08:00" - t.should == Time.xmlschema(s) + t.should == Time.send(@method, s) begin Time.at(-1) @@ -27,27 +27,27 @@ describe :time_xmlschema, shared: true do else t = Time.utc(1937, 1, 1, 11, 40, 27, 870000) s = "1937-01-01T12:00:27.87+00:20" - t.should == Time.xmlschema(s) + t.should == Time.send(@method, s) end # more - # (Time.utc(1999, 5, 31, 13, 20, 0) + 5 * 3600).should == Time.xmlschema("1999-05-31T13:20:00-05:00") - # (Time.local(2000, 1, 20, 12, 0, 0)).should == Time.xmlschema("2000-01-20T12:00:00") - # (Time.utc(2000, 1, 20, 12, 0, 0)).should == Time.xmlschema("2000-01-20T12:00:00Z") - # (Time.utc(2000, 1, 20, 12, 0, 0) - 12 * 3600).should == Time.xmlschema("2000-01-20T12:00:00+12:00") - # (Time.utc(2000, 1, 20, 12, 0, 0) + 13 * 3600).should == Time.xmlschema("2000-01-20T12:00:00-13:00") - # (Time.utc(2000, 3, 4, 23, 0, 0) - 3 * 3600).should == Time.xmlschema("2000-03-04T23:00:00+03:00") - # (Time.utc(2000, 3, 4, 20, 0, 0)).should == Time.xmlschema("2000-03-04T20:00:00Z") - # (Time.local(2000, 1, 15, 0, 0, 0)).should == Time.xmlschema("2000-01-15T00:00:00") - # (Time.local(2000, 2, 15, 0, 0, 0)).should == Time.xmlschema("2000-02-15T00:00:00") - # (Time.local(2000, 1, 15, 12, 0, 0)).should == Time.xmlschema("2000-01-15T12:00:00") - # (Time.utc(2000, 1, 16, 12, 0, 0)).should == Time.xmlschema("2000-01-16T12:00:00Z") - # (Time.local(2000, 1, 1, 12, 0, 0)).should == Time.xmlschema("2000-01-01T12:00:00") - # (Time.utc(1999, 12, 31, 23, 0, 0)).should == Time.xmlschema("1999-12-31T23:00:00Z") - # (Time.local(2000, 1, 16, 12, 0, 0)).should == Time.xmlschema("2000-01-16T12:00:00") - # (Time.local(2000, 1, 16, 0, 0, 0)).should == Time.xmlschema("2000-01-16T00:00:00") - # (Time.utc(2000, 1, 12, 12, 13, 14)).should == Time.xmlschema("2000-01-12T12:13:14Z") - # (Time.utc(2001, 4, 17, 19, 23, 17, 300000)).should == Time.xmlschema("2001-04-17T19:23:17.3Z") + # (Time.utc(1999, 5, 31, 13, 20, 0) + 5 * 3600).should == Time.send(@method, "1999-05-31T13:20:00-05:00") + # (Time.local(2000, 1, 20, 12, 0, 0)).should == Time.send(@method, "2000-01-20T12:00:00") + # (Time.utc(2000, 1, 20, 12, 0, 0)).should == Time.send(@method, "2000-01-20T12:00:00Z") + # (Time.utc(2000, 1, 20, 12, 0, 0) - 12 * 3600).should == Time.send(@method, "2000-01-20T12:00:00+12:00") + # (Time.utc(2000, 1, 20, 12, 0, 0) + 13 * 3600).should == Time.send(@method, "2000-01-20T12:00:00-13:00") + # (Time.utc(2000, 3, 4, 23, 0, 0) - 3 * 3600).should == Time.send(@method, "2000-03-04T23:00:00+03:00") + # (Time.utc(2000, 3, 4, 20, 0, 0)).should == Time.send(@method, "2000-03-04T20:00:00Z") + # (Time.local(2000, 1, 15, 0, 0, 0)).should == Time.send(@method, "2000-01-15T00:00:00") + # (Time.local(2000, 2, 15, 0, 0, 0)).should == Time.send(@method, "2000-02-15T00:00:00") + # (Time.local(2000, 1, 15, 12, 0, 0)).should == Time.send(@method, "2000-01-15T12:00:00") + # (Time.utc(2000, 1, 16, 12, 0, 0)).should == Time.send(@method, "2000-01-16T12:00:00Z") + # (Time.local(2000, 1, 1, 12, 0, 0)).should == Time.send(@method, "2000-01-01T12:00:00") + # (Time.utc(1999, 12, 31, 23, 0, 0)).should == Time.send(@method, "1999-12-31T23:00:00Z") + # (Time.local(2000, 1, 16, 12, 0, 0)).should == Time.send(@method, "2000-01-16T12:00:00") + # (Time.local(2000, 1, 16, 0, 0, 0)).should == Time.send(@method, "2000-01-16T00:00:00") + # (Time.utc(2000, 1, 12, 12, 13, 14)).should == Time.send(@method, "2000-01-12T12:13:14Z") + # (Time.utc(2001, 4, 17, 19, 23, 17, 300000)).should == Time.send(@method, "2001-04-17T19:23:17.3Z") end end diff --git a/spec/ruby/library/time/xmlschema_spec.rb b/spec/ruby/library/time/xmlschema_spec.rb index 4279311199..ff3c864a02 100644 --- a/spec/ruby/library/time/xmlschema_spec.rb +++ b/spec/ruby/library/time/xmlschema_spec.rb @@ -3,5 +3,5 @@ require_relative 'shared/xmlschema' require 'time' describe "Time.xmlschema" do - it_behaves_like :time_xmlschema, :xmlschema + it_behaves_like :time_library_xmlschema, :xmlschema end diff --git a/spec/ruby/library/timeout/timeout_spec.rb b/spec/ruby/library/timeout/timeout_spec.rb index 584b38d8ec..e16bcaea6a 100644 --- a/spec/ruby/library/timeout/timeout_spec.rb +++ b/spec/ruby/library/timeout/timeout_spec.rb @@ -39,4 +39,12 @@ describe "Timeout.timeout" do 42 end.should == 42 end + + ruby_version_is "3.4" do + it "raises an ArgumentError when provided with a negative duration" do + -> { + Timeout.timeout(-1) + }.should raise_error(ArgumentError, "Timeout sec must be a non-negative number") + end + end end diff --git a/spec/ruby/library/uri/generic/host_spec.rb b/spec/ruby/library/uri/generic/host_spec.rb index f2076d2bc1..4a5a162512 100644 --- a/spec/ruby/library/uri/generic/host_spec.rb +++ b/spec/ruby/library/uri/generic/host_spec.rb @@ -2,7 +2,10 @@ require_relative '../../../spec_helper' require 'uri' describe "URI::Generic#host" do - it "needs to be reviewed for spec completeness" + # https://hackerone.com/reports/156615 + it "returns empty string when host is empty" do + URI.parse('http:////foo.com').host.should == '' + end end describe "URI::Generic#host=" do diff --git a/spec/ruby/library/uri/generic/to_s_spec.rb b/spec/ruby/library/uri/generic/to_s_spec.rb index 8c90d7645b..c436ee3c03 100644 --- a/spec/ruby/library/uri/generic/to_s_spec.rb +++ b/spec/ruby/library/uri/generic/to_s_spec.rb @@ -2,5 +2,8 @@ require_relative '../../../spec_helper' require 'uri' describe "URI::Generic#to_s" do - it "needs to be reviewed for spec completeness" + # https://hackerone.com/reports/156615 + it "preserves / characters when host is empty" do + URI('http:///foo.com').to_s.should == 'http:///foo.com' + end end diff --git a/spec/ruby/library/uri/set_component_spec.rb b/spec/ruby/library/uri/set_component_spec.rb index 642a5d6fcf..1d4165c535 100644 --- a/spec/ruby/library/uri/set_component_spec.rb +++ b/spec/ruby/library/uri/set_component_spec.rb @@ -6,25 +6,27 @@ describe "URI#select" do it "conforms to the MatzRuby tests" do uri = URI.parse('http://foo:bar@baz') (uri.user = 'oof').should == 'oof' - uri.to_s.should == 'http://oof:bar@baz' - (uri.password = 'rab').should == 'rab' - uri.to_s.should == 'http://oof:rab@baz' - (uri.userinfo = 'foo').should == 'foo' - uri.to_s.should == 'http://foo:rab@baz' - (uri.userinfo = ['foo', 'bar']).should == ['foo', 'bar'] - uri.to_s.should == 'http://foo:bar@baz' - (uri.userinfo = ['foo']).should == ['foo'] - uri.to_s.should == 'http://foo:bar@baz' - (uri.host = 'zab').should == 'zab' - uri.to_s.should == 'http://foo:bar@zab' - (uri.port = 8080).should == 8080 - uri.to_s.should == 'http://foo:bar@zab:8080' - (uri.path = '/').should == '/' - uri.to_s.should == 'http://foo:bar@zab:8080/' - (uri.query = 'a=1').should == 'a=1' - uri.to_s.should == 'http://foo:bar@zab:8080/?a=1' - (uri.fragment = 'b123').should == 'b123' - uri.to_s.should == 'http://foo:bar@zab:8080/?a=1#b123' + version_is(URI::VERSION, "1.0.4") do + uri.to_s.should == 'http://oof@baz' + (uri.password = 'rab').should == 'rab' + uri.to_s.should == 'http://oof:rab@baz' + (uri.userinfo = 'foo').should == 'foo' + uri.to_s.should == 'http://foo@baz' + (uri.userinfo = ['foo', 'bar']).should == ['foo', 'bar'] + uri.to_s.should == 'http://foo:bar@baz' + (uri.userinfo = ['foo']).should == ['foo'] + uri.to_s.should == 'http://foo@baz' + (uri.host = 'zab').should == 'zab' + uri.to_s.should == 'http://zab' + (uri.port = 8080).should == 8080 + uri.to_s.should == 'http://zab:8080' + (uri.path = '/').should == '/' + uri.to_s.should == 'http://zab:8080/' + (uri.query = 'a=1').should == 'a=1' + uri.to_s.should == 'http://zab:8080/?a=1' + (uri.fragment = 'b123').should == 'b123' + uri.to_s.should == 'http://zab:8080/?a=1#b123' + end uri = URI.parse('http://example.com') -> { uri.password = 'bar' }.should raise_error(URI::InvalidURIError) diff --git a/spec/ruby/library/uri/shared/parse.rb b/spec/ruby/library/uri/shared/parse.rb index 87e1ee933e..c5057b6c4b 100644 --- a/spec/ruby/library/uri/shared/parse.rb +++ b/spec/ruby/library/uri/shared/parse.rb @@ -192,8 +192,15 @@ describe :uri_parse, shared: true do file.should be_kind_of(URI::Generic) end - it "raises errors on malformed URIs" do - -> { @object.parse('http://a_b:80/') }.should raise_error(URI::InvalidURIError) - -> { @object.parse('http://a_b/') }.should raise_error(URI::InvalidURIError) + if URI::DEFAULT_PARSER == URI::RFC2396_Parser + it "raises errors on malformed URIs" do + -> { @object.parse('http://a_b:80/') }.should raise_error(URI::InvalidURIError) + -> { @object.parse('http://a_b/') }.should raise_error(URI::InvalidURIError) + end + elsif URI::DEFAULT_PARSER == URI::RFC3986_Parser + it "does not raise errors on URIs contained underscore" do + -> { @object.parse('http://a_b:80/') }.should_not raise_error(URI::InvalidURIError) + -> { @object.parse('http://a_b/') }.should_not raise_error(URI::InvalidURIError) + end end end diff --git a/spec/ruby/library/win32ole/fixtures/classes.rb b/spec/ruby/library/win32ole/fixtures/classes.rb index f61cf6ba69..5a16fcca45 100644 --- a/spec/ruby/library/win32ole/fixtures/classes.rb +++ b/spec/ruby/library/win32ole/fixtures/classes.rb @@ -1,14 +1,25 @@ require 'win32ole' +# win32ole deprecated constants like WIN32OLE_TYPELIB in Ruby 3.4 +# but only added the replacements like WIN32OLE::TypeLib in Ruby 3.4. +# So we use the new-style constants in specs to avoid deprecation warnings +# and we define the new-style constants as the old ones if they don't exist yet. +WIN32OLE::TypeLib ||= WIN32OLE_TYPELIB +WIN32OLE::RuntimeError ||= WIN32OLERuntimeError +WIN32OLE::Method ||= WIN32OLE_METHOD +WIN32OLE::Type ||= WIN32OLE_TYPE +WIN32OLE::Event ||= WIN32OLE_EVENT +WIN32OLE::Param ||= WIN32OLE_PARAM + module WIN32OLESpecs - MSXML_AVAILABLE = WIN32OLE_TYPELIB.typelibs.any? { |t| t.name.start_with?('Microsoft XML') } - SYSTEM_MONITOR_CONTROL_AVAILABLE = WIN32OLE_TYPELIB.typelibs.any? { |t| t.name.start_with?('System Monitor Control') } + MSXML_AVAILABLE = WIN32OLE::TypeLib.typelibs.any? { |t| t.name.start_with?('Microsoft XML') } + SYSTEM_MONITOR_CONTROL_AVAILABLE = WIN32OLE::TypeLib.typelibs.any? { |t| t.name.start_with?('System Monitor Control') } def self.new_ole(name) tries = 0 begin WIN32OLE.new(name) - rescue WIN32OLERuntimeError => e + rescue WIN32OLE::RuntimeError => e if tries < 3 tries += 1 $stderr.puts "WIN32OLESpecs#new_ole retry (#{tries}): #{e.class}: #{e.message}" diff --git a/spec/ruby/library/win32ole/win32ole/locale_spec.rb b/spec/ruby/library/win32ole/win32ole/locale_spec.rb index 78ede4375a..89e84d8038 100644 --- a/spec/ruby/library/win32ole/win32ole/locale_spec.rb +++ b/spec/ruby/library/win32ole/win32ole/locale_spec.rb @@ -13,14 +13,14 @@ platform_is :windows do begin begin WIN32OLE.locale = 1041 - rescue WIN32OLERuntimeError + rescue WIN32OLE::RuntimeError STDERR.puts("\n#{__FILE__}:#{__LINE__}:#{self.class.name}.test_s_locale_set is skipped(Japanese locale is not installed)") return end WIN32OLE.locale.should == 1041 WIN32OLE.locale = WIN32OLE::LOCALE_SYSTEM_DEFAULT - -> { WIN32OLE.locale = 111 }.should raise_error WIN32OLERuntimeError + -> { WIN32OLE.locale = 111 }.should raise_error WIN32OLE::RuntimeError WIN32OLE.locale.should == WIN32OLE::LOCALE_SYSTEM_DEFAULT ensure WIN32OLE.locale.should == WIN32OLE::LOCALE_SYSTEM_DEFAULT diff --git a/spec/ruby/library/win32ole/win32ole/new_spec.rb b/spec/ruby/library/win32ole/win32ole/new_spec.rb index 7e91c2d3ea..b2a0a5da18 100644 --- a/spec/ruby/library/win32ole/win32ole/new_spec.rb +++ b/spec/ruby/library/win32ole/win32ole/new_spec.rb @@ -17,8 +17,8 @@ platform_is :windows do -> { WIN32OLESpecs.new_ole(42) }.should raise_error( TypeError ) end - it "raises WIN32OLERuntimeError if invalid string is given" do - -> { WIN32OLE.new('foo') }.should raise_error( WIN32OLERuntimeError ) + it "raises WIN32OLE::RuntimeError if invalid string is given" do + -> { WIN32OLE.new('foo') }.should raise_error( WIN32OLE::RuntimeError ) end end diff --git a/spec/ruby/library/win32ole/win32ole/ole_func_methods_spec.rb b/spec/ruby/library/win32ole/win32ole/ole_func_methods_spec.rb index 2bbe8c27d4..b846685518 100644 --- a/spec/ruby/library/win32ole/win32ole/ole_func_methods_spec.rb +++ b/spec/ruby/library/win32ole/win32ole/ole_func_methods_spec.rb @@ -11,8 +11,8 @@ platform_is :windows do -> { @dict.ole_func_methods(1) }.should raise_error ArgumentError end - it "returns an array of WIN32OLE_METHODs" do - @dict.ole_func_methods.all? { |m| m.kind_of? WIN32OLE_METHOD }.should be_true + it "returns an array of WIN32OLE::Methods" do + @dict.ole_func_methods.all? { |m| m.kind_of? WIN32OLE::Method }.should be_true end it "contains a 'AddRef' method for Scripting Dictionary" do diff --git a/spec/ruby/library/win32ole/win32ole/ole_get_methods_spec.rb b/spec/ruby/library/win32ole/win32ole/ole_get_methods_spec.rb index c1d1970214..b6e7f960bb 100644 --- a/spec/ruby/library/win32ole/win32ole/ole_get_methods_spec.rb +++ b/spec/ruby/library/win32ole/win32ole/ole_get_methods_spec.rb @@ -8,8 +8,8 @@ platform_is :windows do @win32ole = WIN32OLESpecs.new_ole('Shell.Application') end - it "returns an array of WIN32OLE_METHOD objects" do - @win32ole.ole_get_methods.all? {|m| m.kind_of? WIN32OLE_METHOD}.should be_true + it "returns an array of WIN32OLE::Method objects" do + @win32ole.ole_get_methods.all? {|m| m.kind_of? WIN32OLE::Method}.should be_true end end diff --git a/spec/ruby/library/win32ole/win32ole/ole_methods_spec.rb b/spec/ruby/library/win32ole/win32ole/ole_methods_spec.rb index fe161ce9f0..92c4363f78 100644 --- a/spec/ruby/library/win32ole/win32ole/ole_methods_spec.rb +++ b/spec/ruby/library/win32ole/win32ole/ole_methods_spec.rb @@ -11,8 +11,8 @@ platform_is :windows do -> { @dict.ole_methods(1) }.should raise_error ArgumentError end - it "returns an array of WIN32OLE_METHODs" do - @dict.ole_methods.all? { |m| m.kind_of? WIN32OLE_METHOD }.should be_true + it "returns an array of WIN32OLE::Methods" do + @dict.ole_methods.all? { |m| m.kind_of? WIN32OLE::Method }.should be_true end it "contains a 'AddRef' method for Scripting Dictionary" do diff --git a/spec/ruby/library/win32ole/win32ole/ole_obj_help_spec.rb b/spec/ruby/library/win32ole/win32ole/ole_obj_help_spec.rb index afcf16a051..f298f19dba 100644 --- a/spec/ruby/library/win32ole/win32ole/ole_obj_help_spec.rb +++ b/spec/ruby/library/win32ole/win32ole/ole_obj_help_spec.rb @@ -12,8 +12,8 @@ platform_is :windows do -> { @dict.ole_obj_help(1) }.should raise_error ArgumentError end - it "returns an instance of WIN32OLE_TYPE" do - @dict.ole_obj_help.kind_of?(WIN32OLE_TYPE).should be_true + it "returns an instance of WIN32OLE::Type" do + @dict.ole_obj_help.kind_of?(WIN32OLE::Type).should be_true end end end diff --git a/spec/ruby/library/win32ole/win32ole/ole_put_methods_spec.rb b/spec/ruby/library/win32ole/win32ole/ole_put_methods_spec.rb index c091c83c95..2b46ae47de 100644 --- a/spec/ruby/library/win32ole/win32ole/ole_put_methods_spec.rb +++ b/spec/ruby/library/win32ole/win32ole/ole_put_methods_spec.rb @@ -11,8 +11,8 @@ platform_is :windows do -> { @dict.ole_put_methods(1) }.should raise_error ArgumentError end - it "returns an array of WIN32OLE_METHODs" do - @dict.ole_put_methods.all? { |m| m.kind_of? WIN32OLE_METHOD }.should be_true + it "returns an array of WIN32OLE::Methods" do + @dict.ole_put_methods.all? { |m| m.kind_of? WIN32OLE::Method }.should be_true end it "contains a 'Key' method for Scripting Dictionary" do diff --git a/spec/ruby/library/win32ole/win32ole/shared/ole_method.rb b/spec/ruby/library/win32ole/win32ole/shared/ole_method.rb index f1fd8713a4..bae424a604 100644 --- a/spec/ruby/library/win32ole/win32ole/shared/ole_method.rb +++ b/spec/ruby/library/win32ole/win32ole/shared/ole_method.rb @@ -10,9 +10,9 @@ platform_is :windows do -> { @dict.send(@method) }.should raise_error ArgumentError end - it "returns the WIN32OLE_METHOD 'Add' if given 'Add'" do + it "returns the WIN32OLE::Method 'Add' if given 'Add'" do result = @dict.send(@method, "Add") - result.kind_of?(WIN32OLE_METHOD).should be_true + result.kind_of?(WIN32OLE::Method).should be_true result.name.should == 'Add' end end diff --git a/spec/ruby/library/win32ole/win32ole_event/new_spec.rb b/spec/ruby/library/win32ole/win32ole_event/new_spec.rb index 94fabb1e3b..4efd4c3e0f 100644 --- a/spec/ruby/library/win32ole/win32ole_event/new_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_event/new_spec.rb @@ -3,7 +3,7 @@ platform_is :windows do require_relative '../fixtures/classes' guard -> { WIN32OLESpecs::MSXML_AVAILABLE } do - describe "WIN32OLE_EVENT.new" do + describe "WIN32OLE::Event.new" do before :all do @xml_dom = WIN32OLESpecs.new_ole('MSXML.DOMDocument') end @@ -13,21 +13,21 @@ platform_is :windows do end it "raises TypeError given invalid argument" do - -> { WIN32OLE_EVENT.new "A" }.should raise_error TypeError + -> { WIN32OLE::Event.new "A" }.should raise_error TypeError end it "raises RuntimeError if event does not exist" do - -> { WIN32OLE_EVENT.new(@xml_dom, 'A') }.should raise_error RuntimeError + -> { WIN32OLE::Event.new(@xml_dom, 'A') }.should raise_error RuntimeError end it "raises RuntimeError if OLE object has no events" do dict = WIN32OLESpecs.new_ole('Scripting.Dictionary') - -> { WIN32OLE_EVENT.new(dict) }.should raise_error RuntimeError + -> { WIN32OLE::Event.new(dict) }.should raise_error RuntimeError end - it "creates WIN32OLE_EVENT object" do - ev = WIN32OLE_EVENT.new(@xml_dom) - ev.should be_kind_of WIN32OLE_EVENT + it "creates WIN32OLE::Event object" do + ev = WIN32OLE::Event.new(@xml_dom) + ev.should be_kind_of WIN32OLE::Event end end end diff --git a/spec/ruby/library/win32ole/win32ole_event/on_event_spec.rb b/spec/ruby/library/win32ole/win32ole_event/on_event_spec.rb index 0957bdd2d4..acc7d2d6b6 100644 --- a/spec/ruby/library/win32ole/win32ole_event/on_event_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_event/on_event_spec.rb @@ -15,7 +15,7 @@ platform_is :windows do @event_spec_alt = "spec_alt" end - describe "WIN32OLE_EVENT#on_event" do + describe "WIN32OLE::Event#on_event" do before :all do @fn_xml = File.absolute_path "../fixtures/event.xml", __dir__ end @@ -23,7 +23,7 @@ platform_is :windows do before :each do @xml_dom = WIN32OLESpecs.new_ole 'MSXML.DOMDocument' @xml_dom.async = true - @ev = WIN32OLE_EVENT.new @xml_dom + @ev = WIN32OLE::Event.new @xml_dom @event_global = '' @event_specific = '' @event_spec_alt = '' @@ -37,21 +37,21 @@ platform_is :windows do it "sets global event handler properly, and the handler is invoked by event loop" do @ev.on_event { |*args| handler_global(*args) } @xml_dom.loadXML "<program><name>Ruby</name><version>trunk</version></program>" - WIN32OLE_EVENT.message_loop + WIN32OLE::Event.message_loop @event_global.should =~ /onreadystatechange/ end it "accepts a String argument and the handler is invoked by event loop" do @ev.on_event("onreadystatechange") { |*args| @event = 'foo' } @xml_dom.loadXML "<program><name>Ruby</name><version>trunk</version></program>" - WIN32OLE_EVENT.message_loop + WIN32OLE::Event.message_loop @event.should =~ /foo/ end it "accepts a Symbol argument and the handler is invoked by event loop" do @ev.on_event(:onreadystatechange) { |*args| @event = 'bar' } @xml_dom.loadXML "<program><name>Ruby</name><version>trunk</version></program>" - WIN32OLE_EVENT.message_loop + WIN32OLE::Event.message_loop @event.should =~ /bar/ end @@ -60,7 +60,7 @@ platform_is :windows do @ev.on_event("onreadystatechange") { |*args| handler_specific(*args) } @ev.on_event("onreadystatechange") { |*args| handler_spec_alt(*args) } @xml_dom.load @fn_xml - WIN32OLE_EVENT.message_loop + WIN32OLE::Event.message_loop @event_global.should == 'ondataavailable' @event_global.should_not =~ /onreadystatechange/ @event_specific.should == '' diff --git a/spec/ruby/library/win32ole/win32ole_method/dispid_spec.rb b/spec/ruby/library/win32ole/win32ole_method/dispid_spec.rb index ece71df0d4..e5f55f2d38 100644 --- a/spec/ruby/library/win32ole/win32ole_method/dispid_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_method/dispid_spec.rb @@ -2,10 +2,10 @@ require_relative "../../../spec_helper" platform_is :windows do require 'win32ole' - describe "WIN32OLE_METHOD#dispid" do + describe "WIN32OLE::Method#dispid" do before :each do - ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell") - @m = WIN32OLE_METHOD.new(ole_type, "namespace") + ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell") + @m = WIN32OLE::Method.new(ole_type, "namespace") end it "raises ArgumentError if argument is given" do diff --git a/spec/ruby/library/win32ole/win32ole_method/event_interface_spec.rb b/spec/ruby/library/win32ole/win32ole_method/event_interface_spec.rb index 78634d2fde..bea47348ee 100644 --- a/spec/ruby/library/win32ole/win32ole_method/event_interface_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_method/event_interface_spec.rb @@ -3,12 +3,12 @@ platform_is :windows do require_relative '../fixtures/classes' guard -> { WIN32OLESpecs::SYSTEM_MONITOR_CONTROL_AVAILABLE } do - describe "WIN32OLE_METHOD#event_interface" do + describe "WIN32OLE::Method#event_interface" do before :each do - ole_type = WIN32OLE_TYPE.new("System Monitor Control", "SystemMonitor") - @on_dbl_click_method = WIN32OLE_METHOD.new(ole_type, "OnDblClick") - ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell") - @namespace_method = WIN32OLE_METHOD.new(ole_type, "namespace") + ole_type = WIN32OLE::Type.new("System Monitor Control", "SystemMonitor") + @on_dbl_click_method = WIN32OLE::Method.new(ole_type, "OnDblClick") + ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell") + @namespace_method = WIN32OLE::Method.new(ole_type, "namespace") end it "raises ArgumentError if argument is given" do diff --git a/spec/ruby/library/win32ole/win32ole_method/event_spec.rb b/spec/ruby/library/win32ole/win32ole_method/event_spec.rb index 9b642a010c..5a94cf5ce6 100644 --- a/spec/ruby/library/win32ole/win32ole_method/event_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_method/event_spec.rb @@ -3,10 +3,10 @@ platform_is :windows do require_relative '../fixtures/classes' guard -> { WIN32OLESpecs::SYSTEM_MONITOR_CONTROL_AVAILABLE } do - describe "WIN32OLE_METHOD#event?" do + describe "WIN32OLE::Method#event?" do before :each do - ole_type = WIN32OLE_TYPE.new("System Monitor Control", "SystemMonitor") - @on_dbl_click_method = WIN32OLE_METHOD.new(ole_type, "OnDblClick") + ole_type = WIN32OLE::Type.new("System Monitor Control", "SystemMonitor") + @on_dbl_click_method = WIN32OLE::Method.new(ole_type, "OnDblClick") end it "raises ArgumentError if argument is given" do diff --git a/spec/ruby/library/win32ole/win32ole_method/helpcontext_spec.rb b/spec/ruby/library/win32ole/win32ole_method/helpcontext_spec.rb index d1c5ee3be2..83f34b9c10 100644 --- a/spec/ruby/library/win32ole/win32ole_method/helpcontext_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_method/helpcontext_spec.rb @@ -2,12 +2,12 @@ require_relative "../../../spec_helper" platform_is :windows do require 'win32ole' - describe "WIN32OLE_METHOD#helpcontext" do + describe "WIN32OLE::Method#helpcontext" do before :each do - ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "FileSystemObject") - @get_file_version = WIN32OLE_METHOD.new(ole_type, "GetFileVersion") - ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "File") - @m_file_name = WIN32OLE_METHOD.new(ole_type, "name") + ole_type = WIN32OLE::Type.new("Microsoft Scripting Runtime", "FileSystemObject") + @get_file_version = WIN32OLE::Method.new(ole_type, "GetFileVersion") + ole_type = WIN32OLE::Type.new("Microsoft Scripting Runtime", "File") + @m_file_name = WIN32OLE::Method.new(ole_type, "name") end it "raises ArgumentError if argument is given" do diff --git a/spec/ruby/library/win32ole/win32ole_method/helpfile_spec.rb b/spec/ruby/library/win32ole/win32ole_method/helpfile_spec.rb index 59dad9244c..9cf9d63d3b 100644 --- a/spec/ruby/library/win32ole/win32ole_method/helpfile_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_method/helpfile_spec.rb @@ -2,10 +2,10 @@ require_relative "../../../spec_helper" platform_is :windows do require 'win32ole' - describe "WIN32OLE_METHOD#helpfile" do + describe "WIN32OLE::Method#helpfile" do before :each do - ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "File") - @m_file_name = WIN32OLE_METHOD.new(ole_type, "name") + ole_type = WIN32OLE::Type.new("Microsoft Scripting Runtime", "File") + @m_file_name = WIN32OLE::Method.new(ole_type, "name") end it "raises ArgumentError if argument is given" do diff --git a/spec/ruby/library/win32ole/win32ole_method/helpstring_spec.rb b/spec/ruby/library/win32ole/win32ole_method/helpstring_spec.rb index b2f24ba151..5ae4a5e090 100644 --- a/spec/ruby/library/win32ole/win32ole_method/helpstring_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_method/helpstring_spec.rb @@ -2,10 +2,10 @@ require_relative "../../../spec_helper" platform_is :windows do require 'win32ole' - describe "WIN32OLE_METHOD#helpstring" do + describe "WIN32OLE::Method#helpstring" do before :each do - ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "File") - @m_file_name = WIN32OLE_METHOD.new(ole_type, "name") + ole_type = WIN32OLE::Type.new("Microsoft Scripting Runtime", "File") + @m_file_name = WIN32OLE::Method.new(ole_type, "name") end it "raises ArgumentError if argument is given" do diff --git a/spec/ruby/library/win32ole/win32ole_method/invkind_spec.rb b/spec/ruby/library/win32ole/win32ole_method/invkind_spec.rb index d7fedf0d36..06acbb58a5 100644 --- a/spec/ruby/library/win32ole/win32ole_method/invkind_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_method/invkind_spec.rb @@ -2,10 +2,10 @@ require_relative "../../../spec_helper" platform_is :windows do require 'win32ole' - describe "WIN32OLE_METHOD#invkind" do + describe "WIN32OLE::Method#invkind" do before :each do - ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "File") - @m_file_name = WIN32OLE_METHOD.new(ole_type, "name") + ole_type = WIN32OLE::Type.new("Microsoft Scripting Runtime", "File") + @m_file_name = WIN32OLE::Method.new(ole_type, "name") end it "raises ArgumentError if argument is given" do diff --git a/spec/ruby/library/win32ole/win32ole_method/invoke_kind_spec.rb b/spec/ruby/library/win32ole/win32ole_method/invoke_kind_spec.rb index d5536fd17b..0e97ec3305 100644 --- a/spec/ruby/library/win32ole/win32ole_method/invoke_kind_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_method/invoke_kind_spec.rb @@ -2,10 +2,10 @@ require_relative "../../../spec_helper" platform_is :windows do require 'win32ole' - describe "WIN32OLE_METHOD#invoke_kind" do + describe "WIN32OLE::Method#invoke_kind" do before :each do - ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "File") - @m_file_name = WIN32OLE_METHOD.new(ole_type, "name") + ole_type = WIN32OLE::Type.new("Microsoft Scripting Runtime", "File") + @m_file_name = WIN32OLE::Method.new(ole_type, "name") end it "raises ArgumentError if argument is given" do diff --git a/spec/ruby/library/win32ole/win32ole_method/name_spec.rb b/spec/ruby/library/win32ole/win32ole_method/name_spec.rb index 477b820f4d..6e2e233a62 100644 --- a/spec/ruby/library/win32ole/win32ole_method/name_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_method/name_spec.rb @@ -4,7 +4,7 @@ require_relative 'shared/name' platform_is :windows do require 'win32ole' - describe "WIN32OLE_METHOD#name" do + describe "WIN32OLE::Method#name" do it_behaves_like :win32ole_method_name, :name end diff --git a/spec/ruby/library/win32ole/win32ole_method/new_spec.rb b/spec/ruby/library/win32ole/win32ole_method/new_spec.rb index 4e427421b9..46186ae566 100644 --- a/spec/ruby/library/win32ole/win32ole_method/new_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_method/new_spec.rb @@ -2,31 +2,31 @@ require_relative "../../../spec_helper" platform_is :windows do require 'win32ole' - describe "WIN32OLE_METHOD.new" do + describe "WIN32OLE::Method.new" do before :each do - @ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell") + @ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell") end it "raises TypeError when given non-strings" do - -> { WIN32OLE_METHOD.new(1, 2) }.should raise_error TypeError + -> { WIN32OLE::Method.new(1, 2) }.should raise_error TypeError end it "raises ArgumentError if only 1 argument is given" do - -> { WIN32OLE_METHOD.new("hello") }.should raise_error ArgumentError - -> { WIN32OLE_METHOD.new(@ole_type) }.should raise_error ArgumentError + -> { WIN32OLE::Method.new("hello") }.should raise_error ArgumentError + -> { WIN32OLE::Method.new(@ole_type) }.should raise_error ArgumentError end - it "returns a valid WIN32OLE_METHOD object" do - WIN32OLE_METHOD.new(@ole_type, "Open").should be_kind_of WIN32OLE_METHOD - WIN32OLE_METHOD.new(@ole_type, "open").should be_kind_of WIN32OLE_METHOD + it "returns a valid WIN32OLE::Method object" do + WIN32OLE::Method.new(@ole_type, "Open").should be_kind_of WIN32OLE::Method + WIN32OLE::Method.new(@ole_type, "open").should be_kind_of WIN32OLE::Method end - it "raises WIN32OLERuntimeError if the method does not exist" do - -> { WIN32OLE_METHOD.new(@ole_type, "NonexistentMethod") }.should raise_error WIN32OLERuntimeError + it "raises WIN32OLE::RuntimeError if the method does not exist" do + -> { WIN32OLE::Method.new(@ole_type, "NonexistentMethod") }.should raise_error WIN32OLE::RuntimeError end it "raises TypeError if second argument is not a String" do - -> { WIN32OLE_METHOD.new(@ole_type, 5) }.should raise_error TypeError + -> { WIN32OLE::Method.new(@ole_type, 5) }.should raise_error TypeError end end diff --git a/spec/ruby/library/win32ole/win32ole_method/offset_vtbl_spec.rb b/spec/ruby/library/win32ole/win32ole_method/offset_vtbl_spec.rb index b3da9a8303..3c80cb3c2a 100644 --- a/spec/ruby/library/win32ole/win32ole_method/offset_vtbl_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_method/offset_vtbl_spec.rb @@ -2,10 +2,10 @@ require_relative "../../../spec_helper" platform_is :windows do require 'win32ole' - describe "WIN32OLE_METHOD#offset_vtbl" do + describe "WIN32OLE::Method#offset_vtbl" do before :each do - ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "File") - @m_file_name = WIN32OLE_METHOD.new(ole_type, "name") + ole_type = WIN32OLE::Type.new("Microsoft Scripting Runtime", "File") + @m_file_name = WIN32OLE::Method.new(ole_type, "name") end it "raises ArgumentError if argument is given" do diff --git a/spec/ruby/library/win32ole/win32ole_method/params_spec.rb b/spec/ruby/library/win32ole/win32ole_method/params_spec.rb index 09fb0eb5ac..0b1b4595a3 100644 --- a/spec/ruby/library/win32ole/win32ole_method/params_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_method/params_spec.rb @@ -2,12 +2,12 @@ require_relative "../../../spec_helper" platform_is :windows do require 'win32ole' - describe "WIN32OLE_METHOD#params" do + describe "WIN32OLE::Method#params" do before :each do - ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "File") - @m_file_name = WIN32OLE_METHOD.new(ole_type, "name") - ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell") - @m_browse_for_folder = WIN32OLE_METHOD.new(ole_type, "BrowseForFolder") + ole_type = WIN32OLE::Type.new("Microsoft Scripting Runtime", "File") + @m_file_name = WIN32OLE::Method.new(ole_type, "name") + ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell") + @m_browse_for_folder = WIN32OLE::Method.new(ole_type, "BrowseForFolder") end it "raises ArgumentError if argument is given" do @@ -19,8 +19,8 @@ platform_is :windows do @m_file_name.params.should be_empty end - it "returns 4-element array of WIN32OLE_PARAM for Shell's 'BrowseForFolder' method" do - @m_browse_for_folder.params.all? { |p| p.kind_of? WIN32OLE_PARAM }.should be_true + it "returns 4-element array of WIN32OLE::Param for Shell's 'BrowseForFolder' method" do + @m_browse_for_folder.params.all? { |p| p.kind_of? WIN32OLE::Param }.should be_true @m_browse_for_folder.params.size == 4 end diff --git a/spec/ruby/library/win32ole/win32ole_method/return_type_detail_spec.rb b/spec/ruby/library/win32ole/win32ole_method/return_type_detail_spec.rb index 582a5951d5..c3725bfef2 100644 --- a/spec/ruby/library/win32ole/win32ole_method/return_type_detail_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_method/return_type_detail_spec.rb @@ -2,10 +2,10 @@ require_relative "../../../spec_helper" platform_is :windows do require 'win32ole' - describe "WIN32OLE_METHOD#return_type_detail" do + describe "WIN32OLE::Method#return_type_detail" do before :each do - ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell") - @m_browse_for_folder = WIN32OLE_METHOD.new(ole_type, "BrowseForFolder") + ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell") + @m_browse_for_folder = WIN32OLE::Method.new(ole_type, "BrowseForFolder") end it "raises ArgumentError if argument is given" do diff --git a/spec/ruby/library/win32ole/win32ole_method/return_type_spec.rb b/spec/ruby/library/win32ole/win32ole_method/return_type_spec.rb index dd8add402d..9e5a1eb1df 100644 --- a/spec/ruby/library/win32ole/win32ole_method/return_type_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_method/return_type_spec.rb @@ -2,10 +2,10 @@ require_relative "../../../spec_helper" platform_is :windows do require 'win32ole' - describe "WIN32OLE_METHOD#return_type" do + describe "WIN32OLE::Method#return_type" do before :each do - ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "File") - @m_file_name = WIN32OLE_METHOD.new(ole_type, "name") + ole_type = WIN32OLE::Type.new("Microsoft Scripting Runtime", "File") + @m_file_name = WIN32OLE::Method.new(ole_type, "name") end it "raises ArgumentError if argument is given" do diff --git a/spec/ruby/library/win32ole/win32ole_method/return_vtype_spec.rb b/spec/ruby/library/win32ole/win32ole_method/return_vtype_spec.rb index 3fca3d54ed..34fd135b8c 100644 --- a/spec/ruby/library/win32ole/win32ole_method/return_vtype_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_method/return_vtype_spec.rb @@ -2,10 +2,10 @@ require_relative "../../../spec_helper" platform_is :windows do require 'win32ole' - describe "WIN32OLE_METHOD#return_vtype" do + describe "WIN32OLE::Method#return_vtype" do before :each do - ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell") - @m_browse_for_folder = WIN32OLE_METHOD.new(ole_type, "BrowseForFolder") + ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell") + @m_browse_for_folder = WIN32OLE::Method.new(ole_type, "BrowseForFolder") end it "raises ArgumentError if argument is given" do diff --git a/spec/ruby/library/win32ole/win32ole_method/shared/name.rb b/spec/ruby/library/win32ole/win32ole_method/shared/name.rb index ddaff4011b..7e2197ca5a 100644 --- a/spec/ruby/library/win32ole/win32ole_method/shared/name.rb +++ b/spec/ruby/library/win32ole/win32ole_method/shared/name.rb @@ -3,8 +3,8 @@ platform_is :windows do describe :win32ole_method_name, shared: true do before :each do - ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "File") - @m_file_name = WIN32OLE_METHOD.new(ole_type, "name") + ole_type = WIN32OLE::Type.new("Microsoft Scripting Runtime", "File") + @m_file_name = WIN32OLE::Method.new(ole_type, "name") end it "raises ArgumentError if argument is given" do diff --git a/spec/ruby/library/win32ole/win32ole_method/size_opt_params_spec.rb b/spec/ruby/library/win32ole/win32ole_method/size_opt_params_spec.rb index fe9facb53a..38cb21ccef 100644 --- a/spec/ruby/library/win32ole/win32ole_method/size_opt_params_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_method/size_opt_params_spec.rb @@ -2,10 +2,10 @@ require_relative "../../../spec_helper" platform_is :windows do require 'win32ole' - describe "WIN32OLE_METHOD#size_opt_params" do + describe "WIN32OLE::Method#size_opt_params" do before :each do - ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell") - @m_browse_for_folder = WIN32OLE_METHOD.new(ole_type, "BrowseForFolder") + ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell") + @m_browse_for_folder = WIN32OLE::Method.new(ole_type, "BrowseForFolder") end it "raises ArgumentError if argument is given" do diff --git a/spec/ruby/library/win32ole/win32ole_method/size_params_spec.rb b/spec/ruby/library/win32ole/win32ole_method/size_params_spec.rb index 8ea6e61e7d..5d0a35a0ef 100644 --- a/spec/ruby/library/win32ole/win32ole_method/size_params_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_method/size_params_spec.rb @@ -2,10 +2,10 @@ require_relative "../../../spec_helper" platform_is :windows do require 'win32ole' - describe "WIN32OLE_METHOD#size_params" do + describe "WIN32OLE::Method#size_params" do before :each do - ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell") - @m_browse_for_folder = WIN32OLE_METHOD.new(ole_type, "BrowseForFolder") + ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell") + @m_browse_for_folder = WIN32OLE::Method.new(ole_type, "BrowseForFolder") end it "raises ArgumentError if argument is given" do diff --git a/spec/ruby/library/win32ole/win32ole_method/to_s_spec.rb b/spec/ruby/library/win32ole/win32ole_method/to_s_spec.rb index 11107a77fc..cdcc4525b1 100644 --- a/spec/ruby/library/win32ole/win32ole_method/to_s_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_method/to_s_spec.rb @@ -4,7 +4,7 @@ require_relative 'shared/name' platform_is :windows do require 'win32ole' - describe "WIN32OLE_METHOD#name" do + describe "WIN32OLE::Method#name" do it_behaves_like :win32ole_method_name, :to_s end diff --git a/spec/ruby/library/win32ole/win32ole_method/visible_spec.rb b/spec/ruby/library/win32ole/win32ole_method/visible_spec.rb index d1a50523fc..2f02c15c8b 100644 --- a/spec/ruby/library/win32ole/win32ole_method/visible_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_method/visible_spec.rb @@ -2,10 +2,10 @@ require_relative "../../../spec_helper" platform_is :windows do require 'win32ole' - describe "WIN32OLE_METHOD#visible?" do + describe "WIN32OLE::Method#visible?" do before :each do - ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell") - @m_browse_for_folder = WIN32OLE_METHOD.new(ole_type, "BrowseForFolder") + ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell") + @m_browse_for_folder = WIN32OLE::Method.new(ole_type, "BrowseForFolder") end it "raises ArgumentError if argument is given" do diff --git a/spec/ruby/library/win32ole/win32ole_param/default_spec.rb b/spec/ruby/library/win32ole/win32ole_param/default_spec.rb index 44bd3d7fd3..a37b03866d 100644 --- a/spec/ruby/library/win32ole/win32ole_param/default_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_param/default_spec.rb @@ -2,14 +2,14 @@ require_relative "../../../spec_helper" platform_is :windows do require 'win32ole' - describe "WIN32OLE_PARAM#default" do + describe "WIN32OLE::Param#default" do before :each do - ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell") - m_browse_for_folder = WIN32OLE_METHOD.new(ole_type, "BrowseForFolder") + ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell") + m_browse_for_folder = WIN32OLE::Method.new(ole_type, "BrowseForFolder") @params = m_browse_for_folder.params - ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "FileSystemObject") - m_copyfile = WIN32OLE_METHOD.new(ole_type, "CopyFile") + ole_type = WIN32OLE::Type.new("Microsoft Scripting Runtime", "FileSystemObject") + m_copyfile = WIN32OLE::Method.new(ole_type, "CopyFile") @param_overwritefiles = m_copyfile.params[2] end @@ -17,7 +17,7 @@ platform_is :windows do -> { @params[0].default(1) }.should raise_error ArgumentError end - it "returns nil for each of WIN32OLE_PARAM for Shell's 'BrowseForFolder' method" do + it "returns nil for each of WIN32OLE::Param for Shell's 'BrowseForFolder' method" do @params.each do |p| p.default.should be_nil end diff --git a/spec/ruby/library/win32ole/win32ole_param/input_spec.rb b/spec/ruby/library/win32ole/win32ole_param/input_spec.rb index e9134b1df8..d7e27d7739 100644 --- a/spec/ruby/library/win32ole/win32ole_param/input_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_param/input_spec.rb @@ -2,10 +2,10 @@ require_relative "../../../spec_helper" platform_is :windows do require 'win32ole' - describe "WIN32OLE_PARAM#input?" do + describe "WIN32OLE::Param#input?" do before :each do - ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "FileSystemObject") - m_copyfile = WIN32OLE_METHOD.new(ole_type, "CopyFile") + ole_type = WIN32OLE::Type.new("Microsoft Scripting Runtime", "FileSystemObject") + m_copyfile = WIN32OLE::Method.new(ole_type, "CopyFile") @param_overwritefiles = m_copyfile.params[2] end diff --git a/spec/ruby/library/win32ole/win32ole_param/name_spec.rb b/spec/ruby/library/win32ole/win32ole_param/name_spec.rb index 67a8955ba4..2c3474ffb3 100644 --- a/spec/ruby/library/win32ole/win32ole_param/name_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_param/name_spec.rb @@ -4,7 +4,7 @@ require_relative 'shared/name' platform_is :windows do require 'win32ole' - describe "WIN32OLE_PARAM#name" do + describe "WIN32OLE::Param#name" do it_behaves_like :win32ole_param_name, :name end diff --git a/spec/ruby/library/win32ole/win32ole_param/ole_type_detail_spec.rb b/spec/ruby/library/win32ole/win32ole_param/ole_type_detail_spec.rb index f05455e3f1..e3379dbf3e 100644 --- a/spec/ruby/library/win32ole/win32ole_param/ole_type_detail_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_param/ole_type_detail_spec.rb @@ -2,10 +2,10 @@ require_relative "../../../spec_helper" platform_is :windows do require 'win32ole' - describe "WIN32OLE_PARAM#ole_type_detail" do + describe "WIN32OLE::Param#ole_type_detail" do before :each do - ole_type_detail = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "FileSystemObject") - m_copyfile = WIN32OLE_METHOD.new(ole_type_detail, "CopyFile") + ole_type_detail = WIN32OLE::Type.new("Microsoft Scripting Runtime", "FileSystemObject") + m_copyfile = WIN32OLE::Method.new(ole_type_detail, "CopyFile") @param_overwritefiles = m_copyfile.params[2] end diff --git a/spec/ruby/library/win32ole/win32ole_param/ole_type_spec.rb b/spec/ruby/library/win32ole/win32ole_param/ole_type_spec.rb index 1467130e03..a7b6666807 100644 --- a/spec/ruby/library/win32ole/win32ole_param/ole_type_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_param/ole_type_spec.rb @@ -2,10 +2,10 @@ require_relative "../../../spec_helper" platform_is :windows do require 'win32ole' - describe "WIN32OLE_PARAM#ole_type" do + describe "WIN32OLE::Param#ole_type" do before :each do - ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "FileSystemObject") - m_copyfile = WIN32OLE_METHOD.new(ole_type, "CopyFile") + ole_type = WIN32OLE::Type.new("Microsoft Scripting Runtime", "FileSystemObject") + m_copyfile = WIN32OLE::Method.new(ole_type, "CopyFile") @param_overwritefiles = m_copyfile.params[2] end diff --git a/spec/ruby/library/win32ole/win32ole_param/optional_spec.rb b/spec/ruby/library/win32ole/win32ole_param/optional_spec.rb index b39ee41179..50e95fc77f 100644 --- a/spec/ruby/library/win32ole/win32ole_param/optional_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_param/optional_spec.rb @@ -2,10 +2,10 @@ require_relative "../../../spec_helper" platform_is :windows do require 'win32ole' - describe "WIN32OLE_PARAM#optional?" do + describe "WIN32OLE::Param#optional?" do before :each do - ole_type_detail = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "FileSystemObject") - m_copyfile = WIN32OLE_METHOD.new(ole_type_detail, "CopyFile") + ole_type_detail = WIN32OLE::Type.new("Microsoft Scripting Runtime", "FileSystemObject") + m_copyfile = WIN32OLE::Method.new(ole_type_detail, "CopyFile") @param_overwritefiles = m_copyfile.params[2] end diff --git a/spec/ruby/library/win32ole/win32ole_param/retval_spec.rb b/spec/ruby/library/win32ole/win32ole_param/retval_spec.rb index dd613dd29a..fa4a09ea0c 100644 --- a/spec/ruby/library/win32ole/win32ole_param/retval_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_param/retval_spec.rb @@ -2,10 +2,10 @@ require_relative "../../../spec_helper" platform_is :windows do require 'win32ole' - describe "WIN32OLE_PARAM#retval?" do + describe "WIN32OLE::Param#retval?" do before :each do - ole_type_detail = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "FileSystemObject") - m_copyfile = WIN32OLE_METHOD.new(ole_type_detail, "CopyFile") + ole_type_detail = WIN32OLE::Type.new("Microsoft Scripting Runtime", "FileSystemObject") + m_copyfile = WIN32OLE::Method.new(ole_type_detail, "CopyFile") @param_overwritefiles = m_copyfile.params[2] end diff --git a/spec/ruby/library/win32ole/win32ole_param/shared/name.rb b/spec/ruby/library/win32ole/win32ole_param/shared/name.rb index 043bc32856..56ff24ddc8 100644 --- a/spec/ruby/library/win32ole/win32ole_param/shared/name.rb +++ b/spec/ruby/library/win32ole/win32ole_param/shared/name.rb @@ -3,8 +3,8 @@ platform_is :windows do describe :win32ole_param_name, shared: true do before :each do - ole_type_detail = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "FileSystemObject") - m_copyfile = WIN32OLE_METHOD.new(ole_type_detail, "CopyFile") + ole_type_detail = WIN32OLE::Type.new("Microsoft Scripting Runtime", "FileSystemObject") + m_copyfile = WIN32OLE::Method.new(ole_type_detail, "CopyFile") @param_overwritefiles = m_copyfile.params[2] end diff --git a/spec/ruby/library/win32ole/win32ole_param/to_s_spec.rb b/spec/ruby/library/win32ole/win32ole_param/to_s_spec.rb index e9153a2eb2..c59f426692 100644 --- a/spec/ruby/library/win32ole/win32ole_param/to_s_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_param/to_s_spec.rb @@ -4,7 +4,7 @@ require_relative 'shared/name' platform_is :windows do require 'win32ole' - describe "WIN32OLE_PARAM#to_s" do + describe "WIN32OLE::Param#to_s" do it_behaves_like :win32ole_param_name, :to_s end diff --git a/spec/ruby/library/win32ole/win32ole_type/guid_spec.rb b/spec/ruby/library/win32ole/win32ole_type/guid_spec.rb index abdf8d34b9..e574a945ad 100644 --- a/spec/ruby/library/win32ole/win32ole_type/guid_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_type/guid_spec.rb @@ -2,9 +2,9 @@ require_relative "../../../spec_helper" platform_is :windows do require 'win32ole' - describe "WIN32OLE_TYPE#guid for Shell Controls" do + describe "WIN32OLE::Type#guid for Shell Controls" do before :each do - @ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell") + @ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell") end after :each do diff --git a/spec/ruby/library/win32ole/win32ole_type/helpcontext_spec.rb b/spec/ruby/library/win32ole/win32ole_type/helpcontext_spec.rb index eee23abc56..35911fec52 100644 --- a/spec/ruby/library/win32ole/win32ole_type/helpcontext_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_type/helpcontext_spec.rb @@ -2,9 +2,9 @@ require_relative "../../../spec_helper" platform_is :windows do require 'win32ole' - describe "WIN32OLE_TYPE#helpcontext for Shell Controls" do + describe "WIN32OLE::Type#helpcontext for Shell Controls" do before :each do - @ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell") + @ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell") end after :each do diff --git a/spec/ruby/library/win32ole/win32ole_type/helpfile_spec.rb b/spec/ruby/library/win32ole/win32ole_type/helpfile_spec.rb index 3a0a9ead94..7bd61a1c40 100644 --- a/spec/ruby/library/win32ole/win32ole_type/helpfile_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_type/helpfile_spec.rb @@ -2,9 +2,9 @@ require_relative "../../../spec_helper" platform_is :windows do require 'win32ole' - describe "WIN32OLE_TYPE#helpfile for Shell Controls" do + describe "WIN32OLE::Type#helpfile for Shell Controls" do before :each do - @ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell") + @ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell") end after :each do diff --git a/spec/ruby/library/win32ole/win32ole_type/helpstring_spec.rb b/spec/ruby/library/win32ole/win32ole_type/helpstring_spec.rb index 9ab0004668..940475b25e 100644 --- a/spec/ruby/library/win32ole/win32ole_type/helpstring_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_type/helpstring_spec.rb @@ -2,9 +2,9 @@ require_relative "../../../spec_helper" platform_is :windows do require 'win32ole' - describe "WIN32OLE_TYPE#helpstring for Shell Controls" do + describe "WIN32OLE::Type#helpstring for Shell Controls" do before :each do - @ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell") + @ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell") end after :each do diff --git a/spec/ruby/library/win32ole/win32ole_type/major_version_spec.rb b/spec/ruby/library/win32ole/win32ole_type/major_version_spec.rb index 7d2731f778..598e5bcef8 100644 --- a/spec/ruby/library/win32ole/win32ole_type/major_version_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_type/major_version_spec.rb @@ -2,9 +2,9 @@ require_relative "../../../spec_helper" platform_is :windows do require 'win32ole' - describe "WIN32OLE_TYPE#major_version for Shell Controls" do + describe "WIN32OLE::Type#major_version for Shell Controls" do before :each do - @ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell") + @ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell") end after :each do diff --git a/spec/ruby/library/win32ole/win32ole_type/minor_version_spec.rb b/spec/ruby/library/win32ole/win32ole_type/minor_version_spec.rb index 3904e78d42..59cfb94012 100644 --- a/spec/ruby/library/win32ole/win32ole_type/minor_version_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_type/minor_version_spec.rb @@ -2,9 +2,9 @@ require_relative "../../../spec_helper" platform_is :windows do require 'win32ole' - describe "WIN32OLE_TYPE#minor_version for Shell Controls" do + describe "WIN32OLE::Type#minor_version for Shell Controls" do before :each do - @ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell") + @ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell") end after :each do diff --git a/spec/ruby/library/win32ole/win32ole_type/name_spec.rb b/spec/ruby/library/win32ole/win32ole_type/name_spec.rb index d76998d7dc..4cc3426872 100644 --- a/spec/ruby/library/win32ole/win32ole_type/name_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_type/name_spec.rb @@ -4,7 +4,7 @@ require_relative 'shared/name' platform_is :windows do require 'win32ole' - describe "WIN32OLE_TYPE#name" do + describe "WIN32OLE::Type#name" do it_behaves_like :win32ole_type_name, :name end diff --git a/spec/ruby/library/win32ole/win32ole_type/new_spec.rb b/spec/ruby/library/win32ole/win32ole_type/new_spec.rb index cc691ffa67..185a235940 100644 --- a/spec/ruby/library/win32ole/win32ole_type/new_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_type/new_spec.rb @@ -2,39 +2,39 @@ require_relative "../../../spec_helper" platform_is :windows do require 'win32ole' - describe "WIN32OLE_TYPE.new" do + describe "WIN32OLE::Type.new" do it "raises ArgumentError with no argument" do - -> { WIN32OLE_TYPE.new }.should raise_error ArgumentError + -> { WIN32OLE::Type.new }.should raise_error ArgumentError end it "raises ArgumentError with invalid string" do - -> { WIN32OLE_TYPE.new("foo") }.should raise_error ArgumentError + -> { WIN32OLE::Type.new("foo") }.should raise_error ArgumentError end it "raises TypeError if second argument is not a String" do - -> { WIN32OLE_TYPE.new(1,2) }.should raise_error TypeError + -> { WIN32OLE::Type.new(1,2) }.should raise_error TypeError -> { - WIN32OLE_TYPE.new('Microsoft Shell Controls And Automation',2) + WIN32OLE::Type.new('Microsoft Shell Controls And Automation',2) }.should raise_error TypeError end - it "raise WIN32OLERuntimeError if OLE object specified is not found" do + it "raise WIN32OLE::RuntimeError if OLE object specified is not found" do -> { - WIN32OLE_TYPE.new('Microsoft Shell Controls And Automation','foo') - }.should raise_error WIN32OLERuntimeError + WIN32OLE::Type.new('Microsoft Shell Controls And Automation','foo') + }.should raise_error WIN32OLE::RuntimeError -> { - WIN32OLE_TYPE.new('Microsoft Shell Controls And Automation','Application') - }.should raise_error WIN32OLERuntimeError + WIN32OLE::Type.new('Microsoft Shell Controls And Automation','Application') + }.should raise_error WIN32OLE::RuntimeError end - it "creates WIN32OLE_TYPE object from name and valid type" do - ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell") - ole_type.should be_kind_of WIN32OLE_TYPE + it "creates WIN32OLE::Type object from name and valid type" do + ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell") + ole_type.should be_kind_of WIN32OLE::Type end - it "creates WIN32OLE_TYPE object from CLSID and valid type" do - ole_type2 = WIN32OLE_TYPE.new("{13709620-C279-11CE-A49E-444553540000}", "Shell") - ole_type2.should be_kind_of WIN32OLE_TYPE + it "creates WIN32OLE::Type object from CLSID and valid type" do + ole_type2 = WIN32OLE::Type.new("{13709620-C279-11CE-A49E-444553540000}", "Shell") + ole_type2.should be_kind_of WIN32OLE::Type end end diff --git a/spec/ruby/library/win32ole/win32ole_type/ole_classes_spec.rb b/spec/ruby/library/win32ole/win32ole_type/ole_classes_spec.rb index a3a1d4ac58..ed14e37a95 100644 --- a/spec/ruby/library/win32ole/win32ole_type/ole_classes_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_type/ole_classes_spec.rb @@ -2,9 +2,9 @@ require_relative "../../../spec_helper" platform_is :windows do require 'win32ole' - describe "WIN32OLE_TYPE.ole_classes for Shell Controls" do + describe "WIN32OLE::Type.ole_classes for Shell Controls" do before :each do - @ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell") + @ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell") end after :each do @@ -12,7 +12,7 @@ platform_is :windows do end it "returns array of WIN32OLE_TYPEs" do - WIN32OLE_TYPE.ole_classes("Microsoft Shell Controls And Automation").all? {|e| e.kind_of? WIN32OLE_TYPE }.should be_true + WIN32OLE::Type.ole_classes("Microsoft Shell Controls And Automation").all? {|e| e.kind_of? WIN32OLE::Type }.should be_true end end diff --git a/spec/ruby/library/win32ole/win32ole_type/ole_methods_spec.rb b/spec/ruby/library/win32ole/win32ole_type/ole_methods_spec.rb index 3b99b97a61..0c031abaa6 100644 --- a/spec/ruby/library/win32ole/win32ole_type/ole_methods_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_type/ole_methods_spec.rb @@ -2,9 +2,9 @@ require_relative "../../../spec_helper" platform_is :windows do require 'win32ole' - describe "WIN32OLE_TYPE#ole_methods for Shell Controls" do + describe "WIN32OLE::Type#ole_methods for Shell Controls" do before :each do - @ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell") + @ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell") end after :each do @@ -12,7 +12,7 @@ platform_is :windows do end it "returns an Integer" do - @ole_type.ole_methods.all? { |m| m.kind_of? WIN32OLE_METHOD }.should be_true + @ole_type.ole_methods.all? { |m| m.kind_of? WIN32OLE::Method }.should be_true end end diff --git a/spec/ruby/library/win32ole/win32ole_type/ole_type_spec.rb b/spec/ruby/library/win32ole/win32ole_type/ole_type_spec.rb index 24292b1c4f..49c1902f8c 100644 --- a/spec/ruby/library/win32ole/win32ole_type/ole_type_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_type/ole_type_spec.rb @@ -2,9 +2,9 @@ require_relative "../../../spec_helper" platform_is :windows do require 'win32ole' - describe "WIN32OLE_TYPE#ole_type for Shell Controls" do + describe "WIN32OLE::Type#ole_type for Shell Controls" do before :each do - @ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell") + @ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell") end after :each do diff --git a/spec/ruby/library/win32ole/win32ole_type/progid_spec.rb b/spec/ruby/library/win32ole/win32ole_type/progid_spec.rb index 340fdb34e8..9a700426d9 100644 --- a/spec/ruby/library/win32ole/win32ole_type/progid_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_type/progid_spec.rb @@ -2,9 +2,9 @@ require_relative "../../../spec_helper" platform_is :windows do require 'win32ole' - describe "WIN32OLE_TYPE#progid for Shell Controls" do + describe "WIN32OLE::Type#progid for Shell Controls" do before :each do - @ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell") + @ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell") end after :each do diff --git a/spec/ruby/library/win32ole/win32ole_type/progids_spec.rb b/spec/ruby/library/win32ole/win32ole_type/progids_spec.rb index 793535b48d..b1b57960cd 100644 --- a/spec/ruby/library/win32ole/win32ole_type/progids_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_type/progids_spec.rb @@ -2,13 +2,13 @@ require_relative "../../../spec_helper" platform_is :windows do require 'win32ole' - describe "WIN32OLE_TYPE.progids" do + describe "WIN32OLE::Type.progids" do it "raises ArgumentError if an argument is given" do - -> { WIN32OLE_TYPE.progids(1) }.should raise_error ArgumentError + -> { WIN32OLE::Type.progids(1) }.should raise_error ArgumentError end it "returns an array containing 'Shell.Explorer'" do - WIN32OLE_TYPE.progids().include?('Shell.Explorer').should be_true + WIN32OLE::Type.progids().include?('Shell.Explorer').should be_true end end diff --git a/spec/ruby/library/win32ole/win32ole_type/shared/name.rb b/spec/ruby/library/win32ole/win32ole_type/shared/name.rb index 6f37446b23..efae7aeec1 100644 --- a/spec/ruby/library/win32ole/win32ole_type/shared/name.rb +++ b/spec/ruby/library/win32ole/win32ole_type/shared/name.rb @@ -3,7 +3,7 @@ platform_is :windows do describe :win32ole_type_name, shared: true do before :each do - @ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "ShellSpecialFolderConstants") + @ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "ShellSpecialFolderConstants") end it "raises ArgumentError if argument is given" do diff --git a/spec/ruby/library/win32ole/win32ole_type/src_type_spec.rb b/spec/ruby/library/win32ole/win32ole_type/src_type_spec.rb index 3f89fe702a..3c7651cc1f 100644 --- a/spec/ruby/library/win32ole/win32ole_type/src_type_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_type/src_type_spec.rb @@ -2,9 +2,9 @@ require_relative "../../../spec_helper" platform_is :windows do require 'win32ole' - describe "WIN32OLE_TYPE#src_type for Shell Controls" do + describe "WIN32OLE::Type#src_type for Shell Controls" do before :each do - @ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell") + @ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell") end after :each do diff --git a/spec/ruby/library/win32ole/win32ole_type/to_s_spec.rb b/spec/ruby/library/win32ole/win32ole_type/to_s_spec.rb index 9f086a5a35..03a0344fdb 100644 --- a/spec/ruby/library/win32ole/win32ole_type/to_s_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_type/to_s_spec.rb @@ -4,7 +4,7 @@ require_relative 'shared/name' platform_is :windows do require 'win32ole' - describe "WIN32OLE_TYPE#to_s" do + describe "WIN32OLE::Type#to_s" do it_behaves_like :win32ole_type_name, :to_s end diff --git a/spec/ruby/library/win32ole/win32ole_type/typekind_spec.rb b/spec/ruby/library/win32ole/win32ole_type/typekind_spec.rb index 391d505e01..8b62f3e2eb 100644 --- a/spec/ruby/library/win32ole/win32ole_type/typekind_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_type/typekind_spec.rb @@ -2,9 +2,9 @@ require_relative "../../../spec_helper" platform_is :windows do require 'win32ole' - describe "WIN32OLE_TYPE#typekind for Shell Controls" do + describe "WIN32OLE::Type#typekind for Shell Controls" do before :each do - @ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell") + @ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell") end after :each do diff --git a/spec/ruby/library/win32ole/win32ole_type/typelibs_spec.rb b/spec/ruby/library/win32ole/win32ole_type/typelibs_spec.rb index a487208caa..71d7cf00f7 100644 --- a/spec/ruby/library/win32ole/win32ole_type/typelibs_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_type/typelibs_spec.rb @@ -2,9 +2,9 @@ require_relative "../../../spec_helper" platform_is :windows do require 'win32ole' - describe "WIN32OLE_TYPE.typelibs for Shell Controls" do + describe "WIN32OLE::Type.typelibs for Shell Controls" do before :each do - @ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell") + @ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell") end after :each do @@ -12,11 +12,11 @@ platform_is :windows do end it "raises ArgumentError if any argument is give" do - -> { WIN32OLE_TYPE.typelibs(1) }.should raise_error ArgumentError + -> { WIN32OLE::Type.typelibs(1) }.should raise_error ArgumentError end it "returns array of type libraries" do - WIN32OLE_TYPE.typelibs().include?("Microsoft Shell Controls And Automation").should be_true + WIN32OLE::Type.typelibs().include?("Microsoft Shell Controls And Automation").should be_true end end diff --git a/spec/ruby/library/win32ole/win32ole_type/variables_spec.rb b/spec/ruby/library/win32ole/win32ole_type/variables_spec.rb index 7f61b8af95..b1a407523c 100644 --- a/spec/ruby/library/win32ole/win32ole_type/variables_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_type/variables_spec.rb @@ -2,9 +2,9 @@ require_relative "../../../spec_helper" platform_is :windows do require 'win32ole' - describe "WIN32OLE_TYPE#variables for Shell Controls" do + describe "WIN32OLE::Type#variables for Shell Controls" do before :each do - @ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell") + @ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell") end after :each do diff --git a/spec/ruby/library/win32ole/win32ole_type/visible_spec.rb b/spec/ruby/library/win32ole/win32ole_type/visible_spec.rb index 99e34edcdd..05c54c8838 100644 --- a/spec/ruby/library/win32ole/win32ole_type/visible_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_type/visible_spec.rb @@ -2,9 +2,9 @@ require_relative "../../../spec_helper" platform_is :windows do require 'win32ole' - describe "WIN32OLE_TYPE#visible? for Shell Controls" do + describe "WIN32OLE::Type#visible? for Shell Controls" do before :each do - @ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell") + @ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell") end after :each do diff --git a/spec/ruby/library/win32ole/win32ole_variable/ole_type_detail_spec.rb b/spec/ruby/library/win32ole/win32ole_variable/ole_type_detail_spec.rb index 7a9c791494..89576ceedc 100644 --- a/spec/ruby/library/win32ole/win32ole_variable/ole_type_detail_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_variable/ole_type_detail_spec.rb @@ -6,7 +6,7 @@ platform_is :windows do # not sure how WIN32OLE_VARIABLE objects are supposed to be generated # WIN32OLE_VARIABLE.new even seg faults in some cases before :each do - ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "ShellSpecialFolderConstants") + ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "ShellSpecialFolderConstants") @var = ole_type.variables[0] end diff --git a/spec/ruby/library/win32ole/win32ole_variable/ole_type_spec.rb b/spec/ruby/library/win32ole/win32ole_variable/ole_type_spec.rb index 03a9aa4c74..441011f1e7 100644 --- a/spec/ruby/library/win32ole/win32ole_variable/ole_type_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_variable/ole_type_spec.rb @@ -6,7 +6,7 @@ platform_is :windows do # not sure how WIN32OLE_VARIABLE objects are supposed to be generated # WIN32OLE_VARIABLE.new even seg faults in some cases before :each do - ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "ShellSpecialFolderConstants") + ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "ShellSpecialFolderConstants") @var = ole_type.variables[0] end diff --git a/spec/ruby/library/win32ole/win32ole_variable/shared/name.rb b/spec/ruby/library/win32ole/win32ole_variable/shared/name.rb index 033e830fac..d02942ce0a 100644 --- a/spec/ruby/library/win32ole/win32ole_variable/shared/name.rb +++ b/spec/ruby/library/win32ole/win32ole_variable/shared/name.rb @@ -5,7 +5,7 @@ platform_is :windows do # not sure how WIN32OLE_VARIABLE objects are supposed to be generated # WIN32OLE_VARIABLE.new even seg faults in some cases before :each do - ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "ShellSpecialFolderConstants") + ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "ShellSpecialFolderConstants") @var = ole_type.variables[0] end diff --git a/spec/ruby/library/win32ole/win32ole_variable/value_spec.rb b/spec/ruby/library/win32ole/win32ole_variable/value_spec.rb index b7849793c5..d26273ebed 100644 --- a/spec/ruby/library/win32ole/win32ole_variable/value_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_variable/value_spec.rb @@ -6,7 +6,7 @@ platform_is :windows do # not sure how WIN32OLE_VARIABLE objects are supposed to be generated # WIN32OLE_VARIABLE.new even seg faults in some cases before :each do - ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "ShellSpecialFolderConstants") + ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "ShellSpecialFolderConstants") @var = ole_type.variables[0] end diff --git a/spec/ruby/library/win32ole/win32ole_variable/variable_kind_spec.rb b/spec/ruby/library/win32ole/win32ole_variable/variable_kind_spec.rb index 7a79d32ddc..17bc47160a 100644 --- a/spec/ruby/library/win32ole/win32ole_variable/variable_kind_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_variable/variable_kind_spec.rb @@ -6,7 +6,7 @@ platform_is :windows do # not sure how WIN32OLE_VARIABLE objects are supposed to be generated # WIN32OLE_VARIABLE.new even seg faults in some cases before :each do - ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "ShellSpecialFolderConstants") + ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "ShellSpecialFolderConstants") @var = ole_type.variables[0] end diff --git a/spec/ruby/library/win32ole/win32ole_variable/varkind_spec.rb b/spec/ruby/library/win32ole/win32ole_variable/varkind_spec.rb index 9d7b8238c8..c5f8164509 100644 --- a/spec/ruby/library/win32ole/win32ole_variable/varkind_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_variable/varkind_spec.rb @@ -7,7 +7,7 @@ platform_is :windows do # not sure how WIN32OLE_VARIABLE objects are supposed to be generated # WIN32OLE_VARIABLE.new even seg faults in some cases before :each do - ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "ShellSpecialFolderConstants") + ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "ShellSpecialFolderConstants") @var = ole_type.variables[0] end diff --git a/spec/ruby/library/win32ole/win32ole_variable/visible_spec.rb b/spec/ruby/library/win32ole/win32ole_variable/visible_spec.rb index 60252e8139..ba53a81de0 100644 --- a/spec/ruby/library/win32ole/win32ole_variable/visible_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_variable/visible_spec.rb @@ -6,7 +6,7 @@ platform_is :windows do # not sure how WIN32OLE_VARIABLE objects are supposed to be generated # WIN32OLE_VARIABLE.new even seg faults in some cases before :each do - ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "ShellSpecialFolderConstants") + ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "ShellSpecialFolderConstants") @var = ole_type.variables[0] end diff --git a/spec/ruby/library/yaml/dump_spec.rb b/spec/ruby/library/yaml/dump_spec.rb index 3107a8f51d..97b665d6a5 100644 --- a/spec/ruby/library/yaml/dump_spec.rb +++ b/spec/ruby/library/yaml/dump_spec.rb @@ -1,17 +1,21 @@ require_relative '../../spec_helper' -require_relative 'fixtures/common' -# TODO: WTF is this using a global? +require 'yaml' + describe "YAML.dump" do + before :each do + @test_file = tmp("yaml_test_file") + end + after :each do - rm_r $test_file + rm_r @test_file end it "converts an object to YAML and write result to io when io provided" do - File.open($test_file, 'w' ) do |io| + File.open(@test_file, 'w' ) do |io| YAML.dump( ['badger', 'elephant', 'tiger'], io ) end - YAML.load_file($test_file).should == ['badger', 'elephant', 'tiger'] + YAML.load_file(@test_file).should == ['badger', 'elephant', 'tiger'] end it "returns a string containing dumped YAML when no io provided" do @@ -35,7 +39,11 @@ describe "YAML.dump" do end it "dumps an OpenStruct" do - require "ostruct" + begin + require "ostruct" + rescue LoadError + skip "OpenStruct is not available" + end os = OpenStruct.new("age" => 20, "name" => "John") yaml_dump = YAML.dump(os) diff --git a/spec/ruby/library/yaml/dump_stream_spec.rb b/spec/ruby/library/yaml/dump_stream_spec.rb index 9d30fef819..f0578fa800 100644 --- a/spec/ruby/library/yaml/dump_stream_spec.rb +++ b/spec/ruby/library/yaml/dump_stream_spec.rb @@ -1,5 +1,6 @@ require_relative '../../spec_helper' -require_relative 'fixtures/common' + +require 'yaml' describe "YAML.dump_stream" do it "returns a YAML stream containing the objects passed" do diff --git a/spec/ruby/library/yaml/fixtures/common.rb b/spec/ruby/library/yaml/fixtures/common.rb deleted file mode 100644 index f7fb4037e7..0000000000 --- a/spec/ruby/library/yaml/fixtures/common.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'yaml' - -$test_file = tmp("yaml_test_file") -$test_parse_file = File.dirname(__FILE__) + "/test_yaml.yml" diff --git a/spec/ruby/library/yaml/fixtures/strings.rb b/spec/ruby/library/yaml/fixtures/strings.rb index 6f66dc3659..f478f89823 100644 --- a/spec/ruby/library/yaml/fixtures/strings.rb +++ b/spec/ruby/library/yaml/fixtures/strings.rb @@ -1,36 +1,26 @@ -$complex_key_1 = <<EOY - ? # PLAY SCHEDULE - - Detroit Tigers - - Chicago Cubs - : - - 2001-07-23 +module YAMLSpecs + COMPLEX_KEY_1 = <<~EOY + ? # PLAY SCHEDULE + - Detroit Tigers + - Chicago Cubs + : + - 2001-07-23 - ? [ New York Yankees, - Atlanta Braves ] - : [ 2001-07-02, 2001-08-12, - 2001-08-14 ] -EOY + ? [ New York Yankees, + Atlanta Braves ] + : [ 2001-07-02, 2001-08-12, + 2001-08-14 ] + EOY -$to_yaml_hash = -<<EOY -- - avg: 0.278 - hr: 65 - name: Mark McGwire -- - avg: 0.288 - hr: 63 - name: Sammy Sosa -EOY + MULTIDOCUMENT = <<~EOY + --- + - Mark McGwire + - Sammy Sosa + - Ken Griffey -$multidocument = <<EOY ---- -- Mark McGwire -- Sammy Sosa -- Ken Griffey - -# Team ranking ---- -- Chicago Cubs -- St Louis Cardinals -EOY + # Team ranking + --- + - Chicago Cubs + - St Louis Cardinals + EOY +end diff --git a/spec/ruby/library/yaml/load_file_spec.rb b/spec/ruby/library/yaml/load_file_spec.rb index 2363c08120..4941d0485b 100644 --- a/spec/ruby/library/yaml/load_file_spec.rb +++ b/spec/ruby/library/yaml/load_file_spec.rb @@ -1,13 +1,18 @@ require_relative '../../spec_helper' -require_relative 'fixtures/common' + +require 'yaml' describe "YAML.load_file" do + before :each do + @test_file = tmp("yaml_test_file") + end + after :each do - rm_r $test_file + rm_r @test_file end it "returns a hash" do - File.open($test_file,'w' ){|io| YAML.dump( {"bar"=>2, "car"=>1}, io ) } - YAML.load_file($test_file).should == {"bar"=>2, "car"=>1} + File.open(@test_file,'w' ){|io| YAML.dump( {"bar"=>2, "car"=>1}, io ) } + YAML.load_file(@test_file).should == {"bar"=>2, "car"=>1} end end diff --git a/spec/ruby/library/yaml/load_stream_spec.rb b/spec/ruby/library/yaml/load_stream_spec.rb index 689653c8cd..31bc862f5e 100644 --- a/spec/ruby/library/yaml/load_stream_spec.rb +++ b/spec/ruby/library/yaml/load_stream_spec.rb @@ -1,8 +1,9 @@ require_relative '../../spec_helper' -require_relative 'fixtures/common' require_relative 'fixtures/strings' require_relative 'shared/each_document' +require 'yaml' + describe "YAML.load_stream" do it_behaves_like :yaml_each_document, :load_stream end diff --git a/spec/ruby/library/yaml/parse_file_spec.rb b/spec/ruby/library/yaml/parse_file_spec.rb index 8c59a2d7ef..7bffcdc62f 100644 --- a/spec/ruby/library/yaml/parse_file_spec.rb +++ b/spec/ruby/library/yaml/parse_file_spec.rb @@ -1,8 +1,10 @@ require_relative '../../spec_helper' -require_relative 'fixtures/common' -describe "YAML#parse_file" do +require 'yaml' + +describe "YAML.parse_file" do it "returns a YAML::Syck::Map object after parsing a YAML file" do - YAML.parse_file($test_parse_file).should be_kind_of(Psych::Nodes::Document) + test_parse_file = fixture __FILE__, "test_yaml.yml" + YAML.parse_file(test_parse_file).should be_kind_of(Psych::Nodes::Document) end end diff --git a/spec/ruby/library/yaml/parse_spec.rb b/spec/ruby/library/yaml/parse_spec.rb index d5dbfdcee2..37e2b7fa0a 100644 --- a/spec/ruby/library/yaml/parse_spec.rb +++ b/spec/ruby/library/yaml/parse_spec.rb @@ -1,13 +1,14 @@ require_relative '../../spec_helper' -require_relative 'fixtures/common' -describe "YAML#parse with an empty string" do +require 'yaml' + +describe "YAML.parse with an empty string" do it "returns false" do YAML.parse('').should be_false end end -describe "YAML#parse" do +describe "YAML.parse" do before :each do @string_yaml = "foo".to_yaml end diff --git a/spec/ruby/library/yaml/shared/each_document.rb b/spec/ruby/library/yaml/shared/each_document.rb index 999123dc2a..6f00aee297 100644 --- a/spec/ruby/library/yaml/shared/each_document.rb +++ b/spec/ruby/library/yaml/shared/each_document.rb @@ -1,7 +1,7 @@ describe :yaml_each_document, shared: true do it "calls the block on each successive document" do documents = [] - YAML.send(@method, $multidocument) do |doc| + YAML.send(@method, YAMLSpecs::MULTIDOCUMENT) do |doc| documents << doc end documents.should == [["Mark McGwire", "Sammy Sosa", "Ken Griffey"], @@ -9,7 +9,8 @@ describe :yaml_each_document, shared: true do end it "works on files" do - File.open($test_parse_file, "r") do |file| + test_parse_file = fixture __FILE__, "test_yaml.yml" + File.open(test_parse_file, "r") do |file| YAML.send(@method, file) do |doc| doc.should == {"project"=>{"name"=>"RubySpec"}} end diff --git a/spec/ruby/library/yaml/shared/load.rb b/spec/ruby/library/yaml/shared/load.rb index 185a5a60cd..b8bb605b0a 100644 --- a/spec/ruby/library/yaml/shared/load.rb +++ b/spec/ruby/library/yaml/shared/load.rb @@ -1,14 +1,16 @@ -require_relative '../fixtures/common' require_relative '../fixtures/strings' +require 'yaml' + describe :yaml_load_safe, shared: true do it "returns a document from current io stream when io provided" do - File.open($test_file, 'w') do |io| + @test_file = tmp("yaml_test_file") + File.open(@test_file, 'w') do |io| YAML.dump( ['badger', 'elephant', 'tiger'], io ) end - File.open($test_file) { |yf| YAML.send(@method, yf ) }.should == ['badger', 'elephant', 'tiger'] + File.open(@test_file) { |yf| YAML.send(@method, yf ) }.should == ['badger', 'elephant', 'tiger'] ensure - rm_r $test_file + rm_r @test_file end it "loads strings" do @@ -104,7 +106,7 @@ describe :yaml_load_unsafe, shared: true do Date.new( 2001, 8, 12 ), Date.new( 2001, 8, 14 ) ] } - YAML.send(@method, $complex_key_1).should == expected + YAML.send(@method, YAMLSpecs::COMPLEX_KEY_1).should == expected end describe "with iso8601 timestamp" do @@ -121,7 +123,11 @@ describe :yaml_load_unsafe, shared: true do end it "loads an OpenStruct" do - require "ostruct" + begin + require "ostruct" + rescue LoadError + skip "OpenStruct is not available" + end os = OpenStruct.new("age" => 20, "name" => "John") loaded = YAML.send(@method, "--- !ruby/object:OpenStruct\ntable:\n :age: 20\n :name: John\n") loaded.should == os diff --git a/spec/ruby/library/yaml/to_yaml_spec.rb b/spec/ruby/library/yaml/to_yaml_spec.rb index 8e80b02cb4..08c5451416 100644 --- a/spec/ruby/library/yaml/to_yaml_spec.rb +++ b/spec/ruby/library/yaml/to_yaml_spec.rb @@ -1,7 +1,8 @@ require_relative '../../spec_helper' -require_relative 'fixtures/common' require_relative 'fixtures/example_class' +require 'yaml' + describe "Object#to_yaml" do it "returns the YAML representation of an Array object" do @@ -12,13 +13,21 @@ describe "Object#to_yaml" do { "a" => "b"}.to_yaml.should match_yaml("--- \na: b\n") end - it "returns the YAML representation of a Class object" do + it "returns the YAML representation of an object" do YAMLSpecs::Example.new("baz").to_yaml.should match_yaml("--- !ruby/object:YAMLSpecs::Example\nname: baz\n") end + it "returns the YAML representation of a Class object" do + YAMLSpecs::Example.to_yaml.should match_yaml("--- !ruby/class 'YAMLSpecs::Example'\n") + end + + it "returns the YAML representation of a Module object" do + Enumerable.to_yaml.should match_yaml("--- !ruby/module 'Enumerable'\n") + end + it "returns the YAML representation of a Date object" do require 'date' - Date.parse('1997/12/30').to_yaml.should match_yaml("--- 1997-12-30\n") + Date.new(1997, 12, 30).to_yaml.should match_yaml("--- 1997-12-30\n") end it "returns the YAML representation of a FalseClass" do @@ -56,6 +65,13 @@ describe "Object#to_yaml" do it "returns the YAML representation of a Struct object" do Person = Struct.new(:name, :gender) Person.new("Jane", "female").to_yaml.should match_yaml("--- !ruby/struct:Person\nname: Jane\ngender: female\n") + ensure + Object.send(:remove_const, :Person) + end + + it "returns the YAML representation of an unnamed Struct object" do + person = Struct.new(:name, :gender) + person.new("Jane", "female").to_yaml.should match_yaml("--- !ruby/struct\nname: Jane\ngender: female\n") end it "returns the YAML representation of a Symbol object" do diff --git a/spec/ruby/library/zlib/deflate/deflate_spec.rb b/spec/ruby/library/zlib/deflate/deflate_spec.rb index 50a563ef6f..e16e6ad0ef 100644 --- a/spec/ruby/library/zlib/deflate/deflate_spec.rb +++ b/spec/ruby/library/zlib/deflate/deflate_spec.rb @@ -23,7 +23,7 @@ describe "Zlib::Deflate.deflate" do it "deflates chunked data" do random_generator = Random.new(0) - deflated = '' + deflated = +'' Zlib::Deflate.deflate(random_generator.bytes(20000)) do |chunk| deflated << chunk @@ -70,7 +70,7 @@ describe "Zlib::Deflate#deflate" do before :each do @deflator = Zlib::Deflate.new @random_generator = Random.new(0) - @original = '' + @original = +'' @chunks = [] end diff --git a/spec/ruby/library/zlib/deflate/new_spec.rb b/spec/ruby/library/zlib/deflate/new_spec.rb deleted file mode 100644 index e15f14f95f..0000000000 --- a/spec/ruby/library/zlib/deflate/new_spec.rb +++ /dev/null @@ -1 +0,0 @@ -require_relative '../../../spec_helper' diff --git a/spec/ruby/library/zlib/deflate/params_spec.rb b/spec/ruby/library/zlib/deflate/params_spec.rb index 0b1cca8c8a..0242653528 100644 --- a/spec/ruby/library/zlib/deflate/params_spec.rb +++ b/spec/ruby/library/zlib/deflate/params_spec.rb @@ -3,7 +3,7 @@ require 'zlib' describe "Zlib::Deflate#params" do it "changes the deflate parameters" do - data = 'abcdefghijklm' + data = +'abcdefghijklm' d = Zlib::Deflate.new Zlib::NO_COMPRESSION, Zlib::MAX_WBITS, Zlib::DEF_MEM_LEVEL, Zlib::DEFAULT_STRATEGY diff --git a/spec/ruby/library/zlib/gzipreader/each_char_spec.rb b/spec/ruby/library/zlib/gzipreader/each_char_spec.rb new file mode 100644 index 0000000000..de6396da7e --- /dev/null +++ b/spec/ruby/library/zlib/gzipreader/each_char_spec.rb @@ -0,0 +1,51 @@ +require_relative '../../../spec_helper' +require 'stringio' +require 'zlib' + +describe "Zlib::GzipReader#each_char" do + + before :each do + @data = '12345abcde' + @zip = [31, 139, 8, 0, 44, 220, 209, 71, 0, 3, 51, 52, 50, 54, 49, 77, + 76, 74, 78, 73, 5, 0, 157, 5, 0, 36, 10, 0, 0, 0].pack('C*') + + @io = StringIO.new @zip + ScratchPad.clear + end + + it "calls the given block for each char in the stream, passing the char as an argument" do + gz = Zlib::GzipReader.new @io + + ScratchPad.record [] + gz.each_char { |b| ScratchPad << b } + + ScratchPad.recorded.should == ["1", "2", "3", "4", "5", "a", "b", "c", "d", "e"] + end + + it "returns an enumerator, which yields each char in the stream, when no block is passed" do + gz = Zlib::GzipReader.new @io + enum = gz.each_char + + ScratchPad.record [] + while true + begin + ScratchPad << enum.next + rescue StopIteration + break + end + end + + ScratchPad.recorded.should == ["1", "2", "3", "4", "5", "a", "b", "c", "d", "e"] + end + + it "increments position before calling the block" do + gz = Zlib::GzipReader.new @io + + i = 1 + gz.each_char do |ignore| + gz.pos.should == i + i += 1 + end + end + +end diff --git a/spec/ruby/library/zlib/gzipreader/mtime_spec.rb b/spec/ruby/library/zlib/gzipreader/mtime_spec.rb new file mode 100644 index 0000000000..e8e71fa72e --- /dev/null +++ b/spec/ruby/library/zlib/gzipreader/mtime_spec.rb @@ -0,0 +1,11 @@ +require_relative '../../../spec_helper' +require 'zlib' +require 'stringio' + +describe "Zlib::GzipReader#mtime" do + it "returns the timestamp from the Gzip header" do + io = StringIO.new "\x1f\x8b\x08\x00\x44\x33\x22\x11\x00\xff\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00" + gz = Zlib::GzipReader.new(io) + gz.mtime.to_i.should == 0x11223344 + end +end diff --git a/spec/ruby/library/zlib/gzipreader/new_spec.rb b/spec/ruby/library/zlib/gzipreader/new_spec.rb deleted file mode 100644 index e15f14f95f..0000000000 --- a/spec/ruby/library/zlib/gzipreader/new_spec.rb +++ /dev/null @@ -1 +0,0 @@ -require_relative '../../../spec_helper' diff --git a/spec/ruby/library/zlib/inflate/inflate_spec.rb b/spec/ruby/library/zlib/inflate/inflate_spec.rb index 79b72bf91c..b308a4ba67 100644 --- a/spec/ruby/library/zlib/inflate/inflate_spec.rb +++ b/spec/ruby/library/zlib/inflate/inflate_spec.rb @@ -72,7 +72,7 @@ describe "Zlib::Inflate.inflate" do data = [120, 156, 75, 203, 207, 7, 0, 2, 130, 1, 69].pack('C*') z = Zlib::Inflate.new # add bytes, one by one - result = "" + result = +"" data.each_byte { |d| result << z.inflate(d.chr)} result << z.finish result.should == "foo" @@ -82,7 +82,7 @@ describe "Zlib::Inflate.inflate" do data = [120, 156, 75, 203, 207, 7, 0, 2, 130, 1, 69].pack('C*')[0,5] z = Zlib::Inflate.new # add bytes, one by one, but not all - result = "" + result = +"" data.each_byte { |d| result << z.inflate(d.chr)} -> { result << z.finish }.should raise_error(Zlib::BufError) end @@ -90,7 +90,7 @@ describe "Zlib::Inflate.inflate" do it "properly handles excessive data, byte-by-byte" do main_data = [120, 156, 75, 203, 207, 7, 0, 2, 130, 1, 69].pack('C*') data = main_data * 2 - result = "" + result = +"" z = Zlib::Inflate.new # add bytes, one by one @@ -105,7 +105,7 @@ describe "Zlib::Inflate.inflate" do it "properly handles excessive data, in one go" do main_data = [120, 156, 75, 203, 207, 7, 0, 2, 130, 1, 69].pack('C*') data = main_data * 2 - result = "" + result = +"" z = Zlib::Inflate.new result << z.inflate(data) diff --git a/spec/ruby/library/zlib/inflate/new_spec.rb b/spec/ruby/library/zlib/inflate/new_spec.rb deleted file mode 100644 index e15f14f95f..0000000000 --- a/spec/ruby/library/zlib/inflate/new_spec.rb +++ /dev/null @@ -1 +0,0 @@ -require_relative '../../../spec_helper' diff --git a/spec/ruby/library/zlib/inflate/set_dictionary_spec.rb b/spec/ruby/library/zlib/inflate/set_dictionary_spec.rb index 251cec44bb..375ee3c765 100644 --- a/spec/ruby/library/zlib/inflate/set_dictionary_spec.rb +++ b/spec/ruby/library/zlib/inflate/set_dictionary_spec.rb @@ -1,4 +1,4 @@ -# -*- encoding: binary -*- +# encoding: binary require_relative '../../../spec_helper' require 'zlib' |
