diff options
Diffstat (limited to 'spec/ruby/library')
1063 files changed, 10179 insertions, 10373 deletions
diff --git a/spec/ruby/library/English/English_spec.rb b/spec/ruby/library/English/English_spec.rb index 4d615d1e25..bdc3774608 100644 --- a/spec/ruby/library/English/English_spec.rb +++ b/spec/ruby/library/English/English_spec.rb @@ -7,26 +7,26 @@ describe "English" do begin raise "error" rescue - $ERROR_INFO.should_not be_nil + $ERROR_INFO.should_not == nil $ERROR_INFO.should == $! end - $ERROR_INFO.should be_nil + $ERROR_INFO.should == nil end it "aliases $ERROR_POSITION to $@" do begin raise "error" rescue - $ERROR_POSITION.should_not be_nil + $ERROR_POSITION.should_not == nil $ERROR_POSITION.should == $@ end - $ERROR_POSITION.should be_nil + $ERROR_POSITION.should == nil end it "aliases $FS to $;" do original = $; suppress_warning {$; = ","} - $FS.should_not be_nil + $FS.should_not == nil $FS.should == $; suppress_warning {$; = original} end @@ -34,7 +34,7 @@ describe "English" do it "aliases $FIELD_SEPARATOR to $;" do original = $; suppress_warning {$; = ","} - $FIELD_SEPARATOR.should_not be_nil + $FIELD_SEPARATOR.should_not == nil $FIELD_SEPARATOR.should == $; suppress_warning {$; = original} end @@ -42,7 +42,7 @@ describe "English" do it "aliases $OFS to $," do original = $, suppress_warning {$, = "|"} - $OFS.should_not be_nil + $OFS.should_not == nil $OFS.should == $, suppress_warning {$, = original} end @@ -50,25 +50,25 @@ describe "English" do it "aliases $OUTPUT_FIELD_SEPARATOR to $," do original = $, suppress_warning {$, = "|"} - $OUTPUT_FIELD_SEPARATOR.should_not be_nil + $OUTPUT_FIELD_SEPARATOR.should_not == nil $OUTPUT_FIELD_SEPARATOR.should == $, suppress_warning {$, = original} end it "aliases $RS to $/" do - $RS.should_not be_nil + $RS.should_not == nil $RS.should == $/ end it "aliases $INPUT_RECORD_SEPARATOR to $/" do - $INPUT_RECORD_SEPARATOR.should_not be_nil + $INPUT_RECORD_SEPARATOR.should_not == nil $INPUT_RECORD_SEPARATOR.should == $/ end it "aliases $ORS to $\\" do original = $\ suppress_warning {$\ = "\t"} - $ORS.should_not be_nil + $ORS.should_not == nil $ORS.should == $\ suppress_warning {$\ = original} end @@ -76,98 +76,86 @@ describe "English" do it "aliases $OUTPUT_RECORD_SEPARATOR to $\\" do original = $\ suppress_warning {$\ = "\t"} - $OUTPUT_RECORD_SEPARATOR.should_not be_nil + $OUTPUT_RECORD_SEPARATOR.should_not == nil $OUTPUT_RECORD_SEPARATOR.should == $\ suppress_warning {$\ = original} end it "aliases $INPUT_LINE_NUMBER to $." do - $INPUT_LINE_NUMBER.should_not be_nil + $INPUT_LINE_NUMBER.should_not == nil $INPUT_LINE_NUMBER.should == $. end it "aliases $NR to $." do - $NR.should_not be_nil + $NR.should_not == nil $NR.should == $. end it "aliases $LAST_READ_LINE to $_ needs to be reviewed for spec completeness" it "aliases $DEFAULT_OUTPUT to $>" do - $DEFAULT_OUTPUT.should_not be_nil + $DEFAULT_OUTPUT.should_not == nil $DEFAULT_OUTPUT.should == $> end it "aliases $DEFAULT_INPUT to $<" do - $DEFAULT_INPUT.should_not be_nil + $DEFAULT_INPUT.should_not == nil $DEFAULT_INPUT.should == $< end it "aliases $PID to $$" do - $PID.should_not be_nil + $PID.should_not == nil $PID.should == $$ end it "aliases $PID to $$" do - $PID.should_not be_nil + $PID.should_not == nil $PID.should == $$ end it "aliases $PROCESS_ID to $$" do - $PROCESS_ID.should_not be_nil + $PROCESS_ID.should_not == nil $PROCESS_ID.should == $$ end it "aliases $CHILD_STATUS to $?" do ruby_exe('exit 0') - $CHILD_STATUS.should_not be_nil + $CHILD_STATUS.should_not == nil $CHILD_STATUS.should == $? end it "aliases $LAST_MATCH_INFO to $~" do /c(a)t/ =~ "cat" - $LAST_MATCH_INFO.should_not be_nil + $LAST_MATCH_INFO.should_not == nil $LAST_MATCH_INFO.should == $~ end - 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 - it "aliases $ARGV to $*" do - $ARGV.should_not be_nil + $ARGV.should_not == nil $ARGV.should == $* end it "aliases $MATCH to $&" do /c(a)t/ =~ "cat" - $MATCH.should_not be_nil + $MATCH.should_not == nil $MATCH.should == $& end it "aliases $PREMATCH to $`" do /c(a)t/ =~ "cat" - $PREMATCH.should_not be_nil + $PREMATCH.should_not == nil $PREMATCH.should == $` end it "aliases $POSTMATCH to $'" do /c(a)t/ =~ "cat" - $POSTMATCH.should_not be_nil + $POSTMATCH.should_not == nil $POSTMATCH.should == $' end it "aliases $LAST_PAREN_MATCH to $+" do /c(a)t/ =~ "cat" - $LAST_PAREN_MATCH.should_not be_nil + $LAST_PAREN_MATCH.should_not == nil $LAST_PAREN_MATCH.should == $+ end end diff --git a/spec/ruby/library/English/alias_spec.rb b/spec/ruby/library/English/alias_spec.rb index 78ccfb4398..3ff92f964d 100644 --- a/spec/ruby/library/English/alias_spec.rb +++ b/spec/ruby/library/English/alias_spec.rb @@ -4,11 +4,11 @@ require 'English' describe "English" do it "aliases $! to $ERROR_INFO and $ERROR_INFO still returns an Exception with a backtrace" do exception = (1 / 0 rescue $ERROR_INFO) - exception.should be_kind_of(Exception) - exception.backtrace.should be_kind_of(Array) + exception.should.is_a?(Exception) + exception.backtrace.should.is_a?(Array) end it "aliases $@ to $ERROR_POSITION and $ERROR_POSITION still returns a backtrace" do - (1 / 0 rescue $ERROR_POSITION).should be_kind_of(Array) + (1 / 0 rescue $ERROR_POSITION).should.is_a?(Array) end end diff --git a/spec/ruby/library/base64/strict_decode64_spec.rb b/spec/ruby/library/base64/strict_decode64_spec.rb index d258223c82..7b52f0c922 100644 --- a/spec/ruby/library/base64/strict_decode64_spec.rb +++ b/spec/ruby/library/base64/strict_decode64_spec.rb @@ -14,25 +14,25 @@ describe "Base64#strict_decode64" do it "raises ArgumentError when the given string contains CR" do -> do Base64.strict_decode64("U2VuZCByZWluZm9yY2VtZW50cw==\r") - end.should raise_error(ArgumentError) + end.should.raise(ArgumentError) end it "raises ArgumentError when the given string contains LF" do -> do Base64.strict_decode64("U2VuZCByZWluZm9yY2VtZW50cw==\n") - end.should raise_error(ArgumentError) + end.should.raise(ArgumentError) end it "raises ArgumentError when the given string has wrong padding" do -> do Base64.strict_decode64("=U2VuZCByZWluZm9yY2VtZW50cw==") - end.should raise_error(ArgumentError) + end.should.raise(ArgumentError) end it "raises ArgumentError when the given string contains an invalid character" do -> do Base64.strict_decode64("%3D") - end.should raise_error(ArgumentError) + end.should.raise(ArgumentError) end it "returns a binary encoded string" do diff --git a/spec/ruby/library/bigdecimal/BigDecimal_spec.rb b/spec/ruby/library/bigdecimal/BigDecimal_spec.rb index 45f5ebffc7..6adebabe84 100644 --- a/spec/ruby/library/bigdecimal/BigDecimal_spec.rb +++ b/spec/ruby/library/bigdecimal/BigDecimal_spec.rb @@ -10,7 +10,7 @@ end describe "Kernel#BigDecimal" do it "creates a new object of class BigDecimal" do - BigDecimal("3.14159").should be_kind_of(BigDecimal) + BigDecimal("3.14159").should.is_a?(BigDecimal) (0..9).each {|i| BigDecimal("1#{i}").should == 10 + i BigDecimal("-1#{i}").should == -10 - i @@ -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 @@ -57,15 +53,15 @@ describe "Kernel#BigDecimal" do end it "does not ignores trailing garbage" do - -> { BigDecimal("123E45ruby") }.should raise_error(ArgumentError) - -> { BigDecimal("123x45") }.should raise_error(ArgumentError) - -> { BigDecimal("123.4%E5") }.should raise_error(ArgumentError) - -> { BigDecimal("1E2E3E4E5E") }.should raise_error(ArgumentError) + -> { BigDecimal("123E45ruby") }.should.raise(ArgumentError) + -> { BigDecimal("123x45") }.should.raise(ArgumentError) + -> { BigDecimal("123.4%E5") }.should.raise(ArgumentError) + -> { BigDecimal("1E2E3E4E5E") }.should.raise(ArgumentError) end it "raises ArgumentError for invalid strings" do - -> { BigDecimal("ruby") }.should raise_error(ArgumentError) - -> { BigDecimal(" \t\n \r-\t\t\tInfinity \n") }.should raise_error(ArgumentError) + -> { BigDecimal("ruby") }.should.raise(ArgumentError) + -> { BigDecimal(" \t\n \r-\t\t\tInfinity \n") }.should.raise(ArgumentError) end it "allows omitting the integer part" do @@ -76,8 +72,8 @@ describe "Kernel#BigDecimal" do reference = BigDecimal("12345.67E89") BigDecimal("12_345.67E89").should == reference - -> { BigDecimal("1_2_3_4_5_._6____7_E89") }.should raise_error(ArgumentError) - -> { BigDecimal("12345_.67E_8__9_") }.should raise_error(ArgumentError) + -> { BigDecimal("1_2_3_4_5_._6____7_E89") }.should.raise(ArgumentError) + -> { BigDecimal("12345_.67E_8__9_") }.should.raise(ArgumentError) end it "accepts NaN and [+-]Infinity" do @@ -95,13 +91,13 @@ describe "Kernel#BigDecimal" do describe "with exception: false" do it "returns nil for invalid strings" do - BigDecimal("invalid", exception: false).should be_nil - BigDecimal("0invalid", exception: false).should be_nil - BigDecimal("invalid0", exception: false).should be_nil + BigDecimal("invalid", exception: false).should == nil + BigDecimal("0invalid", exception: false).should == nil + BigDecimal("invalid0", exception: false).should == nil if BigDecimal::VERSION >= "3.1.9" BigDecimal("0.", exception: false).to_i.should == 0 else - BigDecimal("0.", exception: false).should be_nil + BigDecimal("0.", exception: false).should == nil end end end @@ -156,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 @@ -206,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 @@ -224,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 @@ -259,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 542713011d..a4237298f4 100644 --- a/spec/ruby/library/bigdecimal/add_spec.rb +++ b/spec/ruby/library/bigdecimal/add_spec.rb @@ -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") @@ -173,21 +165,21 @@ describe "BigDecimal#add" do it "raises TypeError when adds nil" do -> { @one.add(nil, 10) - }.should raise_error(TypeError) + }.should.raise(TypeError) -> { @one.add(nil, 0) - }.should raise_error(TypeError) + }.should.raise(TypeError) end it "raises TypeError when precision parameter is nil" do -> { @one.add(@one, nil) - }.should raise_error(TypeError) + }.should.raise(TypeError) end it "raises ArgumentError when precision parameter is negative" do -> { @one.add(@one, -10) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) end end diff --git a/spec/ruby/library/bigdecimal/case_compare_spec.rb b/spec/ruby/library/bigdecimal/case_compare_spec.rb index fac6714356..1f1d223d6a 100644 --- a/spec/ruby/library/bigdecimal/case_compare_spec.rb +++ b/spec/ruby/library/bigdecimal/case_compare_spec.rb @@ -1,7 +1,9 @@ require_relative '../../spec_helper' -require_relative 'shared/eql' +require 'bigdecimal' describe "BigDecimal#===" do - it_behaves_like :bigdecimal_eql, :=== + it "is an alias of BigDecimal#==" do + BigDecimal.instance_method(:===).should == BigDecimal.instance_method(:==) + end end diff --git a/spec/ruby/library/bigdecimal/ceil_spec.rb b/spec/ruby/library/bigdecimal/ceil_spec.rb index 60e71b12fb..3d94b8e578 100644 --- a/spec/ruby/library/bigdecimal/ceil_spec.rb +++ b/spec/ruby/library/bigdecimal/ceil_spec.rb @@ -48,9 +48,9 @@ describe "BigDecimal#ceil" do end it "raise exception, if self is special value" do - -> { @infinity.ceil }.should raise_error(FloatDomainError) - -> { @infinity_neg.ceil }.should raise_error(FloatDomainError) - -> { @nan.ceil }.should raise_error(FloatDomainError) + -> { @infinity.ceil }.should.raise(FloatDomainError) + -> { @infinity_neg.ceil }.should.raise(FloatDomainError) + -> { @nan.ceil }.should.raise(FloatDomainError) end it "returns n digits right of the decimal point if given n > 0" do diff --git a/spec/ruby/library/bigdecimal/clone_spec.rb b/spec/ruby/library/bigdecimal/clone_spec.rb index b3a1c61d6a..979cc4c8e9 100644 --- a/spec/ruby/library/bigdecimal/clone_spec.rb +++ b/spec/ruby/library/bigdecimal/clone_spec.rb @@ -1,6 +1,8 @@ require_relative '../../spec_helper' -require_relative 'shared/clone' +require 'bigdecimal' -describe "BigDecimal#dup" do - it_behaves_like :bigdecimal_clone, :clone +describe "BigDecimal#clone" do + it "is an alias of BigDecimal#dup" do + BigDecimal.instance_method(:clone).should == BigDecimal.instance_method(:dup) + end end diff --git a/spec/ruby/library/bigdecimal/constants_spec.rb b/spec/ruby/library/bigdecimal/constants_spec.rb index 8d879c036a..f2cc42dfc9 100644 --- a/spec/ruby/library/bigdecimal/constants_spec.rb +++ b/spec/ruby/library/bigdecimal/constants_spec.rb @@ -3,17 +3,17 @@ require 'bigdecimal' describe "BigDecimal constants" do it "defines a VERSION value" do - BigDecimal.const_defined?(:VERSION).should be_true + BigDecimal.const_defined?(:VERSION).should == true end it "has a BASE value" do # The actual one is decided based on HAVE_INT64_T in MRI, # which is hard to check here. - [10000, 1000000000].should include(BigDecimal::BASE) + [10000, 1000000000].should.include?(BigDecimal::BASE) end it "has a NaN value" do - BigDecimal::NAN.nan?.should be_true + BigDecimal::NAN.nan?.should == true end it "has an INFINITY value" do diff --git a/spec/ruby/library/bigdecimal/core_spec.rb b/spec/ruby/library/bigdecimal/core_spec.rb index acee4dcf56..8f64fdf388 100644 --- a/spec/ruby/library/bigdecimal/core_spec.rb +++ b/spec/ruby/library/bigdecimal/core_spec.rb @@ -20,9 +20,12 @@ describe "Core extension by bigdecimal" do describe "BigDecimal#log" do it "handles high-precision Rational arguments" do - result = BigDecimal('0.22314354220170971436137296411949880462556361100856391620766259404746040597133837784E0') + # 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) - BigMath.log(r, 50).should == result + [result1, result2].should.include?(BigMath.log(r, 50).mult(1, 50)) end end @@ -30,15 +33,15 @@ describe "Core extension by bigdecimal" 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 + result.first.is_a?(Float).should == true + result.last.is_a?(Float).should == 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 + result.first.is_a?(Rational).should == true + result.last.is_a?(Rational).should == true end it "coerces to Rational, when given a Complex" do @@ -53,7 +56,7 @@ describe "Core extension by bigdecimal" do 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/) + }.should.raise(TypeError, /BigDecimal can't be coerced into Rational/) end end end diff --git a/spec/ruby/library/bigdecimal/div_spec.rb b/spec/ruby/library/bigdecimal/div_spec.rb index 53ad6d0418..967d8b5221 100644 --- a/spec/ruby/library/bigdecimal/div_spec.rb +++ b/spec/ruby/library/bigdecimal/div_spec.rb @@ -51,9 +51,9 @@ describe "BigDecimal#div" do end it "raises FloatDomainError if NaN is involved" do - -> { @one.div(@nan) }.should raise_error(FloatDomainError) - -> { @nan.div(@one) }.should raise_error(FloatDomainError) - -> { @nan.div(@nan) }.should raise_error(FloatDomainError) + -> { @one.div(@nan) }.should.raise(FloatDomainError) + -> { @nan.div(@one) }.should.raise(FloatDomainError) + -> { @nan.div(@nan) }.should.raise(FloatDomainError) end it "returns 0 if divided by Infinity and no precision given" do @@ -69,14 +69,14 @@ describe "BigDecimal#div" do end it "raises ZeroDivisionError if divided by zero and no precision given" do - -> { @one.div(@zero) }.should raise_error(ZeroDivisionError) - -> { @one.div(@zero_plus) }.should raise_error(ZeroDivisionError) - -> { @one.div(@zero_minus) }.should raise_error(ZeroDivisionError) - - -> { @zero.div(@zero) }.should raise_error(ZeroDivisionError) - -> { @zero_minus.div(@zero_plus) }.should raise_error(ZeroDivisionError) - -> { @zero_minus.div(@zero_minus) }.should raise_error(ZeroDivisionError) - -> { @zero_plus.div(@zero_minus) }.should raise_error(ZeroDivisionError) + -> { @one.div(@zero) }.should.raise(ZeroDivisionError) + -> { @one.div(@zero_plus) }.should.raise(ZeroDivisionError) + -> { @one.div(@zero_minus) }.should.raise(ZeroDivisionError) + + -> { @zero.div(@zero) }.should.raise(ZeroDivisionError) + -> { @zero_minus.div(@zero_plus) }.should.raise(ZeroDivisionError) + -> { @zero_minus.div(@zero_minus) }.should.raise(ZeroDivisionError) + -> { @zero_plus.div(@zero_minus) }.should.raise(ZeroDivisionError) end it "returns NaN if zero is divided by zero" do @@ -90,9 +90,9 @@ describe "BigDecimal#div" do end it "raises FloatDomainError if (+|-) Infinity divided by 1 and no precision given" do - -> { @infinity_minus.div(@one) }.should raise_error(FloatDomainError) - -> { @infinity.div(@one) }.should raise_error(FloatDomainError) - -> { @infinity_minus.div(@one_minus) }.should raise_error(FloatDomainError) + -> { @infinity_minus.div(@one) }.should.raise(FloatDomainError) + -> { @infinity.div(@one) }.should.raise(FloatDomainError) + -> { @infinity_minus.div(@one_minus) }.should.raise(FloatDomainError) end it "returns (+|-)Infinity if (+|-)Infinity by 1 and precision given" do diff --git a/spec/ruby/library/bigdecimal/divmod_spec.rb b/spec/ruby/library/bigdecimal/divmod_spec.rb index 294f01cba0..d170c6f845 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") - - -> { 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 = BigDecimal("0") + -> { bd5667.mod_part_of_divmod(0) }.should.raise(ZeroDivisionError) + -> { bd5667.mod_part_of_divmod(BigDecimal("0")) }.should.raise(ZeroDivisionError) + -> { zero.mod_part_of_divmod(zero) }.should.raise(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,43 +136,62 @@ 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(FloatDomainError) + -> { @nan.divmod(val) }.should.raise(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 it "raises ZeroDivisionError if the divisor is zero" do (@special_vals + @regular_vals + @zeroes - [@nan]).each do |val| @zeroes.each do |zero| - -> { val.divmod(zero) }.should raise_error(ZeroDivisionError) + -> { val.divmod(zero) }.should.raise(ZeroDivisionError) end 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 @@ -174,7 +206,7 @@ describe "BigDecimal#divmod" do it "raises TypeError if the argument cannot be coerced to BigDecimal" do -> { @one.divmod('1') - }.should raise_error(TypeError) + }.should.raise(TypeError) end end diff --git a/spec/ruby/library/bigdecimal/dup_spec.rb b/spec/ruby/library/bigdecimal/dup_spec.rb index bfabaf6e8b..dbf79ce5a6 100644 --- a/spec/ruby/library/bigdecimal/dup_spec.rb +++ b/spec/ruby/library/bigdecimal/dup_spec.rb @@ -1,6 +1,14 @@ require_relative '../../spec_helper' -require_relative 'shared/clone' +require 'bigdecimal' describe "BigDecimal#dup" do - it_behaves_like :bigdecimal_clone, :dup + before :each do + @obj = BigDecimal("1.2345") + end + + it "returns self" do + copy = @obj.dup + + copy.should.equal?(@obj) + end end diff --git a/spec/ruby/library/bigdecimal/eql_spec.rb b/spec/ruby/library/bigdecimal/eql_spec.rb index 1be5862751..0346175e1e 100644 --- a/spec/ruby/library/bigdecimal/eql_spec.rb +++ b/spec/ruby/library/bigdecimal/eql_spec.rb @@ -1,6 +1,8 @@ require_relative '../../spec_helper' -require_relative 'shared/eql' +require 'bigdecimal' describe "BigDecimal#eql?" do - it_behaves_like :bigdecimal_eql, :eql? + it "is an alias of BigDecimal#==" do + BigDecimal.instance_method(:eql?).should == BigDecimal.instance_method(:==) + end end diff --git a/spec/ruby/library/bigdecimal/equal_value_spec.rb b/spec/ruby/library/bigdecimal/equal_value_spec.rb index 933060eada..d1133765b1 100644 --- a/spec/ruby/library/bigdecimal/equal_value_spec.rb +++ b/spec/ruby/library/bigdecimal/equal_value_spec.rb @@ -1,7 +1,63 @@ require_relative '../../spec_helper' -require_relative 'shared/eql' +require 'bigdecimal' describe "BigDecimal#==" do - it_behaves_like :bigdecimal_eql, :== + before :each do + @bg6543_21 = BigDecimal("6543.21") + @bg5667_19 = BigDecimal("5667.19") + @a = BigDecimal("1.0000000000000000000000000000000000000000005") + @b = BigDecimal("1.00000000000000000000000000000000000000000005") + @bigint = BigDecimal("1000.0") + @nan = BigDecimal("NaN") + @infinity = BigDecimal("Infinity") + @infinity_minus = BigDecimal("-Infinity") + end + + it "tests for equality" do + (@bg6543_21 == @bg6543_21).should == true + (@a == @a).should == true + (@a == @b).should == false + (@bg6543_21 == @a).should == false + (@bigint == 1000).should == true + end + + it "returns false for NaN as it is never equal to any number" do + (@nan == @nan).should == false + (@a == @nan).should == false + (@nan == @a).should == false + (@nan == @infinity).should == false + (@nan == @infinity_minus).should == false + (@infinity == @nan).should == false + (@infinity_minus == @nan).should == false + end + + it "returns true for infinity values with the same sign" do + (@infinity == @infinity).should == true + (@infinity == BigDecimal("Infinity")).should == true + (BigDecimal("Infinity") == @infinity).should == true + + (@infinity_minus == @infinity_minus).should == true + (@infinity_minus == BigDecimal("-Infinity")).should == true + (BigDecimal("-Infinity") == @infinity_minus).should == true + end + + it "returns false for infinity values with different signs" do + (@infinity == @infinity_minus).should == false + (@infinity_minus == @infinity).should == false + end + + it "returns false when infinite value compared to finite one" do + (@infinity == @a).should == false + (@infinity_minus == @a).should == false + + (@a == @infinity).should == false + (@a == @infinity_minus).should == false + end + + it "returns false when compared objects that can not be coerced into BigDecimal" do + (@infinity == nil).should == false + (@bigint == nil).should == false + (@nan == nil).should == false + end end diff --git a/spec/ruby/library/bigdecimal/fix_spec.rb b/spec/ruby/library/bigdecimal/fix_spec.rb index 2c6276899e..dceb2ce867 100644 --- a/spec/ruby/library/bigdecimal/fix_spec.rb +++ b/spec/ruby/library/bigdecimal/fix_spec.rb @@ -51,7 +51,7 @@ describe "BigDecimal#fix" do it "does not allow any arguments" do -> { @mixed.fix(10) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) end end diff --git a/spec/ruby/library/bigdecimal/floor_spec.rb b/spec/ruby/library/bigdecimal/floor_spec.rb index a7dfec2c9a..c0666c668c 100644 --- a/spec/ruby/library/bigdecimal/floor_spec.rb +++ b/spec/ruby/library/bigdecimal/floor_spec.rb @@ -41,9 +41,9 @@ describe "BigDecimal#floor" do end it "raise exception, if self is special value" do - -> { @infinity.floor }.should raise_error(FloatDomainError) - -> { @infinity_neg.floor }.should raise_error(FloatDomainError) - -> { @nan.floor }.should raise_error(FloatDomainError) + -> { @infinity.floor }.should.raise(FloatDomainError) + -> { @infinity_neg.floor }.should.raise(FloatDomainError) + -> { @nan.floor }.should.raise(FloatDomainError) end it "returns n digits right of the decimal point if given n > 0" do diff --git a/spec/ruby/library/bigdecimal/gt_spec.rb b/spec/ruby/library/bigdecimal/gt_spec.rb index 78547fb85f..e9c9a60e75 100644 --- a/spec/ruby/library/bigdecimal/gt_spec.rb +++ b/spec/ruby/library/bigdecimal/gt_spec.rb @@ -86,11 +86,11 @@ describe "BigDecimal#>" do end it "raises an ArgumentError if the argument can't be coerced into a BigDecimal" do - -> {@zero > nil }.should raise_error(ArgumentError) - -> {@infinity > nil }.should raise_error(ArgumentError) - -> {@infinity_neg > nil }.should raise_error(ArgumentError) - -> {@mixed > nil }.should raise_error(ArgumentError) - -> {@pos_int > nil }.should raise_error(ArgumentError) - -> {@neg_frac > nil }.should raise_error(ArgumentError) + -> {@zero > nil }.should.raise(ArgumentError) + -> {@infinity > nil }.should.raise(ArgumentError) + -> {@infinity_neg > nil }.should.raise(ArgumentError) + -> {@mixed > nil }.should.raise(ArgumentError) + -> {@pos_int > nil }.should.raise(ArgumentError) + -> {@neg_frac > nil }.should.raise(ArgumentError) end end diff --git a/spec/ruby/library/bigdecimal/gte_spec.rb b/spec/ruby/library/bigdecimal/gte_spec.rb index 2a5cc025ba..548f3efe4c 100644 --- a/spec/ruby/library/bigdecimal/gte_spec.rb +++ b/spec/ruby/library/bigdecimal/gte_spec.rb @@ -90,11 +90,11 @@ describe "BigDecimal#>=" do end it "returns nil if the argument is nil" do - -> {@zero >= nil }.should raise_error(ArgumentError) - -> {@infinity >= nil }.should raise_error(ArgumentError) - -> {@infinity_neg >= nil }.should raise_error(ArgumentError) - -> {@mixed >= nil }.should raise_error(ArgumentError) - -> {@pos_int >= nil }.should raise_error(ArgumentError) - -> {@neg_frac >= nil }.should raise_error(ArgumentError) + -> {@zero >= nil }.should.raise(ArgumentError) + -> {@infinity >= nil }.should.raise(ArgumentError) + -> {@infinity_neg >= nil }.should.raise(ArgumentError) + -> {@mixed >= nil }.should.raise(ArgumentError) + -> {@pos_int >= nil }.should.raise(ArgumentError) + -> {@neg_frac >= nil }.should.raise(ArgumentError) end end diff --git a/spec/ruby/library/bigdecimal/lt_spec.rb b/spec/ruby/library/bigdecimal/lt_spec.rb index 02390e76e3..c3f3573247 100644 --- a/spec/ruby/library/bigdecimal/lt_spec.rb +++ b/spec/ruby/library/bigdecimal/lt_spec.rb @@ -84,11 +84,11 @@ describe "BigDecimal#<" do end it "raises an ArgumentError if the argument can't be coerced into a BigDecimal" do - -> {@zero < nil }.should raise_error(ArgumentError) - -> {@infinity < nil }.should raise_error(ArgumentError) - -> {@infinity_neg < nil }.should raise_error(ArgumentError) - -> {@mixed < nil }.should raise_error(ArgumentError) - -> {@pos_int < nil }.should raise_error(ArgumentError) - -> {@neg_frac < nil }.should raise_error(ArgumentError) + -> {@zero < nil }.should.raise(ArgumentError) + -> {@infinity < nil }.should.raise(ArgumentError) + -> {@infinity_neg < nil }.should.raise(ArgumentError) + -> {@mixed < nil }.should.raise(ArgumentError) + -> {@pos_int < nil }.should.raise(ArgumentError) + -> {@neg_frac < nil }.should.raise(ArgumentError) end end diff --git a/spec/ruby/library/bigdecimal/lte_spec.rb b/spec/ruby/library/bigdecimal/lte_spec.rb index b92be04123..7918bde88b 100644 --- a/spec/ruby/library/bigdecimal/lte_spec.rb +++ b/spec/ruby/library/bigdecimal/lte_spec.rb @@ -90,11 +90,11 @@ describe "BigDecimal#<=" do end it "raises an ArgumentError if the argument can't be coerced into a BigDecimal" do - -> {@zero <= nil }.should raise_error(ArgumentError) - -> {@infinity <= nil }.should raise_error(ArgumentError) - -> {@infinity_neg <= nil }.should raise_error(ArgumentError) - -> {@mixed <= nil }.should raise_error(ArgumentError) - -> {@pos_int <= nil }.should raise_error(ArgumentError) - -> {@neg_frac <= nil }.should raise_error(ArgumentError) + -> {@zero <= nil }.should.raise(ArgumentError) + -> {@infinity <= nil }.should.raise(ArgumentError) + -> {@infinity_neg <= nil }.should.raise(ArgumentError) + -> {@mixed <= nil }.should.raise(ArgumentError) + -> {@pos_int <= nil }.should.raise(ArgumentError) + -> {@neg_frac <= nil }.should.raise(ArgumentError) end end diff --git a/spec/ruby/library/bigdecimal/mode_spec.rb b/spec/ruby/library/bigdecimal/mode_spec.rb index 73fa1a118e..26e6d0ea75 100644 --- a/spec/ruby/library/bigdecimal/mode_spec.rb +++ b/spec/ruby/library/bigdecimal/mode_spec.rb @@ -24,13 +24,13 @@ describe "BigDecimal.mode" do it "raise an exception if the flag is true" do BigDecimal.mode(BigDecimal::EXCEPTION_NaN, true) - -> { BigDecimal("NaN").add(BigDecimal("1"),0) }.should raise_error(FloatDomainError) + -> { BigDecimal("NaN").add(BigDecimal("1"),0) }.should.raise(FloatDomainError) BigDecimal.mode(BigDecimal::EXCEPTION_INFINITY, true) - -> { BigDecimal("0").add(BigDecimal("Infinity"),0) }.should raise_error(FloatDomainError) + -> { BigDecimal("0").add(BigDecimal("Infinity"),0) }.should.raise(FloatDomainError) BigDecimal.mode(BigDecimal::EXCEPTION_ZERODIVIDE, true) - -> { BigDecimal("1").quo(BigDecimal("0")) }.should raise_error(FloatDomainError) + -> { BigDecimal("1").quo(BigDecimal("0")) }.should.raise(FloatDomainError) BigDecimal.mode(BigDecimal::EXCEPTION_OVERFLOW, true) - -> { BigDecimal("1E11111111111111111111") }.should raise_error(FloatDomainError) - -> { (BigDecimal("1E1000000000000000000")**10) }.should raise_error(FloatDomainError) + -> { BigDecimal("1E11111111111111111111") }.should.raise(FloatDomainError) + -> { (BigDecimal("1E1000000000000000000")**10) }.should.raise(FloatDomainError) end end diff --git a/spec/ruby/library/bigdecimal/modulo_spec.rb b/spec/ruby/library/bigdecimal/modulo_spec.rb index 035d31bd98..d6b4f91b6d 100644 --- a/spec/ruby/library/bigdecimal/modulo_spec.rb +++ b/spec/ruby/library/bigdecimal/modulo_spec.rb @@ -1,12 +1,21 @@ require_relative '../../spec_helper' require_relative 'shared/modulo' +require 'bigdecimal' describe "BigDecimal#%" do it_behaves_like :bigdecimal_modulo, :% - it_behaves_like :bigdecimal_modulo_zerodivisionerror, :% + + it "raises ZeroDivisionError if other is zero" do + bd5667 = BigDecimal("5667.19") + + -> { bd5667 % 0 }.should.raise(ZeroDivisionError) + -> { bd5667 % BigDecimal("0") }.should.raise(ZeroDivisionError) + -> { @zero % @zero }.should.raise(ZeroDivisionError) + end end describe "BigDecimal#modulo" do - it_behaves_like :bigdecimal_modulo, :modulo - it_behaves_like :bigdecimal_modulo_zerodivisionerror, :modulo + it "is an alias of BigDecimal#%" do + BigDecimal.instance_method(:modulo).should == BigDecimal.instance_method(:%) + end end 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/nonzero_spec.rb b/spec/ruby/library/bigdecimal/nonzero_spec.rb index f43c4393cd..31421ebdf4 100644 --- a/spec/ruby/library/bigdecimal/nonzero_spec.rb +++ b/spec/ruby/library/bigdecimal/nonzero_spec.rb @@ -10,11 +10,11 @@ describe "BigDecimal#nonzero?" do infinity = BigDecimal("Infinity") infinity_minus = BigDecimal("-Infinity") nan = BigDecimal("NaN") - infinity.nonzero?.should equal(infinity) - infinity_minus.nonzero?.should equal(infinity_minus) - nan.nonzero?.should equal(nan) - e3_minus.nonzero?.should equal(e3_minus) - e2_plus.nonzero?.should equal(e2_plus) + infinity.nonzero?.should.equal?(infinity) + infinity_minus.nonzero?.should.equal?(infinity_minus) + nan.nonzero?.should.equal?(nan) + e3_minus.nonzero?.should.equal?(e3_minus) + e2_plus.nonzero?.should.equal?(e2_plus) end it "returns nil otherwise" do 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 bac5f37ba9..27a2986570 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(ZeroDivisionError) + -> { @zero.remainder(@zero) }.should.raise(ZeroDivisionError) + end end it "returns zero if used on zero" do @@ -54,25 +56,6 @@ describe "BigDecimal#remainder" do @nan.remainder(@infinity).should.nan? end - 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? - @infinity.remainder(@mixed).should.nan? - @infinity.remainder(@one_minus).should.nan? - @infinity.remainder(@frac_1).should.nan? - @one.remainder(@infinity).should.nan? - - @infinity_minus.remainder(@infinity_minus).should.nan? - @infinity_minus.remainder(@one).should.nan? - @one.remainder(@infinity_minus).should.nan? - @frac_2.remainder(@infinity_minus).should.nan? - - @infinity.remainder(@infinity_minus).should.nan? - @infinity_minus.remainder(@infinity).should.nan? - end - end - it "coerces arguments to BigDecimal if possible" do @three.remainder(2).should == @one end @@ -88,7 +71,7 @@ describe "BigDecimal#remainder" do it "raises TypeError if the argument cannot be coerced to BigDecimal" do -> { @one.remainder('2') - }.should raise_error(TypeError) + }.should.raise(TypeError) end end diff --git a/spec/ruby/library/bigdecimal/round_spec.rb b/spec/ruby/library/bigdecimal/round_spec.rb index 6a4d220417..622e129d93 100644 --- a/spec/ruby/library/bigdecimal/round_spec.rb +++ b/spec/ruby/library/bigdecimal/round_spec.rb @@ -217,18 +217,18 @@ describe "BigDecimal#round" do end it 'raise exception, if self is special value' do - -> { BigDecimal('NaN').round }.should raise_error(FloatDomainError) - -> { BigDecimal('Infinity').round }.should raise_error(FloatDomainError) - -> { BigDecimal('-Infinity').round }.should raise_error(FloatDomainError) + -> { BigDecimal('NaN').round }.should.raise(FloatDomainError) + -> { BigDecimal('Infinity').round }.should.raise(FloatDomainError) + -> { BigDecimal('-Infinity').round }.should.raise(FloatDomainError) end it 'do not raise exception, if self is special value and precision is given' do - -> { BigDecimal('NaN').round(2) }.should_not raise_error(FloatDomainError) - -> { BigDecimal('Infinity').round(2) }.should_not raise_error(FloatDomainError) - -> { BigDecimal('-Infinity').round(2) }.should_not raise_error(FloatDomainError) + -> { BigDecimal('NaN').round(2) }.should_not.raise(FloatDomainError) + -> { BigDecimal('Infinity').round(2) }.should_not.raise(FloatDomainError) + -> { BigDecimal('-Infinity').round(2) }.should_not.raise(FloatDomainError) end it 'raise for a non-existent round mode' do - -> { @p1_50.round(0, :nonsense) }.should raise_error(ArgumentError, "invalid rounding mode (nonsense)") + -> { @p1_50.round(0, :nonsense) }.should.raise(ArgumentError, "invalid rounding mode (nonsense)") end end diff --git a/spec/ruby/library/bigdecimal/shared/clone.rb b/spec/ruby/library/bigdecimal/shared/clone.rb deleted file mode 100644 index 935ef76e7e..0000000000 --- a/spec/ruby/library/bigdecimal/shared/clone.rb +++ /dev/null @@ -1,13 +0,0 @@ -require 'bigdecimal' - -describe :bigdecimal_clone, shared: true do - before :each do - @obj = BigDecimal("1.2345") - end - - it "returns self" do - copy = @obj.public_send(@method) - - copy.should equal(@obj) - end -end diff --git a/spec/ruby/library/bigdecimal/shared/eql.rb b/spec/ruby/library/bigdecimal/shared/eql.rb deleted file mode 100644 index 8e3e388bab..0000000000 --- a/spec/ruby/library/bigdecimal/shared/eql.rb +++ /dev/null @@ -1,61 +0,0 @@ -require 'bigdecimal' - -describe :bigdecimal_eql, shared: true do - before :each do - @bg6543_21 = BigDecimal("6543.21") - @bg5667_19 = BigDecimal("5667.19") - @a = BigDecimal("1.0000000000000000000000000000000000000000005") - @b = BigDecimal("1.00000000000000000000000000000000000000000005") - @bigint = BigDecimal("1000.0") - @nan = BigDecimal("NaN") - @infinity = BigDecimal("Infinity") - @infinity_minus = BigDecimal("-Infinity") - end - - it "tests for equality" do - @bg6543_21.send(@method, @bg6543_21).should == true - @a.send(@method, @a).should == true - @a.send(@method, @b).should == false - @bg6543_21.send(@method, @a).should == false - @bigint.send(@method, 1000).should == true - end - - it "returns false for NaN as it is never equal to any number" do - @nan.send(@method, @nan).should == false - @a.send(@method, @nan).should == false - @nan.send(@method, @a).should == false - @nan.send(@method, @infinity).should == false - @nan.send(@method, @infinity_minus).should == false - @infinity.send(@method, @nan).should == false - @infinity_minus.send(@method, @nan).should == false - end - - it "returns true for infinity values with the same sign" do - @infinity.send(@method, @infinity).should == true - @infinity.send(@method, BigDecimal("Infinity")).should == true - BigDecimal("Infinity").send(@method, @infinity).should == true - - @infinity_minus.send(@method, @infinity_minus).should == true - @infinity_minus.send(@method, BigDecimal("-Infinity")).should == true - BigDecimal("-Infinity").send(@method, @infinity_minus).should == true - end - - it "returns false for infinity values with different signs" do - @infinity.send(@method, @infinity_minus).should == false - @infinity_minus.send(@method, @infinity).should == false - end - - it "returns false when infinite value compared to finite one" do - @infinity.send(@method, @a).should == false - @infinity_minus.send(@method, @a).should == false - - @a.send(@method, @infinity).should == false - @a.send(@method, @infinity_minus).should == false - end - - it "returns false when compared objects that can not be coerced into BigDecimal" do - @infinity.send(@method, nil).should == false - @bigint.send(@method, nil).should == false - @nan.send(@method, nil).should == false - end -end diff --git a/spec/ruby/library/bigdecimal/shared/modulo.rb b/spec/ruby/library/bigdecimal/shared/modulo.rb index aa5c5a640b..5b5e3503c4 100644 --- a/spec/ruby/library/bigdecimal/shared/modulo.rb +++ b/spec/ruby/library/bigdecimal/shared/modulo.rb @@ -101,25 +101,21 @@ 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 -> { @one.send(@method, '2') - }.should raise_error(TypeError) - end -end - -describe :bigdecimal_modulo_zerodivisionerror, shared: true do - it "raises ZeroDivisionError if other is zero" do - bd5667 = BigDecimal("5667.19") - - -> { bd5667.send(@method, 0) }.should raise_error(ZeroDivisionError) - -> { bd5667.send(@method, BigDecimal("0")) }.should raise_error(ZeroDivisionError) - -> { @zero.send(@method, @zero) }.should raise_error(ZeroDivisionError) + }.should.raise(TypeError) end end 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/to_int.rb b/spec/ruby/library/bigdecimal/shared/to_int.rb deleted file mode 100644 index 44b6a3c7b2..0000000000 --- a/spec/ruby/library/bigdecimal/shared/to_int.rb +++ /dev/null @@ -1,16 +0,0 @@ -require 'bigdecimal' - -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) - end - - it "returns Integer otherwise" do - BigDecimal("3E-20001").send(@method).should == 0 - BigDecimal("2E4000").send(@method).should == 2 * 10 ** 4000 - BigDecimal("2").send(@method).should == 2 - BigDecimal("2E10").send(@method).should == 20000000000 - BigDecimal("3.14159").send(@method).should == 3 - end -end diff --git a/spec/ruby/library/bigdecimal/sqrt_spec.rb b/spec/ruby/library/bigdecimal/sqrt_spec.rb index 42cf4545cb..1f3ef9a8c3 100644 --- a/spec/ruby/library/bigdecimal/sqrt_spec.rb +++ b/spec/ruby/library/bigdecimal/sqrt_spec.rb @@ -45,37 +45,37 @@ describe "BigDecimal#sqrt" do it "raises ArgumentError when no argument is given" do -> { @one.sqrt - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) end it "raises ArgumentError if a negative number is given" do -> { @one.sqrt(-1) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) end it "raises ArgumentError if 2 arguments are given" do -> { @one.sqrt(1, 1) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) end it "raises TypeError if nil is given" do -> { @one.sqrt(nil) - }.should raise_error(TypeError) + }.should.raise(TypeError) end it "raises TypeError if a string is given" do -> { @one.sqrt("stuff") - }.should raise_error(TypeError) + }.should.raise(TypeError) end it "raises TypeError if a plain Object is given" do -> { @one.sqrt(Object.new) - }.should raise_error(TypeError) + }.should.raise(TypeError) end it "returns 1 if precision is 0 or 1" do @@ -86,7 +86,7 @@ describe "BigDecimal#sqrt" do it "raises FloatDomainError on negative values" do -> { BigDecimal('-1').sqrt(10) - }.should raise_error(FloatDomainError) + }.should.raise(FloatDomainError) end it "returns positive infinity for infinity" do @@ -96,13 +96,13 @@ describe "BigDecimal#sqrt" do it "raises FloatDomainError for negative infinity" do -> { @infinity_minus.sqrt(1) - }.should raise_error(FloatDomainError) + }.should.raise(FloatDomainError) end it "raises FloatDomainError for NaN" do -> { @nan.sqrt(1) - }.should raise_error(FloatDomainError) + }.should.raise(FloatDomainError) end it "returns 0 for 0, +0.0 and -0.0" 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_f_spec.rb b/spec/ruby/library/bigdecimal/to_f_spec.rb index 84d4d49de2..f5220d995a 100644 --- a/spec/ruby/library/bigdecimal/to_f_spec.rb +++ b/spec/ruby/library/bigdecimal/to_f_spec.rb @@ -20,9 +20,9 @@ describe "BigDecimal#to_f" do end it "returns number of type float" do - BigDecimal("3.14159").to_f.should be_kind_of(Float) - @vals.each { |val| val.to_f.should be_kind_of(Float) } - @spec_vals.each { |val| val.to_f.should be_kind_of(Float) } + BigDecimal("3.14159").to_f.should.is_a?(Float) + @vals.each { |val| val.to_f.should.is_a?(Float) } + @spec_vals.each { |val| val.to_f.should.is_a?(Float) } end it "rounds correctly to Float precision" do diff --git a/spec/ruby/library/bigdecimal/to_i_spec.rb b/spec/ruby/library/bigdecimal/to_i_spec.rb index e5e65c562e..b6d9e43e57 100644 --- a/spec/ruby/library/bigdecimal/to_i_spec.rb +++ b/spec/ruby/library/bigdecimal/to_i_spec.rb @@ -1,7 +1,17 @@ require_relative '../../spec_helper' -require_relative 'shared/to_int' require 'bigdecimal' describe "BigDecimal#to_i" do - it_behaves_like :bigdecimal_to_int, :to_i + it "raises FloatDomainError if BigDecimal is infinity or NaN" do + -> { BigDecimal("Infinity").to_i }.should.raise(FloatDomainError) + -> { BigDecimal("NaN").to_i }.should.raise(FloatDomainError) + end + + it "returns Integer otherwise" do + BigDecimal("3E-20001").to_i.should == 0 + BigDecimal("2E4000").to_i.should == 2 * 10 ** 4000 + BigDecimal("2").to_i.should == 2 + BigDecimal("2E10").to_i.should == 20000000000 + BigDecimal("3.14159").to_i.should == 3 + end end diff --git a/spec/ruby/library/bigdecimal/to_int_spec.rb b/spec/ruby/library/bigdecimal/to_int_spec.rb index 4df6749845..18f3620f5e 100644 --- a/spec/ruby/library/bigdecimal/to_int_spec.rb +++ b/spec/ruby/library/bigdecimal/to_int_spec.rb @@ -1,8 +1,8 @@ require_relative '../../spec_helper' -require_relative 'shared/to_int' require 'bigdecimal' - describe "BigDecimal#to_int" do - it_behaves_like :bigdecimal_to_int, :to_int + it "is an alias of BigDecimal#to_i" do + BigDecimal.instance_method(:to_int).should == BigDecimal.instance_method(:to_i) + end end diff --git a/spec/ruby/library/bigdecimal/to_r_spec.rb b/spec/ruby/library/bigdecimal/to_r_spec.rb index c350beff08..a112c002ef 100644 --- a/spec/ruby/library/bigdecimal/to_r_spec.rb +++ b/spec/ruby/library/bigdecimal/to_r_spec.rb @@ -4,25 +4,25 @@ require 'bigdecimal' describe "BigDecimal#to_r" do it "returns a Rational" do - BigDecimal("3.14159").to_r.should be_kind_of(Rational) + BigDecimal("3.14159").to_r.should.is_a?(Rational) end it "returns a Rational with bignum values" do r = BigDecimal("3.141592653589793238462643").to_r - r.numerator.should eql(3141592653589793238462643) - r.denominator.should eql(1000000000000000000000000) + r.numerator.should.eql?(3141592653589793238462643) + r.denominator.should.eql?(1000000000000000000000000) end it "returns a Rational from a BigDecimal with an exponent" do r = BigDecimal("1E2").to_r - r.numerator.should eql(100) - r.denominator.should eql(1) + r.numerator.should.eql?(100) + r.denominator.should.eql?(1) end it "returns a Rational from a negative BigDecimal with an exponent" do r = BigDecimal("-1E2").to_r - r.numerator.should eql(-100) - r.denominator.should eql(1) + r.numerator.should.eql?(-100) + r.denominator.should.eql?(1) end end diff --git a/spec/ruby/library/bigdecimal/to_s_spec.rb b/spec/ruby/library/bigdecimal/to_s_spec.rb index ba9f960eb3..5ec54765b5 100644 --- a/spec/ruby/library/bigdecimal/to_s_spec.rb +++ b/spec/ruby/library/bigdecimal/to_s_spec.rb @@ -31,7 +31,7 @@ describe "BigDecimal#to_s" do end it "takes an optional argument" do - -> {@bigdec.to_s("F")}.should_not raise_error() + -> {@bigdec.to_s("F")}.should_not.raise() end it "starts with + if + is supplied and value is positive" do @@ -52,10 +52,8 @@ describe "BigDecimal#to_s" do 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 + 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 it "can return a leading space for values > 0" do @@ -90,11 +88,11 @@ describe "BigDecimal#to_s" 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) + 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) + 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 0ae0421b30..cedc662aeb 100644 --- a/spec/ruby/library/bigdecimal/truncate_spec.rb +++ b/spec/ruby/library/bigdecimal/truncate_spec.rb @@ -74,8 +74,8 @@ describe "BigDecimal#truncate" do end it "returns the same value if self is special value" do - -> { @nan.truncate }.should raise_error(FloatDomainError) - -> { @infinity.truncate }.should raise_error(FloatDomainError) - -> { @infinity_negative.truncate }.should raise_error(FloatDomainError) + -> { @nan.truncate }.should.raise(FloatDomainError) + -> { @infinity.truncate }.should.raise(FloatDomainError) + -> { @infinity_negative.truncate }.should.raise(FloatDomainError) end end diff --git a/spec/ruby/library/bigdecimal/util_spec.rb b/spec/ruby/library/bigdecimal/util_spec.rb index fc67fcf200..69663d4bd2 100644 --- a/spec/ruby/library/bigdecimal/util_spec.rb +++ b/spec/ruby/library/bigdecimal/util_spec.rb @@ -20,7 +20,7 @@ describe "BigDecimal's util method definitions" do it "should define #to_d on BigDecimal" do bd = BigDecimal("3.14") - bd.to_d.should equal(bd) + bd.to_d.should.equal?(bd) end it "should define #to_d on Rational" do diff --git a/spec/ruby/library/cgi/cookie/domain_spec.rb b/spec/ruby/library/cgi/cookie/domain_spec.rb index 622549039f..c118ef6383 100644 --- a/spec/ruby/library/cgi/cookie/domain_spec.rb +++ b/spec/ruby/library/cgi/cookie/domain_spec.rb @@ -1,12 +1,12 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' describe "CGI::Cookie#domain" do it "returns self's domain" do cookie = CGI::Cookie.new("test-cookie") - cookie.domain.should be_nil + cookie.domain.should == nil cookie = CGI::Cookie.new("name" => "test-cookie", "domain" => "example.com") cookie.domain.should == "example.com" diff --git a/spec/ruby/library/cgi/cookie/expires_spec.rb b/spec/ruby/library/cgi/cookie/expires_spec.rb index df52a6f41e..b9cc7d5b65 100644 --- a/spec/ruby/library/cgi/cookie/expires_spec.rb +++ b/spec/ruby/library/cgi/cookie/expires_spec.rb @@ -1,12 +1,12 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do 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 + cookie.expires.should == nil cookie = CGI::Cookie.new("name" => "test-cookie", "expires" => Time.at(1196524602)) cookie.expires.should == Time.at(1196524602) diff --git a/spec/ruby/library/cgi/cookie/initialize_spec.rb b/spec/ruby/library/cgi/cookie/initialize_spec.rb index ac99d5e4fd..80bc2c2196 100644 --- a/spec/ruby/library/cgi/cookie/initialize_spec.rb +++ b/spec/ruby/library/cgi/cookie/initialize_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' describe "CGI::Cookie#initialize when passed String" do @@ -20,7 +20,7 @@ ruby_version_is ""..."3.5" do it "sets self to a non-secure cookie" do @cookie.send(:initialize, "test") - @cookie.secure.should be_false + @cookie.secure.should == false end it "does set self's path to an empty String when ENV[\"SCRIPT_NAME\"] is not set" do @@ -49,11 +49,11 @@ ruby_version_is ""..."3.5" do end it "does not set self's expiration date" do - @cookie.expires.should be_nil + @cookie.expires.should == nil end it "does not set self's domain" do - @cookie.domain.should be_nil + @cookie.domain.should == nil end end @@ -76,7 +76,7 @@ ruby_version_is ""..."3.5" do @cookie.path.should == "some/path/" @cookie.domain.should == "example.com" @cookie.expires.should == Time.at(1196524602) - @cookie.secure.should be_true + @cookie.secure.should == true end it "does set self's path based on ENV[\"SCRIPT_NAME\"] when the Hash has no 'path' entry" do @@ -122,8 +122,8 @@ ruby_version_is ""..."3.5" do 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) + -> { @cookie.send(:initialize, {}) }.should.raise(ArgumentError) + -> { @cookie.send(:initialize, "value" => "test") }.should.raise(ArgumentError) end end @@ -144,7 +144,7 @@ ruby_version_is ""..."3.5" do it "sets self to a non-secure cookie" do @cookie.send(:initialize, "test", "one", "two", "three") - @cookie.secure.should be_false + @cookie.secure.should == 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 712628180b..4908204e8a 100644 --- a/spec/ruby/library/cgi/cookie/name_spec.rb +++ b/spec/ruby/library/cgi/cookie/name_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' describe "CGI::Cookie#name" do diff --git a/spec/ruby/library/cgi/cookie/parse_spec.rb b/spec/ruby/library/cgi/cookie/parse_spec.rb index ecc78d77dc..bc505c37ba 100644 --- a/spec/ruby/library/cgi/cookie/parse_spec.rb +++ b/spec/ruby/library/cgi/cookie/parse_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' describe "CGI::Cookie.parse" do diff --git a/spec/ruby/library/cgi/cookie/path_spec.rb b/spec/ruby/library/cgi/cookie/path_spec.rb index 010e87a6b8..13ee5d726b 100644 --- a/spec/ruby/library/cgi/cookie/path_spec.rb +++ b/spec/ruby/library/cgi/cookie/path_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' describe "CGI::Cookie#path" do diff --git a/spec/ruby/library/cgi/cookie/secure_spec.rb b/spec/ruby/library/cgi/cookie/secure_spec.rb index b526897250..233881b173 100644 --- a/spec/ruby/library/cgi/cookie/secure_spec.rb +++ b/spec/ruby/library/cgi/cookie/secure_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' describe "CGI::Cookie#secure" do @@ -10,10 +10,10 @@ ruby_version_is ""..."3.5" do it "returns whether self is a secure cookie or not" do @cookie.secure = true - @cookie.secure.should be_true + @cookie.secure.should == true @cookie.secure = false - @cookie.secure.should be_false + @cookie.secure.should == false end end @@ -23,12 +23,12 @@ ruby_version_is ""..."3.5" do end it "returns true" do - (@cookie.secure = true).should be_true + (@cookie.secure = true).should == true end it "sets self to a secure cookie" do @cookie.secure = true - @cookie.secure.should be_true + @cookie.secure.should == true end end @@ -38,12 +38,12 @@ ruby_version_is ""..."3.5" do end it "returns false" do - (@cookie.secure = false).should be_false + (@cookie.secure = false).should == false end it "sets self to a non-secure cookie" do @cookie.secure = false - @cookie.secure.should be_false + @cookie.secure.should == false end end @@ -56,18 +56,18 @@ ruby_version_is ""..."3.5" do @cookie.secure = false @cookie.secure = Object.new - @cookie.secure.should be_false + @cookie.secure.should == false @cookie.secure = "Test" - @cookie.secure.should be_false + @cookie.secure.should == false @cookie.secure = true @cookie.secure = Object.new - @cookie.secure.should be_true + @cookie.secure.should == true @cookie.secure = "Test" - @cookie.secure.should be_true + @cookie.secure.should == 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 34326f672b..20d2579f8d 100644 --- a/spec/ruby/library/cgi/cookie/to_s_spec.rb +++ b/spec/ruby/library/cgi/cookie/to_s_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' describe "CGI::Cookie#to_s" do diff --git a/spec/ruby/library/cgi/cookie/value_spec.rb b/spec/ruby/library/cgi/cookie/value_spec.rb index e7c91b55b9..45032edcbf 100644 --- a/spec/ruby/library/cgi/cookie/value_spec.rb +++ b/spec/ruby/library/cgi/cookie/value_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' describe "CGI::Cookie#value" do @@ -37,7 +37,7 @@ ruby_version_is ""..."3.5" do cookie2.value.send(method, *args) fail << method unless cookie1.value == cookie2.value end - fail.should be_empty + fail.should.empty? end end diff --git a/spec/ruby/library/cgi/escapeElement_spec.rb b/spec/ruby/library/cgi/escapeElement_spec.rb index 7bfa3f4feb..72c38d6028 100644 --- a/spec/ruby/library/cgi/escapeElement_spec.rb +++ b/spec/ruby/library/cgi/escapeElement_spec.rb @@ -1,9 +1,9 @@ require_relative '../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' end -ruby_version_is "3.5" do +ruby_version_is "4.0" do require 'cgi/escape' end diff --git a/spec/ruby/library/cgi/escapeURIComponent_spec.rb b/spec/ruby/library/cgi/escapeURIComponent_spec.rb index 02921ab8bf..98efa2e67e 100644 --- a/spec/ruby/library/cgi/escapeURIComponent_spec.rb +++ b/spec/ruby/library/cgi/escapeURIComponent_spec.rb @@ -6,48 +6,67 @@ rescue LoadError end describe "CGI.escapeURIComponent" do - it "escapes whitespace" do - string = "&<>\" \xE3\x82\x86\xE3\x82\x93\xE3\x82\x86\xE3\x82\x93" - CGI.escapeURIComponent(string).should == '%26%3C%3E%22%20%E3%82%86%E3%82%93%E3%82%86%E3%82%93' + 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 escape with unreserved characters" do + it "does not percent-encode unreserved characters according to RFC 3986" do string = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~" CGI.escapeURIComponent(string).should == "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~" end - it "supports String with invalid encoding" do - string = "\xC0\<\<".dup.force_encoding("UTF-8") - CGI.escapeURIComponent(string).should == "%C0%3C%3C" + it "encodes % character as %25" do + CGI.escapeURIComponent("%").should == "%25" end - it "processes String bytes one by one, not characters" do - CGI.escapeURIComponent("β").should == "%CE%B2" # "β" bytes representation is CE B2 + # Compare to .escape which uses "+". + it "percent-encodes single whitespace" do + CGI.escapeURIComponent(" ").should == "%20" end - it "raises a TypeError with nil" do - -> { - CGI.escapeURIComponent(nil) - }.should raise_error(TypeError, 'no implicit conversion of nil into String') + 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 "encodes empty string" do - CGI.escapeURIComponent("").should == "" + 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 "encodes single whitespace" do - CGI.escapeURIComponent(" ").should == "%20" + 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 "encodes double whitespace" do - CGI.escapeURIComponent(" ").should == "%20%20" + 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 encoding" do + 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(TypeError, "no implicit conversion of nil into String") + end + it "uses implicit type conversion to String" do object = Object.new def object.to_str diff --git a/spec/ruby/library/cgi/htmlextension/a_spec.rb b/spec/ruby/library/cgi/htmlextension/a_spec.rb index 16a0552bac..78d3dec8fa 100644 --- a/spec/ruby/library/cgi/htmlextension/a_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/a_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' require_relative 'fixtures/common' diff --git a/spec/ruby/library/cgi/htmlextension/base_spec.rb b/spec/ruby/library/cgi/htmlextension/base_spec.rb index a4c4a61614..1eedfdea54 100644 --- a/spec/ruby/library/cgi/htmlextension/base_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/base_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' require_relative 'fixtures/common' diff --git a/spec/ruby/library/cgi/htmlextension/blockquote_spec.rb b/spec/ruby/library/cgi/htmlextension/blockquote_spec.rb index f8d4ca310e..883e36f78b 100644 --- a/spec/ruby/library/cgi/htmlextension/blockquote_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/blockquote_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' require_relative 'fixtures/common' diff --git a/spec/ruby/library/cgi/htmlextension/br_spec.rb b/spec/ruby/library/cgi/htmlextension/br_spec.rb index 45909a2db7..23c2cb4a48 100644 --- a/spec/ruby/library/cgi/htmlextension/br_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/br_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' require_relative 'fixtures/common' diff --git a/spec/ruby/library/cgi/htmlextension/caption_spec.rb b/spec/ruby/library/cgi/htmlextension/caption_spec.rb index 74f0a098f4..3d3e21ecaa 100644 --- a/spec/ruby/library/cgi/htmlextension/caption_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/caption_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' require_relative 'fixtures/common' diff --git a/spec/ruby/library/cgi/htmlextension/checkbox_group_spec.rb b/spec/ruby/library/cgi/htmlextension/checkbox_group_spec.rb index 1acfe62fda..07163c010e 100644 --- a/spec/ruby/library/cgi/htmlextension/checkbox_group_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/checkbox_group_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' require_relative 'fixtures/common' diff --git a/spec/ruby/library/cgi/htmlextension/checkbox_spec.rb b/spec/ruby/library/cgi/htmlextension/checkbox_spec.rb index ba410f31de..ad87b78061 100644 --- a/spec/ruby/library/cgi/htmlextension/checkbox_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/checkbox_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' require_relative 'fixtures/common' diff --git a/spec/ruby/library/cgi/htmlextension/doctype_spec.rb b/spec/ruby/library/cgi/htmlextension/doctype_spec.rb index 49501ac8f7..02af831855 100644 --- a/spec/ruby/library/cgi/htmlextension/doctype_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/doctype_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' require_relative 'fixtures/common' diff --git a/spec/ruby/library/cgi/htmlextension/file_field_spec.rb b/spec/ruby/library/cgi/htmlextension/file_field_spec.rb index b8ef0b2045..eff077b9a2 100644 --- a/spec/ruby/library/cgi/htmlextension/file_field_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/file_field_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' require_relative 'fixtures/common' diff --git a/spec/ruby/library/cgi/htmlextension/form_spec.rb b/spec/ruby/library/cgi/htmlextension/form_spec.rb index 510ce27b77..55ac63152b 100644 --- a/spec/ruby/library/cgi/htmlextension/form_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/form_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' require_relative 'fixtures/common' diff --git a/spec/ruby/library/cgi/htmlextension/frame_spec.rb b/spec/ruby/library/cgi/htmlextension/frame_spec.rb index 0dc30e94f7..fef40849eb 100644 --- a/spec/ruby/library/cgi/htmlextension/frame_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/frame_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require_relative 'fixtures/common' require 'cgi' diff --git a/spec/ruby/library/cgi/htmlextension/frameset_spec.rb b/spec/ruby/library/cgi/htmlextension/frameset_spec.rb index a37b5f537d..3ad0a9c4d2 100644 --- a/spec/ruby/library/cgi/htmlextension/frameset_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/frameset_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require_relative 'fixtures/common' require 'cgi' diff --git a/spec/ruby/library/cgi/htmlextension/hidden_spec.rb b/spec/ruby/library/cgi/htmlextension/hidden_spec.rb index 5771058fa3..b2323775f6 100644 --- a/spec/ruby/library/cgi/htmlextension/hidden_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/hidden_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' require_relative 'fixtures/common' diff --git a/spec/ruby/library/cgi/htmlextension/html_spec.rb b/spec/ruby/library/cgi/htmlextension/html_spec.rb index 0e4052dcc4..60a10fb6b4 100644 --- a/spec/ruby/library/cgi/htmlextension/html_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/html_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' require_relative 'fixtures/common' diff --git a/spec/ruby/library/cgi/htmlextension/image_button_spec.rb b/spec/ruby/library/cgi/htmlextension/image_button_spec.rb index cd7f1ae4f7..f8770119d4 100644 --- a/spec/ruby/library/cgi/htmlextension/image_button_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/image_button_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' require_relative 'fixtures/common' diff --git a/spec/ruby/library/cgi/htmlextension/img_spec.rb b/spec/ruby/library/cgi/htmlextension/img_spec.rb index 193d3dca26..a05cfdea48 100644 --- a/spec/ruby/library/cgi/htmlextension/img_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/img_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' require_relative 'fixtures/common' diff --git a/spec/ruby/library/cgi/htmlextension/multipart_form_spec.rb b/spec/ruby/library/cgi/htmlextension/multipart_form_spec.rb index e5c16f2475..4b56a7abfe 100644 --- a/spec/ruby/library/cgi/htmlextension/multipart_form_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/multipart_form_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' require_relative 'fixtures/common' @@ -11,7 +11,7 @@ ruby_version_is ""..."3.5" do end describe "when passed no arguments" do - it "returns a 'form'-element with it's enctype set to multipart" do + it "returns a 'form'-element with its enctype set to multipart" do output = @html.multipart_form output.should equal_element("FORM", { "ENCTYPE" => "multipart/form-data", "METHOD" => "post" }, "") end diff --git a/spec/ruby/library/cgi/htmlextension/password_field_spec.rb b/spec/ruby/library/cgi/htmlextension/password_field_spec.rb index a462bea015..0fefdd5c45 100644 --- a/spec/ruby/library/cgi/htmlextension/password_field_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/password_field_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' require_relative 'fixtures/common' diff --git a/spec/ruby/library/cgi/htmlextension/popup_menu_spec.rb b/spec/ruby/library/cgi/htmlextension/popup_menu_spec.rb index 0ec85e96df..7452d15317 100644 --- a/spec/ruby/library/cgi/htmlextension/popup_menu_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/popup_menu_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' require_relative 'fixtures/common' require_relative 'shared/popup_menu' diff --git a/spec/ruby/library/cgi/htmlextension/radio_button_spec.rb b/spec/ruby/library/cgi/htmlextension/radio_button_spec.rb index 865c16d232..8458685cdc 100644 --- a/spec/ruby/library/cgi/htmlextension/radio_button_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/radio_button_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' require_relative 'fixtures/common' diff --git a/spec/ruby/library/cgi/htmlextension/radio_group_spec.rb b/spec/ruby/library/cgi/htmlextension/radio_group_spec.rb index 7381e7183b..fd925a5165 100644 --- a/spec/ruby/library/cgi/htmlextension/radio_group_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/radio_group_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' require_relative 'fixtures/common' diff --git a/spec/ruby/library/cgi/htmlextension/reset_spec.rb b/spec/ruby/library/cgi/htmlextension/reset_spec.rb index d3a5c801fa..80e4441b16 100644 --- a/spec/ruby/library/cgi/htmlextension/reset_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/reset_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' require_relative 'fixtures/common' diff --git a/spec/ruby/library/cgi/htmlextension/scrolling_list_spec.rb b/spec/ruby/library/cgi/htmlextension/scrolling_list_spec.rb index aab52d7409..b565444679 100644 --- a/spec/ruby/library/cgi/htmlextension/scrolling_list_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/scrolling_list_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require_relative 'fixtures/common' require 'cgi' require_relative 'shared/popup_menu' diff --git a/spec/ruby/library/cgi/htmlextension/submit_spec.rb b/spec/ruby/library/cgi/htmlextension/submit_spec.rb index 3401b10356..bb6e079c4e 100644 --- a/spec/ruby/library/cgi/htmlextension/submit_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/submit_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' require_relative 'fixtures/common' diff --git a/spec/ruby/library/cgi/htmlextension/text_field_spec.rb b/spec/ruby/library/cgi/htmlextension/text_field_spec.rb index 4f63dbce59..37e13e3746 100644 --- a/spec/ruby/library/cgi/htmlextension/text_field_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/text_field_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' require_relative 'fixtures/common' diff --git a/spec/ruby/library/cgi/htmlextension/textarea_spec.rb b/spec/ruby/library/cgi/htmlextension/textarea_spec.rb index a3881796fd..99c6d3dd2d 100644 --- a/spec/ruby/library/cgi/htmlextension/textarea_spec.rb +++ b/spec/ruby/library/cgi/htmlextension/textarea_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' require_relative 'fixtures/common' diff --git a/spec/ruby/library/cgi/http_header_spec.rb b/spec/ruby/library/cgi/http_header_spec.rb index 173055718b..8d9f3fe9b8 100644 --- a/spec/ruby/library/cgi/http_header_spec.rb +++ b/spec/ruby/library/cgi/http_header_spec.rb @@ -1,6 +1,6 @@ require_relative '../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' require_relative 'shared/http_header' diff --git a/spec/ruby/library/cgi/initialize_spec.rb b/spec/ruby/library/cgi/initialize_spec.rb index d46b5a3564..6135522c54 100644 --- a/spec/ruby/library/cgi/initialize_spec.rb +++ b/spec/ruby/library/cgi/initialize_spec.rb @@ -1,11 +1,11 @@ require_relative '../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' describe "CGI#initialize" do it "is private" do - CGI.should have_private_instance_method(:initialize) + CGI.private_instance_methods(false).should.include?(:initialize) end end @@ -21,21 +21,21 @@ ruby_version_is ""..."3.5" do it "extends self with CGI::QueryExtension" do @cgi.send(:initialize) - @cgi.should be_kind_of(CGI::QueryExtension) + @cgi.should.is_a?(CGI::QueryExtension) end it "does not extend self with CGI::HtmlExtension" do @cgi.send(:initialize) - @cgi.should_not be_kind_of(CGI::HtmlExtension) + @cgi.should_not.is_a?(CGI::HtmlExtension) end it "does not extend self with any of the other HTML modules" do @cgi.send(:initialize) - @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) + @cgi.should_not.is_a?(CGI::HtmlExtension) + @cgi.should_not.is_a?(CGI::Html3) + @cgi.should_not.is_a?(CGI::Html4) + @cgi.should_not.is_a?(CGI::Html4Tr) + @cgi.should_not.is_a?(CGI::Html4Fr) end it "sets #cookies based on ENV['HTTP_COOKIE']" do @@ -86,51 +86,51 @@ ruby_version_is ""..."3.5" do it "extends self with CGI::QueryExtension" do @cgi.send(:initialize, "test") - @cgi.should be_kind_of(CGI::QueryExtension) + @cgi.should.is_a?(CGI::QueryExtension) 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.is_a?(CGI::Html3) + @cgi.should.is_a?(CGI::HtmlExtension) + @cgi.should.is_a?(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) + @cgi.should_not.is_a?(CGI::Html4) + @cgi.should_not.is_a?(CGI::Html4Tr) + @cgi.should_not.is_a?(CGI::Html4Fr) 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) + @cgi.should.is_a?(CGI::Html4) + @cgi.should.is_a?(CGI::HtmlExtension) + @cgi.should.is_a?(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) + @cgi.should_not.is_a?(CGI::Html3) + @cgi.should_not.is_a?(CGI::Html4Tr) + @cgi.should_not.is_a?(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) + @cgi.should.is_a?(CGI::Html4Tr) + @cgi.should.is_a?(CGI::HtmlExtension) + @cgi.should.is_a?(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) + @cgi.should_not.is_a?(CGI::Html3) + @cgi.should_not.is_a?(CGI::Html4) + @cgi.should_not.is_a?(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.is_a?(CGI::Html4Tr) + @cgi.should.is_a?(CGI::Html4Fr) + @cgi.should.is_a?(CGI::HtmlExtension) + @cgi.should.is_a?(CGI::QueryExtension) - @cgi.should_not be_kind_of(CGI::Html3) - @cgi.should_not be_kind_of(CGI::Html4) + @cgi.should_not.is_a?(CGI::Html3) + @cgi.should_not.is_a?(CGI::Html4) end end end diff --git a/spec/ruby/library/cgi/out_spec.rb b/spec/ruby/library/cgi/out_spec.rb index c79d000284..e9eaf5e151 100644 --- a/spec/ruby/library/cgi/out_spec.rb +++ b/spec/ruby/library/cgi/out_spec.rb @@ -1,6 +1,6 @@ require_relative '../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' describe "CGI#out" do @@ -48,7 +48,7 @@ ruby_version_is ""..."3.5" do end it "raises a LocalJumpError" do - -> { @cgi.out }.should raise_error(LocalJumpError) + -> { @cgi.out }.should.raise(LocalJumpError) end end end diff --git a/spec/ruby/library/cgi/parse_spec.rb b/spec/ruby/library/cgi/parse_spec.rb index d35d0d3365..f09270c195 100644 --- a/spec/ruby/library/cgi/parse_spec.rb +++ b/spec/ruby/library/cgi/parse_spec.rb @@ -1,6 +1,6 @@ require_relative '../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' describe "CGI.parse when passed String" do diff --git a/spec/ruby/library/cgi/pretty_spec.rb b/spec/ruby/library/cgi/pretty_spec.rb index 1fed3bbd2e..9df1611037 100644 --- a/spec/ruby/library/cgi/pretty_spec.rb +++ b/spec/ruby/library/cgi/pretty_spec.rb @@ -1,6 +1,6 @@ require_relative '../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' describe "CGI.pretty when passed html" do diff --git a/spec/ruby/library/cgi/print_spec.rb b/spec/ruby/library/cgi/print_spec.rb index 5057c280a0..f4f461c5c0 100644 --- a/spec/ruby/library/cgi/print_spec.rb +++ b/spec/ruby/library/cgi/print_spec.rb @@ -1,6 +1,6 @@ require_relative '../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' describe "CGI#print" do diff --git a/spec/ruby/library/cgi/queryextension/accept_charset_spec.rb b/spec/ruby/library/cgi/queryextension/accept_charset_spec.rb index 9bfc833a3b..be05f0c175 100644 --- a/spec/ruby/library/cgi/queryextension/accept_charset_spec.rb +++ b/spec/ruby/library/cgi/queryextension/accept_charset_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' describe "CGI::QueryExtension#accept_charset" do diff --git a/spec/ruby/library/cgi/queryextension/accept_encoding_spec.rb b/spec/ruby/library/cgi/queryextension/accept_encoding_spec.rb index f0d7f2058a..42eb4a49b5 100644 --- a/spec/ruby/library/cgi/queryextension/accept_encoding_spec.rb +++ b/spec/ruby/library/cgi/queryextension/accept_encoding_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' describe "CGI::QueryExtension#accept_encoding" do diff --git a/spec/ruby/library/cgi/queryextension/accept_language_spec.rb b/spec/ruby/library/cgi/queryextension/accept_language_spec.rb index e3dfcd0324..19f29c6345 100644 --- a/spec/ruby/library/cgi/queryextension/accept_language_spec.rb +++ b/spec/ruby/library/cgi/queryextension/accept_language_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' describe "CGI::QueryExtension#accept_language" do diff --git a/spec/ruby/library/cgi/queryextension/accept_spec.rb b/spec/ruby/library/cgi/queryextension/accept_spec.rb index 9370a885a4..dcae39a736 100644 --- a/spec/ruby/library/cgi/queryextension/accept_spec.rb +++ b/spec/ruby/library/cgi/queryextension/accept_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' describe "CGI::QueryExtension#accept" do diff --git a/spec/ruby/library/cgi/queryextension/auth_type_spec.rb b/spec/ruby/library/cgi/queryextension/auth_type_spec.rb index c858436037..75e9cdb27a 100644 --- a/spec/ruby/library/cgi/queryextension/auth_type_spec.rb +++ b/spec/ruby/library/cgi/queryextension/auth_type_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' describe "CGI::QueryExtension#auth_type" do diff --git a/spec/ruby/library/cgi/queryextension/cache_control_spec.rb b/spec/ruby/library/cgi/queryextension/cache_control_spec.rb index d42421126c..c4b727e671 100644 --- a/spec/ruby/library/cgi/queryextension/cache_control_spec.rb +++ b/spec/ruby/library/cgi/queryextension/cache_control_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' describe "CGI::QueryExtension#cache_control" do diff --git a/spec/ruby/library/cgi/queryextension/content_length_spec.rb b/spec/ruby/library/cgi/queryextension/content_length_spec.rb index 2e3dca6f58..bd02f3d8da 100644 --- a/spec/ruby/library/cgi/queryextension/content_length_spec.rb +++ b/spec/ruby/library/cgi/queryextension/content_length_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' describe "CGI::QueryExtension#content_length" do @@ -17,10 +17,10 @@ ruby_version_is ""..."3.5" do old_value = ENV['CONTENT_LENGTH'] begin ENV['CONTENT_LENGTH'] = nil - @cgi.content_length.should be_nil + @cgi.content_length.should == nil ENV['CONTENT_LENGTH'] = "100" - @cgi.content_length.should eql(100) + @cgi.content_length.should.eql?(100) ensure ENV['CONTENT_LENGTH'] = old_value end diff --git a/spec/ruby/library/cgi/queryextension/content_type_spec.rb b/spec/ruby/library/cgi/queryextension/content_type_spec.rb index ce1be28571..d3cbdf0b14 100644 --- a/spec/ruby/library/cgi/queryextension/content_type_spec.rb +++ b/spec/ruby/library/cgi/queryextension/content_type_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' describe "CGI::QueryExtension#content_type" do diff --git a/spec/ruby/library/cgi/queryextension/cookies_spec.rb b/spec/ruby/library/cgi/queryextension/cookies_spec.rb index 029ad5991a..266fe0c721 100644 --- a/spec/ruby/library/cgi/queryextension/cookies_spec.rb +++ b/spec/ruby/library/cgi/queryextension/cookies_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' describe "CGI::QueryExtension#cookies" do diff --git a/spec/ruby/library/cgi/queryextension/element_reference_spec.rb b/spec/ruby/library/cgi/queryextension/element_reference_spec.rb index df1c372ab7..c835f385f0 100644 --- a/spec/ruby/library/cgi/queryextension/element_reference_spec.rb +++ b/spec/ruby/library/cgi/queryextension/element_reference_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' describe "CGI::QueryExtension#[]" do @@ -24,7 +24,7 @@ ruby_version_is ""..."3.5" do end it "returns a String" do - @cgi["one"].should be_kind_of(String) + @cgi["one"].should.is_a?(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 8d278f5318..b341e0be10 100644 --- a/spec/ruby/library/cgi/queryextension/from_spec.rb +++ b/spec/ruby/library/cgi/queryextension/from_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' describe "CGI::QueryExtension#from" do diff --git a/spec/ruby/library/cgi/queryextension/gateway_interface_spec.rb b/spec/ruby/library/cgi/queryextension/gateway_interface_spec.rb index d519b80e32..c82522326b 100644 --- a/spec/ruby/library/cgi/queryextension/gateway_interface_spec.rb +++ b/spec/ruby/library/cgi/queryextension/gateway_interface_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' describe "CGI::QueryExtension#gateway_interface" do diff --git a/spec/ruby/library/cgi/queryextension/has_key_spec.rb b/spec/ruby/library/cgi/queryextension/has_key_spec.rb index 5892ecaf77..43f7aae1b2 100644 --- a/spec/ruby/library/cgi/queryextension/has_key_spec.rb +++ b/spec/ruby/library/cgi/queryextension/has_key_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' require_relative 'shared/has_key' diff --git a/spec/ruby/library/cgi/queryextension/host_spec.rb b/spec/ruby/library/cgi/queryextension/host_spec.rb index 2eaf1330c0..e1047c942b 100644 --- a/spec/ruby/library/cgi/queryextension/host_spec.rb +++ b/spec/ruby/library/cgi/queryextension/host_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' describe "CGI::QueryExtension#host" do diff --git a/spec/ruby/library/cgi/queryextension/include_spec.rb b/spec/ruby/library/cgi/queryextension/include_spec.rb index 18520c4aaf..7275c309f9 100644 --- a/spec/ruby/library/cgi/queryextension/include_spec.rb +++ b/spec/ruby/library/cgi/queryextension/include_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' require_relative 'shared/has_key' diff --git a/spec/ruby/library/cgi/queryextension/key_spec.rb b/spec/ruby/library/cgi/queryextension/key_spec.rb index c8c5870eba..dc2f52fbe0 100644 --- a/spec/ruby/library/cgi/queryextension/key_spec.rb +++ b/spec/ruby/library/cgi/queryextension/key_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' require_relative 'shared/has_key' diff --git a/spec/ruby/library/cgi/queryextension/keys_spec.rb b/spec/ruby/library/cgi/queryextension/keys_spec.rb index 0c35404103..bb16914065 100644 --- a/spec/ruby/library/cgi/queryextension/keys_spec.rb +++ b/spec/ruby/library/cgi/queryextension/keys_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' describe "CGI::QueryExtension#keys" do diff --git a/spec/ruby/library/cgi/queryextension/multipart_spec.rb b/spec/ruby/library/cgi/queryextension/multipart_spec.rb index 72c8073a5a..1fa771ca1c 100644 --- a/spec/ruby/library/cgi/queryextension/multipart_spec.rb +++ b/spec/ruby/library/cgi/queryextension/multipart_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' require "stringio" @@ -37,7 +37,7 @@ EOS end it "returns true if the current Request is a multipart request" do - @cgi.multipart?.should be_true + @cgi.multipart?.should == 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 c159c6cfe2..4083e6a8cd 100644 --- a/spec/ruby/library/cgi/queryextension/negotiate_spec.rb +++ b/spec/ruby/library/cgi/queryextension/negotiate_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' describe "CGI::QueryExtension#negotiate" do diff --git a/spec/ruby/library/cgi/queryextension/params_spec.rb b/spec/ruby/library/cgi/queryextension/params_spec.rb index e8b447f227..938028ea14 100644 --- a/spec/ruby/library/cgi/queryextension/params_spec.rb +++ b/spec/ruby/library/cgi/queryextension/params_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' describe "CGI::QueryExtension#params" do diff --git a/spec/ruby/library/cgi/queryextension/path_info_spec.rb b/spec/ruby/library/cgi/queryextension/path_info_spec.rb index 9054f1cfd3..9b7834c514 100644 --- a/spec/ruby/library/cgi/queryextension/path_info_spec.rb +++ b/spec/ruby/library/cgi/queryextension/path_info_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' describe "CGI::QueryExtension#path_info" do diff --git a/spec/ruby/library/cgi/queryextension/path_translated_spec.rb b/spec/ruby/library/cgi/queryextension/path_translated_spec.rb index 4b17f6c01b..a773aaafdb 100644 --- a/spec/ruby/library/cgi/queryextension/path_translated_spec.rb +++ b/spec/ruby/library/cgi/queryextension/path_translated_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' describe "CGI::QueryExtension#path_translated" do diff --git a/spec/ruby/library/cgi/queryextension/pragma_spec.rb b/spec/ruby/library/cgi/queryextension/pragma_spec.rb index c6a9c5b973..be384182a5 100644 --- a/spec/ruby/library/cgi/queryextension/pragma_spec.rb +++ b/spec/ruby/library/cgi/queryextension/pragma_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' describe "CGI::QueryExtension#pragma" do diff --git a/spec/ruby/library/cgi/queryextension/query_string_spec.rb b/spec/ruby/library/cgi/queryextension/query_string_spec.rb index ef3cb9c8fb..64fbeaea10 100644 --- a/spec/ruby/library/cgi/queryextension/query_string_spec.rb +++ b/spec/ruby/library/cgi/queryextension/query_string_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' describe "CGI::QueryExtension#query_string" do diff --git a/spec/ruby/library/cgi/queryextension/raw_cookie2_spec.rb b/spec/ruby/library/cgi/queryextension/raw_cookie2_spec.rb index 07ef00e8c5..30d314aca1 100644 --- a/spec/ruby/library/cgi/queryextension/raw_cookie2_spec.rb +++ b/spec/ruby/library/cgi/queryextension/raw_cookie2_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' describe "CGI::QueryExtension#raw_cookie2" do diff --git a/spec/ruby/library/cgi/queryextension/raw_cookie_spec.rb b/spec/ruby/library/cgi/queryextension/raw_cookie_spec.rb index f1ebb8ad82..affa504b39 100644 --- a/spec/ruby/library/cgi/queryextension/raw_cookie_spec.rb +++ b/spec/ruby/library/cgi/queryextension/raw_cookie_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' describe "CGI::QueryExtension#raw_cookie" do diff --git a/spec/ruby/library/cgi/queryextension/referer_spec.rb b/spec/ruby/library/cgi/queryextension/referer_spec.rb index 737253eac9..53fc19ddd0 100644 --- a/spec/ruby/library/cgi/queryextension/referer_spec.rb +++ b/spec/ruby/library/cgi/queryextension/referer_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' describe "CGI::QueryExtension#referer" do diff --git a/spec/ruby/library/cgi/queryextension/remote_addr_spec.rb b/spec/ruby/library/cgi/queryextension/remote_addr_spec.rb index e2cc696ae2..7b5addc2d5 100644 --- a/spec/ruby/library/cgi/queryextension/remote_addr_spec.rb +++ b/spec/ruby/library/cgi/queryextension/remote_addr_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' describe "CGI::QueryExtension#remote_addr" do diff --git a/spec/ruby/library/cgi/queryextension/remote_host_spec.rb b/spec/ruby/library/cgi/queryextension/remote_host_spec.rb index c4db9e4ffe..2dfe59ca38 100644 --- a/spec/ruby/library/cgi/queryextension/remote_host_spec.rb +++ b/spec/ruby/library/cgi/queryextension/remote_host_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' describe "CGI::QueryExtension#remote_host" do diff --git a/spec/ruby/library/cgi/queryextension/remote_ident_spec.rb b/spec/ruby/library/cgi/queryextension/remote_ident_spec.rb index d507b7d7be..bb05fc7942 100644 --- a/spec/ruby/library/cgi/queryextension/remote_ident_spec.rb +++ b/spec/ruby/library/cgi/queryextension/remote_ident_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' describe "CGI::QueryExtension#remote_ident" do diff --git a/spec/ruby/library/cgi/queryextension/remote_user_spec.rb b/spec/ruby/library/cgi/queryextension/remote_user_spec.rb index ceee410797..29856302ab 100644 --- a/spec/ruby/library/cgi/queryextension/remote_user_spec.rb +++ b/spec/ruby/library/cgi/queryextension/remote_user_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' describe "CGI::QueryExtension#remote_user" do diff --git a/spec/ruby/library/cgi/queryextension/request_method_spec.rb b/spec/ruby/library/cgi/queryextension/request_method_spec.rb index b540280261..7331b134d2 100644 --- a/spec/ruby/library/cgi/queryextension/request_method_spec.rb +++ b/spec/ruby/library/cgi/queryextension/request_method_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' describe "CGI::QueryExtension#request_method" do diff --git a/spec/ruby/library/cgi/queryextension/script_name_spec.rb b/spec/ruby/library/cgi/queryextension/script_name_spec.rb index 49a7847eff..4b359a545f 100644 --- a/spec/ruby/library/cgi/queryextension/script_name_spec.rb +++ b/spec/ruby/library/cgi/queryextension/script_name_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' describe "CGI::QueryExtension#script_name" do diff --git a/spec/ruby/library/cgi/queryextension/server_name_spec.rb b/spec/ruby/library/cgi/queryextension/server_name_spec.rb index ee5d754ad3..c1f7fb4c54 100644 --- a/spec/ruby/library/cgi/queryextension/server_name_spec.rb +++ b/spec/ruby/library/cgi/queryextension/server_name_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' describe "CGI::QueryExtension#server_name" do diff --git a/spec/ruby/library/cgi/queryextension/server_port_spec.rb b/spec/ruby/library/cgi/queryextension/server_port_spec.rb index c4f8df78cf..1c88d3225d 100644 --- a/spec/ruby/library/cgi/queryextension/server_port_spec.rb +++ b/spec/ruby/library/cgi/queryextension/server_port_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' describe "CGI::QueryExtension#server_port" do @@ -17,10 +17,10 @@ ruby_version_is ""..."3.5" do old_value = ENV['SERVER_PORT'] begin ENV['SERVER_PORT'] = nil - @cgi.server_port.should be_nil + @cgi.server_port.should == nil ENV['SERVER_PORT'] = "3000" - @cgi.server_port.should eql(3000) + @cgi.server_port.should.eql?(3000) ensure ENV['SERVER_PORT'] = old_value end diff --git a/spec/ruby/library/cgi/queryextension/server_protocol_spec.rb b/spec/ruby/library/cgi/queryextension/server_protocol_spec.rb index 35d3b8add1..fdbcc2108f 100644 --- a/spec/ruby/library/cgi/queryextension/server_protocol_spec.rb +++ b/spec/ruby/library/cgi/queryextension/server_protocol_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' describe "CGI::QueryExtension#server_protocol" do diff --git a/spec/ruby/library/cgi/queryextension/server_software_spec.rb b/spec/ruby/library/cgi/queryextension/server_software_spec.rb index d4fcceb379..c5811a2268 100644 --- a/spec/ruby/library/cgi/queryextension/server_software_spec.rb +++ b/spec/ruby/library/cgi/queryextension/server_software_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' describe "CGI::QueryExtension#server_software" do diff --git a/spec/ruby/library/cgi/queryextension/shared/has_key.rb b/spec/ruby/library/cgi/queryextension/shared/has_key.rb index cfac5865fa..6231cb548e 100644 --- a/spec/ruby/library/cgi/queryextension/shared/has_key.rb +++ b/spec/ruby/library/cgi/queryextension/shared/has_key.rb @@ -12,8 +12,8 @@ describe :cgi_query_extension_has_key_p, shared: true do end it "returns true when the passed key exists in the HTTP Query" do - @cgi.send(@method, "one").should be_true - @cgi.send(@method, "two").should be_true - @cgi.send(@method, "three").should be_false + @cgi.send(@method, "one").should == true + @cgi.send(@method, "two").should == true + @cgi.send(@method, "three").should == false 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 070a779123..3240352ef6 100644 --- a/spec/ruby/library/cgi/queryextension/user_agent_spec.rb +++ b/spec/ruby/library/cgi/queryextension/user_agent_spec.rb @@ -1,6 +1,6 @@ require_relative '../../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' describe "CGI::QueryExtension#user_agent" do diff --git a/spec/ruby/library/cgi/rfc1123_date_spec.rb b/spec/ruby/library/cgi/rfc1123_date_spec.rb index 2641b40e94..636185f22c 100644 --- a/spec/ruby/library/cgi/rfc1123_date_spec.rb +++ b/spec/ruby/library/cgi/rfc1123_date_spec.rb @@ -1,6 +1,6 @@ require_relative '../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' describe "CGI.rfc1123_date when passed Time" do diff --git a/spec/ruby/library/cgi/shared/http_header.rb b/spec/ruby/library/cgi/shared/http_header.rb index b225b5925e..e739fed538 100644 --- a/spec/ruby/library/cgi/shared/http_header.rb +++ b/spec/ruby/library/cgi/shared/http_header.rb @@ -63,11 +63,11 @@ describe :cgi_http_header, shared: true do header.should == "Content-Type: text/plain; charset=UTF-8\r\n\r\n" header = @cgi.send(@method, "nph" => true) - header.should include("HTTP/1.0 200 OK\r\n") - header.should include("Date: ") - header.should include("Server: ") - header.should include("Connection: close\r\n") - header.should include("Content-Type: text/html\r\n") + header.should.include?("HTTP/1.0 200 OK\r\n") + header.should.include?("Date: ") + header.should.include?("Server: ") + header.should.include?("Connection: close\r\n") + header.should.include?("Content-Type: text/html\r\n") header = @cgi.send(@method, "status" => "OK") header.should == "Status: 200 OK\r\nContent-Type: text/html\r\n\r\n" diff --git a/spec/ruby/library/cgi/unescapeElement_spec.rb b/spec/ruby/library/cgi/unescapeElement_spec.rb index af2fa8a47d..db83f0d2fb 100644 --- a/spec/ruby/library/cgi/unescapeElement_spec.rb +++ b/spec/ruby/library/cgi/unescapeElement_spec.rb @@ -1,9 +1,9 @@ require_relative '../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' end -ruby_version_is "3.5" do +ruby_version_is "4.0" do require 'cgi/escape' end diff --git a/spec/ruby/library/cgi/unescapeURIComponent_spec.rb b/spec/ruby/library/cgi/unescapeURIComponent_spec.rb new file mode 100644 index 0000000000..e0bf4b70e0 --- /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(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 == 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 == 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(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 e750c72921..aa731b9367 100644 --- a/spec/ruby/library/cgi/unescape_spec.rb +++ b/spec/ruby/library/cgi/unescape_spec.rb @@ -1,10 +1,10 @@ # -*- encoding: utf-8 -*- require_relative '../../spec_helper' -ruby_version_is ""..."3.5" do +ruby_version_is ""..."4.0" do require 'cgi' end -ruby_version_is "3.5" do +ruby_version_is "4.0" do require 'cgi/escape' end diff --git a/spec/ruby/library/coverage/result_spec.rb b/spec/ruby/library/coverage/result_spec.rb index 0101eb6a64..2e7d598bb8 100644 --- a/spec/ruby/library/coverage/result_spec.rb +++ b/spec/ruby/library/coverage/result_spec.rb @@ -80,7 +80,7 @@ describe 'Coverage.result' do Coverage.result -> { Coverage.result - }.should raise_error(RuntimeError, 'coverage measurement is not enabled') + }.should.raise(RuntimeError, 'coverage measurement is not enabled') end it 'second run should give same result' do @@ -108,7 +108,7 @@ describe 'Coverage.result' do 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) + Coverage.result.should_not.include?(@config_file) end it 'returns the correct results when eval coverage is enabled' do diff --git a/spec/ruby/library/coverage/start_spec.rb b/spec/ruby/library/coverage/start_spec.rb index c921b85401..11777347a2 100644 --- a/spec/ruby/library/coverage/start_spec.rb +++ b/spec/ruby/library/coverage/start_spec.rb @@ -24,7 +24,7 @@ describe 'Coverage.start' do -> { Coverage.start - }.should raise_error(RuntimeError, 'coverage measurement is already setup') + }.should.raise(RuntimeError, 'coverage measurement is already setup') end it "accepts :all optional argument" do @@ -65,13 +65,13 @@ describe 'Coverage.start' do it "expects a Hash if not passed :all" do -> { Coverage.start(42) - }.should raise_error(TypeError, "no implicit conversion of Integer into Hash") + }.should.raise(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") + }.should.raise(RuntimeError, "cannot enable lines and oneshot_lines simultaneously") end it "enables the coverage measurement if passed options with `false` value" do diff --git a/spec/ruby/library/coverage/supported_spec.rb b/spec/ruby/library/coverage/supported_spec.rb index 9226548c1f..fcf8a76d79 100644 --- a/spec/ruby/library/coverage/supported_spec.rb +++ b/spec/ruby/library/coverage/supported_spec.rb @@ -17,14 +17,14 @@ describe "Coverage.supported?" do it "raise TypeError if argument is not Symbol" do -> { Coverage.supported?("lines") - }.should raise_error(TypeError, "wrong argument type String (expected Symbol)") + }.should.raise(TypeError, "wrong argument type String (expected Symbol)") -> { Coverage.supported?([]) - }.should raise_error(TypeError, "wrong argument type Array (expected Symbol)") + }.should.raise(TypeError, "wrong argument type Array (expected Symbol)") -> { Coverage.supported?(1) - }.should raise_error(TypeError, "wrong argument type Integer (expected Symbol)") + }.should.raise(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 b45e2eb95b..62e19aa6e4 100644 --- a/spec/ruby/library/csv/generate_spec.rb +++ b/spec/ruby/library/csv/generate_spec.rb @@ -26,7 +26,7 @@ describe "CSV.generate" do csv.add_row [1, 2, 3] csv << [4, 5, 6] end - csv_str.should equal str + csv_str.should.equal? str str.should == "1,2,3\n4,5,6\n" end end diff --git a/spec/ruby/library/csv/parse_spec.rb b/spec/ruby/library/csv/parse_spec.rb index ef5d4ea3ca..7000f03cda 100644 --- a/spec/ruby/library/csv/parse_spec.rb +++ b/spec/ruby/library/csv/parse_spec.rb @@ -5,7 +5,7 @@ describe "CSV.parse" do it "parses '' into []" do result = CSV.parse '' - result.should be_kind_of(Array) + result.should.is_a?(Array) result.should == [] end @@ -82,7 +82,7 @@ describe "CSV.parse" do it "raises CSV::MalformedCSVError exception if input is illegal" do -> { CSV.parse('"quoted" field') - }.should raise_error(CSV::MalformedCSVError) + }.should.raise(CSV::MalformedCSVError) end it "handles illegal input with the liberal_parsing option" do diff --git a/spec/ruby/library/csv/readlines_spec.rb b/spec/ruby/library/csv/readlines_spec.rb index 14dea34381..624f906489 100644 --- a/spec/ruby/library/csv/readlines_spec.rb +++ b/spec/ruby/library/csv/readlines_spec.rb @@ -23,7 +23,7 @@ describe "CSV#readlines" do it "raises CSV::MalformedCSVError exception if input is illegal" do csv = CSV.new('"quoted" field') - -> { csv.readlines }.should raise_error(CSV::MalformedCSVError) + -> { csv.readlines }.should.raise(CSV::MalformedCSVError) end it "handles illegal input with the liberal_parsing option" do diff --git a/spec/ruby/library/date/add_month_spec.rb b/spec/ruby/library/date/add_month_spec.rb index 40833f6487..ab802ea97a 100644 --- a/spec/ruby/library/date/add_month_spec.rb +++ b/spec/ruby/library/date/add_month_spec.rb @@ -21,18 +21,18 @@ describe "Date#>>" do end it "raise a TypeError when passed a Symbol" do - -> { Date.civil(2007,2,27) >> :hello }.should raise_error(TypeError) + -> { Date.civil(2007,2,27) >> :hello }.should.raise(TypeError) end it "raise a TypeError when passed a String" do - -> { Date.civil(2007,2,27) >> "hello" }.should raise_error(TypeError) + -> { Date.civil(2007,2,27) >> "hello" }.should.raise(TypeError) end it "raise a TypeError when passed a Date" do - -> { Date.civil(2007,2,27) >> Date.new }.should raise_error(TypeError) + -> { Date.civil(2007,2,27) >> Date.new }.should.raise(TypeError) end it "raise a TypeError when passed an Object" do - -> { Date.civil(2007,2,27) >> Object.new }.should raise_error(TypeError) + -> { Date.civil(2007,2,27) >> Object.new }.should.raise(TypeError) end end diff --git a/spec/ruby/library/date/add_spec.rb b/spec/ruby/library/date/add_spec.rb index 2b9cc62023..5e368decdc 100644 --- a/spec/ruby/library/date/add_spec.rb +++ b/spec/ruby/library/date/add_spec.rb @@ -13,18 +13,18 @@ describe "Date#+" do end it "raises a TypeError when passed a Symbol" do - -> { Date.civil(2007,2,27) + :hello }.should raise_error(TypeError) + -> { Date.civil(2007,2,27) + :hello }.should.raise(TypeError) end it "raises a TypeError when passed a String" do - -> { Date.civil(2007,2,27) + "hello" }.should raise_error(TypeError) + -> { Date.civil(2007,2,27) + "hello" }.should.raise(TypeError) end it "raises a TypeError when passed a Date" do - -> { Date.civil(2007,2,27) + Date.new }.should raise_error(TypeError) + -> { Date.civil(2007,2,27) + Date.new }.should.raise(TypeError) end it "raises a TypeError when passed an Object" do - -> { Date.civil(2007,2,27) + Object.new }.should raise_error(TypeError) + -> { Date.civil(2007,2,27) + Object.new }.should.raise(TypeError) end end diff --git a/spec/ruby/library/date/asctime_spec.rb b/spec/ruby/library/date/asctime_spec.rb index 67d158cc01..e268ffe098 100644 --- a/spec/ruby/library/date/asctime_spec.rb +++ b/spec/ruby/library/date/asctime_spec.rb @@ -2,5 +2,8 @@ require_relative '../../spec_helper' require 'date' describe "Date#asctime" do - it "needs to be reviewed for spec completeness" + it "returns a canonical string representation of date" do + d = Date.today + d.asctime.should == d.strftime("%a %b %e %H:%M:%S %Y") + end end diff --git a/spec/ruby/library/date/commercial_spec.rb b/spec/ruby/library/date/commercial_spec.rb index d7fc34d74a..8e2df79b90 100644 --- a/spec/ruby/library/date/commercial_spec.rb +++ b/spec/ruby/library/date/commercial_spec.rb @@ -1,12 +1,5 @@ require 'date' require_relative '../../spec_helper' -require_relative 'shared/commercial' - -describe "Date#commercial" do - - it_behaves_like :date_commercial, :commercial - -end # reference: # October 1582 (the Gregorian calendar, Civil Date) @@ -15,3 +8,42 @@ end # 17 18 19 20 21 22 23 # 24 25 26 27 28 29 30 # 31 +describe "Date.commercial" do + it "creates a Date for Julian Day Number day 0 by default" do + d = Date.commercial + d.year.should == -4712 + d.month.should == 1 + d.day.should == 1 + end + + it "creates a Date for the monday in the year and week given" do + d = Date.commercial(2000, 1) + d.year.should == 2000 + d.month.should == 1 + d.day.should == 3 + d.cwday.should == 1 + end + + it "creates a Date for the correct day given the year, week and day number" do + d = Date.commercial(2004, 1, 1) + d.year.should == 2003 + d.month.should == 12 + d.day.should == 29 + d.cwday.should == 1 + d.cweek.should == 1 + d.cwyear.should == 2004 + end + + it "creates only Date objects for valid weeks" do + -> { Date.commercial(2004, 53, 1) }.should_not.raise(ArgumentError) + -> { Date.commercial(2004, 53, 0) }.should.raise(ArgumentError) + -> { Date.commercial(2004, 53, 8) }.should.raise(ArgumentError) + -> { Date.commercial(2004, 54, 1) }.should.raise(ArgumentError) + -> { Date.commercial(2004, 0, 1) }.should.raise(ArgumentError) + + -> { Date.commercial(2003, 52, 1) }.should_not.raise(ArgumentError) + -> { Date.commercial(2003, 53, 1) }.should.raise(ArgumentError) + -> { Date.commercial(2003, 52, 0) }.should.raise(ArgumentError) + -> { Date.commercial(2003, 52, 8) }.should.raise(ArgumentError) + end +end diff --git a/spec/ruby/library/date/constants_spec.rb b/spec/ruby/library/date/constants_spec.rb index 1d18dd1b0c..3494b0c296 100644 --- a/spec/ruby/library/date/constants_spec.rb +++ b/spec/ruby/library/date/constants_spec.rb @@ -36,11 +36,11 @@ describe "Date constants" do [Date::MONTHNAMES, Date::DAYNAMES, Date::ABBR_MONTHNAMES, Date::ABBR_DAYNAMES].each do |ary| -> { ary << "Unknown" - }.should raise_error(FrozenError, /frozen/) + }.should.raise(FrozenError, /frozen/) ary.compact.each do |name| -> { name << "modified" - }.should raise_error(FrozenError, /frozen/) + }.should.raise(FrozenError, /frozen/) end end end diff --git a/spec/ruby/library/date/ctime_spec.rb b/spec/ruby/library/date/ctime_spec.rb index 3faa7c6380..330076a735 100644 --- a/spec/ruby/library/date/ctime_spec.rb +++ b/spec/ruby/library/date/ctime_spec.rb @@ -2,5 +2,7 @@ require_relative '../../spec_helper' require 'date' describe "Date#ctime" do - it "needs to be reviewed for spec completeness" + it "is an alias of Date#asctime" do + Date.instance_method(:ctime).should == Date.instance_method(:asctime) + end end diff --git a/spec/ruby/library/date/deconstruct_keys_spec.rb b/spec/ruby/library/date/deconstruct_keys_spec.rb index b9dd6b8816..1fa1e70250 100644 --- a/spec/ruby/library/date/deconstruct_keys_spec.rb +++ b/spec/ruby/library/date/deconstruct_keys_spec.rb @@ -16,16 +16,16 @@ describe "Date#deconstruct_keys" do it "requires one argument" do -> { Date.new(2022, 10, 5).deconstruct_keys - }.should raise_error(ArgumentError) + }.should.raise(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)") + -> { d.deconstruct_keys(1) }.should.raise(TypeError, "wrong argument type Integer (expected Array or nil)") + -> { d.deconstruct_keys("asd") }.should.raise(TypeError, "wrong argument type String (expected Array or nil)") + -> { d.deconstruct_keys(:x) }.should.raise(TypeError, "wrong argument type Symbol (expected Array or nil)") + -> { d.deconstruct_keys({}) }.should.raise(TypeError, "wrong argument type Hash (expected Array or nil)") end it "returns {} when passed []" do diff --git a/spec/ruby/library/date/eql_spec.rb b/spec/ruby/library/date/eql_spec.rb index a1819cae3a..79fabc47f4 100644 --- a/spec/ruby/library/date/eql_spec.rb +++ b/spec/ruby/library/date/eql_spec.rb @@ -3,10 +3,10 @@ require 'date' describe "Date#eql?" do it "returns true if self is equal to another date" do - Date.civil(2007, 10, 11).eql?(Date.civil(2007, 10, 11)).should be_true + Date.civil(2007, 10, 11).eql?(Date.civil(2007, 10, 11)).should == true end it "returns false if self is not equal to another date" do - Date.civil(2007, 10, 11).eql?(Date.civil(2007, 10, 12)).should be_false + Date.civil(2007, 10, 11).eql?(Date.civil(2007, 10, 12)).should == false end end diff --git a/spec/ruby/library/date/friday_spec.rb b/spec/ruby/library/date/friday_spec.rb index 3dc040fabe..62f050346e 100644 --- a/spec/ruby/library/date/friday_spec.rb +++ b/spec/ruby/library/date/friday_spec.rb @@ -3,10 +3,10 @@ require 'date' describe "Date#friday?" do it "should be friday" do - Date.new(2000, 1, 7).friday?.should be_true + Date.new(2000, 1, 7).friday?.should == true end it "should not be friday" do - Date.new(2000, 1, 8).friday?.should be_false + Date.new(2000, 1, 8).friday?.should == false end end diff --git a/spec/ruby/library/date/gregorian_leap_spec.rb b/spec/ruby/library/date/gregorian_leap_spec.rb index c3d25cf90f..c27890faf4 100644 --- a/spec/ruby/library/date/gregorian_leap_spec.rb +++ b/spec/ruby/library/date/gregorian_leap_spec.rb @@ -3,13 +3,13 @@ require 'date' describe "Date#gregorian_leap?" do it "returns true if a year is a leap year in the Gregorian calendar" do - Date.gregorian_leap?(2000).should be_true - Date.gregorian_leap?(2004).should be_true + Date.gregorian_leap?(2000).should == true + Date.gregorian_leap?(2004).should == true end it "returns false if a year is not a leap year in the Gregorian calendar" do - Date.gregorian_leap?(1900).should be_false - Date.gregorian_leap?(1999).should be_false - Date.gregorian_leap?(2002).should be_false + Date.gregorian_leap?(1900).should == false + Date.gregorian_leap?(1999).should == false + Date.gregorian_leap?(2002).should == false end end diff --git a/spec/ruby/library/date/gregorian_spec.rb b/spec/ruby/library/date/gregorian_spec.rb index ea7ece2ade..bbda13af08 100644 --- a/spec/ruby/library/date/gregorian_spec.rb +++ b/spec/ruby/library/date/gregorian_spec.rb @@ -4,13 +4,13 @@ require 'date' describe "Date#gregorian?" do it "marks a day before the calendar reform as Julian" do - Date.civil(1007, 2, 27).gregorian?.should be_false - Date.civil(1907, 2, 27, Date.civil(1930, 1, 1).jd).gregorian?.should be_false + Date.civil(1007, 2, 27).gregorian?.should == false + Date.civil(1907, 2, 27, Date.civil(1930, 1, 1).jd).gregorian?.should == false end it "marks a day after the calendar reform as Julian" do Date.civil(2007, 2, 27).should.gregorian? - Date.civil(1607, 2, 27, Date.civil(1582, 1, 1).jd).gregorian?.should be_true + Date.civil(1607, 2, 27, Date.civil(1582, 1, 1).jd).gregorian?.should == true end end diff --git a/spec/ruby/library/date/iso8601_spec.rb b/spec/ruby/library/date/iso8601_spec.rb index af66845a6b..26815bd76c 100644 --- a/spec/ruby/library/date/iso8601_spec.rb +++ b/spec/ruby/library/date/iso8601_spec.rb @@ -25,17 +25,17 @@ describe "Date.iso8601" do it "raises a Date::Error if the argument is a invalid Date" do -> { Date.iso8601('invalid') - }.should raise_error(Date::Error, "invalid date") + }.should.raise(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") + }.should.raise(Date::Error, "invalid date") end it "raises a TypeError when passed an Object" do - -> { Date.iso8601(Object.new) }.should raise_error(TypeError) + -> { Date.iso8601(Object.new) }.should.raise(TypeError) end end @@ -51,6 +51,6 @@ describe "Date._iso8601" do end it "raises a TypeError when passed an Object" do - -> { Date._iso8601(Object.new) }.should raise_error(TypeError) + -> { Date._iso8601(Object.new) }.should.raise(TypeError) end end diff --git a/spec/ruby/library/date/jd_spec.rb b/spec/ruby/library/date/jd_spec.rb index 336b783e8d..e5cfe10eff 100644 --- a/spec/ruby/library/date/jd_spec.rb +++ b/spec/ruby/library/date/jd_spec.rb @@ -1,15 +1,22 @@ require_relative '../../spec_helper' -require_relative 'shared/jd' require 'date' describe "Date#jd" do - it "determines the Julian day for a Date object" do Date.civil(2008, 1, 16).jd.should == 2454482 end - end describe "Date.jd" do - it_behaves_like :date_jd, :jd + it "constructs a Date object if passed a Julian day" do + Date.jd(2454482).should == Date.civil(2008, 1, 16) + end + + it "returns a Date object representing Julian day 0 (-4712-01-01) if no arguments passed" do + Date.jd.should == Date.civil(-4712, 1, 1) + end + + it "constructs a Date object if passed a negative number" do + Date.jd(-1).should == Date.civil(-4713, 12, 31) + end end diff --git a/spec/ruby/library/date/julian_leap_spec.rb b/spec/ruby/library/date/julian_leap_spec.rb index 2ef2d65d81..42231e012f 100644 --- a/spec/ruby/library/date/julian_leap_spec.rb +++ b/spec/ruby/library/date/julian_leap_spec.rb @@ -3,13 +3,13 @@ require 'date' describe "Date.julian_leap?" do it "determines whether a year is a leap year in the Julian calendar" do - Date.julian_leap?(1900).should be_true - Date.julian_leap?(2000).should be_true - Date.julian_leap?(2004).should be_true + Date.julian_leap?(1900).should == true + Date.julian_leap?(2000).should == true + Date.julian_leap?(2004).should == true end it "determines whether a year is not a leap year in the Julian calendar" do - Date.julian_leap?(1999).should be_false - Date.julian_leap?(2002).should be_false + Date.julian_leap?(1999).should == false + Date.julian_leap?(2002).should == false end end diff --git a/spec/ruby/library/date/julian_spec.rb b/spec/ruby/library/date/julian_spec.rb index db2629d1e7..9f8a670899 100644 --- a/spec/ruby/library/date/julian_spec.rb +++ b/spec/ruby/library/date/julian_spec.rb @@ -5,12 +5,12 @@ describe "Date#julian?" do it "marks a day before the calendar reform as Julian" do Date.civil(1007, 2, 27).should.julian? - Date.civil(1907, 2, 27, Date.civil(1930, 1, 1).jd).julian?.should be_true + Date.civil(1907, 2, 27, Date.civil(1930, 1, 1).jd).julian?.should == true end it "marks a day after the calendar reform as Julian" do Date.civil(2007, 2, 27).should_not.julian? - Date.civil(1607, 2, 27, Date.civil(1582, 1, 1).jd).julian?.should be_false + Date.civil(1607, 2, 27, Date.civil(1582, 1, 1).jd).julian?.should == false end end diff --git a/spec/ruby/library/date/mday_spec.rb b/spec/ruby/library/date/mday_spec.rb index 53f6f98169..32fd8fc7f1 100644 --- a/spec/ruby/library/date/mday_spec.rb +++ b/spec/ruby/library/date/mday_spec.rb @@ -2,5 +2,7 @@ require_relative '../../spec_helper' require 'date' describe "Date#mday" do - it "needs to be reviewed for spec completeness" + it "is an alias of Date#day" do + Date.instance_method(:mday).should == Date.instance_method(:day) + end end diff --git a/spec/ruby/library/date/minus_month_spec.rb b/spec/ruby/library/date/minus_month_spec.rb index 470c4d8a76..d56e19dc31 100644 --- a/spec/ruby/library/date/minus_month_spec.rb +++ b/spec/ruby/library/date/minus_month_spec.rb @@ -14,10 +14,10 @@ describe "Date#<<" do end it "raises an error on non numeric parameters" do - -> { Date.civil(2007,2,27) << :hello }.should raise_error(TypeError) - -> { Date.civil(2007,2,27) << "hello" }.should raise_error(TypeError) - -> { Date.civil(2007,2,27) << Date.new }.should raise_error(TypeError) - -> { Date.civil(2007,2,27) << Object.new }.should raise_error(TypeError) + -> { Date.civil(2007,2,27) << :hello }.should.raise(TypeError) + -> { Date.civil(2007,2,27) << "hello" }.should.raise(TypeError) + -> { Date.civil(2007,2,27) << Date.new }.should.raise(TypeError) + -> { Date.civil(2007,2,27) << Object.new }.should.raise(TypeError) end end diff --git a/spec/ruby/library/date/minus_spec.rb b/spec/ruby/library/date/minus_spec.rb index 5a2a29e04a..c2a08fa5b0 100644 --- a/spec/ruby/library/date/minus_spec.rb +++ b/spec/ruby/library/date/minus_spec.rb @@ -22,9 +22,9 @@ describe "Date#-" do end it "raises an error for non Numeric arguments" do - -> { Date.civil(2007,2,27) - :hello }.should raise_error(TypeError) - -> { Date.civil(2007,2,27) - "hello" }.should raise_error(TypeError) - -> { Date.civil(2007,2,27) - Object.new }.should raise_error(TypeError) + -> { Date.civil(2007,2,27) - :hello }.should.raise(TypeError) + -> { Date.civil(2007,2,27) - "hello" }.should.raise(TypeError) + -> { Date.civil(2007,2,27) - Object.new }.should.raise(TypeError) end end diff --git a/spec/ruby/library/date/mon_spec.rb b/spec/ruby/library/date/mon_spec.rb index 616d72cf88..15754ffb1f 100644 --- a/spec/ruby/library/date/mon_spec.rb +++ b/spec/ruby/library/date/mon_spec.rb @@ -1,7 +1,8 @@ require_relative '../../spec_helper' -require_relative 'shared/month' require 'date' describe "Date#mon" do - it_behaves_like :date_month, :mon + it "is an alias of Date#month" do + Date.instance_method(:mon).should == Date.instance_method(:month) + end end diff --git a/spec/ruby/library/date/monday_spec.rb b/spec/ruby/library/date/monday_spec.rb index 14a117b73c..61d728f3c5 100644 --- a/spec/ruby/library/date/monday_spec.rb +++ b/spec/ruby/library/date/monday_spec.rb @@ -3,6 +3,6 @@ require 'date' describe "Date#monday?" do it "should be monday" do - Date.new(2000, 1, 3).monday?.should be_true + Date.new(2000, 1, 3).monday?.should == true end end diff --git a/spec/ruby/library/date/month_spec.rb b/spec/ruby/library/date/month_spec.rb index f493ec8119..e040f9a94c 100644 --- a/spec/ruby/library/date/month_spec.rb +++ b/spec/ruby/library/date/month_spec.rb @@ -1,7 +1,9 @@ require_relative '../../spec_helper' -require_relative 'shared/month' require 'date' describe "Date#month" do - it_behaves_like :date_month, :month + it "returns the month" do + m = Date.new(2000, 7, 1).month + m.should == 7 + end end diff --git a/spec/ruby/library/date/ordinal_spec.rb b/spec/ruby/library/date/ordinal_spec.rb index ec490fd49c..c8bf715163 100644 --- a/spec/ruby/library/date/ordinal_spec.rb +++ b/spec/ruby/library/date/ordinal_spec.rb @@ -1,7 +1,17 @@ require 'date' require_relative '../../spec_helper' -require_relative 'shared/ordinal' describe "Date.ordinal" do - it_behaves_like :date_ordinal, :ordinal + it "constructs a Date object from an ordinal date" do + # October 1582 (the Gregorian calendar, Ordinal Date) + # S M Tu W Th F S + # 274 275 276 277 278 279 + # 280 281 282 283 284 285 286 + # 287 288 289 290 291 292 293 + # 294 + Date.ordinal(1582, 274).should == Date.civil(1582, 10, 1) + Date.ordinal(1582, 277).should == Date.civil(1582, 10, 4) + Date.ordinal(1582, 278).should == Date.civil(1582, 10, 15) + Date.ordinal(1582, 287, Date::ENGLAND).should == Date.civil(1582, 10, 14, Date::ENGLAND) + end end diff --git a/spec/ruby/library/date/parse_spec.rb b/spec/ruby/library/date/parse_spec.rb index 5ef4f6e9b5..4d655f516e 100644 --- a/spec/ruby/library/date/parse_spec.rb +++ b/spec/ruby/library/date/parse_spec.rb @@ -23,7 +23,7 @@ describe "Date#parse" do # Specs using numbers it "throws an argument error for a single digit" do - ->{ Date.parse("1") }.should raise_error(ArgumentError) + ->{ Date.parse("1") }.should.raise(ArgumentError) end it "parses DD as month day number" do @@ -66,8 +66,8 @@ describe "Date#parse" do end it "raises a TypeError trying to parse non-String-like object" do - -> { Date.parse(1) }.should raise_error(TypeError) - -> { Date.parse([]) }.should raise_error(TypeError) + -> { Date.parse(1) }.should.raise(TypeError) + -> { Date.parse([]) }.should.raise(TypeError) end it "coerces using to_str" do diff --git a/spec/ruby/library/date/plus_spec.rb b/spec/ruby/library/date/plus_spec.rb index 0cb99fd4ca..6179370fca 100644 --- a/spec/ruby/library/date/plus_spec.rb +++ b/spec/ruby/library/date/plus_spec.rb @@ -15,6 +15,6 @@ describe "Date#+" do end it "raises TypeError if argument is not Numeric" do - -> { Date.today + Date.today }.should raise_error(TypeError) + -> { Date.today + Date.today }.should.raise(TypeError) end end diff --git a/spec/ruby/library/date/saturday_spec.rb b/spec/ruby/library/date/saturday_spec.rb index 1527b71d00..29f8267a2b 100644 --- a/spec/ruby/library/date/saturday_spec.rb +++ b/spec/ruby/library/date/saturday_spec.rb @@ -3,6 +3,6 @@ require 'date' describe "Date#saturday?" do it "should be saturday" do - Date.new(2000, 1, 1).saturday?.should be_true + Date.new(2000, 1, 1).saturday?.should == true end end diff --git a/spec/ruby/library/date/shared/civil.rb b/spec/ruby/library/date/shared/civil.rb index bbed4a8866..4499cdf8e9 100644 --- a/spec/ruby/library/date/shared/civil.rb +++ b/spec/ruby/library/date/shared/civil.rb @@ -36,14 +36,14 @@ describe :date_civil, shared: true do end it "doesn't create dates for invalid arguments" do - -> { Date.send(@method, 2000, 13, 31) }.should raise_error(ArgumentError) - -> { Date.send(@method, 2000, 12, 32) }.should raise_error(ArgumentError) - -> { Date.send(@method, 2000, 2, 30) }.should raise_error(ArgumentError) - -> { Date.send(@method, 1900, 2, 29) }.should raise_error(ArgumentError) - -> { Date.send(@method, 2000, 2, 29) }.should_not raise_error(ArgumentError) - - -> { Date.send(@method, 1582, 10, 14) }.should raise_error(ArgumentError) - -> { Date.send(@method, 1582, 10, 15) }.should_not raise_error(ArgumentError) + -> { Date.send(@method, 2000, 13, 31) }.should.raise(ArgumentError) + -> { Date.send(@method, 2000, 12, 32) }.should.raise(ArgumentError) + -> { Date.send(@method, 2000, 2, 30) }.should.raise(ArgumentError) + -> { Date.send(@method, 1900, 2, 29) }.should.raise(ArgumentError) + -> { Date.send(@method, 2000, 2, 29) }.should_not.raise(ArgumentError) + + -> { Date.send(@method, 1582, 10, 14) }.should.raise(ArgumentError) + -> { Date.send(@method, 1582, 10, 15) }.should_not.raise(ArgumentError) end diff --git a/spec/ruby/library/date/shared/commercial.rb b/spec/ruby/library/date/shared/commercial.rb deleted file mode 100644 index 39c9af47b6..0000000000 --- a/spec/ruby/library/date/shared/commercial.rb +++ /dev/null @@ -1,39 +0,0 @@ -describe :date_commercial, shared: true do - it "creates a Date for Julian Day Number day 0 by default" do - d = Date.send(@method) - d.year.should == -4712 - d.month.should == 1 - d.day.should == 1 - end - - it "creates a Date for the monday in the year and week given" do - d = Date.send(@method, 2000, 1) - d.year.should == 2000 - d.month.should == 1 - d.day.should == 3 - d.cwday.should == 1 - end - - it "creates a Date for the correct day given the year, week and day number" do - d = Date.send(@method, 2004, 1, 1) - d.year.should == 2003 - d.month.should == 12 - d.day.should == 29 - d.cwday.should == 1 - d.cweek.should == 1 - d.cwyear.should == 2004 - end - - it "creates only Date objects for valid weeks" do - -> { Date.send(@method, 2004, 53, 1) }.should_not raise_error(ArgumentError) - -> { Date.send(@method, 2004, 53, 0) }.should raise_error(ArgumentError) - -> { Date.send(@method, 2004, 53, 8) }.should raise_error(ArgumentError) - -> { Date.send(@method, 2004, 54, 1) }.should raise_error(ArgumentError) - -> { Date.send(@method, 2004, 0, 1) }.should raise_error(ArgumentError) - - -> { Date.send(@method, 2003, 52, 1) }.should_not raise_error(ArgumentError) - -> { Date.send(@method, 2003, 53, 1) }.should raise_error(ArgumentError) - -> { Date.send(@method, 2003, 52, 0) }.should raise_error(ArgumentError) - -> { Date.send(@method, 2003, 52, 8) }.should raise_error(ArgumentError) - end -end diff --git a/spec/ruby/library/date/shared/jd.rb b/spec/ruby/library/date/shared/jd.rb deleted file mode 100644 index 511557b4f7..0000000000 --- a/spec/ruby/library/date/shared/jd.rb +++ /dev/null @@ -1,14 +0,0 @@ -describe :date_jd, shared: true do - it "constructs a Date object if passed a Julian day" do - Date.send(@method, 2454482).should == Date.civil(2008, 1, 16) - end - - it "returns a Date object representing Julian day 0 (-4712-01-01) if no arguments passed" do - Date.send(@method).should == Date.civil(-4712, 1, 1) - end - - it "constructs a Date object if passed a negative number" do - Date.send(@method, -1).should == Date.civil(-4713, 12, 31) - end - -end diff --git a/spec/ruby/library/date/shared/month.rb b/spec/ruby/library/date/shared/month.rb deleted file mode 100644 index 5fcb2cbeb0..0000000000 --- a/spec/ruby/library/date/shared/month.rb +++ /dev/null @@ -1,6 +0,0 @@ -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/ordinal.rb b/spec/ruby/library/date/shared/ordinal.rb deleted file mode 100644 index 4b182d5a25..0000000000 --- a/spec/ruby/library/date/shared/ordinal.rb +++ /dev/null @@ -1,22 +0,0 @@ -# reference: -# October 1582 (the Gregorian calendar, Civil Date) -# S M Tu W Th F S -# 1 2 3 4 15 16 -# 17 18 19 20 21 22 23 -# 24 25 26 27 28 29 30 -# 31 - -describe :date_ordinal, shared: true do - it "constructs a Date object from an ordinal date" do - # October 1582 (the Gregorian calendar, Ordinal Date) - # S M Tu W Th F S - # 274 275 276 277 278 279 - # 280 281 282 283 284 285 286 - # 287 288 289 290 291 292 293 - # 294 - Date.send(@method, 1582, 274).should == Date.civil(1582, 10, 1) - Date.send(@method, 1582, 277).should == Date.civil(1582, 10, 4) - Date.send(@method, 1582, 278).should == Date.civil(1582, 10, 15) - Date.send(@method, 1582, 287, Date::ENGLAND).should == Date.civil(1582, 10, 14, Date::ENGLAND) - end -end diff --git a/spec/ruby/library/date/shared/valid_civil.rb b/spec/ruby/library/date/shared/valid_civil.rb deleted file mode 100644 index 545c207bbe..0000000000 --- a/spec/ruby/library/date/shared/valid_civil.rb +++ /dev/null @@ -1,36 +0,0 @@ -describe :date_valid_civil?, shared: true do - - # reference: - # October 1582 (the Gregorian calendar, Civil Date) - # S M Tu W Th F S - # 1 2 3 4 15 16 - # 17 18 19 20 21 22 23 - # 24 25 26 27 28 29 30 - # 31 - - it "returns true if it is a valid civil date" do - Date.send(@method, 1582, 10, 15).should be_true - Date.send(@method, 1582, 10, 14, Date::ENGLAND).should be_true - end - - it "returns false if it is not a valid civil date" do - Date.send(@method, 1582, 10, 14).should == false - end - - it "handles negative months and days" do - # October 1582 (the Gregorian calendar, Civil Date) - # S M Tu W Th F S - # -21 -20 -19 -18 -17 -16 - # -15 -14 -13 -12 -11 -10 -9 - # -8 -7 -6 -5 -4 -3 -2 - # -1 - Date.send(@method, 1582, -3, -22).should be_false - Date.send(@method, 1582, -3, -21).should be_true - Date.send(@method, 1582, -3, -18).should be_true - Date.send(@method, 1582, -3, -17).should be_true - - Date.send(@method, 2007, -11, -10).should be_true - Date.send(@method, 2008, -11, -10).should be_true - end - -end diff --git a/spec/ruby/library/date/shared/valid_commercial.rb b/spec/ruby/library/date/shared/valid_commercial.rb deleted file mode 100644 index 117dfe1d3d..0000000000 --- a/spec/ruby/library/date/shared/valid_commercial.rb +++ /dev/null @@ -1,34 +0,0 @@ -describe :date_valid_commercial?, shared: true do - - it "returns true if it is a valid commercial date" do - # October 1582 (the Gregorian calendar, Commercial Date) - # M Tu W Th F Sa Su - # 39: 1 2 3 4 5 6 7 - # 40: 1 2 3 4 5 6 7 - # 41: 1 2 3 4 5 6 7 - Date.send(@method, 1582, 39, 4).should be_true - Date.send(@method, 1582, 39, 5).should be_true - Date.send(@method, 1582, 41, 4).should be_true - Date.send(@method, 1582, 41, 5).should be_true - Date.send(@method, 1582, 41, 4, Date::ENGLAND).should be_true - Date.send(@method, 1752, 37, 4, Date::ENGLAND).should be_true - end - - it "returns false it is not a valid commercial date" do - Date.send(@method, 1999, 53, 1).should be_false - end - - it "handles negative week and day numbers" do - # October 1582 (the Gregorian calendar, Commercial Date) - # M Tu W Th F Sa Su - # -12: -7 -6 -5 -4 -3 -2 -1 - # -11: -7 -6 -5 -4 -3 -2 -1 - # -10: -7 -6 -5 -4 -3 -2 -1 - Date.send(@method, 1582, -12, -4).should be_true - Date.send(@method, 1582, -12, -3).should be_true - Date.send(@method, 2007, -44, -2).should be_true - Date.send(@method, 2008, -44, -2).should be_true - Date.send(@method, 1999, -53, -1).should be_false - end - -end diff --git a/spec/ruby/library/date/shared/valid_jd.rb b/spec/ruby/library/date/shared/valid_jd.rb deleted file mode 100644 index e474dfb450..0000000000 --- a/spec/ruby/library/date/shared/valid_jd.rb +++ /dev/null @@ -1,20 +0,0 @@ -describe :date_valid_jd?, shared: true do - it "returns true if passed a number value" do - Date.send(@method, -100).should be_true - Date.send(@method, 100.0).should be_true - Date.send(@method, 2**100).should be_true - Date.send(@method, Rational(1,2)).should be_true - end - - it "returns false if passed nil" do - Date.send(@method, nil).should be_false - end - - it "returns false if passed symbol" do - Date.send(@method, :number).should be_false - end - - it "returns false if passed false" do - Date.send(@method, false).should be_false - end -end diff --git a/spec/ruby/library/date/shared/valid_ordinal.rb b/spec/ruby/library/date/shared/valid_ordinal.rb deleted file mode 100644 index 1ed961be23..0000000000 --- a/spec/ruby/library/date/shared/valid_ordinal.rb +++ /dev/null @@ -1,26 +0,0 @@ -describe :date_valid_ordinal?, shared: true do - it "determines if the date is a valid ordinal date" do - # October 1582 (the Gregorian calendar, Ordinal Date) - # S M Tu W Th F S - # 274 275 276 277 278 279 - # 280 281 282 283 284 285 286 - # 287 288 289 290 291 292 293 - # 294 - Date.send(@method, 1582, 277).should == true - Date.send(@method, 1582, 278).should == true - Date.send(@method, 1582, 287).should == true - Date.send(@method, 1582, 288).should == true - end - - it "handles negative day numbers" do - # October 1582 (the Gregorian calendar, Ordinal Date) - # S M Tu W Th F S - # -82 -81 -80 -79 -78 -77 - # -76 -75 -74 -73 -72 -71 -70 - # -69 -68 -67 -66 -65 -64 -63 - # -62 - Date.send(@method, 1582, -79).should == true - Date.send(@method, 1582, -78).should == true - Date.send(@method, 2007, -100).should == true - end -end diff --git a/spec/ruby/library/date/succ_spec.rb b/spec/ruby/library/date/succ_spec.rb index c4a902aa63..0b14d3bb73 100644 --- a/spec/ruby/library/date/succ_spec.rb +++ b/spec/ruby/library/date/succ_spec.rb @@ -2,5 +2,7 @@ require_relative '../../spec_helper' require 'date' describe "Date#succ" do - it "needs to be reviewed for spec completeness" + it "is an alias of Date#next" do + Date.instance_method(:succ).should == Date.instance_method(:next) + end end diff --git a/spec/ruby/library/date/sunday_spec.rb b/spec/ruby/library/date/sunday_spec.rb index c3a817fa86..548f36a4f0 100644 --- a/spec/ruby/library/date/sunday_spec.rb +++ b/spec/ruby/library/date/sunday_spec.rb @@ -3,6 +3,6 @@ require 'date' describe "Date#sunday?" do it "should be sunday" do - Date.new(2000, 1, 2).sunday?.should be_true + Date.new(2000, 1, 2).sunday?.should == true end end diff --git a/spec/ruby/library/date/thursday_spec.rb b/spec/ruby/library/date/thursday_spec.rb index 74b5f40365..4df3b9103a 100644 --- a/spec/ruby/library/date/thursday_spec.rb +++ b/spec/ruby/library/date/thursday_spec.rb @@ -3,6 +3,6 @@ require 'date' describe "Date#thursday?" do it "should be thursday" do - Date.new(2000, 1, 6).thursday?.should be_true + Date.new(2000, 1, 6).thursday?.should == true end end diff --git a/spec/ruby/library/date/today_spec.rb b/spec/ruby/library/date/today_spec.rb index 7c6ebc9cb4..4be8d8e931 100644 --- a/spec/ruby/library/date/today_spec.rb +++ b/spec/ruby/library/date/today_spec.rb @@ -3,7 +3,7 @@ require 'date' describe "Date.today" do it "returns a Date object" do - Date.today.should be_kind_of Date + Date.today.should.is_a? Date end it "sets Date object to the current date" do diff --git a/spec/ruby/library/date/tuesday_spec.rb b/spec/ruby/library/date/tuesday_spec.rb index 052837b54e..db31387aed 100644 --- a/spec/ruby/library/date/tuesday_spec.rb +++ b/spec/ruby/library/date/tuesday_spec.rb @@ -3,6 +3,6 @@ require 'date' describe "Date#tuesday?" do it "should be tuesday" do - Date.new(2000, 1, 4).tuesday?.should be_true + Date.new(2000, 1, 4).tuesday?.should == true end end diff --git a/spec/ruby/library/date/valid_civil_spec.rb b/spec/ruby/library/date/valid_civil_spec.rb index 00f2c57205..8cffc80310 100644 --- a/spec/ruby/library/date/valid_civil_spec.rb +++ b/spec/ruby/library/date/valid_civil_spec.rb @@ -1,9 +1,8 @@ require_relative '../../spec_helper' -require_relative 'shared/valid_civil' require 'date' -describe "Date#valid_civil?" do - - it_behaves_like :date_valid_civil?, :valid_civil? - +describe "Date.valid_civil?" do + it "is an alias of Date.valid_date?" do + Date.method(:valid_civil?).should == Date.method(:valid_date?) + end end diff --git a/spec/ruby/library/date/valid_commercial_spec.rb b/spec/ruby/library/date/valid_commercial_spec.rb index 7e96782b6b..21a91ad867 100644 --- a/spec/ruby/library/date/valid_commercial_spec.rb +++ b/spec/ruby/library/date/valid_commercial_spec.rb @@ -1,8 +1,35 @@ require_relative '../../spec_helper' -require_relative 'shared/valid_commercial' require 'date' -describe "Date#valid_commercial?" do +describe "Date.valid_commercial?" do + it "returns true if it is a valid commercial date" do + # October 1582 (the Gregorian calendar, Commercial Date) + # M Tu W Th F Sa Su + # 39: 1 2 3 4 5 6 7 + # 40: 1 2 3 4 5 6 7 + # 41: 1 2 3 4 5 6 7 + Date.valid_commercial?(1582, 39, 4).should == true + Date.valid_commercial?(1582, 39, 5).should == true + Date.valid_commercial?(1582, 41, 4).should == true + Date.valid_commercial?(1582, 41, 5).should == true + Date.valid_commercial?(1582, 41, 4, Date::ENGLAND).should == true + Date.valid_commercial?(1752, 37, 4, Date::ENGLAND).should == true + end - it_behaves_like :date_valid_commercial?, :valid_commercial? + it "returns false it is not a valid commercial date" do + Date.valid_commercial?(1999, 53, 1).should == false + end + + it "handles negative week and day numbers" do + # October 1582 (the Gregorian calendar, Commercial Date) + # M Tu W Th F Sa Su + # -12: -7 -6 -5 -4 -3 -2 -1 + # -11: -7 -6 -5 -4 -3 -2 -1 + # -10: -7 -6 -5 -4 -3 -2 -1 + Date.valid_commercial?(1582, -12, -4).should == true + Date.valid_commercial?(1582, -12, -3).should == true + Date.valid_commercial?(2007, -44, -2).should == true + Date.valid_commercial?(2008, -44, -2).should == true + Date.valid_commercial?(1999, -53, -1).should == false + end end diff --git a/spec/ruby/library/date/valid_date_spec.rb b/spec/ruby/library/date/valid_date_spec.rb index f12a71d966..f0d5ec7b4d 100644 --- a/spec/ruby/library/date/valid_date_spec.rb +++ b/spec/ruby/library/date/valid_date_spec.rb @@ -1,7 +1,36 @@ require_relative '../../spec_helper' -require_relative 'shared/valid_civil' require 'date' -describe "Date#valid_date?" do - it_behaves_like :date_valid_civil?, :valid_date? +describe "Date.valid_date?" do + # reference: + # October 1582 (the Gregorian calendar, Civil Date) + # S M Tu W Th F S + # 1 2 3 4 15 16 + # 17 18 19 20 21 22 23 + # 24 25 26 27 28 29 30 + # 31 + it "returns true if it is a valid civil date" do + Date.valid_date?(1582, 10, 15).should == true + Date.valid_date?(1582, 10, 14, Date::ENGLAND).should == true + end + + it "returns false if it is not a valid civil date" do + Date.valid_date?(1582, 10, 14).should == false + end + + it "handles negative months and days" do + # October 1582 (the Gregorian calendar, Civil Date) + # S M Tu W Th F S + # -21 -20 -19 -18 -17 -16 + # -15 -14 -13 -12 -11 -10 -9 + # -8 -7 -6 -5 -4 -3 -2 + # -1 + Date.valid_date?(1582, -3, -22).should == false + Date.valid_date?(1582, -3, -21).should == true + Date.valid_date?(1582, -3, -18).should == true + Date.valid_date?(1582, -3, -17).should == true + + Date.valid_date?(2007, -11, -10).should == true + Date.valid_date?(2008, -11, -10).should == true + end end diff --git a/spec/ruby/library/date/valid_jd_spec.rb b/spec/ruby/library/date/valid_jd_spec.rb index aecaaabcf4..46f22de497 100644 --- a/spec/ruby/library/date/valid_jd_spec.rb +++ b/spec/ruby/library/date/valid_jd_spec.rb @@ -1,9 +1,23 @@ require_relative '../../spec_helper' -require_relative 'shared/valid_jd' require 'date' describe "Date.valid_jd?" do + it "returns true if passed a number value" do + Date.valid_jd?(-100).should == true + Date.valid_jd?(100.0).should == true + Date.valid_jd?(2**100).should == true + Date.valid_jd?(Rational(1,2)).should == true + end - it_behaves_like :date_valid_jd?, :valid_jd? + it "returns false if passed nil" do + Date.valid_jd?(nil).should == false + end + it "returns false if passed symbol" do + Date.valid_jd?(:number).should == false + end + + it "returns false if passed false" do + Date.valid_jd?(false).should == false + end end diff --git a/spec/ruby/library/date/valid_ordinal_spec.rb b/spec/ruby/library/date/valid_ordinal_spec.rb index 58d548c704..bb5c259606 100644 --- a/spec/ruby/library/date/valid_ordinal_spec.rb +++ b/spec/ruby/library/date/valid_ordinal_spec.rb @@ -1,9 +1,29 @@ require_relative '../../spec_helper' -require_relative 'shared/valid_ordinal' require 'date' describe "Date.valid_ordinal?" do + it "determines if the date is a valid ordinal date" do + # October 1582 (the Gregorian calendar, Ordinal Date) + # S M Tu W Th F S + # 274 275 276 277 278 279 + # 280 281 282 283 284 285 286 + # 287 288 289 290 291 292 293 + # 294 + Date.valid_ordinal?(1582, 277).should == true + Date.valid_ordinal?(1582, 278).should == true + Date.valid_ordinal?(1582, 287).should == true + Date.valid_ordinal?(1582, 288).should == true + end - it_behaves_like :date_valid_ordinal?, :valid_ordinal? - + it "handles negative day numbers" do + # October 1582 (the Gregorian calendar, Ordinal Date) + # S M Tu W Th F S + # -82 -81 -80 -79 -78 -77 + # -76 -75 -74 -73 -72 -71 -70 + # -69 -68 -67 -66 -65 -64 -63 + # -62 + Date.valid_ordinal?(1582, -79).should == true + Date.valid_ordinal?(1582, -78).should == true + Date.valid_ordinal?(2007, -100).should == true + end end diff --git a/spec/ruby/library/date/wednesday_spec.rb b/spec/ruby/library/date/wednesday_spec.rb index e80ec23dd2..4bbeead5b8 100644 --- a/spec/ruby/library/date/wednesday_spec.rb +++ b/spec/ruby/library/date/wednesday_spec.rb @@ -3,6 +3,6 @@ require 'date' describe "Date#wednesday?" do it "should be wednesday" do - Date.new(2000, 1, 5).wednesday?.should be_true + Date.new(2000, 1, 5).wednesday?.should == true end end diff --git a/spec/ruby/library/datetime/deconstruct_keys_spec.rb b/spec/ruby/library/datetime/deconstruct_keys_spec.rb index 154c024a23..07a7bda881 100644 --- a/spec/ruby/library/datetime/deconstruct_keys_spec.rb +++ b/spec/ruby/library/datetime/deconstruct_keys_spec.rb @@ -18,16 +18,16 @@ describe "DateTime#deconstruct_keys" do it "requires one argument" do -> { DateTime.new(2022, 10, 5, 13, 30).deconstruct_keys - }.should raise_error(ArgumentError) + }.should.raise(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)") + -> { d.deconstruct_keys(1) }.should.raise(TypeError, "wrong argument type Integer (expected Array or nil)") + -> { d.deconstruct_keys("asd") }.should.raise(TypeError, "wrong argument type String (expected Array or nil)") + -> { d.deconstruct_keys(:x) }.should.raise(TypeError, "wrong argument type Symbol (expected Array or nil)") + -> { d.deconstruct_keys({}) }.should.raise(TypeError, "wrong argument type Hash (expected Array or nil)") end it "returns {} when passed []" do diff --git a/spec/ruby/library/datetime/hour_spec.rb b/spec/ruby/library/datetime/hour_spec.rb index 8efd5f92f0..5d8e75edcb 100644 --- a/spec/ruby/library/datetime/hour_spec.rb +++ b/spec/ruby/library/datetime/hour_spec.rb @@ -15,28 +15,27 @@ describe "DateTime#hour" do end it "raises an error for Rational" do - -> { new_datetime(hour: 1 + Rational(1,2)) }.should raise_error(ArgumentError) + -> { new_datetime(hour: 1 + Rational(1,2)) }.should.raise(ArgumentError) end it "raises an error for Float" do - -> { new_datetime(hour: 1.5).hour }.should raise_error(ArgumentError) + -> { new_datetime(hour: 1.5).hour }.should.raise(ArgumentError) end it "raises an error for Rational" do - -> { new_datetime(day: 1 + Rational(1,2)) }.should raise_error(ArgumentError) + -> { new_datetime(day: 1 + Rational(1,2)) }.should.raise(ArgumentError) end it "raises an error, when the hour is smaller than -24" do - -> { new_datetime(hour: -25) }.should raise_error(ArgumentError) + -> { new_datetime(hour: -25) }.should.raise(ArgumentError) end it "raises an error, when the hour is larger than 24" do - -> { new_datetime(hour: 25) }.should raise_error(ArgumentError) + -> { new_datetime(hour: 25) }.should.raise(ArgumentError) end it "raises an error for hour fractions smaller than -24" do - -> { new_datetime(hour: -24 - Rational(1,2)) }.should( - raise_error(ArgumentError)) + -> { new_datetime(hour: -24 - Rational(1,2)) }.should.raise(ArgumentError) end it "adds 1 to day, when 24 hours given" do diff --git a/spec/ruby/library/datetime/iso8601_spec.rb b/spec/ruby/library/datetime/iso8601_spec.rb index 457881277a..4368300fd5 100644 --- a/spec/ruby/library/datetime/iso8601_spec.rb +++ b/spec/ruby/library/datetime/iso8601_spec.rb @@ -6,5 +6,7 @@ describe "DateTime.iso8601" do end describe "DateTime#iso8601" do - it "needs to be reviewed for spec completeness" + it "is an alias of DateTime#isoxmlschema8601" do + DateTime.instance_method(:iso8601).should == DateTime.instance_method(:xmlschema) + end end diff --git a/spec/ruby/library/datetime/min_spec.rb b/spec/ruby/library/datetime/min_spec.rb index a1eaa214cb..ca995a7eed 100644 --- a/spec/ruby/library/datetime/min_spec.rb +++ b/spec/ruby/library/datetime/min_spec.rb @@ -1,6 +1,8 @@ require_relative '../../spec_helper' -require_relative 'shared/min' +require 'date' -describe "DateTime.min" do - it_behaves_like :datetime_min, :min +describe "DateTime#min" do + it "is an alias of DateTime#minute" do + DateTime.instance_method(:min).should == DateTime.instance_method(:minute) + end end diff --git a/spec/ruby/library/datetime/minute_spec.rb b/spec/ruby/library/datetime/minute_spec.rb index acdfeda345..6e99752de7 100644 --- a/spec/ruby/library/datetime/minute_spec.rb +++ b/spec/ruby/library/datetime/minute_spec.rb @@ -1,6 +1,40 @@ require_relative '../../spec_helper' -require_relative 'shared/min' +require 'date' -describe "DateTime.minute" do - it_behaves_like :datetime_min, :minute +describe "DateTime#minute" do + it "returns 0 if no argument is passed" do + DateTime.new.minute.should == 0 + end + + it "returns the minute passed as argument" do + new_datetime(minute: 5).minute.should == 5 + end + + it "adds 60 to negative minutes" do + new_datetime(minute: -20).minute.should == 40 + end + + it "raises an error for Rational" do + -> { new_datetime minute: 5 + Rational(1,2) }.should.raise(ArgumentError) + end + + it "raises an error for Float" do + -> { new_datetime minute: 5.5 }.should.raise(ArgumentError) + end + + it "raises an error for Rational" do + -> { new_datetime(hour: 2 + Rational(1,2)) }.should.raise(ArgumentError) + end + + it "raises an error, when the minute is smaller than -60" do + -> { new_datetime(minute: -61) }.should.raise(ArgumentError) + end + + it "raises an error, when the minute is greater or equal than 60" do + -> { new_datetime(minute: 60) }.should.raise(ArgumentError) + end + + it "raises an error for minute fractions smaller than -60" do + -> { new_datetime(minute: -60 - Rational(1,2))}.should.raise(ArgumentError) + end end diff --git a/spec/ruby/library/datetime/new_spec.rb b/spec/ruby/library/datetime/new_spec.rb index 6a4dced384..2b3c3f156c 100644 --- a/spec/ruby/library/datetime/new_spec.rb +++ b/spec/ruby/library/datetime/new_spec.rb @@ -47,6 +47,6 @@ describe "DateTime.new" do end it "raises an error on invalid arguments" do - -> { new_datetime(minute: 999) }.should raise_error(ArgumentError) + -> { new_datetime(minute: 999) }.should.raise(ArgumentError) end end diff --git a/spec/ruby/library/datetime/now_spec.rb b/spec/ruby/library/datetime/now_spec.rb index 9f22153c15..5c0411c2be 100644 --- a/spec/ruby/library/datetime/now_spec.rb +++ b/spec/ruby/library/datetime/now_spec.rb @@ -3,7 +3,7 @@ require 'date' describe "DateTime.now" do it "creates an instance of DateTime" do - DateTime.now.should be_an_instance_of(DateTime) + DateTime.now.should.instance_of?(DateTime) end it "sets the current date" do diff --git a/spec/ruby/library/datetime/parse_spec.rb b/spec/ruby/library/datetime/parse_spec.rb index e9bf4e2ed1..0a965273a0 100644 --- a/spec/ruby/library/datetime/parse_spec.rb +++ b/spec/ruby/library/datetime/parse_spec.rb @@ -20,7 +20,7 @@ describe "DateTime.parse" do # Specs using numbers it "throws an argument error for a single digit" do - ->{ DateTime.parse("1") }.should raise_error(ArgumentError) + ->{ DateTime.parse("1") }.should.raise(ArgumentError) end it "parses DD as month day number" do @@ -54,23 +54,23 @@ describe "DateTime.parse" do end it "throws an argument error for invalid month values" do - ->{DateTime.parse("2012-13-08T15:43:59")}.should raise_error(ArgumentError) + ->{DateTime.parse("2012-13-08T15:43:59")}.should.raise(ArgumentError) end it "throws an argument error for invalid day values" do - ->{DateTime.parse("2012-12-32T15:43:59")}.should raise_error(ArgumentError) + ->{DateTime.parse("2012-12-32T15:43:59")}.should.raise(ArgumentError) end it "throws an argument error for invalid hour values" do - ->{DateTime.parse("2012-12-31T25:43:59")}.should raise_error(ArgumentError) + ->{DateTime.parse("2012-12-31T25:43:59")}.should.raise(ArgumentError) end it "throws an argument error for invalid minute values" do - ->{DateTime.parse("2012-12-31T25:43:59")}.should raise_error(ArgumentError) + ->{DateTime.parse("2012-12-31T25:43:59")}.should.raise(ArgumentError) end it "throws an argument error for invalid second values" do - ->{DateTime.parse("2012-11-08T15:43:61")}.should raise_error(ArgumentError) + ->{DateTime.parse("2012-11-08T15:43:61")}.should.raise(ArgumentError) end end diff --git a/spec/ruby/library/datetime/rfc2822_spec.rb b/spec/ruby/library/datetime/rfc2822_spec.rb index 83f7fa8d5b..11b79a1e84 100644 --- a/spec/ruby/library/datetime/rfc2822_spec.rb +++ b/spec/ruby/library/datetime/rfc2822_spec.rb @@ -5,6 +5,6 @@ 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") + -> { DateTime.rfc2822(nil) }.should.raise(Date::Error, "invalid date") end end diff --git a/spec/ruby/library/datetime/sec_spec.rb b/spec/ruby/library/datetime/sec_spec.rb index f681283c8e..f8a8b4646e 100644 --- a/spec/ruby/library/datetime/sec_spec.rb +++ b/spec/ruby/library/datetime/sec_spec.rb @@ -1,6 +1,8 @@ require_relative '../../spec_helper' -require_relative 'shared/sec' +require 'date' -describe "DateTime.sec" do - it_behaves_like :datetime_sec, :sec +describe "DateTime#sec" do + it "is an alias of DateTime#second" do + DateTime.instance_method(:sec).should == DateTime.instance_method(:second) + end end diff --git a/spec/ruby/library/datetime/second_fraction_spec.rb b/spec/ruby/library/datetime/second_fraction_spec.rb index d5393149ba..70f5abf560 100644 --- a/spec/ruby/library/datetime/second_fraction_spec.rb +++ b/spec/ruby/library/datetime/second_fraction_spec.rb @@ -2,5 +2,7 @@ require_relative '../../spec_helper' require 'date' describe "DateTime#second_fraction" do - it "needs to be reviewed for spec completeness" + it "is an alias of DateTime#sec_fraction" do + DateTime.instance_method(:second_fraction).should == DateTime.instance_method(:sec_fraction) + end end diff --git a/spec/ruby/library/datetime/second_spec.rb b/spec/ruby/library/datetime/second_spec.rb index 545c3f9109..9fb1965b73 100644 --- a/spec/ruby/library/datetime/second_spec.rb +++ b/spec/ruby/library/datetime/second_spec.rb @@ -1,6 +1,45 @@ require_relative '../../spec_helper' -require_relative 'shared/sec' +require 'date' describe "DateTime#second" do - it_behaves_like :datetime_sec, :second + it "returns 0 seconds if passed no arguments" do + d = DateTime.new + d.second.should == 0 + end + + it "returns the seconds passed in the arguments" do + new_datetime(second: 5).second.should == 5 + end + + it "adds 60 to negative values" do + new_datetime(second: -20).second.should == 40 + end + + it "returns the absolute value of a Rational" do + new_datetime(second: 5 + Rational(1,2)).second.should == 5 + end + + it "returns the absolute value of a float" do + new_datetime(second: 5.5).second.should == 5 + end + + it "raises an error when minute is given as a rational" do + -> { new_datetime(minute: 5 + Rational(1,2)) }.should.raise(ArgumentError) + end + + it "raises an error, when the second is smaller than -60" do + -> { new_datetime(second: -61) }.should.raise(ArgumentError) + end + + it "raises an error, when the second is greater or equal than 60" do + -> { new_datetime(second: 60) }.should.raise(ArgumentError) + end + + it "raises an error for second fractions smaller than -60" do + -> { new_datetime(second: -60 - Rational(1,2))}.should.raise(ArgumentError) + end + + it "takes a second fraction near 60" do + new_datetime(second: 59 + Rational(1,2)).second.should == 59 + end end diff --git a/spec/ruby/library/datetime/shared/min.rb b/spec/ruby/library/datetime/shared/min.rb deleted file mode 100644 index a35b839281..0000000000 --- a/spec/ruby/library/datetime/shared/min.rb +++ /dev/null @@ -1,40 +0,0 @@ -require 'date' - -describe :datetime_min, shared: true do - it "returns 0 if no argument is passed" do - DateTime.new.send(@method).should == 0 - end - - it "returns the minute passed as argument" do - new_datetime(minute: 5).send(@method).should == 5 - end - - it "adds 60 to negative minutes" do - new_datetime(minute: -20).send(@method).should == 40 - end - - it "raises an error for Rational" do - -> { new_datetime minute: 5 + Rational(1,2) }.should raise_error(ArgumentError) - end - - it "raises an error for Float" do - -> { new_datetime minute: 5.5 }.should raise_error(ArgumentError) - end - - it "raises an error for Rational" do - -> { new_datetime(hour: 2 + Rational(1,2)) }.should raise_error(ArgumentError) - end - - it "raises an error, when the minute is smaller than -60" do - -> { new_datetime(minute: -61) }.should raise_error(ArgumentError) - end - - it "raises an error, when the minute is greater or equal than 60" do - -> { new_datetime(minute: 60) }.should raise_error(ArgumentError) - end - - it "raises an error for minute fractions smaller than -60" do - -> { new_datetime(minute: -60 - Rational(1,2))}.should( - raise_error(ArgumentError)) - end -end diff --git a/spec/ruby/library/datetime/shared/sec.rb b/spec/ruby/library/datetime/shared/sec.rb deleted file mode 100644 index 60009213aa..0000000000 --- a/spec/ruby/library/datetime/shared/sec.rb +++ /dev/null @@ -1,45 +0,0 @@ -require 'date' - -describe :datetime_sec, shared: true do - it "returns 0 seconds if passed no arguments" do - d = DateTime.new - d.send(@method).should == 0 - end - - it "returns the seconds passed in the arguments" do - new_datetime(second: 5).send(@method).should == 5 - end - - it "adds 60 to negative values" do - new_datetime(second: -20).send(@method).should == 40 - end - - it "returns the absolute value of a Rational" do - new_datetime(second: 5 + Rational(1,2)).send(@method).should == 5 - end - - it "returns the absolute value of a float" do - new_datetime(second: 5.5).send(@method).should == 5 - end - - it "raises an error when minute is given as a rational" do - -> { new_datetime(minute: 5 + Rational(1,2)) }.should raise_error(ArgumentError) - end - - it "raises an error, when the second is smaller than -60" do - -> { new_datetime(second: -61) }.should raise_error(ArgumentError) - end - - it "raises an error, when the second is greater or equal than 60" do - -> { new_datetime(second: 60) }.should raise_error(ArgumentError) - end - - it "raises an error for second fractions smaller than -60" do - -> { new_datetime(second: -60 - Rational(1,2))}.should( - raise_error(ArgumentError)) - end - - it "takes a second fraction near 60" do - new_datetime(second: 59 + Rational(1,2)).send(@method).should == 59 - end -end diff --git a/spec/ruby/library/datetime/to_date_spec.rb b/spec/ruby/library/datetime/to_date_spec.rb index 48c05e7fed..31ccf5ae98 100644 --- a/spec/ruby/library/datetime/to_date_spec.rb +++ b/spec/ruby/library/datetime/to_date_spec.rb @@ -4,7 +4,7 @@ require 'date' describe "DateTime#to_date" do it "returns an instance of Date" do dt = DateTime.new(2012, 12, 24, 12, 23, 00, '+05:00') - dt.to_date.should be_kind_of(Date) + dt.to_date.should.is_a?(Date) end it "maintains the same year" do diff --git a/spec/ruby/library/datetime/to_s_spec.rb b/spec/ruby/library/datetime/to_s_spec.rb index 175fb807f4..ed0746f42b 100644 --- a/spec/ruby/library/datetime/to_s_spec.rb +++ b/spec/ruby/library/datetime/to_s_spec.rb @@ -4,7 +4,7 @@ require 'date' describe "DateTime#to_s" do it "returns a new String object" do dt = DateTime.new(2012, 12, 24, 1, 2, 3, "+03:00") - dt.to_s.should be_kind_of(String) + dt.to_s.should.is_a?(String) end it "maintains timezone regardless of local time" do diff --git a/spec/ruby/library/datetime/to_time_spec.rb b/spec/ruby/library/datetime/to_time_spec.rb index 58bb363653..a3ffc019fb 100644 --- a/spec/ruby/library/datetime/to_time_spec.rb +++ b/spec/ruby/library/datetime/to_time_spec.rb @@ -4,7 +4,7 @@ date_version = defined?(Date::VERSION) ? Date::VERSION : '3.1.0' describe "DateTime#to_time" do it "yields a new Time object" do - DateTime.now.to_time.should be_kind_of(Time) + DateTime.now.to_time.should.is_a?(Time) end it "returns a Time representing the same instant" do diff --git a/spec/ruby/library/delegate/delegate_class/instance_method_spec.rb b/spec/ruby/library/delegate/delegate_class/instance_method_spec.rb index 16bf8d734c..19ffc4cf85 100644 --- a/spec/ruby/library/delegate/delegate_class/instance_method_spec.rb +++ b/spec/ruby/library/delegate/delegate_class/instance_method_spec.rb @@ -9,44 +9,44 @@ describe "DelegateClass.instance_method" do it "returns a method object for public instance methods of the delegated class" do m = @klass.instance_method(:pub) - m.should be_an_instance_of(UnboundMethod) + m.should.instance_of?(UnboundMethod) m.bind(@obj).call.should == :foo end it "returns a method object for protected instance methods of the delegated class" do m = @klass.instance_method(:prot) - m.should be_an_instance_of(UnboundMethod) + m.should.instance_of?(UnboundMethod) m.bind(@obj).call.should == :protected end it "raises a NameError for a private instance methods of the delegated class" do -> { @klass.instance_method(:priv) - }.should raise_error(NameError) + }.should.raise(NameError) end it "returns a method object for public instance methods of the DelegateClass class" do m = @klass.instance_method(:extra) - m.should be_an_instance_of(UnboundMethod) + m.should.instance_of?(UnboundMethod) m.bind(@obj).call.should == :cheese end it "returns a method object for protected instance methods of the DelegateClass class" do m = @klass.instance_method(:extra_protected) - m.should be_an_instance_of(UnboundMethod) + m.should.instance_of?(UnboundMethod) m.bind(@obj).call.should == :baz end it "returns a method object for private instance methods of the DelegateClass class" do m = @klass.instance_method(:extra_private) - m.should be_an_instance_of(UnboundMethod) + m.should.instance_of?(UnboundMethod) m.bind(@obj).call.should == :bar end it "raises a NameError for an invalid method name" do -> { @klass.instance_method(:invalid_and_silly_method_name) - }.should raise_error(NameError) + }.should.raise(NameError) end end diff --git a/spec/ruby/library/delegate/delegate_class/instance_methods_spec.rb b/spec/ruby/library/delegate/delegate_class/instance_methods_spec.rb index 6012ff72de..586be56cae 100644 --- a/spec/ruby/library/delegate/delegate_class/instance_methods_spec.rb +++ b/spec/ruby/library/delegate/delegate_class/instance_methods_spec.rb @@ -7,20 +7,20 @@ describe "DelegateClass.instance_methods" do end it "includes all public methods of the delegated class" do - @methods.should include :pub + @methods.should.include? :pub end it "includes all protected methods of the delegated class" do - @methods.should include :prot + @methods.should.include? :prot end it "includes instance methods of the DelegateClass class" do - @methods.should include :extra - @methods.should include :extra_protected + @methods.should.include? :extra + @methods.should.include? :extra_protected end it "does not include private methods" do - @methods.should_not include :priv - @methods.should_not include :extra_private + @methods.should_not.include? :priv + @methods.should_not.include? :extra_private end end diff --git a/spec/ruby/library/delegate/delegate_class/private_instance_methods_spec.rb b/spec/ruby/library/delegate/delegate_class/private_instance_methods_spec.rb index 06b2115cc5..18ca2a4c88 100644 --- a/spec/ruby/library/delegate/delegate_class/private_instance_methods_spec.rb +++ b/spec/ruby/library/delegate/delegate_class/private_instance_methods_spec.rb @@ -7,17 +7,17 @@ describe "DelegateClass.private_instance_methods" do end it "does not include any instance methods of the delegated class" do - @methods.should_not include :pub - @methods.should_not include :prot - @methods.should_not include :priv # since these are not forwarded... + @methods.should_not.include? :pub + @methods.should_not.include? :prot + @methods.should_not.include? :priv # since these are not forwarded... end it "includes private instance methods of the DelegateClass class" do - @methods.should include :extra_private + @methods.should.include? :extra_private end it "does not include public or protected instance methods of the DelegateClass class" do - @methods.should_not include :extra - @methods.should_not include :extra_protected + @methods.should_not.include? :extra + @methods.should_not.include? :extra_protected end end diff --git a/spec/ruby/library/delegate/delegate_class/protected_instance_methods_spec.rb b/spec/ruby/library/delegate/delegate_class/protected_instance_methods_spec.rb index ac6659ec1e..d540b45065 100644 --- a/spec/ruby/library/delegate/delegate_class/protected_instance_methods_spec.rb +++ b/spec/ruby/library/delegate/delegate_class/protected_instance_methods_spec.rb @@ -7,23 +7,23 @@ describe "DelegateClass.protected_instance_methods" do end it "does not include public methods of the delegated class" do - @methods.should_not include :pub + @methods.should_not.include? :pub end it "includes the protected methods of the delegated class" do - @methods.should include :prot + @methods.should.include? :prot end it "includes protected instance methods of the DelegateClass class" do - @methods.should include :extra_protected + @methods.should.include? :extra_protected end it "does not include public instance methods of the DelegateClass class" do - @methods.should_not include :extra + @methods.should_not.include? :extra end it "does not include private methods" do - @methods.should_not include :priv - @methods.should_not include :extra_private + @methods.should_not.include? :priv + @methods.should_not.include? :extra_private end end diff --git a/spec/ruby/library/delegate/delegate_class/public_instance_methods_spec.rb b/spec/ruby/library/delegate/delegate_class/public_instance_methods_spec.rb index 6c0d9bcab1..124b92de82 100644 --- a/spec/ruby/library/delegate/delegate_class/public_instance_methods_spec.rb +++ b/spec/ruby/library/delegate/delegate_class/public_instance_methods_spec.rb @@ -7,19 +7,19 @@ describe "DelegateClass.public_instance_methods" do end it "includes all public methods of the delegated class" do - @methods.should include :pub + @methods.should.include? :pub end it "does not include the protected methods of the delegated class" do - @methods.should_not include :prot + @methods.should_not.include? :prot end it "includes public instance methods of the DelegateClass class" do - @methods.should include :extra + @methods.should.include? :extra end it "does not include private methods" do - @methods.should_not include :priv - @methods.should_not include :extra_private + @methods.should_not.include? :priv + @methods.should_not.include? :extra_private end end diff --git a/spec/ruby/library/delegate/delegator/eql_spec.rb b/spec/ruby/library/delegate/delegator/eql_spec.rb index 34f56f44c9..b302bb7016 100644 --- a/spec/ruby/library/delegate/delegator/eql_spec.rb +++ b/spec/ruby/library/delegate/delegator/eql_spec.rb @@ -6,14 +6,14 @@ describe "Delegator#eql?" do base = mock('base') delegator = DelegateSpecs::Delegator.new(base) - delegator.eql?(delegator).should be_true + delegator.eql?(delegator).should == true end it "returns true when compared with the inner object" do base = mock('base') delegator = DelegateSpecs::Delegator.new(base) - delegator.eql?(base).should be_true + delegator.eql?(base).should == true end it "returns false when compared with the delegator with other object" do @@ -22,7 +22,7 @@ describe "Delegator#eql?" do delegator0 = DelegateSpecs::Delegator.new(base) delegator1 = DelegateSpecs::Delegator.new(other) - delegator0.eql?(delegator1).should be_false + delegator0.eql?(delegator1).should == false end it "returns false when compared with the other object" do @@ -30,6 +30,6 @@ describe "Delegator#eql?" do other = mock('other') delegator = DelegateSpecs::Delegator.new(base) - delegator.eql?(other).should be_false + delegator.eql?(other).should == false end end diff --git a/spec/ruby/library/delegate/delegator/equal_spec.rb b/spec/ruby/library/delegate/delegator/equal_spec.rb index c8711c74b5..97aabebabe 100644 --- a/spec/ruby/library/delegate/delegator/equal_spec.rb +++ b/spec/ruby/library/delegate/delegator/equal_spec.rb @@ -6,8 +6,8 @@ describe "Delegator#equal?" do obj = mock('base') delegator = DelegateSpecs::Delegator.new(obj) obj.should_not_receive(:equal?) - delegator.equal?(obj).should be_false - delegator.equal?(nil).should be_false - delegator.equal?(delegator).should be_true + delegator.equal?(obj).should == false + delegator.equal?(nil).should == false + delegator.equal?(delegator).should == true end end diff --git a/spec/ruby/library/delegate/delegator/equal_value_spec.rb b/spec/ruby/library/delegate/delegator/equal_value_spec.rb index 0c967d5f94..d70aad1e03 100644 --- a/spec/ruby/library/delegate/delegator/equal_value_spec.rb +++ b/spec/ruby/library/delegate/delegator/equal_value_spec.rb @@ -9,16 +9,16 @@ describe "Delegator#==" do it "is not delegated when passed self" do @base.should_not_receive(:==) - (@delegator == @delegator).should be_true + (@delegator == @delegator).should == true end it "is delegated when passed the delegated object" do @base.should_receive(:==).and_return(false) - (@delegator == @base).should be_false + (@delegator == @base).should == false end it "is delegated in general" do @base.should_receive(:==).and_return(true) - (@delegator == 42).should be_true + (@delegator == 42).should == true end end diff --git a/spec/ruby/library/delegate/delegator/frozen_spec.rb b/spec/ruby/library/delegate/delegator/frozen_spec.rb index b3145c54b1..ad87dc8bdf 100644 --- a/spec/ruby/library/delegate/delegator/frozen_spec.rb +++ b/spec/ruby/library/delegate/delegator/frozen_spec.rb @@ -10,30 +10,30 @@ describe "Delegator when frozen" do it "is still readable" do @delegate.should == [42, :hello] - @delegate.include?("bar").should be_false + @delegate.include?("bar").should == false end it "is frozen" do - @delegate.frozen?.should be_true + @delegate.frozen?.should == true end it "is not writable" do - ->{ @delegate[0] += 2 }.should raise_error( RuntimeError ) + ->{ @delegate[0] += 2 }.should.raise( RuntimeError ) end it "creates a frozen clone" do - @delegate.clone.frozen?.should be_true + @delegate.clone.frozen?.should == true end it "creates an unfrozen dup" do - @delegate.dup.frozen?.should be_false + @delegate.dup.frozen?.should == false end it "causes mutative calls to raise RuntimeError" do - ->{ @delegate.__setobj__("hola!") }.should raise_error( RuntimeError ) + ->{ @delegate.__setobj__("hola!") }.should.raise( RuntimeError ) end it "returns false if only the delegated object is frozen" do - DelegateSpecs::Delegator.new([1,2,3].freeze).frozen?.should be_false + DelegateSpecs::Delegator.new([1,2,3].freeze).frozen?.should == false end end diff --git a/spec/ruby/library/delegate/delegator/marshal_spec.rb b/spec/ruby/library/delegate/delegator/marshal_spec.rb index 6c75c8f573..2817ac7e0b 100644 --- a/spec/ruby/library/delegate/delegator/marshal_spec.rb +++ b/spec/ruby/library/delegate/delegator/marshal_spec.rb @@ -10,7 +10,7 @@ describe "SimpleDelegator" do it "can be marshalled" do m = Marshal.load(Marshal.dump(@delegate)) m.class.should == SimpleDelegator - (m == @obj).should be_true + (m == @obj).should == true end it "can be marshalled with its instance variables intact" do diff --git a/spec/ruby/library/delegate/delegator/method_spec.rb b/spec/ruby/library/delegate/delegator/method_spec.rb index 81c8eea710..e41d3b4a53 100644 --- a/spec/ruby/library/delegate/delegator/method_spec.rb +++ b/spec/ruby/library/delegate/delegator/method_spec.rb @@ -9,7 +9,7 @@ describe "Delegator#method" do it "returns a method object for public methods of the delegate object" do m = @delegate.method(:pub) - m.should be_an_instance_of(Method) + m.should.instance_of?(Method) m.call.should == :foo end @@ -18,7 +18,7 @@ describe "Delegator#method" do -> { @delegate.method(:prot) }.should complain(/delegator does not forward private method #prot/) - }.should raise_error(NameError) + }.should.raise(NameError) end it "raises a NameError for a private methods of the delegate object" do @@ -26,36 +26,36 @@ describe "Delegator#method" do -> { @delegate.method(:priv) }.should complain(/delegator does not forward private method #priv/) - }.should raise_error(NameError) + }.should.raise(NameError) end it "returns a method object for public methods of the Delegator class" do m = @delegate.method(:extra) - m.should be_an_instance_of(Method) + m.should.instance_of?(Method) m.call.should == :cheese end it "returns a method object for protected methods of the Delegator class" do m = @delegate.method(:extra_protected) - m.should be_an_instance_of(Method) + m.should.instance_of?(Method) m.call.should == :baz end it "returns a method object for private methods of the Delegator class" do m = @delegate.method(:extra_private) - m.should be_an_instance_of(Method) + m.should.instance_of?(Method) m.call.should == :bar end it "raises a NameError for an invalid method name" do -> { @delegate.method(:invalid_and_silly_method_name) - }.should raise_error(NameError) + }.should.raise(NameError) end it "returns a method that respond_to_missing?" do m = @delegate.method(:pub_too) - m.should be_an_instance_of(Method) + m.should.instance_of?(Method) m.call.should == :pub_too end @@ -64,6 +64,6 @@ describe "Delegator#method" do @delegate.__setobj__([1,2,3]) -> { m.call - }.should raise_error(NameError) + }.should.raise(NameError) end end diff --git a/spec/ruby/library/delegate/delegator/methods_spec.rb b/spec/ruby/library/delegate/delegator/methods_spec.rb index b9942bd230..928f63f21d 100644 --- a/spec/ruby/library/delegate/delegator/methods_spec.rb +++ b/spec/ruby/library/delegate/delegator/methods_spec.rb @@ -14,24 +14,24 @@ describe "Delegator#methods" do end it "returns singleton methods when passed false" do - @delegate.methods(false).should include(:singleton_method) + @delegate.methods(false).should.include?(:singleton_method) end it "includes all public methods of the delegate object" do - @methods.should include :pub + @methods.should.include? :pub end it "includes all protected methods of the delegate object" do - @methods.should include :prot + @methods.should.include? :prot end it "includes instance methods of the Delegator class" do - @methods.should include :extra - @methods.should include :extra_protected + @methods.should.include? :extra + @methods.should.include? :extra_protected end it "does not include private methods" do - @methods.should_not include :priv - @methods.should_not include :extra_private + @methods.should_not.include? :priv + @methods.should_not.include? :extra_private end end diff --git a/spec/ruby/library/delegate/delegator/not_equal_spec.rb b/spec/ruby/library/delegate/delegator/not_equal_spec.rb index 6f2df21715..7fd234a671 100644 --- a/spec/ruby/library/delegate/delegator/not_equal_spec.rb +++ b/spec/ruby/library/delegate/delegator/not_equal_spec.rb @@ -9,16 +9,16 @@ describe "Delegator#!=" do it "is not delegated when passed self" do @base.should_not_receive(:"!=") - (@delegator != @delegator).should be_false + (@delegator != @delegator).should == false end it "is delegated when passed the delegated object" do @base.should_receive(:"!=").and_return(true) - (@delegator != @base).should be_true + (@delegator != @base).should == true end it "is delegated in general" do @base.should_receive(:"!=").and_return(false) - (@delegator != 42).should be_false + (@delegator != 42).should == false end end diff --git a/spec/ruby/library/delegate/delegator/private_methods_spec.rb b/spec/ruby/library/delegate/delegator/private_methods_spec.rb index 7724b8d413..5615ed0668 100644 --- a/spec/ruby/library/delegate/delegator/private_methods_spec.rb +++ b/spec/ruby/library/delegate/delegator/private_methods_spec.rb @@ -9,12 +9,12 @@ describe "Delegator#private_methods" do end it "does not include any method of the delegate object" do # since delegates does not forward private calls - @methods.should_not include :priv - @methods.should_not include :prot - @methods.should_not include :pub + @methods.should_not.include? :priv + @methods.should_not.include? :prot + @methods.should_not.include? :pub end it "includes all private instance methods of the Delegate class" do - @methods.should include :extra_private + @methods.should.include? :extra_private end end diff --git a/spec/ruby/library/delegate/delegator/protected_methods_spec.rb b/spec/ruby/library/delegate/delegator/protected_methods_spec.rb index fd7874fb21..3ee999fdac 100644 --- a/spec/ruby/library/delegate/delegator/protected_methods_spec.rb +++ b/spec/ruby/library/delegate/delegator/protected_methods_spec.rb @@ -9,10 +9,10 @@ describe "Delegator#protected_methods" do end it "includes protected methods of the delegate object" do - @methods.should include :prot + @methods.should.include? :prot end it "includes protected instance methods of the Delegator class" do - @methods.should include :extra_protected + @methods.should.include? :extra_protected end end diff --git a/spec/ruby/library/delegate/delegator/public_methods_spec.rb b/spec/ruby/library/delegate/delegator/public_methods_spec.rb index 18da16a613..8cf6621e2d 100644 --- a/spec/ruby/library/delegate/delegator/public_methods_spec.rb +++ b/spec/ruby/library/delegate/delegator/public_methods_spec.rb @@ -9,10 +9,10 @@ describe "Delegator#public_methods" do end it "includes public methods of the delegate object" do - @methods.should include :pub + @methods.should.include? :pub end it "includes public instance methods of the Delegator class" do - @methods.should include :extra + @methods.should.include? :extra end end diff --git a/spec/ruby/library/delegate/delegator/send_spec.rb b/spec/ruby/library/delegate/delegator/send_spec.rb index 3022c2ce91..cc18a2794b 100644 --- a/spec/ruby/library/delegate/delegator/send_spec.rb +++ b/spec/ruby/library/delegate/delegator/send_spec.rb @@ -12,15 +12,15 @@ describe "SimpleDelegator.new" do end it "forwards protected method calls" do - ->{ @delegate.prot }.should raise_error( NoMethodError ) + ->{ @delegate.prot }.should.raise( NoMethodError ) end it "doesn't forward private method calls" do - ->{ @delegate.priv }.should raise_error( NoMethodError ) + ->{ @delegate.priv }.should.raise( NoMethodError ) end it "doesn't forward private method calls even via send or __send__" do - ->{ @delegate.send(:priv, 42) }.should raise_error( NoMethodError ) - ->{ @delegate.__send__(:priv, 42) }.should raise_error( NoMethodError ) + ->{ @delegate.send(:priv, 42) }.should.raise( NoMethodError ) + ->{ @delegate.__send__(:priv, 42) }.should.raise( NoMethodError ) end end diff --git a/spec/ruby/library/delegate/delegator/tap_spec.rb b/spec/ruby/library/delegate/delegator/tap_spec.rb index 34a88fa1d5..916e4a37fe 100644 --- a/spec/ruby/library/delegate/delegator/tap_spec.rb +++ b/spec/ruby/library/delegate/delegator/tap_spec.rb @@ -11,6 +11,6 @@ describe "Delegator#tap" do yielded << x end yielded.size.should == 1 - yielded[0].equal?(delegator).should be_true + yielded[0].equal?(delegator).should == true end end diff --git a/spec/ruby/library/digest/bubblebabble_spec.rb b/spec/ruby/library/digest/bubblebabble_spec.rb index bbc11ceec5..44a9bf0e26 100644 --- a/spec/ruby/library/digest/bubblebabble_spec.rb +++ b/spec/ruby/library/digest/bubblebabble_spec.rb @@ -3,7 +3,7 @@ require 'digest/bubblebabble' describe "Digest.bubblebabble" do it "returns a String" do - Digest.bubblebabble('').should be_an_instance_of(String) + Digest.bubblebabble('').should.instance_of?(String) end it "returns a String in the Bubble Babble Binary Data Encoding format" do @@ -20,10 +20,10 @@ describe "Digest.bubblebabble" do end it "raises a TypeError when passed nil" do - -> { Digest.bubblebabble(nil) }.should raise_error(TypeError) + -> { Digest.bubblebabble(nil) }.should.raise(TypeError) end it "raises a TypeError when passed an Integer" do - -> { Digest.bubblebabble(9001) }.should raise_error(TypeError) + -> { Digest.bubblebabble(9001) }.should.raise(TypeError) end end diff --git a/spec/ruby/library/digest/hexencode_spec.rb b/spec/ruby/library/digest/hexencode_spec.rb index 4b6db6eaff..3359303d15 100644 --- a/spec/ruby/library/digest/hexencode_spec.rb +++ b/spec/ruby/library/digest/hexencode_spec.rb @@ -22,10 +22,10 @@ describe "Digest.hexencode" do end it "raises a TypeError when passed nil" do - -> { Digest.hexencode(nil) }.should raise_error(TypeError) + -> { Digest.hexencode(nil) }.should.raise(TypeError) end it "raises a TypeError when passed an Integer" do - -> { Digest.hexencode(9001) }.should raise_error(TypeError) + -> { Digest.hexencode(9001) }.should.raise(TypeError) end end diff --git a/spec/ruby/library/digest/instance/append_spec.rb b/spec/ruby/library/digest/instance/append_spec.rb index 2499579298..7f4ce3d121 100644 --- a/spec/ruby/library/digest/instance/append_spec.rb +++ b/spec/ruby/library/digest/instance/append_spec.rb @@ -1,7 +1,11 @@ require_relative '../../../spec_helper' require 'digest' -require_relative 'shared/update' describe "Digest::Instance#<<" do - it_behaves_like :digest_instance_update, :<< + it "raises a RuntimeError if called" do + c = Class.new do + include Digest::Instance + end + -> { c.new << "test" }.should.raise(RuntimeError) + end end diff --git a/spec/ruby/library/digest/instance/shared/update.rb b/spec/ruby/library/digest/instance/shared/update.rb deleted file mode 100644 index 17779e54a4..0000000000 --- a/spec/ruby/library/digest/instance/shared/update.rb +++ /dev/null @@ -1,8 +0,0 @@ -describe :digest_instance_update, shared: true do - it "raises a RuntimeError if called" do - c = Class.new do - include Digest::Instance - end - -> { c.new.send(@method, "test") }.should raise_error(RuntimeError) - end -end diff --git a/spec/ruby/library/digest/instance/update_spec.rb b/spec/ruby/library/digest/instance/update_spec.rb index 3bb4dd7f1b..d15b976213 100644 --- a/spec/ruby/library/digest/instance/update_spec.rb +++ b/spec/ruby/library/digest/instance/update_spec.rb @@ -1,7 +1,8 @@ require_relative '../../../spec_helper' require 'digest' -require_relative 'shared/update' describe "Digest::Instance#update" do - it_behaves_like :digest_instance_update, :update + it "is an alias of Digest::Instance#<<" do + Digest::Instance.instance_method(:update).should == Digest::Instance.instance_method(:<<) + end end diff --git a/spec/ruby/library/digest/md5/append_spec.rb b/spec/ruby/library/digest/md5/append_spec.rb index 0abdc074a1..6f42e4f286 100644 --- a/spec/ruby/library/digest/md5/append_spec.rb +++ b/spec/ruby/library/digest/md5/append_spec.rb @@ -1,7 +1,10 @@ require_relative '../../../spec_helper' require_relative 'shared/constants' -require_relative 'shared/update' describe "Digest::MD5#<<" do - it_behaves_like :md5_update, :<< + it "can update" do + cur_digest = Digest::MD5.new + cur_digest << MD5Constants::Contents + cur_digest.digest.should == MD5Constants::Digest + end end diff --git a/spec/ruby/library/digest/md5/file_spec.rb b/spec/ruby/library/digest/md5/file_spec.rb index 0c8d12cbc9..9a78a8c055 100644 --- a/spec/ruby/library/digest/md5/file_spec.rb +++ b/spec/ruby/library/digest/md5/file_spec.rb @@ -15,7 +15,7 @@ describe "Digest::MD5.file" do end it "returns a Digest::MD5 object" do - Digest::MD5.file(@file).should be_kind_of(Digest::MD5) + Digest::MD5.file(@file).should.is_a?(Digest::MD5) end it "returns a Digest::MD5 object with the correct digest" do @@ -26,7 +26,7 @@ describe "Digest::MD5.file" do obj = mock("to_str") obj.should_receive(:to_str).and_return(@file) result = Digest::MD5.file(obj) - result.should be_kind_of(Digest::MD5) + result.should.is_a?(Digest::MD5) result.digest.should == MD5Constants::Digest end end @@ -34,10 +34,10 @@ describe "Digest::MD5.file" do it_behaves_like :file_read_directory, :file, Digest::MD5 it "raises a Errno::ENOENT when passed a path that does not exist" do - -> { Digest::MD5.file("") }.should raise_error(Errno::ENOENT) + -> { Digest::MD5.file("") }.should.raise(Errno::ENOENT) end it "raises a TypeError when passed nil" do - -> { Digest::MD5.file(nil) }.should raise_error(TypeError) + -> { Digest::MD5.file(nil) }.should.raise(TypeError) end end diff --git a/spec/ruby/library/digest/md5/length_spec.rb b/spec/ruby/library/digest/md5/length_spec.rb index b05b2a20fd..18bda51129 100644 --- a/spec/ruby/library/digest/md5/length_spec.rb +++ b/spec/ruby/library/digest/md5/length_spec.rb @@ -1,7 +1,11 @@ require_relative '../../../spec_helper' require_relative 'shared/constants' -require_relative 'shared/length' describe "Digest::MD5#length" do - it_behaves_like :md5_length, :length + it "returns the length of the digest" do + cur_digest = Digest::MD5.new + cur_digest.length.should == MD5Constants::BlankDigest.size + cur_digest << MD5Constants::Contents + cur_digest.length.should == MD5Constants::Digest.size + end end diff --git a/spec/ruby/library/digest/md5/shared/length.rb b/spec/ruby/library/digest/md5/shared/length.rb deleted file mode 100644 index c5b2b97b58..0000000000 --- a/spec/ruby/library/digest/md5/shared/length.rb +++ /dev/null @@ -1,8 +0,0 @@ -describe :md5_length, shared: true do - it "returns the length of the digest" do - cur_digest = Digest::MD5.new - cur_digest.send(@method).should == MD5Constants::BlankDigest.size - cur_digest << MD5Constants::Contents - cur_digest.send(@method).should == MD5Constants::Digest.size - end -end diff --git a/spec/ruby/library/digest/md5/shared/update.rb b/spec/ruby/library/digest/md5/shared/update.rb deleted file mode 100644 index be8622aed5..0000000000 --- a/spec/ruby/library/digest/md5/shared/update.rb +++ /dev/null @@ -1,7 +0,0 @@ -describe :md5_update, shared: true do - it "can update" do - cur_digest = Digest::MD5.new - cur_digest.send @method, MD5Constants::Contents - cur_digest.digest.should == MD5Constants::Digest - end -end diff --git a/spec/ruby/library/digest/md5/size_spec.rb b/spec/ruby/library/digest/md5/size_spec.rb index 22e3272d36..54709234de 100644 --- a/spec/ruby/library/digest/md5/size_spec.rb +++ b/spec/ruby/library/digest/md5/size_spec.rb @@ -1,7 +1,8 @@ require_relative '../../../spec_helper' require_relative 'shared/constants' -require_relative 'shared/length' describe "Digest::MD5#size" do - it_behaves_like :md5_length, :size + it "is an alias of Digest::MD5#length" do + Digest::MD5.instance_method(:size).should == Digest::MD5.instance_method(:length) + end end diff --git a/spec/ruby/library/digest/md5/update_spec.rb b/spec/ruby/library/digest/md5/update_spec.rb index 4773db308c..830ccfead6 100644 --- a/spec/ruby/library/digest/md5/update_spec.rb +++ b/spec/ruby/library/digest/md5/update_spec.rb @@ -1,7 +1,8 @@ require_relative '../../../spec_helper' -require_relative 'shared/constants' -require_relative 'shared/update' +require 'digest' describe "Digest::MD5#update" do - it_behaves_like :md5_update, :update + it "is an alias of Digest::MD5#<<" do + Digest::MD5.instance_method(:update).should == Digest::MD5.instance_method(:<<) + end end diff --git a/spec/ruby/library/digest/sha1/file_spec.rb b/spec/ruby/library/digest/sha1/file_spec.rb index 9c15f5b02f..d36e560e21 100644 --- a/spec/ruby/library/digest/sha1/file_spec.rb +++ b/spec/ruby/library/digest/sha1/file_spec.rb @@ -15,7 +15,7 @@ describe "Digest::SHA1.file" do end it "returns a Digest::SHA1 object" do - Digest::SHA1.file(@file).should be_kind_of(Digest::SHA1) + Digest::SHA1.file(@file).should.is_a?(Digest::SHA1) end it "returns a Digest::SHA1 object with the correct digest" do @@ -26,7 +26,7 @@ describe "Digest::SHA1.file" do obj = mock("to_str") obj.should_receive(:to_str).and_return(@file) result = Digest::SHA1.file(obj) - result.should be_kind_of(Digest::SHA1) + result.should.is_a?(Digest::SHA1) result.digest.should == SHA1Constants::Digest end end @@ -34,10 +34,10 @@ describe "Digest::SHA1.file" do it_behaves_like :file_read_directory, :file, Digest::SHA1 it "raises a Errno::ENOENT when passed a path that does not exist" do - -> { Digest::SHA1.file("") }.should raise_error(Errno::ENOENT) + -> { Digest::SHA1.file("") }.should.raise(Errno::ENOENT) end it "raises a TypeError when passed nil" do - -> { Digest::SHA1.file(nil) }.should raise_error(TypeError) + -> { Digest::SHA1.file(nil) }.should.raise(TypeError) end end diff --git a/spec/ruby/library/digest/sha256/append_spec.rb b/spec/ruby/library/digest/sha256/append_spec.rb index ab594c105f..f18b06c2a1 100644 --- a/spec/ruby/library/digest/sha256/append_spec.rb +++ b/spec/ruby/library/digest/sha256/append_spec.rb @@ -1,7 +1,10 @@ require_relative '../../../spec_helper' require_relative 'shared/constants' -require_relative 'shared/update' describe "Digest::SHA256#<<" do - it_behaves_like :sha256_update, :<< + it "can update" do + cur_digest = Digest::SHA256.new + cur_digest << SHA256Constants::Contents + cur_digest.digest.should == SHA256Constants::Digest + end end diff --git a/spec/ruby/library/digest/sha256/file_spec.rb b/spec/ruby/library/digest/sha256/file_spec.rb index 8cbc5a2755..d67a9ebcd6 100644 --- a/spec/ruby/library/digest/sha256/file_spec.rb +++ b/spec/ruby/library/digest/sha256/file_spec.rb @@ -15,7 +15,7 @@ describe "Digest::SHA256.file" do end it "returns a Digest::SHA256 object" do - Digest::SHA256.file(@file).should be_kind_of(Digest::SHA256) + Digest::SHA256.file(@file).should.is_a?(Digest::SHA256) end it "returns a Digest::SHA256 object with the correct digest" do @@ -30,7 +30,7 @@ describe "Digest::SHA256.file" do obj = mock("to_str") obj.should_receive(:to_str).and_return(@file) result = Digest::SHA256.file(obj) - result.should be_kind_of(Digest::SHA256) + result.should.is_a?(Digest::SHA256) result.digest.should == SHA256Constants::Digest end end @@ -38,10 +38,10 @@ describe "Digest::SHA256.file" do it_behaves_like :file_read_directory, :file, Digest::SHA256 it "raises a Errno::ENOENT when passed a path that does not exist" do - -> { Digest::SHA256.file("") }.should raise_error(Errno::ENOENT) + -> { Digest::SHA256.file("") }.should.raise(Errno::ENOENT) end it "raises a TypeError when passed nil" do - -> { Digest::SHA256.file(nil) }.should raise_error(TypeError) + -> { Digest::SHA256.file(nil) }.should.raise(TypeError) end end diff --git a/spec/ruby/library/digest/sha256/length_spec.rb b/spec/ruby/library/digest/sha256/length_spec.rb index 181ac564ad..fc3db6548e 100644 --- a/spec/ruby/library/digest/sha256/length_spec.rb +++ b/spec/ruby/library/digest/sha256/length_spec.rb @@ -1,7 +1,11 @@ require_relative '../../../spec_helper' require_relative 'shared/constants' -require_relative 'shared/length' describe "Digest::SHA256#length" do - it_behaves_like :sha256_length, :length + it "returns the length of the digest" do + cur_digest = Digest::SHA256.new + cur_digest.length.should == SHA256Constants::BlankDigest.size + cur_digest << SHA256Constants::Contents + cur_digest.length.should == SHA256Constants::Digest.size + end end diff --git a/spec/ruby/library/digest/sha256/shared/length.rb b/spec/ruby/library/digest/sha256/shared/length.rb deleted file mode 100644 index 996673a5bd..0000000000 --- a/spec/ruby/library/digest/sha256/shared/length.rb +++ /dev/null @@ -1,8 +0,0 @@ -describe :sha256_length, shared: true do - it "returns the length of the digest" do - cur_digest = Digest::SHA256.new - cur_digest.send(@method).should == SHA256Constants::BlankDigest.size - cur_digest << SHA256Constants::Contents - cur_digest.send(@method).should == SHA256Constants::Digest.size - end -end diff --git a/spec/ruby/library/digest/sha256/shared/update.rb b/spec/ruby/library/digest/sha256/shared/update.rb deleted file mode 100644 index 0edc07935b..0000000000 --- a/spec/ruby/library/digest/sha256/shared/update.rb +++ /dev/null @@ -1,7 +0,0 @@ -describe :sha256_update, shared: true do - it "can update" do - cur_digest = Digest::SHA256.new - cur_digest.send @method, SHA256Constants::Contents - cur_digest.digest.should == SHA256Constants::Digest - end -end diff --git a/spec/ruby/library/digest/sha256/size_spec.rb b/spec/ruby/library/digest/sha256/size_spec.rb index 1028263342..6102e1c8aa 100644 --- a/spec/ruby/library/digest/sha256/size_spec.rb +++ b/spec/ruby/library/digest/sha256/size_spec.rb @@ -1,7 +1,8 @@ require_relative '../../../spec_helper' require_relative 'shared/constants' -require_relative 'shared/length' describe "Digest::SHA256#size" do - it_behaves_like :sha256_length, :size + it "is an alias of Digest::SHA256#length" do + Digest::SHA256.instance_method(:size).should == Digest::SHA256.instance_method(:length) + end end diff --git a/spec/ruby/library/digest/sha256/update_spec.rb b/spec/ruby/library/digest/sha256/update_spec.rb index 92316eb752..d6724936f1 100644 --- a/spec/ruby/library/digest/sha256/update_spec.rb +++ b/spec/ruby/library/digest/sha256/update_spec.rb @@ -1,7 +1,8 @@ require_relative '../../../spec_helper' -require_relative 'shared/constants' -require_relative 'shared/update' +require 'digest' describe "Digest::SHA256#update" do - it_behaves_like :sha256_update, :update + it "is an alias of Digest::SHA256#<<" do + Digest::SHA256.instance_method(:update).should == Digest::SHA256.instance_method(:<<) + end end diff --git a/spec/ruby/library/digest/sha384/append_spec.rb b/spec/ruby/library/digest/sha384/append_spec.rb index 94c036cc3f..b9a862f1c2 100644 --- a/spec/ruby/library/digest/sha384/append_spec.rb +++ b/spec/ruby/library/digest/sha384/append_spec.rb @@ -1,7 +1,10 @@ require_relative '../../../spec_helper' require_relative 'shared/constants' -require_relative 'shared/update' describe "Digest::SHA384#<<" do - it_behaves_like :sha384_update, :<< + it "can update" do + cur_digest = Digest::SHA384.new + cur_digest << SHA384Constants::Contents + cur_digest.digest.should == SHA384Constants::Digest + end end diff --git a/spec/ruby/library/digest/sha384/file_spec.rb b/spec/ruby/library/digest/sha384/file_spec.rb index 8556f10175..3726ad4423 100644 --- a/spec/ruby/library/digest/sha384/file_spec.rb +++ b/spec/ruby/library/digest/sha384/file_spec.rb @@ -15,7 +15,7 @@ describe "Digest::SHA384.file" do end it "returns a Digest::SHA384 object" do - Digest::SHA384.file(@file).should be_kind_of(Digest::SHA384) + Digest::SHA384.file(@file).should.is_a?(Digest::SHA384) end it "returns a Digest::SHA384 object with the correct digest" do @@ -26,7 +26,7 @@ describe "Digest::SHA384.file" do obj = mock("to_str") obj.should_receive(:to_str).and_return(@file) result = Digest::SHA384.file(obj) - result.should be_kind_of(Digest::SHA384) + result.should.is_a?(Digest::SHA384) result.digest.should == SHA384Constants::Digest end end @@ -34,10 +34,10 @@ describe "Digest::SHA384.file" do it_behaves_like :file_read_directory, :file, Digest::SHA384 it "raises a Errno::ENOENT when passed a path that does not exist" do - -> { Digest::SHA384.file("") }.should raise_error(Errno::ENOENT) + -> { Digest::SHA384.file("") }.should.raise(Errno::ENOENT) end it "raises a TypeError when passed nil" do - -> { Digest::SHA384.file(nil) }.should raise_error(TypeError) + -> { Digest::SHA384.file(nil) }.should.raise(TypeError) end end diff --git a/spec/ruby/library/digest/sha384/length_spec.rb b/spec/ruby/library/digest/sha384/length_spec.rb index 33fed492ef..e5cd6131fd 100644 --- a/spec/ruby/library/digest/sha384/length_spec.rb +++ b/spec/ruby/library/digest/sha384/length_spec.rb @@ -1,7 +1,11 @@ require_relative '../../../spec_helper' require_relative 'shared/constants' -require_relative 'shared/length' describe "Digest::SHA384#length" do - it_behaves_like :sha384_length, :length + it "returns the length of the digest" do + cur_digest = Digest::SHA384.new + cur_digest.length.should == SHA384Constants::BlankDigest.size + cur_digest << SHA384Constants::Contents + cur_digest.length.should == SHA384Constants::Digest.size + end end diff --git a/spec/ruby/library/digest/sha384/shared/length.rb b/spec/ruby/library/digest/sha384/shared/length.rb deleted file mode 100644 index 0c88288bcf..0000000000 --- a/spec/ruby/library/digest/sha384/shared/length.rb +++ /dev/null @@ -1,8 +0,0 @@ -describe :sha384_length, shared: true do - it "returns the length of the digest" do - cur_digest = Digest::SHA384.new - cur_digest.send(@method).should == SHA384Constants::BlankDigest.size - cur_digest << SHA384Constants::Contents - cur_digest.send(@method).should == SHA384Constants::Digest.size - end -end diff --git a/spec/ruby/library/digest/sha384/shared/update.rb b/spec/ruby/library/digest/sha384/shared/update.rb deleted file mode 100644 index 1c6e31cf6a..0000000000 --- a/spec/ruby/library/digest/sha384/shared/update.rb +++ /dev/null @@ -1,7 +0,0 @@ -describe :sha384_update, shared: true do - it "can update" do - cur_digest = Digest::SHA384.new - cur_digest.send @method, SHA384Constants::Contents - cur_digest.digest.should == SHA384Constants::Digest - end -end diff --git a/spec/ruby/library/digest/sha384/size_spec.rb b/spec/ruby/library/digest/sha384/size_spec.rb index 4c3b14f7a0..40c291c623 100644 --- a/spec/ruby/library/digest/sha384/size_spec.rb +++ b/spec/ruby/library/digest/sha384/size_spec.rb @@ -1,7 +1,8 @@ require_relative '../../../spec_helper' -require_relative 'shared/constants' -require_relative 'shared/length' +require 'digest' describe "Digest::SHA384#size" do - it_behaves_like :sha384_length, :size + it "is an alias of Digest::SHA384#length" do + Digest::SHA384.instance_method(:size).should == Digest::SHA384.instance_method(:length) + end end diff --git a/spec/ruby/library/digest/sha384/update_spec.rb b/spec/ruby/library/digest/sha384/update_spec.rb index a1d0dd6068..561dcad3ec 100644 --- a/spec/ruby/library/digest/sha384/update_spec.rb +++ b/spec/ruby/library/digest/sha384/update_spec.rb @@ -1,7 +1,8 @@ require_relative '../../../spec_helper' -require_relative 'shared/constants' -require_relative 'shared/update' +require 'digest' describe "Digest::SHA384#update" do - it_behaves_like :sha384_update, :update + it "is an alias of Digest::SHA384#<<" do + Digest::SHA384.instance_method(:update).should == Digest::SHA384.instance_method(:<<) + end end diff --git a/spec/ruby/library/digest/sha512/append_spec.rb b/spec/ruby/library/digest/sha512/append_spec.rb index 9106e9685d..f297005403 100644 --- a/spec/ruby/library/digest/sha512/append_spec.rb +++ b/spec/ruby/library/digest/sha512/append_spec.rb @@ -1,7 +1,10 @@ require_relative '../../../spec_helper' require_relative 'shared/constants' -require_relative 'shared/update' describe "Digest::SHA512#<<" do - it_behaves_like :sha512_update, :<< + it "can update" do + cur_digest = Digest::SHA512.new + cur_digest << SHA512Constants::Contents + cur_digest.digest.should == SHA512Constants::Digest + end end diff --git a/spec/ruby/library/digest/sha512/file_spec.rb b/spec/ruby/library/digest/sha512/file_spec.rb index 781ec781e5..78d6d3d4f3 100644 --- a/spec/ruby/library/digest/sha512/file_spec.rb +++ b/spec/ruby/library/digest/sha512/file_spec.rb @@ -15,7 +15,7 @@ describe "Digest::SHA512.file" do end it "returns a Digest::SHA512 object" do - Digest::SHA512.file(@file).should be_kind_of(Digest::SHA512) + Digest::SHA512.file(@file).should.is_a?(Digest::SHA512) end it "returns a Digest::SHA512 object with the correct digest" do @@ -26,7 +26,7 @@ describe "Digest::SHA512.file" do obj = mock("to_str") obj.should_receive(:to_str).and_return(@file) result = Digest::SHA512.file(obj) - result.should be_kind_of(Digest::SHA512) + result.should.is_a?(Digest::SHA512) result.digest.should == SHA512Constants::Digest end end @@ -34,10 +34,10 @@ describe "Digest::SHA512.file" do it_behaves_like :file_read_directory, :file, Digest::SHA512 it "raises a Errno::ENOENT when passed a path that does not exist" do - -> { Digest::SHA512.file("") }.should raise_error(Errno::ENOENT) + -> { Digest::SHA512.file("") }.should.raise(Errno::ENOENT) end it "raises a TypeError when passed nil" do - -> { Digest::SHA512.file(nil) }.should raise_error(TypeError) + -> { Digest::SHA512.file(nil) }.should.raise(TypeError) end end diff --git a/spec/ruby/library/digest/sha512/length_spec.rb b/spec/ruby/library/digest/sha512/length_spec.rb index e9fde90577..8e909482c5 100644 --- a/spec/ruby/library/digest/sha512/length_spec.rb +++ b/spec/ruby/library/digest/sha512/length_spec.rb @@ -1,7 +1,11 @@ require_relative '../../../spec_helper' require_relative 'shared/constants' -require_relative 'shared/length' describe "Digest::SHA512#length" do - it_behaves_like :sha512_length, :length + it "returns the length of the digest" do + cur_digest = Digest::SHA512.new + cur_digest.length.should == SHA512Constants::BlankDigest.size + cur_digest << SHA512Constants::Contents + cur_digest.length.should == SHA512Constants::Digest.size + end end diff --git a/spec/ruby/library/digest/sha512/shared/length.rb b/spec/ruby/library/digest/sha512/shared/length.rb deleted file mode 100644 index c0609d5386..0000000000 --- a/spec/ruby/library/digest/sha512/shared/length.rb +++ /dev/null @@ -1,8 +0,0 @@ -describe :sha512_length, shared: true do - it "returns the length of the digest" do - cur_digest = Digest::SHA512.new - cur_digest.send(@method).should == SHA512Constants::BlankDigest.size - cur_digest << SHA512Constants::Contents - cur_digest.send(@method).should == SHA512Constants::Digest.size - end -end diff --git a/spec/ruby/library/digest/sha512/shared/update.rb b/spec/ruby/library/digest/sha512/shared/update.rb deleted file mode 100644 index ca74dbf4df..0000000000 --- a/spec/ruby/library/digest/sha512/shared/update.rb +++ /dev/null @@ -1,7 +0,0 @@ -describe :sha512_update, shared: true do - it "can update" do - cur_digest = Digest::SHA512.new - cur_digest.send @method, SHA512Constants::Contents - cur_digest.digest.should == SHA512Constants::Digest - end -end diff --git a/spec/ruby/library/digest/sha512/size_spec.rb b/spec/ruby/library/digest/sha512/size_spec.rb index 6d0acdabdb..498d686802 100644 --- a/spec/ruby/library/digest/sha512/size_spec.rb +++ b/spec/ruby/library/digest/sha512/size_spec.rb @@ -1,7 +1,8 @@ require_relative '../../../spec_helper' -require_relative 'shared/constants' -require_relative 'shared/length' +require 'digest' describe "Digest::SHA512#size" do - it_behaves_like :sha512_length, :size + it "is an alias of Digest::SHA512#length" do + Digest::SHA512.instance_method(:size).should == Digest::SHA512.instance_method(:length) + end end diff --git a/spec/ruby/library/digest/sha512/update_spec.rb b/spec/ruby/library/digest/sha512/update_spec.rb index 682d3a19bb..33edf216ac 100644 --- a/spec/ruby/library/digest/sha512/update_spec.rb +++ b/spec/ruby/library/digest/sha512/update_spec.rb @@ -1,7 +1,8 @@ require_relative '../../../spec_helper' -require_relative 'shared/constants' -require_relative 'shared/update' +require 'digest' describe "Digest::SHA512#update" do - it_behaves_like :sha512_update, :update + it "is an alias of Digest::SHA512#<<" do + Digest::SHA512.instance_method(:update).should == Digest::SHA512.instance_method(:<<) + end end diff --git a/spec/ruby/library/erb/filename_spec.rb b/spec/ruby/library/erb/filename_spec.rb index 8ecaed7343..bbd2233bb3 100644 --- a/spec/ruby/library/erb/filename_spec.rb +++ b/spec/ruby/library/erb/filename_spec.rb @@ -13,7 +13,7 @@ describe "ERB#filename" do @ex = e raise e end - }.should raise_error(SyntaxError) + }.should.raise(SyntaxError) expected = filename @ex.message =~ /^(.*?):(\d+): / @@ -30,7 +30,7 @@ describe "ERB#filename" do @ex = e raise e end - }.should raise_error(SyntaxError) + }.should.raise(SyntaxError) expected = '(erb)' @ex.message =~ /^(.*?):(\d+): / diff --git a/spec/ruby/library/erb/new_spec.rb b/spec/ruby/library/erb/new_spec.rb index ec1be5c234..35ac0dfdfe 100644 --- a/spec/ruby/library/erb/new_spec.rb +++ b/spec/ruby/library/erb/new_spec.rb @@ -83,7 +83,7 @@ END -> { ERBSpecs.new_erb(input, trim_mode: '-').result - }.should raise_error(SyntaxError) + }.should.raise(SyntaxError) end it "regards lines starting with '%' as '<% ... %>' when trim_mode is '%'" do @@ -136,20 +136,22 @@ END it "forget local variables defined previous one" do ERB.new(@eruby_str).result - ->{ ERB.new("<%= list %>").result }.should raise_error(NameError) + ->{ ERB.new("<%= list %>").result }.should.raise(NameError) end - describe "warning about arguments" do - it "warns when passed safe_level and later arguments" do - -> { - ERB.new(@eruby_str, nil, '%') - }.should complain(/warning: Passing safe_level with the 2nd argument of ERB.new is deprecated. Do not use it, and specify other arguments as keyword arguments./) - end - - it "does not warn when passed arguments as keyword argument" do - -> { - ERB.new(@eruby_str, trim_mode: '%') - }.should_not complain(/warning: Passing safe_level with the 2nd argument of ERB.new is deprecated. Do not use it, and specify other arguments as keyword arguments./) + 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, '%') + }.should complain(/warning: Passing safe_level with the 2nd argument of ERB.new is deprecated. Do not use it, and specify other arguments as keyword arguments./) + end + + it "does not warn when passed arguments as keyword argument" do + -> { + ERB.new(@eruby_str, trim_mode: '%') + }.should_not complain(/warning: Passing safe_level with the 2nd argument of ERB.new is deprecated. Do not use it, and specify other arguments as keyword arguments./) + end end end end diff --git a/spec/ruby/library/erb/result_spec.rb b/spec/ruby/library/erb/result_spec.rb index a29c1ccedb..84333031ec 100644 --- a/spec/ruby/library/erb/result_spec.rb +++ b/spec/ruby/library/erb/result_spec.rb @@ -43,7 +43,7 @@ END input = "<%=h '<>' %>" -> { ERB.new(input).result() - }.should raise_error(NameError) + }.should.raise(NameError) end @@ -81,6 +81,6 @@ END -> { myerb2.new.main2() - }.should raise_error(NameError) + }.should.raise(NameError) end end diff --git a/spec/ruby/library/erb/run_spec.rb b/spec/ruby/library/erb/run_spec.rb index 602e53ab38..d81d534087 100644 --- a/spec/ruby/library/erb/run_spec.rb +++ b/spec/ruby/library/erb/run_spec.rb @@ -54,7 +54,7 @@ END input = "<%=h '<>' %>" -> { _steal_stdout { ERB.new(input).run() } - }.should raise_error(NameError) + }.should.raise(NameError) end it "is able to h() or u() if ERB::Util is included" do @@ -91,6 +91,6 @@ END -> { _steal_stdout { myerb2.new.main2() } - }.should raise_error(NameError) + }.should.raise(NameError) end end diff --git a/spec/ruby/library/etc/confstr_spec.rb b/spec/ruby/library/etc/confstr_spec.rb index 5b43461150..786cb16407 100644 --- a/spec/ruby/library/etc/confstr_spec.rb +++ b/spec/ruby/library/etc/confstr_spec.rb @@ -4,11 +4,11 @@ require 'etc' platform_is_not :windows, :android do describe "Etc.confstr" do it "returns a String for Etc::CS_PATH" do - Etc.confstr(Etc::CS_PATH).should be_an_instance_of(String) + Etc.confstr(Etc::CS_PATH).should.instance_of?(String) end it "raises Errno::EINVAL for unknown configuration variables" do - -> { Etc.confstr(-1) }.should raise_error(Errno::EINVAL) + -> { Etc.confstr(-1) }.should.raise(Errno::EINVAL) end end end diff --git a/spec/ruby/library/etc/getgrgid_spec.rb b/spec/ruby/library/etc/getgrgid_spec.rb index 14da5e041d..472d4c82c8 100644 --- a/spec/ruby/library/etc/getgrgid_spec.rb +++ b/spec/ruby/library/etc/getgrgid_spec.rb @@ -34,7 +34,7 @@ platform_is_not :windows do it "returns the Etc::Group for a given gid if it exists" do grp = Etc.getgrgid(@gid) - grp.should be_kind_of(Etc::Group) + grp.should.is_a?(Etc::Group) grp.gid.should == @gid grp.name.should == @name end @@ -47,12 +47,12 @@ platform_is_not :windows do end it "raises if the group does not exist" do - -> { Etc.getgrgid(9876)}.should raise_error(ArgumentError) + -> { Etc.getgrgid(9876)}.should.raise(ArgumentError) end it "raises a TypeError if not passed an Integer" do - -> { Etc.getgrgid("foo") }.should raise_error(TypeError) - -> { Etc.getgrgid(nil) }.should raise_error(TypeError) + -> { Etc.getgrgid("foo") }.should.raise(TypeError) + -> { Etc.getgrgid(nil) }.should.raise(TypeError) end it "can be called safely by multiple threads" do diff --git a/spec/ruby/library/etc/getgrnam_spec.rb b/spec/ruby/library/etc/getgrnam_spec.rb index fa49f15349..325ea7b297 100644 --- a/spec/ruby/library/etc/getgrnam_spec.rb +++ b/spec/ruby/library/etc/getgrnam_spec.rb @@ -24,7 +24,7 @@ platform_is_not :windows, :android do -> { Etc.getgrnam(123) Etc.getgrnam(nil) - }.should raise_error(TypeError) + }.should.raise(TypeError) end end end diff --git a/spec/ruby/library/etc/getlogin_spec.rb b/spec/ruby/library/etc/getlogin_spec.rb index 7a4fd79ae2..2bc598c0af 100644 --- a/spec/ruby/library/etc/getlogin_spec.rb +++ b/spec/ruby/library/etc/getlogin_spec.rb @@ -14,7 +14,7 @@ describe "Etc.getlogin" do if ENV['TRAVIS'] and platform_is(:darwin) # See https://travis-ci.org/ruby/spec/jobs/285967744 # and https://travis-ci.org/ruby/spec/jobs/285999602 - Etc.getlogin.should be_an_instance_of(String) + Etc.getlogin.should.instance_of?(String) else # Etc.getlogin returns the same result of logname(2) # if it returns non NULL @@ -28,7 +28,7 @@ describe "Etc.getlogin" do else # Etc.getlogin may return nil if the login name is not set # because of chroot or sudo or something. - Etc.getlogin.should be_nil + Etc.getlogin.should == nil getlogin_null = true end ensure diff --git a/spec/ruby/library/etc/getpwnam_spec.rb b/spec/ruby/library/etc/getpwnam_spec.rb index 3f4416aa9d..a0b3c9e1fe 100644 --- a/spec/ruby/library/etc/getpwnam_spec.rb +++ b/spec/ruby/library/etc/getpwnam_spec.rb @@ -22,7 +22,7 @@ platform_is_not :windows do -> { Etc.getpwnam(123) Etc.getpwnam(nil) - }.should raise_error(TypeError) + }.should.raise(TypeError) end end end diff --git a/spec/ruby/library/etc/getpwuid_spec.rb b/spec/ruby/library/etc/getpwuid_spec.rb index 5b98f0f8d9..3e35dfe6d5 100644 --- a/spec/ruby/library/etc/getpwuid_spec.rb +++ b/spec/ruby/library/etc/getpwuid_spec.rb @@ -30,7 +30,7 @@ platform_is_not :windows do -> { Etc.getpwuid("foo") Etc.getpwuid(nil) - }.should raise_error(TypeError) + }.should.raise(TypeError) end end end diff --git a/spec/ruby/library/etc/group_spec.rb b/spec/ruby/library/etc/group_spec.rb index fda808eec9..d7addbbec1 100644 --- a/spec/ruby/library/etc/group_spec.rb +++ b/spec/ruby/library/etc/group_spec.rb @@ -9,7 +9,7 @@ describe "Etc.group" do it "returns a Etc::Group struct" do group = Etc.group begin - group.should be_an_instance_of(Etc::Group) + group.should.instance_of?(Etc::Group) ensure Etc.endgrent end @@ -21,7 +21,7 @@ describe "Etc.group" do Etc.group do | group2 | end end - }.should raise_error(RuntimeError) + }.should.raise(RuntimeError) end end end diff --git a/spec/ruby/library/etc/nprocessors_spec.rb b/spec/ruby/library/etc/nprocessors_spec.rb index ec7ffc81da..482719dde0 100644 --- a/spec/ruby/library/etc/nprocessors_spec.rb +++ b/spec/ruby/library/etc/nprocessors_spec.rb @@ -3,7 +3,7 @@ require 'etc' describe "Etc.nprocessors" do it "returns the number of online processors" do - Etc.nprocessors.should be_kind_of(Integer) + Etc.nprocessors.should.is_a?(Integer) Etc.nprocessors.should >= 1 end end diff --git a/spec/ruby/library/etc/passwd_spec.rb b/spec/ruby/library/etc/passwd_spec.rb index 7157fd3f2e..0602b7e10b 100644 --- a/spec/ruby/library/etc/passwd_spec.rb +++ b/spec/ruby/library/etc/passwd_spec.rb @@ -6,7 +6,7 @@ platform_is_not :windows do it "returns a Etc::Passwd struct" do passwd = Etc.passwd begin - passwd.should be_an_instance_of(Etc::Passwd) + passwd.should.instance_of?(Etc::Passwd) ensure Etc.endpwent end diff --git a/spec/ruby/library/etc/sysconf_spec.rb b/spec/ruby/library/etc/sysconf_spec.rb index 1f2c7a770f..81ce1ca258 100644 --- a/spec/ruby/library/etc/sysconf_spec.rb +++ b/spec/ruby/library/etc/sysconf_spec.rb @@ -14,7 +14,7 @@ platform_is_not :windows do if value.nil? value.should == nil else - value.should be_kind_of(Integer) + value.should.is_a?(Integer) end end end diff --git a/spec/ruby/library/etc/sysconfdir_spec.rb b/spec/ruby/library/etc/sysconfdir_spec.rb index 8538faa65b..eb2d6b649a 100644 --- a/spec/ruby/library/etc/sysconfdir_spec.rb +++ b/spec/ruby/library/etc/sysconfdir_spec.rb @@ -3,6 +3,6 @@ require 'etc' describe "Etc.sysconfdir" do it "returns a String" do - Etc.sysconfdir.should be_an_instance_of(String) + Etc.sysconfdir.should.instance_of?(String) end end diff --git a/spec/ruby/library/etc/systmpdir_spec.rb b/spec/ruby/library/etc/systmpdir_spec.rb index 5b007aa9f9..ed34cb43fc 100644 --- a/spec/ruby/library/etc/systmpdir_spec.rb +++ b/spec/ruby/library/etc/systmpdir_spec.rb @@ -3,6 +3,6 @@ require 'etc' describe "Etc.systmpdir" do it "returns a String" do - Etc.systmpdir.should be_an_instance_of(String) + Etc.systmpdir.should.instance_of?(String) end end diff --git a/spec/ruby/library/etc/uname_spec.rb b/spec/ruby/library/etc/uname_spec.rb index a42558f593..1c5fe2a741 100644 --- a/spec/ruby/library/etc/uname_spec.rb +++ b/spec/ruby/library/etc/uname_spec.rb @@ -4,7 +4,7 @@ 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.is_a?(Hash) uname.should.key?(:sysname) uname.should.key?(:nodename) uname.should.key?(:release) diff --git a/spec/ruby/library/expect/expect_spec.rb b/spec/ruby/library/expect/expect_spec.rb index 76ea3d5451..ba705c5535 100644 --- a/spec/ruby/library/expect/expect_spec.rb +++ b/spec/ruby/library/expect/expect_spec.rb @@ -40,14 +40,14 @@ platform_is_not :windows do -> { @read.expect("hello") - }.should raise_error(IOError) + }.should.raise(IOError) end it "returns nil if eof is hit" do @write << "pro" @write.close - @read.expect("prompt").should be_nil + @read.expect("prompt").should == nil end it "yields the result if a block is given" do diff --git a/spec/ruby/library/fiddle/handle/initialize_spec.rb b/spec/ruby/library/fiddle/handle/initialize_spec.rb index 51c2470efd..84c809a727 100644 --- a/spec/ruby/library/fiddle/handle/initialize_spec.rb +++ b/spec/ruby/library/fiddle/handle/initialize_spec.rb @@ -5,6 +5,6 @@ describe "Fiddle::Handle#initialize" do it "raises Fiddle::DLError if the library cannot be found" do -> { Fiddle::Handle.new("doesnotexist.doesnotexist") - }.should raise_error(Fiddle::DLError) + }.should.raise(Fiddle::DLError) end end diff --git a/spec/ruby/library/find/find_spec.rb b/spec/ruby/library/find/find_spec.rb index 7cd76fa01b..c4ccfa76fd 100644 --- a/spec/ruby/library/find/find_spec.rb +++ b/spec/ruby/library/find/find_spec.rb @@ -13,7 +13,7 @@ describe "Find.find" do describe "when called without a block" do it "returns an Enumerator" do - Find.find(FindDirSpecs.mock_dir).should be_an_instance_of(Enumerator) + Find.find(FindDirSpecs.mock_dir).should.instance_of?(Enumerator) Find.find(FindDirSpecs.mock_dir).to_a.sort.should == FindDirSpecs.expected_paths end end diff --git a/spec/ruby/library/getoptlong/each_option_spec.rb b/spec/ruby/library/getoptlong/each_option_spec.rb index c6d82af86d..3349554aaa 100644 --- a/spec/ruby/library/getoptlong/each_option_spec.rb +++ b/spec/ruby/library/getoptlong/each_option_spec.rb @@ -1,7 +1,21 @@ require_relative '../../spec_helper' require 'getoptlong' -require_relative 'shared/each' describe "GetoptLong#each_option" do - it_behaves_like :getoptlong_each, :each_option + before :each do + @opts = GetoptLong.new( + [ '--size', '-s', GetoptLong::REQUIRED_ARGUMENT ], + [ '--verbose', '-v', GetoptLong::NO_ARGUMENT ], + [ '--query', '-q', GetoptLong::NO_ARGUMENT ], + [ '--check', '--valid', '-c', GetoptLong::NO_ARGUMENT ] + ) + end + + it "passes each_option argument/value pair to the block" do + argv [ "--size", "10k", "-v", "-q", "a.txt", "b.txt" ] do + pairs = [] + @opts.each_option { |arg, val| pairs << [ arg, val ] } + pairs.should == [ [ "--size", "10k" ], [ "--verbose", "" ], [ "--query", ""] ] + end + end end diff --git a/spec/ruby/library/getoptlong/each_spec.rb b/spec/ruby/library/getoptlong/each_spec.rb index d9022f02af..646c3297b5 100644 --- a/spec/ruby/library/getoptlong/each_spec.rb +++ b/spec/ruby/library/getoptlong/each_spec.rb @@ -1,7 +1,8 @@ require_relative '../../spec_helper' require 'getoptlong' -require_relative 'shared/each' describe "GetoptLong#each" do - it_behaves_like :getoptlong_each, :each + it "is an alias of GetoptLong#each_option" do + GetoptLong.instance_method(:each).should == GetoptLong.instance_method(:each_option) + end end diff --git a/spec/ruby/library/getoptlong/error_message_spec.rb b/spec/ruby/library/getoptlong/error_message_spec.rb index 1ed9419f6c..10435b1350 100644 --- a/spec/ruby/library/getoptlong/error_message_spec.rb +++ b/spec/ruby/library/getoptlong/error_message_spec.rb @@ -14,7 +14,7 @@ describe "GetoptLong#error_message" do opts.get -> { opts.ordering = GetoptLong::PERMUTE - }.should raise_error(ArgumentError) { |e| + }.should.raise(ArgumentError) { |e| e.message.should == "argument error" opts.error_message.should == "argument error" } diff --git a/spec/ruby/library/getoptlong/get_option_spec.rb b/spec/ruby/library/getoptlong/get_option_spec.rb index 3cb2044379..1d80e3622e 100644 --- a/spec/ruby/library/getoptlong/get_option_spec.rb +++ b/spec/ruby/library/getoptlong/get_option_spec.rb @@ -1,7 +1,8 @@ require_relative '../../spec_helper' require 'getoptlong' -require_relative 'shared/get' describe "GetoptLong#get_option" do - it_behaves_like :getoptlong_get, :get_option + it "is an alias of GetoptLong#get" do + GetoptLong.instance_method(:get_option).should == GetoptLong.instance_method(:get) + end end diff --git a/spec/ruby/library/getoptlong/get_spec.rb b/spec/ruby/library/getoptlong/get_spec.rb index a8ec586fc9..bfc6697a5a 100644 --- a/spec/ruby/library/getoptlong/get_spec.rb +++ b/spec/ruby/library/getoptlong/get_spec.rb @@ -1,7 +1,65 @@ require_relative '../../spec_helper' require 'getoptlong' -require_relative 'shared/get' describe "GetoptLong#get" do - it_behaves_like :getoptlong_get, :get + before :each do + @opts = GetoptLong.new( + [ '--size', '-s', GetoptLong::REQUIRED_ARGUMENT ], + [ '--verbose', '-v', GetoptLong::NO_ARGUMENT ], + [ '--query', '-q', GetoptLong::NO_ARGUMENT ], + [ '--check', '--valid', '-c', GetoptLong::NO_ARGUMENT ] + ) + @opts.quiet = true # silence using $deferr + end + + it "returns the next option name and its argument as an Array" do + argv [ "--size", "10k", "-v", "-q", "a.txt", "b.txt" ] do + @opts.get.should == [ "--size", "10k" ] + @opts.get.should == [ "--verbose", "" ] + @opts.get.should == [ "--query", ""] + @opts.get.should == nil + end + end + + it "shifts ARGV on each call" do + argv [ "--size", "10k", "-v", "-q", "a.txt", "b.txt" ] do + @opts.get + ARGV.should == [ "-v", "-q", "a.txt", "b.txt" ] + + @opts.get + ARGV.should == [ "-q", "a.txt", "b.txt" ] + + @opts.get + ARGV.should == [ "a.txt", "b.txt" ] + + @opts.get + ARGV.should == [ "a.txt", "b.txt" ] + end + end + + it "terminates processing when encountering '--'" do + argv [ "--size", "10k", "--", "-v", "-q", "a.txt", "b.txt" ] do + @opts.get + ARGV.should == ["--", "-v", "-q", "a.txt", "b.txt"] + + @opts.get + ARGV.should == ["-v", "-q", "a.txt", "b.txt"] + + @opts.get + ARGV.should == ["-v", "-q", "a.txt", "b.txt"] + end + end + + it "raises a if an argument was required, but none given" do + argv [ "--size" ] do + -> { @opts.get }.should.raise(GetoptLong::MissingArgument) + end + end + + # https://bugs.ruby-lang.org/issues/13858 + it "returns multiline argument" do + argv [ "--size=\n10k\n" ] do + @opts.get.should == [ "--size", "\n10k\n" ] + end + end end diff --git a/spec/ruby/library/getoptlong/ordering_spec.rb b/spec/ruby/library/getoptlong/ordering_spec.rb index 695d1cafa7..60ce73afaa 100644 --- a/spec/ruby/library/getoptlong/ordering_spec.rb +++ b/spec/ruby/library/getoptlong/ordering_spec.rb @@ -11,7 +11,7 @@ describe "GetoptLong#ordering=" do -> { opts.ordering = GetoptLong::PERMUTE - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) end end @@ -20,7 +20,7 @@ describe "GetoptLong#ordering=" do -> { opts.ordering = 12345 - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) end it "does not allow changing ordering to PERMUTE if ENV['POSIXLY_CORRECT'] is set" do diff --git a/spec/ruby/library/getoptlong/set_options_spec.rb b/spec/ruby/library/getoptlong/set_options_spec.rb index 36b9c579c4..f60dcc87a3 100644 --- a/spec/ruby/library/getoptlong/set_options_spec.rb +++ b/spec/ruby/library/getoptlong/set_options_spec.rb @@ -41,7 +41,7 @@ describe "GetoptLong#set_options" do argv [] do -> { @opts.set_options(["--size", GetoptLong::NO_ARGUMENT, GetoptLong::REQUIRED_ARGUMENT]) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) end end @@ -50,7 +50,7 @@ describe "GetoptLong#set_options" do @opts.get -> { @opts.set_options() - }.should raise_error(RuntimeError) + }.should.raise(RuntimeError) end end @@ -58,7 +58,7 @@ describe "GetoptLong#set_options" do argv [] do -> { @opts.set_options(["--size"]) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) end end @@ -68,7 +68,7 @@ describe "GetoptLong#set_options" do @opts.set_options( ["--size", GetoptLong::REQUIRED_ARGUMENT], "test") - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) end end @@ -78,13 +78,13 @@ describe "GetoptLong#set_options" do @opts.set_options( ["--size", GetoptLong::NO_ARGUMENT], ["--size", GetoptLong::OPTIONAL_ARGUMENT]) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) -> { @opts.set_options( ["--size", GetoptLong::NO_ARGUMENT], ["-s", "--size", GetoptLong::OPTIONAL_ARGUMENT]) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) end end @@ -92,7 +92,7 @@ describe "GetoptLong#set_options" do argv [] do -> { @opts.set_options(["-size", GetoptLong::NO_ARGUMENT]) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) end end end diff --git a/spec/ruby/library/getoptlong/shared/each.rb b/spec/ruby/library/getoptlong/shared/each.rb deleted file mode 100644 index b534e24c0f..0000000000 --- a/spec/ruby/library/getoptlong/shared/each.rb +++ /dev/null @@ -1,18 +0,0 @@ -describe :getoptlong_each, shared: true do - before :each do - @opts = GetoptLong.new( - [ '--size', '-s', GetoptLong::REQUIRED_ARGUMENT ], - [ '--verbose', '-v', GetoptLong::NO_ARGUMENT ], - [ '--query', '-q', GetoptLong::NO_ARGUMENT ], - [ '--check', '--valid', '-c', GetoptLong::NO_ARGUMENT ] - ) - end - - it "passes each argument/value pair to the block" do - argv [ "--size", "10k", "-v", "-q", "a.txt", "b.txt" ] do - pairs = [] - @opts.send(@method) { |arg, val| pairs << [ arg, val ] } - pairs.should == [ [ "--size", "10k" ], [ "--verbose", "" ], [ "--query", ""] ] - end - end -end diff --git a/spec/ruby/library/getoptlong/shared/get.rb b/spec/ruby/library/getoptlong/shared/get.rb deleted file mode 100644 index f44cf583d2..0000000000 --- a/spec/ruby/library/getoptlong/shared/get.rb +++ /dev/null @@ -1,62 +0,0 @@ -describe :getoptlong_get, shared: true do - before :each do - @opts = GetoptLong.new( - [ '--size', '-s', GetoptLong::REQUIRED_ARGUMENT ], - [ '--verbose', '-v', GetoptLong::NO_ARGUMENT ], - [ '--query', '-q', GetoptLong::NO_ARGUMENT ], - [ '--check', '--valid', '-c', GetoptLong::NO_ARGUMENT ] - ) - @opts.quiet = true # silence using $deferr - end - - it "returns the next option name and its argument as an Array" do - argv [ "--size", "10k", "-v", "-q", "a.txt", "b.txt" ] do - @opts.send(@method).should == [ "--size", "10k" ] - @opts.send(@method).should == [ "--verbose", "" ] - @opts.send(@method).should == [ "--query", ""] - @opts.send(@method).should == nil - end - end - - it "shifts ARGV on each call" do - argv [ "--size", "10k", "-v", "-q", "a.txt", "b.txt" ] do - @opts.send(@method) - ARGV.should == [ "-v", "-q", "a.txt", "b.txt" ] - - @opts.send(@method) - ARGV.should == [ "-q", "a.txt", "b.txt" ] - - @opts.send(@method) - ARGV.should == [ "a.txt", "b.txt" ] - - @opts.send(@method) - ARGV.should == [ "a.txt", "b.txt" ] - end - end - - it "terminates processing when encountering '--'" do - argv [ "--size", "10k", "--", "-v", "-q", "a.txt", "b.txt" ] do - @opts.send(@method) - ARGV.should == ["--", "-v", "-q", "a.txt", "b.txt"] - - @opts.send(@method) - ARGV.should == ["-v", "-q", "a.txt", "b.txt"] - - @opts.send(@method) - ARGV.should == ["-v", "-q", "a.txt", "b.txt"] - end - end - - it "raises a if an argument was required, but none given" do - argv [ "--size" ] do - -> { @opts.send(@method) }.should raise_error(GetoptLong::MissingArgument) - end - end - - # https://bugs.ruby-lang.org/issues/13858 - it "returns multiline argument" do - argv [ "--size=\n10k\n" ] do - @opts.send(@method).should == [ "--size", "\n10k\n" ] - end - end -end diff --git a/spec/ruby/library/io-wait/wait_spec.rb b/spec/ruby/library/io-wait/wait_spec.rb index 6a3890a401..1d784e7aa4 100644 --- a/spec/ruby/library/io-wait/wait_spec.rb +++ b/spec/ruby/library/io-wait/wait_spec.rb @@ -56,12 +56,12 @@ describe "IO#wait" do it "raises IOError when io is closed (closed stream (IOError))" do @io.close - -> { @io.wait(IO::READABLE, 0) }.should raise_error(IOError, "closed stream") + -> { @io.wait(IO::READABLE, 0) }.should.raise(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!") + -> { @w.wait(0, 0) }.should.raise(ArgumentError, "Events must be positive integer!") + -> { @w.wait(-1, 0) }.should.raise(ArgumentError, "Events must be positive integer!") end it "changes thread status to 'sleep' when waits for READABLE event" do @@ -147,16 +147,16 @@ describe "IO#wait" do end it "raises ArgumentError when passed wrong Symbol value as mode argument" do - -> { @io.wait(0, :wrong) }.should raise_error(ArgumentError, "unsupported mode: wrong") + -> { @io.wait(0, :wrong) }.should.raise(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") + -> { @w.wait(0, 10, :r) }.should.raise(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") + -> { @io.wait(0, :r) }.should.raise(IOError, "closed stream") end end end diff --git a/spec/ruby/library/ipaddr/new_spec.rb b/spec/ruby/library/ipaddr/new_spec.rb index 2c0f44acf2..7fba2b372e 100644 --- a/spec/ruby/library/ipaddr/new_spec.rb +++ b/spec/ruby/library/ipaddr/new_spec.rb @@ -3,9 +3,9 @@ require 'ipaddr' describe "IPAddr#new" do it "initializes IPAddr" do - ->{ IPAddr.new("3FFE:505:ffff::/48") }.should_not raise_error - ->{ IPAddr.new("0:0:0:1::") }.should_not raise_error - ->{ IPAddr.new("2001:200:300::/48") }.should_not raise_error + ->{ IPAddr.new("3FFE:505:ffff::/48") }.should_not.raise + ->{ IPAddr.new("0:0:0:1::") }.should_not.raise + ->{ IPAddr.new("2001:200:300::/48") }.should_not.raise end it "initializes IPAddr ipv6 address with short notation" do @@ -86,7 +86,7 @@ describe "IPAddr#new" do ].each { |args| ->{ IPAddr.new(*args) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) } end end diff --git a/spec/ruby/library/ipaddr/operator_spec.rb b/spec/ruby/library/ipaddr/operator_spec.rb index f90c56009c..3337d22300 100644 --- a/spec/ruby/library/ipaddr/operator_spec.rb +++ b/spec/ruby/library/ipaddr/operator_spec.rb @@ -66,17 +66,17 @@ describe "IPAddr Operator" do end it "checks whether an address is included in a range" do - @a.should include(IPAddr.new("3ffe:505:2::")) - @a.should include(IPAddr.new("3ffe:505:2::1")) - @a.should_not include(IPAddr.new("3ffe:505:3::")) + @a.should.include?(IPAddr.new("3ffe:505:2::")) + @a.should.include?(IPAddr.new("3ffe:505:2::1")) + @a.should_not.include?(IPAddr.new("3ffe:505:3::")) net1 = IPAddr.new("192.168.2.0/24") - net1.should include(IPAddr.new("192.168.2.0")) - net1.should include(IPAddr.new("192.168.2.255")) - net1.should_not include(IPAddr.new("192.168.3.0")) + net1.should.include?(IPAddr.new("192.168.2.0")) + net1.should.include?(IPAddr.new("192.168.2.255")) + net1.should_not.include?(IPAddr.new("192.168.3.0")) # test with integer parameter int = (192 << 24) + (168 << 16) + (2 << 8) + 13 - net1.should include(int) - net1.should_not include(int+255) + net1.should.include?(int) + net1.should_not.include?(int+255) end end diff --git a/spec/ruby/library/ipaddr/reverse_spec.rb b/spec/ruby/library/ipaddr/reverse_spec.rb index 6ebb343269..9bda60ca70 100644 --- a/spec/ruby/library/ipaddr/reverse_spec.rb +++ b/spec/ruby/library/ipaddr/reverse_spec.rb @@ -13,7 +13,7 @@ describe "IPAddr#ip6_arpa" do IPAddr.new("3ffe:505:2::f").ip6_arpa.should == "f.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.0.0.5.0.5.0.e.f.f.3.ip6.arpa" ->{ IPAddr.new("192.168.2.1").ip6_arpa - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) end end @@ -22,6 +22,6 @@ describe "IPAddr#ip6_int" do IPAddr.new("3ffe:505:2::f").ip6_int.should == "f.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.0.0.5.0.5.0.e.f.f.3.ip6.int" ->{ IPAddr.new("192.168.2.1").ip6_int - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) end end diff --git a/spec/ruby/library/logger/device/new_spec.rb b/spec/ruby/library/logger/device/new_spec.rb index 26a38c2b8c..c943e7fbe2 100644 --- a/spec/ruby/library/logger/device/new_spec.rb +++ b/spec/ruby/library/logger/device/new_spec.rb @@ -14,11 +14,11 @@ describe "Logger::LogDevice#new" do it "creates a new log device" do l = Logger::LogDevice.new(@log_file) - l.dev.should be_kind_of(File) + l.dev.should.is_a?(File) end it "receives an IO object to log there as first argument" do - @log_file.should be_kind_of(IO) + @log_file.should.is_a?(IO) l = Logger::LogDevice.new(@log_file) l.write("foo") @log_file.rewind @@ -33,7 +33,7 @@ describe "Logger::LogDevice#new" do File.should.exist?(path) File.open(path) do |f| - f.readlines.should_not be_empty + f.readlines.should_not.empty? end rm_r path @@ -42,6 +42,6 @@ describe "Logger::LogDevice#new" do it "receives options via a hash as second argument" do -> { Logger::LogDevice.new(STDERR, shift_age: 8, shift_size: 10) - }.should_not raise_error + }.should_not.raise end end diff --git a/spec/ruby/library/logger/logger/add_spec.rb b/spec/ruby/library/logger/logger/add_spec.rb index 3f709e18ba..98ac88f64f 100644 --- a/spec/ruby/library/logger/logger/add_spec.rb +++ b/spec/ruby/library/logger/logger/add_spec.rb @@ -56,7 +56,7 @@ describe "Logger#add" do @logger.log(nil, "test", "TestApp") do 1+1 end - }.should_not raise_error + }.should_not.raise end it "calls the block if message is nil" do @@ -65,7 +65,7 @@ describe "Logger#add" do @logger.log(nil, nil, "TestApp") do temp = 1+1 end - }.should_not raise_error + }.should_not.raise temp.should == 2 end @@ -75,7 +75,7 @@ describe "Logger#add" do @logger.log(nil, "not nil", "TestApp") do temp = 1+1 end - }.should_not raise_error + }.should_not.raise temp.should == 0 end end diff --git a/spec/ruby/library/logger/logger/datetime_format_spec.rb b/spec/ruby/library/logger/logger/datetime_format_spec.rb index 582b34bfda..75a7f6cc03 100644 --- a/spec/ruby/library/logger/logger/datetime_format_spec.rb +++ b/spec/ruby/library/logger/logger/datetime_format_spec.rb @@ -49,7 +49,7 @@ describe "Logger#datetime_format=" do end it "follows the Time#strftime format" do - -> { @logger.datetime_format = "%Y-%m" }.should_not raise_error + -> { @logger.datetime_format = "%Y-%m" }.should_not.raise regex = /\d{4}-\d{2}-\d{2}oo-\w+ar/ @logger.datetime_format = "%Foo-%Bar" diff --git a/spec/ruby/library/logger/logger/new_spec.rb b/spec/ruby/library/logger/logger/new_spec.rb index 3db20e7432..b311c96132 100644 --- a/spec/ruby/library/logger/logger/new_spec.rb +++ b/spec/ruby/library/logger/logger/new_spec.rb @@ -28,13 +28,13 @@ describe "Logger#new" do 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 + -> { Logger.new(@log_file, "weekly") }.should_not.raise + -> { Logger.new(@log_file, "monthly") }.should_not.raise end it "also receives a number of log files to keep as second argument" do - -> { Logger.new(@log_file, 1).close }.should_not raise_error + -> { Logger.new(@log_file, 1).close }.should_not.raise end it "receives a maximum logfile size as third argument" do @@ -94,7 +94,7 @@ describe "Logger#new" do logger.formatter.should == formatter end - it "receives shift_period_suffix " do + it "receives shift_period_suffix" do shift_period_suffix = "%Y-%m-%d" path = tmp("shift_period_suffix_test.log") now = Time.now diff --git a/spec/ruby/library/logger/logger/unknown_spec.rb b/spec/ruby/library/logger/logger/unknown_spec.rb index b174b8b2c9..4d37c9797e 100644 --- a/spec/ruby/library/logger/logger/unknown_spec.rb +++ b/spec/ruby/library/logger/logger/unknown_spec.rb @@ -29,7 +29,7 @@ describe "Logger#unknown" do end it "receives empty messages" do - -> { @logger.unknown("") }.should_not raise_error + -> { @logger.unknown("") }.should_not.raise @log_file.rewind LoggerSpecs.strip_date(@log_file.readlines.first).should == "ANY -- : \n" end diff --git a/spec/ruby/library/matrix/I_spec.rb b/spec/ruby/library/matrix/I_spec.rb index 6eeffe8e98..ca5e79279a 100644 --- a/spec/ruby/library/matrix/I_spec.rb +++ b/spec/ruby/library/matrix/I_spec.rb @@ -1,6 +1,8 @@ require_relative '../../spec_helper' -require_relative 'shared/identity' +require 'matrix' describe "Matrix.I" do - it_behaves_like :matrix_identity, :I + it "is an alias of Matrix.identity" do + Matrix.method(:I).should == Matrix.method(:identity) + end end diff --git a/spec/ruby/library/matrix/antisymmetric_spec.rb b/spec/ruby/library/matrix/antisymmetric_spec.rb index 200df703cb..b4b8858f32 100644 --- a/spec/ruby/library/matrix/antisymmetric_spec.rb +++ b/spec/ruby/library/matrix/antisymmetric_spec.rb @@ -4,11 +4,11 @@ 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 + Matrix[[0, -2, Complex(1, 3)], [2, 0, 5], [-Complex(1, 3), -5, 0]].antisymmetric?.should == true end it "returns true for a 0x0 empty matrix" do - Matrix.empty.antisymmetric?.should be_true + Matrix.empty.antisymmetric?.should == true end it "returns false for non-antisymmetric matrices" do @@ -17,7 +17,7 @@ describe "Matrix#antisymmetric?" do 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 + matrix.antisymmetric?.should == false end end @@ -30,7 +30,7 @@ describe "Matrix#antisymmetric?" do ].each do |rectangular_matrix| -> { rectangular_matrix.antisymmetric? - }.should raise_error(Matrix::ErrDimensionMismatch) + }.should.raise(Matrix::ErrDimensionMismatch) end end end diff --git a/spec/ruby/library/matrix/build_spec.rb b/spec/ruby/library/matrix/build_spec.rb index 6d8017a3df..49eb2e69a5 100644 --- a/spec/ruby/library/matrix/build_spec.rb +++ b/spec/ruby/library/matrix/build_spec.rb @@ -6,7 +6,7 @@ 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.should.instance_of?(Matrix) m.row_size.should == 3 m.column_size.should == 4 end @@ -24,32 +24,32 @@ describe "Matrix.build" do it "returns an Enumerator is no block is given" do enum = Matrix.build(2, 1) - enum.should be_an_instance_of(Enumerator) + enum.should.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) + -> { Matrix.build("1", "2"){1} }.should.raise(TypeError) + -> { Matrix.build(nil, nil){1} }.should.raise(TypeError) + -> { Matrix.build(1..2){1} }.should.raise(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) + -> { Matrix.build(-1, 1){1} }.should.raise(ArgumentError) + -> { Matrix.build(+1,-1){1} }.should.raise(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.should.empty? m.column_size.should == 3 m = Matrix.build(3, 0){ raise "Should not yield" } - m.should be_empty + m.should.empty? m.row_size.should == 3 end @@ -68,6 +68,6 @@ 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) + MatrixSub.build(3){1}.should.instance_of?(MatrixSub) end end diff --git a/spec/ruby/library/matrix/clone_spec.rb b/spec/ruby/library/matrix/clone_spec.rb index 74e5bf157e..51aefc6010 100644 --- a/spec/ruby/library/matrix/clone_spec.rb +++ b/spec/ruby/library/matrix/clone_spec.rb @@ -9,17 +9,17 @@ describe "Matrix#clone" do it "returns a shallow copy of the matrix" do b = @a.clone - @a.should_not equal(b) - b.should be_kind_of(Matrix) + @a.should_not.equal?(b) + b.should.is_a?(Matrix) b.should == @a 0.upto(@a.row_size - 1) do |i| - @a.row(i).should_not equal(b.row(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) + MatrixSub.ins.clone.should.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 4022f00236..6032dd2f62 100644 --- a/spec/ruby/library/matrix/coerce_spec.rb +++ b/spec/ruby/library/matrix/coerce_spec.rb @@ -2,7 +2,7 @@ require_relative '../../spec_helper' require 'matrix' describe "Matrix#coerce" do - it "allows the division of integer by a Matrix " 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 bba640213b..664c3f3038 100644 --- a/spec/ruby/library/matrix/collect_spec.rb +++ b/spec/ruby/library/matrix/collect_spec.rb @@ -1,6 +1,8 @@ require_relative '../../spec_helper' -require_relative 'shared/collect' +require 'matrix' describe "Matrix#collect" do - it_behaves_like :collect, :collect + it "is an alias of Matrix#map" do + Matrix.instance_method(:collect).should == Matrix.instance_method(:map) + end end diff --git a/spec/ruby/library/matrix/column_spec.rb b/spec/ruby/library/matrix/column_spec.rb index 1f3c80964a..d5d8c80c1a 100644 --- a/spec/ruby/library/matrix/column_spec.rb +++ b/spec/ruby/library/matrix/column_spec.rb @@ -21,7 +21,7 @@ describe "Matrix#column" do end it "returns self when called with a block" do - @m.column(0) { |x| x }.should equal(@m) + @m.column(0) { |x| x }.should.equal?(@m) end it "returns nil when out of bounds" do @@ -29,7 +29,7 @@ describe "Matrix#column" do 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 + -> { @m.column(3){ raise } }.should_not.raise + -> { @m.column(-4){ raise } }.should_not.raise end end diff --git a/spec/ruby/library/matrix/column_vector_spec.rb b/spec/ruby/library/matrix/column_vector_spec.rb index 47e866a8d5..d86c3f9e42 100644 --- a/spec/ruby/library/matrix/column_vector_spec.rb +++ b/spec/ruby/library/matrix/column_vector_spec.rb @@ -6,20 +6,20 @@ 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.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.should.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) + MatrixSub.column_vector([4,5,6]).should.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 b0cb6f914c..7ac6871e7f 100644 --- a/spec/ruby/library/matrix/column_vectors_spec.rb +++ b/spec/ruby/library/matrix/column_vectors_spec.rb @@ -8,11 +8,11 @@ describe "Matrix#column_vectors" do end it "returns an Array" do - Matrix[ [1,2], [3,4] ].column_vectors.should be_an_instance_of(Array) + Matrix[ [1,2], [3,4] ].column_vectors.should.instance_of?(Array) end it "returns an Array of Vectors" do - @vectors.all? {|v| v.should be_an_instance_of(Vector)} + @vectors.all? {|v| v.should.instance_of?(Vector)} end it "returns each column as a Vector" do diff --git a/spec/ruby/library/matrix/columns_spec.rb b/spec/ruby/library/matrix/columns_spec.rb index 3095fdd7af..ac9587899d 100644 --- a/spec/ruby/library/matrix/columns_spec.rb +++ b/spec/ruby/library/matrix/columns_spec.rb @@ -10,7 +10,7 @@ describe "Matrix.columns" do end it "creates a Matrix from argument columns" do - @m.should be_an_instance_of(Matrix) + @m.should.instance_of?(Matrix) @m.column(0).to_a.should == @a @m.column(1).to_a.should == @b end @@ -36,7 +36,7 @@ describe "Matrix.columns" do describe "for a subclass of Matrix" do it "returns an instance of that subclass" do - MatrixSub.columns([[1]]).should be_an_instance_of(MatrixSub) + MatrixSub.columns([[1]]).should.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 ecee95c255..eff5986fc4 100644 --- a/spec/ruby/library/matrix/conj_spec.rb +++ b/spec/ruby/library/matrix/conj_spec.rb @@ -1,6 +1,8 @@ require_relative '../../spec_helper' -require_relative 'shared/conjugate' +require 'matrix' describe "Matrix#conj" do - it_behaves_like :matrix_conjugate, :conj + it "is an alias of Matrix#conjugate" do + Matrix.instance_method(:conj).should == Matrix.instance_method(:conjugate) + end end diff --git a/spec/ruby/library/matrix/conjugate_spec.rb b/spec/ruby/library/matrix/conjugate_spec.rb index 682bd41d94..46077d4fa9 100644 --- a/spec/ruby/library/matrix/conjugate_spec.rb +++ b/spec/ruby/library/matrix/conjugate_spec.rb @@ -1,6 +1,20 @@ require_relative '../../spec_helper' -require_relative 'shared/conjugate' +require_relative 'fixtures/classes' describe "Matrix#conjugate" do - it_behaves_like :matrix_conjugate, :conjugate + it "returns a matrix with all entries 'conjugated'" do + Matrix[ [1, 2], [3, 4] ].conjugate.should == Matrix[ [1, 2], [3, 4] ] + Matrix[ [1.9, Complex(1,1)], [3, 4] ].conjugate.should == Matrix[ [1.9, Complex(1,-1)], [3, 4] ] + end + + it "returns empty matrices on the same size if empty" do + Matrix.empty(0, 3).conjugate.should == Matrix.empty(0, 3) + Matrix.empty(3, 0).conjugate.should == Matrix.empty(3, 0) + end + + describe "for a subclass of Matrix" do + it "returns an instance of that subclass" do + MatrixSub.ins.conjugate.should.instance_of?(MatrixSub) + end + end end diff --git a/spec/ruby/library/matrix/constructor_spec.rb b/spec/ruby/library/matrix/constructor_spec.rb index 70d77babbb..026525f36d 100644 --- a/spec/ruby/library/matrix/constructor_spec.rb +++ b/spec/ruby/library/matrix/constructor_spec.rb @@ -5,10 +5,10 @@ require 'matrix' 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) + -> { Matrix[5] }.should.raise(TypeError) + -> { Matrix[nil] }.should.raise(TypeError) + -> { Matrix[1..2] }.should.raise(TypeError) + -> { Matrix[[1, 2], 3] }.should.raise(TypeError) end it "creates an empty Matrix with no arguments" do @@ -18,15 +18,13 @@ describe "Matrix.[]" do 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) + ->{ Matrix[ [0], [0,1] ] }.should.raise(Matrix::ErrDimensionMismatch) + ->{ Matrix[ [0,1], [0,1,2], [0,1] ]}.should.raise(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.instance_of?(Matrix) a.should == Matrix[ [1, 2], [3, 4] ] end @@ -38,7 +36,7 @@ describe "Matrix.[]" do it "returns a Matrix object" do - Matrix[ [1] ].should be_an_instance_of(Matrix) + Matrix[ [1] ].should.instance_of?(Matrix) end it "can create an nxn Matrix" do @@ -59,7 +57,7 @@ describe "Matrix.[]" do 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) + MatrixSub[ [20,30], [40.5, 9] ].should.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 aa7086cacf..fc4b1c252a 100644 --- a/spec/ruby/library/matrix/det_spec.rb +++ b/spec/ruby/library/matrix/det_spec.rb @@ -1,7 +1,8 @@ require_relative '../../spec_helper' -require_relative 'shared/determinant' require 'matrix' describe "Matrix#det" do - it_behaves_like :determinant, :det + it "is an alias of Matrix#determinant" do + Matrix.instance_method(:det).should == Matrix.instance_method(:determinant) + end end diff --git a/spec/ruby/library/matrix/determinant_spec.rb b/spec/ruby/library/matrix/determinant_spec.rb index 825c9907b1..603e13ba28 100644 --- a/spec/ruby/library/matrix/determinant_spec.rb +++ b/spec/ruby/library/matrix/determinant_spec.rb @@ -1,7 +1,39 @@ require_relative '../../spec_helper' -require_relative 'shared/determinant' require 'matrix' describe "Matrix#determinant" do - it_behaves_like :determinant, :determinant + it "returns the determinant of a square Matrix" do + m = Matrix[ [7,6], [3,9] ] + m.determinant.should == 45 + + m = Matrix[ [9, 8], [6,5] ] + m.determinant.should == -3 + + m = Matrix[ [9,8,3], [4,20,5], [1,1,1] ] + m.determinant.should == 95 + end + + it "returns the determinant of a single-element Matrix" do + m = Matrix[ [2] ] + m.determinant.should == 2 + end + + it "returns 1 for an empty Matrix" do + m = Matrix[ ] + m.determinant.should == 1 + end + + it "returns the determinant even for Matrices containing 0 as first entry" do + Matrix[[0,1],[1,0]].determinant.should == -1 + end + + it "raises an error for rectangular matrices" do + -> { + Matrix[[1], [2], [3]].determinant + }.should.raise(Matrix::ErrDimensionMismatch) + + -> { + Matrix.empty(3,0).determinant + }.should.raise(Matrix::ErrDimensionMismatch) + end end diff --git a/spec/ruby/library/matrix/diagonal_spec.rb b/spec/ruby/library/matrix/diagonal_spec.rb index ef9738e73e..ee84ac8c28 100644 --- a/spec/ruby/library/matrix/diagonal_spec.rb +++ b/spec/ruby/library/matrix/diagonal_spec.rb @@ -8,7 +8,7 @@ describe "Matrix.diagonal" do end it "returns an object of type Matrix" do - @m.should be_kind_of(Matrix) + @m.should.is_a?(Matrix) end it "returns a square Matrix of the right size" do @@ -34,27 +34,27 @@ describe "Matrix.diagonal" do describe "for a subclass of Matrix" do it "returns an instance of that subclass" do - MatrixSub.diagonal(1).should be_an_instance_of(MatrixSub) + MatrixSub.diagonal(1).should.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 + Matrix.diagonal([1, 2, 3]).diagonal?.should == true end it "returns true for a zero square Matrix" do - Matrix.zero(3).diagonal?.should be_true + Matrix.zero(3).diagonal?.should == 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 + Matrix[[0, 1], [0, 0]].diagonal?.should == false + Matrix[[1, 2, 3], [1, 2, 3], [1, 2, 3]].diagonal?.should == false end it "returns true for an empty 0x0 matrix" do - Matrix.empty(0,0).diagonal?.should be_true + Matrix.empty(0,0).diagonal?.should == true end it "raises an error for rectangular matrices" do @@ -66,7 +66,7 @@ describe "Matrix.diagonal?" do ].each do |rectangular_matrix| -> { rectangular_matrix.diagonal? - }.should raise_error(Matrix::ErrDimensionMismatch) + }.should.raise(Matrix::ErrDimensionMismatch) end end end diff --git a/spec/ruby/library/matrix/divide_spec.rb b/spec/ruby/library/matrix/divide_spec.rb index 2e3bb85bf6..711a5189e4 100644 --- a/spec/ruby/library/matrix/divide_spec.rb +++ b/spec/ruby/library/matrix/divide_spec.rb @@ -30,25 +30,25 @@ describe "Matrix#/" do end it "raises a Matrix::ErrDimensionMismatch if the matrices are different sizes" do - -> { @a / Matrix[ [1] ] }.should raise_error(Matrix::ErrDimensionMismatch) + -> { @a / Matrix[ [1] ] }.should.raise(Matrix::ErrDimensionMismatch) end it "returns an instance of Matrix" do - (@a / @b).should be_kind_of(Matrix) + (@a / @b).should.is_a?(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) + (m/m).should.instance_of?(MatrixSub) + (m/1).should.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) + -> { @a / nil }.should.raise(TypeError) + -> { @a / "a" }.should.raise(TypeError) + -> { @a / [ [1, 2] ] }.should.raise(TypeError) + -> { @a / Object.new }.should.raise(TypeError) end end diff --git a/spec/ruby/library/matrix/each_spec.rb b/spec/ruby/library/matrix/each_spec.rb index f3b0f01867..b4bfd3c76f 100644 --- a/spec/ruby/library/matrix/each_spec.rb +++ b/spec/ruby/library/matrix/each_spec.rb @@ -9,12 +9,12 @@ describe "Matrix#each" do it "returns an Enumerator when called without a block" do enum = @m.each - enum.should be_an_instance_of(Enumerator) + enum.should.instance_of?(Enumerator) enum.to_a.should == @result end it "returns self" do - @m.each{}.should equal(@m) + @m.each{}.should.equal?(@m) end it "yields the elements starting with the those of the first row" do @@ -33,13 +33,13 @@ describe "Matrix#each with an argument" do it "raises an ArgumentError for unrecognized argument" do -> { @m.each("all"){} - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) -> { @m.each(nil){} - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) -> { @m.each(:left){} - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) end it "yields the rights elements when passed :diagonal" do diff --git a/spec/ruby/library/matrix/each_with_index_spec.rb b/spec/ruby/library/matrix/each_with_index_spec.rb index a005b88621..17e3f3f44c 100644 --- a/spec/ruby/library/matrix/each_with_index_spec.rb +++ b/spec/ruby/library/matrix/each_with_index_spec.rb @@ -16,12 +16,12 @@ describe "Matrix#each_with_index" do it "returns an Enumerator when called without a block" do enum = @m.each_with_index - enum.should be_an_instance_of(Enumerator) + enum.should.instance_of?(Enumerator) enum.to_a.should == @result end it "returns self" do - @m.each_with_index{}.should equal(@m) + @m.each_with_index{}.should.equal?(@m) end it "yields the elements starting with the those of the first row" do @@ -40,13 +40,13 @@ describe "Matrix#each_with_index with an argument" do it "raises an ArgumentError for unrecognized argument" do -> { @m.each_with_index("all"){} - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) -> { @m.each_with_index(nil){} - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) -> { @m.each_with_index(:left){} - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) end it "yields the rights elements when passed :diagonal" do diff --git a/spec/ruby/library/matrix/eigenvalue_decomposition/initialize_spec.rb b/spec/ruby/library/matrix/eigenvalue_decomposition/initialize_spec.rb index 8438f63133..cbda82a16a 100644 --- a/spec/ruby/library/matrix/eigenvalue_decomposition/initialize_spec.rb +++ b/spec/ruby/library/matrix/eigenvalue_decomposition/initialize_spec.rb @@ -5,16 +5,16 @@ describe "Matrix::EigenvalueDecomposition#initialize" do it "raises an error if argument is not a matrix" do -> { Matrix::EigenvalueDecomposition.new([[]]) - }.should raise_error(TypeError) + }.should.raise(TypeError) -> { Matrix::EigenvalueDecomposition.new(42) - }.should raise_error(TypeError) + }.should.raise(TypeError) end it "raises an error if matrix is not square" do -> { Matrix::EigenvalueDecomposition.new(Matrix[[1, 2]]) - }.should raise_error(Matrix::ErrDimensionMismatch) + }.should.raise(Matrix::ErrDimensionMismatch) end it "never hangs" do diff --git a/spec/ruby/library/matrix/element_reference_spec.rb b/spec/ruby/library/matrix/element_reference_spec.rb index b950d1c391..c6804b3846 100644 --- a/spec/ruby/library/matrix/element_reference_spec.rb +++ b/spec/ruby/library/matrix/element_reference_spec.rb @@ -16,8 +16,8 @@ describe "Matrix#[]" do end it "returns nil for an invalid index pair" do - @m[8,1].should be_nil - @m[1,8].should be_nil + @m[8,1].should == nil + @m[1,8].should == nil end end diff --git a/spec/ruby/library/matrix/empty_spec.rb b/spec/ruby/library/matrix/empty_spec.rb index 5f294711db..7b0f0af9eb 100644 --- a/spec/ruby/library/matrix/empty_spec.rb +++ b/spec/ruby/library/matrix/empty_spec.rb @@ -4,20 +4,20 @@ 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 + Matrix[ ].empty?.should == true + Matrix[ [], [], [] ].empty?.should == true + Matrix[ [], [], [] ].transpose.empty?.should == 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 + Matrix[ [1, 2] ].empty?.should == false + Matrix[ [1], [2] ].empty?.should == false end it "doesn't accept any parameter" do ->{ Matrix[ [1, 2] ].empty?(42) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) end end @@ -40,29 +40,29 @@ describe "Matrix.empty" do it "does not accept more than two parameters" do ->{ Matrix.empty(1, 2, 3) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) end it "raises an error if both dimensions are > 0" do ->{ Matrix.empty(1, 2) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) end it "raises an error if any dimension is < 0" do ->{ Matrix.empty(-2, 0) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) ->{ Matrix.empty(0, -2) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) 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) + MatrixSub.empty(0, 1).should.instance_of?(MatrixSub) end end diff --git a/spec/ruby/library/matrix/eql_spec.rb b/spec/ruby/library/matrix/eql_spec.rb index ea26c3320d..cda122f4d8 100644 --- a/spec/ruby/library/matrix/eql_spec.rb +++ b/spec/ruby/library/matrix/eql_spec.rb @@ -6,6 +6,6 @@ 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 + Matrix[[1, 2],[3, 4]].eql?(Matrix[[1, 2],[3, 4.0]]).should == false end end diff --git a/spec/ruby/library/matrix/exponent_spec.rb b/spec/ruby/library/matrix/exponent_spec.rb index 38cdfa9276..4cbe63587d 100644 --- a/spec/ruby/library/matrix/exponent_spec.rb +++ b/spec/ruby/library/matrix/exponent_spec.rb @@ -17,8 +17,8 @@ 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) + -> { m ** 3 }.should.raise(Matrix::ErrDimensionMismatch) + -> { m ** 0 }.should.raise(Matrix::ErrDimensionMismatch) end describe "that is < 0" do @@ -30,7 +30,7 @@ describe "Matrix#**" do it "raises a ErrNotRegular for irregular matrices" do m = Matrix[ [1, 1], [1, 1] ] - -> { m ** -2 }.should raise_error(Matrix::ErrNotRegular) + -> { m ** -2 }.should.raise(Matrix::ErrNotRegular) end end @@ -42,7 +42,7 @@ describe "Matrix#**" do it "raises an ErrDimensionMismatch for non-square matrices" do m = Matrix[ [1, 1] ] - -> { m ** 0 }.should raise_error(Matrix::ErrDimensionMismatch) + -> { m ** 0 }.should.raise(Matrix::ErrDimensionMismatch) end end end @@ -56,7 +56,7 @@ describe "Matrix#**" do describe "for a subclass of Matrix" do it "returns an instance of that subclass" do - (MatrixSub.ins ** 1).should be_an_instance_of(MatrixSub) + (MatrixSub.ins ** 1).should.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 c2bfa6d61a..c7278fd449 100644 --- a/spec/ruby/library/matrix/find_index_spec.rb +++ b/spec/ruby/library/matrix/find_index_spec.rb @@ -8,12 +8,12 @@ describe "Matrix#find_index without any argument" do it "returns an Enumerator when called without a block" do enum = @m.find_index - enum.should be_an_instance_of(Enumerator) + enum.should.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 + @m.find_index{false}.should == nil end it "returns the first index for which the block is true" do @@ -48,7 +48,7 @@ describe "Matrix#find_index with a subselection 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) + matrix.find_index(selector).should.instance_of?(Enumerator) end end end @@ -116,7 +116,7 @@ describe "Matrix#find_index with only a generic argument" do end it "returns nil if the value is not found" do - @m.find_index(42).should be_nil + @m.find_index(42).should == nil end it "returns the first index for of the requested value" do @@ -132,15 +132,15 @@ 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) + }.should.raise(ArgumentError) -> { @m.find_index(1, nil){} - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) -> { @m.find_index(1, :left){} - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) -> { @m.find_index(:diagonal, 1){} - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) end end diff --git a/spec/ruby/library/matrix/hash_spec.rb b/spec/ruby/library/matrix/hash_spec.rb index 7dabcd3737..27bf7b9751 100644 --- a/spec/ruby/library/matrix/hash_spec.rb +++ b/spec/ruby/library/matrix/hash_spec.rb @@ -4,7 +4,7 @@ require 'matrix' describe "Matrix#hash" do it "returns an Integer" do - Matrix[ [1,2] ].hash.should be_an_instance_of(Integer) + Matrix[ [1,2] ].hash.should.instance_of?(Integer) end it "returns the same value for the same matrix" do diff --git a/spec/ruby/library/matrix/hermitian_spec.rb b/spec/ruby/library/matrix/hermitian_spec.rb index 177ca64d83..94d0dbe6b6 100644 --- a/spec/ruby/library/matrix/hermitian_spec.rb +++ b/spec/ruby/library/matrix/hermitian_spec.rb @@ -3,15 +3,15 @@ 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 + Matrix[[1, 2, Complex(0, 3)], [2, 4, 5], [Complex(0, -3), 5, 6]].hermitian?.should == true end it "returns true for a 0x0 empty matrix" do - Matrix.empty.hermitian?.should be_true + Matrix.empty.hermitian?.should == true end it "returns false for an asymmetric Matrix" do - Matrix[[1, 2],[-2, 1]].hermitian?.should be_false + Matrix[[1, 2],[-2, 1]].hermitian?.should == false end it "raises an error for rectangular matrices" do @@ -23,12 +23,12 @@ describe "Matrix.hermitian?" do ].each do |rectangular_matrix| -> { rectangular_matrix.hermitian? - }.should raise_error(Matrix::ErrDimensionMismatch) + }.should.raise(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 + Matrix[[Complex(1,1)]].hermitian?.should == false + Matrix[[Complex(1,0)]].hermitian?.should == true end end diff --git a/spec/ruby/library/matrix/identity_spec.rb b/spec/ruby/library/matrix/identity_spec.rb index 646462bc47..afefd27565 100644 --- a/spec/ruby/library/matrix/identity_spec.rb +++ b/spec/ruby/library/matrix/identity_spec.rb @@ -1,6 +1,20 @@ require_relative '../../spec_helper' -require_relative 'shared/identity' +require_relative 'fixtures/classes' +require 'matrix' describe "Matrix.identity" do - it_behaves_like :matrix_identity, :identity + it "returns a Matrix" do + Matrix.identity(2).should.is_a?(Matrix) + end + + it "returns a n x n identity matrix" do + Matrix.identity(3).should == Matrix.scalar(3, 1) + Matrix.identity(100).should == Matrix.scalar(100, 1) + end + + describe "for a subclass of Matrix" do + it "returns an instance of that subclass" do + MatrixSub.identity(2).should.instance_of?(MatrixSub) + end + end end diff --git a/spec/ruby/library/matrix/imag_spec.rb b/spec/ruby/library/matrix/imag_spec.rb index 1c988753d8..9d6cc2e953 100644 --- a/spec/ruby/library/matrix/imag_spec.rb +++ b/spec/ruby/library/matrix/imag_spec.rb @@ -1,6 +1,8 @@ require_relative '../../spec_helper' -require_relative 'shared/imaginary' +require 'matrix' describe "Matrix#imag" do - it_behaves_like :matrix_imaginary, :imag + it "is an alias of Matrix#imaginary" do + Matrix.instance_method(:imag).should == Matrix.instance_method(:imaginary) + end end diff --git a/spec/ruby/library/matrix/imaginary_spec.rb b/spec/ruby/library/matrix/imaginary_spec.rb index ceae4bbe8d..bbd06677b7 100644 --- a/spec/ruby/library/matrix/imaginary_spec.rb +++ b/spec/ruby/library/matrix/imaginary_spec.rb @@ -1,6 +1,21 @@ require_relative '../../spec_helper' -require_relative 'shared/imaginary' +require_relative 'fixtures/classes' +require 'matrix' describe "Matrix#imaginary" do - it_behaves_like :matrix_imaginary, :imaginary + it "returns a matrix with the imaginary part of the elements of the receiver" do + Matrix[ [1, 2], [3, 4] ].imaginary.should == Matrix[ [0, 0], [0, 0] ] + Matrix[ [1.9, Complex(1,1)], [Complex(-2,0.42), 4] ].imaginary.should == Matrix[ [0, 1], [0.42, 0] ] + end + + it "returns empty matrices on the same size if empty" do + Matrix.empty(0, 3).imaginary.should == Matrix.empty(0, 3) + Matrix.empty(3, 0).imaginary.should == Matrix.empty(3, 0) + end + + describe "for a subclass of Matrix" do + it "returns an instance of that subclass" do + MatrixSub.ins.imaginary.should.instance_of?(MatrixSub) + end + end end diff --git a/spec/ruby/library/matrix/inv_spec.rb b/spec/ruby/library/matrix/inv_spec.rb index 82879a6d82..02684030d2 100644 --- a/spec/ruby/library/matrix/inv_spec.rb +++ b/spec/ruby/library/matrix/inv_spec.rb @@ -1,7 +1,8 @@ require_relative '../../spec_helper' -require_relative 'spec_helper' -require_relative 'shared/inverse' +require 'matrix' describe "Matrix#inv" do - it_behaves_like :inverse, :inv + it "is an alias of Matrix#inverse" do + Matrix.instance_method(:inv).should == Matrix.instance_method(:inverse) + end end diff --git a/spec/ruby/library/matrix/inverse_spec.rb b/spec/ruby/library/matrix/inverse_spec.rb index fa3fa7de8a..38b01b28fb 100644 --- a/spec/ruby/library/matrix/inverse_spec.rb +++ b/spec/ruby/library/matrix/inverse_spec.rb @@ -1,7 +1,39 @@ require_relative '../../spec_helper' require_relative 'spec_helper' -require_relative 'shared/inverse' +require_relative 'fixtures/classes' +require 'matrix' describe "Matrix#inverse" do - it_behaves_like :inverse, :inverse + it "returns a Matrix" do + Matrix[ [1,2], [2,1] ].inverse.should.instance_of?(Matrix) + end + + it "returns the inverse of the Matrix" do + Matrix[ + [1, 3, 3], [1, 4, 3], [1, 3, 4] + ].inverse.should == + Matrix[ + [7, -3, -3], [-1, 1, 0], [-1, 0, 1] + ] + end + + it "returns the inverse of the Matrix (other case)" do + Matrix[ + [1, 2, 3], [0, 1, 4], [5, 6, 0] + ].inverse.should be_close_to_matrix([ + [-24, 18, 5], [20, -15, -4], [-5, 4, 1] + ]) + end + + it "raises a ErrDimensionMismatch if the Matrix is not square" do + ->{ + Matrix[ [1,2,3], [1,2,3] ].inverse + }.should.raise(Matrix::ErrDimensionMismatch) + end + + describe "for a subclass of Matrix" do + it "returns an instance of that subclass" do + MatrixSub.ins.inverse.should.instance_of?(MatrixSub) + end + end end diff --git a/spec/ruby/library/matrix/lower_triangular_spec.rb b/spec/ruby/library/matrix/lower_triangular_spec.rb index f3aa4501f4..7e8688fd9b 100644 --- a/spec/ruby/library/matrix/lower_triangular_spec.rb +++ b/spec/ruby/library/matrix/lower_triangular_spec.rb @@ -3,22 +3,22 @@ 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 + Matrix[[1, 0, 0], [1, 2, 0], [1, 2, 3]].lower_triangular?.should == true + Matrix.diagonal([1, 2, 3]).lower_triangular?.should == true + Matrix[[1, 0], [1, 2], [1, 2], [1, 2]].lower_triangular?.should == true + Matrix[[1, 0, 0, 0], [1, 2, 0, 0]].lower_triangular?.should == 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 + Matrix.empty(3, 0).lower_triangular?.should == true + Matrix.empty(0, 3).lower_triangular?.should == true + Matrix.empty(0, 0).lower_triangular?.should == 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 + Matrix[[0, 1], [0, 0]].lower_triangular?.should == false + Matrix[[1, 2, 3], [1, 2, 3], [1, 2, 3]].lower_triangular?.should == false + Matrix[[0, 1], [0, 0], [0, 0], [0, 0]].lower_triangular?.should == false + Matrix[[0, 0, 0, 1], [0, 0, 0, 0]].lower_triangular?.should == 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 9d733066c1..98ac5c71a3 100644 --- a/spec/ruby/library/matrix/lup_decomposition/determinant_spec.rb +++ b/spec/ruby/library/matrix/lup_decomposition/determinant_spec.rb @@ -15,7 +15,7 @@ describe "Matrix::LUPDecomposition#determinant" do lup = m.lup -> { lup.determinant - }.should raise_error(Matrix::ErrDimensionMismatch) + }.should.raise(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 36afb349e6..b813757525 100644 --- a/spec/ruby/library/matrix/lup_decomposition/initialize_spec.rb +++ b/spec/ruby/library/matrix/lup_decomposition/initialize_spec.rb @@ -5,9 +5,9 @@ describe "Matrix::LUPDecomposition#initialize" do it "raises an error if argument is not a matrix" do -> { Matrix::LUPDecomposition.new([[]]) - }.should raise_error(TypeError) + }.should.raise(TypeError) -> { Matrix::LUPDecomposition.new(42) - }.should raise_error(TypeError) + }.should.raise(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 9514ab5d06..0a6797cc85 100644 --- a/spec/ruby/library/matrix/lup_decomposition/l_spec.rb +++ b/spec/ruby/library/matrix/lup_decomposition/l_spec.rb @@ -13,6 +13,6 @@ describe "Matrix::LUPDecomposition#l" do end it "returns a lower triangular matrix" do - @l.lower_triangular?.should be_true + @l.lower_triangular?.should == 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 c7b5e9196e..2c44399b79 100644 --- a/spec/ruby/library/matrix/lup_decomposition/p_spec.rb +++ b/spec/ruby/library/matrix/lup_decomposition/p_spec.rb @@ -13,6 +13,6 @@ describe "Matrix::LUPDecomposition#p" do end it "returns a permutation matrix" do - @p.permutation?.should be_true + @p.permutation?.should == 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 66242627e9..9927e96727 100644 --- a/spec/ruby/library/matrix/lup_decomposition/solve_spec.rb +++ b/spec/ruby/library/matrix/lup_decomposition/solve_spec.rb @@ -8,7 +8,7 @@ describe "Matrix::LUPDecomposition#solve" do lu = Matrix::LUPDecomposition.new(a) -> { lu.solve(a) - }.should raise_error(Matrix::ErrNotRegular) + }.should.raise(Matrix::ErrNotRegular) end describe "for non singular matrices" do @@ -33,7 +33,7 @@ describe "Matrix::LUPDecomposition#solve" do values = Matrix[[1, 2, 3, 4], [0, 1, 2, 3]] -> { @lu.solve(values) - }.should raise_error(Matrix::ErrDimensionMismatch) + }.should.raise(Matrix::ErrDimensionMismatch) end it "returns the right vector when given a vector of the appropriate size" do @@ -46,7 +46,7 @@ describe "Matrix::LUPDecomposition#solve" do values = Vector[14, 55] -> { @lu.solve(values) - }.should raise_error(Matrix::ErrDimensionMismatch) + }.should.raise(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 9b1dccbbac..ab59677dd9 100644 --- a/spec/ruby/library/matrix/lup_decomposition/to_a_spec.rb +++ b/spec/ruby/library/matrix/lup_decomposition/to_a_spec.rb @@ -10,9 +10,9 @@ describe "Matrix::LUPDecomposition#to_a" do end it "returns an array of three matrices" do - @to_a.should be_kind_of(Array) + @to_a.should.is_a?(Array) @to_a.length.should == 3 - @to_a.each{|m| m.should be_kind_of(Matrix)} + @to_a.each{|m| m.should.is_a?(Matrix)} end it "returns [l, u, p] such that l*u == a*p" do diff --git a/spec/ruby/library/matrix/lup_decomposition/u_spec.rb b/spec/ruby/library/matrix/lup_decomposition/u_spec.rb index ca3dfc1f00..967bc669dc 100644 --- a/spec/ruby/library/matrix/lup_decomposition/u_spec.rb +++ b/spec/ruby/library/matrix/lup_decomposition/u_spec.rb @@ -13,6 +13,6 @@ describe "Matrix::LUPDecomposition#u" do end it "returns an upper triangular matrix" do - @u.upper_triangular?.should be_true + @u.upper_triangular?.should == true end end diff --git a/spec/ruby/library/matrix/map_spec.rb b/spec/ruby/library/matrix/map_spec.rb index bc07c48cda..bae96db381 100644 --- a/spec/ruby/library/matrix/map_spec.rb +++ b/spec/ruby/library/matrix/map_spec.rb @@ -1,6 +1,26 @@ require_relative '../../spec_helper' -require_relative 'shared/collect' +require_relative 'fixtures/classes' describe "Matrix#map" do - it_behaves_like :collect, :map + before :all do + @m = Matrix[ [1, 2], [1, 2] ] + end + + it "returns an instance of Matrix" do + @m.map{|n| n * 2 }.should.is_a?(Matrix) + end + + it "returns a Matrix where each element is the result of the block" do + @m.map { |n| n * 2 }.should == Matrix[ [2, 4], [2, 4] ] + end + + it "returns an enumerator if no block is given" do + @m.map.should.instance_of?(Enumerator) + end + + describe "for a subclass of Matrix" do + it "returns an instance of that subclass" do + MatrixSub.ins.map{1}.should.instance_of?(MatrixSub) + end + end end diff --git a/spec/ruby/library/matrix/minor_spec.rb b/spec/ruby/library/matrix/minor_spec.rb index 009826c3d6..6b29db568b 100644 --- a/spec/ruby/library/matrix/minor_spec.rb +++ b/spec/ruby/library/matrix/minor_spec.rb @@ -79,7 +79,7 @@ describe "Matrix#minor" do 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) + MatrixSub.ins.minor(0, 1, 0, 1).should.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 95cf4a6072..7426aa2d2c 100644 --- a/spec/ruby/library/matrix/minus_spec.rb +++ b/spec/ruby/library/matrix/minus_spec.rb @@ -13,30 +13,30 @@ describe "Matrix#-" do end it "returns an instance of Matrix" do - (@a - @b).should be_kind_of(Matrix) + (@a - @b).should.is_a?(Matrix) end it "raises a Matrix::ErrDimensionMismatch if the matrices are different sizes" do - -> { @a - Matrix[ [1] ] }.should raise_error(Matrix::ErrDimensionMismatch) + -> { @a - Matrix[ [1] ] }.should.raise(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) + -> { @a - 2 }.should.raise(Matrix::ErrOperationNotDefined) + -> { @a - 1.2 }.should.raise(Matrix::ErrOperationNotDefined) + -> { @a - bignum_value }.should.raise(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) + -> { @a - nil }.should.raise(TypeError) + -> { @a - "a" }.should.raise(TypeError) + -> { @a - [ [1, 2] ] }.should.raise(TypeError) + -> { @a - Object.new }.should.raise(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-m).should.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 206868af92..6c495c5521 100644 --- a/spec/ruby/library/matrix/multiply_spec.rb +++ b/spec/ruby/library/matrix/multiply_spec.rb @@ -33,7 +33,7 @@ describe "Matrix#*" do end it "raises a Matrix::ErrDimensionMismatch if the matrices are different sizes" do - -> { @a * Matrix[ [1] ] }.should raise_error(Matrix::ErrDimensionMismatch) + -> { @a * Matrix[ [1] ] }.should.raise(Matrix::ErrDimensionMismatch) end it "returns a zero matrix if (nx0) * (0xn)" do @@ -53,17 +53,17 @@ describe "Matrix#*" do 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) + -> { @a * nil }.should.raise(TypeError) + -> { @a * "a" }.should.raise(TypeError) + -> { @a * [ [1, 2] ] }.should.raise(TypeError) + -> { @a * Object.new }.should.raise(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) + (m*m).should.instance_of?(MatrixSub) + (m*1).should.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 3005066846..bde9d9f4c8 100644 --- a/spec/ruby/library/matrix/new_spec.rb +++ b/spec/ruby/library/matrix/new_spec.rb @@ -3,6 +3,6 @@ require 'matrix' describe "Matrix.new" do it "is private" do - Matrix.should have_private_method(:new) + Matrix.private_methods(false).should.include?(:new) end end diff --git a/spec/ruby/library/matrix/normal_spec.rb b/spec/ruby/library/matrix/normal_spec.rb index a9e6c645fa..420d4b011f 100644 --- a/spec/ruby/library/matrix/normal_spec.rb +++ b/spec/ruby/library/matrix/normal_spec.rb @@ -20,7 +20,7 @@ describe "Matrix.normal?" do ].each do |rectangular_matrix| -> { rectangular_matrix.normal? - }.should raise_error(Matrix::ErrDimensionMismatch) + }.should.raise(Matrix::ErrDimensionMismatch) end end end diff --git a/spec/ruby/library/matrix/orthogonal_spec.rb b/spec/ruby/library/matrix/orthogonal_spec.rb index 26afe89ff0..71ac831fe8 100644 --- a/spec/ruby/library/matrix/orthogonal_spec.rb +++ b/spec/ruby/library/matrix/orthogonal_spec.rb @@ -20,7 +20,7 @@ describe "Matrix.orthogonal?" do ].each do |rectangular_matrix| -> { rectangular_matrix.orthogonal? - }.should raise_error(Matrix::ErrDimensionMismatch) + }.should.raise(Matrix::ErrDimensionMismatch) end end end diff --git a/spec/ruby/library/matrix/permutation_spec.rb b/spec/ruby/library/matrix/permutation_spec.rb index 825a9d982c..43727edea1 100644 --- a/spec/ruby/library/matrix/permutation_spec.rb +++ b/spec/ruby/library/matrix/permutation_spec.rb @@ -3,18 +3,18 @@ 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 + Matrix[[0, 1, 0], [0, 0, 1], [1, 0, 0]].permutation?.should == 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 + Matrix[[0, 1], [0, 0]].permutation?.should == false + Matrix[[-1, 0], [0, -1]].permutation?.should == false + Matrix[[1, 0], [1, 0]].permutation?.should == false + Matrix[[1, 0], [1, 1]].permutation?.should == false end it "returns true for an empty 0x0 matrix" do - Matrix.empty(0,0).permutation?.should be_true + Matrix.empty(0,0).permutation?.should == true end it "raises an error for rectangular matrices" do @@ -26,7 +26,7 @@ describe "Matrix#permutation?" do ].each do |rectangular_matrix| -> { rectangular_matrix.permutation? - }.should raise_error(Matrix::ErrDimensionMismatch) + }.should.raise(Matrix::ErrDimensionMismatch) end end end diff --git a/spec/ruby/library/matrix/plus_spec.rb b/spec/ruby/library/matrix/plus_spec.rb index 2706bad060..72a9ba8f8f 100644 --- a/spec/ruby/library/matrix/plus_spec.rb +++ b/spec/ruby/library/matrix/plus_spec.rb @@ -13,30 +13,30 @@ describe "Matrix#+" do end it "returns an instance of Matrix" do - (@a + @b).should be_kind_of(Matrix) + (@a + @b).should.is_a?(Matrix) end it "raises a Matrix::ErrDimensionMismatch if the matrices are different sizes" do - -> { @a + Matrix[ [1] ] }.should raise_error(Matrix::ErrDimensionMismatch) + -> { @a + Matrix[ [1] ] }.should.raise(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) + -> { @a + 2 }.should.raise(ExceptionForMatrix::ErrOperationNotDefined) + -> { @a + 1.2 }.should.raise(ExceptionForMatrix::ErrOperationNotDefined) + -> { @a + bignum_value }.should.raise(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) + -> { @a + nil }.should.raise(TypeError) + -> { @a + "a" }.should.raise(TypeError) + -> { @a + [ [1, 2] ] }.should.raise(TypeError) + -> { @a + Object.new }.should.raise(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+m).should.instance_of?(MatrixSub) end end end diff --git a/spec/ruby/library/matrix/real_spec.rb b/spec/ruby/library/matrix/real_spec.rb index 38033c63c8..4589dc22a5 100644 --- a/spec/ruby/library/matrix/real_spec.rb +++ b/spec/ruby/library/matrix/real_spec.rb @@ -4,22 +4,22 @@ 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 + Matrix[ [1, 2], [3, 4] ].real?.should == true + Matrix[ [1.9, 2], [3, 4] ].real?.should == true end it "returns true for empty matrices" do - Matrix.empty.real?.should be_true + Matrix.empty.real?.should == true end it "returns false if one element is a Complex" do - Matrix[ [Complex(1,1), 2], [3, 4] ].real?.should be_false + Matrix[ [Complex(1,1), 2], [3, 4] ].real?.should == 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 + Matrix[ [Complex(1,0), 2], [3, 4] ].real?.should == false end end end @@ -37,7 +37,7 @@ describe "Matrix#real" do describe "for a subclass of Matrix" do it "returns an instance of that subclass" do - MatrixSub.ins.real.should be_an_instance_of(MatrixSub) + MatrixSub.ins.real.should.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 83a0404e47..b0ca3f0421 100644 --- a/spec/ruby/library/matrix/rect_spec.rb +++ b/spec/ruby/library/matrix/rect_spec.rb @@ -1,6 +1,8 @@ require_relative '../../spec_helper' -require_relative 'shared/rectangular' +require 'matrix' describe "Matrix#rect" do - it_behaves_like :matrix_rectangular, :rect + it "is an alias of Matrix#rectangular" do + Matrix.instance_method(:rect).should == Matrix.instance_method(:rectangular) + end end diff --git a/spec/ruby/library/matrix/rectangular_spec.rb b/spec/ruby/library/matrix/rectangular_spec.rb index a235fac640..c0732f96bc 100644 --- a/spec/ruby/library/matrix/rectangular_spec.rb +++ b/spec/ruby/library/matrix/rectangular_spec.rb @@ -1,6 +1,19 @@ require_relative '../../spec_helper' -require_relative 'shared/rectangular' +require_relative 'fixtures/classes' +require 'matrix' describe "Matrix#rectangular" do - it_behaves_like :matrix_rectangular, :rectangular + it "returns [receiver.real, receiver.imag]" do + m = Matrix[ [1.2, Complex(1,2)], [Complex(-2,0.42), 4] ] + m.rectangular.should == [m.real, m.imag] + + m = Matrix.empty(3, 0) + m.rectangular.should == [m.real, m.imag] + end + + describe "for a subclass of Matrix" do + it "returns instances of that subclass" do + MatrixSub.ins.rectangular.each{|m| m.should.instance_of?(MatrixSub) } + end + end end diff --git a/spec/ruby/library/matrix/regular_spec.rb b/spec/ruby/library/matrix/regular_spec.rb index 3699d0ef8b..4cb00819ac 100644 --- a/spec/ruby/library/matrix/regular_spec.rb +++ b/spec/ruby/library/matrix/regular_spec.rb @@ -5,27 +5,27 @@ 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 + m.regular?.should == false m = Matrix[ [1,2,9], [3,4,9], [1,2,9] ] - m.regular?.should be_false + m.regular?.should == false end it "returns true if the Matrix is regular" do - Matrix[ [0,1], [1,0] ].regular?.should be_true + Matrix[ [0,1], [1,0] ].regular?.should == true end it "returns true for an empty 0x0 matrix" do - Matrix.empty(0,0).regular?.should be_true + Matrix.empty(0,0).regular?.should == true end it "raises an error for rectangular matrices" do -> { Matrix[[1], [2], [3]].regular? - }.should raise_error(Matrix::ErrDimensionMismatch) + }.should.raise(Matrix::ErrDimensionMismatch) -> { Matrix.empty(3,0).regular? - }.should raise_error(Matrix::ErrDimensionMismatch) + }.should.raise(Matrix::ErrDimensionMismatch) end end diff --git a/spec/ruby/library/matrix/round_spec.rb b/spec/ruby/library/matrix/round_spec.rb index 1dc29df890..cdec646fa1 100644 --- a/spec/ruby/library/matrix/round_spec.rb +++ b/spec/ruby/library/matrix/round_spec.rb @@ -15,7 +15,7 @@ describe "Matrix#round" do describe "for a subclass of Matrix" do it "returns an instance of that subclass" do - MatrixSub.ins.round.should be_an_instance_of(MatrixSub) + MatrixSub.ins.round.should.instance_of?(MatrixSub) end end end diff --git a/spec/ruby/library/matrix/row_spec.rb b/spec/ruby/library/matrix/row_spec.rb index 00b1f02a8e..8a7662fdf2 100644 --- a/spec/ruby/library/matrix/row_spec.rb +++ b/spec/ruby/library/matrix/row_spec.rb @@ -21,7 +21,7 @@ describe "Matrix#row" do end it "returns self when called with a block" do - @m.row(0) { |x| x }.should equal(@m) + @m.row(0) { |x| x }.should.equal?(@m) end it "returns nil when out of bounds" do @@ -30,7 +30,7 @@ describe "Matrix#row" do 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 + -> { @m.row(3){ raise } }.should_not.raise + -> { @m.row(-4){ raise } }.should_not.raise end end diff --git a/spec/ruby/library/matrix/row_vector_spec.rb b/spec/ruby/library/matrix/row_vector_spec.rb index 341437ee05..f3919fb7d8 100644 --- a/spec/ruby/library/matrix/row_vector_spec.rb +++ b/spec/ruby/library/matrix/row_vector_spec.rb @@ -5,7 +5,7 @@ require 'matrix' describe "Matrix.row_vector" do it "returns a Matrix" do - Matrix.row_vector([]).should be_an_instance_of(Matrix) + Matrix.row_vector([]).should.instance_of?(Matrix) end it "returns a single-row Matrix with the specified values" do @@ -18,7 +18,7 @@ describe "Matrix.row_vector" do 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) + MatrixSub.row_vector([1]).should.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 6f99c439a6..4a0db67527 100644 --- a/spec/ruby/library/matrix/row_vectors_spec.rb +++ b/spec/ruby/library/matrix/row_vectors_spec.rb @@ -8,11 +8,11 @@ describe "Matrix#row_vectors" do end it "returns an Array" do - Matrix[ [1,2], [3,4] ].row_vectors.should be_an_instance_of(Array) + Matrix[ [1,2], [3,4] ].row_vectors.should.instance_of?(Array) end it "returns an Array of Vectors" do - @vectors.all? {|v| v.should be_an_instance_of(Vector)} + @vectors.all? {|v| v.should.instance_of?(Vector)} end it "returns each row as a Vector" do diff --git a/spec/ruby/library/matrix/rows_spec.rb b/spec/ruby/library/matrix/rows_spec.rb index 41ba635775..9c248cd8a4 100644 --- a/spec/ruby/library/matrix/rows_spec.rb +++ b/spec/ruby/library/matrix/rows_spec.rb @@ -10,7 +10,7 @@ describe "Matrix.rows" do end it "returns a Matrix" do - @m.should be_kind_of(Matrix) + @m.should.is_a?(Matrix) end it "creates a matrix from argument rows" do @@ -21,8 +21,8 @@ describe "Matrix.rows" do 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) + @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 @@ -35,7 +35,7 @@ describe "Matrix.rows" do 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) + MatrixSub.rows([[0, 1], [0, 1]]).should.instance_of?(MatrixSub) end end end diff --git a/spec/ruby/library/matrix/scalar_spec.rb b/spec/ruby/library/matrix/scalar_spec.rb index 7fdd64c9d9..5b93b60533 100644 --- a/spec/ruby/library/matrix/scalar_spec.rb +++ b/spec/ruby/library/matrix/scalar_spec.rb @@ -10,7 +10,7 @@ describe "Matrix.scalar" do end it "returns a Matrix" do - @a.should be_kind_of(Matrix) + @a.should.is_a?(Matrix) end it "returns a n x n matrix" do @@ -41,7 +41,7 @@ describe "Matrix.scalar" do end it "returns a Matrix" do - @a.should be_kind_of(Matrix) + @a.should.is_a?(Matrix) end it "returns a square matrix, where the first argument specifies the side of the square" do diff --git a/spec/ruby/library/matrix/shared/collect.rb b/spec/ruby/library/matrix/shared/collect.rb deleted file mode 100644 index 852f7fd6cf..0000000000 --- a/spec/ruby/library/matrix/shared/collect.rb +++ /dev/null @@ -1,26 +0,0 @@ -require_relative '../fixtures/classes' -require 'matrix' - -describe :collect, shared: true do - before :all do - @m = Matrix[ [1, 2], [1, 2] ] - end - - it "returns an instance of Matrix" do - @m.send(@method){|n| n * 2 }.should be_kind_of(Matrix) - end - - it "returns a Matrix where each element is the result of the block" do - @m.send(@method) { |n| n * 2 }.should == Matrix[ [2, 4], [2, 4] ] - end - - it "returns an enumerator if no block is given" do - @m.send(@method).should be_an_instance_of(Enumerator) - end - - describe "for a subclass of Matrix" do - it "returns an instance of that subclass" do - MatrixSub.ins.send(@method){1}.should be_an_instance_of(MatrixSub) - end - end -end diff --git a/spec/ruby/library/matrix/shared/conjugate.rb b/spec/ruby/library/matrix/shared/conjugate.rb deleted file mode 100644 index d87658f855..0000000000 --- a/spec/ruby/library/matrix/shared/conjugate.rb +++ /dev/null @@ -1,20 +0,0 @@ -require_relative '../fixtures/classes' -require 'matrix' - -describe :matrix_conjugate, shared: true do - it "returns a matrix with all entries 'conjugated'" do - Matrix[ [1, 2], [3, 4] ].send(@method).should == Matrix[ [1, 2], [3, 4] ] - Matrix[ [1.9, Complex(1,1)], [3, 4] ].send(@method).should == Matrix[ [1.9, Complex(1,-1)], [3, 4] ] - end - - it "returns empty matrices on the same size if empty" do - Matrix.empty(0, 3).send(@method).should == Matrix.empty(0, 3) - Matrix.empty(3, 0).send(@method).should == Matrix.empty(3, 0) - end - - describe "for a subclass of Matrix" do - it "returns an instance of that subclass" do - MatrixSub.ins.send(@method).should be_an_instance_of(MatrixSub) - end - end -end diff --git a/spec/ruby/library/matrix/shared/determinant.rb b/spec/ruby/library/matrix/shared/determinant.rb deleted file mode 100644 index 9e0528c24b..0000000000 --- a/spec/ruby/library/matrix/shared/determinant.rb +++ /dev/null @@ -1,38 +0,0 @@ -require 'matrix' - -describe :determinant, shared: true do - it "returns the determinant of a square Matrix" do - m = Matrix[ [7,6], [3,9] ] - m.send(@method).should == 45 - - m = Matrix[ [9, 8], [6,5] ] - m.send(@method).should == -3 - - m = Matrix[ [9,8,3], [4,20,5], [1,1,1] ] - m.send(@method).should == 95 - end - - it "returns the determinant of a single-element Matrix" do - m = Matrix[ [2] ] - m.send(@method).should == 2 - end - - it "returns 1 for an empty Matrix" do - m = Matrix[ ] - m.send(@method).should == 1 - end - - it "returns the determinant even for Matrices containing 0 as first entry" do - Matrix[[0,1],[1,0]].send(@method).should == -1 - end - - it "raises an error for rectangular matrices" do - -> { - Matrix[[1], [2], [3]].send(@method) - }.should raise_error(Matrix::ErrDimensionMismatch) - - -> { - Matrix.empty(3,0).send(@method) - }.should raise_error(Matrix::ErrDimensionMismatch) - end -end diff --git a/spec/ruby/library/matrix/shared/equal_value.rb b/spec/ruby/library/matrix/shared/equal_value.rb index 2b2311d49e..9bc6ed908b 100644 --- a/spec/ruby/library/matrix/shared/equal_value.rb +++ b/spec/ruby/library/matrix/shared/equal_value.rb @@ -7,27 +7,27 @@ describe :equal, shared: true do end it "returns true for self" do - @matrix.send(@method, @matrix).should be_true + @matrix.send(@method, @matrix).should == true end it "returns true for equal matrices" do - @matrix.send(@method, Matrix[ [1, 2, 3, 4, 5], [2, 3, 4, 5, 6] ]).should be_true + @matrix.send(@method, Matrix[ [1, 2, 3, 4, 5], [2, 3, 4, 5, 6] ]).should == true end it "returns false for different matrices" do - @matrix.send(@method, Matrix[ [42, 2, 3, 4, 5], [2, 3, 4, 5, 6] ]).should be_false - @matrix.send(@method, Matrix[ [1, 2, 3, 4, 5, 6], [2, 3, 4, 5, 6, 7] ]).should be_false - @matrix.send(@method, Matrix[ [1, 2, 3], [2, 3, 4] ]).should be_false + @matrix.send(@method, Matrix[ [42, 2, 3, 4, 5], [2, 3, 4, 5, 6] ]).should == false + @matrix.send(@method, Matrix[ [1, 2, 3, 4, 5, 6], [2, 3, 4, 5, 6, 7] ]).should == false + @matrix.send(@method, Matrix[ [1, 2, 3], [2, 3, 4] ]).should == false end it "returns false for different empty matrices" do - Matrix.empty(42, 0).send(@method, Matrix.empty(6, 0)).should be_false - Matrix.empty(0, 42).send(@method, Matrix.empty(0, 6)).should be_false - Matrix.empty(0, 0).send(@method, Matrix.empty(6, 0)).should be_false - Matrix.empty(0, 0).send(@method, Matrix.empty(0, 6)).should be_false + Matrix.empty(42, 0).send(@method, Matrix.empty(6, 0)).should == false + Matrix.empty(0, 42).send(@method, Matrix.empty(0, 6)).should == false + Matrix.empty(0, 0).send(@method, Matrix.empty(6, 0)).should == false + Matrix.empty(0, 0).send(@method, Matrix.empty(0, 6)).should == false end it "doesn't distinguish on subclasses" do - MatrixSub.ins.send(@method, Matrix.I(2)).should be_true + MatrixSub.ins.send(@method, Matrix.I(2)).should == true end end diff --git a/spec/ruby/library/matrix/shared/identity.rb b/spec/ruby/library/matrix/shared/identity.rb deleted file mode 100644 index 114f86e7b0..0000000000 --- a/spec/ruby/library/matrix/shared/identity.rb +++ /dev/null @@ -1,19 +0,0 @@ -require_relative '../fixtures/classes' -require 'matrix' - -describe :matrix_identity, shared: true do - it "returns a Matrix" do - Matrix.send(@method, 2).should be_kind_of(Matrix) - end - - it "returns a n x n identity matrix" do - Matrix.send(@method, 3).should == Matrix.scalar(3, 1) - Matrix.send(@method, 100).should == Matrix.scalar(100, 1) - end - - describe "for a subclass of Matrix" do - it "returns an instance of that subclass" do - MatrixSub.send(@method, 2).should be_an_instance_of(MatrixSub) - end - end -end diff --git a/spec/ruby/library/matrix/shared/imaginary.rb b/spec/ruby/library/matrix/shared/imaginary.rb deleted file mode 100644 index d28ecc69f1..0000000000 --- a/spec/ruby/library/matrix/shared/imaginary.rb +++ /dev/null @@ -1,20 +0,0 @@ -require_relative '../fixtures/classes' -require 'matrix' - -describe :matrix_imaginary, shared: true do - it "returns a matrix with the imaginary part of the elements of the receiver" do - Matrix[ [1, 2], [3, 4] ].send(@method).should == Matrix[ [0, 0], [0, 0] ] - Matrix[ [1.9, Complex(1,1)], [Complex(-2,0.42), 4] ].send(@method).should == Matrix[ [0, 1], [0.42, 0] ] - end - - it "returns empty matrices on the same size if empty" do - Matrix.empty(0, 3).send(@method).should == Matrix.empty(0, 3) - Matrix.empty(3, 0).send(@method).should == Matrix.empty(3, 0) - end - - describe "for a subclass of Matrix" do - it "returns an instance of that subclass" do - MatrixSub.ins.send(@method).should be_an_instance_of(MatrixSub) - end - end -end diff --git a/spec/ruby/library/matrix/shared/inverse.rb b/spec/ruby/library/matrix/shared/inverse.rb deleted file mode 100644 index c8a6b90da5..0000000000 --- a/spec/ruby/library/matrix/shared/inverse.rb +++ /dev/null @@ -1,38 +0,0 @@ -require_relative '../fixtures/classes' -require 'matrix' - -describe :inverse, shared: true do - - it "returns a Matrix" do - Matrix[ [1,2], [2,1] ].send(@method).should be_an_instance_of(Matrix) - end - - it "returns the inverse of the Matrix" do - Matrix[ - [1, 3, 3], [1, 4, 3], [1, 3, 4] - ].send(@method).should == - Matrix[ - [7, -3, -3], [-1, 1, 0], [-1, 0, 1] - ] - end - - it "returns the inverse of the Matrix (other case)" do - Matrix[ - [1, 2, 3], [0, 1, 4], [5, 6, 0] - ].send(@method).should be_close_to_matrix([ - [-24, 18, 5], [20, -15, -4], [-5, 4, 1] - ]) - end - - it "raises a ErrDimensionMismatch if the Matrix is not square" do - ->{ - Matrix[ [1,2,3], [1,2,3] ].send(@method) - }.should raise_error(Matrix::ErrDimensionMismatch) - end - - describe "for a subclass of Matrix" do - it "returns an instance of that subclass" do - MatrixSub.ins.send(@method).should be_an_instance_of(MatrixSub) - end - end -end diff --git a/spec/ruby/library/matrix/shared/rectangular.rb b/spec/ruby/library/matrix/shared/rectangular.rb deleted file mode 100644 index 3d9a0dfe8a..0000000000 --- a/spec/ruby/library/matrix/shared/rectangular.rb +++ /dev/null @@ -1,18 +0,0 @@ -require_relative '../fixtures/classes' -require 'matrix' - -describe :matrix_rectangular, shared: true do - it "returns [receiver.real, receiver.imag]" do - m = Matrix[ [1.2, Complex(1,2)], [Complex(-2,0.42), 4] ] - m.send(@method).should == [m.real, m.imag] - - m = Matrix.empty(3, 0) - m.send(@method).should == [m.real, m.imag] - end - - describe "for a subclass of Matrix" do - it "returns instances of that subclass" do - MatrixSub.ins.send(@method).each{|m| m.should be_an_instance_of(MatrixSub) } - end - end -end diff --git a/spec/ruby/library/matrix/shared/trace.rb b/spec/ruby/library/matrix/shared/trace.rb deleted file mode 100644 index 57b89863f8..0000000000 --- a/spec/ruby/library/matrix/shared/trace.rb +++ /dev/null @@ -1,12 +0,0 @@ -require 'matrix' - -describe :trace, shared: true do - it "returns the sum of diagonal elements in a square Matrix" do - Matrix[[7,6], [3,9]].trace.should == 16 - end - - it "returns the sum of diagonal elements in a rectangular Matrix" do - ->{ Matrix[[1,2,3], [4,5,6]].trace}.should raise_error(Matrix::ErrDimensionMismatch) - end - -end diff --git a/spec/ruby/library/matrix/shared/transpose.rb b/spec/ruby/library/matrix/shared/transpose.rb deleted file mode 100644 index 89b1d025be..0000000000 --- a/spec/ruby/library/matrix/shared/transpose.rb +++ /dev/null @@ -1,19 +0,0 @@ -require_relative '../fixtures/classes' -require 'matrix' - -describe :matrix_transpose, shared: true do - it "returns a transposed matrix" do - Matrix[[1, 2], [3, 4], [5, 6]].send(@method).should == Matrix[[1, 3, 5], [2, 4, 6]] - end - - it "can transpose empty matrices" do - m = Matrix[[], [], []] - m.send(@method).send(@method).should == m - end - - describe "for a subclass of Matrix" do - it "returns an instance of that subclass" do - MatrixSub.ins.send(@method).should be_an_instance_of(MatrixSub) - end - end -end diff --git a/spec/ruby/library/matrix/singular_spec.rb b/spec/ruby/library/matrix/singular_spec.rb index 7bba36a54a..00b93af495 100644 --- a/spec/ruby/library/matrix/singular_spec.rb +++ b/spec/ruby/library/matrix/singular_spec.rb @@ -4,28 +4,28 @@ 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 + m.singular?.should == true m = Matrix[ [1,2,9], [3,4,9], [1,2,9] ] - m.singular?.should be_true + m.singular?.should == true end it "returns false if the Matrix is regular" do - Matrix[ [0,1], [1,0] ].singular?.should be_false + Matrix[ [0,1], [1,0] ].singular?.should == false end it "returns false for an empty 0x0 matrix" do - Matrix.empty(0,0).singular?.should be_false + Matrix.empty(0,0).singular?.should == false end it "raises an error for rectangular matrices" do -> { Matrix[[1], [2], [3]].singular? - }.should raise_error(Matrix::ErrDimensionMismatch) + }.should.raise(Matrix::ErrDimensionMismatch) -> { Matrix.empty(3,0).singular? - }.should raise_error(Matrix::ErrDimensionMismatch) + }.should.raise(Matrix::ErrDimensionMismatch) end end diff --git a/spec/ruby/library/matrix/square_spec.rb b/spec/ruby/library/matrix/square_spec.rb index 25d2d1ad9c..b8cf4acf44 100644 --- a/spec/ruby/library/matrix/square_spec.rb +++ b/spec/ruby/library/matrix/square_spec.rb @@ -4,25 +4,25 @@ require 'matrix' 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 + Matrix[ [1,2], [2,4] ].square?.should == true + Matrix[ [100,3,5], [9.5, 4.9, 8], [2,0,77] ].square?.should == true end it "returns true when the Matrix has only one element" do - Matrix[ [9] ].square?.should be_true + Matrix[ [9] ].square?.should == true end it "returns false when the Matrix is rectangular" do - Matrix[ [1, 2] ].square?.should be_false + Matrix[ [1, 2] ].square?.should == false end it "returns false when the Matrix is rectangular" do - Matrix[ [1], [2] ].square?.should be_false + Matrix[ [1], [2] ].square?.should == false end it "returns handles empty matrices" do - Matrix[].square?.should be_true - Matrix[[]].square?.should be_false - Matrix.columns([[]]).square?.should be_false + Matrix[].square?.should == true + Matrix[[]].square?.should == false + Matrix.columns([[]]).square?.should == false end end diff --git a/spec/ruby/library/matrix/symmetric_spec.rb b/spec/ruby/library/matrix/symmetric_spec.rb index 6f2a99276a..4b86c19503 100644 --- a/spec/ruby/library/matrix/symmetric_spec.rb +++ b/spec/ruby/library/matrix/symmetric_spec.rb @@ -3,15 +3,15 @@ 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 + Matrix[[1, 2, Complex(0, 3)], [2, 4, 5], [Complex(0, 3), 5, 6]].symmetric?.should == true end it "returns true for a 0x0 empty matrix" do - Matrix.empty.symmetric?.should be_true + Matrix.empty.symmetric?.should == true end it "returns false for an asymmetric Matrix" do - Matrix[[1, 2],[-2, 1]].symmetric?.should be_false + Matrix[[1, 2],[-2, 1]].symmetric?.should == false end it "raises an error for rectangular matrices" do @@ -23,7 +23,7 @@ describe "Matrix.symmetric?" do ].each do |rectangular_matrix| -> { rectangular_matrix.symmetric? - }.should raise_error(Matrix::ErrDimensionMismatch) + }.should.raise(Matrix::ErrDimensionMismatch) end end end diff --git a/spec/ruby/library/matrix/t_spec.rb b/spec/ruby/library/matrix/t_spec.rb index 6f1a5178e0..9411597e7c 100644 --- a/spec/ruby/library/matrix/t_spec.rb +++ b/spec/ruby/library/matrix/t_spec.rb @@ -1,6 +1,8 @@ require_relative '../../spec_helper' -require_relative 'shared/transpose' +require 'matrix' -describe "Matrix#transpose" do - it_behaves_like :matrix_transpose, :t +describe "Matrix#t" do + it "is an alias of Matrix#transpose" do + Matrix.instance_method(:t).should == Matrix.instance_method(:transpose) + end end diff --git a/spec/ruby/library/matrix/tr_spec.rb b/spec/ruby/library/matrix/tr_spec.rb index e17bd790d7..04d237d483 100644 --- a/spec/ruby/library/matrix/tr_spec.rb +++ b/spec/ruby/library/matrix/tr_spec.rb @@ -1,7 +1,8 @@ require_relative '../../spec_helper' -require_relative 'shared/trace' require 'matrix' describe "Matrix#tr" do - it_behaves_like :trace, :tr + it "is an alias of Matrix#trace" do + Matrix.instance_method(:tr).should == Matrix.instance_method(:trace) + end end diff --git a/spec/ruby/library/matrix/trace_spec.rb b/spec/ruby/library/matrix/trace_spec.rb index 290e7cb1f7..831278c838 100644 --- a/spec/ruby/library/matrix/trace_spec.rb +++ b/spec/ruby/library/matrix/trace_spec.rb @@ -1,7 +1,12 @@ require_relative '../../spec_helper' -require_relative 'shared/trace' require 'matrix' describe "Matrix#trace" do - it_behaves_like :trace, :trace + it "returns the sum of diagonal elements in a square Matrix" do + Matrix[[7,6], [3,9]].trace.should == 16 + end + + it "returns the sum of diagonal elements in a rectangular Matrix" do + ->{ Matrix[[1,2,3], [4,5,6]].trace}.should.raise(Matrix::ErrDimensionMismatch) + end end diff --git a/spec/ruby/library/matrix/transpose_spec.rb b/spec/ruby/library/matrix/transpose_spec.rb index 79600dd439..0b24ab32a7 100644 --- a/spec/ruby/library/matrix/transpose_spec.rb +++ b/spec/ruby/library/matrix/transpose_spec.rb @@ -1,6 +1,19 @@ require_relative '../../spec_helper' -require_relative 'shared/transpose' +require_relative 'fixtures/classes' describe "Matrix#transpose" do - it_behaves_like :matrix_transpose, :transpose + it "returns a transposed matrix" do + Matrix[[1, 2], [3, 4], [5, 6]].transpose.should == Matrix[[1, 3, 5], [2, 4, 6]] + end + + it "can transpose empty matrices" do + m = Matrix[[], [], []] + m.transpose.transpose.should == m + end + + describe "for a subclass of Matrix" do + it "returns an instance of that subclass" do + MatrixSub.ins.transpose.should.instance_of?(MatrixSub) + end + end end diff --git a/spec/ruby/library/matrix/unit_spec.rb b/spec/ruby/library/matrix/unit_spec.rb index 6a41d729c7..1121996122 100644 --- a/spec/ruby/library/matrix/unit_spec.rb +++ b/spec/ruby/library/matrix/unit_spec.rb @@ -1,6 +1,8 @@ require_relative '../../spec_helper' -require_relative 'shared/identity' +require 'matrix' describe "Matrix.unit" do - it_behaves_like :matrix_identity, :unit + it "is an alias of Matrix.identity" do + Matrix.method(:unit).should == Matrix.method(:identity) + end end diff --git a/spec/ruby/library/matrix/unitary_spec.rb b/spec/ruby/library/matrix/unitary_spec.rb index c214ee9b2f..4490e8f8d4 100644 --- a/spec/ruby/library/matrix/unitary_spec.rb +++ b/spec/ruby/library/matrix/unitary_spec.rb @@ -26,7 +26,7 @@ describe "Matrix.unitary?" do ].each do |rectangular_matrix| -> { rectangular_matrix.unitary? - }.should raise_error(Matrix::ErrDimensionMismatch) + }.should.raise(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 2514294a80..0e2bf611e2 100644 --- a/spec/ruby/library/matrix/upper_triangular_spec.rb +++ b/spec/ruby/library/matrix/upper_triangular_spec.rb @@ -3,22 +3,22 @@ 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 + Matrix[[1, 2, 3], [0, 2, 3], [0, 0, 3]].upper_triangular?.should == true + Matrix.diagonal([1, 2, 3]).upper_triangular?.should == true + Matrix[[1, 2], [0, 2], [0, 0], [0, 0]].upper_triangular?.should == true + Matrix[[1, 2, 3, 4], [0, 2, 3, 4]].upper_triangular?.should == 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 + Matrix[[0, 0], [1, 0]].upper_triangular?.should == false + Matrix[[1, 2, 3], [1, 2, 3], [1, 2, 3]].upper_triangular?.should == false + Matrix[[0, 0], [0, 0], [0, 0], [0, 1]].upper_triangular?.should == false + Matrix[[0, 0, 0, 0], [1, 0, 0, 0]].upper_triangular?.should == 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 + Matrix.empty(3,0).upper_triangular?.should == true + Matrix.empty(0,3).upper_triangular?.should == true + Matrix.empty(0,0).upper_triangular?.should == 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 c2698ade4c..96a462c067 100644 --- a/spec/ruby/library/matrix/vector/cross_product_spec.rb +++ b/spec/ruby/library/matrix/vector/cross_product_spec.rb @@ -9,6 +9,6 @@ describe "Vector#cross_product" do 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) + }.should.raise(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 10d2fc404d..86e7ed75aa 100644 --- a/spec/ruby/library/matrix/vector/each2_spec.rb +++ b/spec/ruby/library/matrix/vector/each2_spec.rb @@ -8,8 +8,8 @@ describe "Vector.each2" do end it "requires one argument" do - -> { @v.each2(@v2, @v2){} }.should raise_error(ArgumentError) - -> { @v.each2(){} }.should raise_error(ArgumentError) + -> { @v.each2(@v2, @v2){} }.should.raise(ArgumentError) + -> { @v.each2(){} }.should.raise(ArgumentError) end describe "given one argument" do @@ -20,8 +20,8 @@ describe "Vector.each2" do 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) + -> { @v.each2(Vector[1,2]){} }.should.raise(Vector::ErrDimensionMismatch) + -> { @v.each2(Vector[1,2,3,4]){} }.should.raise(Vector::ErrDimensionMismatch) end it "yields arguments in sequence" do @@ -37,12 +37,12 @@ describe "Vector.each2" do end it "returns self when given a block" do - @v.each2(@v2){}.should equal(@v) + @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.should.instance_of?(Enumerator) enum.to_a.should == [[1, 4], [2, 5], [3, 6]] end end diff --git a/spec/ruby/library/matrix/vector/eql_spec.rb b/spec/ruby/library/matrix/vector/eql_spec.rb index eb2451b550..6e2cd47b8e 100644 --- a/spec/ruby/library/matrix/vector/eql_spec.rb +++ b/spec/ruby/library/matrix/vector/eql_spec.rb @@ -7,10 +7,10 @@ describe "Vector#eql?" do end it "returns true for self" do - @vector.eql?(@vector).should be_true + @vector.eql?(@vector).should == 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 + @vector.eql?(Vector[1, 2, 3, 4, 5.0]).should == 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 1cf8771e04..79dee10833 100644 --- a/spec/ruby/library/matrix/vector/inner_product_spec.rb +++ b/spec/ruby/library/matrix/vector/inner_product_spec.rb @@ -13,7 +13,7 @@ describe "Vector#inner_product" do it "raises an error for mismatched vectors" do -> { Vector[1, 2, 3].inner_product(Vector[0, -4]) - }.should raise_error(Vector::ErrDimensionMismatch) + }.should.raise(Vector::ErrDimensionMismatch) end it "uses the conjugate of its argument" do diff --git a/spec/ruby/library/matrix/vector/normalize_spec.rb b/spec/ruby/library/matrix/vector/normalize_spec.rb index 527c9260de..bb1f046786 100644 --- a/spec/ruby/library/matrix/vector/normalize_spec.rb +++ b/spec/ruby/library/matrix/vector/normalize_spec.rb @@ -10,9 +10,9 @@ describe "Vector#normalize" do it "raises an error for zero vectors" do -> { Vector[].normalize - }.should raise_error(Vector::ZeroVectorError) + }.should.raise(Vector::ZeroVectorError) -> { Vector[0, 0, 0].normalize - }.should raise_error(Vector::ZeroVectorError) + }.should.raise(Vector::ZeroVectorError) end end diff --git a/spec/ruby/library/matrix/zero_spec.rb b/spec/ruby/library/matrix/zero_spec.rb index 68e8567c26..406bcad6ed 100644 --- a/spec/ruby/library/matrix/zero_spec.rb +++ b/spec/ruby/library/matrix/zero_spec.rb @@ -4,7 +4,7 @@ require 'matrix' describe "Matrix.zero" do it "returns an object of type Matrix" do - Matrix.zero(3).should be_kind_of(Matrix) + Matrix.zero(3).should.is_a?(Matrix) end it "creates a n x n matrix" do @@ -30,7 +30,7 @@ describe "Matrix.zero" do describe "for a subclass of Matrix" do it "returns an instance of that subclass" do - MatrixSub.zero(3).should be_an_instance_of(MatrixSub) + MatrixSub.zero(3).should.instance_of?(MatrixSub) end end end diff --git a/spec/ruby/library/monitor/exit_spec.rb b/spec/ruby/library/monitor/exit_spec.rb index 952ad9525d..0748a523ac 100644 --- a/spec/ruby/library/monitor/exit_spec.rb +++ b/spec/ruby/library/monitor/exit_spec.rb @@ -5,6 +5,6 @@ describe "Monitor#exit" do it "raises ThreadError when monitor is not entered" do m = Monitor.new - -> { m.exit }.should raise_error(ThreadError) + -> { m.exit }.should.raise(ThreadError) end end diff --git a/spec/ruby/library/monitor/mon_initialize_spec.rb b/spec/ruby/library/monitor/mon_initialize_spec.rb index e0fe6c2d97..092aee929c 100644 --- a/spec/ruby/library/monitor/mon_initialize_spec.rb +++ b/spec/ruby/library/monitor/mon_initialize_spec.rb @@ -26,6 +26,6 @@ describe "MonitorMixin#mon_initialize" do instance = cls.new(1, 2, 3) copy = instance.dup - copy.should_not equal(instance) + copy.should_not.equal?(instance) end end diff --git a/spec/ruby/library/monitor/synchronize_spec.rb b/spec/ruby/library/monitor/synchronize_spec.rb index d78393eb3a..27cc1258b4 100644 --- a/spec/ruby/library/monitor/synchronize_spec.rb +++ b/spec/ruby/library/monitor/synchronize_spec.rb @@ -31,11 +31,11 @@ describe "Monitor#synchronize" do end it "raises a LocalJumpError if not passed a block" do - -> { Monitor.new.synchronize }.should raise_error(LocalJumpError) + -> { Monitor.new.synchronize }.should.raise(LocalJumpError) end it "raises a thread error if the monitor is not owned on exiting the block" do monitor = Monitor.new - -> { monitor.synchronize { monitor.exit } }.should raise_error(ThreadError) + -> { monitor.synchronize { monitor.exit } }.should.raise(ThreadError) end end diff --git a/spec/ruby/library/net-ftp/FTPError_spec.rb b/spec/ruby/library/net-ftp/FTPError_spec.rb index 0c31b65dcc..b447e50546 100644 --- a/spec/ruby/library/net-ftp/FTPError_spec.rb +++ b/spec/ruby/library/net-ftp/FTPError_spec.rb @@ -1,8 +1,11 @@ require_relative '../../spec_helper' -require 'net/ftp' -describe "Net::FTPError" do - it "is an Exception" do - Net::FTPError.should < Exception +ruby_version_is ""..."4.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-ftp/FTPPermError_spec.rb b/spec/ruby/library/net-ftp/FTPPermError_spec.rb index b43e12c503..b9a2d93aef 100644 --- a/spec/ruby/library/net-ftp/FTPPermError_spec.rb +++ b/spec/ruby/library/net-ftp/FTPPermError_spec.rb @@ -1,12 +1,15 @@ require_relative '../../spec_helper' -require 'net/ftp' -describe "Net::FTPPermError" do - it "is an Exception" do - Net::FTPPermError.should < Exception - end +ruby_version_is ""..."4.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 + it "is a subclass of Net::FTPError" do + Net::FTPPermError.should < Net::FTPError + end end end diff --git a/spec/ruby/library/net-ftp/FTPProtoError_spec.rb b/spec/ruby/library/net-ftp/FTPProtoError_spec.rb index e7abbc0dd8..a1d9e44d63 100644 --- a/spec/ruby/library/net-ftp/FTPProtoError_spec.rb +++ b/spec/ruby/library/net-ftp/FTPProtoError_spec.rb @@ -1,12 +1,15 @@ require_relative '../../spec_helper' -require 'net/ftp' -describe "Net::FTPProtoError" do - it "is an Exception" do - Net::FTPProtoError.should < Exception - end +ruby_version_is ""..."4.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 + it "is a subclass of Net::FTPError" do + Net::FTPPermError.should < Net::FTPError + end end end diff --git a/spec/ruby/library/net-ftp/FTPReplyError_spec.rb b/spec/ruby/library/net-ftp/FTPReplyError_spec.rb index fcc7501fc1..c9e6468323 100644 --- a/spec/ruby/library/net-ftp/FTPReplyError_spec.rb +++ b/spec/ruby/library/net-ftp/FTPReplyError_spec.rb @@ -1,12 +1,15 @@ require_relative '../../spec_helper' -require 'net/ftp' -describe "Net::FTPReplyError" do - it "is an Exception" do - Net::FTPReplyError.should < Exception - end +ruby_version_is ""..."4.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 + it "is a subclass of Net::FTPError" do + Net::FTPPermError.should < Net::FTPError + end end end diff --git a/spec/ruby/library/net-ftp/FTPTempError_spec.rb b/spec/ruby/library/net-ftp/FTPTempError_spec.rb index f4b045dfb5..c0953cb0f2 100644 --- a/spec/ruby/library/net-ftp/FTPTempError_spec.rb +++ b/spec/ruby/library/net-ftp/FTPTempError_spec.rb @@ -1,12 +1,15 @@ require_relative '../../spec_helper' -require 'net/ftp' -describe "Net::FTPTempError" do - it "is an Exception" do - Net::FTPTempError.should < Exception - end +ruby_version_is ""..."4.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 + 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 index 335d056512..9e8be53c68 100644 --- a/spec/ruby/library/net-ftp/abort_spec.rb +++ b/spec/ruby/library/net-ftp/abort_spec.rb @@ -1,62 +1,65 @@ 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 +ruby_version_is ""..."4.1" do + require_relative 'spec_helper' + require_relative 'fixtures/server' - @ftp = Net::FTP.new - @ftp.connect(@server.hostname, @server.server_port) - end + describe "Net::FTP#abort" do + before :each do + @server = NetFTPSpecs::DummyFTP.new + @server.serve_once - after :each do - @ftp.quit rescue nil - @ftp.close - @server.stop - end + @ftp = Net::FTP.new + @ftp.connect(@server.hostname, @server.server_port) + end - it "sends the ABOR command to the server" do - -> { @ftp.abort }.should_not raise_error - end + after :each do + @ftp.quit rescue nil + @ftp.close + @server.stop + end - it "ignores the response" do - @ftp.abort - @ftp.last_response.should == "220 Dummy FTP Server ready!\n" - end + it "sends the ABOR command to the server" do + -> { @ftp.abort }.should_not.raise + end - it "returns the full response" do - @ftp.abort.should == "226 Closing data connection. (ABOR)\n" - end + it "ignores the response" do + @ftp.abort + @ftp.last_response.should == "220 Dummy FTP Server ready!\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 "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 226" do - @server.should_receive(:abor).and_respond("226 Closing data connection.") - -> { @ftp.abort }.should_not raise_error - 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 + 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 "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 + 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 500" do + @server.should_receive(:abor).and_respond("500 Syntax error, command unrecognized.") + -> { @ftp.abort }.should.raise(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 501" do + @server.should_receive(:abor).and_respond("501 Syntax error in parameters or arguments.") + -> { @ftp.abort }.should.raise(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(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) + 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(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 index ab093448a2..a64a0f48a8 100644 --- a/spec/ruby/library/net-ftp/acct_spec.rb +++ b/spec/ruby/library/net-ftp/acct_spec.rb @@ -1,58 +1,61 @@ 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) +ruby_version_is ""..."4.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 + 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(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(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(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(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(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 index 1e0585b795..de8d0ac103 100644 --- a/spec/ruby/library/net-ftp/binary_spec.rb +++ b/spec/ruby/library/net-ftp/binary_spec.rb @@ -1,24 +1,27 @@ 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 +ruby_version_is ""..."4.1" do + require_relative 'spec_helper' - ftp.binary = false - ftp.binary.should be_false + describe "Net::FTP#binary" do + it "returns true when self is in binary mode" do + ftp = Net::FTP.new + ftp.binary.should == true + + ftp.binary = false + ftp.binary.should == false + end end -end -describe "Net::FTP#binary=" do - it "sets self to binary mode when passed true" do - ftp = Net::FTP.new + 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 = true + ftp.binary.should == true - ftp.binary = false - ftp.binary.should be_false + ftp.binary = false + ftp.binary.should == false + end end end diff --git a/spec/ruby/library/net-ftp/chdir_spec.rb b/spec/ruby/library/net-ftp/chdir_spec.rb index cc129b5e42..f8f352158c 100644 --- a/spec/ruby/library/net-ftp/chdir_spec.rb +++ b/spec/ruby/library/net-ftp/chdir_spec.rb @@ -1,99 +1,102 @@ 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 +ruby_version_is ""..."4.1" do + require_relative 'spec_helper' + require_relative 'fixtures/server' - @ftp = Net::FTP.new - @ftp.connect(@server.hostname, @server.server_port) - end + describe "Net::FTP#chdir" do + before :each do + @server = NetFTPSpecs::DummyFTP.new + @server.serve_once - after :each do - @ftp.quit rescue nil - @ftp.close - @server.stop - end + @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 == 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(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(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(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(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(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(Net::FTPPermError) + end + 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" + 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("..").should be_nil + @ftp.chdir("test").should == 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) + 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(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) + @server.should_receive(:cwd).and_respond("501 Syntax error in parameters or arguments.") + -> { @ftp.chdir("test") }.should.raise(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) + @server.should_receive(:cwd).and_respond("502 Command not implemented.") + -> { @ftp.chdir("test") }.should.raise(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) + @server.should_receive(:cwd).and_respond("421 Service not available, closing control connection.") + -> { @ftp.chdir("test") }.should.raise(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) + @server.should_receive(:cwd).and_respond("530 Not logged in.") + -> { @ftp.chdir("test") }.should.raise(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) + @server.should_receive(:cwd).and_respond("550 Requested action not taken.") + -> { @ftp.chdir("test") }.should.raise(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 index 183f14a84b..9d5d4c638a 100644 --- a/spec/ruby/library/net-ftp/close_spec.rb +++ b/spec/ruby/library/net-ftp/close_spec.rb @@ -1,30 +1,33 @@ 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) +ruby_version_is ""..."4.1" do + require_relative 'spec_helper' - @ftp = Net::FTP.new - @ftp.instance_variable_set(:@sock, @socket) - end + 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) - it "closes the socket" do - @socket.should_receive(:close) - @ftp.close.should be_nil - end + @ftp = Net::FTP.new + @ftp.instance_variable_set(:@sock, @socket) + 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 "closes the socket" do + @socket.should_receive(:close) + @ftp.close.should == 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 == 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 + it "does not try to close the socket if it is nil" do + @ftp.instance_variable_set(:@sock, nil) + @ftp.close.should == nil + end end end diff --git a/spec/ruby/library/net-ftp/closed_spec.rb b/spec/ruby/library/net-ftp/closed_spec.rb index 84001cdc0f..1c8693932e 100644 --- a/spec/ruby/library/net-ftp/closed_spec.rb +++ b/spec/ruby/library/net-ftp/closed_spec.rb @@ -1,21 +1,24 @@ require_relative '../../spec_helper' -require_relative 'spec_helper' -describe "Net::FTP#closed?" do - before :each do - @socket = mock("Socket") +ruby_version_is ""..."4.1" do + require_relative 'spec_helper' - @ftp = Net::FTP.new - @ftp.instance_variable_set(:@sock, @socket) - end + describe "Net::FTP#closed?" do + before :each do + @socket = mock("Socket") - it "returns true when the socket is closed" do - @socket.should_receive(:closed?).and_return(true) - @ftp.closed?.should be_true - end + @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 == true + end - it "returns true when the socket is nil" do - @ftp.instance_variable_set(:@sock, nil) - @ftp.closed?.should be_true + it "returns true when the socket is nil" do + @ftp.instance_variable_set(:@sock, nil) + @ftp.closed?.should == true + end end end diff --git a/spec/ruby/library/net-ftp/connect_spec.rb b/spec/ruby/library/net-ftp/connect_spec.rb index e606b11e2a..597381f67c 100644 --- a/spec/ruby/library/net-ftp/connect_spec.rb +++ b/spec/ruby/library/net-ftp/connect_spec.rb @@ -1,43 +1,46 @@ 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) +ruby_version_is ""..."4.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 + end + + it "returns nil" do + @ftp.connect(@server.hostname, @server.server_port).should == 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 + 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(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(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 index f2ef53c089..28765b9d1c 100644 --- a/spec/ruby/library/net-ftp/debug_mode_spec.rb +++ b/spec/ruby/library/net-ftp/debug_mode_spec.rb @@ -1,23 +1,26 @@ 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 +ruby_version_is ""..."4.1" do + require_relative 'spec_helper' - ftp.debug_mode = true - ftp.debug_mode.should be_true + describe "Net::FTP#debug_mode" do + it "returns true when self is in debug mode" do + ftp = Net::FTP.new + ftp.debug_mode.should == false + + ftp.debug_mode = true + ftp.debug_mode.should == true + end 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 + 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 == true - ftp.debug_mode = false - ftp.debug_mode.should be_false + ftp.debug_mode = false + ftp.debug_mode.should == 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 index 3f14f6187e..b47b4e9782 100644 --- a/spec/ruby/library/net-ftp/default_passive_spec.rb +++ b/spec/ruby/library/net-ftp/default_passive_spec.rb @@ -1,8 +1,11 @@ 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" +ruby_version_is ""..."4.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 index bfb7da1ffe..40cd8f1d99 100644 --- a/spec/ruby/library/net-ftp/delete_spec.rb +++ b/spec/ruby/library/net-ftp/delete_spec.rb @@ -1,59 +1,62 @@ 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) +ruby_version_is ""..."4.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(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(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(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(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(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(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(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 index 894f03dd7b..af38724fad 100644 --- a/spec/ruby/library/net-ftp/dir_spec.rb +++ b/spec/ruby/library/net-ftp/dir_spec.rb @@ -1,8 +1,11 @@ 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 +ruby_version_is ""..."4.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/fixtures/server.rb b/spec/ruby/library/net-ftp/fixtures/server.rb index 8b34d3f8bd..9fc2beb57b 100644 --- a/spec/ruby/library/net-ftp/fixtures/server.rb +++ b/spec/ruby/library/net-ftp/fixtures/server.rb @@ -1,277 +1,279 @@ -module NetFTPSpecs - class DummyFTP - attr_accessor :connect_message - attr_reader :login_user, :login_pass, :login_acct - - # hostname or IP address - attr_reader :hostname - # port number - attr_reader :server_port - - def initialize - @hostname = "127.0.0.1" - @server = TCPServer.new(@hostname, 0) - @server_port = @server.addr[1] - - @handlers = {} - @commands = [] - @connect_message = nil - end +ruby_version_is ""..."4.1" do + module NetFTPSpecs + class DummyFTP + attr_accessor :connect_message + attr_reader :login_user, :login_pass, :login_acct + + # hostname or IP address + attr_reader :hostname + # port number + attr_reader :server_port + + def initialize + @hostname = "127.0.0.1" + @server = TCPServer.new(@hostname, 0) + @server_port = @server.addr[1] + + @handlers = {} + @commands = [] + @connect_message = nil + end - def serve_once - @thread = Thread.new do - @socket = @server.accept - @socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_OOBINLINE, 1) - begin - handle_request - ensure - @socket.close + def serve_once + @thread = Thread.new do + @socket = @server.accept + @socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_OOBINLINE, 1) + begin + handle_request + ensure + @socket.close + end end end - end - - def handle_request - # Send out the welcome message. - response @connect_message || "220 Dummy FTP Server ready!" - begin - while command = @socket.gets - command, argument = command.chomp.split(" ", 2) + def handle_request + # Send out the welcome message. + response @connect_message || "220 Dummy FTP Server ready!" - if command == "QUIT" - self.response("221 OK, bye") - break - elsif proc_handler = @handlers[command.downcase.to_sym] - if argument.nil? - proc_handler.call(self) - else - proc_handler.call(self, argument) - end - else - if argument.nil? - self.send(command.downcase.to_sym) + begin + while command = @socket.gets + command, argument = command.chomp.split(" ", 2) + + if command == "QUIT" + self.response("221 OK, bye") + break + elsif proc_handler = @handlers[command.downcase.to_sym] + if argument.nil? + proc_handler.call(self) + else + proc_handler.call(self, argument) + end else - self.send(command.downcase.to_sym, argument) + if argument.nil? + self.send(command.downcase.to_sym) + else + self.send(command.downcase.to_sym, argument) + end end end + rescue => e + self.error_response("Exception: #{e} #{e.backtrace.inspect}") end - rescue => e - self.error_response("Exception: #{e} #{e.backtrace.inspect}") end - end - def error_response(text) - self.response("451 #{text}") - end + def error_response(text) + self.response("451 #{text}") + end - def response(text) - @socket.puts(text) unless @socket.closed? - end + def response(text) + @socket.puts(text) unless @socket.closed? + end - def stop - @datasocket.close unless @datasocket.nil? || @datasocket.closed? - @server.close - @thread.join - end + def stop + @datasocket.close unless @datasocket.nil? || @datasocket.closed? + @server.close + @thread.join + end - ## - def handle(sym, &block) - @handlers[sym] = block - end + ## + def handle(sym, &block) + @handlers[sym] = block + end - def should_receive(method) - @handler_for = method - self - end + def should_receive(method) + @handler_for = method + self + end - def and_respond(text) - @handlers[@handler_for] = -> s, *args { s.response(text) } - end + def and_respond(text) + @handlers[@handler_for] = -> s, *args { s.response(text) } + end - ## - # FTP methods - ## + ## + # FTP methods + ## - def abor - self.response("226 Closing data connection. (ABOR)") - end + def abor + self.response("226 Closing data connection. (ABOR)") + end - def acct(account) - @login_acct = account - self.response("230 User '#{account}' logged in, proceed. (ACCT)") - end + def acct(account) + @login_acct = account + self.response("230 User '#{account}' logged in, proceed. (ACCT)") + end - def cdup - self.response("200 Command okay. (CDUP)") - end + def cdup + self.response("200 Command okay. (CDUP)") + end - def cwd(dir) - self.response("200 Command okay. (CWD #{dir})") - end + def cwd(dir) + self.response("200 Command okay. (CWD #{dir})") + end - def dele(file) - self.response("250 Requested file action okay, completed. (DELE #{file})") - end + def dele(file) + self.response("250 Requested file action okay, completed. (DELE #{file})") + end - def eprt(arg) - _, _, host, port = arg.split("|") + def eprt(arg) + _, _, host, port = arg.split("|") - @datasocket = TCPSocket.new(host, port) - self.response("200 port opened") - end + @datasocket = TCPSocket.new(host, port) + self.response("200 port opened") + end - def help(param = :default) - if param == :default - self.response("211 System status, or system help reply. (HELP)") - else - self.response("211 System status, or system help reply. (HELP #{param})") + def help(param = :default) + if param == :default + self.response("211 System status, or system help reply. (HELP)") + else + self.response("211 System status, or system help reply. (HELP #{param})") + end end - end - def list(folder) - self.response("150 opening ASCII connection for file list") - @datasocket.puts("-rw-r--r-- 1 spec staff 507 17 Jul 18:41 last_response_code.rb") - @datasocket.puts("-rw-r--r-- 1 spec staff 50 17 Jul 18:41 list.rb") - @datasocket.puts("-rw-r--r-- 1 spec staff 48 17 Jul 18:41 pwd.rb") - @datasocket.close() - self.response("226 transfer complete (LIST #{folder})") - end + def list(folder) + self.response("150 opening ASCII connection for file list") + @datasocket.puts("-rw-r--r-- 1 spec staff 507 17 Jul 18:41 last_response_code.rb") + @datasocket.puts("-rw-r--r-- 1 spec staff 50 17 Jul 18:41 list.rb") + @datasocket.puts("-rw-r--r-- 1 spec staff 48 17 Jul 18:41 pwd.rb") + @datasocket.close() + self.response("226 transfer complete (LIST #{folder})") + end - def mdtm(filename) - self.response("213 19980705132316") - end + def mdtm(filename) + self.response("213 19980705132316") + end - def mkd(foldername) - self.response(%Q{257 "#{foldername.gsub('"', '""')}" created.}) - end + def mkd(foldername) + self.response(%Q{257 "#{foldername.gsub('"', '""')}" created.}) + end - def nlst(folder = nil) - self.response("150 opening ASCII connection for file list") - @datasocket.puts("last_response_code.rb") - @datasocket.puts("list.rb") - @datasocket.puts("pwd.rb") - @datasocket.close() - self.response("226 transfer complete (NLST#{folder ? " #{folder}" : ""})") - end + def nlst(folder = nil) + self.response("150 opening ASCII connection for file list") + @datasocket.puts("last_response_code.rb") + @datasocket.puts("list.rb") + @datasocket.puts("pwd.rb") + @datasocket.close() + self.response("226 transfer complete (NLST#{folder ? " #{folder}" : ""})") + end - def noop - self.response("200 Command okay. (NOOP)") - end + def noop + self.response("200 Command okay. (NOOP)") + end - def pass(password) - @login_pass = password - self.response("230 User logged in, proceed. (PASS #{password})") - end + def pass(password) + @login_pass = password + self.response("230 User logged in, proceed. (PASS #{password})") + end - def port(arg) - nums = arg.split(",") + def port(arg) + nums = arg.split(",") + + if nums[0] == "::1" + # IPv6 + port = nums[1].to_i * 256 + nums[2].to_i + host = nums[0] + else + # IPv4 + port = nums[4].to_i * 256 + nums[5].to_i + host = nums[0..3].join(".") + end - if nums[0] == "::1" - # IPv6 - port = nums[1].to_i * 256 + nums[2].to_i - host = nums[0] - else - # IPv4 - port = nums[4].to_i * 256 + nums[5].to_i - host = nums[0..3].join(".") + @datasocket = TCPSocket.new(host, port) + self.response("200 port opened") end - @datasocket = TCPSocket.new(host, port) - self.response("200 port opened") - end - - def pwd - self.response('257 "/some/dir/" - current directory') - end + def pwd + self.response('257 "/some/dir/" - current directory') + end - def retr(file) - self.response("125 Data transfer starting") - if @restart_at && @restart_at == 20 - @datasocket.puts("of the file named '#{file}'.") - @restart_at = nil - else - @datasocket.puts("This is the content") - @datasocket.puts("of the file named '#{file}'.") - end - @datasocket.close() - self.response("226 Closing data connection. (RETR #{file})") - end + def retr(file) + self.response("125 Data transfer starting") + if @restart_at && @restart_at == 20 + @datasocket.puts("of the file named '#{file}'.") + @restart_at = nil + else + @datasocket.puts("This is the content") + @datasocket.puts("of the file named '#{file}'.") + end + @datasocket.close() + self.response("226 Closing data connection. (RETR #{file})") + end - def rest(at_bytes) - @restart_at = at_bytes.to_i - self.response("350 Requested file action pending further information. (REST)") - end + def rest(at_bytes) + @restart_at = at_bytes.to_i + self.response("350 Requested file action pending further information. (REST)") + end - def rmd(folder) - self.response("250 Requested file action okay, completed. (RMD #{folder})") - end + def rmd(folder) + self.response("250 Requested file action okay, completed. (RMD #{folder})") + end - def rnfr(from) - @rename_from = from - self.response("350 Requested file action pending further information.") - end + def rnfr(from) + @rename_from = from + self.response("350 Requested file action pending further information.") + end - def rnto(to) - self.response("250 Requested file action okay, completed. (Renamed #{@rename_from} to #{to})") - @rename_from = nil - end + def rnto(to) + self.response("250 Requested file action okay, completed. (Renamed #{@rename_from} to #{to})") + @rename_from = nil + end - def site(param) - self.response("200 Command okay. (SITE #{param})") - end + def site(param) + self.response("200 Command okay. (SITE #{param})") + end - def size(filename) - if filename == "binary" - self.response("213 24") - else - self.response("213 1024") + def size(filename) + if filename == "binary" + self.response("213 24") + else + self.response("213 1024") + end end - end - def stat(param = :default) - if param == :default - self.response("211 System status, or system help reply. (STAT)") - else - self.response("211 System status, or system help reply. (STAT #{param})") + def stat(param = :default) + if param == :default + self.response("211 System status, or system help reply. (STAT)") + else + self.response("211 System status, or system help reply. (STAT #{param})") + end end - end - def stor(file) - tmp_file = tmp("#{file}file", false) + def stor(file) + tmp_file = tmp("#{file}file", false) - self.response("125 Data transfer starting.") + self.response("125 Data transfer starting.") - mode = @restart_at ? "a" : "w" + mode = @restart_at ? "a" : "w" - File.open(tmp_file, mode + "b") do |f| - loop do - data = @datasocket.recv(1024) - break if !data || data.empty? - f << data + File.open(tmp_file, mode + "b") do |f| + loop do + data = @datasocket.recv(1024) + break if !data || data.empty? + f << data + end end - end - @datasocket.close() - self.response("200 OK, Data received. (STOR #{file})") - end + @datasocket.close() + self.response("200 OK, Data received. (STOR #{file})") + end - def appe(file) - @restart_at = true - stor(file) - end + def appe(file) + @restart_at = true + stor(file) + end - def syst - self.response("215 FTP Dummy Server (SYST)") - end + def syst + self.response("215 FTP Dummy Server (SYST)") + end - def type(type) - self.response("200 TYPE switched to #{type}") - end + def type(type) + self.response("200 TYPE switched to #{type}") + end - def user(name) - @login_user = name - self.response("230 User logged in, proceed. (USER #{name})") + def user(name) + @login_user = name + self.response("230 User logged in, proceed. (USER #{name})") + end end end end diff --git a/spec/ruby/library/net-ftp/get_spec.rb b/spec/ruby/library/net-ftp/get_spec.rb index 1bc1bd744b..6a8aa3e206 100644 --- a/spec/ruby/library/net-ftp/get_spec.rb +++ b/spec/ruby/library/net-ftp/get_spec.rb @@ -1,21 +1,24 @@ 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 +ruby_version_is ""..."4.1" do + require_relative 'spec_helper' + require_relative 'fixtures/server' + require_relative 'shared/gettextfile' + require_relative 'shared/getbinaryfile' - it_behaves_like :net_ftp_getbinaryfile, :get -end + describe "Net::FTP#get (binary mode)" do + before :each do + @binary_mode = true + end -describe "Net::FTP#get (text mode)" do - before :each do - @binary_mode = false + it_behaves_like :net_ftp_getbinaryfile, :get end - it_behaves_like :net_ftp_gettextfile, :get + 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 index e9898fccc7..6b2d38edf5 100644 --- a/spec/ruby/library/net-ftp/getbinaryfile_spec.rb +++ b/spec/ruby/library/net-ftp/getbinaryfile_spec.rb @@ -1,8 +1,11 @@ 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 +ruby_version_is ""..."4.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 index 756d6a23af..2ff62d399d 100644 --- a/spec/ruby/library/net-ftp/getdir_spec.rb +++ b/spec/ruby/library/net-ftp/getdir_spec.rb @@ -1,7 +1,10 @@ require_relative '../../spec_helper' -require_relative 'spec_helper' -require_relative 'shared/pwd' -describe "Net::FTP#getdir" do - it_behaves_like :net_ftp_pwd, :getdir +ruby_version_is ""..."4.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 index cdd1b4c797..3bb037663b 100644 --- a/spec/ruby/library/net-ftp/gettextfile_spec.rb +++ b/spec/ruby/library/net-ftp/gettextfile_spec.rb @@ -1,8 +1,11 @@ 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 +ruby_version_is ""..."4.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 index c562be50b2..bb52fb9e69 100644 --- a/spec/ruby/library/net-ftp/help_spec.rb +++ b/spec/ruby/library/net-ftp/help_spec.rb @@ -1,66 +1,69 @@ require_relative '../../spec_helper' -require_relative 'spec_helper' -require_relative 'fixtures/server' -describe "Net::FTP#help" do - def with_connection - yield - end +ruby_version_is ""..."4.1" do + require_relative 'spec_helper' + require_relative 'fixtures/server' - before :each do - @server = NetFTPSpecs::DummyFTP.new - @server.serve_once + describe "Net::FTP#help" do + def with_connection + yield + end - @ftp = Net::FTP.new - @ftp.connect(@server.hostname, @server.server_port) - end + before :each do + @server = NetFTPSpecs::DummyFTP.new + @server.serve_once - after :each do - @ftp.quit rescue nil - @ftp.close - @server.stop - end + @ftp = Net::FTP.new + @ftp.connect(@server.hostname, @server.server_port) + 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 + after :each do + @ftp.quit rescue nil + @ftp.close + @server.stop + 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 to the server" do + @ftp.help + @ftp.last_response.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 "returns the server's response" do + @ftp.help.should == "211 System status, or system help reply. (HELP)\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 "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 214" do - @server.should_receive(:help).and_respond("214 Help message.") - -> { @ftp.help }.should_not raise_error - 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 + 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 "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 + 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 500" do + @server.should_receive(:help).and_respond("500 Syntax error, command unrecognized.") + -> { @ftp.help }.should.raise(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::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(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(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) + 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(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 index 4d775e8dc1..9079ad6b79 100644 --- a/spec/ruby/library/net-ftp/initialize_spec.rb +++ b/spec/ruby/library/net-ftp/initialize_spec.rb @@ -1,402 +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 +ruby_version_is ""..."4.1" do + require_relative 'spec_helper' - 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 + describe "Net::FTP#initialize" do + before :each do + @ftp = Net::FTP.allocate + @ftp.stub!(:connect) + @port_args = [] + @port_args << 21 + 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 "is private" do + Net::FTP.private_instance_methods(false).should.include?(:initialize) + 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 + it "sets self into binary mode" do + @ftp.binary.should == nil + @ftp.send(:initialize) + @ftp.binary.should == true + end - describe "when passed no arguments" do - it "does not try to connect" do - @ftp.should_not_receive(:connect) + it "sets self into active mode" do + @ftp.passive.should == nil @ftp.send(:initialize) + @ftp.passive.should == false 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") + it "sets self into non-debug mode" do + @ftp.debug_mode.should == nil + @ftp.send(:initialize) + @ftp.debug_mode.should == false 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") + it "sets self to not resume file uploads/downloads" do + @ftp.resume.should == nil + @ftp.send(:initialize) + @ftp.resume.should == false end - it "tries to login with the passed username" do - @ftp.should_receive(:login).with("rubyspec", nil, nil) - @ftp.send(:initialize, "localhost", "rubyspec") + describe "when passed no arguments" do + it "does not try to connect" do + @ftp.should_not_receive(:connect) + @ftp.send(:initialize) + end 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") + 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 - 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") + 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 - 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") + 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 - 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") + 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 - end - before :each do - @ftp.stub!(:login) - 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) + 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) + @ftp.send(:initialize, 'localhost', options) + end 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) + 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') + @ftp.send(:initialize, 'localhost') + end 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) + 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 - 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) + 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) + @ftp.send(:initialize, 'localhost', options) + end 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') + 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) + @ftp.send(:initialize, 'localhost', options) + end 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) + 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) + @ftp.send(:initialize, 'localhost', options) + end 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) + 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) + @ftp.send(:initialize, 'localhost', options) + end end end end - end - describe 'is unset' do - it 'does not try to connect' do - @ftp.should_not_receive(:connect) + describe 'is unset' do + it 'does not try to connect' do + @ftp.should_not_receive(:connect) - @ftp.send(:initialize) - end + @ftp.send(:initialize) + end - it 'does not try to log in' do - @ftp.should_not_receive(:login) + it 'does not try to log in' do + @ftp.should_not_receive(:login) - @ftp.send(:initialize) + @ftp.send(:initialize) + end 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 }) + 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 + @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 'to false' do + describe 'is unset' 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.send(:initialize) @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 }) - 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 - @ftp.send(:initialize, nil, options) - @ftp.debug_mode.should == true + 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 'to false' do + describe 'is unset' 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.send(:initialize) @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 }) + 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 + @ftp.send(:initialize, nil, options) + @ftp.open_timeout.should == 42 + end end - end - describe 'is not set' do - it 'sets open_timeout to nil' do - @ftp.send(:initialize) - @ftp.open_timeout.should == nil + describe 'is not set' do + it 'sets open_timeout to nil' do + @ftp.send(:initialize) + @ftp.open_timeout.should == nil + end 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 }) + 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 + @ftp.send(:initialize, nil, options) + @ftp.read_timeout.should == 100 + end end - end - describe 'is not set' do - it 'sets read_timeout to the default value' do - @ftp.send(:initialize) - @ftp.read_timeout.should == 60 + 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 - 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 }) + 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 + @ftp.send(:initialize, nil, options) + @ftp.ssl_handshake_timeout.should == 23 + end end - end - describe 'is not set' do - it 'sets ssl_handshake_timeout to nil' do - @ftp.send(:initialize) - @ftp.ssl_handshake_timeout.should == nil + 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 - 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 }) + 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) + 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({}) + 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 + @ftp.send(:initialize, nil, options) + @ftp.instance_variable_get(:@ssl_context).should == ssl_context + end 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'} }) + 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) + 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'}) + 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 + @ftp.send(:initialize, nil, options) + @ftp.instance_variable_get(:@ssl_context).should == ssl_context + end 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' }) + 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' + @ftp.send(:initialize, nil, options) + @ftp.instance_variable_get(:@private_data_connection).should == 'true' + end 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 }) + 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 + @ftp.send(:initialize, nil, options) + @ftp.instance_variable_get(:@private_data_connection).should == true + end 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({}) + 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 + @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 }) + 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/) + -> { + @ftp.send(:initialize, nil, options) + }.should.raise(ArgumentError, /private_data_connection can be set to true only when ssl is enabled/) + end 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({}) + 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 + @ftp.send(:initialize, nil, options) + @ftp.instance_variable_get(:@private_data_connection).should == false + 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 index c17c28f0f8..03329758b5 100644 --- a/spec/ruby/library/net-ftp/last_response_code_spec.rb +++ b/spec/ruby/library/net-ftp/last_response_code_spec.rb @@ -1,8 +1,11 @@ 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 +ruby_version_is ""..."4.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 index c9d9d70f35..7cda9fa7a4 100644 --- a/spec/ruby/library/net-ftp/last_response_spec.rb +++ b/spec/ruby/library/net-ftp/last_response_spec.rb @@ -1,25 +1,28 @@ 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 +ruby_version_is ""..."4.1" do + require_relative 'spec_helper' + require_relative 'fixtures/server' - @ftp = Net::FTP.new - @ftp.connect(@server.hostname, @server.server_port) - end + describe "Net::FTP#last_response" do + before :each do + @server = NetFTPSpecs::DummyFTP.new + @server.serve_once - after :each do - @ftp.quit rescue nil - @ftp.close - @server.stop - end + @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" + 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 index e0c1b862a0..c373670ec4 100644 --- a/spec/ruby/library/net-ftp/lastresp_spec.rb +++ b/spec/ruby/library/net-ftp/lastresp_spec.rb @@ -1,8 +1,11 @@ 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 +ruby_version_is ""..."4.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 index 6cb1bbc4b8..297d100dd9 100644 --- a/spec/ruby/library/net-ftp/list_spec.rb +++ b/spec/ruby/library/net-ftp/list_spec.rb @@ -1,8 +1,11 @@ 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 +ruby_version_is ""..."4.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 index 0de2f5cc63..05bb6b7f81 100644 --- a/spec/ruby/library/net-ftp/login_spec.rb +++ b/spec/ruby/library/net-ftp/login_spec.rb @@ -1,195 +1,198 @@ 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 +ruby_version_is ""..."4.1" do + require_relative 'spec_helper' + require_relative 'fixtures/server' - @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 + describe "Net::FTP#login" 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) + @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(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(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(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(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(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(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(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(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(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 + 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(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(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(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(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(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 + 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(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(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(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(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(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 index acd7e9e523..f8fdb10e8f 100644 --- a/spec/ruby/library/net-ftp/ls_spec.rb +++ b/spec/ruby/library/net-ftp/ls_spec.rb @@ -1,8 +1,11 @@ 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 +ruby_version_is ""..."4.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 index a504507c84..effd22a6e4 100644 --- a/spec/ruby/library/net-ftp/mdtm_spec.rb +++ b/spec/ruby/library/net-ftp/mdtm_spec.rb @@ -1,38 +1,41 @@ 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 +ruby_version_is ""..."4.1" do + require_relative 'spec_helper' + require_relative 'fixtures/server' - @ftp = Net::FTP.new - @ftp.connect(@server.hostname, @server.server_port) - end + describe "Net::FTP#mdtm" do + before :each do + @server = NetFTPSpecs::DummyFTP.new + @server.serve_once - after :each do - @ftp.quit rescue nil - @ftp.close - @server.stop - end + @ftp = Net::FTP.new + @ftp.connect(@server.hostname, @server.server_port) + 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 + after :each do + @ftp.quit rescue nil + @ftp.close + @server.stop + end - it "returns the last modification time of the passed file" do - @ftp.mdtm("test.file").should == "19980705132316" - 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 "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 "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(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) + 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(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 index 8cc6ae785e..6daeb7c022 100644 --- a/spec/ruby/library/net-ftp/mkdir_spec.rb +++ b/spec/ruby/library/net-ftp/mkdir_spec.rb @@ -1,61 +1,64 @@ 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 +ruby_version_is ""..."4.1" do + require_relative 'spec_helper' + require_relative 'fixtures/server' - @ftp = Net::FTP.new - @ftp.connect(@server.hostname, @server.server_port) - end + describe "Net::FTP#mkdir" do + before :each do + @server = NetFTPSpecs::DummyFTP.new + @server.serve_once - after :each do - @ftp.quit rescue nil - @ftp.close - @server.stop - end + @ftp = Net::FTP.new + @ftp.connect(@server.hostname, @server.server_port) + 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 + after :each do + @ftp.quit rescue nil + @ftp.close + @server.stop + 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 "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 "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 "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 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 500" do + @server.should_receive(:mkd).and_respond("500 Syntax error, command unrecognized.") + -> { @ftp.mkdir("test.folder") }.should.raise(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::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(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 502" do + @server.should_receive(:mkd).and_respond("502 Command not implemented.") + -> { @ftp.mkdir("test.folder") }.should.raise(Net::FTPPermError) + 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::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(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(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) + 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(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 index 9dde1278a8..694036a296 100644 --- a/spec/ruby/library/net-ftp/mtime_spec.rb +++ b/spec/ruby/library/net-ftp/mtime_spec.rb @@ -1,50 +1,53 @@ 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 +ruby_version_is ""..."4.1" do + require_relative 'spec_helper' + require_relative 'fixtures/server' - @ftp = Net::FTP.new - @ftp.connect(@server.hostname, @server.server_port) - end + describe "Net::FTP#mtime" do + before :each do + @server = NetFTPSpecs::DummyFTP.new + @server.serve_once - after :each do - @ftp.quit rescue nil - @ftp.close - @server.stop - end + @ftp = Net::FTP.new + @ftp.connect(@server.hostname, @server.server_port) + 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 + after :each do + @ftp.quit rescue nil + @ftp.close + @server.stop + 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") + 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 - 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") + 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 - 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") + 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 - 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::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(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) + 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(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 index 2f22543af6..87b80b43fd 100644 --- a/spec/ruby/library/net-ftp/nlst_spec.rb +++ b/spec/ruby/library/net-ftp/nlst_spec.rb @@ -1,92 +1,95 @@ 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 +ruby_version_is ""..."4.1" do + require_relative 'spec_helper' + require_relative 'fixtures/server' - @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 "Net::FTP#nlst" do + before :each do + @server = NetFTPSpecs::DummyFTP.new + @server.serve_once - 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" + @ftp = Net::FTP.new + @ftp.passive = false + @ftp.connect(@server.hostname, @server.server_port) 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" + after :each do + @ftp.quit rescue nil + @ftp.close + @server.stop 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) + 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 - 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) + 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 - 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 + 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(Net::FTPTempError) + 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::FTPPermError when the response code is 500" do + @server.should_receive(:nlst).and_respond("500 Syntax error, command unrecognized.") + -> { @ftp.nlst }.should.raise(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 501" do + @server.should_receive(:nlst).and_respond("501 Syntax error, command unrecognized.") + -> { @ftp.nlst }.should.raise(Net::FTPPermError) + 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 + 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(Net::FTPPermError) + 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::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(Net::FTPTempError) + 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) + 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(Net::FTPPermError) + end 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 + 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(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(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(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) + 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(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 index 4743a39ef6..43c48e355a 100644 --- a/spec/ruby/library/net-ftp/noop_spec.rb +++ b/spec/ruby/library/net-ftp/noop_spec.rb @@ -1,38 +1,41 @@ 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 +ruby_version_is ""..."4.1" do + require_relative 'spec_helper' + require_relative 'fixtures/server' - @ftp = Net::FTP.new - @ftp.connect(@server.hostname, @server.server_port) - end + describe "Net::FTP#noop" do + before :each do + @server = NetFTPSpecs::DummyFTP.new + @server.serve_once - after :each do - @ftp.quit rescue nil - @ftp.close - @server.stop - end + @ftp = Net::FTP.new + @ftp.connect(@server.hostname, @server.server_port) + end - it "sends the NOOP command to the server" do - @ftp.noop - @ftp.last_response.should == "200 Command okay. (NOOP)\n" - end + after :each do + @ftp.quit rescue nil + @ftp.close + @server.stop + end - it "returns nil" do - @ftp.noop.should be_nil - end + it "sends the NOOP command to the server" do + @ftp.noop + @ftp.last_response.should == "200 Command okay. (NOOP)\n" + 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 "returns nil" do + @ftp.noop.should == 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(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) + 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(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 index e59496dc3c..2d6477ec4d 100644 --- a/spec/ruby/library/net-ftp/open_spec.rb +++ b/spec/ruby/library/net-ftp/open_spec.rb @@ -1,55 +1,58 @@ 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 +ruby_version_is ""..."4.1" do + require_relative 'spec_helper' - describe "when passed no block" do - it "returns a new Net::FTP instance" do - Net::FTP.open("localhost").should equal(@ftp) + describe "Net::FTP.open" do + before :each do + @ftp = mock("Net::FTP instance") + Net::FTP.stub!(:new).and_return(@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 no block" do + it "returns a new Net::FTP instance" do + Net::FTP.open("localhost").should.equal?(@ftp) + end - describe "when passed a block" do - before :each do - @ftp.stub!(:close) + 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 - 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) + describe "when passed a block" do + before :each do + @ftp.stub!(:close) 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) + 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 == true end - end - it "closes the Net::FTP instance even if an exception is raised while yielding" do - begin + it "closes the Net::FTP instance after yielding" do 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 + 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 index 97659f1b68..6acabd3f98 100644 --- a/spec/ruby/library/net-ftp/passive_spec.rb +++ b/spec/ruby/library/net-ftp/passive_spec.rb @@ -1,28 +1,31 @@ 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 +ruby_version_is ""..."4.1" do + require_relative 'spec_helper' - ftp.passive = true - ftp.passive.should be_true - end + describe "Net::FTP#passive" do + it "returns true when self is in passive mode" do + ftp = Net::FTP.new + ftp.passive.should == false + + ftp.passive = true + ftp.passive.should == true + end - it "is the value of Net::FTP.default_value by default" do - ruby_exe(fixture(__FILE__, "passive.rb")).should == "true" + it "is the value of Net::FTP.default_value by default" do + ruby_exe(fixture(__FILE__, "passive.rb")).should == "true" + end end -end -describe "Net::FTP#passive=" do - it "sets self to passive mode when passed true" do - ftp = Net::FTP.new + 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 = true + ftp.passive.should == true - ftp.passive = false - ftp.passive.should be_false + ftp.passive = false + ftp.passive.should == false + end end end diff --git a/spec/ruby/library/net-ftp/put_spec.rb b/spec/ruby/library/net-ftp/put_spec.rb index 6d40d3d5b9..603409e283 100644 --- a/spec/ruby/library/net-ftp/put_spec.rb +++ b/spec/ruby/library/net-ftp/put_spec.rb @@ -1,21 +1,24 @@ 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 +ruby_version_is ""..."4.1" do + require_relative 'spec_helper' + require_relative 'fixtures/server' + require_relative 'shared/puttextfile' + require_relative 'shared/putbinaryfile' - it_behaves_like :net_ftp_putbinaryfile, :put -end + describe "Net::FTP#put (binary mode)" do + before :each do + @binary_mode = true + end -describe "Net::FTP#put (text mode)" do - before :each do - @binary_mode = false + it_behaves_like :net_ftp_putbinaryfile, :put end - it_behaves_like :net_ftp_puttextfile, :put + 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 index d0398229e5..ce8a6f0473 100644 --- a/spec/ruby/library/net-ftp/putbinaryfile_spec.rb +++ b/spec/ruby/library/net-ftp/putbinaryfile_spec.rb @@ -1,8 +1,11 @@ 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 +ruby_version_is ""..."4.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 index b8bcac33df..b4ab86aab1 100644 --- a/spec/ruby/library/net-ftp/puttextfile_spec.rb +++ b/spec/ruby/library/net-ftp/puttextfile_spec.rb @@ -1,8 +1,11 @@ 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 +ruby_version_is ""..."4.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 index 992e2c4ed2..53692b553f 100644 --- a/spec/ruby/library/net-ftp/pwd_spec.rb +++ b/spec/ruby/library/net-ftp/pwd_spec.rb @@ -1,53 +1,56 @@ 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) +ruby_version_is ""..."4.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(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(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(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(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(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 index c5352ceada..1af0107d34 100644 --- a/spec/ruby/library/net-ftp/quit_spec.rb +++ b/spec/ruby/library/net-ftp/quit_spec.rb @@ -1,33 +1,36 @@ 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 +ruby_version_is ""..."4.1" do + require_relative 'spec_helper' + require_relative 'fixtures/server' - @ftp = Net::FTP.new - @ftp.connect(@server.hostname, @server.server_port) - end + describe "Net::FTP#quit" do + before :each do + @server = NetFTPSpecs::DummyFTP.new + @server.serve_once - after :each do - @ftp.quit rescue nil - @ftp.close - @server.stop - end + @ftp = Net::FTP.new + @ftp.connect(@server.hostname, @server.server_port) + end - it "sends the QUIT command to the server" do - @ftp.quit - @ftp.last_response.should == "221 OK, bye\n" - end + after :each do + @ftp.quit rescue nil + @ftp.close + @server.stop + end - it "does not close the socket automatically" do - @ftp.quit - @ftp.closed?.should be_false - 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 == false + end - it "returns nil" do - @ftp.quit.should be_nil + it "returns nil" do + @ftp.quit.should == nil + end end end diff --git a/spec/ruby/library/net-ftp/rename_spec.rb b/spec/ruby/library/net-ftp/rename_spec.rb index 48f81b7deb..6541fe5301 100644 --- a/spec/ruby/library/net-ftp/rename_spec.rb +++ b/spec/ruby/library/net-ftp/rename_spec.rb @@ -1,94 +1,97 @@ 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 +ruby_version_is ""..."4.1" do + require_relative 'spec_helper' + require_relative 'fixtures/server' - @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 + describe "Net::FTP#rename" do + before :each do + @server = NetFTPSpecs::DummyFTP.new + @server.serve_once - 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) + @ftp = Net::FTP.new + @ftp.connect(@server.hostname, @server.server_port) 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) + after :each do + @ftp.quit rescue nil + @ftp.close + @server.stop 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 + 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 "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) + it "returns something" do + @ftp.rename("from.file", "to.file").should == nil + end 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) + 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(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(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(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(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(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(Net::FTPPermError) + end 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) + 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(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(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(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(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(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(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 index 6592fc5bb0..5ec565d155 100644 --- a/spec/ruby/library/net-ftp/resume_spec.rb +++ b/spec/ruby/library/net-ftp/resume_spec.rb @@ -1,23 +1,26 @@ 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 +ruby_version_is ""..."4.1" do + require_relative 'spec_helper' - ftp.resume = true - ftp.resume.should be_true + describe "Net::FTP#resume" do + it "returns true when self is set to resume uploads/downloads" do + ftp = Net::FTP.new + ftp.resume.should == false + + ftp.resume = true + ftp.resume.should == true + end 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 + 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 == true - ftp.resume = false - ftp.resume.should be_false + ftp.resume = false + ftp.resume.should == false + end end end diff --git a/spec/ruby/library/net-ftp/retrbinary_spec.rb b/spec/ruby/library/net-ftp/retrbinary_spec.rb index de024208aa..ff8c8098a4 100644 --- a/spec/ruby/library/net-ftp/retrbinary_spec.rb +++ b/spec/ruby/library/net-ftp/retrbinary_spec.rb @@ -1,30 +1,33 @@ 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 +ruby_version_is ""..."4.1" do + require_relative 'spec_helper' + require_relative 'fixtures/server' - @ftp = Net::FTP.new - @ftp.connect(@server.hostname, @server.server_port) - end + describe "Net::FTP#retrbinary" do + before :each do + @server = NetFTPSpecs::DummyFTP.new + @server.serve_once - after :each do - @ftp.quit rescue nil - @ftp.close - @server.stop - end + @ftp = Net::FTP.new + @ftp.connect(@server.hostname, @server.server_port) + 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 + 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" ] + 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 index 866ecb5f40..2963da14f7 100644 --- a/spec/ruby/library/net-ftp/retrlines_spec.rb +++ b/spec/ruby/library/net-ftp/retrlines_spec.rb @@ -1,34 +1,37 @@ 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 +ruby_version_is ""..."4.1" do + require_relative 'spec_helper' + require_relative 'fixtures/server' - @ftp = Net::FTP.new - @ftp.connect(@server.hostname, @server.server_port) - end + describe "Net::FTP#retrlines" do + before :each do + @server = NetFTPSpecs::DummyFTP.new + @server.serve_once - after :each do - @ftp.quit rescue nil - @ftp.close - @server.stop - end + @ftp = Net::FTP.new + @ftp.connect(@server.hostname, @server.server_port) + 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 + 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" - ] + 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 index 35a6232f7e..fcf5a32aa7 100644 --- a/spec/ruby/library/net-ftp/return_code_spec.rb +++ b/spec/ruby/library/net-ftp/return_code_spec.rb @@ -1,24 +1,27 @@ require_relative '../../spec_helper' -require_relative 'spec_helper' -describe "Net::FTP#return_code" do - before :each do - @ftp = Net::FTP.new - end +ruby_version_is ""..."4.1" do + require_relative 'spec_helper' - 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 -describe "Net::FTP#return_code=" do - before :each do - @ftp = Net::FTP.new + 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 - it "outputs a warning" do - -> { @ftp.return_code = 123 }.should complain(/warning: Net::FTP#return_code= is obsolete and do nothing/) + 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 index 400874d60d..23650ebcc8 100644 --- a/spec/ruby/library/net-ftp/rmdir_spec.rb +++ b/spec/ruby/library/net-ftp/rmdir_spec.rb @@ -1,58 +1,61 @@ 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) +ruby_version_is ""..."4.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 == 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(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(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(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(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(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(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 index c50b373869..67dbd3bdb8 100644 --- a/spec/ruby/library/net-ftp/sendcmd_spec.rb +++ b/spec/ruby/library/net-ftp/sendcmd_spec.rb @@ -1,54 +1,57 @@ 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) +ruby_version_is ""..."4.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 + + @server.should_receive(:help).and_respond("200 Command okay.") + -> { @ftp.sendcmd("HELP") }.should_not.raise + + @server.should_receive(:help).and_respond("350 Requested file action pending further information.") + -> { @ftp.sendcmd("HELP") }.should_not.raise + 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(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(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(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 index 8182dd8b33..ad83dfcc4f 100644 --- a/spec/ruby/library/net-ftp/set_socket_spec.rb +++ b/spec/ruby/library/net-ftp/set_socket_spec.rb @@ -1,8 +1,11 @@ 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" +ruby_version_is ""..."4.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/shared/getbinaryfile.rb b/spec/ruby/library/net-ftp/shared/getbinaryfile.rb index ceec8e7cd5..4fc4731c45 100644 --- a/spec/ruby/library/net-ftp/shared/getbinaryfile.rb +++ b/spec/ruby/library/net-ftp/shared/getbinaryfile.rb @@ -1,150 +1,152 @@ -describe :net_ftp_getbinaryfile, shared: true do - before :each do - @fixture_file = __dir__ + "/../fixtures/getbinaryfile" - @tmp_file = tmp("getbinaryfile") +ruby_version_is ""..."4.1" do + describe :net_ftp_getbinaryfile, shared: true do + before :each do + @fixture_file = __dir__ + "/../fixtures/getbinaryfile" + @tmp_file = tmp("getbinaryfile") - @server = NetFTPSpecs::DummyFTP.new - @server.serve_once + @server = NetFTPSpecs::DummyFTP.new + @server.serve_once - @ftp = Net::FTP.new - @ftp.connect(@server.hostname, @server.server_port) - @ftp.binary = @binary_mode - end + @ftp = Net::FTP.new + @ftp.connect(@server.hostname, @server.server_port) + @ftp.binary = @binary_mode + end - after :each do - @ftp.quit rescue nil - @ftp.close - @server.stop + after :each do + @ftp.quit rescue nil + @ftp.close + @server.stop - rm_r @tmp_file - end + rm_r @tmp_file + end - it "sends the RETR command to the server" do - @ftp.send(@method, "test", @tmp_file) - @ftp.last_response.should == "226 Closing data connection. (RETR test)\n" - end + it "sends the RETR command to the server" do + @ftp.send(@method, "test", @tmp_file) + @ftp.last_response.should == "226 Closing data connection. (RETR test)\n" + end - it "returns nil" do - @ftp.send(@method, "test", @tmp_file).should be_nil - end + it "returns nil" do + @ftp.send(@method, "test", @tmp_file).should == nil + end - it "saves the contents of the passed remote file to the passed local file" do - @ftp.send(@method, "test", @tmp_file) - File.read(@tmp_file).should == "This is the content\nof the file named 'test'.\n" - end + it "saves the contents of the passed remote file to the passed local file" do + @ftp.send(@method, "test", @tmp_file) + File.read(@tmp_file).should == "This is the content\nof the file named 'test'.\n" + end - describe "when passed a block" do - it "yields the received content as binary blocks of the passed size" do - res = [] - @ftp.send(@method, "test", @tmp_file, 10) { |bin| res << bin } - res.should == [ "This is th", "e content\n", "of the fil", "e named 't", "est'.\n" ] + describe "when passed a block" do + it "yields the received content as binary blocks of the passed size" do + res = [] + @ftp.send(@method, "test", @tmp_file, 10) { |bin| res << bin } + res.should == [ "This is th", "e content\n", "of the fil", "e named 't", "est'.\n" ] + end end - end - describe "when resuming an existing file" do - before :each do - @tmp_file = tmp("getbinaryfile_resume") + describe "when resuming an existing file" do + before :each do + @tmp_file = tmp("getbinaryfile_resume") - File.open(@tmp_file, "wb") do |f| - f << "This is the content\n" + File.open(@tmp_file, "wb") do |f| + f << "This is the content\n" + end + + @ftp.resume = true end - @ftp.resume = true - end + it "saves the remaining content of the passed remote file to the passed local file" do + @ftp.send(@method, "test", @tmp_file) + File.read(@tmp_file).should == "This is the content\nof the file named 'test'.\n" + end - it "saves the remaining content of the passed remote file to the passed local file" do - @ftp.send(@method, "test", @tmp_file) - File.read(@tmp_file).should == "This is the content\nof the file named 'test'.\n" + describe "and the REST command fails" do + it "raises a Net::FTPProtoError when the response code is 550" do + @server.should_receive(:rest).and_respond("Requested action not taken.") + -> { @ftp.send(@method, "test", @tmp_file) }.should.raise(Net::FTPProtoError) + end + + it "raises a Net::FTPPermError when the response code is 500" do + @server.should_receive(:rest).and_respond("500 Syntax error, command unrecognized.") + -> { @ftp.send(@method, "test", @tmp_file) }.should.raise(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 501" do + @server.should_receive(:rest).and_respond("501 Syntax error, command unrecognized.") + -> { @ftp.send(@method, "test", @tmp_file) }.should.raise(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 502" do + @server.should_receive(:rest).and_respond("502 Command not implemented.") + -> { @ftp.send(@method, "test", @tmp_file) }.should.raise(Net::FTPPermError) + end + + it "raises a Net::FTPTempError when the response code is 421" do + @server.should_receive(:rest).and_respond("421 Service not available, closing control connection.") + -> { @ftp.send(@method, "test", @tmp_file) }.should.raise(Net::FTPTempError) + end + + it "raises a Net::FTPPermError when the response code is 530" do + @server.should_receive(:rest).and_respond("530 Not logged in.") + -> { @ftp.send(@method, "test", @tmp_file) }.should.raise(Net::FTPPermError) + end + end end - describe "and the REST command fails" do + describe "when the RETR command fails" do + it "raises a Net::FTPTempError when the response code is 450" do + @server.should_receive(:retr).and_respond("450 Requested file action not taken.") + -> { @ftp.send(@method, "test", @tmp_file) }.should.raise(Net::FTPTempError) + end + it "raises a Net::FTPProtoError when the response code is 550" do - @server.should_receive(:rest).and_respond("Requested action not taken.") - -> { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPProtoError) + @server.should_receive(:retr).and_respond("Requested action not taken.") + -> { @ftp.send(@method, "test", @tmp_file) }.should.raise(Net::FTPProtoError) end it "raises a Net::FTPPermError when the response code is 500" do - @server.should_receive(:rest).and_respond("500 Syntax error, command unrecognized.") - -> { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError) + @server.should_receive(:retr).and_respond("500 Syntax error, command unrecognized.") + -> { @ftp.send(@method, "test", @tmp_file) }.should.raise(Net::FTPPermError) end it "raises a Net::FTPPermError when the response code is 501" do - @server.should_receive(:rest).and_respond("501 Syntax error, command unrecognized.") - -> { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPPermError when the response code is 502" do - @server.should_receive(:rest).and_respond("502 Command not implemented.") - -> { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError) + @server.should_receive(:retr).and_respond("501 Syntax error, command unrecognized.") + -> { @ftp.send(@method, "test", @tmp_file) }.should.raise(Net::FTPPermError) end it "raises a Net::FTPTempError when the response code is 421" do - @server.should_receive(:rest).and_respond("421 Service not available, closing control connection.") - -> { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPTempError) + @server.should_receive(:retr).and_respond("421 Service not available, closing control connection.") + -> { @ftp.send(@method, "test", @tmp_file) }.should.raise(Net::FTPTempError) end it "raises a Net::FTPPermError when the response code is 530" do - @server.should_receive(:rest).and_respond("530 Not logged in.") - -> { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError) + @server.should_receive(:retr).and_respond("530 Not logged in.") + -> { @ftp.send(@method, "test", @tmp_file) }.should.raise(Net::FTPPermError) end end - end - - describe "when the RETR command fails" do - it "raises a Net::FTPTempError when the response code is 450" do - @server.should_receive(:retr).and_respond("450 Requested file action not taken.") - -> { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPTempError) - end - - it "raises a Net::FTPProtoError when the response code is 550" do - @server.should_receive(:retr).and_respond("Requested action not taken.") - -> { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPProtoError) - end - - it "raises a Net::FTPPermError when the response code is 500" do - @server.should_receive(:retr).and_respond("500 Syntax error, command unrecognized.") - -> { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPPermError when the response code is 501" do - @server.should_receive(:retr).and_respond("501 Syntax error, command unrecognized.") - -> { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPTempError when the response code is 421" do - @server.should_receive(:retr).and_respond("421 Service not available, closing control connection.") - -> { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPTempError) - end - - it "raises a Net::FTPPermError when the response code is 530" do - @server.should_receive(:retr).and_respond("530 Not logged in.") - -> { @ftp.send(@method, "test", @tmp_file) }.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.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError) - 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.send(@method, "test", @tmp_file) }.should.raise(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.send(@method, "test", @tmp_file) }.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.send(@method, "test", @tmp_file) }.should.raise(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.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPTempError) - 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.send(@method, "test", @tmp_file) }.should.raise(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.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError) + 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.send(@method, "test", @tmp_file) }.should.raise(Net::FTPPermError) + end end end end diff --git a/spec/ruby/library/net-ftp/shared/gettextfile.rb b/spec/ruby/library/net-ftp/shared/gettextfile.rb index 7fe14f7dfb..562c7a3047 100644 --- a/spec/ruby/library/net-ftp/shared/gettextfile.rb +++ b/spec/ruby/library/net-ftp/shared/gettextfile.rb @@ -1,100 +1,102 @@ -describe :net_ftp_gettextfile, shared: true do - before :each do - @tmp_file = tmp("gettextfile") +ruby_version_is ""..."4.1" do + describe :net_ftp_gettextfile, shared: true do + before :each do + @tmp_file = tmp("gettextfile") - @server = NetFTPSpecs::DummyFTP.new - @server.serve_once + @server = NetFTPSpecs::DummyFTP.new + @server.serve_once - @ftp = Net::FTP.new - @ftp.connect(@server.hostname, @server.server_port) - @ftp.binary = @binary_mode - end - - after :each do - @ftp.quit rescue nil - @ftp.close - @server.stop - - rm_r @tmp_file - end - - it "sends the RETR command to the server" do - @ftp.send(@method, "test", @tmp_file) - @ftp.last_response.should == "226 Closing data connection. (RETR test)\n" - end - - it "returns nil" do - @ftp.send(@method, "test", @tmp_file).should be_nil - end - - it "saves the contents of the passed remote file to the passed local file" do - @ftp.send(@method, "test", @tmp_file) - File.read(@tmp_file).should == "This is the content\nof the file named 'test'.\n" - end - - describe "when passed a block" do - it "yields each line of the retrieved file to the passed block" do - res = [] - @ftp.send(@method, "test", @tmp_file) { |line| res << line } - res.should == [ "This is the content", "of the file named 'test'."] + @ftp = Net::FTP.new + @ftp.connect(@server.hostname, @server.server_port) + @ftp.binary = @binary_mode end - end - describe "when the RETR command fails" do - it "raises a Net::FTPTempError when the response code is 450" do - @server.should_receive(:retr).and_respond("450 Requested file action not taken.") - -> { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPTempError) - end + after :each do + @ftp.quit rescue nil + @ftp.close + @server.stop - it "raises a Net::FTPProtoError when the response code is 550" do - @server.should_receive(:retr).and_respond("Requested action not taken.") - -> { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPProtoError) + rm_r @tmp_file end - it "raises a Net::FTPPermError when the response code is 500" do - @server.should_receive(:retr).and_respond("500 Syntax error, command unrecognized.") - -> { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError) + it "sends the RETR command to the server" do + @ftp.send(@method, "test", @tmp_file) + @ftp.last_response.should == "226 Closing data connection. (RETR test)\n" end - it "raises a Net::FTPPermError when the response code is 501" do - @server.should_receive(:retr).and_respond("501 Syntax error, command unrecognized.") - -> { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError) + it "returns nil" do + @ftp.send(@method, "test", @tmp_file).should == nil end - it "raises a Net::FTPTempError when the response code is 421" do - @server.should_receive(:retr).and_respond("421 Service not available, closing control connection.") - -> { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPTempError) - end - - it "raises a Net::FTPPermError when the response code is 530" do - @server.should_receive(:retr).and_respond("530 Not logged in.") - -> { @ftp.send(@method, "test", @tmp_file) }.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.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError) + it "saves the contents of the passed remote file to the passed local file" do + @ftp.send(@method, "test", @tmp_file) + File.read(@tmp_file).should == "This is the content\nof the file named 'test'.\n" 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.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError) + describe "when passed a block" do + it "yields each line of the retrieved file to the passed block" do + res = [] + @ftp.send(@method, "test", @tmp_file) { |line| res << line } + res.should == [ "This is the content", "of the file named 'test'."] + end 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.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPTempError) + describe "when the RETR command fails" do + it "raises a Net::FTPTempError when the response code is 450" do + @server.should_receive(:retr).and_respond("450 Requested file action not taken.") + -> { @ftp.send(@method, "test", @tmp_file) }.should.raise(Net::FTPTempError) + end + + it "raises a Net::FTPProtoError when the response code is 550" do + @server.should_receive(:retr).and_respond("Requested action not taken.") + -> { @ftp.send(@method, "test", @tmp_file) }.should.raise(Net::FTPProtoError) + end + + it "raises a Net::FTPPermError when the response code is 500" do + @server.should_receive(:retr).and_respond("500 Syntax error, command unrecognized.") + -> { @ftp.send(@method, "test", @tmp_file) }.should.raise(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 501" do + @server.should_receive(:retr).and_respond("501 Syntax error, command unrecognized.") + -> { @ftp.send(@method, "test", @tmp_file) }.should.raise(Net::FTPPermError) + end + + it "raises a Net::FTPTempError when the response code is 421" do + @server.should_receive(:retr).and_respond("421 Service not available, closing control connection.") + -> { @ftp.send(@method, "test", @tmp_file) }.should.raise(Net::FTPTempError) + end + + it "raises a Net::FTPPermError when the response code is 530" do + @server.should_receive(:retr).and_respond("530 Not logged in.") + -> { @ftp.send(@method, "test", @tmp_file) }.should.raise(Net::FTPPermError) + end 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.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError) + 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.send(@method, "test", @tmp_file) }.should.raise(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.send(@method, "test", @tmp_file) }.should.raise(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.send(@method, "test", @tmp_file) }.should.raise(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.send(@method, "test", @tmp_file) }.should.raise(Net::FTPPermError) + end end end end 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..9d36e37f0c 100644 --- a/spec/ruby/library/net-ftp/shared/last_response_code.rb +++ b/spec/ruby/library/net-ftp/shared/last_response_code.rb @@ -1,25 +1,27 @@ -describe :net_ftp_last_response_code, shared: true do - before :each do - @server = NetFTPSpecs::DummyFTP.new - @server.serve_once +ruby_version_is ""..."4.1" do + describe :net_ftp_last_response_code, shared: true do + before :each do + @server = NetFTPSpecs::DummyFTP.new + @server.serve_once - @ftp = Net::FTP.new - @ftp.connect(@server.hostname, @server.server_port) - end + @ftp = Net::FTP.new + @ftp.connect(@server.hostname, @server.server_port) + end - after :each do - @ftp.quit rescue nil - @ftp.close - @server.stop - end + after :each do + @ftp.quit rescue nil + @ftp.close + @server.stop + end - it "returns the response code for the last response" do - @server.should_receive(:help).and_respond("200 Command okay.") - @ftp.help - @ftp.send(@method).should == "200" + it "returns the response code for the last response" do + @server.should_receive(:help).and_respond("200 Command okay.") + @ftp.help + @ftp.send(@method).should == "200" - @server.should_receive(:help).and_respond("212 Directory status.") - @ftp.help - @ftp.send(@method).should == "212" + @server.should_receive(:help).and_respond("212 Directory status.") + @ftp.help + @ftp.send(@method).should == "212" + end end end diff --git a/spec/ruby/library/net-ftp/shared/list.rb b/spec/ruby/library/net-ftp/shared/list.rb index adc3fa59c1..ec372447e8 100644 --- a/spec/ruby/library/net-ftp/shared/list.rb +++ b/spec/ruby/library/net-ftp/shared/list.rb @@ -1,104 +1,106 @@ -describe :net_ftp_list, shared: true 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 a block" do - it "yields each file in the list of files in the passed dir" do - expected = [ - "-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" - ] - - res = [] - @ftp.send(@method, "test.folder") { |line| res << line} - res.should == expected - - @ftp.last_response.should == "226 transfer complete (LIST test.folder)\n" +ruby_version_is ""..."4.1" do + describe :net_ftp_list, shared: true 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 - end - - describe "when passed no block" do - it "returns an Array containing a list of files in the passed dir" do - expected = [ - "-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" - ] - @ftp.send(@method, "test.folder").should == expected - - @ftp.last_response.should == "226 transfer complete (LIST test.folder)\n" + after :each do + @ftp.quit rescue nil + @ftp.close + @server.stop end - end - describe "when the LIST command fails" do - it "raises a Net::FTPTempError when the response code is 450" do - @server.should_receive(:list).and_respond("450 Requested file action not taken..") - -> { @ftp.send(@method) }.should raise_error(Net::FTPTempError) - end + describe "when passed a block" do + it "yields each file in the list of files in the passed dir" do + expected = [ + "-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" + ] - it "raises a Net::FTPPermError when the response code is 500" do - @server.should_receive(:list).and_respond("500 Syntax error, command unrecognized.") - -> { @ftp.send(@method) }.should raise_error(Net::FTPPermError) - end + res = [] + @ftp.send(@method, "test.folder") { |line| res << line} + res.should == expected - it "raises a Net::FTPPermError when the response code is 501" do - @server.should_receive(:list).and_respond("501 Syntax error, command unrecognized.") - -> { @ftp.send(@method) }.should raise_error(Net::FTPPermError) + @ftp.last_response.should == "226 transfer complete (LIST test.folder)\n" + end end - it "raises a Net::FTPPermError when the response code is 502" do - @server.should_receive(:list).and_respond("502 Command not implemented.") - -> { @ftp.send(@method) }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPTempError when the response code is 421" do - @server.should_receive(:list).and_respond("421 Service not available, closing control connection.") - -> { @ftp.send(@method) }.should raise_error(Net::FTPTempError) - end + describe "when passed no block" do + it "returns an Array containing a list of files in the passed dir" do + expected = [ + "-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" + ] - it "raises a Net::FTPPermError when the response code is 530" do - @server.should_receive(:list).and_respond("530 Not logged in.") - -> { @ftp.send(@method) }.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.send(@method) }.should raise_error(Net::FTPPermError) - end + @ftp.send(@method, "test.folder").should == expected - 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.send(@method) }.should raise_error(Net::FTPPermError) + @ftp.last_response.should == "226 transfer complete (LIST test.folder)\n" + end 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.send(@method) }.should raise_error(Net::FTPTempError) + describe "when the LIST command fails" do + it "raises a Net::FTPTempError when the response code is 450" do + @server.should_receive(:list).and_respond("450 Requested file action not taken..") + -> { @ftp.send(@method) }.should.raise(Net::FTPTempError) + end + + it "raises a Net::FTPPermError when the response code is 500" do + @server.should_receive(:list).and_respond("500 Syntax error, command unrecognized.") + -> { @ftp.send(@method) }.should.raise(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 501" do + @server.should_receive(:list).and_respond("501 Syntax error, command unrecognized.") + -> { @ftp.send(@method) }.should.raise(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 502" do + @server.should_receive(:list).and_respond("502 Command not implemented.") + -> { @ftp.send(@method) }.should.raise(Net::FTPPermError) + end + + it "raises a Net::FTPTempError when the response code is 421" do + @server.should_receive(:list).and_respond("421 Service not available, closing control connection.") + -> { @ftp.send(@method) }.should.raise(Net::FTPTempError) + end + + it "raises a Net::FTPPermError when the response code is 530" do + @server.should_receive(:list).and_respond("530 Not logged in.") + -> { @ftp.send(@method) }.should.raise(Net::FTPPermError) + end 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.send(@method) }.should raise_error(Net::FTPPermError) + 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.send(@method) }.should.raise(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.send(@method) }.should.raise(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.send(@method) }.should.raise(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.send(@method) }.should.raise(Net::FTPPermError) + end end end end diff --git a/spec/ruby/library/net-ftp/shared/putbinaryfile.rb b/spec/ruby/library/net-ftp/shared/putbinaryfile.rb index 45f53adc2a..afbe3c61f8 100644 --- a/spec/ruby/library/net-ftp/shared/putbinaryfile.rb +++ b/spec/ruby/library/net-ftp/shared/putbinaryfile.rb @@ -1,167 +1,169 @@ -describe :net_ftp_putbinaryfile, shared: true do - before :each do - @server = NetFTPSpecs::DummyFTP.new - @server.serve_once +ruby_version_is ""..."4.1" do + describe :net_ftp_putbinaryfile, shared: true do + before :each do + @server = NetFTPSpecs::DummyFTP.new + @server.serve_once - @local_fixture_file = __dir__ + "/../fixtures/putbinaryfile" - @remote_tmp_file = tmp("binaryfile", false) + @local_fixture_file = __dir__ + "/../fixtures/putbinaryfile" + @remote_tmp_file = tmp("binaryfile", false) - @ftp = Net::FTP.new - @ftp.connect(@server.hostname, @server.server_port) - @ftp.binary = @binary_mode - end + @ftp = Net::FTP.new + @ftp.connect(@server.hostname, @server.server_port) + @ftp.binary = @binary_mode + end - after :each do - @ftp.quit rescue nil - @ftp.close - @server.stop + after :each do + @ftp.quit rescue nil + @ftp.close + @server.stop - rm_r @remote_tmp_file - end - - it "sends the STOR command to the server" do - @ftp.send(@method, @local_fixture_file, "binary") - @ftp.last_response.should == "200 OK, Data received. (STOR binary)\n" - end + rm_r @remote_tmp_file + end - it "sends the contents of the passed local_file, without modifications" do - @ftp.send(@method, @local_fixture_file, "binary") + it "sends the STOR command to the server" do + @ftp.send(@method, @local_fixture_file, "binary") + @ftp.last_response.should == "200 OK, Data received. (STOR binary)\n" + end - remote_lines = File.readlines(@remote_tmp_file) - local_lines = File.readlines(@local_fixture_file) + it "sends the contents of the passed local_file, without modifications" do + @ftp.send(@method, @local_fixture_file, "binary") - remote_lines.should == local_lines - end + remote_lines = File.readlines(@remote_tmp_file) + local_lines = File.readlines(@local_fixture_file) - it "returns nil" do - @ftp.send(@method, @local_fixture_file, "binary").should be_nil - end + remote_lines.should == local_lines + end - describe "when passed a block" do - it "yields the transmitted content as binary blocks of the passed size" do - res = [] - @ftp.send(@method, @local_fixture_file, "binary", 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" - ] + it "returns nil" do + @ftp.send(@method, @local_fixture_file, "binary").should == nil end - end - describe "when resuming an existing file" do - before :each do - File.open(@remote_tmp_file, "w") do |f| - f << "This is an example file\n" + describe "when passed a block" do + it "yields the transmitted content as binary blocks of the passed size" do + res = [] + @ftp.send(@method, @local_fixture_file, "binary", 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 - - @ftp.resume = true end - it "sends the remaining content of the passed local_file to the passed remote_file" do - @ftp.send(@method, @local_fixture_file, "binary") - File.read(@remote_tmp_file).should == File.read(@local_fixture_file) - end + describe "when resuming an existing file" do + before :each do + File.open(@remote_tmp_file, "w") do |f| + f << "This is an example file\n" + end - describe "and the APPE command fails" do - it "raises a Net::FTPProtoError when the response code is 550" do - @server.should_receive(:appe).and_respond("Requested action not taken.") - -> { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPProtoError) + @ftp.resume = true end - it "raises a Net::FTPPermError when the response code is 500" do - @server.should_receive(:appe).and_respond("500 Syntax error, command unrecognized.") - -> { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError) + it "sends the remaining content of the passed local_file to the passed remote_file" do + @ftp.send(@method, @local_fixture_file, "binary") + File.read(@remote_tmp_file).should == File.read(@local_fixture_file) end - it "raises a Net::FTPPermError when the response code is 501" do - @server.should_receive(:appe).and_respond("501 Syntax error, command unrecognized.") - -> { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError) + describe "and the APPE command fails" do + it "raises a Net::FTPProtoError when the response code is 550" do + @server.should_receive(:appe).and_respond("Requested action not taken.") + -> { @ftp.send(@method, @local_fixture_file, "binary") }.should.raise(Net::FTPProtoError) + end + + it "raises a Net::FTPPermError when the response code is 500" do + @server.should_receive(:appe).and_respond("500 Syntax error, command unrecognized.") + -> { @ftp.send(@method, @local_fixture_file, "binary") }.should.raise(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 501" do + @server.should_receive(:appe).and_respond("501 Syntax error, command unrecognized.") + -> { @ftp.send(@method, @local_fixture_file, "binary") }.should.raise(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 502" do + @server.should_receive(:appe).and_respond("502 Command not implemented.") + -> { @ftp.send(@method, @local_fixture_file, "binary") }.should.raise(Net::FTPPermError) + end + + it "raises a Net::FTPTempError when the response code is 421" do + @server.should_receive(:appe).and_respond("421 Service not available, closing control connection.") + -> { @ftp.send(@method, @local_fixture_file, "binary") }.should.raise(Net::FTPTempError) + end + + it "raises a Net::FTPPermError when the response code is 530" do + @server.should_receive(:appe).and_respond("530 Not logged in.") + -> { @ftp.send(@method, @local_fixture_file, "binary") }.should.raise(Net::FTPPermError) + end end + end - it "raises a Net::FTPPermError when the response code is 502" do - @server.should_receive(:appe).and_respond("502 Command not implemented.") - -> { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError) + describe "when the STOR command fails" do + it "raises a Net::FTPPermError when the response code is 532" do + @server.should_receive(:stor).and_respond("532 Need account for storing files.") + -> { @ftp.send(@method, @local_fixture_file, "binary") }.should.raise(Net::FTPPermError) end - it "raises a Net::FTPTempError when the response code is 421" do - @server.should_receive(:appe).and_respond("421 Service not available, closing control connection.") - -> { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPTempError) + it "raises a Net::FTPTempError when the response code is 450" do + @server.should_receive(:stor).and_respond("450 Requested file action not taken.") + -> { @ftp.send(@method, @local_fixture_file, "binary") }.should.raise(Net::FTPTempError) end - it "raises a Net::FTPPermError when the response code is 530" do - @server.should_receive(:appe).and_respond("530 Not logged in.") - -> { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError) + it "raises a Net::FTPTempError when the response code is 452" do + @server.should_receive(:stor).and_respond("452 Requested action not taken.") + -> { @ftp.send(@method, @local_fixture_file, "binary") }.should.raise(Net::FTPTempError) end - end - end - - describe "when the STOR command fails" do - it "raises a Net::FTPPermError when the response code is 532" do - @server.should_receive(:stor).and_respond("532 Need account for storing files.") - -> { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPTempError when the response code is 450" do - @server.should_receive(:stor).and_respond("450 Requested file action not taken.") - -> { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPTempError) - end - - it "raises a Net::FTPTempError when the response code is 452" do - @server.should_receive(:stor).and_respond("452 Requested action not taken.") - -> { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPTempError) - end - it "raises a Net::FTPPermError when the response code is 553" do - @server.should_receive(:stor).and_respond("553 Requested action not taken.") - -> { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError) - end + it "raises a Net::FTPPermError when the response code is 553" do + @server.should_receive(:stor).and_respond("553 Requested action not taken.") + -> { @ftp.send(@method, @local_fixture_file, "binary") }.should.raise(Net::FTPPermError) + end - it "raises a Net::FTPPermError when the response code is 500" do - @server.should_receive(:stor).and_respond("500 Syntax error, command unrecognized.") - -> { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError) - end + it "raises a Net::FTPPermError when the response code is 500" do + @server.should_receive(:stor).and_respond("500 Syntax error, command unrecognized.") + -> { @ftp.send(@method, @local_fixture_file, "binary") }.should.raise(Net::FTPPermError) + end - it "raises a Net::FTPPermError when the response code is 501" do - @server.should_receive(:stor).and_respond("501 Syntax error in parameters or arguments.") - -> { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError) - end + it "raises a Net::FTPPermError when the response code is 501" do + @server.should_receive(:stor).and_respond("501 Syntax error in parameters or arguments.") + -> { @ftp.send(@method, @local_fixture_file, "binary") }.should.raise(Net::FTPPermError) + end - it "raises a Net::FTPTempError when the response code is 421" do - @server.should_receive(:stor).and_respond("421 Service not available, closing control connection.") - -> { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPTempError) - end + it "raises a Net::FTPTempError when the response code is 421" do + @server.should_receive(:stor).and_respond("421 Service not available, closing control connection.") + -> { @ftp.send(@method, @local_fixture_file, "binary") }.should.raise(Net::FTPTempError) + end - it "raises a Net::FTPPermError when the response code is 530" do - @server.should_receive(:stor).and_respond("530 Not logged in.") - -> { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError) + it "raises a Net::FTPPermError when the response code is 530" do + @server.should_receive(:stor).and_respond("530 Not logged in.") + -> { @ftp.send(@method, @local_fixture_file, "binary") }.should.raise(Net::FTPPermError) + end 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.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError) - 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.send(@method, @local_fixture_file, "binary") }.should.raise(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.send(@method, @local_fixture_file, "binary") }.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.send(@method, @local_fixture_file, "binary") }.should.raise(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.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPTempError) - 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.send(@method, @local_fixture_file, "binary") }.should.raise(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.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError) + 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.send(@method, @local_fixture_file, "binary") }.should.raise(Net::FTPPermError) + end end end end diff --git a/spec/ruby/library/net-ftp/shared/puttextfile.rb b/spec/ruby/library/net-ftp/shared/puttextfile.rb index e2c0453352..3650cad230 100644 --- a/spec/ruby/library/net-ftp/shared/puttextfile.rb +++ b/spec/ruby/library/net-ftp/shared/puttextfile.rb @@ -1,128 +1,130 @@ -describe :net_ftp_puttextfile, shared: true do - before :each do - @server = NetFTPSpecs::DummyFTP.new - @server.serve_once - - @local_fixture_file = __dir__ + "/../fixtures/puttextfile" - @remote_tmp_file = tmp("textfile", false) - - @ftp = Net::FTP.new - @ftp.connect(@server.hostname, @server.server_port) - @ftp.binary = @binary_mode - end - - after :each do - @ftp.quit rescue nil - @ftp.close - @server.stop - - rm_r @remote_tmp_file - end - - it "sends the STOR command to the server" do - @ftp.send(@method, @local_fixture_file, "text") - @ftp.last_response.should == "200 OK, Data received. (STOR text)\n" - end - - 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 = 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 - - guard -> { Net::FTP::VERSION < '0.3.6' } do - it "returns nil" do - @ftp.send(@method, @local_fixture_file, "text").should be_nil +ruby_version_is ""..."4.1" do + describe :net_ftp_puttextfile, shared: true do + before :each do + @server = NetFTPSpecs::DummyFTP.new + @server.serve_once + + @local_fixture_file = __dir__ + "/../fixtures/puttextfile" + @remote_tmp_file = tmp("textfile", false) + + @ftp = Net::FTP.new + @ftp.connect(@server.hostname, @server.server_port) + @ftp.binary = @binary_mode 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 + after :each do + @ftp.quit rescue nil + @ftp.close + @server.stop - describe "when passed a block" do - it "yields each transmitted line" do - res = [] - @ftp.send(@method, @local_fixture_file, "text") { |x| res << x } - res.should == [ - "This is an example file\r\n", - "which is going to be transmitted\r\n", - "using #puttextfile.\r\n" - ] + rm_r @remote_tmp_file end - end - describe "when the STOR command fails" do - it "raises a Net::FTPPermError when the response code is 532" do - @server.should_receive(:stor).and_respond("532 Need account for storing files.") - -> { @ftp.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPPermError) + it "sends the STOR command to the server" do + @ftp.send(@method, @local_fixture_file, "text") + @ftp.last_response.should == "200 OK, Data received. (STOR text)\n" end - it "raises a Net::FTPTempError when the response code is 450" do - @server.should_receive(:stor).and_respond("450 Requested file action not taken.") - -> { @ftp.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPTempError) - end + it "sends the contents of the passed local_file, using \\r\\n as the newline separator" do + @ftp.send(@method, @local_fixture_file, "text") - it "raises a Net::FTPTempError when the response code is 452" do - @server.should_receive(:stor).and_respond("452 Requested action not taken.") - -> { @ftp.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPTempError) - end + remote_lines = File.binread(@remote_tmp_file) + local_lines = File.binread(@local_fixture_file) - it "raises a Net::FTPPermError when the response code is 553" do - @server.should_receive(:stor).and_respond("553 Requested action not taken.") - -> { @ftp.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPPermError) + remote_lines.should_not == local_lines + remote_lines.should == local_lines.gsub("\n", "\r\n") end - it "raises a Net::FTPPermError when the response code is 500" do - @server.should_receive(:stor).and_respond("500 Syntax error, command unrecognized.") - -> { @ftp.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPPermError) + guard -> { Net::FTP::VERSION < '0.3.6' } do + it "returns nil" do + @ftp.send(@method, @local_fixture_file, "text").should == nil + end end - it "raises a Net::FTPPermError when the response code is 501" do - @server.should_receive(:stor).and_respond("501 Syntax error in parameters or arguments.") - -> { @ftp.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPPermError) - end - - it "raises a Net::FTPTempError when the response code is 421" do - @server.should_receive(:stor).and_respond("421 Service not available, closing control connection.") - -> { @ftp.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPTempError) - end - - it "raises a Net::FTPPermError when the response code is 530" do - @server.should_receive(:stor).and_respond("530 Not logged in.") - -> { @ftp.send(@method, @local_fixture_file, "text") }.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.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPPermError) + 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 - 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.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPPermError) + describe "when passed a block" do + it "yields each transmitted line" do + res = [] + @ftp.send(@method, @local_fixture_file, "text") { |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 - 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.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPTempError) + describe "when the STOR command fails" do + it "raises a Net::FTPPermError when the response code is 532" do + @server.should_receive(:stor).and_respond("532 Need account for storing files.") + -> { @ftp.send(@method, @local_fixture_file, "text") }.should.raise(Net::FTPPermError) + end + + it "raises a Net::FTPTempError when the response code is 450" do + @server.should_receive(:stor).and_respond("450 Requested file action not taken.") + -> { @ftp.send(@method, @local_fixture_file, "text") }.should.raise(Net::FTPTempError) + end + + it "raises a Net::FTPTempError when the response code is 452" do + @server.should_receive(:stor).and_respond("452 Requested action not taken.") + -> { @ftp.send(@method, @local_fixture_file, "text") }.should.raise(Net::FTPTempError) + end + + it "raises a Net::FTPPermError when the response code is 553" do + @server.should_receive(:stor).and_respond("553 Requested action not taken.") + -> { @ftp.send(@method, @local_fixture_file, "text") }.should.raise(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 500" do + @server.should_receive(:stor).and_respond("500 Syntax error, command unrecognized.") + -> { @ftp.send(@method, @local_fixture_file, "text") }.should.raise(Net::FTPPermError) + end + + it "raises a Net::FTPPermError when the response code is 501" do + @server.should_receive(:stor).and_respond("501 Syntax error in parameters or arguments.") + -> { @ftp.send(@method, @local_fixture_file, "text") }.should.raise(Net::FTPPermError) + end + + it "raises a Net::FTPTempError when the response code is 421" do + @server.should_receive(:stor).and_respond("421 Service not available, closing control connection.") + -> { @ftp.send(@method, @local_fixture_file, "text") }.should.raise(Net::FTPTempError) + end + + it "raises a Net::FTPPermError when the response code is 530" do + @server.should_receive(:stor).and_respond("530 Not logged in.") + -> { @ftp.send(@method, @local_fixture_file, "text") }.should.raise(Net::FTPPermError) + end 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.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPPermError) + 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.send(@method, @local_fixture_file, "text") }.should.raise(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.send(@method, @local_fixture_file, "text") }.should.raise(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.send(@method, @local_fixture_file, "text") }.should.raise(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.send(@method, @local_fixture_file, "text") }.should.raise(Net::FTPPermError) + end end end end diff --git a/spec/ruby/library/net-ftp/shared/pwd.rb b/spec/ruby/library/net-ftp/shared/pwd.rb index 951d020f2d..db3e587464 100644 --- a/spec/ruby/library/net-ftp/shared/pwd.rb +++ b/spec/ruby/library/net-ftp/shared/pwd.rb @@ -1,3 +1,5 @@ -describe :net_ftp_pwd, shared: true do +ruby_version_is ""..."4.1" do + describe :net_ftp_pwd, shared: true do + end end diff --git a/spec/ruby/library/net-ftp/site_spec.rb b/spec/ruby/library/net-ftp/site_spec.rb index c3e589a920..adc7dfafdf 100644 --- a/spec/ruby/library/net-ftp/site_spec.rb +++ b/spec/ruby/library/net-ftp/site_spec.rb @@ -1,53 +1,56 @@ 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) +ruby_version_is ""..."4.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 == 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 + 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(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(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(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(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 index 0cf2e24477..dd84e5a449 100644 --- a/spec/ruby/library/net-ftp/size_spec.rb +++ b/spec/ruby/library/net-ftp/size_spec.rb @@ -1,48 +1,51 @@ 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) +ruby_version_is ""..."4.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(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(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(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(Net::FTPPermError) + end end end diff --git a/spec/ruby/library/net-ftp/spec_helper.rb b/spec/ruby/library/net-ftp/spec_helper.rb index c87d16218b..7689b4fb0c 100644 --- a/spec/ruby/library/net-ftp/spec_helper.rb +++ b/spec/ruby/library/net-ftp/spec_helper.rb @@ -1,5 +1,7 @@ -require "net/ftp" +ruby_version_is ""..."4.1" do + require "net/ftp" -if defined?(Net::FTP.default_passive) - Net::FTP.default_passive = false + if defined?(Net::FTP.default_passive) + Net::FTP.default_passive = false + end end diff --git a/spec/ruby/library/net-ftp/status_spec.rb b/spec/ruby/library/net-ftp/status_spec.rb index 9d9f86c381..ce29e215d4 100644 --- a/spec/ruby/library/net-ftp/status_spec.rb +++ b/spec/ruby/library/net-ftp/status_spec.rb @@ -1,67 +1,70 @@ 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 +ruby_version_is ""..."4.1" do + require_relative 'spec_helper' + require_relative 'fixtures/server' - @ftp = Net::FTP.new - @ftp.connect(@server.hostname, @server.server_port) - end + describe "Net::FTP#status" do + before :each do + @server = NetFTPSpecs::DummyFTP.new + @server.serve_once - after :each do - @ftp.quit rescue nil - @ftp.close - @server.stop - end + @ftp = Net::FTP.new + @ftp.connect(@server.hostname, @server.server_port) + 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 + after :each do + @ftp.quit rescue nil + @ftp.close + @server.stop + 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 "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 "returns the received information" do - @ftp.status.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 "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 "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 213" do - @server.should_receive(:stat).and_respond("213 File status.") - -> { @ftp.status }.should_not raise_error - 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 + 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 "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 + 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 500" do + @server.should_receive(:stat).and_respond("500 Syntax error, command unrecognized.") + -> { @ftp.status }.should.raise(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::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(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 502" do + @server.should_receive(:stat).and_respond("502 Command not implemented.") + -> { @ftp.status }.should.raise(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(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) + 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(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 index aa4c51f2e8..a2f81fc669 100644 --- a/spec/ruby/library/net-ftp/storbinary_spec.rb +++ b/spec/ruby/library/net-ftp/storbinary_spec.rb @@ -1,49 +1,52 @@ require_relative '../../spec_helper' -require_relative 'spec_helper' -require_relative 'fixtures/server' +ruby_version_is ""..."4.1" do -describe "Net::FTP#storbinary" do - before :each do - @server = NetFTPSpecs::DummyFTP.new - @server.serve_once + require_relative 'spec_helper' + require_relative 'fixtures/server' - @local_fixture_file = __dir__ + "/fixtures/putbinaryfile" - @tmp_file = tmp("binaryfile", false) + describe "Net::FTP#storbinary" do + before :each do + @server = NetFTPSpecs::DummyFTP.new + @server.serve_once - @ftp = Net::FTP.new - @ftp.connect(@server.hostname, @server.server_port) - end + @local_fixture_file = __dir__ + "/fixtures/putbinaryfile" + @tmp_file = tmp("binaryfile", false) - after :each do - @ftp.quit rescue nil - @ftp.close - @server.stop + @ftp = Net::FTP.new + @ftp.connect(@server.hostname, @server.server_port) + end - rm_r @tmp_file - end + after :each do + @ftp.quit rescue nil + @ftp.close + @server.stop - 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 + 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" + @ftp.storbinary("STOR binary", f, 4096) {} + @ftp.last_response.should == "200 OK, Data received. (STOR binary)\n" + end 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" - ] + 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 index dc6830da7b..09340bafe9 100644 --- a/spec/ruby/library/net-ftp/storlines_spec.rb +++ b/spec/ruby/library/net-ftp/storlines_spec.rb @@ -1,44 +1,47 @@ require_relative '../../spec_helper' -require_relative 'spec_helper' -require_relative 'fixtures/server' +ruby_version_is ""..."4.1" do -describe "Net::FTP#storlines" do - before :each do - @server = NetFTPSpecs::DummyFTP.new - @server.serve_once + require_relative 'spec_helper' + require_relative 'fixtures/server' - @local_fixture_file = __dir__ + "/fixtures/puttextfile" - @tmp_file = tmp("textfile", false) + describe "Net::FTP#storlines" do + before :each do + @server = NetFTPSpecs::DummyFTP.new + @server.serve_once - @ftp = Net::FTP.new - @ftp.connect(@server.hostname, @server.server_port) - end + @local_fixture_file = __dir__ + "/fixtures/puttextfile" + @tmp_file = tmp("textfile", false) - after :each do - @ftp.quit rescue nil - @ftp.close - @server.stop + @ftp = Net::FTP.new + @ftp.connect(@server.hostname, @server.server_port) + end - rm_r @tmp_file - end + after :each do + @ftp.quit rescue nil + @ftp.close + @server.stop - 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" + 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 - 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" - ] + 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 index 2b7f0d2560..fa61776282 100644 --- a/spec/ruby/library/net-ftp/system_spec.rb +++ b/spec/ruby/library/net-ftp/system_spec.rb @@ -1,48 +1,51 @@ 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) +ruby_version_is ""..."4.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(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(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(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(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 index f2536fe697..4f74da7a70 100644 --- a/spec/ruby/library/net-ftp/voidcmd_spec.rb +++ b/spec/ruby/library/net-ftp/voidcmd_spec.rb @@ -1,54 +1,57 @@ 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) +ruby_version_is ""..."4.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 + end + + it "returns nil" do + @server.should_receive(:help).and_respond("2xx Does not raise.") + @ftp.voidcmd("HELP").should == 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(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(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(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(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(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 index 4279127ce3..761a0f9a3e 100644 --- a/spec/ruby/library/net-ftp/welcome_spec.rb +++ b/spec/ruby/library/net-ftp/welcome_spec.rb @@ -1,25 +1,28 @@ 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 +ruby_version_is ""..."4.1" do + require_relative 'spec_helper' + require_relative 'fixtures/server' - @ftp = Net::FTP.new - @ftp.connect(@server.hostname, @server.server_port) - end + describe "Net::FTP#welcome" do + before :each do + @server = NetFTPSpecs::DummyFTP.new + @server.serve_once - after :each do - @ftp.quit rescue nil - @ftp.close - @server.stop - end + @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" + it "returns the server's welcome message" do + @ftp.welcome.should == 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 index 5e0a833fee..020d3cce85 100644 --- a/spec/ruby/library/net-http/HTTPServerException_spec.rb +++ b/spec/ruby/library/net-http/HTTPServerException_spec.rb @@ -3,10 +3,10 @@ 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/) + -> { 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 - -> { Net::HTTPServerException.should < Net::HTTPExceptions }.should complain(/warning: constant Net::HTTPServerException is deprecated/) + -> { 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 a1a04fa00b..7753ce5e30 100644 --- a/spec/ruby/library/net-http/http/Proxy_spec.rb +++ b/spec/ruby/library/net-http/http/Proxy_spec.rb @@ -13,7 +13,7 @@ describe "Net::HTTP.Proxy" do it "sets the returned subclasses' proxy options based on the passed arguments" do http_with_proxy = Net::HTTP.Proxy("localhost", 1234, "rspec", "rocks") http_with_proxy.proxy_address.should == "localhost" - http_with_proxy.proxy_port.should eql(1234) + http_with_proxy.proxy_port.should.eql?(1234) http_with_proxy.proxy_user.should == "rspec" http_with_proxy.proxy_pass.should == "rocks" end @@ -22,14 +22,14 @@ end describe "Net::HTTP#proxy?" do describe "when self is no proxy class instance" do it "returns false" do - Net::HTTP.new("localhost", 3333).proxy?.should be_false + Net::HTTP.new("localhost", 3333).proxy?.should == false end end describe "when self is a proxy class instance" do it "returns false" do http_with_proxy = Net::HTTP.Proxy("localhost", 1234, "rspec", "rocks") - http_with_proxy.new("localhost", 3333).proxy?.should be_true + http_with_proxy.new("localhost", 3333).proxy?.should == true end end end diff --git a/spec/ruby/library/net-http/http/active_spec.rb b/spec/ruby/library/net-http/http/active_spec.rb index c260274594..ba870b39d2 100644 --- a/spec/ruby/library/net-http/http/active_spec.rb +++ b/spec/ruby/library/net-http/http/active_spec.rb @@ -1,8 +1,8 @@ require_relative '../../../spec_helper' require 'net/http' -require_relative 'fixtures/http_server' -require_relative 'shared/started' describe "Net::HTTP#active?" do - it_behaves_like :net_http_started_p, :active? + it "is an alias of Net::HTTP#started?" do + Net::HTTP.instance_method(:active?).should == Net::HTTP.instance_method(:started?) + end end diff --git a/spec/ruby/library/net-http/http/copy_spec.rb b/spec/ruby/library/net-http/http/copy_spec.rb index fba96c0f11..1f3e25009f 100644 --- a/spec/ruby/library/net-http/http/copy_spec.rb +++ b/spec/ruby/library/net-http/http/copy_spec.rb @@ -15,7 +15,7 @@ describe "Net::HTTP#copy" do it "sends a COPY request to the passed path and returns the response" do response = @http.copy("/request") - response.should be_kind_of(Net::HTTPResponse) + response.should.is_a?(Net::HTTPResponse) response.body.should == "Request type: COPY" end end 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 95b7316a0c..20407d0b12 100644 --- a/spec/ruby/library/net-http/http/default_port_spec.rb +++ b/spec/ruby/library/net-http/http/default_port_spec.rb @@ -3,6 +3,6 @@ require 'net/http' describe "Net::HTTP.default_port" do it "returns 80" do - Net::HTTP.http_default_port.should eql(80) + Net::HTTP.http_default_port.should.eql?(80) end end diff --git a/spec/ruby/library/net-http/http/delete_spec.rb b/spec/ruby/library/net-http/http/delete_spec.rb index d73aa5b375..09ddd74000 100644 --- a/spec/ruby/library/net-http/http/delete_spec.rb +++ b/spec/ruby/library/net-http/http/delete_spec.rb @@ -15,7 +15,7 @@ describe "Net::HTTP#delete" do it "sends a DELETE request to the passed path and returns the response" do response = @http.delete("/request") - response.should be_kind_of(Net::HTTPResponse) + response.should.is_a?(Net::HTTPResponse) response.body.should == "Request type: DELETE" end end diff --git a/spec/ruby/library/net-http/http/finish_spec.rb b/spec/ruby/library/net-http/http/finish_spec.rb index d4aa00dffe..0d466675f3 100644 --- a/spec/ruby/library/net-http/http/finish_spec.rb +++ b/spec/ruby/library/net-http/http/finish_spec.rb @@ -17,13 +17,13 @@ describe "Net::HTTP#finish" do it "closes the tcp connection" do @http.start @http.finish - @http.started?.should be_false + @http.started?.should == false end end describe "when self has not been started yet" do it "raises an IOError" do - -> { @http.finish }.should raise_error(IOError) + -> { @http.finish }.should.raise(IOError) end end end diff --git a/spec/ruby/library/net-http/http/get2_spec.rb b/spec/ruby/library/net-http/http/get2_spec.rb index 57c05ec64b..046443d73e 100644 --- a/spec/ruby/library/net-http/http/get2_spec.rb +++ b/spec/ruby/library/net-http/http/get2_spec.rb @@ -1,8 +1,8 @@ require_relative '../../../spec_helper' require 'net/http' -require_relative 'fixtures/http_server' -require_relative 'shared/request_get' describe "Net::HTTP#get2" do - it_behaves_like :net_http_request_get, :get2 + it "is an alias of Net::HTTP#request_get" do + Net::HTTP.instance_method(:get2).should == Net::HTTP.instance_method(:request_get) + end end diff --git a/spec/ruby/library/net-http/http/get_spec.rb b/spec/ruby/library/net-http/http/get_spec.rb index e64a61c52c..9be726dc3b 100644 --- a/spec/ruby/library/net-http/http/get_spec.rb +++ b/spec/ruby/library/net-http/http/get_spec.rb @@ -74,7 +74,7 @@ describe "Net::HTTP.get" do socket, client_thread = start_threads begin client_thread.raise my_exception, "my exception" - -> { client_thread.value }.should raise_error(my_exception) + -> { client_thread.value }.should.raise(my_exception) ensure socket.close end diff --git a/spec/ruby/library/net-http/http/head2_spec.rb b/spec/ruby/library/net-http/http/head2_spec.rb index 84cfff33d7..19c0cede9f 100644 --- a/spec/ruby/library/net-http/http/head2_spec.rb +++ b/spec/ruby/library/net-http/http/head2_spec.rb @@ -1,8 +1,8 @@ require_relative '../../../spec_helper' require 'net/http' -require_relative 'fixtures/http_server' -require_relative 'shared/request_head' describe "Net::HTTP#head2" do - it_behaves_like :net_http_request_head, :head2 + it "is an alias of Net::HTTP#request_head" do + Net::HTTP.instance_method(:head2).should == Net::HTTP.instance_method(:request_head) + end end diff --git a/spec/ruby/library/net-http/http/head_spec.rb b/spec/ruby/library/net-http/http/head_spec.rb index 64621fa87b..4824d22534 100644 --- a/spec/ruby/library/net-http/http/head_spec.rb +++ b/spec/ruby/library/net-http/http/head_spec.rb @@ -16,10 +16,10 @@ describe "Net::HTTP#head" do it "sends a HEAD request to the passed path and returns the response" do response = @http.head("/request") # HEAD requests have no responses - response.body.should be_nil + response.body.should == nil end it "returns a Net::HTTPResponse" do - @http.head("/request").should be_kind_of(Net::HTTPResponse) + @http.head("/request").should.is_a?(Net::HTTPResponse) end end 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 3b17bcd0a5..82c88e58a8 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 @@ -3,6 +3,6 @@ require 'net/http' describe "Net::HTTP.http_default_port" do it "returns 80" do - Net::HTTP.http_default_port.should eql(80) + Net::HTTP.http_default_port.should.eql?(80) end end 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 8c24e1d97c..24b9c3b462 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 @@ -3,6 +3,6 @@ require 'net/http' describe "Net::HTTP.https_default_port" do it "returns 443" do - Net::HTTP.https_default_port.should eql(443) + Net::HTTP.https_default_port.should.eql?(443) end end diff --git a/spec/ruby/library/net-http/http/initialize_spec.rb b/spec/ruby/library/net-http/http/initialize_spec.rb index 78aa01e1aa..907314cb25 100644 --- a/spec/ruby/library/net-http/http/initialize_spec.rb +++ b/spec/ruby/library/net-http/http/initialize_spec.rb @@ -3,7 +3,7 @@ require 'net/http' describe "Net::HTTP#initialize" do it "is private" do - Net::HTTP.should have_private_instance_method(:initialize) + Net::HTTP.private_instance_methods(false).should.include?(:initialize) end describe "when passed address" do @@ -17,11 +17,11 @@ describe "Net::HTTP#initialize" do end it "sets the new Net::HTTP instance's port to the default HTTP port" do - @net.port.should eql(Net::HTTP.default_port) + @net.port.should.eql?(Net::HTTP.default_port) end it "does not start the new Net::HTTP instance" do - @net.started?.should be_false + @net.started?.should == false end end @@ -36,11 +36,11 @@ describe "Net::HTTP#initialize" do end it "sets the new Net::HTTP instance's port to the passed port" do - @net.port.should eql(3333) + @net.port.should.eql?(3333) end it "does not start the new Net::HTTP instance" do - @net.started?.should be_false + @net.started?.should == false end end end diff --git a/spec/ruby/library/net-http/http/inspect_spec.rb b/spec/ruby/library/net-http/http/inspect_spec.rb index b8f650809e..fd4e6116c7 100644 --- a/spec/ruby/library/net-http/http/inspect_spec.rb +++ b/spec/ruby/library/net-http/http/inspect_spec.rb @@ -15,7 +15,7 @@ describe "Net::HTTP#inspect" do end it "returns a String representation of self" do - @http.inspect.should be_kind_of(String) + @http.inspect.should.is_a?(String) @http.inspect.should == "#<Net::HTTP localhost:#{@port} open=false>" @http.start 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 bdb343f9e0..f4910ef1e4 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,7 +1,8 @@ require_relative '../../../spec_helper' require 'net/http' -require_relative 'shared/version_1_1' describe "Net::HTTP.is_version_1_1?" do - it_behaves_like :net_http_version_1_1_p, :is_version_1_1? + it "is an alias of Net::HTTP.version_1_1?" do + Net::HTTP.method(:is_version_1_1?).should == Net::HTTP.method(:version_1_1?) + end end 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 555bb205dd..555724babe 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,7 +1,8 @@ require_relative '../../../spec_helper' require 'net/http' -require_relative 'shared/version_1_2' describe "Net::HTTP.is_version_1_2?" do - it_behaves_like :net_http_version_1_2_p, :is_version_1_2? + it "is an alias of Net::HTTP.version_1_2?" do + Net::HTTP.method(:is_version_1_2?).should == Net::HTTP.method(:version_1_2?) + end end diff --git a/spec/ruby/library/net-http/http/lock_spec.rb b/spec/ruby/library/net-http/http/lock_spec.rb index aa1f944196..12df138ad0 100644 --- a/spec/ruby/library/net-http/http/lock_spec.rb +++ b/spec/ruby/library/net-http/http/lock_spec.rb @@ -15,7 +15,7 @@ describe "Net::HTTP#lock" do it "sends a LOCK request to the passed path and returns the response" do response = @http.lock("/request", "test=test") - response.should be_kind_of(Net::HTTPResponse) + response.should.is_a?(Net::HTTPResponse) response.body.should == "Request type: LOCK" end end diff --git a/spec/ruby/library/net-http/http/mkcol_spec.rb b/spec/ruby/library/net-http/http/mkcol_spec.rb index f8009f9059..b1a5055982 100644 --- a/spec/ruby/library/net-http/http/mkcol_spec.rb +++ b/spec/ruby/library/net-http/http/mkcol_spec.rb @@ -15,7 +15,7 @@ describe "Net::HTTP#mkcol" do it "sends a MKCOL request to the passed path and returns the response" do response = @http.mkcol("/request") - response.should be_kind_of(Net::HTTPResponse) + response.should.is_a?(Net::HTTPResponse) response.body.should == "Request type: MKCOL" end end diff --git a/spec/ruby/library/net-http/http/move_spec.rb b/spec/ruby/library/net-http/http/move_spec.rb index ae43016a2c..a57c2a0f49 100644 --- a/spec/ruby/library/net-http/http/move_spec.rb +++ b/spec/ruby/library/net-http/http/move_spec.rb @@ -20,6 +20,6 @@ describe "Net::HTTP#head" do end it "returns a Net::HTTPResponse" do - @http.move("/request").should be_kind_of(Net::HTTPResponse) + @http.move("/request").should.is_a?(Net::HTTPResponse) end end diff --git a/spec/ruby/library/net-http/http/new_spec.rb b/spec/ruby/library/net-http/http/new_spec.rb index 1ec6bbd0c0..8feb3d1351 100644 --- a/spec/ruby/library/net-http/http/new_spec.rb +++ b/spec/ruby/library/net-http/http/new_spec.rb @@ -8,8 +8,8 @@ describe "Net::HTTP.new" do end it "returns a Net::HTTP instance" do - @http.proxy?.should be_false - @http.instance_of?(Net::HTTP).should be_true + @http.proxy?.should == false + @http.instance_of?(Net::HTTP).should == true end it "sets the new Net::HTTP instance's address to the passed address" do @@ -17,11 +17,11 @@ describe "Net::HTTP.new" do end it "sets the new Net::HTTP instance's port to the default HTTP port" do - @http.port.should eql(Net::HTTP.default_port) + @http.port.should.eql?(Net::HTTP.default_port) end it "does not start the new Net::HTTP instance" do - @http.started?.should be_false + @http.started?.should == false end end @@ -31,8 +31,8 @@ describe "Net::HTTP.new" do end it "returns a Net::HTTP instance" do - @http.proxy?.should be_false - @http.instance_of?(Net::HTTP).should be_true + @http.proxy?.should == false + @http.instance_of?(Net::HTTP).should == true end it "sets the new Net::HTTP instance's address to the passed address" do @@ -40,44 +40,44 @@ describe "Net::HTTP.new" do end it "sets the new Net::HTTP instance's port to the passed port" do - @http.port.should eql(3333) + @http.port.should.eql?(3333) end it "does not start the new Net::HTTP instance" do - @http.started?.should be_false + @http.started?.should == false end end describe "when passed address, port, *proxy_options" do it "returns a Net::HTTP instance" do http = Net::HTTP.new("localhost", 3333, "localhost") - http.proxy?.should be_true - http.instance_of?(Net::HTTP).should be_true - http.should be_kind_of(Net::HTTP) + http.proxy?.should == true + http.instance_of?(Net::HTTP).should == true + http.should.is_a?(Net::HTTP) end it "correctly sets the passed Proxy options" do http = Net::HTTP.new("localhost", 3333, "localhost") http.proxy_address.should == "localhost" - http.proxy_port.should eql(80) - http.proxy_user.should be_nil - http.proxy_pass.should be_nil + http.proxy_port.should.eql?(80) + http.proxy_user.should == nil + http.proxy_pass.should == nil http = Net::HTTP.new("localhost", 3333, "localhost", 1234) http.proxy_address.should == "localhost" - http.proxy_port.should eql(1234) - http.proxy_user.should be_nil - http.proxy_pass.should be_nil + http.proxy_port.should.eql?(1234) + http.proxy_user.should == nil + http.proxy_pass.should == nil http = Net::HTTP.new("localhost", 3333, "localhost", 1234, "rubyspec") http.proxy_address.should == "localhost" - http.proxy_port.should eql(1234) + http.proxy_port.should.eql?(1234) http.proxy_user.should == "rubyspec" - http.proxy_pass.should be_nil + http.proxy_pass.should == nil http = Net::HTTP.new("localhost", 3333, "localhost", 1234, "rubyspec", "rocks") http.proxy_address.should == "localhost" - http.proxy_port.should eql(1234) + http.proxy_port.should.eql?(1234) http.proxy_user.should == "rubyspec" http.proxy_pass.should == "rocks" end diff --git a/spec/ruby/library/net-http/http/newobj_spec.rb b/spec/ruby/library/net-http/http/newobj_spec.rb index e19b30fca9..d398fb7d9a 100644 --- a/spec/ruby/library/net-http/http/newobj_spec.rb +++ b/spec/ruby/library/net-http/http/newobj_spec.rb @@ -8,7 +8,7 @@ describe "Net::HTTP.newobj" do describe "when passed address" do it "returns a new Net::HTTP instance" do - @net.should be_kind_of(Net::HTTP) + @net.should.is_a?(Net::HTTP) end it "sets the new Net::HTTP instance's address to the passed address" do @@ -16,11 +16,11 @@ describe "Net::HTTP.newobj" do end it "sets the new Net::HTTP instance's port to the default HTTP port" do - @net.port.should eql(Net::HTTP.default_port) + @net.port.should.eql?(Net::HTTP.default_port) end it "does not start the new Net::HTTP instance" do - @net.started?.should be_false + @net.started?.should == false end end @@ -30,7 +30,7 @@ describe "Net::HTTP.newobj" do end it "returns a new Net::HTTP instance" do - @net.should be_kind_of(Net::HTTP) + @net.should.is_a?(Net::HTTP) end it "sets the new Net::HTTP instance's address to the passed address" do @@ -38,11 +38,11 @@ describe "Net::HTTP.newobj" do end it "sets the new Net::HTTP instance's port to the passed port" do - @net.port.should eql(3333) + @net.port.should.eql?(3333) end it "does not start the new Net::HTTP instance" do - @net.started?.should be_false + @net.started?.should == false end end end 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 0d93752271..d00f844b38 100644 --- a/spec/ruby/library/net-http/http/open_timeout_spec.rb +++ b/spec/ruby/library/net-http/http/open_timeout_spec.rb @@ -4,9 +4,9 @@ require 'net/http' describe "Net::HTTP#open_timeout" do it "returns the seconds to wait till the connection is open" do net = Net::HTTP.new("localhost") - net.open_timeout.should eql(60) + net.open_timeout.should.eql?(60) net.open_timeout = 10 - net.open_timeout.should eql(10) + net.open_timeout.should.eql?(10) end end @@ -14,11 +14,11 @@ describe "Net::HTTP#open_timeout=" do it "sets the seconds to wait till the connection is open" do net = Net::HTTP.new("localhost") net.open_timeout = 10 - net.open_timeout.should eql(10) + net.open_timeout.should.eql?(10) end it "returns the newly set value" do net = Net::HTTP.new("localhost") - (net.open_timeout = 10).should eql(10) + (net.open_timeout = 10).should.eql?(10) end end diff --git a/spec/ruby/library/net-http/http/options_spec.rb b/spec/ruby/library/net-http/http/options_spec.rb index 3d9887a557..3b90573cfa 100644 --- a/spec/ruby/library/net-http/http/options_spec.rb +++ b/spec/ruby/library/net-http/http/options_spec.rb @@ -20,6 +20,6 @@ describe "Net::HTTP#options" do end it "returns a Net::HTTPResponse" do - @http.options("/request").should be_kind_of(Net::HTTPResponse) + @http.options("/request").should.is_a?(Net::HTTPResponse) end end diff --git a/spec/ruby/library/net-http/http/port_spec.rb b/spec/ruby/library/net-http/http/port_spec.rb index 0984d5e6ce..edb689f9ca 100644 --- a/spec/ruby/library/net-http/http/port_spec.rb +++ b/spec/ruby/library/net-http/http/port_spec.rb @@ -4,6 +4,6 @@ require 'net/http' describe "Net::HTTP#port" do it "returns the current port number" do net = Net::HTTP.new("localhost", 3333) - net.port.should eql(3333) + net.port.should.eql?(3333) end end diff --git a/spec/ruby/library/net-http/http/post2_spec.rb b/spec/ruby/library/net-http/http/post2_spec.rb index abc998709f..68c2a9ea06 100644 --- a/spec/ruby/library/net-http/http/post2_spec.rb +++ b/spec/ruby/library/net-http/http/post2_spec.rb @@ -1,8 +1,8 @@ require_relative '../../../spec_helper' require 'net/http' -require_relative 'fixtures/http_server' -require_relative 'shared/request_post' describe "Net::HTTP#post2" do - it_behaves_like :net_http_request_post, :post2 + it "is an alias of Net::HTTP#request_post" do + Net::HTTP.instance_method(:post2).should == Net::HTTP.instance_method(:request_post) + end end diff --git a/spec/ruby/library/net-http/http/post_spec.rb b/spec/ruby/library/net-http/http/post_spec.rb index cebbee4ff3..f294411197 100644 --- a/spec/ruby/library/net-http/http/post_spec.rb +++ b/spec/ruby/library/net-http/http/post_spec.rb @@ -22,13 +22,13 @@ describe "Net::HTTP.post" do it "returns a Net::HTTPResponse" do response = Net::HTTP.post(URI("http://localhost:#{NetHTTPSpecs.port}/request"), "test=test") - response.should be_kind_of(Net::HTTPResponse) + response.should.is_a?(Net::HTTPResponse) end - ruby_version_is ""..."3.5" do + 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("{}")) + response.body.should.include?({ "Content-Type" => "application/x-www-form-urlencoded" }.inspect.delete("{}")) end end @@ -57,7 +57,7 @@ describe "Net::HTTP#post" do end it "returns a Net::HTTPResponse" do - @http.post("/request", "test=test").should be_kind_of(Net::HTTPResponse) + @http.post("/request", "test=test").should.is_a?(Net::HTTPResponse) end describe "when passed a block" do @@ -70,7 +70,7 @@ describe "Net::HTTP#post" do end it "returns a Net::HTTPResponse" do - @http.post("/request", "test=test") {}.should be_kind_of(Net::HTTPResponse) + @http.post("/request", "test=test") {}.should.is_a?(Net::HTTPResponse) end end end diff --git a/spec/ruby/library/net-http/http/propfind_spec.rb b/spec/ruby/library/net-http/http/propfind_spec.rb index f3742d1b1a..6a1be0392a 100644 --- a/spec/ruby/library/net-http/http/propfind_spec.rb +++ b/spec/ruby/library/net-http/http/propfind_spec.rb @@ -19,6 +19,6 @@ describe "Net::HTTP#propfind" do end it "returns a Net::HTTPResponse" do - @http.propfind("/request", "test=test").should be_kind_of(Net::HTTPResponse) + @http.propfind("/request", "test=test").should.is_a?(Net::HTTPResponse) end end diff --git a/spec/ruby/library/net-http/http/proppatch_spec.rb b/spec/ruby/library/net-http/http/proppatch_spec.rb index 0163d24d46..074dfafaef 100644 --- a/spec/ruby/library/net-http/http/proppatch_spec.rb +++ b/spec/ruby/library/net-http/http/proppatch_spec.rb @@ -19,6 +19,6 @@ describe "Net::HTTP#proppatch" do end it "returns a Net::HTTPResponse" do - @http.proppatch("/request", "test=test").should be_kind_of(Net::HTTPResponse) + @http.proppatch("/request", "test=test").should.is_a?(Net::HTTPResponse) end end 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 5b5efb7ac0..ba040336ad 100644 --- a/spec/ruby/library/net-http/http/proxy_address_spec.rb +++ b/spec/ruby/library/net-http/http/proxy_address_spec.rb @@ -4,7 +4,7 @@ require 'net/http' describe "Net::HTTP.proxy_address" do describe "when self is no proxy class" do it "returns nil" do - Net::HTTP.proxy_address.should be_nil + Net::HTTP.proxy_address.should == nil end end @@ -18,7 +18,7 @@ end describe "Net::HTTP#proxy_address" do describe "when self is no proxy class instance" do it "returns nil" do - Net::HTTP.new("localhost", 3333).proxy_address.should be_nil + Net::HTTP.new("localhost", 3333).proxy_address.should == nil end end 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 00975aef4e..eda027c893 100644 --- a/spec/ruby/library/net-http/http/proxy_class_spec.rb +++ b/spec/ruby/library/net-http/http/proxy_class_spec.rb @@ -3,7 +3,7 @@ require 'net/http' describe "Net::HTTP.proxy_class?" do it "returns true if self is a class created with Net::HTTP.Proxy" do - Net::HTTP.proxy_class?.should be_false - Net::HTTP.Proxy("localhost").proxy_class?.should be_true + Net::HTTP.proxy_class?.should == false + Net::HTTP.Proxy("localhost").proxy_class?.should == true end end 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 4e393a53ff..ad02d896c0 100644 --- a/spec/ruby/library/net-http/http/proxy_pass_spec.rb +++ b/spec/ruby/library/net-http/http/proxy_pass_spec.rb @@ -4,13 +4,13 @@ require 'net/http' describe "Net::HTTP.proxy_pass" do describe "when self is no proxy class" do it "returns nil" do - Net::HTTP.proxy_pass.should be_nil + Net::HTTP.proxy_pass.should == nil end end describe "when self is a proxy class" do it "returns nil if no password was set for self's proxy connection" do - Net::HTTP.Proxy("localhost").proxy_pass.should be_nil + Net::HTTP.Proxy("localhost").proxy_pass.should == nil end it "returns the password for self's proxy connection" do @@ -22,13 +22,13 @@ end describe "Net::HTTP#proxy_pass" do describe "when self is no proxy class instance" do it "returns nil" do - Net::HTTP.new("localhost", 3333).proxy_pass.should be_nil + Net::HTTP.new("localhost", 3333).proxy_pass.should == nil end end describe "when self is a proxy class instance" do it "returns nil if no password was set for self's proxy connection" do - Net::HTTP.Proxy("localhost").new("localhost", 3333).proxy_pass.should be_nil + Net::HTTP.Proxy("localhost").new("localhost", 3333).proxy_pass.should == nil end it "returns the password for self's proxy connection" 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 d7d37f3927..21c1e4180e 100644 --- a/spec/ruby/library/net-http/http/proxy_port_spec.rb +++ b/spec/ruby/library/net-http/http/proxy_port_spec.rb @@ -4,17 +4,17 @@ require 'net/http' describe "Net::HTTP.proxy_port" do describe "when self is no proxy class" do it "returns nil" do - Net::HTTP.proxy_port.should be_nil + Net::HTTP.proxy_port.should == nil end end describe "when self is a proxy class" do it "returns 80 if no port was set for self's proxy connection" do - Net::HTTP.Proxy("localhost").proxy_port.should eql(80) + Net::HTTP.Proxy("localhost").proxy_port.should.eql?(80) end it "returns the port for self's proxy connection" do - Net::HTTP.Proxy("localhost", 1234, "rspec", "rocks").proxy_port.should eql(1234) + Net::HTTP.Proxy("localhost", 1234, "rspec", "rocks").proxy_port.should.eql?(1234) end end end @@ -22,18 +22,18 @@ end describe "Net::HTTP#proxy_port" do describe "when self is no proxy class instance" do it "returns nil" do - Net::HTTP.new("localhost", 3333).proxy_port.should be_nil + Net::HTTP.new("localhost", 3333).proxy_port.should == nil end end describe "when self is a proxy class instance" do it "returns 80 if no port was set for self's proxy connection" do - Net::HTTP.Proxy("localhost").new("localhost", 3333).proxy_port.should eql(80) + Net::HTTP.Proxy("localhost").new("localhost", 3333).proxy_port.should.eql?(80) end it "returns the port for self's proxy connection" do http_with_proxy = Net::HTTP.Proxy("localhost", 1234, "rspec", "rocks") - http_with_proxy.new("localhost", 3333).proxy_port.should eql(1234) + http_with_proxy.new("localhost", 3333).proxy_port.should.eql?(1234) end end end 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 ef7654425d..492ea2e8ee 100644 --- a/spec/ruby/library/net-http/http/proxy_user_spec.rb +++ b/spec/ruby/library/net-http/http/proxy_user_spec.rb @@ -4,13 +4,13 @@ require 'net/http' describe "Net::HTTP.proxy_user" do describe "when self is no proxy class" do it "returns nil" do - Net::HTTP.proxy_user.should be_nil + Net::HTTP.proxy_user.should == nil end end describe "when self is a proxy class" do it "returns nil if no username was set for self's proxy connection" do - Net::HTTP.Proxy("localhost").proxy_user.should be_nil + Net::HTTP.Proxy("localhost").proxy_user.should == nil end it "returns the username for self's proxy connection" do @@ -22,13 +22,13 @@ end describe "Net::HTTP#proxy_user" do describe "when self is no proxy class instance" do it "returns nil" do - Net::HTTP.new("localhost", 3333).proxy_user.should be_nil + Net::HTTP.new("localhost", 3333).proxy_user.should == nil end end describe "when self is a proxy class instance" do it "returns nil if no username was set for self's proxy connection" do - Net::HTTP.Proxy("localhost").new("localhost", 3333).proxy_user.should be_nil + Net::HTTP.Proxy("localhost").new("localhost", 3333).proxy_user.should == nil end it "returns the username for self's proxy connection" do diff --git a/spec/ruby/library/net-http/http/put2_spec.rb b/spec/ruby/library/net-http/http/put2_spec.rb index 7b03a39d0b..237df67e82 100644 --- a/spec/ruby/library/net-http/http/put2_spec.rb +++ b/spec/ruby/library/net-http/http/put2_spec.rb @@ -1,8 +1,8 @@ require_relative '../../../spec_helper' require 'net/http' -require_relative 'fixtures/http_server' -require_relative 'shared/request_put' describe "Net::HTTP#put2" do - it_behaves_like :net_http_request_put, :put2 + it "is an alias of Net::HTTP#request_put" do + Net::HTTP.instance_method(:put2).should == Net::HTTP.instance_method(:request_put) + end end diff --git a/spec/ruby/library/net-http/http/put_spec.rb b/spec/ruby/library/net-http/http/put_spec.rb index 75f3c243d4..7ef9219f63 100644 --- a/spec/ruby/library/net-http/http/put_spec.rb +++ b/spec/ruby/library/net-http/http/put_spec.rb @@ -19,6 +19,6 @@ describe "Net::HTTP#put" do end it "returns a Net::HTTPResponse" do - @http.put("/request", "test=test").should be_kind_of(Net::HTTPResponse) + @http.put("/request", "test=test").should.is_a?(Net::HTTPResponse) end end 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 7a0d2f1d72..81e71337bb 100644 --- a/spec/ruby/library/net-http/http/read_timeout_spec.rb +++ b/spec/ruby/library/net-http/http/read_timeout_spec.rb @@ -4,9 +4,9 @@ require 'net/http' describe "Net::HTTP#read_timeout" do it "returns the seconds to wait until reading one block" do net = Net::HTTP.new("localhost") - net.read_timeout.should eql(60) + net.read_timeout.should.eql?(60) net.read_timeout = 10 - net.read_timeout.should eql(10) + net.read_timeout.should.eql?(10) end end @@ -14,11 +14,11 @@ describe "Net::HTTP#read_timeout=" do it "sets the seconds to wait till the connection is open" do net = Net::HTTP.new("localhost") net.read_timeout = 10 - net.read_timeout.should eql(10) + net.read_timeout.should.eql?(10) end it "returns the newly set value" do net = Net::HTTP.new("localhost") - (net.read_timeout = 10).should eql(10) + (net.read_timeout = 10).should.eql?(10) end end 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 98025a14a1..1737e62439 100644 --- a/spec/ruby/library/net-http/http/request_get_spec.rb +++ b/spec/ruby/library/net-http/http/request_get_spec.rb @@ -1,8 +1,45 @@ require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' -require_relative 'shared/request_get' describe "Net::HTTP#request_get" do - it_behaves_like :net_http_request_get, :get2 + before :each do + NetHTTPSpecs.start_server + @http = Net::HTTP.start("localhost", NetHTTPSpecs.port) + end + + after :each do + @http.finish if @http.started? + NetHTTPSpecs.stop_server + end + + describe "when passed no block" do + it "sends a GET request to the passed path and returns the response" do + response = @http.request_get("/request") + response.body.should == "Request type: GET" + end + + it "returns a Net::HTTPResponse object" do + response = @http.request_get("/request") + response.should.is_a?(Net::HTTPResponse) + end + end + + describe "when passed a block" do + it "sends a GET request to the passed path and returns the response" do + response = @http.request_get("/request") {} + response.body.should == "Request type: GET" + end + + it "yields the response to the passed block" do + @http.request_get("/request") do |response| + response.body.should == "Request type: GET" + end + end + + it "returns a Net::HTTPResponse object" do + response = @http.request_get("/request") {} + response.should.is_a?(Net::HTTPResponse) + end + end end 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 8f514d4eee..7c46ebfc53 100644 --- a/spec/ruby/library/net-http/http/request_head_spec.rb +++ b/spec/ruby/library/net-http/http/request_head_spec.rb @@ -1,8 +1,45 @@ require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' -require_relative 'shared/request_head' describe "Net::HTTP#request_head" do - it_behaves_like :net_http_request_head, :request_head + before :each do + NetHTTPSpecs.start_server + @http = Net::HTTP.start("localhost", NetHTTPSpecs.port) + end + + after :each do + @http.finish if @http.started? + NetHTTPSpecs.stop_server + end + + describe "when passed no block" do + it "sends a head request to the passed path and returns the response" do + response = @http.request_head("/request") + response.body.should == nil + end + + it "returns a Net::HTTPResponse object" do + response = @http.request_head("/request") + response.should.is_a?(Net::HTTPResponse) + end + end + + describe "when passed a block" do + it "sends a head request to the passed path and returns the response" do + response = @http.request_head("/request") {} + response.body.should == nil + end + + it "yields the response to the passed block" do + @http.request_head("/request") do |response| + response.body.should == nil + end + end + + it "returns a Net::HTTPResponse object" do + response = @http.request_head("/request") {} + response.should.is_a?(Net::HTTPResponse) + end + end end 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 719bd5a7ee..8cfdd3469e 100644 --- a/spec/ruby/library/net-http/http/request_post_spec.rb +++ b/spec/ruby/library/net-http/http/request_post_spec.rb @@ -1,8 +1,45 @@ require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' -require_relative 'shared/request_post' describe "Net::HTTP#request_post" do - it_behaves_like :net_http_request_post, :request_post + before :each do + NetHTTPSpecs.start_server + @http = Net::HTTP.start("localhost", NetHTTPSpecs.port) + end + + after :each do + @http.finish if @http.started? + NetHTTPSpecs.stop_server + end + + describe "when passed no block" do + it "sends a post request to the passed path and returns the response" do + response = @http.request_post("/request", "test=test") + response.body.should == "Request type: POST" + end + + it "returns a Net::HTTPResponse object" do + response = @http.request_post("/request", "test=test") + response.should.is_a?(Net::HTTPResponse) + end + end + + describe "when passed a block" do + it "sends a post request to the passed path and returns the response" do + response = @http.request_post("/request", "test=test") {} + response.body.should == "Request type: POST" + end + + it "yields the response to the passed block" do + @http.request_post("/request", "test=test") do |response| + response.body.should == "Request type: POST" + end + end + + it "returns a Net::HTTPResponse object" do + response = @http.request_post("/request", "test=test") {} + response.should.is_a?(Net::HTTPResponse) + end + end end 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 9fcf3a98d6..b7388a21c8 100644 --- a/spec/ruby/library/net-http/http/request_put_spec.rb +++ b/spec/ruby/library/net-http/http/request_put_spec.rb @@ -1,8 +1,45 @@ require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' -require_relative 'shared/request_put' describe "Net::HTTP#request_put" do - it_behaves_like :net_http_request_put, :request_put + before :each do + NetHTTPSpecs.start_server + @http = Net::HTTP.start("localhost", NetHTTPSpecs.port) + end + + after :each do + @http.finish if @http.started? + NetHTTPSpecs.stop_server + end + + describe "when passed no block" do + it "sends a put request to the passed path and returns the response" do + response = @http.request_put("/request", "test=test") + response.body.should == "Request type: PUT" + end + + it "returns a Net::HTTPResponse object" do + response = @http.request_put("/request", "test=test") + response.should.is_a?(Net::HTTPResponse) + end + end + + describe "when passed a block" do + it "sends a put request to the passed path and returns the response" do + response = @http.request_put("/request", "test=test") {} + response.body.should == "Request type: PUT" + end + + it "yields the response to the passed block" do + @http.request_put("/request", "test=test") do |response| + response.body.should == "Request type: PUT" + end + end + + it "returns a Net::HTTPResponse object" do + response = @http.request_put("/request", "test=test") {} + response.should.is_a?(Net::HTTPResponse) + end + end end diff --git a/spec/ruby/library/net-http/http/request_spec.rb b/spec/ruby/library/net-http/http/request_spec.rb index 356e605b3b..e05ee96b55 100644 --- a/spec/ruby/library/net-http/http/request_spec.rb +++ b/spec/ruby/library/net-http/http/request_spec.rb @@ -19,7 +19,7 @@ describe "Net::HTTP#request" do response.body.should == "Request type: GET" response = @http.request(Net::HTTP::Head.new("/request"), "test=test") - response.body.should be_nil + response.body.should == nil response = @http.request(Net::HTTP::Post.new("/request"), "test=test") response.body.should == "Request type: POST" @@ -38,7 +38,7 @@ describe "Net::HTTP#request" do # TODO: Does not work? #response = @http.request(Net::HTTP::Options.new("/request"), "test=test") - #response.body.should be_nil + #response.body.should == nil response = @http.request(Net::HTTP::Propfind.new("/request"), "test=test") response.body.should == "Request type: PROPFIND" @@ -66,7 +66,7 @@ describe "Net::HTTP#request" do response.body.should == "test=test" response = @http.request(Net::HTTP::Head.new("/request/body"), "test=test") - response.body.should be_nil + response.body.should == nil response = @http.request(Net::HTTP::Post.new("/request/body"), "test=test") response.body.should == "test=test" @@ -85,7 +85,7 @@ describe "Net::HTTP#request" do # TODO: Does not work? #response = @http.request(Net::HTTP::Options.new("/request/body"), "test=test") - #response.body.should be_nil + #response.body.should == nil response = @http.request(Net::HTTP::Propfind.new("/request/body"), "test=test") response.body.should == "test=test" 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 53aef1ee58..0adc625979 100644 --- a/spec/ruby/library/net-http/http/request_types_spec.rb +++ b/spec/ruby/library/net-http/http/request_types_spec.rb @@ -11,11 +11,11 @@ describe "Net::HTTP::Get" do end it "has no Request Body" do - Net::HTTP::Get::REQUEST_HAS_BODY.should be_false + Net::HTTP::Get::REQUEST_HAS_BODY.should == false end it "has a Response Body" do - Net::HTTP::Get::RESPONSE_HAS_BODY.should be_true + Net::HTTP::Get::RESPONSE_HAS_BODY.should == true end end @@ -29,11 +29,11 @@ describe "Net::HTTP::Head" do end it "has no Request Body" do - Net::HTTP::Head::REQUEST_HAS_BODY.should be_false + Net::HTTP::Head::REQUEST_HAS_BODY.should == false end it "has no Response Body" do - Net::HTTP::Head::RESPONSE_HAS_BODY.should be_false + Net::HTTP::Head::RESPONSE_HAS_BODY.should == false end end @@ -47,11 +47,11 @@ describe "Net::HTTP::Post" do end it "has a Request Body" do - Net::HTTP::Post::REQUEST_HAS_BODY.should be_true + Net::HTTP::Post::REQUEST_HAS_BODY.should == true end it "has a Response Body" do - Net::HTTP::Post::RESPONSE_HAS_BODY.should be_true + Net::HTTP::Post::RESPONSE_HAS_BODY.should == true end end @@ -65,11 +65,11 @@ describe "Net::HTTP::Put" do end it "has a Request Body" do - Net::HTTP::Put::REQUEST_HAS_BODY.should be_true + Net::HTTP::Put::REQUEST_HAS_BODY.should == true end it "has a Response Body" do - Net::HTTP::Put::RESPONSE_HAS_BODY.should be_true + Net::HTTP::Put::RESPONSE_HAS_BODY.should == true end end @@ -83,11 +83,11 @@ describe "Net::HTTP::Delete" do end it "has no Request Body" do - Net::HTTP::Delete::REQUEST_HAS_BODY.should be_false + Net::HTTP::Delete::REQUEST_HAS_BODY.should == false end it "has a Response Body" do - Net::HTTP::Delete::RESPONSE_HAS_BODY.should be_true + Net::HTTP::Delete::RESPONSE_HAS_BODY.should == true end end @@ -101,11 +101,11 @@ describe "Net::HTTP::Options" do end it "has no Request Body" do - Net::HTTP::Options::REQUEST_HAS_BODY.should be_false + Net::HTTP::Options::REQUEST_HAS_BODY.should == false end it "has no Response Body" do - Net::HTTP::Options::RESPONSE_HAS_BODY.should be_true + Net::HTTP::Options::RESPONSE_HAS_BODY.should == true end end @@ -119,11 +119,11 @@ describe "Net::HTTP::Trace" do end it "has no Request Body" do - Net::HTTP::Trace::REQUEST_HAS_BODY.should be_false + Net::HTTP::Trace::REQUEST_HAS_BODY.should == false end it "has a Response Body" do - Net::HTTP::Trace::RESPONSE_HAS_BODY.should be_true + Net::HTTP::Trace::RESPONSE_HAS_BODY.should == true end end @@ -137,11 +137,11 @@ describe "Net::HTTP::Propfind" do end it "has a Request Body" do - Net::HTTP::Propfind::REQUEST_HAS_BODY.should be_true + Net::HTTP::Propfind::REQUEST_HAS_BODY.should == true end it "has a Response Body" do - Net::HTTP::Propfind::RESPONSE_HAS_BODY.should be_true + Net::HTTP::Propfind::RESPONSE_HAS_BODY.should == true end end @@ -155,11 +155,11 @@ describe "Net::HTTP::Proppatch" do end it "has a Request Body" do - Net::HTTP::Proppatch::REQUEST_HAS_BODY.should be_true + Net::HTTP::Proppatch::REQUEST_HAS_BODY.should == true end it "has a Response Body" do - Net::HTTP::Proppatch::RESPONSE_HAS_BODY.should be_true + Net::HTTP::Proppatch::RESPONSE_HAS_BODY.should == true end end @@ -173,11 +173,11 @@ describe "Net::HTTP::Mkcol" do end it "has a Request Body" do - Net::HTTP::Mkcol::REQUEST_HAS_BODY.should be_true + Net::HTTP::Mkcol::REQUEST_HAS_BODY.should == true end it "has a Response Body" do - Net::HTTP::Mkcol::RESPONSE_HAS_BODY.should be_true + Net::HTTP::Mkcol::RESPONSE_HAS_BODY.should == true end end @@ -191,11 +191,11 @@ describe "Net::HTTP::Copy" do end it "has no Request Body" do - Net::HTTP::Copy::REQUEST_HAS_BODY.should be_false + Net::HTTP::Copy::REQUEST_HAS_BODY.should == false end it "has a Response Body" do - Net::HTTP::Copy::RESPONSE_HAS_BODY.should be_true + Net::HTTP::Copy::RESPONSE_HAS_BODY.should == true end end @@ -209,11 +209,11 @@ describe "Net::HTTP::Move" do end it "has no Request Body" do - Net::HTTP::Move::REQUEST_HAS_BODY.should be_false + Net::HTTP::Move::REQUEST_HAS_BODY.should == false end it "has a Response Body" do - Net::HTTP::Move::RESPONSE_HAS_BODY.should be_true + Net::HTTP::Move::RESPONSE_HAS_BODY.should == true end end @@ -227,11 +227,11 @@ describe "Net::HTTP::Lock" do end it "has a Request Body" do - Net::HTTP::Lock::REQUEST_HAS_BODY.should be_true + Net::HTTP::Lock::REQUEST_HAS_BODY.should == true end it "has a Response Body" do - Net::HTTP::Lock::RESPONSE_HAS_BODY.should be_true + Net::HTTP::Lock::RESPONSE_HAS_BODY.should == true end end @@ -245,10 +245,10 @@ describe "Net::HTTP::Unlock" do end it "has a Request Body" do - Net::HTTP::Unlock::REQUEST_HAS_BODY.should be_true + Net::HTTP::Unlock::REQUEST_HAS_BODY.should == true end it "has a Response Body" do - Net::HTTP::Unlock::RESPONSE_HAS_BODY.should be_true + Net::HTTP::Unlock::RESPONSE_HAS_BODY.should == true end end 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 af35c068ce..e2dfc505b6 100644 --- a/spec/ruby/library/net-http/http/send_request_spec.rb +++ b/spec/ruby/library/net-http/http/send_request_spec.rb @@ -24,7 +24,7 @@ describe "Net::HTTP#send_request" do describe "when passed type, path" do it "sends a HTTP Request of the passed type to the passed path" do response = @http.send_request("HEAD", "/request") - response.body.should be_nil + response.body.should == nil (@methods - %w[POST PUT]).each do |method| response = @http.send_request(method, "/request") @@ -36,7 +36,7 @@ describe "Net::HTTP#send_request" do describe "when passed type, path, body" do it "sends a HTTP Request with the passed body" do response = @http.send_request("HEAD", "/request/body", "test=test") - response.body.should be_nil + response.body.should == nil @methods.each do |method| response = @http.send_request(method, "/request/body", "test=test") @@ -50,11 +50,11 @@ describe "Net::HTTP#send_request" do referer = 'https://www.ruby-lang.org/'.freeze response = @http.send_request("HEAD", "/request/header", "test=test", "referer" => referer) - response.body.should be_nil + response.body.should == nil @methods.each do |method| response = @http.send_request(method, "/request/header", "test=test", "referer" => referer) - response.body.should include({ "Referer" => referer }.inspect.delete("{}")) + 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 5ceecb39fb..491ac38b5d 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 @@ -19,7 +19,7 @@ describe "Net::HTTP#set_debug_output when passed io" do @http.set_debug_output(io) @http.start - io.string.should_not be_empty + io.string.should_not.empty? size = io.string.size @http.get("/") diff --git a/spec/ruby/library/net-http/http/shared/request_get.rb b/spec/ruby/library/net-http/http/shared/request_get.rb deleted file mode 100644 index d25f32049b..0000000000 --- a/spec/ruby/library/net-http/http/shared/request_get.rb +++ /dev/null @@ -1,41 +0,0 @@ -describe :net_http_request_get, shared: true do - before :each do - NetHTTPSpecs.start_server - @http = Net::HTTP.start("localhost", NetHTTPSpecs.port) - end - - after :each do - @http.finish if @http.started? - NetHTTPSpecs.stop_server - end - - describe "when passed no block" do - it "sends a GET request to the passed path and returns the response" do - response = @http.send(@method, "/request") - response.body.should == "Request type: GET" - end - - it "returns a Net::HTTPResponse object" do - response = @http.send(@method, "/request") - response.should be_kind_of(Net::HTTPResponse) - end - end - - describe "when passed a block" do - it "sends a GET request to the passed path and returns the response" do - response = @http.send(@method, "/request") {} - response.body.should == "Request type: GET" - end - - it "yields the response to the passed block" do - @http.send(@method, "/request") do |response| - response.body.should == "Request type: GET" - end - end - - it "returns a Net::HTTPResponse object" do - response = @http.send(@method, "/request") {} - response.should be_kind_of(Net::HTTPResponse) - end - end -end diff --git a/spec/ruby/library/net-http/http/shared/request_head.rb b/spec/ruby/library/net-http/http/shared/request_head.rb deleted file mode 100644 index 78b555884b..0000000000 --- a/spec/ruby/library/net-http/http/shared/request_head.rb +++ /dev/null @@ -1,41 +0,0 @@ -describe :net_http_request_head, shared: true do - before :each do - NetHTTPSpecs.start_server - @http = Net::HTTP.start("localhost", NetHTTPSpecs.port) - end - - after :each do - @http.finish if @http.started? - NetHTTPSpecs.stop_server - end - - describe "when passed no block" do - it "sends a head request to the passed path and returns the response" do - response = @http.send(@method, "/request") - response.body.should be_nil - end - - it "returns a Net::HTTPResponse object" do - response = @http.send(@method, "/request") - response.should be_kind_of(Net::HTTPResponse) - end - end - - describe "when passed a block" do - it "sends a head request to the passed path and returns the response" do - response = @http.send(@method, "/request") {} - response.body.should be_nil - end - - it "yields the response to the passed block" do - @http.send(@method, "/request") do |response| - response.body.should be_nil - end - end - - it "returns a Net::HTTPResponse object" do - response = @http.send(@method, "/request") {} - response.should be_kind_of(Net::HTTPResponse) - end - end -end diff --git a/spec/ruby/library/net-http/http/shared/request_post.rb b/spec/ruby/library/net-http/http/shared/request_post.rb deleted file mode 100644 index e832411c48..0000000000 --- a/spec/ruby/library/net-http/http/shared/request_post.rb +++ /dev/null @@ -1,41 +0,0 @@ -describe :net_http_request_post, shared: true do - before :each do - NetHTTPSpecs.start_server - @http = Net::HTTP.start("localhost", NetHTTPSpecs.port) - end - - after :each do - @http.finish if @http.started? - NetHTTPSpecs.stop_server - end - - describe "when passed no block" do - it "sends a post request to the passed path and returns the response" do - response = @http.send(@method, "/request", "test=test") - response.body.should == "Request type: POST" - end - - it "returns a Net::HTTPResponse object" do - response = @http.send(@method, "/request", "test=test") - response.should be_kind_of(Net::HTTPResponse) - end - end - - describe "when passed a block" do - it "sends a post request to the passed path and returns the response" do - response = @http.send(@method, "/request", "test=test") {} - response.body.should == "Request type: POST" - end - - it "yields the response to the passed block" do - @http.send(@method, "/request", "test=test") do |response| - response.body.should == "Request type: POST" - end - end - - it "returns a Net::HTTPResponse object" do - response = @http.send(@method, "/request", "test=test") {} - response.should be_kind_of(Net::HTTPResponse) - end - end -end diff --git a/spec/ruby/library/net-http/http/shared/request_put.rb b/spec/ruby/library/net-http/http/shared/request_put.rb deleted file mode 100644 index 3b902f4957..0000000000 --- a/spec/ruby/library/net-http/http/shared/request_put.rb +++ /dev/null @@ -1,41 +0,0 @@ -describe :net_http_request_put, shared: true do - before :each do - NetHTTPSpecs.start_server - @http = Net::HTTP.start("localhost", NetHTTPSpecs.port) - end - - after :each do - @http.finish if @http.started? - NetHTTPSpecs.stop_server - end - - describe "when passed no block" do - it "sends a put request to the passed path and returns the response" do - response = @http.send(@method, "/request", "test=test") - response.body.should == "Request type: PUT" - end - - it "returns a Net::HTTPResponse object" do - response = @http.send(@method, "/request", "test=test") - response.should be_kind_of(Net::HTTPResponse) - end - end - - describe "when passed a block" do - it "sends a put request to the passed path and returns the response" do - response = @http.send(@method, "/request", "test=test") {} - response.body.should == "Request type: PUT" - end - - it "yields the response to the passed block" do - @http.send(@method, "/request", "test=test") do |response| - response.body.should == "Request type: PUT" - end - end - - it "returns a Net::HTTPResponse object" do - response = @http.send(@method, "/request", "test=test") {} - response.should be_kind_of(Net::HTTPResponse) - end - end -end diff --git a/spec/ruby/library/net-http/http/shared/started.rb b/spec/ruby/library/net-http/http/shared/started.rb deleted file mode 100644 index 9ff6272c31..0000000000 --- a/spec/ruby/library/net-http/http/shared/started.rb +++ /dev/null @@ -1,26 +0,0 @@ -describe :net_http_started_p, shared: true do - before :each do - NetHTTPSpecs.start_server - @http = Net::HTTP.new("localhost", NetHTTPSpecs.port) - end - - after :each do - @http.finish if @http.started? - NetHTTPSpecs.stop_server - end - - it "returns true when self has been started" do - @http.start - @http.send(@method).should be_true - end - - it "returns false when self has not been started yet" do - @http.send(@method).should be_false - end - - it "returns false when self has been stopped again" do - @http.start - @http.finish - @http.send(@method).should be_false - end -end 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 deleted file mode 100644 index db3d6a986d..0000000000 --- a/spec/ruby/library/net-http/http/shared/version_1_1.rb +++ /dev/null @@ -1,6 +0,0 @@ -describe :net_http_version_1_1_p, shared: true do - it "returns the state of net/http 1.1 features" do - Net::HTTP.version_1_2 - Net::HTTP.send(@method).should be_false - end -end 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 deleted file mode 100644 index b044182c60..0000000000 --- a/spec/ruby/library/net-http/http/shared/version_1_2.rb +++ /dev/null @@ -1,6 +0,0 @@ -describe :net_http_version_1_2_p, shared: true do - it "returns the state of net/http 1.2 features" do - Net::HTTP.version_1_2 - Net::HTTP.send(@method).should be_true - end -end diff --git a/spec/ruby/library/net-http/http/start_spec.rb b/spec/ruby/library/net-http/http/start_spec.rb index 0ce3e79269..1aebc16f4d 100644 --- a/spec/ruby/library/net-http/http/start_spec.rb +++ b/spec/ruby/library/net-http/http/start_spec.rb @@ -22,13 +22,13 @@ describe "Net::HTTP.start" do end it "returns a new Net::HTTP object for the passed address and port" do - @http.should be_kind_of(Net::HTTP) + @http.should.is_a?(Net::HTTP) @http.address.should == "localhost" @http.port.should == @port end it "opens the tcp connection" do - @http.started?.should be_true + @http.started?.should == true end end @@ -41,19 +41,19 @@ describe "Net::HTTP.start" do yielded = false Net::HTTP.start("localhost", @port) do |net| yielded = true - net.should be_kind_of(Net::HTTP) + net.should.is_a?(Net::HTTP) end - yielded.should be_true + yielded.should == true end it "opens the tcp connection before yielding" do - Net::HTTP.start("localhost", @port) { |http| http.started?.should be_true } + Net::HTTP.start("localhost", @port) { |http| http.started?.should == true } end it "closes the tcp connection after yielding" do net = nil Net::HTTP.start("localhost", @port) { |x| net = x } - net.started?.should be_false + net.started?.should == false end end end @@ -70,18 +70,18 @@ describe "Net::HTTP#start" do end it "returns self" do - @http.start.should equal(@http) + @http.start.should.equal?(@http) end it "opens the tcp connection" do @http.start - @http.started?.should be_true + @http.started?.should == true end describe "when self has already been started" do it "raises an IOError" do @http.start - -> { @http.start }.should raise_error(IOError) + -> { @http.start }.should.raise(IOError) end end @@ -94,18 +94,18 @@ describe "Net::HTTP#start" do yielded = false @http.start do |http| yielded = true - http.should equal(@http) + http.should.equal?(@http) end - yielded.should be_true + yielded.should == true end it "opens the tcp connection before yielding" do - @http.start { |http| http.started?.should be_true } + @http.start { |http| http.started?.should == true } end it "closes the tcp connection after yielding" do @http.start { } - @http.started?.should be_false + @http.started?.should == false end end end diff --git a/spec/ruby/library/net-http/http/started_spec.rb b/spec/ruby/library/net-http/http/started_spec.rb index cbb82ceefa..a0b46fcbd2 100644 --- a/spec/ruby/library/net-http/http/started_spec.rb +++ b/spec/ruby/library/net-http/http/started_spec.rb @@ -1,8 +1,30 @@ require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' -require_relative 'shared/started' describe "Net::HTTP#started?" do - it_behaves_like :net_http_started_p, :started? + before :each do + NetHTTPSpecs.start_server + @http = Net::HTTP.new("localhost", NetHTTPSpecs.port) + end + + after :each do + @http.finish if @http.started? + NetHTTPSpecs.stop_server + end + + it "returns true when self has been started" do + @http.start + @http.started?.should == true + end + + it "returns false when self has not been started yet" do + @http.started?.should == false + end + + it "returns false when self has been stopped again" do + @http.start + @http.finish + @http.started?.should == false + end end diff --git a/spec/ruby/library/net-http/http/trace_spec.rb b/spec/ruby/library/net-http/http/trace_spec.rb index 9809d537c5..e0ff741b04 100644 --- a/spec/ruby/library/net-http/http/trace_spec.rb +++ b/spec/ruby/library/net-http/http/trace_spec.rb @@ -19,6 +19,6 @@ describe "Net::HTTP#trace" do end it "returns a Net::HTTPResponse" do - @http.trace("/request").should be_kind_of(Net::HTTPResponse) + @http.trace("/request").should.is_a?(Net::HTTPResponse) end end diff --git a/spec/ruby/library/net-http/http/unlock_spec.rb b/spec/ruby/library/net-http/http/unlock_spec.rb index adf0b49f65..cbfc803f09 100644 --- a/spec/ruby/library/net-http/http/unlock_spec.rb +++ b/spec/ruby/library/net-http/http/unlock_spec.rb @@ -19,6 +19,6 @@ describe "Net::HTTP#unlock" do end it "returns a Net::HTTPResponse" do - @http.unlock("/request", "test=test").should be_kind_of(Net::HTTPResponse) + @http.unlock("/request", "test=test").should.is_a?(Net::HTTPResponse) end end 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 912a62a8ba..b283655359 100644 --- a/spec/ruby/library/net-http/http/use_ssl_spec.rb +++ b/spec/ruby/library/net-http/http/use_ssl_spec.rb @@ -4,6 +4,6 @@ require 'net/http' describe "Net::HTTP#use_ssl?" do it "returns false" do http = Net::HTTP.new("localhost") - http.use_ssl?.should be_false + http.use_ssl?.should == false end end 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 34a4ac8a6b..7f87bf30f9 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,7 +1,9 @@ require_relative '../../../spec_helper' require 'net/http' -require_relative 'shared/version_1_1' describe "Net::HTTP.version_1_1?" do - it_behaves_like :net_http_version_1_1_p, :version_1_1? + it "returns the state of net/http 1.1 features" do + Net::HTTP.version_1_2 + Net::HTTP.version_1_1?.should == false + end end 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 e994511aea..73ca70ac7b 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,20 +1,22 @@ require_relative '../../../spec_helper' require 'net/http' -require_relative 'shared/version_1_2' describe "Net::HTTP.version_1_2" do it "turns on net/http 1.2 features" do Net::HTTP.version_1_2 - Net::HTTP.version_1_2?.should be_true - Net::HTTP.version_1_1?.should be_false + Net::HTTP.version_1_2?.should == true + Net::HTTP.version_1_1?.should == false end it "returns true" do - Net::HTTP.version_1_2.should be_true + Net::HTTP.version_1_2.should == true end end describe "Net::HTTP.version_1_2?" do - it_behaves_like :net_http_version_1_2_p, :version_1_2? + it "returns the state of net/http 1.2 features" do + Net::HTTP.version_1_2 + Net::HTTP.version_1_2?.should == true + end end 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 6c886499ca..96a761929e 100644 --- a/spec/ruby/library/net-http/httpgenericrequest/body_exist_spec.rb +++ b/spec/ruby/library/net-http/httpgenericrequest/body_exist_spec.rb @@ -4,10 +4,10 @@ require 'net/http' describe "Net::HTTPGenericRequest#body_exist?" do it "returns true when the response is expected to have a body" do request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path") - request.body_exist?.should be_true + request.body_exist?.should == true request = Net::HTTPGenericRequest.new("POST", true, false, "/some/path") - request.body_exist?.should be_false + request.body_exist?.should == false end describe "when $VERBOSE is true" do diff --git a/spec/ruby/library/net-http/httpgenericrequest/body_spec.rb b/spec/ruby/library/net-http/httpgenericrequest/body_spec.rb index 5f7315f303..63cda994e5 100644 --- a/spec/ruby/library/net-http/httpgenericrequest/body_spec.rb +++ b/spec/ruby/library/net-http/httpgenericrequest/body_spec.rb @@ -5,7 +5,7 @@ require "stringio" describe "Net::HTTPGenericRequest#body" do it "returns self's request body" do request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path") - request.body.should be_nil + request.body.should == nil request.body = "Some Content" request.body.should == "Some Content" @@ -25,6 +25,6 @@ describe "Net::HTTPGenericRequest#body=" do it "sets self's body stream to nil" do @request.body_stream = StringIO.new("") @request.body = "Some Content" - @request.body_stream.should be_nil + @request.body_stream.should == nil end end 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 dea1c8c883..3237dbb861 100644 --- a/spec/ruby/library/net-http/httpgenericrequest/body_stream_spec.rb +++ b/spec/ruby/library/net-http/httpgenericrequest/body_stream_spec.rb @@ -5,11 +5,11 @@ require "stringio" describe "Net::HTTPGenericRequest#body_stream" do it "returns self's body stream Object" do request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path") - request.body_stream.should be_nil + request.body_stream.should == nil stream = StringIO.new("test") request.body_stream = stream - request.body_stream.should equal(stream) + request.body_stream.should.equal?(stream) end end @@ -21,12 +21,12 @@ describe "Net::HTTPGenericRequest#body_stream=" do it "sets self's body stream to the passed Object" do @request.body_stream = @stream - @request.body_stream.should equal(@stream) + @request.body_stream.should.equal?(@stream) end it "sets self's body to nil" do @request.body = "Some Content" @request.body_stream = @stream - @request.body.should be_nil + @request.body.should == nil end end diff --git a/spec/ruby/library/net-http/httpgenericrequest/exec_spec.rb b/spec/ruby/library/net-http/httpgenericrequest/exec_spec.rb index 0912e5a71f..0ccf80e3b6 100644 --- a/spec/ruby/library/net-http/httpgenericrequest/exec_spec.rb +++ b/spec/ruby/library/net-http/httpgenericrequest/exec_spec.rb @@ -31,7 +31,7 @@ describe "Net::HTTPGenericRequest#exec when passed socket, version, path" do end describe "when a request body is set" do - ruby_version_is ""..."3.5" do + 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" @@ -64,7 +64,7 @@ describe "Net::HTTPGenericRequest#exec when passed socket, version, path" do end describe "when a body stream is set" do - ruby_version_is ""..."3.5" do + 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") @@ -129,7 +129,7 @@ describe "Net::HTTPGenericRequest#exec when passed socket, version, path" do "Content-Type" => "text/html") request.body_stream = StringIO.new("Some Content") - -> { request.exec(@buffered_socket, "1.1", "/some/other/path") }.should raise_error(ArgumentError) + -> { request.exec(@buffered_socket, "1.1", "/some/other/path") }.should.raise(ArgumentError) end end end 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 1713b59baf..ba836e8130 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 @@ -4,9 +4,9 @@ require 'net/http' describe "Net::HTTPGenericRequest#request_body_permitted?" do it "returns true when the request is expected to have a body" do request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path") - request.request_body_permitted?.should be_true + request.request_body_permitted?.should == true request = Net::HTTPGenericRequest.new("POST", false, true, "/some/path") - request.request_body_permitted?.should be_false + request.request_body_permitted?.should == false end end 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 2f0751c344..067500f60d 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 @@ -4,9 +4,9 @@ require 'net/http' describe "Net::HTTPGenericRequest#response_body_permitted?" do it "returns true when the response is expected to have a body" do request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path") - request.response_body_permitted?.should be_true + request.response_body_permitted?.should == true request = Net::HTTPGenericRequest.new("POST", true, false, "/some/path") - request.response_body_permitted?.should be_false + request.response_body_permitted?.should == false end end 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 358aa6cde3..f241d8d698 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 @@ -13,9 +13,9 @@ describe "Net::HTTPGenericRequest#set_body_internal when passed string" do it "raises an ArgumentError when the body or body_stream of self have already been set" do @request.body = "Some Content" - -> { @request.set_body_internal("Some other Content") }.should raise_error(ArgumentError) + -> { @request.set_body_internal("Some other Content") }.should.raise(ArgumentError) @request.body_stream = "Some Content" - -> { @request.set_body_internal("Some other Content") }.should raise_error(ArgumentError) + -> { @request.set_body_internal("Some other Content") }.should.raise(ArgumentError) end end 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 64a5cae89e..c009e9f7ea 100644 --- a/spec/ruby/library/net-http/httpheader/canonical_each_spec.rb +++ b/spec/ruby/library/net-http/httpheader/canonical_each_spec.rb @@ -1,8 +1,9 @@ require_relative '../../../spec_helper' require 'net/http' -require_relative 'fixtures/classes' -require_relative 'shared/each_capitalized' describe "Net::HTTPHeader#canonical_each" do - it_behaves_like :net_httpheader_each_capitalized, :canonical_each + it "is an alias of Net::HTTPHeader#each_capitalized" do + Net::HTTPHeader.instance_method(:canonical_each).should == + Net::HTTPHeader.instance_method(:each_capitalized) + end end diff --git a/spec/ruby/library/net-http/httpheader/chunked_spec.rb b/spec/ruby/library/net-http/httpheader/chunked_spec.rb index b32a0aab38..4da218ae25 100644 --- a/spec/ruby/library/net-http/httpheader/chunked_spec.rb +++ b/spec/ruby/library/net-http/httpheader/chunked_spec.rb @@ -8,15 +8,15 @@ describe "Net::HTTPHeader#chunked?" do end it "returns true if the 'Transfer-Encoding' header entry is set to chunked" do - @headers.chunked?.should be_false + @headers.chunked?.should == false @headers["Transfer-Encoding"] = "bla" - @headers.chunked?.should be_false + @headers.chunked?.should == false @headers["Transfer-Encoding"] = "blachunkedbla" - @headers.chunked?.should be_false + @headers.chunked?.should == false @headers["Transfer-Encoding"] = "chunked" - @headers.chunked?.should be_true + @headers.chunked?.should == true end end 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 f05c5f8d8b..c66d5673c1 100644 --- a/spec/ruby/library/net-http/httpheader/content_length_spec.rb +++ b/spec/ruby/library/net-http/httpheader/content_length_spec.rb @@ -8,23 +8,23 @@ describe "Net::HTTPHeader#content_length" do end it "returns nil if no 'Content-Length' header entry is set" do - @headers.content_length.should be_nil + @headers.content_length.should == nil end it "raises a Net::HTTPHeaderSyntaxError when the 'Content-Length' header entry has an invalid format" do @headers["Content-Length"] = "invalid" - -> { @headers.content_length }.should raise_error(Net::HTTPHeaderSyntaxError) + -> { @headers.content_length }.should.raise(Net::HTTPHeaderSyntaxError) end it "returns the value of the 'Content-Length' header entry as an Integer" do @headers["Content-Length"] = "123" - @headers.content_length.should eql(123) + @headers.content_length.should.eql?(123) @headers["Content-Length"] = "123valid" - @headers.content_length.should eql(123) + @headers.content_length.should.eql?(123) @headers["Content-Length"] = "valid123" - @headers.content_length.should eql(123) + @headers.content_length.should.eql?(123) end end @@ -36,7 +36,7 @@ describe "Net::HTTPHeader#content_length=" do it "removes the 'Content-Length' entry if passed false or nil" do @headers["Content-Length"] = "123" @headers.content_length = nil - @headers["Content-Length"].should be_nil + @headers["Content-Length"].should == nil end it "sets the 'Content-Length' entry to the passed value" do 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 09737141a5..3635fb3f1b 100644 --- a/spec/ruby/library/net-http/httpheader/content_range_spec.rb +++ b/spec/ruby/library/net-http/httpheader/content_range_spec.rb @@ -16,17 +16,17 @@ describe "Net::HTTPHeader#content_range" do end it "returns nil when there is no 'Content-Range' header entry" do - @headers.content_range.should be_nil + @headers.content_range.should == nil end it "raises a Net::HTTPHeaderSyntaxError when the 'Content-Range' has an invalid format" do @headers["Content-Range"] = "invalid" - -> { @headers.content_range }.should raise_error(Net::HTTPHeaderSyntaxError) + -> { @headers.content_range }.should.raise(Net::HTTPHeaderSyntaxError) @headers["Content-Range"] = "bytes 123-abc" - -> { @headers.content_range }.should raise_error(Net::HTTPHeaderSyntaxError) + -> { @headers.content_range }.should.raise(Net::HTTPHeaderSyntaxError) @headers["Content-Range"] = "bytes abc-123" - -> { @headers.content_range }.should raise_error(Net::HTTPHeaderSyntaxError) + -> { @headers.content_range }.should.raise(Net::HTTPHeaderSyntaxError) end end 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 a6e1ae1093..0ee43a6942 100644 --- a/spec/ruby/library/net-http/httpheader/content_type_spec.rb +++ b/spec/ruby/library/net-http/httpheader/content_type_spec.rb @@ -1,7 +1,6 @@ require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' -require_relative 'shared/set_content_type' describe "Net::HTTPHeader#content_type" do before :each do @@ -17,10 +16,13 @@ describe "Net::HTTPHeader#content_type" do end it "returns nil if the 'Content-Type' header entry does not exist" do - @headers.content_type.should be_nil + @headers.content_type.should == nil end end describe "Net::HTTPHeader#content_type=" do - it_behaves_like :net_httpheader_set_content_type, :content_type= + it "is an alias of Net::HTTPHeader#set_content_type" do + Net::HTTPHeader.instance_method(:content_type=).should == + Net::HTTPHeader.instance_method(:set_content_type) + end end diff --git a/spec/ruby/library/net-http/httpheader/delete_spec.rb b/spec/ruby/library/net-http/httpheader/delete_spec.rb index 8d929dbd86..09bae65a13 100644 --- a/spec/ruby/library/net-http/httpheader/delete_spec.rb +++ b/spec/ruby/library/net-http/httpheader/delete_spec.rb @@ -11,8 +11,8 @@ describe "Net::HTTPHeader#delete when passed key" do @headers["My-Header"] = "test" @headers.delete("My-Header") - @headers["My-Header"].should be_nil - @headers.size.should eql(0) + @headers["My-Header"].should == nil + @headers.size.should.eql?(0) end it "returns the removed values" do @@ -24,7 +24,7 @@ describe "Net::HTTPHeader#delete when passed key" do @headers["My-Header"] = "test" @headers.delete("my-header") - @headers["My-Header"].should be_nil - @headers.size.should eql(0) + @headers["My-Header"].should == nil + @headers.size.should.eql?(0) end end 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 27713577f9..54874c0535 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 @@ -23,7 +23,7 @@ describe "Net::HTTPHeader#each_capitalized_name" do describe "when passed no block" do it "returns an Enumerator" do enumerator = @headers.each_capitalized_name - enumerator.should be_an_instance_of(Enumerator) + enumerator.should.instance_of?(Enumerator) res = [] enumerator.each do |key| 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 1e853995ea..e24e778238 100644 --- a/spec/ruby/library/net-http/httpheader/each_capitalized_spec.rb +++ b/spec/ruby/library/net-http/httpheader/each_capitalized_spec.rb @@ -1,8 +1,35 @@ require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' -require_relative 'shared/each_capitalized' describe "Net::HTTPHeader#each_capitalized" do - it_behaves_like :net_httpheader_each_capitalized, :each_capitalized + before :each do + @headers = NetHTTPHeaderSpecs::Example.new + @headers["my-header"] = "test" + @headers.add_field("my-Other-Header", "a") + @headers.add_field("My-Other-header", "b") + end + + describe "when passed a block" do + it "yields each header entry to the passed block (capitalized keys, values joined)" do + res = [] + @headers.each_capitalized do |key, value| + res << [key, value] + end + res.sort.should == [["My-Header", "test"], ["My-Other-Header", "a, b"]] + end + end + + describe "when passed no block" do + it "returns an Enumerator" do + enumerator = @headers.each_capitalized + enumerator.should.instance_of?(Enumerator) + + res = [] + enumerator.each do |*key| + res << key + end + res.sort.should == [["My-Header", "test"], ["My-Other-Header", "a, b"]] + end + end end 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 869feebacf..63c1106d18 100644 --- a/spec/ruby/library/net-http/httpheader/each_header_spec.rb +++ b/spec/ruby/library/net-http/httpheader/each_header_spec.rb @@ -1,8 +1,35 @@ require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' -require_relative 'shared/each_header' describe "Net::HTTPHeader#each_header" do - it_behaves_like :net_httpheader_each_header, :each_header + before :each do + @headers = NetHTTPHeaderSpecs::Example.new + @headers["My-Header"] = "test" + @headers.add_field("My-Other-Header", "a") + @headers.add_field("My-Other-Header", "b") + end + + describe "when passed a block" do + it "yields each header entry to the passed block (keys in lower case, values joined)" do + res = [] + @headers.each_header do |key, value| + res << [key, value] + end + res.sort.should == [["my-header", "test"], ["my-other-header", "a, b"]] + end + end + + describe "when passed no block" do + it "returns an Enumerator" do + enumerator = @headers.each_header + enumerator.should.instance_of?(Enumerator) + + res = [] + enumerator.each do |*key| + res << key + end + res.sort.should == [["my-header", "test"], ["my-other-header", "a, b"]] + end + end end 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 1ad145629f..a5635da5db 100644 --- a/spec/ruby/library/net-http/httpheader/each_key_spec.rb +++ b/spec/ruby/library/net-http/httpheader/each_key_spec.rb @@ -1,8 +1,35 @@ require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' -require_relative 'shared/each_name' describe "Net::HTTPHeader#each_key" do - it_behaves_like :net_httpheader_each_name, :each_key + before :each do + @headers = NetHTTPHeaderSpecs::Example.new + @headers["My-Header"] = "test" + @headers.add_field("My-Other-Header", "a") + @headers.add_field("My-Other-Header", "b") + end + + describe "when passed a block" do + it "yields each header key to the passed block (keys in lower case)" do + res = [] + @headers.each_key do |key| + res << key + end + res.sort.should == ["my-header", "my-other-header"] + end + end + + describe "when passed no block" do + it "returns an Enumerator" do + enumerator = @headers.each_key + enumerator.should.instance_of?(Enumerator) + + res = [] + enumerator.each do |key| + res << key + end + res.sort.should == ["my-header", "my-other-header"] + end + end end 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 f819bd989d..02f9761f80 100644 --- a/spec/ruby/library/net-http/httpheader/each_name_spec.rb +++ b/spec/ruby/library/net-http/httpheader/each_name_spec.rb @@ -1,8 +1,10 @@ require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' -require_relative 'shared/each_name' describe "Net::HTTPHeader#each_name" do - it_behaves_like :net_httpheader_each_name, :each_name + it "is an alias of Net::HTTPHeader#each_key" do + Net::HTTPHeader.instance_method(:each_name).should == + Net::HTTPHeader.instance_method(:each_key) + end end diff --git a/spec/ruby/library/net-http/httpheader/each_spec.rb b/spec/ruby/library/net-http/httpheader/each_spec.rb index ff37249d0a..e219609b67 100644 --- a/spec/ruby/library/net-http/httpheader/each_spec.rb +++ b/spec/ruby/library/net-http/httpheader/each_spec.rb @@ -1,8 +1,9 @@ require_relative '../../../spec_helper' require 'net/http' -require_relative 'fixtures/classes' -require_relative 'shared/each_header' describe "Net::HTTPHeader#each" do - it_behaves_like :net_httpheader_each_header, :each + it "is an alias of Net::HTTPHeader#each_header" do + Net::HTTPHeader.instance_method(:each).should == + Net::HTTPHeader.instance_method(:each_header) + end end 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 b71df58c65..55ba4c1ef8 100644 --- a/spec/ruby/library/net-http/httpheader/each_value_spec.rb +++ b/spec/ruby/library/net-http/httpheader/each_value_spec.rb @@ -23,7 +23,7 @@ describe "Net::HTTPHeader#each_value" do describe "when passed no block" do it "returns an Enumerator" do enumerator = @headers.each_value - enumerator.should be_an_instance_of(Enumerator) + enumerator.should.instance_of?(Enumerator) res = [] enumerator.each do |key| 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 1003c41af9..f12f8494db 100644 --- a/spec/ruby/library/net-http/httpheader/element_reference_spec.rb +++ b/spec/ruby/library/net-http/httpheader/element_reference_spec.rb @@ -33,7 +33,7 @@ describe "Net::HTTPHeader#[] when passed key" do end it "returns nil for non-existing entries" do - @headers["My-Header"].should be_nil - @headers["My-Other-Header"].should be_nil + @headers["My-Header"].should == nil + @headers["My-Other-Header"].should == nil end end 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 376df2f977..633fe18b2e 100644 --- a/spec/ruby/library/net-http/httpheader/element_set_spec.rb +++ b/spec/ruby/library/net-http/httpheader/element_set_spec.rb @@ -26,16 +26,16 @@ describe "Net::HTTPHeader#[]= when passed key, value" do @headers['MY-HEADER'] = "last one" @headers["My-Header"].should == "last one" - @headers.size.should eql(1) + @headers.size.should.eql?(1) end it "removes the header entry with the passed key when the value is false or nil" do @headers['My-Header'] = "test" @headers['My-Header'] = nil - @headers['My-Header'].should be_nil + @headers['My-Header'].should == nil @headers['My-Header'] = "test" @headers['My-Header'] = false - @headers['My-Header'].should be_nil + @headers['My-Header'].should == nil end end diff --git a/spec/ruby/library/net-http/httpheader/fetch_spec.rb b/spec/ruby/library/net-http/httpheader/fetch_spec.rb index 58c69c0377..d1c273dada 100644 --- a/spec/ruby/library/net-http/httpheader/fetch_spec.rb +++ b/spec/ruby/library/net-http/httpheader/fetch_spec.rb @@ -25,7 +25,7 @@ describe "Net::HTTPHeader#fetch" do end it "returns nil when there is no entry for the passed key" do - -> { @headers.fetch("my-header") }.should raise_error(IndexError) + -> { @headers.fetch("my-header") }.should.raise(IndexError) end end 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 acd913f53a..8d4974cde3 100644 --- a/spec/ruby/library/net-http/httpheader/form_data_spec.rb +++ b/spec/ruby/library/net-http/httpheader/form_data_spec.rb @@ -1,8 +1,10 @@ require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' -require_relative 'shared/set_form_data' describe "Net::HTTPHeader#form_data=" do - it_behaves_like :net_httpheader_set_form_data, :form_data= + it "is an alias of Net::HTTPHeader#set_form_data" do + Net::HTTPHeader.instance_method(:form_data=).should == + Net::HTTPHeader.instance_method(:set_form_data) + end end 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 0278bcede2..76da63bc31 100644 --- a/spec/ruby/library/net-http/httpheader/get_fields_spec.rb +++ b/spec/ruby/library/net-http/httpheader/get_fields_spec.rb @@ -26,8 +26,8 @@ describe "Net::HTTPHeader#get_fields when passed key" do end it "returns nil for non-existing header entries" do - @headers.get_fields("My-Header").should be_nil - @headers.get_fields("My-Other-header").should be_nil + @headers.get_fields("My-Header").should == nil + @headers.get_fields("My-Other-header").should == nil end it "is case-insensitive" do diff --git a/spec/ruby/library/net-http/httpheader/key_spec.rb b/spec/ruby/library/net-http/httpheader/key_spec.rb index 2b7aeb9c2a..65662591eb 100644 --- a/spec/ruby/library/net-http/httpheader/key_spec.rb +++ b/spec/ruby/library/net-http/httpheader/key_spec.rb @@ -8,14 +8,14 @@ describe "Net::HTTPHeader#key? when passed key" do end it "returns true if the header entry with the passed key exists" do - @headers.key?("My-Header").should be_false + @headers.key?("My-Header").should == false @headers["My-Header"] = "test" - @headers.key?("My-Header").should be_true + @headers.key?("My-Header").should == true end it "is case-insensitive" do @headers["My-Header"] = "test" - @headers.key?("my-header").should be_true - @headers.key?("MY-HEADER").should be_true + @headers.key?("my-header").should == true + @headers.key?("MY-HEADER").should == true end end diff --git a/spec/ruby/library/net-http/httpheader/length_spec.rb b/spec/ruby/library/net-http/httpheader/length_spec.rb index 57e32742e4..1f059719e9 100644 --- a/spec/ruby/library/net-http/httpheader/length_spec.rb +++ b/spec/ruby/library/net-http/httpheader/length_spec.rb @@ -1,8 +1,9 @@ require_relative '../../../spec_helper' require 'net/http' -require_relative 'fixtures/classes' -require_relative 'shared/size' describe "Net::HTTPHeader#length" do - it_behaves_like :net_httpheader_size, :length + it "is an alias of Net::HTTPHeader#size" do + Net::HTTPHeader.instance_method(:length).should == + Net::HTTPHeader.instance_method(:size) + end end 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 4dd551d8f4..af7d3e05a3 100644 --- a/spec/ruby/library/net-http/httpheader/main_type_spec.rb +++ b/spec/ruby/library/net-http/httpheader/main_type_spec.rb @@ -19,6 +19,6 @@ describe "Net::HTTPHeader#main_type" do end it "returns nil if the 'Content-Type' header entry does not exist" do - @headers.main_type.should be_nil + @headers.main_type.should == nil end end 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 77323ac872..34db7e6126 100644 --- a/spec/ruby/library/net-http/httpheader/range_length_spec.rb +++ b/spec/ruby/library/net-http/httpheader/range_length_spec.rb @@ -9,24 +9,24 @@ describe "Net::HTTPHeader#range_length" do it "returns the length of the Range represented by the 'Content-Range' header entry" do @headers["Content-Range"] = "bytes 0-499/1234" - @headers.range_length.should eql(500) + @headers.range_length.should.eql?(500) @headers["Content-Range"] = "bytes 500-1233/1234" - @headers.range_length.should eql(734) + @headers.range_length.should.eql?(734) end it "returns nil when there is no 'Content-Range' header entry" do - @headers.range_length.should be_nil + @headers.range_length.should == nil end it "raises a Net::HTTPHeaderSyntaxError when the 'Content-Range' has an invalid format" do @headers["Content-Range"] = "invalid" - -> { @headers.range_length }.should raise_error(Net::HTTPHeaderSyntaxError) + -> { @headers.range_length }.should.raise(Net::HTTPHeaderSyntaxError) @headers["Content-Range"] = "bytes 123-abc" - -> { @headers.range_length }.should raise_error(Net::HTTPHeaderSyntaxError) + -> { @headers.range_length }.should.raise(Net::HTTPHeaderSyntaxError) @headers["Content-Range"] = "bytes abc-123" - -> { @headers.range_length }.should raise_error(Net::HTTPHeaderSyntaxError) + -> { @headers.range_length }.should.raise(Net::HTTPHeaderSyntaxError) end end diff --git a/spec/ruby/library/net-http/httpheader/range_spec.rb b/spec/ruby/library/net-http/httpheader/range_spec.rb index 2de80a825e..8944e2d5f2 100644 --- a/spec/ruby/library/net-http/httpheader/range_spec.rb +++ b/spec/ruby/library/net-http/httpheader/range_spec.rb @@ -1,7 +1,6 @@ require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' -require_relative 'shared/set_range' describe "Net::HTTPHeader#range" do before :each do @@ -23,26 +22,29 @@ describe "Net::HTTPHeader#range" do end it "returns nil when there is no 'Range' header entry" do - @headers.range.should be_nil + @headers.range.should == nil end it "raises a Net::HTTPHeaderSyntaxError when the 'Range' has an invalid format" do @headers["Range"] = "invalid" - -> { @headers.range }.should raise_error(Net::HTTPHeaderSyntaxError) + -> { @headers.range }.should.raise(Net::HTTPHeaderSyntaxError) @headers["Range"] = "bytes 123-abc" - -> { @headers.range }.should raise_error(Net::HTTPHeaderSyntaxError) + -> { @headers.range }.should.raise(Net::HTTPHeaderSyntaxError) @headers["Range"] = "bytes abc-123" - -> { @headers.range }.should raise_error(Net::HTTPHeaderSyntaxError) + -> { @headers.range }.should.raise(Net::HTTPHeaderSyntaxError) end it "raises a Net::HTTPHeaderSyntaxError when the 'Range' was not specified" do @headers["Range"] = "bytes=-" - -> { @headers.range }.should raise_error(Net::HTTPHeaderSyntaxError) + -> { @headers.range }.should.raise(Net::HTTPHeaderSyntaxError) end end describe "Net::HTTPHeader#range=" do - it_behaves_like :net_httpheader_set_range, :range= + it "is an alias of Net::HTTPHeader#set_range" do + Net::HTTPHeader.instance_method(:range=).should == + Net::HTTPHeader.instance_method(:set_range) + end end 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 7ec4f90b8e..3674061626 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,8 +1,22 @@ require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' -require_relative 'shared/set_content_type' describe "Net::HTTPHeader#set_content_type" do - it_behaves_like :net_httpheader_set_content_type, :set_content_type + describe "when passed type, params" do + before :each do + @headers = NetHTTPHeaderSpecs::Example.new + end + + it "sets the 'Content-Type' header entry based on the passed type and params" do + @headers.set_content_type("text/html") + @headers["Content-Type"].should == "text/html" + + @headers.set_content_type("text/html", "charset" => "utf-8") + @headers["Content-Type"].should == "text/html; charset=utf-8" + + @headers.set_content_type("text/html", "charset" => "utf-8", "rubyspec" => "rocks") + @headers["Content-Type"].split(/; /).sort.should == %w[charset=utf-8 rubyspec=rocks text/html] + end + end end 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 7aac19f045..093dc100d5 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,8 +1,31 @@ require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' -require_relative 'shared/set_form_data' describe "Net::HTTPHeader#set_form_data" do - it_behaves_like :net_httpheader_set_form_data, :set_form_data + before :each do + @headers = NetHTTPHeaderSpecs::Example.new + end + + describe "when passed params" do + it "automatically set the 'Content-Type' to 'application/x-www-form-urlencoded'" do + @headers.set_form_data("cmd" => "search", "q" => "ruby", "max" => "50") + @headers["Content-Type"].should == "application/x-www-form-urlencoded" + end + + it "sets self's body based on the passed form parameters" do + @headers.set_form_data("cmd" => "search", "q" => "ruby", "max" => "50") + @headers.body.split("&").sort.should == ["cmd=search", "max=50", "q=ruby"] + end + end + + describe "when passed params, separator" do + it "sets self's body based on the passed form parameters and the passed separator" do + @headers.set_form_data({"cmd" => "search", "q" => "ruby", "max" => "50"}, "&") + @headers.body.split("&").sort.should == ["cmd=search", "max=50", "q=ruby"] + + @headers.set_form_data({"cmd" => "search", "q" => "ruby", "max" => "50"}, ";") + @headers.body.split(";").sort.should == ["cmd=search", "max=50", "q=ruby"] + end + end end 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 0f98de55e6..d48ed1897a 100644 --- a/spec/ruby/library/net-http/httpheader/set_range_spec.rb +++ b/spec/ruby/library/net-http/httpheader/set_range_spec.rb @@ -1,8 +1,93 @@ require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' -require_relative 'shared/set_range' describe "Net::HTTPHeader#set_range" do - it_behaves_like :net_httpheader_set_range, :set_range + before :each do + @headers = NetHTTPHeaderSpecs::Example.new + end + + describe "when passed nil" do + it "returns nil" do + @headers.set_range(nil).should == nil + end + + it "deletes the 'Range' header entry" do + @headers["Range"] = "bytes 0-499/1234" + @headers.set_range(nil) + @headers["Range"].should == nil + end + end + + describe "when passed Numeric" do + it "sets the 'Range' header entry based on the passed Numeric" do + @headers.set_range(10) + @headers["Range"].should == "bytes=0-9" + + @headers.set_range(-10) + @headers["Range"].should == "bytes=-10" + + @headers.set_range(10.9) + @headers["Range"].should == "bytes=0-9" + end + end + + describe "when passed Range" do + it "sets the 'Range' header entry based on the passed Range" do + @headers.set_range(10..200) + @headers["Range"].should == "bytes=10-200" + + @headers.set_range(1..5) + @headers["Range"].should == "bytes=1-5" + + @headers.set_range(1...5) + @headers["Range"].should == "bytes=1-4" + + @headers.set_range(234..567) + @headers["Range"].should == "bytes=234-567" + + @headers.set_range(-5..-1) + @headers["Range"].should == "bytes=-5" + + @headers.set_range(1..-1) + @headers["Range"].should == "bytes=1-" + end + + it "raises a Net::HTTPHeaderSyntaxError when the first Range element is negative" do + -> { @headers.set_range(-10..5) }.should.raise(Net::HTTPHeaderSyntaxError) + end + + it "raises a Net::HTTPHeaderSyntaxError when the last Range element is negative" do + -> { @headers.set_range(10..-5) }.should.raise(Net::HTTPHeaderSyntaxError) + end + + it "raises a Net::HTTPHeaderSyntaxError when the last Range element is smaller than the first" do + -> { @headers.set_range(10..5) }.should.raise(Net::HTTPHeaderSyntaxError) + end + end + + describe "when passed start, end" do + it "sets the 'Range' header entry based on the passed start and length values" do + @headers.set_range(10, 200) + @headers["Range"].should == "bytes=10-209" + + @headers.set_range(1, 5) + @headers["Range"].should == "bytes=1-5" + + @headers.set_range(234, 567) + @headers["Range"].should == "bytes=234-800" + end + + it "raises a Net::HTTPHeaderSyntaxError when start is negative" do + -> { @headers.set_range(-10, 5) }.should.raise(Net::HTTPHeaderSyntaxError) + end + + it "raises a Net::HTTPHeaderSyntaxError when start + length is negative" do + -> { @headers.set_range(10, -15) }.should.raise(Net::HTTPHeaderSyntaxError) + end + + it "raises a Net::HTTPHeaderSyntaxError when length is negative" do + -> { @headers.set_range(10, -4) }.should.raise(Net::HTTPHeaderSyntaxError) + end + end end diff --git a/spec/ruby/library/net-http/httpheader/shared/each_capitalized.rb b/spec/ruby/library/net-http/httpheader/shared/each_capitalized.rb deleted file mode 100644 index 3bac409876..0000000000 --- a/spec/ruby/library/net-http/httpheader/shared/each_capitalized.rb +++ /dev/null @@ -1,31 +0,0 @@ -describe :net_httpheader_each_capitalized, shared: true do - before :each do - @headers = NetHTTPHeaderSpecs::Example.new - @headers["my-header"] = "test" - @headers.add_field("my-Other-Header", "a") - @headers.add_field("My-Other-header", "b") - end - - describe "when passed a block" do - it "yields each header entry to the passed block (capitalized keys, values joined)" do - res = [] - @headers.send(@method) do |key, value| - res << [key, value] - end - res.sort.should == [["My-Header", "test"], ["My-Other-Header", "a, b"]] - end - end - - describe "when passed no block" do - it "returns an Enumerator" do - enumerator = @headers.send(@method) - enumerator.should be_an_instance_of(Enumerator) - - res = [] - enumerator.each do |*key| - res << key - end - res.sort.should == [["My-Header", "test"], ["My-Other-Header", "a, b"]] - end - end -end diff --git a/spec/ruby/library/net-http/httpheader/shared/each_header.rb b/spec/ruby/library/net-http/httpheader/shared/each_header.rb deleted file mode 100644 index 6bf3a6ddfe..0000000000 --- a/spec/ruby/library/net-http/httpheader/shared/each_header.rb +++ /dev/null @@ -1,31 +0,0 @@ -describe :net_httpheader_each_header, shared: true do - before :each do - @headers = NetHTTPHeaderSpecs::Example.new - @headers["My-Header"] = "test" - @headers.add_field("My-Other-Header", "a") - @headers.add_field("My-Other-Header", "b") - end - - describe "when passed a block" do - it "yields each header entry to the passed block (keys in lower case, values joined)" do - res = [] - @headers.send(@method) do |key, value| - res << [key, value] - end - res.sort.should == [["my-header", "test"], ["my-other-header", "a, b"]] - end - end - - describe "when passed no block" do - it "returns an Enumerator" do - enumerator = @headers.send(@method) - enumerator.should be_an_instance_of(Enumerator) - - res = [] - enumerator.each do |*key| - res << key - end - res.sort.should == [["my-header", "test"], ["my-other-header", "a, b"]] - end - end -end diff --git a/spec/ruby/library/net-http/httpheader/shared/each_name.rb b/spec/ruby/library/net-http/httpheader/shared/each_name.rb deleted file mode 100644 index efc6a09dfd..0000000000 --- a/spec/ruby/library/net-http/httpheader/shared/each_name.rb +++ /dev/null @@ -1,31 +0,0 @@ -describe :net_httpheader_each_name, shared: true do - before :each do - @headers = NetHTTPHeaderSpecs::Example.new - @headers["My-Header"] = "test" - @headers.add_field("My-Other-Header", "a") - @headers.add_field("My-Other-Header", "b") - end - - describe "when passed a block" do - it "yields each header key to the passed block (keys in lower case)" do - res = [] - @headers.send(@method) do |key| - res << key - end - res.sort.should == ["my-header", "my-other-header"] - end - end - - describe "when passed no block" do - it "returns an Enumerator" do - enumerator = @headers.send(@method) - enumerator.should be_an_instance_of(Enumerator) - - res = [] - enumerator.each do |key| - res << key - end - res.sort.should == ["my-header", "my-other-header"] - end - end -end 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 deleted file mode 100644 index b7359bdca6..0000000000 --- a/spec/ruby/library/net-http/httpheader/shared/set_content_type.rb +++ /dev/null @@ -1,18 +0,0 @@ -describe :net_httpheader_set_content_type, shared: true do - describe "when passed type, params" do - before :each do - @headers = NetHTTPHeaderSpecs::Example.new - end - - it "sets the 'Content-Type' header entry based on the passed type and params" do - @headers.send(@method, "text/html") - @headers["Content-Type"].should == "text/html" - - @headers.send(@method, "text/html", "charset" => "utf-8") - @headers["Content-Type"].should == "text/html; charset=utf-8" - - @headers.send(@method, "text/html", "charset" => "utf-8", "rubyspec" => "rocks") - @headers["Content-Type"].split(/; /).sort.should == %w[charset=utf-8 rubyspec=rocks text/html] - end - end -end 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 deleted file mode 100644 index db20b18803..0000000000 --- a/spec/ruby/library/net-http/httpheader/shared/set_form_data.rb +++ /dev/null @@ -1,27 +0,0 @@ -describe :net_httpheader_set_form_data, shared: true do - before :each do - @headers = NetHTTPHeaderSpecs::Example.new - end - - describe "when passed params" do - it "automatically set the 'Content-Type' to 'application/x-www-form-urlencoded'" do - @headers.send(@method, "cmd" => "search", "q" => "ruby", "max" => "50") - @headers["Content-Type"].should == "application/x-www-form-urlencoded" - end - - it "sets self's body based on the passed form parameters" do - @headers.send(@method, "cmd" => "search", "q" => "ruby", "max" => "50") - @headers.body.split("&").sort.should == ["cmd=search", "max=50", "q=ruby"] - end - end - - describe "when passed params, separator" do - it "sets self's body based on the passed form parameters and the passed separator" do - @headers.send(@method, {"cmd" => "search", "q" => "ruby", "max" => "50"}, "&") - @headers.body.split("&").sort.should == ["cmd=search", "max=50", "q=ruby"] - - @headers.send(@method, {"cmd" => "search", "q" => "ruby", "max" => "50"}, ";") - @headers.body.split(";").sort.should == ["cmd=search", "max=50", "q=ruby"] - end - end -end diff --git a/spec/ruby/library/net-http/httpheader/shared/set_range.rb b/spec/ruby/library/net-http/httpheader/shared/set_range.rb deleted file mode 100644 index 87f51d46f3..0000000000 --- a/spec/ruby/library/net-http/httpheader/shared/set_range.rb +++ /dev/null @@ -1,89 +0,0 @@ -describe :net_httpheader_set_range, shared: true do - before :each do - @headers = NetHTTPHeaderSpecs::Example.new - end - - describe "when passed nil" do - it "returns nil" do - @headers.send(@method, nil).should be_nil - end - - it "deletes the 'Range' header entry" do - @headers["Range"] = "bytes 0-499/1234" - @headers.send(@method, nil) - @headers["Range"].should be_nil - end - end - - describe "when passed Numeric" do - it "sets the 'Range' header entry based on the passed Numeric" do - @headers.send(@method, 10) - @headers["Range"].should == "bytes=0-9" - - @headers.send(@method, -10) - @headers["Range"].should == "bytes=-10" - - @headers.send(@method, 10.9) - @headers["Range"].should == "bytes=0-9" - end - end - - describe "when passed Range" do - it "sets the 'Range' header entry based on the passed Range" do - @headers.send(@method, 10..200) - @headers["Range"].should == "bytes=10-200" - - @headers.send(@method, 1..5) - @headers["Range"].should == "bytes=1-5" - - @headers.send(@method, 1...5) - @headers["Range"].should == "bytes=1-4" - - @headers.send(@method, 234..567) - @headers["Range"].should == "bytes=234-567" - - @headers.send(@method, -5..-1) - @headers["Range"].should == "bytes=-5" - - @headers.send(@method, 1..-1) - @headers["Range"].should == "bytes=1-" - end - - it "raises a Net::HTTPHeaderSyntaxError when the first Range element is negative" do - -> { @headers.send(@method, -10..5) }.should raise_error(Net::HTTPHeaderSyntaxError) - end - - it "raises a Net::HTTPHeaderSyntaxError when the last Range element is negative" do - -> { @headers.send(@method, 10..-5) }.should raise_error(Net::HTTPHeaderSyntaxError) - end - - it "raises a Net::HTTPHeaderSyntaxError when the last Range element is smaller than the first" do - -> { @headers.send(@method, 10..5) }.should raise_error(Net::HTTPHeaderSyntaxError) - end - end - - describe "when passed start, end" do - it "sets the 'Range' header entry based on the passed start and length values" do - @headers.send(@method, 10, 200) - @headers["Range"].should == "bytes=10-209" - - @headers.send(@method, 1, 5) - @headers["Range"].should == "bytes=1-5" - - @headers.send(@method, 234, 567) - @headers["Range"].should == "bytes=234-800" - end - - it "raises a Net::HTTPHeaderSyntaxError when start is negative" do - -> { @headers.send(@method, -10, 5) }.should raise_error(Net::HTTPHeaderSyntaxError) - end - - it "raises a Net::HTTPHeaderSyntaxError when start + length is negative" do - -> { @headers.send(@method, 10, -15) }.should raise_error(Net::HTTPHeaderSyntaxError) - end - - it "raises a Net::HTTPHeaderSyntaxError when length is negative" do - -> { @headers.send(@method, 10, -4) }.should raise_error(Net::HTTPHeaderSyntaxError) - end - end -end diff --git a/spec/ruby/library/net-http/httpheader/shared/size.rb b/spec/ruby/library/net-http/httpheader/shared/size.rb deleted file mode 100644 index e2b1e4c22b..0000000000 --- a/spec/ruby/library/net-http/httpheader/shared/size.rb +++ /dev/null @@ -1,18 +0,0 @@ -describe :net_httpheader_size, shared: true do - before :each do - @headers = NetHTTPHeaderSpecs::Example.new - end - - it "returns the number of header entries in self" do - @headers.send(@method).should eql(0) - - @headers["a"] = "b" - @headers.send(@method).should eql(1) - - @headers["b"] = "b" - @headers.send(@method).should eql(2) - - @headers["c"] = "c" - @headers.send(@method).should eql(3) - end -end diff --git a/spec/ruby/library/net-http/httpheader/size_spec.rb b/spec/ruby/library/net-http/httpheader/size_spec.rb index 210060ce21..f84a0fb5ab 100644 --- a/spec/ruby/library/net-http/httpheader/size_spec.rb +++ b/spec/ruby/library/net-http/httpheader/size_spec.rb @@ -1,8 +1,22 @@ require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' -require_relative 'shared/size' describe "Net::HTTPHeader#size" do - it_behaves_like :net_httpheader_size, :size + before :each do + @headers = NetHTTPHeaderSpecs::Example.new + end + + it "returns the number of header entries in self" do + @headers.size.should.eql?(0) + + @headers["a"] = "b" + @headers.size.should.eql?(1) + + @headers["b"] = "b" + @headers.size.should.eql?(2) + + @headers["c"] = "c" + @headers.size.should.eql?(3) + end end 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 b39b57fe8d..9e7d2a5368 100644 --- a/spec/ruby/library/net-http/httpheader/sub_type_spec.rb +++ b/spec/ruby/library/net-http/httpheader/sub_type_spec.rb @@ -20,13 +20,13 @@ describe "Net::HTTPHeader#sub_type" do it "returns nil if no 'sub-content-type' is set" do @headers["Content-Type"] = "text" - @headers.sub_type.should be_nil + @headers.sub_type.should == nil @headers["Content-Type"] = "text;charset=utf-8" - @headers.sub_type.should be_nil + @headers.sub_type.should == nil end it "returns nil if the 'Content-Type' header entry does not exist" do - @headers.sub_type.should be_nil + @headers.sub_type.should == nil end end 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 3cebc519a6..e245c20d4c 100644 --- a/spec/ruby/library/net-http/httpheader/to_hash_spec.rb +++ b/spec/ruby/library/net-http/httpheader/to_hash_spec.rb @@ -20,6 +20,6 @@ describe "Net::HTTPHeader#to_hash" do it "does not allow modifying the headers from the returned hash" do @headers.to_hash["my-header"] = ["test"] @headers.to_hash.should == {} - @headers.key?("my-header").should be_false + @headers.key?("my-header").should == false end end diff --git a/spec/ruby/library/net-http/httprequest/initialize_spec.rb b/spec/ruby/library/net-http/httprequest/initialize_spec.rb index d009a00ed2..1229986bef 100644 --- a/spec/ruby/library/net-http/httprequest/initialize_spec.rb +++ b/spec/ruby/library/net-http/httprequest/initialize_spec.rb @@ -21,12 +21,12 @@ describe "Net::HTTPRequest#initialize" do it "uses the REQUEST_HAS_BODY to set whether the Request has a body or not" do @req.send(:initialize, "/some/path") - @req.request_body_permitted?.should be_false + @req.request_body_permitted?.should == false end it "uses the RESPONSE_HAS_BODY to set whether the Response can have a body or not" do @req.send(:initialize, "/some/path") - @req.response_body_permitted?.should be_true + @req.response_body_permitted?.should == true end describe "when passed path" do diff --git a/spec/ruby/library/net-http/httpresponse/body_spec.rb b/spec/ruby/library/net-http/httpresponse/body_spec.rb index ddfcd834c4..5b00913687 100644 --- a/spec/ruby/library/net-http/httpresponse/body_spec.rb +++ b/spec/ruby/library/net-http/httpresponse/body_spec.rb @@ -1,7 +1,22 @@ require_relative '../../../spec_helper' require 'net/http' -require_relative 'shared/body' +require 'stringio' describe "Net::HTTPResponse#body" do - it_behaves_like :net_httpresponse_body, :body + before :each do + @res = Net::HTTPUnknownResponse.new("1.0", "???", "test response") + @socket = Net::BufferedIO.new(StringIO.new("test body")) + end + + it "returns the read body" do + @res.reading_body(@socket, true) do + @res.body.should == "test body" + end + end + + it "returns the previously read body if called a second time" do + @res.reading_body(@socket, true) do + @res.body.should.equal?(@res.body) + end + end end diff --git a/spec/ruby/library/net-http/httpresponse/entity_spec.rb b/spec/ruby/library/net-http/httpresponse/entity_spec.rb index ca8c4b29c0..d2201db37b 100644 --- a/spec/ruby/library/net-http/httpresponse/entity_spec.rb +++ b/spec/ruby/library/net-http/httpresponse/entity_spec.rb @@ -1,7 +1,9 @@ require_relative '../../../spec_helper' require 'net/http' -require_relative 'shared/body' describe "Net::HTTPResponse#entity" do - it_behaves_like :net_httpresponse_body, :entity + it "is an alias of Net::HTTPResponse#body" do + Net::HTTPResponse.instance_method(:entity).should == + Net::HTTPResponse.instance_method(:body) + end end diff --git a/spec/ruby/library/net-http/httpresponse/error_spec.rb b/spec/ruby/library/net-http/httpresponse/error_spec.rb index 6ced90fa23..e194df95af 100644 --- a/spec/ruby/library/net-http/httpresponse/error_spec.rb +++ b/spec/ruby/library/net-http/httpresponse/error_spec.rb @@ -4,21 +4,21 @@ require 'net/http' describe "Net::HTTPResponse#error!" do it "raises self's class 'EXCEPTION_TYPE' Exception" do res = Net::HTTPUnknownResponse.new("1.0", "???", "test response") - -> { res.error! }.should raise_error(Net::HTTPError) + -> { res.error! }.should.raise(Net::HTTPError) res = Net::HTTPInformation.new("1.0", "1xx", "test response") - -> { res.error! }.should raise_error(Net::HTTPError) + -> { res.error! }.should.raise(Net::HTTPError) res = Net::HTTPSuccess.new("1.0", "2xx", "test response") - -> { res.error! }.should raise_error(Net::HTTPError) + -> { res.error! }.should.raise(Net::HTTPError) res = Net::HTTPRedirection.new("1.0", "3xx", "test response") - -> { res.error! }.should raise_error(Net::HTTPRetriableError) + -> { res.error! }.should.raise(Net::HTTPRetriableError) res = Net::HTTPClientError.new("1.0", "4xx", "test response") - -> { res.error! }.should raise_error(Net::HTTPClientException) + -> { res.error! }.should.raise(Net::HTTPClientException) res = Net::HTTPServerError.new("1.0", "5xx", "test response") - -> { res.error! }.should raise_error(Net::HTTPFatalError) + -> { res.error! }.should.raise(Net::HTTPFatalError) end end diff --git a/spec/ruby/library/net-http/httpresponse/header_spec.rb b/spec/ruby/library/net-http/httpresponse/header_spec.rb index a403dbd2c3..3ddadfb8e4 100644 --- a/spec/ruby/library/net-http/httpresponse/header_spec.rb +++ b/spec/ruby/library/net-http/httpresponse/header_spec.rb @@ -4,6 +4,6 @@ require 'net/http' describe "Net::HTTPResponse#header" do it "returns self" do res = Net::HTTPUnknownResponse.new("1.0", "???", "test response") - res.response.should equal(res) + res.response.should.equal?(res) end end 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 4530a26bfc..d8b2418624 100644 --- a/spec/ruby/library/net-http/httpresponse/read_body_spec.rb +++ b/spec/ruby/library/net-http/httpresponse/read_body_spec.rb @@ -17,7 +17,7 @@ describe "Net::HTTPResponse#read_body" do it "returns the previously read body if called a second time" do @res.reading_body(@socket, true) do - @res.read_body.should equal(@res.read_body) + @res.read_body.should.equal?(@res.read_body) end end end @@ -34,14 +34,14 @@ describe "Net::HTTPResponse#read_body" do it "returns the passed buffer" do @res.reading_body(@socket, true) do buffer = +"" - @res.read_body(buffer).should equal(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(+"") }.should.raise(IOError) end end end @@ -57,21 +57,21 @@ describe "Net::HTTPResponse#read_body" do buffer << body end - yielded.should be_true + yielded.should == true buffer.should == "test body" end end it "returns the ReadAdapter" do @res.reading_body(@socket, true) do - @res.read_body { nil }.should be_kind_of(Net::ReadAdapter) + @res.read_body { nil }.should.is_a?(Net::ReadAdapter) 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 {} }.should.raise(IOError) end end end @@ -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(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 3ea4ee834b..70ce988502 100644 --- a/spec/ruby/library/net-http/httpresponse/read_header_spec.rb +++ b/spec/ruby/library/net-http/httpresponse/read_header_spec.rb @@ -4,6 +4,6 @@ require 'net/http' describe "Net::HTTPResponse#read_header" do it "returns self" do res = Net::HTTPUnknownResponse.new("1.0", "???", "test response") - res.response.should equal(res) + res.response.should.equal?(res) end end 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 82f7a47ce8..3795e29d83 100644 --- a/spec/ruby/library/net-http/httpresponse/read_new_spec.rb +++ b/spec/ruby/library/net-http/httpresponse/read_new_spec.rb @@ -12,7 +12,7 @@ test-body EOS response = Net::HTTPResponse.read_new(socket) - response.should be_kind_of(Net::HTTPOK) + response.should.is_a?(Net::HTTPOK) response.code.should == "200" response["Content-Type"].should == "text/html; charset=utf-8" 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 637a2806f8..a3671d6eb5 100644 --- a/spec/ruby/library/net-http/httpresponse/reading_body_spec.rb +++ b/spec/ruby/library/net-http/httpresponse/reading_body_spec.rb @@ -22,7 +22,7 @@ describe "Net::HTTPResponse#reading_body" do yielded = true end - yielded.should be_true + yielded.should == true end describe "but the response type is not allowed to have a body" do @@ -31,28 +31,28 @@ describe "Net::HTTPResponse#reading_body" do end it "returns nil" do - @res.reading_body(@socket, false) {}.should be_nil - @res.body.should be_nil + @res.reading_body(@socket, false) {}.should == nil + @res.body.should == nil end it "yields the passed block" do yielded = false @res.reading_body(@socket, true) { yielded = true } - yielded.should be_true + yielded.should == true end end end describe "when body_allowed is false" do it "returns nil" do - @res.reading_body(@socket, false) {}.should be_nil - @res.body.should be_nil + @res.reading_body(@socket, false) {}.should == nil + @res.body.should == nil end it "yields the passed block" do yielded = false @res.reading_body(@socket, true) { yielded = true } - yielded.should be_true + yielded.should == true end end end diff --git a/spec/ruby/library/net-http/httpresponse/response_spec.rb b/spec/ruby/library/net-http/httpresponse/response_spec.rb index caa0ca2d19..440c33c168 100644 --- a/spec/ruby/library/net-http/httpresponse/response_spec.rb +++ b/spec/ruby/library/net-http/httpresponse/response_spec.rb @@ -4,6 +4,6 @@ require 'net/http' describe "Net::HTTPResponse#response" do it "returns self" do res = Net::HTTPUnknownResponse.new("1.0", "???", "test response") - res.response.should equal(res) + res.response.should.equal?(res) end end diff --git a/spec/ruby/library/net-http/httpresponse/shared/body.rb b/spec/ruby/library/net-http/httpresponse/shared/body.rb deleted file mode 100644 index 618e3936fb..0000000000 --- a/spec/ruby/library/net-http/httpresponse/shared/body.rb +++ /dev/null @@ -1,20 +0,0 @@ -require 'stringio' - -describe :net_httpresponse_body, shared: true do - before :each do - @res = Net::HTTPUnknownResponse.new("1.0", "???", "test response") - @socket = Net::BufferedIO.new(StringIO.new("test body")) - end - - it "returns the read body" do - @res.reading_body(@socket, true) do - @res.send(@method).should == "test body" - end - end - - it "returns the previously read body if called a second time" do - @res.reading_body(@socket, true) do - @res.send(@method).should equal(@res.send(@method)) - end - end -end diff --git a/spec/ruby/library/net-http/httpresponse/value_spec.rb b/spec/ruby/library/net-http/httpresponse/value_spec.rb index 2df8beaa10..e32d37500a 100644 --- a/spec/ruby/library/net-http/httpresponse/value_spec.rb +++ b/spec/ruby/library/net-http/httpresponse/value_spec.rb @@ -4,21 +4,21 @@ require 'net/http' describe "Net::HTTPResponse#value" do it "raises an HTTP error for non 2xx HTTP Responses" do res = Net::HTTPUnknownResponse.new("1.0", "???", "test response") - -> { res.value }.should raise_error(Net::HTTPError) + -> { res.value }.should.raise(Net::HTTPError) res = Net::HTTPInformation.new("1.0", "1xx", "test response") - -> { res.value }.should raise_error(Net::HTTPError) + -> { res.value }.should.raise(Net::HTTPError) res = Net::HTTPSuccess.new("1.0", "2xx", "test response") - -> { res.value }.should_not raise_error(Net::HTTPError) + -> { res.value }.should_not.raise(Net::HTTPError) res = Net::HTTPRedirection.new("1.0", "3xx", "test response") - -> { res.value }.should raise_error(Net::HTTPRetriableError) + -> { res.value }.should.raise(Net::HTTPRetriableError) res = Net::HTTPClientError.new("1.0", "4xx", "test response") - -> { res.value }.should raise_error(Net::HTTPClientException) + -> { res.value }.should.raise(Net::HTTPClientException) res = Net::HTTPServerError.new("1.0", "5xx", "test response") - -> { res.value }.should raise_error(Net::HTTPFatalError) + -> { res.value }.should.raise(Net::HTTPFatalError) end end diff --git a/spec/ruby/library/objectspace/dump_all_spec.rb b/spec/ruby/library/objectspace/dump_all_spec.rb index e9b449a905..c92812ebd5 100644 --- a/spec/ruby/library/objectspace/dump_all_spec.rb +++ b/spec/ruby/library/objectspace/dump_all_spec.rb @@ -82,7 +82,7 @@ describe "ObjectSpace.dump_all" do ObjectSpace.dump_all(output: :stdout) RUBY - stdout.should include('"value":"abc"') + stdout.should.include?('"value":"abc"') end it "dumps Ruby heap to provided IO when passed output: IO" do @@ -107,6 +107,6 @@ describe "ObjectSpace.dump_all" do end it "raises ArgumentError when passed not supported :output value" do - -> { ObjectSpace.dump_all(output: Object.new) }.should raise_error(ArgumentError, /wrong output option/) + -> { ObjectSpace.dump_all(output: Object.new) }.should.raise(ArgumentError, /wrong output option/) end end diff --git a/spec/ruby/library/objectspace/dump_spec.rb b/spec/ruby/library/objectspace/dump_spec.rb index e22ee3df1e..4b5e0da198 100644 --- a/spec/ruby/library/objectspace/dump_spec.rb +++ b/spec/ruby/library/objectspace/dump_spec.rb @@ -13,23 +13,23 @@ describe "ObjectSpace.dump" do 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"') + string.should.is_a?(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"') + string.should.is_a?(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.should.is_a?(File) file.rewind content = file.read - content.should include('"value":"abc"') + content.should.include?('"value":"abc"') ensure file.close File.unlink file.path @@ -37,10 +37,10 @@ describe "ObjectSpace.dump" do it "dumps to a temporary file when passed output: :nil" do file = ObjectSpace.dump("abc", output: nil) - file.should be_kind_of(File) + file.should.is_a?(File) file.rewind - file.read.should include('"value":"abc"') + file.read.should.include?('"value":"abc"') ensure file.close File.unlink file.path @@ -48,7 +48,7 @@ describe "ObjectSpace.dump" do 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"') + stdout.should.include?('"value":"abc"') end it "dumps to provided IO when passed output: IO" do @@ -58,13 +58,13 @@ describe "ObjectSpace.dump" do result.should.equal? io io.rewind - io.read.should include('"value":"abc"') + 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/) + -> { ObjectSpace.dump("abc", output: Object.new) }.should.raise(ArgumentError, /wrong output option/) end end diff --git a/spec/ruby/library/objectspace/memsize_of_all_spec.rb b/spec/ruby/library/objectspace/memsize_of_all_spec.rb index c5a48165ce..9fc6e8be9d 100644 --- a/spec/ruby/library/objectspace/memsize_of_all_spec.rb +++ b/spec/ruby/library/objectspace/memsize_of_all_spec.rb @@ -3,12 +3,12 @@ require 'objspace' describe "ObjectSpace.memsize_of_all" do it "returns a non-zero Integer for all objects" do - ObjectSpace.memsize_of_all.should be_kind_of(Integer) + ObjectSpace.memsize_of_all.should.is_a?(Integer) ObjectSpace.memsize_of_all.should > 0 end it "returns a non-zero Integer for Class" do - ObjectSpace.memsize_of_all(Class).should be_kind_of(Integer) + ObjectSpace.memsize_of_all(Class).should.is_a?(Integer) ObjectSpace.memsize_of_all(Class).should > 0 end diff --git a/spec/ruby/library/objectspace/memsize_of_spec.rb b/spec/ruby/library/objectspace/memsize_of_spec.rb index cbb5a07d54..9c8aea4e84 100644 --- a/spec/ruby/library/objectspace/memsize_of_spec.rb +++ b/spec/ruby/library/objectspace/memsize_of_spec.rb @@ -18,7 +18,7 @@ describe "ObjectSpace.memsize_of" do it "returns a positive Integer for an Object" do obj = Object.new - ObjectSpace.memsize_of(obj).should be_kind_of(Integer) + ObjectSpace.memsize_of(obj).should.is_a?(Integer) ObjectSpace.memsize_of(obj).should > 0 end diff --git a/spec/ruby/library/objectspace/reachable_objects_from_spec.rb b/spec/ruby/library/objectspace/reachable_objects_from_spec.rb index dee5961663..4620bdec31 100644 --- a/spec/ruby/library/objectspace/reachable_objects_from_spec.rb +++ b/spec/ruby/library/objectspace/reachable_objects_from_spec.rb @@ -16,7 +16,7 @@ describe "ObjectSpace.reachable_objects_from" do end it "enumerates objects directly reachable from a given object" do - ObjectSpace.reachable_objects_from(['a', 'b', 'c']).should include(Array, 'a', 'b', 'c') + ObjectSpace.reachable_objects_from(['a', 'b', 'c']).to_set.should >= Set[Array, 'a', 'b', 'c'] ObjectSpace.reachable_objects_from(Object.new).should == [Object] end @@ -24,7 +24,7 @@ describe "ObjectSpace.reachable_objects_from" do obj = Object.new ary = [obj] reachable = ObjectSpace.reachable_objects_from(ary) - reachable.should include(obj) + reachable.should.include?(obj) end it "finds an object stored in a copy-on-write Array" do @@ -33,8 +33,8 @@ describe "ObjectSpace.reachable_objects_from" do ary = [removed, obj] ary.shift reachable = ObjectSpace.reachable_objects_from(ary) - reachable.should include(obj) - reachable.should_not include(removed) + reachable.should.include?(obj) + reachable.should_not.include?(removed) end it "finds an object stored in a Queue" do @@ -44,7 +44,7 @@ describe "ObjectSpace.reachable_objects_from" do reachable = ObjectSpace.reachable_objects_from(q) reachable = reachable + reachable.flat_map { |r| ObjectSpace.reachable_objects_from(r) } - reachable.should include(o) + reachable.should.include?(o) end it "finds an object stored in a SizedQueue" do @@ -54,6 +54,6 @@ describe "ObjectSpace.reachable_objects_from" do reachable = ObjectSpace.reachable_objects_from(q) reachable = reachable + reachable.flat_map { |r| ObjectSpace.reachable_objects_from(r) } - reachable.should include(o) + reachable.should.include?(o) end end diff --git a/spec/ruby/library/objectspace/trace_object_allocations_spec.rb b/spec/ruby/library/objectspace/trace_object_allocations_spec.rb index 0f1e2aa8b9..0bb6efbfa5 100644 --- a/spec/ruby/library/objectspace/trace_object_allocations_spec.rb +++ b/spec/ruby/library/objectspace/trace_object_allocations_spec.rb @@ -74,7 +74,7 @@ describe "ObjectSpace.trace_object_allocations" do o = Object.new ObjectSpace.allocation_class_path(o).should == obj_class_path ObjectSpace.trace_object_allocations_clear - ObjectSpace.allocation_class_path(o).should be_nil + ObjectSpace.allocation_class_path(o).should == nil end end diff --git a/spec/ruby/library/observer/notify_observers_spec.rb b/spec/ruby/library/observer/notify_observers_spec.rb index 31f82e9266..6f3f984637 100644 --- a/spec/ruby/library/observer/notify_observers_spec.rb +++ b/spec/ruby/library/observer/notify_observers_spec.rb @@ -18,7 +18,7 @@ describe "Observer#notify_observers" do it "verifies observer responds to update" do -> { @observable.add_observer(@observable) - }.should raise_error(NoMethodError) + }.should.raise(NoMethodError) end it "receives the callback" do diff --git a/spec/ruby/library/open3/popen3_spec.rb b/spec/ruby/library/open3/popen3_spec.rb index d3103ad3cb..3651bd516c 100644 --- a/spec/ruby/library/open3/popen3_spec.rb +++ b/spec/ruby/library/open3/popen3_spec.rb @@ -5,10 +5,10 @@ describe "Open3.popen3" do it "returns in, out, err and a thread waiting the process" do stdin, out, err, waiter = Open3.popen3(ruby_cmd("print :foo")) begin - stdin.should be_kind_of IO - out.should be_kind_of IO - err.should be_kind_of IO - waiter.should be_kind_of Thread + stdin.should.is_a? IO + out.should.is_a? IO + err.should.is_a? IO + waiter.should.is_a? Thread out.read.should == "foo" ensure diff --git a/spec/ruby/library/openssl/cipher_spec.rb b/spec/ruby/library/openssl/cipher_spec.rb index f66f25f9c6..91da1c592c 100644 --- a/spec/ruby/library/openssl/cipher_spec.rb +++ b/spec/ruby/library/openssl/cipher_spec.rb @@ -4,6 +4,6 @@ require 'openssl' describe "OpenSSL::Cipher's CipherError" do it "exists under OpenSSL::Cipher namespace" do - OpenSSL::Cipher.should have_constant :CipherError + OpenSSL::Cipher.should.const_defined?(:CipherError, false) end end diff --git a/spec/ruby/library/openssl/digest/initialize_spec.rb b/spec/ruby/library/openssl/digest/initialize_spec.rb index 1cd0409c4d..e24ab51d14 100644 --- a/spec/ruby/library/openssl/digest/initialize_spec.rb +++ b/spec/ruby/library/openssl/digest/initialize_spec.rb @@ -23,18 +23,14 @@ describe "OpenSSL::Digest#initialize" do OpenSSL::Digest.new("sha512").name.should == "SHA512" end - it "throws an error when called with an unknown digest" do - -> { OpenSSL::Digest.new("wd40") }.should raise_error(RuntimeError, /Unsupported digest algorithm \(wd40\)/) + 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(OpenSSL::Digest::DigestError, /wd40/) + end end it "cannot be called with a symbol" do - -> { OpenSSL::Digest.new(:SHA1) }.should raise_error(TypeError, /wrong argument type Symbol/) - end - - it "does not call #to_str on the argument" do - name = mock("digest name") - name.should_not_receive(:to_str) - -> { OpenSSL::Digest.new(name) }.should raise_error(TypeError, /wrong argument type/) + -> { OpenSSL::Digest.new(:SHA1) }.should.raise(TypeError) end end @@ -62,7 +58,7 @@ describe "OpenSSL::Digest#initialize" do end it "cannot be called with a digest class" do - -> { OpenSSL::Digest.new(OpenSSL::Digest::SHA1) }.should raise_error(TypeError, /wrong argument type Class/) + -> { OpenSSL::Digest.new(OpenSSL::Digest::SHA1) }.should.raise(TypeError) end context "when called without an initial String argument" do diff --git a/spec/ruby/library/openssl/digest/shared/update.rb b/spec/ruby/library/openssl/digest/shared/update.rb index e5ff9dcb16..37277c945d 100644 --- a/spec/ruby/library/openssl/digest/shared/update.rb +++ b/spec/ruby/library/openssl/digest/shared/update.rb @@ -96,28 +96,28 @@ describe :openssl_digest_update, shared: true do digest = OpenSSL::Digest.new('sha1') -> { digest.send(@method, Object.new) - }.should raise_error(TypeError, 'no implicit conversion of Object into String') + }.should.raise(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') + }.should.raise(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') + }.should.raise(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') + }.should.raise(TypeError, 'no implicit conversion of Object into String') end end 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 index 5a2ca168b5..cc638e1f0d 100644 --- a/spec/ruby/library/openssl/fixed_length_secure_compare_spec.rb +++ b/spec/ruby/library/openssl/fixed_length_secure_compare_spec.rb @@ -5,13 +5,13 @@ 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 + OpenSSL.fixed_length_secure_compare(input1, input2).should == 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 + OpenSSL.fixed_length_secure_compare(input1, input2).should == false end it "converts both arguments to strings using #to_str" do @@ -19,17 +19,17 @@ describe "OpenSSL.fixed_length_secure_compare" do 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 + OpenSSL.fixed_length_secure_compare(input1, input2).should == 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') + }.should.raise(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') + }.should.raise(TypeError, 'no implicit conversion of Object into String') end it "raises an ArgumentError for two strings of different size" do @@ -37,6 +37,6 @@ describe "OpenSSL.fixed_length_secure_compare" do input2 = "the quick brown fox" -> { OpenSSL.fixed_length_secure_compare(input1, input2) - }.should raise_error(ArgumentError, 'inputs must be of equal length') + }.should.raise(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 index 40f8597275..2558dbb9ec 100644 --- a/spec/ruby/library/openssl/kdf/pbkdf2_hmac_spec.rb +++ b/spec/ruby/library/openssl/kdf/pbkdf2_hmac_spec.rb @@ -83,86 +83,80 @@ describe "OpenSSL::KDF.pbkdf2_hmac" do 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") + }.should.raise(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") + }.should.raise(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") + }.should.raise(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") + }.should.raise(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, "wrong argument type Object (expected OpenSSL/Digest)") + }.should.raise(TypeError) end - it "raises a TypeError when hash is neither a String nor an OpenSSL::Digest, it does not try to call #to_str" do - hash = mock("hash") - hash.should_not_receive(:to_str) - -> { - OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults, hash: hash) - }.should raise_error(TypeError, "wrong argument type MockObject (expected OpenSSL/Digest)") - end - - it "raises a RuntimeError for unknown digest algorithms" do - -> { - OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults, hash: "wd40") - }.should raise_error(RuntimeError, /Unsupported digest algorithm \(wd40\)/) + 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(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') + }.should.raise(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') + }.should.raise(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') + }.should.raise(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') + }.should.raise(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') + }.should.raise(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") + }.should.raise(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/) + }.should.raise(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 index e01b8bca8a..c00f91bb5b 100644 --- a/spec/ruby/library/openssl/kdf/scrypt_spec.rb +++ b/spec/ruby/library/openssl/kdf/scrypt_spec.rb @@ -89,79 +89,79 @@ guard -> { OpenSSL::OPENSSL_VERSION.start_with?('OpenSSL') and OpenSSL::OPENSSL_ 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") + }.should.raise(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") + }.should.raise(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") + }.should.raise(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") + }.should.raise(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") + }.should.raise(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") + }.should.raise(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') + }.should.raise(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') + }.should.raise(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') + }.should.raise(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') + }.should.raise(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') + }.should.raise(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') + }.should.raise(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/) + }.should.raise(OpenSSL::KDF::KDFError, /EVP_PBE_scrypt/) end it "requires N to be at least 2" do @@ -170,41 +170,41 @@ guard -> { OpenSSL::OPENSSL_VERSION.start_with?('OpenSSL') and OpenSSL::OPENSSL_ -> { OpenSSL::KDF.scrypt("secret", **@defaults, N: 1) - }.should raise_error(OpenSSL::KDF::KDFError, /EVP_PBE_scrypt/) + }.should.raise(OpenSSL::KDF::KDFError, /EVP_PBE_scrypt/) -> { OpenSSL::KDF.scrypt("secret", **@defaults, N: 0) - }.should raise_error(OpenSSL::KDF::KDFError, /EVP_PBE_scrypt/) + }.should.raise(OpenSSL::KDF::KDFError, /EVP_PBE_scrypt/) -> { OpenSSL::KDF.scrypt("secret", **@defaults, N: -1) - }.should raise_error(OpenSSL::KDF::KDFError, /EVP_PBE_scrypt/) + }.should.raise(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/) + }.should.raise(OpenSSL::KDF::KDFError, /EVP_PBE_scrypt/) -> { OpenSSL::KDF.scrypt("secret", **@defaults, r: -1) - }.should raise_error(OpenSSL::KDF::KDFError, /EVP_PBE_scrypt/) + }.should.raise(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/) + }.should.raise(OpenSSL::KDF::KDFError, /EVP_PBE_scrypt/) -> { OpenSSL::KDF.scrypt("secret", **@defaults, p: -1) - }.should raise_error(OpenSSL::KDF::KDFError, /EVP_PBE_scrypt/) + }.should.raise(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)") + }.should.raise(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 f97ccd9974..4d1751e57e 100644 --- a/spec/ruby/library/openssl/random/shared/random_bytes.rb +++ b/spec/ruby/library/openssl/random/shared/random_bytes.rb @@ -5,7 +5,7 @@ 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) - bytes.should be_kind_of(String) + bytes.should.is_a?(String) bytes.length.should == idx end end @@ -24,6 +24,6 @@ describe :openssl_random_bytes, shared: true do it "raises ArgumentError on negative arguments" do -> { OpenSSL::Random.send(@method, -1) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) end end diff --git a/spec/ruby/library/openssl/secure_compare_spec.rb b/spec/ruby/library/openssl/secure_compare_spec.rb index cec48e01e7..ce2a4a0d43 100644 --- a/spec/ruby/library/openssl/secure_compare_spec.rb +++ b/spec/ruby/library/openssl/secure_compare_spec.rb @@ -5,13 +5,13 @@ 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 + OpenSSL.secure_compare(input1, input2).should == 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 + OpenSSL.secure_compare(input1, input2).should == false end it "converts both arguments to strings using #to_str, but adds equality check for the original objects" do @@ -19,20 +19,20 @@ describe "OpenSSL.secure_compare" do 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 + OpenSSL.secure_compare(input1, input2).should == 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 + OpenSSL.secure_compare(input, input).should == 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') + }.should.raise(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') + }.should.raise(TypeError, 'no implicit conversion of Object into String') end end diff --git a/spec/ruby/library/openssl/x509/name/parse_spec.rb b/spec/ruby/library/openssl/x509/name/parse_spec.rb index 6624161d83..84e3d442f6 100644 --- a/spec/ruby/library/openssl/x509/name/parse_spec.rb +++ b/spec/ruby/library/openssl/x509/name/parse_spec.rb @@ -37,12 +37,12 @@ describe "OpenSSL::X509::Name.parse" do it "raises TypeError if the given string contains no key/value pairs" do -> do OpenSSL::X509::Name.parse("hello") - end.should raise_error(TypeError) + end.should.raise(TypeError) end it "raises OpenSSL::X509::NameError if the given string contains invalid keys" do -> do OpenSSL::X509::Name.parse("hello=goodbye") - end.should raise_error(OpenSSL::X509::NameError) + end.should.raise(OpenSSL::X509::NameError) end end diff --git a/spec/ruby/library/openstruct/delete_field_spec.rb b/spec/ruby/library/openstruct/delete_field_spec.rb index 9ac80196cc..12fed6c90d 100644 --- a/spec/ruby/library/openstruct/delete_field_spec.rb +++ b/spec/ruby/library/openstruct/delete_field_spec.rb @@ -8,12 +8,12 @@ describe "OpenStruct#delete_field" do it "removes the named field from self's method/value table" do @os.delete_field(:name) - @os[:name].should be_nil + @os[:name].should == nil end it "does remove the accessor methods" do @os.delete_field(:name) - @os.respond_to?(:name).should be_false - @os.respond_to?(:name=).should be_false + @os.respond_to?(:name).should == false + @os.respond_to?(:name=).should == false end end diff --git a/spec/ruby/library/openstruct/equal_value_spec.rb b/spec/ruby/library/openstruct/equal_value_spec.rb index 103ac13588..ec30214fd3 100644 --- a/spec/ruby/library/openstruct/equal_value_spec.rb +++ b/spec/ruby/library/openstruct/equal_value_spec.rb @@ -1,5 +1,5 @@ require_relative '../../spec_helper' -require "ostruct" +require 'ostruct' require_relative 'fixtures/classes' describe "OpenStruct#==" do @@ -8,21 +8,21 @@ describe "OpenStruct#==" do end it "returns false when the passed argument is no OpenStruct" do - (@os == Object.new).should be_false - (@os == "Test").should be_false - (@os == 10).should be_false - (@os == :sym).should be_false + (@os == Object.new).should == false + (@os == "Test").should == false + (@os == 10).should == false + (@os == :sym).should == false end it "returns true when self and other are equal method/value wise" do - (@os == @os).should be_true - (@os == OpenStruct.new(name: "John")).should be_true - (@os == OpenStructSpecs::OpenStructSub.new(name: "John")).should be_true + (@os == @os).should == true + (@os == OpenStruct.new(name: "John")).should == true + (@os == OpenStructSpecs::OpenStructSub.new(name: "John")).should == true - (@os == OpenStruct.new(name: "Jonny")).should be_false - (@os == OpenStructSpecs::OpenStructSub.new(name: "Jonny")).should be_false + (@os == OpenStruct.new(name: "Jonny")).should == false + (@os == OpenStructSpecs::OpenStructSub.new(name: "Jonny")).should == false - (@os == OpenStruct.new(name: "John", age: 20)).should be_false - (@os == OpenStructSpecs::OpenStructSub.new(name: "John", age: 20)).should be_false + (@os == OpenStruct.new(name: "John", age: 20)).should == false + (@os == OpenStructSpecs::OpenStructSub.new(name: "John", age: 20)).should == false end end diff --git a/spec/ruby/library/openstruct/frozen_spec.rb b/spec/ruby/library/openstruct/frozen_spec.rb index c14a4bac55..c37fd18c8c 100644 --- a/spec/ruby/library/openstruct/frozen_spec.rb +++ b/spec/ruby/library/openstruct/frozen_spec.rb @@ -9,25 +9,25 @@ describe "OpenStruct.new when frozen" do # method_missing case handled in method_missing_spec.rb # it "is still readable" do - @os.age.should eql(70) - @os.pension.should eql(300) + @os.age.should.eql?(70) + @os.pension.should.eql?(300) @os.name.should == "John Smith" end it "is not writable" do - ->{ @os.age = 42 }.should raise_error( RuntimeError ) + ->{ @os.age = 42 }.should.raise( RuntimeError ) end it "cannot create new fields" do - ->{ @os.state = :new }.should raise_error( RuntimeError ) + ->{ @os.state = :new }.should.raise( RuntimeError ) end it "creates a frozen clone" do f = @os.clone f.frozen?.should == true f.age.should == 70 - ->{ f.age = 0 }.should raise_error( RuntimeError ) - ->{ f.state = :newer }.should raise_error( RuntimeError ) + ->{ f.age = 0 }.should.raise( RuntimeError ) + ->{ f.state = :newer }.should.raise( RuntimeError ) end it "creates an unfrozen dup" do diff --git a/spec/ruby/library/openstruct/initialize_spec.rb b/spec/ruby/library/openstruct/initialize_spec.rb index dee5de48c6..52304cf780 100644 --- a/spec/ruby/library/openstruct/initialize_spec.rb +++ b/spec/ruby/library/openstruct/initialize_spec.rb @@ -3,6 +3,6 @@ require 'ostruct' describe "OpenStruct#initialize" do it "is private" do - OpenStruct.should have_private_instance_method(:initialize) + OpenStruct.private_instance_methods(false).should.include?(:initialize) end end diff --git a/spec/ruby/library/openstruct/inspect_spec.rb b/spec/ruby/library/openstruct/inspect_spec.rb index e2fed41528..81da96d6bf 100644 --- a/spec/ruby/library/openstruct/inspect_spec.rb +++ b/spec/ruby/library/openstruct/inspect_spec.rb @@ -1,8 +1,8 @@ require_relative '../../spec_helper' require 'ostruct' -require_relative 'fixtures/classes' -require_relative 'shared/inspect' describe "OpenStruct#inspect" do - it_behaves_like :ostruct_inspect, :inspect + it "is an alias of OpenStruct#to_s" do + OpenStruct.instance_method(:inspect).should == OpenStruct.instance_method(:to_s) + end end diff --git a/spec/ruby/library/openstruct/marshal_load_spec.rb b/spec/ruby/library/openstruct/marshal_load_spec.rb index 342e5e68cd..a8cdda3b43 100644 --- a/spec/ruby/library/openstruct/marshal_load_spec.rb +++ b/spec/ruby/library/openstruct/marshal_load_spec.rb @@ -6,7 +6,7 @@ describe "OpenStruct#marshal_load when passed [Hash]" do os = OpenStruct.new os.send :marshal_load, age: 20, name: "John" - os.age.should eql(20) + os.age.should.eql?(20) os.name.should == "John" end end diff --git a/spec/ruby/library/openstruct/method_missing_spec.rb b/spec/ruby/library/openstruct/method_missing_spec.rb index 89f83d07b3..cf6734d629 100644 --- a/spec/ruby/library/openstruct/method_missing_spec.rb +++ b/spec/ruby/library/openstruct/method_missing_spec.rb @@ -7,18 +7,18 @@ describe "OpenStruct#method_missing when called with a method name ending in '=' end it "raises an ArgumentError when not passed any additional arguments" do - -> { @os.send(:test=) }.should raise_error(ArgumentError) + -> { @os.send(:test=) }.should.raise(ArgumentError) end end describe "OpenStruct#method_missing when passed additional arguments" do it "raises a NoMethodError when the key does not exist" do os = OpenStruct.new - -> { os.test(1, 2, 3) }.should raise_error(NoMethodError) + -> { os.test(1, 2, 3) }.should.raise(NoMethodError) end it "raises an ArgumentError when the key exists" do os = OpenStruct.new(test: 20) - -> { os.test(1, 2, 3) }.should raise_error(ArgumentError) + -> { os.test(1, 2, 3) }.should.raise(ArgumentError) end end diff --git a/spec/ruby/library/openstruct/new_spec.rb b/spec/ruby/library/openstruct/new_spec.rb index 5d2cacea40..9e53948c82 100644 --- a/spec/ruby/library/openstruct/new_spec.rb +++ b/spec/ruby/library/openstruct/new_spec.rb @@ -7,8 +7,8 @@ describe "OpenStruct.new when passed [Hash]" do end it "creates an attribute for each key of the passed Hash" do - @os.age.should eql(70) - @os.pension.should eql(300) + @os.age.should.eql?(70) + @os.pension.should.eql?(300) @os.name.should == "John Smith" end end diff --git a/spec/ruby/library/openstruct/shared/inspect.rb b/spec/ruby/library/openstruct/shared/inspect.rb deleted file mode 100644 index ffcd690e1f..0000000000 --- a/spec/ruby/library/openstruct/shared/inspect.rb +++ /dev/null @@ -1,20 +0,0 @@ -describe :ostruct_inspect, shared: true do - it "returns a String representation of self" do - os = OpenStruct.new(name: "John Smith") - os.send(@method).should == "#<OpenStruct name=\"John Smith\">" - - os = OpenStruct.new(age: 20, name: "John Smith") - os.send(@method).should be_kind_of(String) - end - - it "correctly handles self-referential OpenStructs" do - os = OpenStruct.new - os.self = os - os.send(@method).should == "#<OpenStruct self=#<OpenStruct ...>>" - end - - it "correctly handles OpenStruct subclasses" do - os = OpenStructSpecs::OpenStructSub.new(name: "John Smith") - os.send(@method).should == "#<OpenStructSpecs::OpenStructSub name=\"John Smith\">" - end -end diff --git a/spec/ruby/library/openstruct/to_h_spec.rb b/spec/ruby/library/openstruct/to_h_spec.rb index 6c272bcc71..7d9c7db5dc 100644 --- a/spec/ruby/library/openstruct/to_h_spec.rb +++ b/spec/ruby/library/openstruct/to_h_spec.rb @@ -19,7 +19,7 @@ describe "OpenStruct#to_h" do end it "does not return the hash used as initializer" do - @to_h.should_not equal(@h) + @to_h.should_not.equal?(@h) end it "returns a Hash that is independent from the struct" do @@ -36,17 +36,17 @@ describe "OpenStruct#to_h" do it "raises ArgumentError if block returns longer or shorter array" do -> do @os.to_h { |k, v| [k.to_s, v*2, 1] } - end.should raise_error(ArgumentError, /element has wrong array length/) + end.should.raise(ArgumentError, /element has wrong array length/) -> do @os.to_h { |k, v| [k] } - end.should raise_error(ArgumentError, /element has wrong array length/) + end.should.raise(ArgumentError, /element has wrong array length/) end it "raises TypeError if block returns something other than Array" do -> do @os.to_h { |k, v| "not-array" } - end.should raise_error(TypeError, /wrong element type String/) + end.should.raise(TypeError, /wrong element type String/) end it "coerces returned pair to Array with #to_ary" do @@ -62,7 +62,7 @@ describe "OpenStruct#to_h" do -> do @os.to_h { |k| x } - end.should raise_error(TypeError, /wrong element type MockObject/) + end.should.raise(TypeError, /wrong element type MockObject/) end end end diff --git a/spec/ruby/library/openstruct/to_s_spec.rb b/spec/ruby/library/openstruct/to_s_spec.rb index 73d91bf981..9131cd4897 100644 --- a/spec/ruby/library/openstruct/to_s_spec.rb +++ b/spec/ruby/library/openstruct/to_s_spec.rb @@ -1,8 +1,24 @@ require_relative '../../spec_helper' require 'ostruct' require_relative 'fixtures/classes' -require_relative 'shared/inspect' describe "OpenStruct#to_s" do - it_behaves_like :ostruct_inspect, :to_s + it "returns a String representation of self" do + os = OpenStruct.new(name: "John Smith") + os.to_s.should == "#<OpenStruct name=\"John Smith\">" + + os = OpenStruct.new(age: 20, name: "John Smith") + os.to_s.should.is_a?(String) + end + + it "correctly handles self-referential OpenStructs" do + os = OpenStruct.new + os.self = os + os.to_s.should == "#<OpenStruct self=#<OpenStruct ...>>" + end + + it "correctly handles OpenStruct subclasses" do + os = OpenStructSpecs::OpenStructSub.new(name: "John Smith") + os.to_s.should == "#<OpenStructSpecs::OpenStructSub name=\"John Smith\">" + end end diff --git a/spec/ruby/library/pathname/birthtime_spec.rb b/spec/ruby/library/pathname/birthtime_spec.rb index 109c112303..387f0aa54d 100644 --- a/spec/ruby/library/pathname/birthtime_spec.rb +++ b/spec/ruby/library/pathname/birthtime_spec.rb @@ -4,13 +4,13 @@ require 'pathname' describe "Pathname#birthtime" do platform_is :windows, :darwin, :freebsd, :netbsd do it "returns the birth time for self" do - Pathname.new(__FILE__).birthtime.should be_kind_of(Time) + Pathname.new(__FILE__).birthtime.should.is_a?(Time) end end platform_is :openbsd do it "raises an NotImplementedError" do - -> { Pathname.new(__FILE__).birthtime }.should raise_error(NotImplementedError) + -> { Pathname.new(__FILE__).birthtime }.should.raise(NotImplementedError) end end end diff --git a/spec/ruby/library/pathname/case_compare_spec.rb b/spec/ruby/library/pathname/case_compare_spec.rb new file mode 100644 index 0000000000..0cf799dd23 --- /dev/null +++ b/spec/ruby/library/pathname/case_compare_spec.rb @@ -0,0 +1,8 @@ +require_relative '../../spec_helper' +require 'pathname' + +describe "Pathname#===" do + it "is an alias of Pathname#==" do + Pathname.instance_method(:===).should == Pathname.instance_method(:==) + end +end diff --git a/spec/ruby/library/pathname/divide_spec.rb b/spec/ruby/library/pathname/divide_spec.rb index 8af79d0c8f..e5afc9f864 100644 --- a/spec/ruby/library/pathname/divide_spec.rb +++ b/spec/ruby/library/pathname/divide_spec.rb @@ -1,6 +1,8 @@ require_relative '../../spec_helper' -require_relative 'shared/plus' +require 'pathname' describe "Pathname#/" do - it_behaves_like :pathname_plus, :/ + it "is an alias of Pathname#+" do + Pathname.instance_method(:/).should == Pathname.instance_method(:+) + end end diff --git a/spec/ruby/library/pathname/empty_spec.rb b/spec/ruby/library/pathname/empty_spec.rb index 4deade5b64..9f0305a0f0 100644 --- a/spec/ruby/library/pathname/empty_spec.rb +++ b/spec/ruby/library/pathname/empty_spec.rb @@ -15,18 +15,18 @@ describe 'Pathname#empty?' do end it 'returns true when file is not empty' do - Pathname.new(__FILE__).empty?.should be_false + Pathname.new(__FILE__).empty?.should == false end it 'returns false when the directory is not empty' do - Pathname.new(__dir__).empty?.should be_false + Pathname.new(__dir__).empty?.should == false end it 'return true when file is empty' do - Pathname.new(@file).empty?.should be_true + Pathname.new(@file).empty?.should == true end it 'returns true when directory is empty' do - Pathname.new(@dir).empty?.should be_true + Pathname.new(@dir).empty?.should == true end end diff --git a/spec/ruby/library/pathname/glob_spec.rb b/spec/ruby/library/pathname/glob_spec.rb index de322bab47..e20e6f8f85 100644 --- a/spec/ruby/library/pathname/glob_spec.rb +++ b/spec/ruby/library/pathname/glob_spec.rb @@ -41,7 +41,7 @@ describe 'Pathname.glob' do it "raises an ArgumentError when supplied a keyword argument other than :base" do -> { Pathname.glob('*i*.rb', foo: @dir + 'lib') - }.should raise_error(ArgumentError, /unknown keyword: :?foo/) + }.should.raise(ArgumentError, "unknown keyword: :foo") end it "does not raise an ArgumentError when supplied a flag and :base keyword argument" do @@ -81,7 +81,7 @@ describe 'Pathname#glob' do it 'yields matching file paths to block' do ary = [] - Pathname.new(@dir).glob('lib/*i*.rb') { |p| ary << p }.should be_nil + Pathname.new(@dir).glob('lib/*i*.rb') { |p| ary << p }.should == nil ary.sort.should == [Pathname.new(@file_1), Pathname.new(@file_2)].sort end diff --git a/spec/ruby/library/pathname/inspect_spec.rb b/spec/ruby/library/pathname/inspect_spec.rb index 304746fbe5..3abba6cbb5 100644 --- a/spec/ruby/library/pathname/inspect_spec.rb +++ b/spec/ruby/library/pathname/inspect_spec.rb @@ -4,7 +4,7 @@ require 'pathname' describe "Pathname#inspect" do it "returns a consistent String" do result = Pathname.new('/tmp').inspect - result.should be_an_instance_of(String) + result.should.instance_of?(String) result.should == "#<Pathname:/tmp>" end end diff --git a/spec/ruby/library/pathname/new_spec.rb b/spec/ruby/library/pathname/new_spec.rb index 36226ed515..3ef9d9b76d 100644 --- a/spec/ruby/library/pathname/new_spec.rb +++ b/spec/ruby/library/pathname/new_spec.rb @@ -3,18 +3,18 @@ require 'pathname' describe "Pathname.new" do it "returns a new Pathname Object with 1 argument" do - Pathname.new('').should be_kind_of(Pathname) + Pathname.new('').should.is_a?(Pathname) end it "raises an ArgumentError when called with \0" do - -> { Pathname.new("\0")}.should raise_error(ArgumentError) + -> { Pathname.new("\0")}.should.raise(ArgumentError) end it "raises a TypeError if not passed a String type" do - -> { Pathname.new(nil) }.should raise_error(TypeError) - -> { Pathname.new(0) }.should raise_error(TypeError) - -> { Pathname.new(true) }.should raise_error(TypeError) - -> { Pathname.new(false) }.should raise_error(TypeError) + -> { Pathname.new(nil) }.should.raise(TypeError) + -> { Pathname.new(0) }.should.raise(TypeError) + -> { Pathname.new(true) }.should.raise(TypeError) + -> { Pathname.new(false) }.should.raise(TypeError) end it "initializes with an object with to_path" do diff --git a/spec/ruby/library/pathname/pathname_spec.rb b/spec/ruby/library/pathname/pathname_spec.rb index 0fb2881468..6fa6fd2bcb 100644 --- a/spec/ruby/library/pathname/pathname_spec.rb +++ b/spec/ruby/library/pathname/pathname_spec.rb @@ -3,11 +3,11 @@ require 'pathname' describe "Kernel#Pathname" do it "is a private instance method" do - Kernel.should have_private_instance_method(:Pathname) + Kernel.private_instance_methods(false).should.include?(:Pathname) end it "is also a public method" do - Kernel.should have_method(:Pathname) + Kernel.should.respond_to?(:Pathname) end it "returns same argument when called with a pathname argument" do diff --git a/spec/ruby/library/pathname/plus_spec.rb b/spec/ruby/library/pathname/plus_spec.rb index 57e472c266..76316df9d2 100644 --- a/spec/ruby/library/pathname/plus_spec.rb +++ b/spec/ruby/library/pathname/plus_spec.rb @@ -1,6 +1,9 @@ require_relative '../../spec_helper' -require_relative 'shared/plus' +require 'pathname' describe "Pathname#+" do - it_behaves_like :pathname_plus, :+ + it "appends a pathname to self" do + p = Pathname.new("/usr") + (p + "bin/ruby").should == Pathname.new("/usr/bin/ruby") + end end diff --git a/spec/ruby/library/pathname/realdirpath_spec.rb b/spec/ruby/library/pathname/realdirpath_spec.rb index a9e44e354e..e50741a737 100644 --- a/spec/ruby/library/pathname/realdirpath_spec.rb +++ b/spec/ruby/library/pathname/realdirpath_spec.rb @@ -4,7 +4,7 @@ require 'pathname' describe "Pathname#realdirpath" do it "returns a Pathname" do - Pathname.pwd.realdirpath.should be_an_instance_of(Pathname) + Pathname.pwd.realdirpath.should.instance_of?(Pathname) end end diff --git a/spec/ruby/library/pathname/realpath_spec.rb b/spec/ruby/library/pathname/realpath_spec.rb index f2c654308e..d8b87f57d0 100644 --- a/spec/ruby/library/pathname/realpath_spec.rb +++ b/spec/ruby/library/pathname/realpath_spec.rb @@ -4,7 +4,7 @@ require 'pathname' describe "Pathname#realpath" do it "returns a Pathname" do - Pathname.pwd.realpath.should be_an_instance_of(Pathname) + Pathname.pwd.realpath.should.instance_of?(Pathname) end end diff --git a/spec/ruby/library/pathname/relative_path_from_spec.rb b/spec/ruby/library/pathname/relative_path_from_spec.rb index 133a149849..7cbd22c3d6 100644 --- a/spec/ruby/library/pathname/relative_path_from_spec.rb +++ b/spec/ruby/library/pathname/relative_path_from_spec.rb @@ -7,11 +7,11 @@ describe "Pathname#relative_path_from" do end it "raises an error when the two paths do not share a common prefix" do - -> { relative_path_str('/usr', 'foo') }.should raise_error(ArgumentError) + -> { relative_path_str('/usr', 'foo') }.should.raise(ArgumentError) end it "raises an error when the base directory has .." do - -> { relative_path_str('a', '..') }.should raise_error(ArgumentError) + -> { relative_path_str('a', '..') }.should.raise(ArgumentError) end it "returns a path relative from root" do diff --git a/spec/ruby/library/pathname/shared/plus.rb b/spec/ruby/library/pathname/shared/plus.rb deleted file mode 100644 index b3b896ea43..0000000000 --- a/spec/ruby/library/pathname/shared/plus.rb +++ /dev/null @@ -1,8 +0,0 @@ -require 'pathname' - -describe :pathname_plus, shared: true do - it "appends a pathname to self" do - p = Pathname.new("/usr") - p.send(@method, "bin/ruby").should == Pathname.new("/usr/bin/ruby") - end -end diff --git a/spec/ruby/library/prime/each_spec.rb b/spec/ruby/library/prime/each_spec.rb index b99cf7cf0e..d81e952a88 100644 --- a/spec/ruby/library/prime/each_spec.rb +++ b/spec/ruby/library/prime/each_spec.rb @@ -32,11 +32,11 @@ describe :prime_each, shared: true do all_prime &&= (2..Math.sqrt(prime)).all? { |d| prime % d != 0 } end - all_prime.should be_true + all_prime.should == true end it "returns the last evaluated expression in the passed block" do - @object.each { break :value }.should equal(:value) + @object.each { break :value }.should.equal?(:value) end describe "when not passed a block" do @@ -45,23 +45,23 @@ describe :prime_each, shared: true do end it "returns an object that is Enumerable" do - @prime_enum.each.should be_kind_of(Enumerable) + @prime_enum.each.should.is_a?(Enumerable) end it "returns an object that responds to #with_index" do - @prime_enum.should respond_to(:with_index) + @prime_enum.should.respond_to?(:with_index) end it "returns an object that responds to #with_object" do - @prime_enum.should respond_to(:with_object) + @prime_enum.should.respond_to?(:with_object) end it "returns an object that responds to #next" do - @prime_enum.should respond_to(:next) + @prime_enum.should.respond_to?(:next) end it "returns an object that responds to #rewind" do - @prime_enum.should respond_to(:rewind) + @prime_enum.should.respond_to?(:rewind) end it "yields primes starting at 2 independent of prior enumerators" do @@ -106,13 +106,13 @@ describe :prime_each_with_arguments, shared: true do ScratchPad.recorded.all? do |prime| (2..Math.sqrt(prime)).all? { |d| prime % d != 0 } - end.should be_true + end.should == true - ScratchPad.recorded.all? { |prime| prime <= bound }.should be_true + ScratchPad.recorded.all? { |prime| prime <= bound }.should == true end it "returns nil when no prime is generated" do - @object.each(1) { :value }.should be_nil + @object.each(1) { :value }.should == nil end it "yields primes starting at 2 independent of prior enumeration" do @@ -132,7 +132,7 @@ describe :prime_each_with_arguments, shared: true do 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 + @object.each(bound).all? { |prime| prime <= bound }.should == true end end end diff --git a/spec/ruby/library/prime/instance_spec.rb b/spec/ruby/library/prime/instance_spec.rb index 5183f36901..680895eb64 100644 --- a/spec/ruby/library/prime/instance_spec.rb +++ b/spec/ruby/library/prime/instance_spec.rb @@ -3,12 +3,12 @@ require 'prime' describe "Prime.instance" do it "returns a object representing the set of prime numbers" do - Prime.instance.should be_kind_of(Prime) + Prime.instance.should.is_a?(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) + Prime.instance.should_not.respond_to?(:succ) + Prime.instance.should_not.respond_to?(:next) end it "does not complain anything" do @@ -16,6 +16,6 @@ describe "Prime.instance" do end it "raises a ArgumentError when is called with some arguments" do - -> { Prime.instance(1) }.should raise_error(ArgumentError) + -> { Prime.instance(1) }.should.raise(ArgumentError) 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 be03438a6f..5631b22d0a 100644 --- a/spec/ruby/library/prime/integer/prime_division_spec.rb +++ b/spec/ruby/library/prime/integer/prime_division_spec.rb @@ -14,6 +14,6 @@ describe "Integer#prime_division" do -1.prime_division.should == [[-1, 1]] end it "raises ZeroDivisionError for 0" do - -> { 0.prime_division }.should raise_error(ZeroDivisionError) + -> { 0.prime_division }.should.raise(ZeroDivisionError) end end diff --git a/spec/ruby/library/prime/integer/prime_spec.rb b/spec/ruby/library/prime/integer/prime_spec.rb index 53de76d5ab..d24f883b19 100644 --- a/spec/ruby/library/prime/integer/prime_spec.rb +++ b/spec/ruby/library/prime/integer/prime_spec.rb @@ -3,15 +3,15 @@ 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) + 2.prime?.should == true + 3.prime?.should == true + (2**31-1).prime?.should == 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 + 4.prime?.should == false + 15.prime?.should == false + (2**32-1).prime?.should == false + ( (2**17-1)*(2**19-1) ).prime?.should == false # M6*M7 end end diff --git a/spec/ruby/library/prime/next_spec.rb b/spec/ruby/library/prime/next_spec.rb index 39c4ae16ae..07e80ab3a5 100644 --- a/spec/ruby/library/prime/next_spec.rb +++ b/spec/ruby/library/prime/next_spec.rb @@ -1,7 +1,11 @@ require_relative '../../spec_helper' -require_relative 'shared/next' require 'prime' describe "Prime#next" do - it_behaves_like :prime_next, :next + it "returns the element at the current position and moves forward" do + p = Prime.instance.each + p.next.should == 2 + p.next.should == 3 + p.next.next.should == 6 + end end diff --git a/spec/ruby/library/prime/prime_division_spec.rb b/spec/ruby/library/prime/prime_division_spec.rb index 6293478f59..cc39969a56 100644 --- a/spec/ruby/library/prime/prime_division_spec.rb +++ b/spec/ruby/library/prime/prime_division_spec.rb @@ -16,10 +16,10 @@ describe "Prime.prime_division" do end it "includes [[-1, 1]] in the divisors of a negative number" do - Prime.prime_division(-10).should include([-1, 1]) + Prime.prime_division(-10).should.include?([-1, 1]) end it "raises ZeroDivisionError for 0" do - -> { Prime.prime_division(0) }.should raise_error(ZeroDivisionError) + -> { Prime.prime_division(0) }.should.raise(ZeroDivisionError) end end diff --git a/spec/ruby/library/prime/prime_spec.rb b/spec/ruby/library/prime/prime_spec.rb index 0896c7f0f3..207c763aed 100644 --- a/spec/ruby/library/prime/prime_spec.rb +++ b/spec/ruby/library/prime/prime_spec.rb @@ -3,15 +3,15 @@ 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) + Prime.prime?(2).should == true + Prime.prime?(3).should == true + Prime.prime?(2**31-1).should == 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 + Prime.prime?(4).should == false + Prime.prime?(15).should == false + Prime.prime?(2**32-1).should == false + Prime.prime?( (2**17-1)*(2**19-1) ).should == false # M6*M7 end end diff --git a/spec/ruby/library/prime/shared/next.rb b/spec/ruby/library/prime/shared/next.rb deleted file mode 100644 index f79b2c051e..0000000000 --- a/spec/ruby/library/prime/shared/next.rb +++ /dev/null @@ -1,8 +0,0 @@ -describe :prime_next, shared: true do - it "returns the element at the current position and moves forward" do - p = Prime.instance.each - p.next.should == 2 - p.next.should == 3 - p.next.next.should == 6 - end -end diff --git a/spec/ruby/library/prime/succ_spec.rb b/spec/ruby/library/prime/succ_spec.rb index 34c18d2ba0..86f76c2513 100644 --- a/spec/ruby/library/prime/succ_spec.rb +++ b/spec/ruby/library/prime/succ_spec.rb @@ -1,7 +1,9 @@ require_relative '../../spec_helper' -require_relative 'shared/next' require 'prime' describe "Prime#succ" do - it_behaves_like :prime_next, :succ + it "is an alias of Prime#next" do + p = Prime.instance.each + p.method(:succ).should == p.method(:next) + end end diff --git a/spec/ruby/library/random/formatter/alphanumeric_spec.rb b/spec/ruby/library/random/formatter/alphanumeric_spec.rb index 9bd325e1d0..62a4698d0d 100644 --- a/spec/ruby/library/random/formatter/alphanumeric_spec.rb +++ b/spec/ruby/library/random/formatter/alphanumeric_spec.rb @@ -30,7 +30,7 @@ describe "Random::Formatter#alphanumeric" do it "raises an ArgumentError if the size is not numeric" do -> { @object.alphanumeric("10") - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) end it "does not coerce the size argument with #to_int" do @@ -38,19 +38,17 @@ describe "Random::Formatter#alphanumeric" do size.should_not_receive(:to_int) -> { @object.alphanumeric(size) - }.should raise_error(ArgumentError) + }.should.raise(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 "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 + 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 diff --git a/spec/ruby/library/rbconfig/rbconfig_spec.rb b/spec/ruby/library/rbconfig/rbconfig_spec.rb index b9a4588bf0..4195128a05 100644 --- a/spec/ruby/library/rbconfig/rbconfig_spec.rb +++ b/spec/ruby/library/rbconfig/rbconfig_spec.rb @@ -4,8 +4,8 @@ require 'rbconfig' describe 'RbConfig::CONFIG' do it 'values are all strings' do RbConfig::CONFIG.each do |k, v| - k.should be_kind_of String - v.should be_kind_of String + k.should.is_a? String + v.should.is_a? String end end @@ -32,7 +32,7 @@ describe 'RbConfig::CONFIG' do it "['sitelibdir'] is set and is part of $LOAD_PATH" do sitelibdir = RbConfig::CONFIG['sitelibdir'] - sitelibdir.should be_kind_of String + sitelibdir.should.is_a? String $LOAD_PATH.map{|path| File.realpath(path) rescue path }.should.include? sitelibdir end end @@ -80,7 +80,7 @@ describe 'RbConfig::CONFIG' do ar = RbConfig::CONFIG.fetch('AR') out = `#{ar} --version` $?.should.success? - out.should_not be_empty + out.should_not.empty? end it "['STRIP'] exists and can be executed" do diff --git a/spec/ruby/library/rbconfig/sizeof/limits_spec.rb b/spec/ruby/library/rbconfig/sizeof/limits_spec.rb index 776099da27..08b1185965 100644 --- a/spec/ruby/library/rbconfig/sizeof/limits_spec.rb +++ b/spec/ruby/library/rbconfig/sizeof/limits_spec.rb @@ -3,13 +3,13 @@ require 'rbconfig/sizeof' describe "RbConfig::LIMITS" do it "is a Hash" do - RbConfig::LIMITS.should be_kind_of(Hash) + RbConfig::LIMITS.should.is_a?(Hash) end it "has string keys and numeric values" do RbConfig::LIMITS.each do |key, value| - key.should be_kind_of String - value.should be_kind_of Numeric + key.should.is_a? String + value.should.is_a? Numeric end end diff --git a/spec/ruby/library/rbconfig/sizeof/sizeof_spec.rb b/spec/ruby/library/rbconfig/sizeof/sizeof_spec.rb index f2582dc4fd..b74dae5166 100644 --- a/spec/ruby/library/rbconfig/sizeof/sizeof_spec.rb +++ b/spec/ruby/library/rbconfig/sizeof/sizeof_spec.rb @@ -3,13 +3,13 @@ require 'rbconfig/sizeof' describe "RbConfig::SIZEOF" do it "is a Hash" do - RbConfig::SIZEOF.should be_kind_of(Hash) + RbConfig::SIZEOF.should.is_a?(Hash) end it "has string keys and integer values" do RbConfig::SIZEOF.each do |key, value| - key.should be_kind_of String - value.should be_kind_of Integer + key.should.is_a? String + value.should.is_a? Integer 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 2c6d1f4e93..521a750bf7 100644 --- a/spec/ruby/library/rbconfig/unicode_emoji_version_spec.rb +++ b/spec/ruby/library/rbconfig/unicode_emoji_version_spec.rb @@ -9,9 +9,9 @@ describe "RbConfig::CONFIG['UNICODE_EMOJI_VERSION']" do end # Caution: ruby_version_is means is_or_later - ruby_version_is "3.5" do - it "is 16.0" do - RbConfig::CONFIG['UNICODE_EMOJI_VERSION'].should == "16.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 961bb989a5..5cdde74f79 100644 --- a/spec/ruby/library/rbconfig/unicode_version_spec.rb +++ b/spec/ruby/library/rbconfig/unicode_version_spec.rb @@ -9,9 +9,9 @@ describe "RbConfig::CONFIG['UNICODE_VERSION']" do end # Caution: ruby_version_is means is_or_later - ruby_version_is "3.5" do - it "is 16.0.0" do - RbConfig::CONFIG['UNICODE_VERSION'].should == "16.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/readline/basic_quote_characters_spec.rb b/spec/ruby/library/readline/basic_quote_characters_spec.rb index 216899d875..f6467c8be4 100644 --- a/spec/ruby/library/readline/basic_quote_characters_spec.rb +++ b/spec/ruby/library/readline/basic_quote_characters_spec.rb @@ -4,7 +4,7 @@ platform_is_not :darwin do with_feature :readline do describe "Readline.basic_quote_characters" do it "returns not nil" do - Readline.basic_quote_characters.should_not be_nil + Readline.basic_quote_characters.should_not == nil end end diff --git a/spec/ruby/library/readline/basic_word_break_characters_spec.rb b/spec/ruby/library/readline/basic_word_break_characters_spec.rb index daa0e1cb76..ef05d6560b 100644 --- a/spec/ruby/library/readline/basic_word_break_characters_spec.rb +++ b/spec/ruby/library/readline/basic_word_break_characters_spec.rb @@ -3,7 +3,7 @@ require_relative 'spec_helper' with_feature :readline do describe "Readline.basic_word_break_characters" do it "returns not nil" do - Readline.basic_word_break_characters.should_not be_nil + Readline.basic_word_break_characters.should_not == nil end end diff --git a/spec/ruby/library/readline/completer_quote_characters_spec.rb b/spec/ruby/library/readline/completer_quote_characters_spec.rb index 86c58f3cf6..1109ea1f03 100644 --- a/spec/ruby/library/readline/completer_quote_characters_spec.rb +++ b/spec/ruby/library/readline/completer_quote_characters_spec.rb @@ -3,7 +3,7 @@ require_relative 'spec_helper' with_feature :readline do describe "Readline.completer_quote_characters" do it "returns nil" do - Readline.completer_quote_characters.should be_nil + Readline.completer_quote_characters.should == nil end end diff --git a/spec/ruby/library/readline/completer_word_break_characters_spec.rb b/spec/ruby/library/readline/completer_word_break_characters_spec.rb index c72f1135c4..91a002b9de 100644 --- a/spec/ruby/library/readline/completer_word_break_characters_spec.rb +++ b/spec/ruby/library/readline/completer_word_break_characters_spec.rb @@ -3,7 +3,7 @@ require_relative 'spec_helper' with_feature :readline do describe "Readline.completer_word_break_characters" do it "returns nil" do - Readline.completer_word_break_characters.should be_nil + Readline.completer_word_break_characters.should == nil end end diff --git a/spec/ruby/library/readline/completion_append_character_spec.rb b/spec/ruby/library/readline/completion_append_character_spec.rb index 615b523f4e..2a14d5d30e 100644 --- a/spec/ruby/library/readline/completion_append_character_spec.rb +++ b/spec/ruby/library/readline/completion_append_character_spec.rb @@ -3,7 +3,7 @@ require_relative 'spec_helper' with_feature :readline do describe "Readline.completion_append_character" do it "returns not nil" do - Readline.completion_append_character.should_not be_nil + Readline.completion_append_character.should_not == nil end end diff --git a/spec/ruby/library/readline/completion_case_fold_spec.rb b/spec/ruby/library/readline/completion_case_fold_spec.rb index 966f5d6c79..b6a4aab101 100644 --- a/spec/ruby/library/readline/completion_case_fold_spec.rb +++ b/spec/ruby/library/readline/completion_case_fold_spec.rb @@ -3,7 +3,7 @@ require_relative 'spec_helper' with_feature :readline do describe "Readline.completion_case_fold" do it "returns nil" do - Readline.completion_case_fold.should be_nil + Readline.completion_case_fold.should == nil end end diff --git a/spec/ruby/library/readline/completion_proc_spec.rb b/spec/ruby/library/readline/completion_proc_spec.rb index 2d7a353ec5..037fc6de21 100644 --- a/spec/ruby/library/readline/completion_proc_spec.rb +++ b/spec/ruby/library/readline/completion_proc_spec.rb @@ -3,7 +3,7 @@ require_relative 'spec_helper' with_feature :readline do describe "Readline.completion_proc" do it "returns nil" do - Readline.completion_proc.should be_nil + Readline.completion_proc.should == nil end end @@ -16,7 +16,7 @@ with_feature :readline do end it "returns an ArgumentError if not given an Proc or #call" do - -> { Readline.completion_proc = "test" }.should raise_error(ArgumentError) + -> { Readline.completion_proc = "test" }.should.raise(ArgumentError) end end end diff --git a/spec/ruby/library/readline/constants_spec.rb b/spec/ruby/library/readline/constants_spec.rb index 8fee274866..91536ce1cc 100644 --- a/spec/ruby/library/readline/constants_spec.rb +++ b/spec/ruby/library/readline/constants_spec.rb @@ -11,8 +11,8 @@ with_feature :readline do describe "Readline::VERSION" do it "is defined and is a non-empty String" do Readline.const_defined?(:VERSION).should == true - Readline::VERSION.should be_kind_of(String) - Readline::VERSION.should_not be_empty + Readline::VERSION.should.is_a?(String) + Readline::VERSION.should_not.empty? end end end diff --git a/spec/ruby/library/readline/emacs_editing_mode_spec.rb b/spec/ruby/library/readline/emacs_editing_mode_spec.rb index f7e8eda982..93ded3d023 100644 --- a/spec/ruby/library/readline/emacs_editing_mode_spec.rb +++ b/spec/ruby/library/readline/emacs_editing_mode_spec.rb @@ -4,7 +4,7 @@ platform_is_not :darwin do with_feature :readline do describe "Readline.emacs_editing_mode" do it "returns nil" do - Readline.emacs_editing_mode.should be_nil + Readline.emacs_editing_mode.should == nil end end end diff --git a/spec/ruby/library/readline/filename_quote_characters_spec.rb b/spec/ruby/library/readline/filename_quote_characters_spec.rb index de8ce700a8..6bcb04fc79 100644 --- a/spec/ruby/library/readline/filename_quote_characters_spec.rb +++ b/spec/ruby/library/readline/filename_quote_characters_spec.rb @@ -4,7 +4,7 @@ platform_is_not :darwin do with_feature :readline do describe "Readline.filename_quote_characters" do it "returns nil" do - Readline.filename_quote_characters.should be_nil + Readline.filename_quote_characters.should == nil end end diff --git a/spec/ruby/library/readline/history/append_spec.rb b/spec/ruby/library/readline/history/append_spec.rb index 5383271374..be0e515b84 100644 --- a/spec/ruby/library/readline/history/append_spec.rb +++ b/spec/ruby/library/readline/history/append_spec.rb @@ -22,7 +22,7 @@ with_feature :readline do end it "raises a TypeError when the passed Object can't be converted to a String" do - -> { Readline::HISTORY << mock("Object") }.should raise_error(TypeError) + -> { Readline::HISTORY << mock("Object") }.should.raise(TypeError) end end end diff --git a/spec/ruby/library/readline/history/delete_at_spec.rb b/spec/ruby/library/readline/history/delete_at_spec.rb index 3bd577e75c..4383ff7e83 100644 --- a/spec/ruby/library/readline/history/delete_at_spec.rb +++ b/spec/ruby/library/readline/history/delete_at_spec.rb @@ -31,8 +31,8 @@ with_feature :readline do end it "raises an IndexError when the given index is greater than the history size" do - -> { Readline::HISTORY.delete_at(10) }.should raise_error(IndexError) - -> { Readline::HISTORY.delete_at(-10) }.should raise_error(IndexError) + -> { Readline::HISTORY.delete_at(10) }.should.raise(IndexError) + -> { Readline::HISTORY.delete_at(-10) }.should.raise(IndexError) end end end diff --git a/spec/ruby/library/readline/history/element_reference_spec.rb b/spec/ruby/library/readline/history/element_reference_spec.rb index 0a74f3d62d..1f1642626f 100644 --- a/spec/ruby/library/readline/history/element_reference_spec.rb +++ b/spec/ruby/library/readline/history/element_reference_spec.rb @@ -23,13 +23,13 @@ with_feature :readline do end it "raises an IndexError when there is no item at the passed index" do - -> { Readline::HISTORY[-10] }.should raise_error(IndexError) - -> { Readline::HISTORY[-9] }.should raise_error(IndexError) - -> { Readline::HISTORY[-8] }.should raise_error(IndexError) + -> { Readline::HISTORY[-10] }.should.raise(IndexError) + -> { Readline::HISTORY[-9] }.should.raise(IndexError) + -> { Readline::HISTORY[-8] }.should.raise(IndexError) - -> { Readline::HISTORY[8] }.should raise_error(IndexError) - -> { Readline::HISTORY[9] }.should raise_error(IndexError) - -> { Readline::HISTORY[10] }.should raise_error(IndexError) + -> { Readline::HISTORY[8] }.should.raise(IndexError) + -> { Readline::HISTORY[9] }.should.raise(IndexError) + -> { Readline::HISTORY[10] }.should.raise(IndexError) end end end diff --git a/spec/ruby/library/readline/history/element_set_spec.rb b/spec/ruby/library/readline/history/element_set_spec.rb index 776adaacd1..0787b6343d 100644 --- a/spec/ruby/library/readline/history/element_set_spec.rb +++ b/spec/ruby/library/readline/history/element_set_spec.rb @@ -17,7 +17,7 @@ with_feature :readline do end it "raises an IndexError when there is no item at the passed positive index" do - -> { Readline::HISTORY[10] = "test" }.should raise_error(IndexError) + -> { Readline::HISTORY[10] = "test" }.should.raise(IndexError) end it "sets the item at the given index" do @@ -29,7 +29,7 @@ with_feature :readline do end it "raises an IndexError when there is no item at the passed negative index" do - -> { Readline::HISTORY[10] = "test" }.should raise_error(IndexError) + -> { Readline::HISTORY[10] = "test" }.should.raise(IndexError) end end end diff --git a/spec/ruby/library/readline/history/empty_spec.rb b/spec/ruby/library/readline/history/empty_spec.rb index 31d01d9601..5b722dccd3 100644 --- a/spec/ruby/library/readline/history/empty_spec.rb +++ b/spec/ruby/library/readline/history/empty_spec.rb @@ -3,11 +3,11 @@ require_relative '../spec_helper' with_feature :readline do describe "Readline::HISTORY.empty?" do it "returns true when the history is empty" do - Readline::HISTORY.should be_empty + Readline::HISTORY.should.empty? Readline::HISTORY.push("test") - Readline::HISTORY.should_not be_empty + Readline::HISTORY.should_not.empty? Readline::HISTORY.pop - Readline::HISTORY.should be_empty + Readline::HISTORY.should.empty? end end end diff --git a/spec/ruby/library/readline/history/history_spec.rb b/spec/ruby/library/readline/history/history_spec.rb index 927dd52ebf..3233071033 100644 --- a/spec/ruby/library/readline/history/history_spec.rb +++ b/spec/ruby/library/readline/history/history_spec.rb @@ -3,7 +3,7 @@ require_relative '../spec_helper' with_feature :readline do describe "Readline::HISTORY" do it "is extended with the Enumerable module" do - Readline::HISTORY.should be_kind_of(Enumerable) + Readline::HISTORY.should.is_a?(Enumerable) end end end diff --git a/spec/ruby/library/readline/history/pop_spec.rb b/spec/ruby/library/readline/history/pop_spec.rb index 156a8a06f8..0b780a38cc 100644 --- a/spec/ruby/library/readline/history/pop_spec.rb +++ b/spec/ruby/library/readline/history/pop_spec.rb @@ -3,7 +3,7 @@ require_relative '../spec_helper' with_feature :readline do describe "Readline::HISTORY.pop" do it "returns nil when the history is empty" do - Readline::HISTORY.pop.should be_nil + Readline::HISTORY.pop.should == nil end it "returns and removes the last item from the history" do diff --git a/spec/ruby/library/readline/history/push_spec.rb b/spec/ruby/library/readline/history/push_spec.rb index 53505ccba6..4bbf1763a1 100644 --- a/spec/ruby/library/readline/history/push_spec.rb +++ b/spec/ruby/library/readline/history/push_spec.rb @@ -20,7 +20,7 @@ with_feature :readline do end it "raises a TypeError when the passed Object can't be converted to a String" do - -> { Readline::HISTORY.push(mock("Object")) }.should raise_error(TypeError) + -> { Readline::HISTORY.push(mock("Object")) }.should.raise(TypeError) end end end diff --git a/spec/ruby/library/readline/history/shift_spec.rb b/spec/ruby/library/readline/history/shift_spec.rb index 9aad7d5399..d852480a2a 100644 --- a/spec/ruby/library/readline/history/shift_spec.rb +++ b/spec/ruby/library/readline/history/shift_spec.rb @@ -3,7 +3,7 @@ require_relative '../spec_helper' with_feature :readline do describe "Readline::HISTORY.shift" do it "returns nil when the history is empty" do - Readline::HISTORY.shift.should be_nil + Readline::HISTORY.shift.should == nil end it "returns and removes the first item from the history" do diff --git a/spec/ruby/library/readline/vi_editing_mode_spec.rb b/spec/ruby/library/readline/vi_editing_mode_spec.rb index 6622962ceb..3ce4f5a7e6 100644 --- a/spec/ruby/library/readline/vi_editing_mode_spec.rb +++ b/spec/ruby/library/readline/vi_editing_mode_spec.rb @@ -4,7 +4,7 @@ platform_is_not :darwin do with_feature :readline do describe "Readline.vi_editing_mode" do it "returns nil" do - Readline.vi_editing_mode.should be_nil + Readline.vi_editing_mode.should == nil end end end diff --git a/spec/ruby/library/resolv/get_address_spec.rb b/spec/ruby/library/resolv/get_address_spec.rb index ecc2cdf7de..9caa94643a 100644 --- a/spec/ruby/library/resolv/get_address_spec.rb +++ b/spec/ruby/library/resolv/get_address_spec.rb @@ -14,6 +14,6 @@ describe "Resolv#getaddress" do res = Resolv.new([]) -> { res.getaddress("should.raise.error.") - }.should raise_error(Resolv::ResolvError) + }.should.raise(Resolv::ResolvError) end end diff --git a/spec/ruby/library/resolv/get_name_spec.rb b/spec/ruby/library/resolv/get_name_spec.rb index 3ef97a2cea..81e0cda28d 100644 --- a/spec/ruby/library/resolv/get_name_spec.rb +++ b/spec/ruby/library/resolv/get_name_spec.rb @@ -13,6 +13,6 @@ describe "Resolv#getname" do res = Resolv.new([]) -> { res.getname("should.raise.error") - }.should raise_error(Resolv::ResolvError) + }.should.raise(Resolv::ResolvError) end end diff --git a/spec/ruby/library/ripper/lex_spec.rb b/spec/ruby/library/ripper/lex_spec.rb index 97cfb06904..0255480579 100644 --- a/spec/ruby/library/ripper/lex_spec.rb +++ b/spec/ruby/library/ripper/lex_spec.rb @@ -10,14 +10,14 @@ describe "Ripper.lex" do [[1, 5], :on_lparen, "(", 'BEG|LABEL'], [[1, 6], :on_ident, "a", 'ARG'], [[1, 7], :on_rparen, ")", 'ENDFN'], - [[1, 8], :on_sp, " ", 'BEG'], + [[1, 8], :on_semicolon, ";", 'BEG'], [[1, 9], :on_kw, "nil", 'END'], [[1, 12], :on_sp, " ", 'END'], [[1, 13], :on_kw, "end", 'END'] ] - lexed = Ripper.lex("def m(a) nil end") + lexed = Ripper.lex("def m(a);nil end") lexed.map { |e| - e[0...-1] + [e[-1].to_s.split('|').map { |s| s.sub(/^EXPR_/, '') }.join('|')] + e[0...-1] + [e[-1].to_s] }.should == expected end end diff --git a/spec/ruby/library/rubygems/gem/load_path_insert_index_spec.rb b/spec/ruby/library/rubygems/gem/load_path_insert_index_spec.rb index 9b37eaa43c..693c72a29e 100644 --- a/spec/ruby/library/rubygems/gem/load_path_insert_index_spec.rb +++ b/spec/ruby/library/rubygems/gem/load_path_insert_index_spec.rb @@ -4,7 +4,7 @@ require 'rubygems' describe "Gem.load_path_insert_index" do guard -> { RbConfig::TOPDIR } do it "is set for an installed Ruby" do - Gem.load_path_insert_index.should be_kind_of Integer + Gem.load_path_insert_index.should.is_a? Integer end end end diff --git a/spec/ruby/library/securerandom/base64_spec.rb b/spec/ruby/library/securerandom/base64_spec.rb index 34cd419ce2..49d4b8a029 100644 --- a/spec/ruby/library/securerandom/base64_spec.rb +++ b/spec/ruby/library/securerandom/base64_spec.rb @@ -6,13 +6,13 @@ describe "SecureRandom.base64" do it "generates a random base64 string out of specified number of random bytes" do (16..128).each do |idx| base64 = SecureRandom.base64(idx) - base64.should be_kind_of(String) + base64.should.is_a?(String) base64.length.should < 2 * idx base64.should =~ /^[A-Za-z0-9\+\/]+={0,2}$/ end base64 = SecureRandom.base64(16.5) - base64.should be_kind_of(String) + base64.should.is_a?(String) base64.length.should < 2 * 16 end @@ -32,19 +32,19 @@ describe "SecureRandom.base64" do end it "generates a random base64 string out of 32 random bytes" do - SecureRandom.base64.should be_kind_of(String) + SecureRandom.base64.should.is_a?(String) SecureRandom.base64.length.should < 32 * 2 end it "treats nil argument as default one and generates a random base64 string" do - SecureRandom.base64(nil).should be_kind_of(String) + SecureRandom.base64(nil).should.is_a?(String) SecureRandom.base64(nil).length.should < 32 * 2 end it "raises ArgumentError on negative arguments" do -> { SecureRandom.base64(-1) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) end it "tries to convert the passed argument to an Integer using #to_int" do diff --git a/spec/ruby/library/securerandom/hex_spec.rb b/spec/ruby/library/securerandom/hex_spec.rb index bdb920b217..ec33aca1ee 100644 --- a/spec/ruby/library/securerandom/hex_spec.rb +++ b/spec/ruby/library/securerandom/hex_spec.rb @@ -6,13 +6,13 @@ describe "SecureRandom.hex" do it "generates a random hex string of length twice the specified argument" do (1..64).each do |idx| hex = SecureRandom.hex(idx) - hex.should be_kind_of(String) + hex.should.is_a?(String) hex.length.should == 2 * idx end base64 = SecureRandom.hex(5.5) - base64.should be_kind_of(String) - base64.length.should eql(10) + base64.should.is_a?(String) + base64.length.should.eql?(10) end it "returns an empty string when argument is 0" do @@ -31,24 +31,24 @@ describe "SecureRandom.hex" do end it "generates a random hex string of length 32 if no argument is provided" do - SecureRandom.hex.should be_kind_of(String) + SecureRandom.hex.should.is_a?(String) SecureRandom.hex.length.should == 32 end it "treats nil argument as default one and generates a random hex string of length 32" do - SecureRandom.hex(nil).should be_kind_of(String) + SecureRandom.hex(nil).should.is_a?(String) SecureRandom.hex(nil).length.should == 32 end it "raises ArgumentError on negative arguments" do -> { SecureRandom.hex(-1) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) end it "tries to convert the passed argument to an Integer using #to_int" do obj = mock("to_int") obj.should_receive(:to_int).and_return(5) - SecureRandom.hex(obj).size.should eql(10) + SecureRandom.hex(obj).size.should.eql?(10) end end diff --git a/spec/ruby/library/securerandom/random_bytes_spec.rb b/spec/ruby/library/securerandom/random_bytes_spec.rb index ed3a02255c..4e30a53163 100644 --- a/spec/ruby/library/securerandom/random_bytes_spec.rb +++ b/spec/ruby/library/securerandom/random_bytes_spec.rb @@ -8,24 +8,24 @@ describe "SecureRandom.random_bytes" do it "generates a random binary string of length 16 if no argument is provided" do bytes = SecureRandom.random_bytes - bytes.should be_kind_of(String) + bytes.should.is_a?(String) bytes.length.should == 16 end it "generates a random binary string of length 16 if argument is nil" do bytes = SecureRandom.random_bytes(nil) - bytes.should be_kind_of(String) + bytes.should.is_a?(String) bytes.length.should == 16 end it "generates a random binary string of specified length" do (1..64).each do |idx| bytes = SecureRandom.random_bytes(idx) - bytes.should be_kind_of(String) + bytes.should.is_a?(String) bytes.length.should == idx end - SecureRandom.random_bytes(2.2).length.should eql(2) + SecureRandom.random_bytes(2.2).length.should.eql?(2) end it "generates different binary strings with subsequent invocations" do @@ -42,12 +42,12 @@ describe "SecureRandom.random_bytes" do it "raises ArgumentError on negative arguments" do -> { SecureRandom.random_bytes(-1) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) end it "tries to convert the passed argument to an Integer using #to_int" do obj = mock("to_int") obj.should_receive(:to_int).and_return(5) - SecureRandom.random_bytes(obj).size.should eql(5) + SecureRandom.random_bytes(obj).size.should.eql?(5) end end diff --git a/spec/ruby/library/securerandom/random_number_spec.rb b/spec/ruby/library/securerandom/random_number_spec.rb index bb25bc496e..97cd66f7bc 100644 --- a/spec/ruby/library/securerandom/random_number_spec.rb +++ b/spec/ruby/library/securerandom/random_number_spec.rb @@ -10,7 +10,7 @@ describe "SecureRandom.random_number" do it "generates a random positive number smaller then the positive integer argument" do (1..64).each do |idx| num = SecureRandom.random_number(idx) - num.should be_kind_of(Integer) + num.should.is_a?(Integer) 0.should <= num num.should < idx end @@ -20,7 +20,7 @@ describe "SecureRandom.random_number" do max = 12345678901234567890 11.times do num = SecureRandom.random_number max - num.should be_kind_of(Integer) + num.should.is_a?(Integer) 0.should <= num num.should < max end @@ -29,7 +29,7 @@ describe "SecureRandom.random_number" do it "generates a random float number between 0.0 and 1.0 if no argument provided" do 64.times do num = SecureRandom.random_number - num.should be_kind_of(Float) + num.should.is_a?(Float) 0.0.should <= num num.should < 1.0 end @@ -38,7 +38,7 @@ describe "SecureRandom.random_number" do it "generates a random value in given (integer) range limits" do 64.times do num = SecureRandom.random_number 11...13 - num.should be_kind_of(Integer) + num.should.is_a?(Integer) 11.should <= num num.should < 13 end @@ -49,7 +49,7 @@ describe "SecureRandom.random_number" do upper = 12345678901234567890 + 5 32.times do num = SecureRandom.random_number lower..upper - num.should be_kind_of(Integer) + num.should.is_a?(Integer) lower.should <= num num.should <= upper end @@ -58,7 +58,7 @@ describe "SecureRandom.random_number" do it "generates a random value in given (float) range limits" do 64.times do num = SecureRandom.random_number 0.6..0.9 - num.should be_kind_of(Float) + num.should.is_a?(Float) 0.6.should <= num num.should <= 0.9 end @@ -66,14 +66,14 @@ describe "SecureRandom.random_number" do 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) + num.should.is_a?(Float) 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) + num.should.is_a?(Float) 0.0.should <= num num.should < 1.0 end @@ -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.should_not include(val) + values.should_not.include?(val) values << val end end @@ -92,6 +92,6 @@ describe "SecureRandom.random_number" do it "raises ArgumentError if the argument is non-numeric" do -> { SecureRandom.random_number(Object.new) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) end end diff --git a/spec/ruby/library/shellwords/shellwords_spec.rb b/spec/ruby/library/shellwords/shellwords_spec.rb index fe86b6faab..d1b61e0a6e 100644 --- a/spec/ruby/library/shellwords/shellwords_spec.rb +++ b/spec/ruby/library/shellwords/shellwords_spec.rb @@ -19,11 +19,11 @@ describe "Shellwords#shellwords" do end it "raises ArgumentError when double quoted strings are misquoted" do - -> { Shellwords.shellwords('a "b c d e') }.should raise_error(ArgumentError) + -> { Shellwords.shellwords('a "b c d e') }.should.raise(ArgumentError) end it "raises ArgumentError when single quoted strings are misquoted" do - -> { Shellwords.shellwords("a 'b c d e") }.should raise_error(ArgumentError) + -> { Shellwords.shellwords("a 'b c d e") }.should.raise(ArgumentError) end # https://bugs.ruby-lang.org/issues/10055 diff --git a/spec/ruby/library/singleton/allocate_spec.rb b/spec/ruby/library/singleton/allocate_spec.rb index 6a1512d53b..a0094fb32a 100644 --- a/spec/ruby/library/singleton/allocate_spec.rb +++ b/spec/ruby/library/singleton/allocate_spec.rb @@ -3,6 +3,6 @@ require_relative 'fixtures/classes' describe "Singleton.allocate" do it "is a private method" do - -> { SingletonSpecs::MyClass.allocate }.should raise_error(NoMethodError) + -> { SingletonSpecs::MyClass.allocate }.should.raise(NoMethodError) end end diff --git a/spec/ruby/library/singleton/clone_spec.rb b/spec/ruby/library/singleton/clone_spec.rb index 3635bcd594..a7b7b731f5 100644 --- a/spec/ruby/library/singleton/clone_spec.rb +++ b/spec/ruby/library/singleton/clone_spec.rb @@ -3,6 +3,6 @@ require_relative 'fixtures/classes' describe "Singleton#clone" do it "is prevented" do - -> { SingletonSpecs::MyClass.instance.clone }.should raise_error(TypeError) + -> { SingletonSpecs::MyClass.instance.clone }.should.raise(TypeError) end end diff --git a/spec/ruby/library/singleton/dup_spec.rb b/spec/ruby/library/singleton/dup_spec.rb index 13d5a213e9..a0455f37b7 100644 --- a/spec/ruby/library/singleton/dup_spec.rb +++ b/spec/ruby/library/singleton/dup_spec.rb @@ -3,6 +3,6 @@ require_relative 'fixtures/classes' describe "Singleton#dup" do it "is prevented" do - -> { SingletonSpecs::MyClass.instance.dup }.should raise_error(TypeError) + -> { SingletonSpecs::MyClass.instance.dup }.should.raise(TypeError) end end diff --git a/spec/ruby/library/singleton/instance_spec.rb b/spec/ruby/library/singleton/instance_spec.rb index 1679728d4c..20cac602b5 100644 --- a/spec/ruby/library/singleton/instance_spec.rb +++ b/spec/ruby/library/singleton/instance_spec.rb @@ -3,28 +3,28 @@ require_relative 'fixtures/classes' describe "Singleton.instance" do it "returns an instance of the singleton class" do - SingletonSpecs::MyClass.instance.should be_kind_of(SingletonSpecs::MyClass) + SingletonSpecs::MyClass.instance.should.is_a?(SingletonSpecs::MyClass) end it "returns the same instance for multiple calls to instance" do - SingletonSpecs::MyClass.instance.should equal(SingletonSpecs::MyClass.instance) + SingletonSpecs::MyClass.instance.should.equal?(SingletonSpecs::MyClass.instance) end it "returns an instance of the singleton's subclasses" do - SingletonSpecs::MyClassChild.instance.should be_kind_of(SingletonSpecs::MyClassChild) + SingletonSpecs::MyClassChild.instance.should.is_a?(SingletonSpecs::MyClassChild) end it "returns the same instance for multiple class to instance on subclasses" do - SingletonSpecs::MyClassChild.instance.should equal(SingletonSpecs::MyClassChild.instance) + SingletonSpecs::MyClassChild.instance.should.equal?(SingletonSpecs::MyClassChild.instance) end it "returns an instance of the singleton's clone" do klone = SingletonSpecs::MyClassChild.clone - klone.instance.should be_kind_of(klone) + klone.instance.should.is_a?(klone) end it "returns the same instance for multiple class to instance on clones" do klone = SingletonSpecs::MyClassChild.clone - klone.instance.should equal(klone.instance) + klone.instance.should.equal?(klone.instance) end end diff --git a/spec/ruby/library/singleton/load_spec.rb b/spec/ruby/library/singleton/load_spec.rb index 4c753f9e7a..ab95d14640 100644 --- a/spec/ruby/library/singleton/load_spec.rb +++ b/spec/ruby/library/singleton/load_spec.rb @@ -1,21 +1,20 @@ require_relative '../../spec_helper' require_relative 'fixtures/classes' -# TODO: change to a.should be_equal(b) # TODO: write spec for cloning classes and calling private methods # TODO: write spec for private_methods not showing up via extended describe "Singleton._load" do it "returns the singleton instance for anything passed in" do klass = SingletonSpecs::MyClass - klass._load("").should equal(klass.instance) - klass._load("42").should equal(klass.instance) - klass._load(42).should equal(klass.instance) + klass._load("").should.equal?(klass.instance) + klass._load("42").should.equal?(klass.instance) + klass._load(42).should.equal?(klass.instance) end it "returns the singleton instance for anything passed in to subclass" do subklass = SingletonSpecs::MyClassChild - subklass._load("").should equal(subklass.instance) - subklass._load("42").should equal(subklass.instance) - subklass._load(42).should equal(subklass.instance) + subklass._load("").should.equal?(subklass.instance) + subklass._load("42").should.equal?(subklass.instance) + subklass._load(42).should.equal?(subklass.instance) end end diff --git a/spec/ruby/library/singleton/new_spec.rb b/spec/ruby/library/singleton/new_spec.rb index 2f45db819c..6167231a29 100644 --- a/spec/ruby/library/singleton/new_spec.rb +++ b/spec/ruby/library/singleton/new_spec.rb @@ -3,6 +3,6 @@ require_relative 'fixtures/classes' describe "Singleton.new" do it "is a private method" do - -> { SingletonSpecs::NewSpec.new }.should raise_error(NoMethodError) + -> { SingletonSpecs::NewSpec.new }.should.raise(NoMethodError) 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/bind_spec.rb b/spec/ruby/library/socket/addrinfo/bind_spec.rb index 6f78890a4d..cdd187771f 100644 --- a/spec/ruby/library/socket/addrinfo/bind_spec.rb +++ b/spec/ruby/library/socket/addrinfo/bind_spec.rb @@ -13,16 +13,16 @@ describe "Addrinfo#bind" do it "returns a bound socket when no block is given" do @socket = @addrinfo.bind - @socket.should be_kind_of(Socket) - @socket.closed?.should be_false + @socket.should.is_a?(Socket) + @socket.closed?.should == false end it "yields the socket if a block is given" do @addrinfo.bind do |sock| @socket = sock - sock.should be_kind_of(Socket) + sock.should.is_a?(Socket) end - @socket.closed?.should be_true + @socket.closed?.should == true end end diff --git a/spec/ruby/library/socket/addrinfo/canonname_spec.rb b/spec/ruby/library/socket/addrinfo/canonname_spec.rb index a1cc8b3980..efd3147125 100644 --- a/spec/ruby/library/socket/addrinfo/canonname_spec.rb +++ b/spec/ruby/library/socket/addrinfo/canonname_spec.rb @@ -10,7 +10,7 @@ describe "Addrinfo#canonname" do it "returns the canonical name for a host" do canonname = @addrinfos.map { |a| a.canonname }.find { |name| name and name.include?("localhost") } if canonname - canonname.should include("localhost") + canonname.should.include?("localhost") else canonname.should == nil end @@ -20,7 +20,7 @@ describe "Addrinfo#canonname" do it 'returns nil' do addr = Addrinfo.new(Socket.sockaddr_in(0, '127.0.0.1')) - addr.canonname.should be_nil + addr.canonname.should == nil end end diff --git a/spec/ruby/library/socket/addrinfo/connect_from_spec.rb b/spec/ruby/library/socket/addrinfo/connect_from_spec.rb index 55fce2e159..b1f6caa174 100644 --- a/spec/ruby/library/socket/addrinfo/connect_from_spec.rb +++ b/spec/ruby/library/socket/addrinfo/connect_from_spec.rb @@ -17,18 +17,18 @@ describe 'Addrinfo#connect_from' do describe 'using separate arguments' do it 'returns a Socket when no block is given' do @socket = @addr.connect_from(ip_address, 0) - @socket.should be_an_instance_of(Socket) + @socket.should.instance_of?(Socket) end it 'yields the Socket when a block is given' do @addr.connect_from(ip_address, 0) do |socket| - socket.should be_an_instance_of(Socket) + socket.should.instance_of?(Socket) end end it 'treats the last argument as a set of options if it is a Hash' do @socket = @addr.connect_from(ip_address, 0, timeout: 2) - @socket.should be_an_instance_of(Socket) + @socket.should.instance_of?(Socket) end it 'binds the socket to the local address' do @@ -48,18 +48,18 @@ describe 'Addrinfo#connect_from' do it 'returns a Socket when no block is given' do @socket = @addr.connect_from(@from_addr) - @socket.should be_an_instance_of(Socket) + @socket.should.instance_of?(Socket) end it 'yields the Socket when a block is given' do @addr.connect_from(@from_addr) do |socket| - socket.should be_an_instance_of(Socket) + socket.should.instance_of?(Socket) end end it 'treats the last argument as a set of options if it is a Hash' do @socket = @addr.connect_from(@from_addr, timeout: 2) - @socket.should be_an_instance_of(Socket) + @socket.should.instance_of?(Socket) end it 'binds the socket to the local address' do diff --git a/spec/ruby/library/socket/addrinfo/connect_spec.rb b/spec/ruby/library/socket/addrinfo/connect_spec.rb index 1c2dc609ca..a8494b5501 100644 --- a/spec/ruby/library/socket/addrinfo/connect_spec.rb +++ b/spec/ruby/library/socket/addrinfo/connect_spec.rb @@ -16,20 +16,20 @@ describe 'Addrinfo#connect' do it 'returns a Socket when no block is given' do addr = Addrinfo.tcp(ip_address, @port) @socket = addr.connect - @socket.should be_an_instance_of(Socket) + @socket.should.instance_of?(Socket) end it 'yields a Socket when a block is given' do addr = Addrinfo.tcp(ip_address, @port) addr.connect do |socket| - socket.should be_an_instance_of(Socket) + socket.should.instance_of?(Socket) end end it 'accepts a Hash of options' do addr = Addrinfo.tcp(ip_address, @port) @socket = addr.connect(timeout: 2) - @socket.should be_an_instance_of(Socket) + @socket.should.instance_of?(Socket) end end end diff --git a/spec/ruby/library/socket/addrinfo/connect_to_spec.rb b/spec/ruby/library/socket/addrinfo/connect_to_spec.rb index 69666da19b..2bf49a38e8 100644 --- a/spec/ruby/library/socket/addrinfo/connect_to_spec.rb +++ b/spec/ruby/library/socket/addrinfo/connect_to_spec.rb @@ -17,18 +17,18 @@ describe 'Addrinfo#connect_to' do describe 'using separate arguments' do it 'returns a Socket when no block is given' do @socket = @addr.connect_to(ip_address, @port) - @socket.should be_an_instance_of(Socket) + @socket.should.instance_of?(Socket) end it 'yields the Socket when a block is given' do @addr.connect_to(ip_address, @port) do |socket| - socket.should be_an_instance_of(Socket) + socket.should.instance_of?(Socket) end end it 'treats the last argument as a set of options if it is a Hash' do @socket = @addr.connect_to(ip_address, @port, timeout: 2) - @socket.should be_an_instance_of(Socket) + @socket.should.instance_of?(Socket) end it 'binds the Addrinfo to the local address' do @@ -48,18 +48,18 @@ describe 'Addrinfo#connect_to' do it 'returns a Socket when no block is given' do @socket = @addr.connect_to(@to_addr) - @socket.should be_an_instance_of(Socket) + @socket.should.instance_of?(Socket) end it 'yields the Socket when a block is given' do @addr.connect_to(@to_addr) do |socket| - socket.should be_an_instance_of(Socket) + socket.should.instance_of?(Socket) end end it 'treats the last argument as a set of options if it is a Hash' do @socket = @addr.connect_to(@to_addr, timeout: 2) - @socket.should be_an_instance_of(Socket) + @socket.should.instance_of?(Socket) end it 'binds the socket to the local address' do diff --git a/spec/ruby/library/socket/addrinfo/family_addrinfo_spec.rb b/spec/ruby/library/socket/addrinfo/family_addrinfo_spec.rb index 2bc3b6a2e3..38834ade91 100644 --- a/spec/ruby/library/socket/addrinfo/family_addrinfo_spec.rb +++ b/spec/ruby/library/socket/addrinfo/family_addrinfo_spec.rb @@ -4,7 +4,7 @@ describe 'Addrinfo#family_addrinfo' do it 'raises ArgumentError if no arguments are given' do addr = Addrinfo.tcp('127.0.0.1', 0) - -> { addr.family_addrinfo }.should raise_error(ArgumentError) + -> { addr.family_addrinfo }.should.raise(ArgumentError) end describe 'using multiple arguments' do @@ -14,17 +14,17 @@ describe 'Addrinfo#family_addrinfo' do end it 'raises ArgumentError if only 1 argument is given' do - -> { @source.family_addrinfo('127.0.0.1') }.should raise_error(ArgumentError) + -> { @source.family_addrinfo('127.0.0.1') }.should.raise(ArgumentError) end it 'raises ArgumentError if more than 2 arguments are given' do - -> { @source.family_addrinfo('127.0.0.1', 0, 666) }.should raise_error(ArgumentError) + -> { @source.family_addrinfo('127.0.0.1', 0, 666) }.should.raise(ArgumentError) end it 'returns an Addrinfo when a host and port are given' do addr = @source.family_addrinfo('127.0.0.1', 0) - addr.should be_an_instance_of(Addrinfo) + addr.should.instance_of?(Addrinfo) end describe 'the returned Addrinfo' do @@ -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(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.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 @@ -99,17 +97,17 @@ describe 'Addrinfo#family_addrinfo' do it 'raises ArgumentError if more than 1 argument is given' do input = Addrinfo.tcp('127.0.0.2', 0) - -> { @source.family_addrinfo(input, 666) }.should raise_error(ArgumentError) + -> { @source.family_addrinfo(input, 666) }.should.raise(ArgumentError) end it "raises ArgumentError if the protocol families don't match" do input = Addrinfo.tcp('::1', 0) - -> { @source.family_addrinfo(input) }.should raise_error(ArgumentError) + -> { @source.family_addrinfo(input) }.should.raise(ArgumentError) end it "raises ArgumentError if the socket types don't match" do input = Addrinfo.udp('127.0.0.1', 0) - -> { @source.family_addrinfo(input) }.should raise_error(ArgumentError) + -> { @source.family_addrinfo(input) }.should.raise(ArgumentError) end end end diff --git a/spec/ruby/library/socket/addrinfo/foreach_spec.rb b/spec/ruby/library/socket/addrinfo/foreach_spec.rb index 6ec8fab905..8cbbddb8f0 100644 --- a/spec/ruby/library/socket/addrinfo/foreach_spec.rb +++ b/spec/ruby/library/socket/addrinfo/foreach_spec.rb @@ -3,7 +3,7 @@ require_relative '../spec_helper' describe 'Addrinfo.foreach' do it 'yields Addrinfo instances to the supplied block' do Addrinfo.foreach('127.0.0.1', 80) do |addr| - addr.should be_an_instance_of(Addrinfo) + addr.should.instance_of?(Addrinfo) end end end diff --git a/spec/ruby/library/socket/addrinfo/getaddrinfo_spec.rb b/spec/ruby/library/socket/addrinfo/getaddrinfo_spec.rb index e05fe9967a..47393ee167 100644 --- a/spec/ruby/library/socket/addrinfo/getaddrinfo_spec.rb +++ b/spec/ruby/library/socket/addrinfo/getaddrinfo_spec.rb @@ -5,8 +5,8 @@ describe 'Addrinfo.getaddrinfo' do it 'returns an Array of Addrinfo instances' do array = Addrinfo.getaddrinfo('127.0.0.1', 80) - array.should be_an_instance_of(Array) - array[0].should be_an_instance_of(Addrinfo) + array.should.instance_of?(Array) + array[0].should.instance_of?(Addrinfo) end SocketSpecs.each_ip_protocol do |family, ip_address| @@ -54,7 +54,7 @@ describe 'Addrinfo.getaddrinfo' do array = Addrinfo.getaddrinfo('127.0.0.1', 80) possible = [Socket::SOCK_STREAM, Socket::SOCK_DGRAM] - possible.should include(array[0].socktype) + possible.should.include?(array[0].socktype) end end @@ -69,7 +69,7 @@ describe 'Addrinfo.getaddrinfo' do array = Addrinfo.getaddrinfo('127.0.0.1', 80) possible = [Socket::IPPROTO_TCP, Socket::IPPROTO_UDP] - possible.should include(array[0].protocol) + possible.should.include?(array[0].protocol) end end @@ -82,6 +82,6 @@ describe 'Addrinfo.getaddrinfo' 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) - array[0].canonname.should be_an_instance_of(String) + array[0].canonname.should.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 b7477efc79..f33255e38b 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,11 +53,11 @@ describe "Addrinfo#initialize" do @addrinfo.ip_port.should == 25 end - it "returns the Socket::UNSPEC pfamily" do + it "returns the specified pfamily" do @addrinfo.pfamily.should == Socket::PF_INET6 end - it "returns the INET6 afamily" do + it "returns the specified afamily" do @addrinfo.afamily.should == Socket::AF_INET6 end @@ -83,11 +83,11 @@ describe "Addrinfo#initialize" do @addrinfo.ip_port.should == 25 end - it "returns the Socket::UNSPEC pfamily" do + it "returns the specified pfamily" do @addrinfo.pfamily.should == Socket::PF_INET6 end - it "returns the INET6 afamily" do + it "returns the specified afamily" do @addrinfo.afamily.should == Socket::AF_INET6 end @@ -113,11 +113,11 @@ describe "Addrinfo#initialize" do @addrinfo.ip_port.should == 25 end - it "returns the Socket::UNSPEC pfamily" do + it "returns the specified pfamily" do @addrinfo.pfamily.should == Socket::PF_INET6 end - it "returns the INET6 afamily" do + it "returns the specified afamily" do @addrinfo.afamily.should == Socket::AF_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 specified pfamily" do @addrinfo.pfamily.should == Socket::PF_INET end - it "returns the INET6 afamily" do + it "returns the specified afamily" do @addrinfo.afamily.should == Socket::AF_INET end @@ -200,7 +200,7 @@ describe "Addrinfo#initialize" do it 'raises SocketError' do block = -> { Addrinfo.new(['AF_INET6', 80, 'hostname', '127.0.0.1']) } - block.should raise_error(SocketError) + block.should.raise(SocketError) end 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 specified pfamily" do @addrinfo.pfamily.should == Socket::PF_INET end - it "returns the INET6 afamily" do + it "returns the specified 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 specified pfamily" do @addrinfo.pfamily.should == Socket::PF_INET end - it "returns the INET6 afamily" do + it "returns the specified afamily" do @addrinfo.afamily.should == Socket::AF_INET end @@ -294,7 +294,7 @@ describe "Addrinfo#initialize" do value = Socket::SOCK_RDM block = -> { Addrinfo.new(sockaddr, nil, value) } - block.should raise_error(SocketError) + block.should.raise(SocketError) end 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 specified pfamily" do @addrinfo.pfamily.should == Socket::PF_INET end - it "returns the INET6 afamily" do + it "returns the specified afamily" do @addrinfo.afamily.should == Socket::AF_INET end @@ -340,7 +340,7 @@ describe "Addrinfo#initialize" do value = Socket.const_get(constant) -> { Addrinfo.new(@sockaddr, value) - }.should raise_error(SocketError) + }.should.raise(SocketError) end end end @@ -368,7 +368,7 @@ describe "Addrinfo#initialize" do value = Socket.const_get(type) block = -> { Addrinfo.new(@sockaddr, nil, nil, value) } - block.should raise_error(SocketError) + block.should.raise(SocketError) end end end @@ -396,7 +396,7 @@ describe "Addrinfo#initialize" do value = Socket.const_get(type) block = -> { Addrinfo.new(@sockaddr, nil, @socktype, value) } - block.should raise_error(SocketError) + block.should.raise(SocketError) end end end @@ -413,7 +413,7 @@ describe "Addrinfo#initialize" do value = Socket.const_get(type) block = -> { Addrinfo.new(@sockaddr, nil, @socktype, value) } - block.should raise_error(SocketError) + block.should.raise(SocketError) end end end @@ -444,7 +444,7 @@ describe "Addrinfo#initialize" do value = Socket.const_get(type) block = -> { Addrinfo.new(@sockaddr, nil, @socktype, value) } - block.should raise_error(SocketError) + block.should.raise(SocketError) end end end @@ -472,7 +472,7 @@ describe "Addrinfo#initialize" do value = Socket.const_get(type) block = -> { Addrinfo.new(@sockaddr, nil, @socktype, value) } - block.should raise_error(SocketError) + block.should.raise(SocketError) end end end @@ -501,7 +501,7 @@ describe "Addrinfo#initialize" do value = Socket.const_get(type) block = -> { Addrinfo.new(@sockaddr, nil, @socktype, value) } - block.should raise_error(SocketError) + block.should.raise(SocketError) end end end @@ -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 the specified pfamily for :PF_INET' 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 the specified pfamily for :INET' 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 the specified pfamily for PF_INET' 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 the specified pfamily for INET' 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..9a0ede4eeb 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(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..00f74cdd46 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(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..2237eca263 100644 --- a/spec/ruby/library/socket/addrinfo/ip_spec.rb +++ b/spec/ruby/library/socket/addrinfo/ip_spec.rb @@ -8,7 +8,7 @@ describe "Addrinfo#ip?" do end it "returns true" do - @addrinfo.ip?.should be_true + @addrinfo.ip?.should == true end end @@ -18,19 +18,17 @@ describe "Addrinfo#ip?" do end it "returns true" do - @addrinfo.ip?.should be_true + @addrinfo.ip?.should == true 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 == false end end end @@ -38,7 +36,7 @@ end describe 'Addrinfo.ip' do SocketSpecs.each_ip_protocol do |family, ip_address| it 'returns an Addrinfo instance' do - Addrinfo.ip(ip_address).should be_an_instance_of(Addrinfo) + Addrinfo.ip(ip_address).should.instance_of?(Addrinfo) end it 'sets the IP address' do diff --git a/spec/ruby/library/socket/addrinfo/ip_unpack_spec.rb b/spec/ruby/library/socket/addrinfo/ip_unpack_spec.rb index 6c81c48d1c..b48ca062ee 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(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..266281ce7a 100644 --- a/spec/ruby/library/socket/addrinfo/ipv4_loopback_spec.rb +++ b/spec/ruby/library/socket/addrinfo/ipv4_loopback_spec.rb @@ -10,7 +10,7 @@ describe "Addrinfo#ipv4_loopback?" do end it "returns false for another address" do - Addrinfo.ip('255.255.255.0').ipv4_loopback?.should be_false + Addrinfo.ip('255.255.255.0').ipv4_loopback?.should == false end end @@ -21,23 +21,21 @@ describe "Addrinfo#ipv4_loopback?" do end it "returns false for the loopback address" do - @loopback.ipv4_loopback?.should be_false + @loopback.ipv4_loopback?.should == false end it "returns false for another address" do - @other.ipv4_loopback?.should be_false + @other.ipv4_loopback?.should == false 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 == 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..bc8a31dfa8 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 == 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..8cfbf0a25e 100644 --- a/spec/ruby/library/socket/addrinfo/ipv4_private_spec.rb +++ b/spec/ruby/library/socket/addrinfo/ipv4_private_spec.rb @@ -19,7 +19,7 @@ describe "Addrinfo#ipv4_private?" do end it "returns false for a public address" do - @other.ipv4_private?.should be_false + @other.ipv4_private?.should == false end end @@ -29,19 +29,17 @@ describe "Addrinfo#ipv4_private?" do end it "returns false" do - @other.ipv4_private?.should be_false + @other.ipv4_private?.should == false 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_private?.should be_false - end + it "returns false" do + @addrinfo.ipv4_private?.should == 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..8fef94a8e8 100644 --- a/spec/ruby/library/socket/addrinfo/ipv4_spec.rb +++ b/spec/ruby/library/socket/addrinfo/ipv4_spec.rb @@ -7,7 +7,7 @@ describe "Addrinfo#ipv4?" do end it "returns true" do - @addrinfo.ipv4?.should be_true + @addrinfo.ipv4?.should == true end end @@ -17,19 +17,17 @@ describe "Addrinfo#ipv4?" do end it "returns false" do - @addrinfo.ipv4?.should be_false + @addrinfo.ipv4?.should == false 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 == 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..2e8241e336 100644 --- a/spec/ruby/library/socket/addrinfo/ipv6_loopback_spec.rb +++ b/spec/ruby/library/socket/addrinfo/ipv6_loopback_spec.rb @@ -8,11 +8,11 @@ describe "Addrinfo#ipv6_loopback?" do end it "returns false for the loopback address" do - @loopback.ipv6_loopback?.should be_false + @loopback.ipv6_loopback?.should == false end it "returns false for another address" do - @other.ipv6_loopback?.should be_false + @other.ipv6_loopback?.should == false end end @@ -23,23 +23,21 @@ describe "Addrinfo#ipv6_loopback?" do end it "returns true for the loopback address" do - @loopback.ipv6_loopback?.should be_true + @loopback.ipv6_loopback?.should == true end it "returns false for another address" do - @other.ipv6_loopback?.should be_false + @other.ipv6_loopback?.should == false 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_loopback?.should be_false - end + it "returns false" do + @addrinfo.ipv6_loopback?.should == 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..52787e5e53 100644 --- a/spec/ruby/library/socket/addrinfo/ipv6_multicast_spec.rb +++ b/spec/ruby/library/socket/addrinfo/ipv6_multicast_spec.rb @@ -8,11 +8,11 @@ describe "Addrinfo#ipv6_multicast?" do end it "returns true for a multicast address" do - @multicast.ipv6_multicast?.should be_false + @multicast.ipv6_multicast?.should == false end it "returns false for another address" do - @other.ipv6_multicast?.should be_false + @other.ipv6_multicast?.should == false end end @@ -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 + 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 + it "returns false" do + @addrinfo.ipv6_multicast?.should == 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..9fa8e9bd0c 100644 --- a/spec/ruby/library/socket/addrinfo/ipv6_spec.rb +++ b/spec/ruby/library/socket/addrinfo/ipv6_spec.rb @@ -7,7 +7,7 @@ describe "Addrinfo#ipv6?" do end it "returns true" do - @addrinfo.ipv6?.should be_false + @addrinfo.ipv6?.should == false end end @@ -17,19 +17,17 @@ describe "Addrinfo#ipv6?" do end it "returns false" do - @addrinfo.ipv6?.should be_true + @addrinfo.ipv6?.should == true 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 == 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..d1436d4527 100644 --- a/spec/ruby/library/socket/addrinfo/ipv6_to_ipv4_spec.rb +++ b/spec/ruby/library/socket/addrinfo/ipv6_to_ipv4_spec.rb @@ -6,7 +6,7 @@ guard -> { SocketSpecs.ipv6_available? } do it 'returns an Addrinfo for ::192.168.1.1' do addr = Addrinfo.ip('::192.168.1.1').ipv6_to_ipv4 - addr.should be_an_instance_of(Addrinfo) + addr.should.instance_of?(Addrinfo) addr.afamily.should == Socket::AF_INET addr.ip_address.should == '192.168.1.1' @@ -16,7 +16,7 @@ guard -> { SocketSpecs.ipv6_available? } do it 'returns an Addrinfo for ::0.0.1.1' do addr = Addrinfo.ip('::0.0.1.1').ipv6_to_ipv4 - addr.should be_an_instance_of(Addrinfo) + addr.should.instance_of?(Addrinfo) addr.afamily.should == Socket::AF_INET addr.ip_address.should == '0.0.1.1' @@ -25,7 +25,7 @@ guard -> { SocketSpecs.ipv6_available? } do it 'returns an Addrinfo for ::0.0.1.0' do addr = Addrinfo.ip('::0.0.1.0').ipv6_to_ipv4 - addr.should be_an_instance_of(Addrinfo) + addr.should.instance_of?(Addrinfo) addr.afamily.should == Socket::AF_INET addr.ip_address.should == '0.0.1.0' @@ -34,7 +34,7 @@ guard -> { SocketSpecs.ipv6_available? } do it 'returns an Addrinfo for ::0.1.0.0' do addr = Addrinfo.ip('::0.1.0.0').ipv6_to_ipv4 - addr.should be_an_instance_of(Addrinfo) + addr.should.instance_of?(Addrinfo) addr.afamily.should == Socket::AF_INET addr.ip_address.should == '0.1.0.0' @@ -44,27 +44,27 @@ guard -> { SocketSpecs.ipv6_available? } do it 'returns an Addrinfo for ::ffff:192.168.1.1' do addr = Addrinfo.ip('::ffff:192.168.1.1').ipv6_to_ipv4 - addr.should be_an_instance_of(Addrinfo) + addr.should.instance_of?(Addrinfo) addr.afamily.should == Socket::AF_INET addr.ip_address.should == '192.168.1.1' end it 'returns nil for ::0.0.0.1' do - Addrinfo.ip('::0.0.0.1').ipv6_to_ipv4.should be_nil + Addrinfo.ip('::0.0.0.1').ipv6_to_ipv4.should == nil end it 'returns nil for a pure IPv6 Addrinfo' do - Addrinfo.ip('::1').ipv6_to_ipv4.should be_nil + Addrinfo.ip('::1').ipv6_to_ipv4.should == nil end it 'returns nil for an IPv4 Addrinfo' do - Addrinfo.ip('192.168.1.1').ipv6_to_ipv4.should be_nil + Addrinfo.ip('192.168.1.1').ipv6_to_ipv4.should == 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 + Addrinfo.unix('foo').ipv6_to_ipv4.should == nil end end end diff --git a/spec/ruby/library/socket/addrinfo/listen_spec.rb b/spec/ruby/library/socket/addrinfo/listen_spec.rb index 931093f732..80bcdc7f83 100644 --- a/spec/ruby/library/socket/addrinfo/listen_spec.rb +++ b/spec/ruby/library/socket/addrinfo/listen_spec.rb @@ -13,12 +13,12 @@ describe 'Addrinfo#listen' do it 'returns a Socket when no block is given' do @socket = @addr.listen - @socket.should be_an_instance_of(Socket) + @socket.should.instance_of?(Socket) end it 'yields the Socket if a block is given' do @addr.listen do |socket| - socket.should be_an_instance_of(Socket) + socket.should.instance_of?(Socket) end end diff --git a/spec/ruby/library/socket/addrinfo/marshal_dump_spec.rb b/spec/ruby/library/socket/addrinfo/marshal_dump_spec.rb index 2d69a33b53..438b04a99c 100644 --- a/spec/ruby/library/socket/addrinfo/marshal_dump_spec.rb +++ b/spec/ruby/library/socket/addrinfo/marshal_dump_spec.rb @@ -8,7 +8,7 @@ describe 'Addrinfo#marshal_dump' do end it 'returns an Array' do - @addr.marshal_dump.should be_an_instance_of(Array) + @addr.marshal_dump.should.instance_of?(Array) end describe 'the returned Array' do @@ -42,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.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 deleted file mode 100644 index 4f7cf439a0..0000000000 --- a/spec/ruby/library/socket/addrinfo/shared/to_sockaddr.rb +++ /dev/null @@ -1,49 +0,0 @@ -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) - end - - it "returns a sockaddr packed structure" do - @addrinfo.send(@method).should == Socket.sockaddr_in(80, '127.0.0.1') - end - end - - describe "for an ipv6 socket" do - before :each do - @addrinfo = Addrinfo.tcp("::1", 80) - end - - it "returns a sockaddr packed structure" do - @addrinfo.send(@method).should == Socket.sockaddr_in(80, '::1') - end - end - - with_feature :unix_socket do - 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 - end - end - - describe 'using a Addrinfo with just an IP address' do - it 'returns a String' do - addr = Addrinfo.ip('127.0.0.1') - - addr.send(@method).should == Socket.sockaddr_in(0, '127.0.0.1') - end - end - - describe 'using a Addrinfo without an IP and port' do - it 'returns a String' do - addr = Addrinfo.new(['AF_INET', 0, '', '']) - - 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/tcp_spec.rb b/spec/ruby/library/socket/addrinfo/tcp_spec.rb index c74c9c21c2..0669de16a6 100644 --- a/spec/ruby/library/socket/addrinfo/tcp_spec.rb +++ b/spec/ruby/library/socket/addrinfo/tcp_spec.rb @@ -4,7 +4,7 @@ require_relative '../fixtures/classes' describe 'Addrinfo.tcp' do SocketSpecs.each_ip_protocol do |family, ip_address| it 'returns an Addrinfo instance' do - Addrinfo.tcp(ip_address, 80).should be_an_instance_of(Addrinfo) + Addrinfo.tcp(ip_address, 80).should.instance_of?(Addrinfo) end it 'sets the IP address' do diff --git a/spec/ruby/library/socket/addrinfo/to_s_spec.rb b/spec/ruby/library/socket/addrinfo/to_s_spec.rb index ddf994e051..5c1c82793c 100644 --- a/spec/ruby/library/socket/addrinfo/to_s_spec.rb +++ b/spec/ruby/library/socket/addrinfo/to_s_spec.rb @@ -1,6 +1,7 @@ require_relative '../spec_helper' -require_relative 'shared/to_sockaddr' describe "Addrinfo#to_s" do - it_behaves_like :socket_addrinfo_to_sockaddr, :to_s + it "is an alias of Addrinfo#to_sockaddr" do + Addrinfo.instance_method(:to_s).should == Addrinfo.instance_method(:to_sockaddr) + end end diff --git a/spec/ruby/library/socket/addrinfo/to_sockaddr_spec.rb b/spec/ruby/library/socket/addrinfo/to_sockaddr_spec.rb index b9f75454bd..c703c7b28f 100644 --- a/spec/ruby/library/socket/addrinfo/to_sockaddr_spec.rb +++ b/spec/ruby/library/socket/addrinfo/to_sockaddr_spec.rb @@ -1,6 +1,49 @@ require_relative '../spec_helper' -require_relative 'shared/to_sockaddr' describe "Addrinfo#to_sockaddr" do - it_behaves_like :socket_addrinfo_to_sockaddr, :to_sockaddr + describe "for an ipv4 socket" do + before :each do + @addrinfo = Addrinfo.tcp("127.0.0.1", 80) + end + + it "returns a sockaddr packed structure" do + @addrinfo.to_sockaddr.should == Socket.sockaddr_in(80, '127.0.0.1') + end + end + + describe "for an ipv6 socket" do + before :each do + @addrinfo = Addrinfo.tcp("::1", 80) + end + + it "returns a sockaddr packed structure" do + @addrinfo.to_sockaddr.should == Socket.sockaddr_in(80, '::1') + end + end + + describe "for a unix socket" do + before :each do + @addrinfo = Addrinfo.unix("/tmp/sock") + end + + it "returns a sockaddr packed structure" do + @addrinfo.to_sockaddr.should == Socket.sockaddr_un('/tmp/sock') + end + end + + describe 'using a Addrinfo with just an IP address' do + it 'returns a String' do + addr = Addrinfo.ip('127.0.0.1') + + addr.to_sockaddr.should == Socket.sockaddr_in(0, '127.0.0.1') + end + end + + describe 'using a Addrinfo without an IP and port' do + it 'returns a String' do + addr = Addrinfo.new(['AF_INET', 0, '', '']) + + addr.to_sockaddr.should == Socket.sockaddr_in(0, '') + end + end end diff --git a/spec/ruby/library/socket/addrinfo/udp_spec.rb b/spec/ruby/library/socket/addrinfo/udp_spec.rb index ac02e76ef5..51d7f5588e 100644 --- a/spec/ruby/library/socket/addrinfo/udp_spec.rb +++ b/spec/ruby/library/socket/addrinfo/udp_spec.rb @@ -4,7 +4,7 @@ require_relative '../fixtures/classes' describe 'Addrinfo.udp' do SocketSpecs.each_ip_protocol do |family, ip_address| it 'returns an Addrinfo instance' do - Addrinfo.udp(ip_address, 80).should be_an_instance_of(Addrinfo) + Addrinfo.udp(ip_address, 80).should.instance_of?(Addrinfo) end it 'sets the IP address' do diff --git a/spec/ruby/library/socket/addrinfo/unix_path_spec.rb b/spec/ruby/library/socket/addrinfo/unix_path_spec.rb index 6bfb56a4ac..c15075bce3 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(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(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..da65e13efb 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.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 @@ -42,7 +40,7 @@ describe "Addrinfo#unix?" do end it "returns false" do - @addrinfo.unix?.should be_false + @addrinfo.unix?.should == false end end @@ -53,7 +51,7 @@ describe "Addrinfo#unix?" do end it "returns false" do - @addrinfo.unix?.should be_false + @addrinfo.unix?.should == false end end @@ -64,7 +62,7 @@ describe "Addrinfo#unix?" do end it "returns true" do - @addrinfo.unix?.should be_true + @addrinfo.unix?.should == true end end end diff --git a/spec/ruby/library/socket/ancillarydata/cmsg_is_spec.rb b/spec/ruby/library/socket/ancillarydata/cmsg_is_spec.rb index c54ee29825..c77f3bdbae 100644 --- a/spec/ruby/library/socket/ancillarydata/cmsg_is_spec.rb +++ b/spec/ruby/library/socket/ancillarydata/cmsg_is_spec.rb @@ -26,7 +26,7 @@ with_feature :ancillary_data do end it 'raises SocketError when comparing with :IPV6 and :RIGHTS' do - -> { @data.cmsg_is?(:IPV6, :RIGHTS) }.should raise_error(SocketError) + -> { @data.cmsg_is?(:IPV6, :RIGHTS) }.should.raise(SocketError) end end end diff --git a/spec/ruby/library/socket/ancillarydata/initialize_spec.rb b/spec/ruby/library/socket/ancillarydata/initialize_spec.rb index eca45599d7..60f5ac7a90 100644 --- a/spec/ruby/library/socket/ancillarydata/initialize_spec.rb +++ b/spec/ruby/library/socket/ancillarydata/initialize_spec.rb @@ -115,25 +115,25 @@ with_feature :ancillary_data do it 'raises TypeError when using a numeric string as the type argument' do -> { Socket::AncillaryData.new(:INET, :IGMP, Socket::SCM_RIGHTS.to_s, '') - }.should raise_error(TypeError) + }.should.raise(TypeError) end it 'raises SocketError when using :RECVTTL as the type argument' do -> { Socket::AncillaryData.new(:INET, :SOCKET, :RECVTTL, '') - }.should raise_error(SocketError) + }.should.raise(SocketError) end it 'raises SocketError when using :MOO as the type argument' do -> { Socket::AncillaryData.new(:INET, :SOCKET, :MOO, '') - }.should raise_error(SocketError) + }.should.raise(SocketError) end it 'raises SocketError when using :IP_RECVTTL as the type argument' do -> { Socket::AncillaryData.new(:INET, :SOCKET, :IP_RECVTTL, '') - }.should raise_error(SocketError) + }.should.raise(SocketError) end end @@ -157,13 +157,13 @@ with_feature :ancillary_data do it 'raises SocketError when using :RIGHTS as the type argument' do -> { Socket::AncillaryData.new(:INET, :IP, :RIGHTS, '') - }.should raise_error(SocketError) + }.should.raise(SocketError) end it 'raises SocketError when using :MOO as the type argument' do -> { Socket::AncillaryData.new(:INET, :IP, :MOO, '') - }.should raise_error(SocketError) + }.should.raise(SocketError) end end @@ -181,13 +181,13 @@ with_feature :ancillary_data do it 'raises SocketError when using :RIGHTS as the type argument' do -> { Socket::AncillaryData.new(:INET, :IPV6, :RIGHTS, '') - }.should raise_error(SocketError) + }.should.raise(SocketError) end it 'raises SocketError when using :MOO as the type argument' do -> { Socket::AncillaryData.new(:INET, :IPV6, :MOO, '') - }.should raise_error(SocketError) + }.should.raise(SocketError) end end @@ -207,13 +207,13 @@ with_feature :ancillary_data do it 'raises SocketError when using :RIGHTS as the type argument' do -> { Socket::AncillaryData.new(:INET, :TCP, :RIGHTS, '') - }.should raise_error(SocketError) + }.should.raise(SocketError) end it 'raises SocketError when using :MOO as the type argument' do -> { Socket::AncillaryData.new(:INET, :TCP, :MOO, '') - }.should raise_error(SocketError) + }.should.raise(SocketError) end end @@ -227,13 +227,13 @@ with_feature :ancillary_data do it 'raises SocketError when using :RIGHTS as the type argument' do -> { Socket::AncillaryData.new(:INET, :UDP, :RIGHTS, '') - }.should raise_error(SocketError) + }.should.raise(SocketError) end it 'raises SocketError when using :MOO as the type argument' do -> { Socket::AncillaryData.new(:INET, :UDP, :MOO, '') - }.should raise_error(SocketError) + }.should.raise(SocketError) end end @@ -245,7 +245,7 @@ with_feature :ancillary_data do it 'raises SocketError when using :CORK sa the type argument' do -> { Socket::AncillaryData.new(:UNIX, :SOCKET, :CORK, '') - }.should raise_error(SocketError) + }.should.raise(SocketError) end end @@ -253,7 +253,7 @@ with_feature :ancillary_data do it 'raises SocketError' do -> { Socket::AncillaryData.new(:UNIX, :IP, :RECVTTL, '') - }.should raise_error(SocketError) + }.should.raise(SocketError) end end @@ -261,7 +261,7 @@ with_feature :ancillary_data do it 'raises SocketError' do -> { Socket::AncillaryData.new(:UNIX, :IPV6, :NEXTHOP, '') - }.should raise_error(SocketError) + }.should.raise(SocketError) end end @@ -269,7 +269,7 @@ with_feature :ancillary_data do it 'raises SocketError' do -> { Socket::AncillaryData.new(:UNIX, :TCP, :CORK, '') - }.should raise_error(SocketError) + }.should.raise(SocketError) end end @@ -277,7 +277,7 @@ with_feature :ancillary_data do it 'raises SocketError' do -> { Socket::AncillaryData.new(:UNIX, :UDP, :CORK, '') - }.should raise_error(SocketError) + }.should.raise(SocketError) end end end diff --git a/spec/ruby/library/socket/ancillarydata/int_spec.rb b/spec/ruby/library/socket/ancillarydata/int_spec.rb index fe41a30a1a..10c5dea436 100644 --- a/spec/ruby/library/socket/ancillarydata/int_spec.rb +++ b/spec/ruby/library/socket/ancillarydata/int_spec.rb @@ -7,7 +7,7 @@ with_feature :ancillary_data do end it 'returns a Socket::AncillaryData' do - @data.should be_an_instance_of(Socket::AncillaryData) + @data.should.instance_of?(Socket::AncillaryData) end it 'sets the family to AF_INET' do @@ -37,7 +37,7 @@ with_feature :ancillary_data do it 'raises when the data is not an Integer' do data = Socket::AncillaryData.new(:UNIX, :SOCKET, :RIGHTS, 'ugh') - -> { data.int }.should raise_error(TypeError) + -> { data.int }.should.raise(TypeError) end end end diff --git a/spec/ruby/library/socket/ancillarydata/ip_pktinfo_spec.rb b/spec/ruby/library/socket/ancillarydata/ip_pktinfo_spec.rb index 84910a038a..065bcf1f39 100644 --- a/spec/ruby/library/socket/ancillarydata/ip_pktinfo_spec.rb +++ b/spec/ruby/library/socket/ancillarydata/ip_pktinfo_spec.rb @@ -8,7 +8,7 @@ with_feature :ancillary_data, :pktinfo do end it 'returns a Socket::AncillaryData' do - @data.should be_an_instance_of(Socket::AncillaryData) + @data.should.instance_of?(Socket::AncillaryData) end it 'sets the family to AF_INET' do @@ -32,7 +32,7 @@ with_feature :ancillary_data, :pktinfo do end it 'returns a Socket::AncillaryData' do - @data.should be_an_instance_of(Socket::AncillaryData) + @data.should.instance_of?(Socket::AncillaryData) end it 'sets the family to AF_INET' do @@ -58,7 +58,7 @@ with_feature :ancillary_data, :pktinfo do end it 'returns an Array' do - @data.ip_pktinfo.should be_an_instance_of(Array) + @data.ip_pktinfo.should.instance_of?(Array) end describe 'the returned Array' do @@ -67,15 +67,15 @@ with_feature :ancillary_data, :pktinfo do end it 'stores an Addrinfo at index 0' do - @info[0].should be_an_instance_of(Addrinfo) + @info[0].should.instance_of?(Addrinfo) end it 'stores the ifindex at index 1' do - @info[1].should be_kind_of(Integer) + @info[1].should.is_a?(Integer) end it 'stores an Addrinfo at index 2' do - @info[2].should be_an_instance_of(Addrinfo) + @info[2].should.instance_of?(Addrinfo) end end @@ -89,7 +89,7 @@ with_feature :ancillary_data, :pktinfo do end it 'is not the same object as the input Addrinfo' do - @addr.should_not equal @source + @addr.should_not.equal? @source end end @@ -109,7 +109,7 @@ with_feature :ancillary_data, :pktinfo do end it 'is not the same object as the input Addrinfo' do - @addr.should_not equal @dest + @addr.should_not.equal? @dest end end end diff --git a/spec/ruby/library/socket/ancillarydata/ipv6_pktinfo_addr_spec.rb b/spec/ruby/library/socket/ancillarydata/ipv6_pktinfo_addr_spec.rb index f70fe27d6a..7c630218d1 100644 --- a/spec/ruby/library/socket/ancillarydata/ipv6_pktinfo_addr_spec.rb +++ b/spec/ruby/library/socket/ancillarydata/ipv6_pktinfo_addr_spec.rb @@ -5,7 +5,7 @@ with_feature :ancillary_data, :ipv6_pktinfo do it 'returns an Addrinfo' do data = Socket::AncillaryData.ipv6_pktinfo(Addrinfo.ip('::1'), 4) - data.ipv6_pktinfo_addr.should be_an_instance_of(Addrinfo) + data.ipv6_pktinfo_addr.should.instance_of?(Addrinfo) end end end diff --git a/spec/ruby/library/socket/ancillarydata/ipv6_pktinfo_spec.rb b/spec/ruby/library/socket/ancillarydata/ipv6_pktinfo_spec.rb index 0fffc720dc..b5b779c36e 100644 --- a/spec/ruby/library/socket/ancillarydata/ipv6_pktinfo_spec.rb +++ b/spec/ruby/library/socket/ancillarydata/ipv6_pktinfo_spec.rb @@ -7,7 +7,7 @@ with_feature :ancillary_data, :ipv6_pktinfo do end it 'returns a Socket::AncillaryData' do - @data.should be_an_instance_of(Socket::AncillaryData) + @data.should.instance_of?(Socket::AncillaryData) end it 'sets the family to AF_INET' do @@ -31,7 +31,7 @@ with_feature :ancillary_data, :ipv6_pktinfo do end it 'returns an Array' do - @data.ipv6_pktinfo.should be_an_instance_of(Array) + @data.ipv6_pktinfo.should.instance_of?(Array) end describe 'the returned Array' do @@ -40,11 +40,11 @@ with_feature :ancillary_data, :ipv6_pktinfo do end it 'stores an Addrinfo at index 0' do - @info[0].should be_an_instance_of(Addrinfo) + @info[0].should.instance_of?(Addrinfo) end it 'stores the ifindex at index 1' do - @info[1].should be_kind_of(Integer) + @info[1].should.is_a?(Integer) end end @@ -58,7 +58,7 @@ with_feature :ancillary_data, :ipv6_pktinfo do end it 'is not the same object as the input Addrinfo' do - @addr.should_not equal @source + @addr.should_not.equal? @source end end diff --git a/spec/ruby/library/socket/ancillarydata/unix_rights_spec.rb b/spec/ruby/library/socket/ancillarydata/unix_rights_spec.rb index 95052fd91c..6dd144ba5a 100644 --- a/spec/ruby/library/socket/ancillarydata/unix_rights_spec.rb +++ b/spec/ruby/library/socket/ancillarydata/unix_rights_spec.rb @@ -26,7 +26,7 @@ with_feature :ancillary_data do describe 'using non IO objects' do it 'raises TypeError' do - -> { Socket::AncillaryData.unix_rights(10) }.should raise_error(TypeError) + -> { Socket::AncillaryData.unix_rights(10) }.should.raise(TypeError) end end end @@ -41,20 +41,20 @@ with_feature :ancillary_data do it 'returns nil when the data is not a list of file descriptors' do data = Socket::AncillaryData.new(:UNIX, :SOCKET, :RIGHTS, '') - data.unix_rights.should be_nil + data.unix_rights.should == nil end it 'raises TypeError when the level is not SOL_SOCKET' do data = Socket::AncillaryData.new(:INET, :IP, :RECVTTL, '') - -> { data.unix_rights }.should raise_error(TypeError) + -> { data.unix_rights }.should.raise(TypeError) end platform_is_not :aix do it 'raises TypeError when the type is not SCM_RIGHTS' do data = Socket::AncillaryData.new(:INET, :SOCKET, :TIMESTAMP, '') - -> { data.unix_rights }.should raise_error(TypeError) + -> { data.unix_rights }.should.raise(TypeError) end end end diff --git a/spec/ruby/library/socket/basicsocket/close_read_spec.rb b/spec/ruby/library/socket/basicsocket/close_read_spec.rb index f317b34955..35bec203d7 100644 --- a/spec/ruby/library/socket/basicsocket/close_read_spec.rb +++ b/spec/ruby/library/socket/basicsocket/close_read_spec.rb @@ -12,32 +12,32 @@ describe "Socket::BasicSocket#close_read" do it "closes the reading end of the socket" do @server.close_read - -> { @server.read }.should raise_error(IOError) + -> { @server.read }.should.raise(IOError) end it 'does not raise when called on a socket already closed for reading' do @server.close_read @server.close_read - -> { @server.read }.should raise_error(IOError) + -> { @server.read }.should.raise(IOError) end it 'does not fully close the socket' do @server.close_read - @server.closed?.should be_false + @server.closed?.should == false end it "fully closes the socket if it was already closed for writing" do @server.close_write @server.close_read - @server.closed?.should be_true + @server.closed?.should == true end it 'raises IOError when called on a fully closed socket' do @server.close - -> { @server.close_read }.should raise_error(IOError) + -> { @server.close_read }.should.raise(IOError) end it "returns nil" do - @server.close_read.should be_nil + @server.close_read.should == nil end end diff --git a/spec/ruby/library/socket/basicsocket/close_write_spec.rb b/spec/ruby/library/socket/basicsocket/close_write_spec.rb index 232cfbb7c6..c1b6d9e9ef 100644 --- a/spec/ruby/library/socket/basicsocket/close_write_spec.rb +++ b/spec/ruby/library/socket/basicsocket/close_write_spec.rb @@ -12,18 +12,18 @@ describe "Socket::BasicSocket#close_write" do it "closes the writing end of the socket" do @server.close_write - -> { @server.write("foo") }.should raise_error(IOError) + -> { @server.write("foo") }.should.raise(IOError) end it 'does not raise when called on a socket already closed for writing' do @server.close_write @server.close_write - -> { @server.write("foo") }.should raise_error(IOError) + -> { @server.write("foo") }.should.raise(IOError) end it 'does not fully close the socket' do @server.close_write - @server.closed?.should be_false + @server.closed?.should == false end it "does not prevent reading" do @@ -34,15 +34,15 @@ describe "Socket::BasicSocket#close_write" do it "fully closes the socket if it was already closed for reading" do @server.close_read @server.close_write - @server.closed?.should be_true + @server.closed?.should == true end it 'raises IOError when called on a fully closed socket' do @server.close - -> { @server.close_write }.should raise_error(IOError) + -> { @server.close_write }.should.raise(IOError) end it "returns nil" do - @server.close_write.should be_nil + @server.close_write.should == nil end end diff --git a/spec/ruby/library/socket/basicsocket/connect_address_spec.rb b/spec/ruby/library/socket/basicsocket/connect_address_spec.rb index 1a1c9982d9..e330b6e1be 100644 --- a/spec/ruby/library/socket/basicsocket/connect_address_spec.rb +++ b/spec/ruby/library/socket/basicsocket/connect_address_spec.rb @@ -10,7 +10,7 @@ describe 'Socket#connect_address' do it 'raises SocketError' do @sock = Socket.new(:INET, :STREAM) - -> { @sock.connect_address }.should raise_error(SocketError) + -> { @sock.connect_address }.should.raise(SocketError) end end @@ -25,7 +25,7 @@ describe 'Socket#connect_address' do end it 'returns an Addrinfo' do - @sock.connect_address.should be_an_instance_of(Addrinfo) + @sock.connect_address.should.instance_of?(Addrinfo) end it 'uses 127.0.0.1 as the IP address' do @@ -65,7 +65,7 @@ describe 'Socket#connect_address' do end it 'returns an Addrinfo' do - @sock.connect_address.should be_an_instance_of(Addrinfo) + @sock.connect_address.should.instance_of?(Addrinfo) end it 'uses ::1 as the IP address' do @@ -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(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.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/do_not_reverse_lookup_spec.rb b/spec/ruby/library/socket/basicsocket/do_not_reverse_lookup_spec.rb index a8800a8493..36338bfd59 100644 --- a/spec/ruby/library/socket/basicsocket/do_not_reverse_lookup_spec.rb +++ b/spec/ruby/library/socket/basicsocket/do_not_reverse_lookup_spec.rb @@ -16,7 +16,7 @@ describe "BasicSocket.do_not_reverse_lookup" do end it "defaults to true" do - BasicSocket.do_not_reverse_lookup.should be_true + BasicSocket.do_not_reverse_lookup.should == true end it "causes 'peeraddr' to avoid name lookups" do diff --git a/spec/ruby/library/socket/basicsocket/for_fd_spec.rb b/spec/ruby/library/socket/basicsocket/for_fd_spec.rb index 9c9e6a8b55..8d5b71cfa9 100644 --- a/spec/ruby/library/socket/basicsocket/for_fd_spec.rb +++ b/spec/ruby/library/socket/basicsocket/for_fd_spec.rb @@ -15,7 +15,7 @@ describe "BasicSocket.for_fd" do it "return a Socket instance wrapped around the descriptor" do @s2 = TCPServer.for_fd(@server.fileno) @s2.autoclose = false - @s2.should be_kind_of(TCPServer) + @s2.should.is_a?(TCPServer) @s2.fileno.should == @server.fileno end @@ -24,7 +24,7 @@ describe "BasicSocket.for_fd" do socket2 = Socket.for_fd(@socket1.fileno) socket2.autoclose = false - socket2.should be_an_instance_of(Socket) + socket2.should.instance_of?(Socket) socket2.fileno.should == @socket1.fileno end @@ -33,6 +33,6 @@ describe "BasicSocket.for_fd" do socket2 = Socket.for_fd(@socket1.fileno) socket2.autoclose = false - socket2.binmode?.should be_true + socket2.binmode?.should == true end end diff --git a/spec/ruby/library/socket/basicsocket/getpeereid_spec.rb b/spec/ruby/library/socket/basicsocket/getpeereid_spec.rb index 6179211d96..b9851bae15 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 @@ -30,7 +30,7 @@ describe 'BasicSocket#getpeereid' do it 'raises NoMethodError' do @sock = TCPServer.new('127.0.0.1', 0) - -> { @sock.getpeereid }.should raise_error(NoMethodError) + -> { @sock.getpeereid }.should.raise(NoMethodError) end end end diff --git a/spec/ruby/library/socket/basicsocket/getpeername_spec.rb b/spec/ruby/library/socket/basicsocket/getpeername_spec.rb index 0b93f02eef..7e2f6f2e7b 100644 --- a/spec/ruby/library/socket/basicsocket/getpeername_spec.rb +++ b/spec/ruby/library/socket/basicsocket/getpeername_spec.rb @@ -20,6 +20,6 @@ describe "Socket::BasicSocket#getpeername" do end it 'raises Errno::ENOTCONN for a disconnected socket' do - -> { @server.getpeername }.should raise_error(Errno::ENOTCONN) + -> { @server.getpeername }.should.raise(Errno::ENOTCONN) end end diff --git a/spec/ruby/library/socket/basicsocket/getsockname_spec.rb b/spec/ruby/library/socket/basicsocket/getsockname_spec.rb index b33db088b6..a54626647e 100644 --- a/spec/ruby/library/socket/basicsocket/getsockname_spec.rb +++ b/spec/ruby/library/socket/basicsocket/getsockname_spec.rb @@ -3,7 +3,7 @@ require_relative '../fixtures/classes' describe "Socket::BasicSocket#getsockname" do after :each do - @socket.closed?.should be_false + @socket.closed?.should == false @socket.close end @@ -16,7 +16,7 @@ describe "Socket::BasicSocket#getsockname" do it "works on sockets listening in ipaddr_any" do @socket = TCPServer.new(0) sockaddr = Socket.unpack_sockaddr_in(@socket.getsockname) - ["::", "0.0.0.0", "::ffff:0.0.0.0"].include?(sockaddr[1]).should be_true + ["::", "0.0.0.0", "::ffff:0.0.0.0"].include?(sockaddr[1]).should == true sockaddr[0].should == @socket.addr[1] end diff --git a/spec/ruby/library/socket/basicsocket/getsockopt_spec.rb b/spec/ruby/library/socket/basicsocket/getsockopt_spec.rb index ce65d6c92b..744297ad02 100644 --- a/spec/ruby/library/socket/basicsocket/getsockopt_spec.rb +++ b/spec/ruby/library/socket/basicsocket/getsockopt_spec.rb @@ -7,7 +7,7 @@ describe "BasicSocket#getsockopt" do end after :each do - @sock.closed?.should be_false + @sock.closed?.should == false @sock.close end @@ -41,13 +41,13 @@ describe "BasicSocket#getsockopt" do end it "raises a SystemCallError with an invalid socket option" do - -> { @sock.getsockopt Socket::SOL_SOCKET, -1 }.should raise_error(Errno::ENOPROTOOPT) + -> { @sock.getsockopt Socket::SOL_SOCKET, -1 }.should.raise(Errno::ENOPROTOOPT) end it 'returns a Socket::Option using a constant' do opt = @sock.getsockopt(Socket::SOL_SOCKET, Socket::SO_TYPE) - opt.should be_an_instance_of(Socket::Option) + opt.should.instance_of?(Socket::Option) end it 'returns a Socket::Option for a boolean option' do @@ -59,7 +59,7 @@ describe "BasicSocket#getsockopt" do it 'returns a Socket::Option for a numeric option' do opt = @sock.getsockopt(Socket::IPPROTO_IP, Socket::IP_TTL) - opt.int.should be_kind_of(Integer) + opt.int.should.is_a?(Integer) end it 'returns a Socket::Option for a struct option' do @@ -69,7 +69,7 @@ describe "BasicSocket#getsockopt" do end it 'raises Errno::ENOPROTOOPT when requesting an invalid option' do - -> { @sock.getsockopt(Socket::SOL_SOCKET, -1) }.should raise_error(Errno::ENOPROTOOPT) + -> { @sock.getsockopt(Socket::SOL_SOCKET, -1) }.should.raise(Errno::ENOPROTOOPT) end describe 'using Symbols as arguments' do @@ -171,7 +171,7 @@ describe "BasicSocket#getsockopt" do opt = @sock.getsockopt(Socket::IPPROTO_IP, Socket::IP_TTL).to_s array = opt.unpack('i') - array[0].should be_kind_of(Integer) + array[0].should.is_a?(Integer) array[0].should > 0 end diff --git a/spec/ruby/library/socket/basicsocket/recv_nonblock_spec.rb b/spec/ruby/library/socket/basicsocket/recv_nonblock_spec.rb index f2a6682f12..8aca7d0332 100644 --- a/spec/ruby/library/socket/basicsocket/recv_nonblock_spec.rb +++ b/spec/ruby/library/socket/basicsocket/recv_nonblock_spec.rb @@ -16,7 +16,7 @@ describe "Socket::BasicSocket#recv_nonblock" do platform_is_not :windows do describe 'using an unbound socket' do it 'raises an exception extending IO::WaitReadable' do - -> { @s1.recv_nonblock(1) }.should raise_error(IO::WaitReadable) + -> { @s1.recv_nonblock(1) }.should.raise(IO::WaitReadable) end end end @@ -25,12 +25,12 @@ describe "Socket::BasicSocket#recv_nonblock" do @s1.bind(Socket.pack_sockaddr_in(0, ip_address)) -> { @s1.recv_nonblock(5) - }.should raise_error(IO::WaitReadable) { |e| + }.should.raise(IO::WaitReadable) { |e| platform_is_not :windows do - e.should be_kind_of(Errno::EAGAIN) + e.should.is_a?(Errno::EAGAIN) end platform_is :windows do - e.should be_kind_of(Errno::EWOULDBLOCK) + e.should.is_a?(Errno::EWOULDBLOCK) end } end @@ -74,7 +74,7 @@ describe "Socket::BasicSocket#recv_nonblock" do @s1.recv_nonblock(1).should == "a" -> { @s1.recv_nonblock(5) - }.should raise_error(IO::WaitReadable) + }.should.raise(IO::WaitReadable) end end @@ -89,10 +89,10 @@ describe "Socket::BasicSocket#recv_nonblock" do end it "raises Errno::ENOTCONN" do - -> { @server.recv_nonblock(1) }.should raise_error { |e| + -> { @server.recv_nonblock(1) }.should.raise { |e| [Errno::ENOTCONN, Errno::EINVAL].should.include?(e.class) } - -> { @server.recv_nonblock(1, exception: false) }.should raise_error { |e| + -> { @server.recv_nonblock(1, exception: false) }.should.raise { |e| [Errno::ENOTCONN, Errno::EINVAL].should.include?(e.class) } end @@ -112,60 +112,30 @@ describe "Socket::BasicSocket#recv_nonblock" 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 + it "returns nil on a closed stream socket" do + ready = false - socket = TCPSocket.new('127.0.0.1', @port) - socket.close - ready = true + t = Thread.new do + client = @server.accept - 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 + 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 + Thread.pass while t.status and t.status != "sleep" + t.status.should_not == nil - socket = TCPSocket.new('127.0.0.1', @port) - socket.close - ready = true + socket = TCPSocket.new('127.0.0.1', @port) + socket.close + ready = true - t.value.should be_nil - end + t.value.should == nil end end end diff --git a/spec/ruby/library/socket/basicsocket/recv_spec.rb b/spec/ruby/library/socket/basicsocket/recv_spec.rb index a51920f52a..5c393218bc 100644 --- a/spec/ruby/library/socket/basicsocket/recv_spec.rb +++ b/spec/ruby/library/socket/basicsocket/recv_spec.rb @@ -22,7 +22,7 @@ describe "BasicSocket#recv" do client.close end Thread.pass while t.status and t.status != "sleep" - t.status.should_not be_nil + t.status.should_not == nil socket = TCPSocket.new('127.0.0.1', @port) socket.send('hello', 0) @@ -44,7 +44,7 @@ describe "BasicSocket#recv" do client.close end Thread.pass while t.status and t.status != "sleep" - t.status.should_not be_nil + t.status.should_not == nil socket = TCPSocket.new('127.0.0.1', @port) socket.send('helloU', Socket::MSG_OOB) @@ -64,7 +64,7 @@ describe "BasicSocket#recv" do client.close end Thread.pass while t.status and t.status != "sleep" - t.status.should_not be_nil + t.status.should_not == nil socket = TCPSocket.new('127.0.0.1', @port) socket.write("firstline\377secondline\377") @@ -184,42 +184,21 @@ describe "BasicSocket#recv" 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 == "" + 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 - 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 + Thread.pass while t.status and t.status != "sleep" + t.status.should_not == nil - socket = TCPSocket.new('127.0.0.1', @port) - socket.close + socket = TCPSocket.new('127.0.0.1', @port) + socket.close - t.value.should be_nil - end + t.value.should == nil 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 b5fdd7c93b..9d77f5df6b 100644 --- a/spec/ruby/library/socket/basicsocket/recvmsg_nonblock_spec.rb +++ b/spec/ruby/library/socket/basicsocket/recvmsg_nonblock_spec.rb @@ -17,7 +17,7 @@ describe 'BasicSocket#recvmsg_nonblock' do platform_is_not :windows do describe 'using an unbound socket' do it 'raises an exception extending IO::WaitReadable' do - -> { @server.recvmsg_nonblock }.should raise_error(IO::WaitReadable) + -> { @server.recvmsg_nonblock }.should.raise(IO::WaitReadable) end end end @@ -29,7 +29,7 @@ describe 'BasicSocket#recvmsg_nonblock' do describe 'without any data available' do it 'raises an exception extending IO::WaitReadable' do - -> { @server.recvmsg_nonblock }.should raise_error(IO::WaitReadable) + -> { @server.recvmsg_nonblock }.should.raise(IO::WaitReadable) end it 'returns :wait_readable with exception: false' do @@ -47,7 +47,7 @@ describe 'BasicSocket#recvmsg_nonblock' do end it 'returns an Array containing the data, an Addrinfo and the flags' do - @server.recvmsg_nonblock.should be_an_instance_of(Array) + @server.recvmsg_nonblock.should.instance_of?(Array) end describe 'without a maximum message length' do @@ -74,12 +74,12 @@ describe 'BasicSocket#recvmsg_nonblock' do end it 'stores an Addrinfo at index 1' do - @array[1].should be_an_instance_of(Addrinfo) + @array[1].should.instance_of?(Addrinfo) end platform_is_not :windows do it 'stores the flags at index 2' do - @array[2].should be_kind_of(Integer) + @array[2].should.is_a?(Integer) end end @@ -124,8 +124,8 @@ describe 'BasicSocket#recvmsg_nonblock' do end it "raises Errno::ENOTCONN" do - -> { @server.recvmsg_nonblock }.should raise_error(Errno::ENOTCONN) - -> { @server.recvmsg_nonblock(exception: false) }.should raise_error(Errno::ENOTCONN) + -> { @server.recvmsg_nonblock }.should.raise(Errno::ENOTCONN) + -> { @server.recvmsg_nonblock(exception: false) }.should.raise(Errno::ENOTCONN) end end @@ -154,7 +154,7 @@ describe 'BasicSocket#recvmsg_nonblock' do ensure socket.close end - }.should raise_error(IO::WaitReadable) + }.should.raise(IO::WaitReadable) end end @@ -171,7 +171,7 @@ describe 'BasicSocket#recvmsg_nonblock' do end it 'returns an Array containing the data, an Addrinfo and the flags' do - @socket.recvmsg_nonblock.should be_an_instance_of(Array) + @socket.recvmsg_nonblock.should.instance_of?(Array) end describe 'the returned Array' do @@ -184,11 +184,11 @@ describe 'BasicSocket#recvmsg_nonblock' do end it 'stores an Addrinfo at index 1' do - @array[1].should be_an_instance_of(Addrinfo) + @array[1].should.instance_of?(Addrinfo) end it 'stores the flags at index 2' do - @array[2].should be_kind_of(Integer) + @array[2].should.is_a?(Integer) end describe 'the returned Addrinfo' do @@ -197,7 +197,7 @@ describe 'BasicSocket#recvmsg_nonblock' do end it 'raises when receiving the ip_address message' do - -> { @addr.ip_address }.should raise_error(SocketError) + -> { @addr.ip_address }.should.raise(SocketError) end it 'uses the correct address family' do @@ -213,7 +213,7 @@ describe 'BasicSocket#recvmsg_nonblock' do end it 'raises when receiving the ip_port message' do - -> { @addr.ip_port }.should raise_error(SocketError) + -> { @addr.ip_port }.should.raise(SocketError) end end end @@ -235,64 +235,31 @@ describe 'BasicSocket#recvmsg_nonblock' 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 + platform_is_not :windows do + it "returns nil on a closed stream socket" do + ready = false - t = Thread.new do - client = @server.accept + 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 + Thread.pass while !ready + begin + client.recvmsg_nonblock(10) + rescue IO::EAGAINWaitReadable + retry 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 == "" + ensure + client.close if client 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 + Thread.pass while t.status and t.status != "sleep" + t.status.should_not == nil - t = Thread.new do - client = @server.accept + socket = TCPSocket.new('127.0.0.1', @port) + socket.close + ready = true - 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 + t.value.should == nil end end end diff --git a/spec/ruby/library/socket/basicsocket/recvmsg_spec.rb b/spec/ruby/library/socket/basicsocket/recvmsg_spec.rb index 04ba1d74c7..eabfb9dd18 100644 --- a/spec/ruby/library/socket/basicsocket/recvmsg_spec.rb +++ b/spec/ruby/library/socket/basicsocket/recvmsg_spec.rb @@ -41,7 +41,7 @@ describe 'BasicSocket#recvmsg' do end it 'returns an Array containing the data, an Addrinfo and the flags' do - @server.recvmsg.should be_an_instance_of(Array) + @server.recvmsg.should.instance_of?(Array) end describe 'without a maximum message length' do @@ -66,12 +66,12 @@ describe 'BasicSocket#recvmsg' do end it 'stores an Addrinfo at index 1' do - @array[1].should be_an_instance_of(Addrinfo) + @array[1].should.instance_of?(Addrinfo) end platform_is_not :windows do it 'stores the flags at index 2' do - @array[2].should be_kind_of(Integer) + @array[2].should.is_a?(Integer) end end @@ -144,7 +144,7 @@ describe 'BasicSocket#recvmsg' do end it 'returns an Array containing the data, an Addrinfo and the flags' do - @socket.recvmsg.should be_an_instance_of(Array) + @socket.recvmsg.should.instance_of?(Array) end describe 'the returned Array' do @@ -157,11 +157,11 @@ describe 'BasicSocket#recvmsg' do end it 'stores an Addrinfo at index 1' do - @array[1].should be_an_instance_of(Addrinfo) + @array[1].should.instance_of?(Addrinfo) end it 'stores the flags at index 2' do - @array[2].should be_kind_of(Integer) + @array[2].should.is_a?(Integer) end describe 'the returned Addrinfo' do @@ -170,7 +170,7 @@ describe 'BasicSocket#recvmsg' do end it 'raises when receiving the ip_address message' do - -> { @addr.ip_address }.should raise_error(SocketError) + -> { @addr.ip_address }.should.raise(SocketError) end it 'uses the correct address family' do @@ -186,7 +186,7 @@ describe 'BasicSocket#recvmsg' do end it 'raises when receiving the ip_port message' do - -> { @addr.ip_port }.should raise_error(SocketError) + -> { @addr.ip_port }.should.raise(SocketError) end end end @@ -208,46 +208,22 @@ describe 'BasicSocket#recvmsg' 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 == "" + 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 - 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 + Thread.pass while t.status and t.status != "sleep" + t.status.should_not == nil - socket = TCPSocket.new('127.0.0.1', @port) - socket.close + socket = TCPSocket.new('127.0.0.1', @port) + socket.close - t.value.should be_nil - end + t.value.should == nil end end end diff --git a/spec/ruby/library/socket/basicsocket/send_spec.rb b/spec/ruby/library/socket/basicsocket/send_spec.rb index 25ba3f5655..a2c2ee8de9 100644 --- a/spec/ruby/library/socket/basicsocket/send_spec.rb +++ b/spec/ruby/library/socket/basicsocket/send_spec.rb @@ -9,8 +9,8 @@ describe "BasicSocket#send" do end after :each do - @server.closed?.should be_false - @socket.closed?.should be_false + @server.closed?.should == false + @socket.closed?.should == false @server.close @socket.close @@ -28,7 +28,7 @@ describe "BasicSocket#send" do client.close end Thread.pass while t.status and t.status != "sleep" - t.status.should_not be_nil + t.status.should_not == nil @socket.send('hello', 0).should == 5 @socket.shutdown(1) # indicate, that we are done sending @@ -50,7 +50,7 @@ describe "BasicSocket#send" do client.close end Thread.pass while t.status and t.status != "sleep" - t.status.should_not be_nil + t.status.should_not == nil @socket.send('helloU', Socket::MSG_PEEK | Socket::MSG_OOB).should == 6 @socket.shutdown # indicate, that we are done sending @@ -73,7 +73,7 @@ describe "BasicSocket#send" do client.close end Thread.pass while t.status and t.status != "sleep" - t.status.should_not be_nil + t.status.should_not == nil sockaddr = Socket.pack_sockaddr_in(@port, "127.0.0.1") @socket.send('hello', 0, sockaddr).should == 5 @@ -109,7 +109,7 @@ describe 'BasicSocket#send' do describe 'without a destination address' do it "raises #{SocketSpecs.dest_addr_req_error}" do - -> { @client.send('hello', 0) }.should raise_error(SocketSpecs.dest_addr_req_error) + -> { @client.send('hello', 0) }.should.raise(SocketSpecs.dest_addr_req_error) end end @@ -121,7 +121,7 @@ describe 'BasicSocket#send' do it 'does not persist the connection after writing to the socket' do @client.send('hello', 0, @server.getsockname) - -> { @client.send('hello', 0) }.should raise_error(SocketSpecs.dest_addr_req_error) + -> { @client.send('hello', 0) }.should.raise(SocketSpecs.dest_addr_req_error) end end diff --git a/spec/ruby/library/socket/basicsocket/sendmsg_nonblock_spec.rb b/spec/ruby/library/socket/basicsocket/sendmsg_nonblock_spec.rb index 7acfc659bd..4cd6e8bdca 100644 --- a/spec/ruby/library/socket/basicsocket/sendmsg_nonblock_spec.rb +++ b/spec/ruby/library/socket/basicsocket/sendmsg_nonblock_spec.rb @@ -20,10 +20,10 @@ describe 'BasicSocket#sendmsg_nonblock' do it "raises #{SocketSpecs.dest_addr_req_error}" do -> { @client.sendmsg_nonblock('hello') - }.should raise_error(SocketSpecs.dest_addr_req_error) + }.should.raise(SocketSpecs.dest_addr_req_error) -> { @client.sendmsg_nonblock('hello', exception: false) - }.should raise_error(SocketSpecs.dest_addr_req_error) + }.should.raise(SocketSpecs.dest_addr_req_error) end end @@ -101,7 +101,7 @@ describe 'BasicSocket#sendmsg_nonblock' do it 'raises IO::WaitWritable when the underlying buffer is full' do -> { 10.times { @client.sendmsg_nonblock('hello' * 1_000_000) } - }.should raise_error(IO::WaitWritable) + }.should.raise(IO::WaitWritable) end it 'returns :wait_writable when the underlying buffer is full with exception: false' do diff --git a/spec/ruby/library/socket/basicsocket/sendmsg_spec.rb b/spec/ruby/library/socket/basicsocket/sendmsg_spec.rb index 7ff336c0b7..dc999b32df 100644 --- a/spec/ruby/library/socket/basicsocket/sendmsg_spec.rb +++ b/spec/ruby/library/socket/basicsocket/sendmsg_spec.rb @@ -19,7 +19,7 @@ describe 'BasicSocket#sendmsg' do platform_is_not :windows do describe 'without a destination address' do it "raises #{SocketSpecs.dest_addr_req_error}" do - -> { @client.sendmsg('hello') }.should raise_error(SocketSpecs.dest_addr_req_error) + -> { @client.sendmsg('hello') }.should.raise(SocketSpecs.dest_addr_req_error) end end end diff --git a/spec/ruby/library/socket/basicsocket/setsockopt_spec.rb b/spec/ruby/library/socket/basicsocket/setsockopt_spec.rb index 1e8d84e1c9..e306581aa3 100644 --- a/spec/ruby/library/socket/basicsocket/setsockopt_spec.rb +++ b/spec/ruby/library/socket/basicsocket/setsockopt_spec.rb @@ -40,7 +40,7 @@ describe "BasicSocket#setsockopt" do it "raises EINVAL if passed wrong linger value" do -> do @sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_LINGER, 0) - end.should raise_error(Errno::EINVAL) + end.should.raise(Errno::EINVAL) end end @@ -72,7 +72,7 @@ describe "BasicSocket#setsockopt" do platform_is_not :windows do -> { @sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_OOBINLINE, "") - }.should raise_error(SystemCallError) + }.should.raise(SystemCallError) end @sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_OOBINLINE, "blah").should == 0 @@ -82,7 +82,7 @@ describe "BasicSocket#setsockopt" do platform_is_not :windows do -> { @sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_OOBINLINE, "0") - }.should raise_error(SystemCallError) + }.should.raise(SystemCallError) end @sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_OOBINLINE, "\x00\x00\x00\x00").should == 0 @@ -92,13 +92,13 @@ describe "BasicSocket#setsockopt" do platform_is_not :windows do -> { @sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_OOBINLINE, "1") - }.should raise_error(SystemCallError) + }.should.raise(SystemCallError) end platform_is_not :windows do -> { @sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_OOBINLINE, "\x00\x00\x00") - }.should raise_error(SystemCallError) + }.should.raise(SystemCallError) end @sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_OOBINLINE, [1].pack('i')).should == 0 @@ -127,7 +127,7 @@ describe "BasicSocket#setsockopt" do -> { @sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_SNDBUF, nil).should == 0 - }.should raise_error(TypeError) + }.should.raise(TypeError) @sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_SNDBUF, 1).should == 0 n = @sock.getsockopt(Socket::SOL_SOCKET, Socket::SO_SNDBUF).to_s @@ -139,23 +139,23 @@ describe "BasicSocket#setsockopt" do -> { @sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_SNDBUF, "") - }.should raise_error(SystemCallError) + }.should.raise(SystemCallError) -> { @sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_SNDBUF, "bla") - }.should raise_error(SystemCallError) + }.should.raise(SystemCallError) -> { @sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_SNDBUF, "0") - }.should raise_error(SystemCallError) + }.should.raise(SystemCallError) -> { @sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_SNDBUF, "1") - }.should raise_error(SystemCallError) + }.should.raise(SystemCallError) -> { @sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_SNDBUF, "\x00\x00\x00") - }.should raise_error(SystemCallError) + }.should.raise(SystemCallError) @sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_SNDBUF, "\x00\x00\x01\x00").should == 0 n = @sock.getsockopt(Socket::SOL_SOCKET, Socket::SO_SNDBUF).to_s @@ -207,7 +207,7 @@ describe "BasicSocket#setsockopt" do onoff, seconds = @sock.getsockopt(Socket::SOL_SOCKET, Socket::SO_LINGER).linger seconds.should == 10 # Both results can be produced depending on the OS and value of Socket::SO_LINGER - [true, Socket::SO_LINGER].should include(onoff) + [true, Socket::SO_LINGER].should.include?(onoff) end end end @@ -224,7 +224,7 @@ describe 'BasicSocket#setsockopt' do describe 'using separate arguments with Symbols' do it 'raises TypeError when the first argument is nil' do - -> { @socket.setsockopt(nil, :REUSEADDR, true) }.should raise_error(TypeError) + -> { @socket.setsockopt(nil, :REUSEADDR, true) }.should.raise(TypeError) end it 'sets a boolean option' do @@ -251,7 +251,7 @@ describe 'BasicSocket#setsockopt' do platform_is_not :windows do it 'raises Errno::EINVAL when setting an invalid option value' do - -> { @socket.setsockopt(:SOCKET, :OOBINLINE, 'bla') }.should raise_error(Errno::EINVAL) + -> { @socket.setsockopt(:SOCKET, :OOBINLINE, 'bla') }.should.raise(Errno::EINVAL) end end end @@ -305,32 +305,30 @@ describe 'BasicSocket#setsockopt' do it 'raises ArgumentError when passing 2 arguments' do option = Socket::Option.bool(:INET, :SOCKET, :REUSEADDR, true) - -> { @socket.setsockopt(option, :REUSEADDR) }.should raise_error(ArgumentError) + -> { @socket.setsockopt(option, :REUSEADDR) }.should.raise(ArgumentError) end it 'raises TypeError when passing 3 arguments' do option = Socket::Option.bool(:INET, :SOCKET, :REUSEADDR, true) - -> { @socket.setsockopt(option, :REUSEADDR, true) }.should raise_error(TypeError) + -> { @socket.setsockopt(option, :REUSEADDR, true) }.should.raise(TypeError) end 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 c78b32de38..c96c62abe1 100644 --- a/spec/ruby/library/socket/basicsocket/shutdown_spec.rb +++ b/spec/ruby/library/socket/basicsocket/shutdown_spec.rb @@ -23,25 +23,25 @@ platform_is_not :windows do # hangs it 'shuts down a socket for reading' do @client.shutdown(Socket::SHUT_RD) - @client.recv(1).to_s.should be_empty + @client.recv(1).to_s.should.empty? end it 'shuts down a socket for writing' do @client.shutdown(Socket::SHUT_WR) - -> { @client.write('hello') }.should raise_error(Errno::EPIPE) + -> { @client.write('hello') }.should.raise(Errno::EPIPE) end it 'shuts down a socket for reading and writing' do @client.shutdown(Socket::SHUT_RDWR) - @client.recv(1).to_s.should be_empty + @client.recv(1).to_s.should.empty? - -> { @client.write('hello') }.should raise_error(Errno::EPIPE) + -> { @client.write('hello') }.should.raise(Errno::EPIPE) end it 'raises ArgumentError when using an invalid option' do - -> { @server.shutdown(666) }.should raise_error(ArgumentError) + -> { @server.shutdown(666) }.should.raise(ArgumentError) end end @@ -49,37 +49,37 @@ platform_is_not :windows do # hangs it 'shuts down a socket for reading using :RD' do @client.shutdown(:RD) - @client.recv(1).to_s.should be_empty + @client.recv(1).to_s.should.empty? end it 'shuts down a socket for reading using :SHUT_RD' do @client.shutdown(:SHUT_RD) - @client.recv(1).to_s.should be_empty + @client.recv(1).to_s.should.empty? end it 'shuts down a socket for writing using :WR' do @client.shutdown(:WR) - -> { @client.write('hello') }.should raise_error(Errno::EPIPE) + -> { @client.write('hello') }.should.raise(Errno::EPIPE) end it 'shuts down a socket for writing using :SHUT_WR' do @client.shutdown(:SHUT_WR) - -> { @client.write('hello') }.should raise_error(Errno::EPIPE) + -> { @client.write('hello') }.should.raise(Errno::EPIPE) end it 'shuts down a socket for reading and writing' do @client.shutdown(:RDWR) - @client.recv(1).to_s.should be_empty + @client.recv(1).to_s.should.empty? - -> { @client.write('hello') }.should raise_error(Errno::EPIPE) + -> { @client.write('hello') }.should.raise(Errno::EPIPE) end it 'raises ArgumentError when using an invalid option' do - -> { @server.shutdown(:Nope) }.should raise_error(SocketError) + -> { @server.shutdown(:Nope) }.should.raise(SocketError) end end @@ -87,29 +87,29 @@ platform_is_not :windows do # hangs it 'shuts down a socket for reading using "RD"' do @client.shutdown('RD') - @client.recv(1).to_s.should be_empty + @client.recv(1).to_s.should.empty? end it 'shuts down a socket for reading using "SHUT_RD"' do @client.shutdown('SHUT_RD') - @client.recv(1).to_s.should be_empty + @client.recv(1).to_s.should.empty? end it 'shuts down a socket for writing using "WR"' do @client.shutdown('WR') - -> { @client.write('hello') }.should raise_error(Errno::EPIPE) + -> { @client.write('hello') }.should.raise(Errno::EPIPE) end it 'shuts down a socket for writing using "SHUT_WR"' do @client.shutdown('SHUT_WR') - -> { @client.write('hello') }.should raise_error(Errno::EPIPE) + -> { @client.write('hello') }.should.raise(Errno::EPIPE) end it 'raises ArgumentError when using an invalid option' do - -> { @server.shutdown('Nope') }.should raise_error(SocketError) + -> { @server.shutdown('Nope') }.should.raise(SocketError) end end @@ -123,7 +123,7 @@ platform_is_not :windows do # hangs @client.shutdown(@dummy) - @client.recv(1).to_s.should be_empty + @client.recv(1).to_s.should.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).to_s.should be_empty + @client.recv(1).to_s.should.empty? end it 'shuts down a socket for reading and writing' do @@ -139,15 +139,15 @@ platform_is_not :windows do # hangs @client.shutdown(@dummy) - @client.recv(1).to_s.should be_empty + @client.recv(1).to_s.should.empty? - -> { @client.write('hello') }.should raise_error(Errno::EPIPE) + -> { @client.write('hello') }.should.raise(Errno::EPIPE) end end describe 'using an object that does not respond to #to_str' do it 'raises TypeError' do - -> { @server.shutdown(mock(:dummy)) }.should raise_error(TypeError) + -> { @server.shutdown(mock(:dummy)) }.should.raise(TypeError) end end end diff --git a/spec/ruby/library/socket/constants/constants_spec.rb b/spec/ruby/library/socket/constants/constants_spec.rb index b9a9d42725..a936473bb6 100644 --- a/spec/ruby/library/socket/constants/constants_spec.rb +++ b/spec/ruby/library/socket/constants/constants_spec.rb @@ -5,47 +5,47 @@ describe "Socket::Constants" do it "defines socket types" do consts = ["SOCK_DGRAM", "SOCK_RAW", "SOCK_RDM", "SOCK_SEQPACKET", "SOCK_STREAM"] consts.each do |c| - Socket::Constants.should have_constant(c) + Socket::Constants.should.const_defined?(c, false) end end it "defines protocol families" do consts = ["PF_INET6", "PF_INET", "PF_UNIX", "PF_UNSPEC"] consts.each do |c| - Socket::Constants.should have_constant(c) + Socket::Constants.should.const_defined?(c, false) end end platform_is_not :aix do it "defines PF_IPX protocol" do - Socket::Constants.should have_constant("PF_IPX") + Socket::Constants.should.const_defined?("PF_IPX", false) end end it "defines address families" do consts = ["AF_INET6", "AF_INET", "AF_UNIX", "AF_UNSPEC"] consts.each do |c| - Socket::Constants.should have_constant(c) + Socket::Constants.should.const_defined?(c, false) end end platform_is_not :aix do it "defines AF_IPX address" do - Socket::Constants.should have_constant("AF_IPX") + Socket::Constants.should.const_defined?("AF_IPX", false) end end it "defines send/receive options" do consts = ["MSG_DONTROUTE", "MSG_OOB", "MSG_PEEK"] consts.each do |c| - Socket::Constants.should have_constant(c) + Socket::Constants.should.const_defined?(c, false) end end it "defines socket level options" do consts = ["SOL_SOCKET"] consts.each do |c| - Socket::Constants.should have_constant(c) + Socket::Constants.should.const_defined?(c, false) end end @@ -53,7 +53,7 @@ describe "Socket::Constants" do consts = ["SO_BROADCAST", "SO_DEBUG", "SO_DONTROUTE", "SO_ERROR", "SO_KEEPALIVE", "SO_LINGER", "SO_OOBINLINE", "SO_RCVBUF", "SO_REUSEADDR", "SO_SNDBUF", "SO_TYPE"] consts.each do |c| - Socket::Constants.should have_constant(c) + Socket::Constants.should.const_defined?(c, false) end end @@ -64,7 +64,7 @@ describe "Socket::Constants" do consts += ["IP_DEFAULT_MULTICAST_LOOP", "IP_DEFAULT_MULTICAST_TTL"] end consts.each do |c| - Socket::Constants.should have_constant(c) + Socket::Constants.should.const_defined?(c, false) end end @@ -72,7 +72,7 @@ describe "Socket::Constants" do it "defines multicast options" do consts = ["IP_MAX_MEMBERSHIPS"] consts.each do |c| - Socket::Constants.should have_constant(c) + Socket::Constants.should.const_defined?(c, false) end end end @@ -83,13 +83,13 @@ describe "Socket::Constants" do consts << "TCP_MAXSEG" end consts.each do |c| - Socket::Constants.should have_constant(c) + Socket::Constants.should.const_defined?(c, false) end end platform_is_not :windows do it 'defines SCM options' do - Socket::Constants.should have_constant('SCM_RIGHTS') + Socket::Constants.should.const_defined?('SCM_RIGHTS', false) end it 'defines error options' do @@ -101,7 +101,7 @@ describe "Socket::Constants" do end consts.each do |c| - Socket::Constants.should have_constant(c) + Socket::Constants.should.const_defined?(c, false) end end end diff --git a/spec/ruby/library/socket/ipsocket/addr_spec.rb b/spec/ruby/library/socket/ipsocket/addr_spec.rb index 199eb85ab7..eb16a8efdf 100644 --- a/spec/ruby/library/socket/ipsocket/addr_spec.rb +++ b/spec/ruby/library/socket/ipsocket/addr_spec.rb @@ -17,7 +17,7 @@ describe "Socket::IPSocket#addr" do BasicSocket.do_not_reverse_lookup = false addrinfo = @socket.addr addrinfo[0].should == "AF_INET" - addrinfo[1].should be_kind_of(Integer) + addrinfo[1].should.is_a?(Integer) addrinfo[2].should == SocketSpecs.hostname addrinfo[3].should == "127.0.0.1" end @@ -27,7 +27,7 @@ describe "Socket::IPSocket#addr" do BasicSocket.do_not_reverse_lookup = true addrinfo = @socket.addr addrinfo[0].should == "AF_INET" - addrinfo[1].should be_kind_of(Integer) + addrinfo[1].should.is_a?(Integer) addrinfo[2].should == "127.0.0.1" addrinfo[3].should == "127.0.0.1" end @@ -35,7 +35,7 @@ describe "Socket::IPSocket#addr" do it "returns an address in the array if passed false" do addrinfo = @socket.addr(false) addrinfo[0].should == "AF_INET" - addrinfo[1].should be_kind_of(Integer) + addrinfo[1].should.is_a?(Integer) addrinfo[2].should == "127.0.0.1" addrinfo[3].should == "127.0.0.1" end @@ -81,7 +81,7 @@ describe 'Socket::IPSocket#addr' do describe 'using :cats as the argument' do it 'raises ArgumentError' do - -> { @server.addr(:cats) }.should raise_error(ArgumentError) + -> { @server.addr(:cats) }.should.raise(ArgumentError) end end end diff --git a/spec/ruby/library/socket/ipsocket/getaddress_spec.rb b/spec/ruby/library/socket/ipsocket/getaddress_spec.rb index 329f8267d3..d302cd6a8a 100644 --- a/spec/ruby/library/socket/ipsocket/getaddress_spec.rb +++ b/spec/ruby/library/socket/ipsocket/getaddress_spec.rb @@ -23,6 +23,6 @@ describe "Socket::IPSocket#getaddress" do it "raises an error on unknown hostnames" do -> { IPSocket.getaddress("rubyspecdoesntexist.ruby-lang.org") - }.should raise_error(SocketError) + }.should.raise(SocketError) end end diff --git a/spec/ruby/library/socket/ipsocket/inspect_spec.rb b/spec/ruby/library/socket/ipsocket/inspect_spec.rb new file mode 100644 index 0000000000..85780a16f6 --- /dev/null +++ b/spec/ruby/library/socket/ipsocket/inspect_spec.rb @@ -0,0 +1,24 @@ +require_relative '../spec_helper' + +describe 'IPSocket#inspect' do + it "returns a String with the fd, family, address and port for TCPSocket" do + @server = TCPServer.new("127.0.0.1", 0) + @socket = TCPSocket.new("127.0.0.1", @server.addr[1]) + port = @socket.addr[1] + + @socket.inspect.should == "#<TCPSocket:fd #{@socket.fileno}, AF_INET, 127.0.0.1, #{port}>" + ensure + @socket&.close + @server&.close + end + + it 'returns a String with the fd, family, address and port for UDPSocket' do + @socket = UDPSocket.new + @socket.bind('127.0.0.1', 0) + port = @socket.addr[1] + + @socket.inspect.should == "#<UDPSocket:fd #{@socket.fileno}, AF_INET, 127.0.0.1, #{port}>" + ensure + @socket&.close + end +end diff --git a/spec/ruby/library/socket/ipsocket/peeraddr_spec.rb b/spec/ruby/library/socket/ipsocket/peeraddr_spec.rb index 702650940b..b79222000a 100644 --- a/spec/ruby/library/socket/ipsocket/peeraddr_spec.rb +++ b/spec/ruby/library/socket/ipsocket/peeraddr_spec.rb @@ -18,7 +18,7 @@ describe "Socket::IPSocket#peeraddr" do it "raises error if socket is not connected" do -> { @server.peeraddr - }.should raise_error(Errno::ENOTCONN) + }.should.raise(Errno::ENOTCONN) end it "returns an array of information on the peer" do @@ -92,7 +92,7 @@ describe 'Socket::IPSocket#peeraddr' do describe 'using :cats as the argument' do it 'raises ArgumentError' do - -> { @client.peeraddr(:cats) }.should raise_error(ArgumentError) + -> { @client.peeraddr(:cats) }.should.raise(ArgumentError) end end end diff --git a/spec/ruby/library/socket/ipsocket/recvfrom_spec.rb b/spec/ruby/library/socket/ipsocket/recvfrom_spec.rb index b58903df23..7af0078be1 100644 --- a/spec/ruby/library/socket/ipsocket/recvfrom_spec.rb +++ b/spec/ruby/library/socket/ipsocket/recvfrom_spec.rb @@ -83,43 +83,21 @@ describe "Socket::IPSocket#recvfrom" do @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 == "" + 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 - 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 + Thread.pass while t.status and t.status != "sleep" + t.status.should_not == nil - @client.close + @client.close - t.value.should be_nil - end + t.value.should == nil end end diff --git a/spec/ruby/library/socket/option/bool_spec.rb b/spec/ruby/library/socket/option/bool_spec.rb index 144a78043d..9992e842b3 100644 --- a/spec/ruby/library/socket/option/bool_spec.rb +++ b/spec/ruby/library/socket/option/bool_spec.rb @@ -4,7 +4,7 @@ require_relative '../fixtures/classes' describe "Socket::Option.bool" do it "creates a new Socket::Option" do so = Socket::Option.bool(:INET, :SOCKET, :KEEPALIVE, true) - so.should be_an_instance_of(Socket::Option) + so.should.instance_of?(Socket::Option) so.family.should == Socket::AF_INET so.level.should == Socket::SOL_SOCKET so.optname.should == Socket::SO_KEEPALIVE @@ -21,7 +21,7 @@ describe "Socket::Option#bool" do platform_is_not :windows do it 'raises TypeError when called on a non boolean option' do opt = Socket::Option.linger(1, 4) - -> { opt.bool }.should raise_error(TypeError) + -> { opt.bool }.should.raise(TypeError) end end end diff --git a/spec/ruby/library/socket/option/initialize_spec.rb b/spec/ruby/library/socket/option/initialize_spec.rb index 8071ad7ef0..5af274f332 100644 --- a/spec/ruby/library/socket/option/initialize_spec.rb +++ b/spec/ruby/library/socket/option/initialize_spec.rb @@ -10,7 +10,7 @@ describe 'Socket::Option#initialize' do opt = Socket::Option .new(Socket::AF_INET, Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, @bool) - opt.should be_an_instance_of(Socket::Option) + opt.should.instance_of?(Socket::Option) opt.family.should == Socket::AF_INET opt.level.should == Socket::SOL_SOCKET @@ -23,7 +23,7 @@ describe 'Socket::Option#initialize' do it 'returns a Socket::Option' do opt = Socket::Option.new(:INET, :SOCKET, :KEEPALIVE, @bool) - opt.should be_an_instance_of(Socket::Option) + opt.should.instance_of?(Socket::Option) opt.family.should == Socket::AF_INET opt.level.should == Socket::SOL_SOCKET @@ -34,19 +34,19 @@ describe 'Socket::Option#initialize' do it 'raises when using an invalid address family' do -> { Socket::Option.new(:INET2, :SOCKET, :KEEPALIVE, @bool) - }.should raise_error(SocketError) + }.should.raise(SocketError) end it 'raises when using an invalid level' do -> { Socket::Option.new(:INET, :CATS, :KEEPALIVE, @bool) - }.should raise_error(SocketError) + }.should.raise(SocketError) end it 'raises when using an invalid option name' do -> { Socket::Option.new(:INET, :SOCKET, :CATS, @bool) - }.should raise_error(SocketError) + }.should.raise(SocketError) end end @@ -54,7 +54,7 @@ describe 'Socket::Option#initialize' do it 'returns a Socket::Option' do opt = Socket::Option.new('INET', 'SOCKET', 'KEEPALIVE', @bool) - opt.should be_an_instance_of(Socket::Option) + opt.should.instance_of?(Socket::Option) opt.family.should == Socket::AF_INET opt.level.should == Socket::SOL_SOCKET @@ -65,19 +65,19 @@ describe 'Socket::Option#initialize' do it 'raises when using an invalid address family' do -> { Socket::Option.new('INET2', 'SOCKET', 'KEEPALIVE', @bool) - }.should raise_error(SocketError) + }.should.raise(SocketError) end it 'raises when using an invalid level' do -> { Socket::Option.new('INET', 'CATS', 'KEEPALIVE', @bool) - }.should raise_error(SocketError) + }.should.raise(SocketError) end it 'raises when using an invalid option name' do -> { Socket::Option.new('INET', 'SOCKET', 'CATS', @bool) - }.should raise_error(SocketError) + }.should.raise(SocketError) end end end diff --git a/spec/ruby/library/socket/option/int_spec.rb b/spec/ruby/library/socket/option/int_spec.rb index 8c69ef6cbd..0cd341f88a 100644 --- a/spec/ruby/library/socket/option/int_spec.rb +++ b/spec/ruby/library/socket/option/int_spec.rb @@ -4,7 +4,7 @@ require_relative '../fixtures/classes' describe "Socket::Option.int" do it "creates a new Socket::Option" do so = Socket::Option.int(:INET, :SOCKET, :KEEPALIVE, 5) - so.should be_an_instance_of(Socket::Option) + so.should.instance_of?(Socket::Option) so.family.should == Socket::Constants::AF_INET so.level.should == Socket::Constants::SOL_SOCKET so.optname.should == Socket::Constants::SO_KEEPALIVE @@ -14,7 +14,7 @@ describe "Socket::Option.int" do it 'returns a Socket::Option' do opt = Socket::Option.int(:INET, :IP, :TTL, 4) - opt.should be_an_instance_of(Socket::Option) + opt.should.instance_of?(Socket::Option) opt.family.should == Socket::AF_INET opt.level.should == Socket::IPPROTO_IP @@ -37,7 +37,7 @@ describe "Socket::Option#int" do platform_is_not :windows do it 'raises TypeError when called on a non integer option' do opt = Socket::Option.linger(1, 4) - -> { opt.int }.should raise_error(TypeError) + -> { opt.int }.should.raise(TypeError) end end end diff --git a/spec/ruby/library/socket/option/linger_spec.rb b/spec/ruby/library/socket/option/linger_spec.rb index ee987db85b..87c5e0982e 100644 --- a/spec/ruby/library/socket/option/linger_spec.rb +++ b/spec/ruby/library/socket/option/linger_spec.rb @@ -9,7 +9,7 @@ end describe "Socket::Option.linger" do it "creates a new Socket::Option for SO_LINGER" do so = Socket::Option.linger(1, 10) - so.should be_an_instance_of(Socket::Option) + so.should.instance_of?(Socket::Option) so.family.should == Socket::Constants::AF_UNSPEC so.level.should == Socket::Constants::SOL_SOCKET @@ -31,46 +31,46 @@ describe "Socket::Option#linger" do it "returns linger option" do so = Socket::Option.linger(0, 5) ary = so.linger - ary[0].should be_false + ary[0].should == false ary[1].should == 5 so = Socket::Option.linger(false, 4) ary = so.linger - ary[0].should be_false + ary[0].should == false ary[1].should == 4 so = Socket::Option.linger(1, 10) ary = so.linger - ary[0].should be_true + ary[0].should == true ary[1].should == 10 so = Socket::Option.linger(true, 9) ary = so.linger - ary[0].should be_true + ary[0].should == true ary[1].should == 9 end it "raises TypeError if not a SO_LINGER" do so = Socket::Option.int(:AF_UNSPEC, :SOL_SOCKET, :KEEPALIVE, 1) - -> { so.linger }.should raise_error(TypeError) + -> { so.linger }.should.raise(TypeError) end it 'raises TypeError when called on a non SOL_SOCKET/SO_LINGER option' do opt = Socket::Option.int(:INET, :IP, :TTL, 4) - -> { opt.linger }.should raise_error(TypeError) + -> { opt.linger }.should.raise(TypeError) end platform_is_not :windows do it "raises TypeError if option has not good size" do so = Socket::Option.int(:AF_UNSPEC, :SOL_SOCKET, :LINGER, 1) - -> { so.linger }.should raise_error(TypeError) + -> { so.linger }.should.raise(TypeError) end end it 'raises TypeError when called on a non linger option' do opt = Socket::Option.new(:INET, :SOCKET, :LINGER, '') - -> { opt.linger }.should raise_error(TypeError) + -> { opt.linger }.should.raise(TypeError) end end diff --git a/spec/ruby/library/socket/option/new_spec.rb b/spec/ruby/library/socket/option/new_spec.rb index a9e6f09097..3721d63ee5 100644 --- a/spec/ruby/library/socket/option/new_spec.rb +++ b/spec/ruby/library/socket/option/new_spec.rb @@ -22,14 +22,14 @@ describe "Socket::Option.new" do end it "should raise error on unknown family" do - -> { Socket::Option.new(:INET4, :SOCKET, :KEEPALIVE, [0].pack('i')) }.should raise_error(SocketError) + -> { Socket::Option.new(:INET4, :SOCKET, :KEEPALIVE, [0].pack('i')) }.should.raise(SocketError) end it "should raise error on unknown level" do - -> { Socket::Option.new(:INET, :ROCKET, :KEEPALIVE, [0].pack('i')) }.should raise_error(SocketError) + -> { Socket::Option.new(:INET, :ROCKET, :KEEPALIVE, [0].pack('i')) }.should.raise(SocketError) end it "should raise error on unknown option name" do - -> { Socket::Option.new(:INET, :SOCKET, :ALIVE, [0].pack('i')) }.should raise_error(SocketError) + -> { Socket::Option.new(:INET, :SOCKET, :ALIVE, [0].pack('i')) }.should.raise(SocketError) end end diff --git a/spec/ruby/library/socket/shared/address.rb b/spec/ruby/library/socket/shared/address.rb index f3be9cfb99..c64602df2f 100644 --- a/spec/ruby/library/socket/shared/address.rb +++ b/spec/ruby/library/socket/shared/address.rb @@ -46,7 +46,7 @@ describe :socket_local_remote_address, shared: true do end it 'returns an Addrinfo' do - @addr.should be_an_instance_of(Addrinfo) + @addr.should.instance_of?(Addrinfo) end it 'uses 0 as the protocol' do @@ -110,7 +110,7 @@ describe :socket_local_remote_address, shared: true do end it 'returns an Addrinfo' do - @addr.should be_an_instance_of(Addrinfo) + @addr.should.instance_of?(Addrinfo) end it 'uses 0 as the protocol' do @@ -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.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 @@ -230,7 +240,7 @@ describe :socket_local_remote_address, shared: true do end it 'returns an Addrinfo' do - @addr.should be_an_instance_of(Addrinfo) + @addr.should.instance_of?(Addrinfo) end it 'uses 0 as the protocol' do diff --git a/spec/ruby/library/socket/shared/pack_sockaddr.rb b/spec/ruby/library/socket/shared/pack_sockaddr.rb deleted file mode 100644 index f309aa02c7..0000000000 --- a/spec/ruby/library/socket/shared/pack_sockaddr.rb +++ /dev/null @@ -1,94 +0,0 @@ -# coding: utf-8 -describe :socket_pack_sockaddr_in, shared: true do - it "packs and unpacks" do - sockaddr_in = Socket.public_send(@method, 0, nil) - port, addr = Socket.unpack_sockaddr_in(sockaddr_in) - ["127.0.0.1", "::1"].include?(addr).should == true - port.should == 0 - - sockaddr_in = Socket.public_send(@method, 0, '') - Socket.unpack_sockaddr_in(sockaddr_in).should == [0, '0.0.0.0'] - - sockaddr_in = Socket.public_send(@method, 80, '127.0.0.1') - Socket.unpack_sockaddr_in(sockaddr_in).should == [80, '127.0.0.1'] - - sockaddr_in = Socket.public_send(@method, '80', '127.0.0.1') - Socket.unpack_sockaddr_in(sockaddr_in).should == [80, '127.0.0.1'] - - 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 - - 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 - it 'returns a String of 16 bytes' do - str = Socket.public_send(@method, 80, '127.0.0.1') - - str.should be_an_instance_of(String) - str.bytesize.should == 16 - end - end - - 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 - -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 "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 - end - - platform_is :linux do - it 'returns a String of 110 bytes' do - str = Socket.public_send(@method, '/tmp/test.sock') - - str.should be_an_instance_of(String) - str.bytesize.should == 110 - end - end - - platform_is :bsd do - it 'returns a String of 106 bytes' do - str = Socket.public_send(@method, '/tmp/test.sock') - - str.should be_an_instance_of(String) - str.bytesize.should == 106 - end - end - - platform_is_not :windows, :aix do - it "raises ArgumentError for paths that are too long" do - # AIX doesn't raise error - long_path = 'a' * 110 - -> { Socket.public_send(@method, long_path) }.should raise_error(ArgumentError) - end - end -end diff --git a/spec/ruby/library/socket/shared/socketpair.rb b/spec/ruby/library/socket/shared/socketpair.rb deleted file mode 100644 index 25146cfff6..0000000000 --- a/spec/ruby/library/socket/shared/socketpair.rb +++ /dev/null @@ -1,138 +0,0 @@ -describe :socket_socketpair, shared: true do - platform_is_not :windows do - it "ensures the returned sockets are connected" do - s1, s2 = Socket.public_send(@method, Socket::AF_UNIX, 1, 0) - s1.puts("test") - s2.gets.should == "test\n" - s1.close - s2.close - end - - it "responses with array of two sockets" do - begin - s1, s2 = Socket.public_send(@method, :UNIX, :STREAM) - - s1.should be_an_instance_of(Socket) - s2.should be_an_instance_of(Socket) - ensure - s1.close - s2.close - end - end - - describe 'using an Integer as the 1st and 2nd argument' do - it 'returns two Socket objects' do - s1, s2 = Socket.public_send(@method, Socket::AF_UNIX, Socket::SOCK_STREAM) - - s1.should be_an_instance_of(Socket) - s2.should be_an_instance_of(Socket) - s1.close - s2.close - end - end - - describe 'using a Symbol as the 1st and 2nd argument' do - it 'returns two Socket objects' do - s1, s2 = Socket.public_send(@method, :UNIX, :STREAM) - - s1.should be_an_instance_of(Socket) - s2.should be_an_instance_of(Socket) - s1.close - s2.close - end - - it 'raises SocketError for an unknown address family' do - -> { Socket.public_send(@method, :CATS, :STREAM) }.should raise_error(SocketError) - end - - it 'raises SocketError for an unknown socket type' do - -> { Socket.public_send(@method, :UNIX, :CATS) }.should raise_error(SocketError) - end - end - - describe 'using a String as the 1st and 2nd argument' do - it 'returns two Socket objects' do - s1, s2 = Socket.public_send(@method, 'UNIX', 'STREAM') - - s1.should be_an_instance_of(Socket) - s2.should be_an_instance_of(Socket) - s1.close - s2.close - end - - it 'raises SocketError for an unknown address family' do - -> { Socket.public_send(@method, 'CATS', 'STREAM') }.should raise_error(SocketError) - end - - it 'raises SocketError for an unknown socket type' do - -> { Socket.public_send(@method, 'UNIX', 'CATS') }.should raise_error(SocketError) - end - end - - describe 'using an object that responds to #to_str as the 1st and 2nd argument' do - it 'returns two Socket objects' do - family = mock(:family) - type = mock(:type) - - family.stub!(:to_str).and_return('UNIX') - type.stub!(:to_str).and_return('STREAM') - - s1, s2 = Socket.public_send(@method, family, type) - - s1.should be_an_instance_of(Socket) - s2.should be_an_instance_of(Socket) - s1.close - s2.close - end - - it 'raises TypeError when #to_str does not return a String' do - family = mock(:family) - type = mock(:type) - - family.stub!(:to_str).and_return(Socket::AF_UNIX) - type.stub!(:to_str).and_return(Socket::SOCK_STREAM) - - -> { Socket.public_send(@method, family, type) }.should raise_error(TypeError) - end - - it 'raises SocketError for an unknown address family' do - family = mock(:family) - type = mock(:type) - - family.stub!(:to_str).and_return('CATS') - type.stub!(:to_str).and_return('STREAM') - - -> { Socket.public_send(@method, family, type) }.should raise_error(SocketError) - end - - it 'raises SocketError for an unknown socket type' do - family = mock(:family) - type = mock(:type) - - family.stub!(:to_str).and_return('UNIX') - type.stub!(:to_str).and_return('CATS') - - -> { Socket.public_send(@method, family, type) }.should raise_error(SocketError) - end - end - - it 'accepts a custom protocol as an Integer as the 3rd argument' do - s1, s2 = Socket.public_send(@method, :UNIX, :STREAM, Socket::IPPROTO_IP) - s1.should be_an_instance_of(Socket) - s2.should be_an_instance_of(Socket) - s1.close - s2.close - end - - it 'connects the returned Socket objects' do - s1, s2 = Socket.public_send(@method, :UNIX, :STREAM) - begin - s1.write('hello') - s2.recv(5).should == 'hello' - ensure - s1.close - s2.close - end - end - end -end diff --git a/spec/ruby/library/socket/socket/accept_loop_spec.rb b/spec/ruby/library/socket/socket/accept_loop_spec.rb index 78e8c3fa4a..6c65b192ed 100644 --- a/spec/ruby/library/socket/socket/accept_loop_spec.rb +++ b/spec/ruby/library/socket/socket/accept_loop_spec.rb @@ -41,8 +41,8 @@ describe 'Socket.accept_loop' do end begin - conn.should be_an_instance_of(Socket) - addr.should be_an_instance_of(Addrinfo) + conn.should.instance_of?(Socket) + addr.should.instance_of?(Addrinfo) ensure conn.close end @@ -73,8 +73,8 @@ describe 'Socket.accept_loop' do end begin - conn.should be_an_instance_of(Socket) - addr.should be_an_instance_of(Addrinfo) + conn.should.instance_of?(Socket) + addr.should.instance_of?(Addrinfo) ensure conn.close end diff --git a/spec/ruby/library/socket/socket/accept_nonblock_spec.rb b/spec/ruby/library/socket/socket/accept_nonblock_spec.rb index 011622988c..09cdbaa7b4 100644 --- a/spec/ruby/library/socket/socket/accept_nonblock_spec.rb +++ b/spec/ruby/library/socket/socket/accept_nonblock_spec.rb @@ -17,12 +17,12 @@ describe "Socket#accept_nonblock" do it "raises IO::WaitReadable if the connection is not accepted yet" do -> { @socket.accept_nonblock - }.should raise_error(IO::WaitReadable) { |e| + }.should.raise(IO::WaitReadable) { |e| platform_is_not :windows do - e.should be_kind_of(Errno::EAGAIN) + e.should.is_a?(Errno::EAGAIN) end platform_is :windows do - e.should be_kind_of(Errno::EWOULDBLOCK) + e.should.is_a?(Errno::EWOULDBLOCK) end } end @@ -45,8 +45,8 @@ describe 'Socket#accept_nonblock' do describe 'using an unbound socket' do it 'raises Errno::EINVAL' do - -> { @server.accept_nonblock }.should raise_error(Errno::EINVAL) - -> { @server.accept_nonblock(exception: false) }.should raise_error(Errno::EINVAL) + -> { @server.accept_nonblock }.should.raise(Errno::EINVAL) + -> { @server.accept_nonblock(exception: false) }.should.raise(Errno::EINVAL) end end @@ -56,8 +56,8 @@ describe 'Socket#accept_nonblock' do end it 'raises Errno::EINVAL' do - -> { @server.accept_nonblock }.should raise_error(Errno::EINVAL) - -> { @server.accept_nonblock(exception: false) }.should raise_error(Errno::EINVAL) + -> { @server.accept_nonblock }.should.raise(Errno::EINVAL) + -> { @server.accept_nonblock(exception: false) }.should.raise(Errno::EINVAL) end end @@ -65,8 +65,8 @@ describe 'Socket#accept_nonblock' do it 'raises IOError' do @server.close - -> { @server.accept_nonblock }.should raise_error(IOError) - -> { @server.accept_nonblock(exception: false) }.should raise_error(IOError) + -> { @server.accept_nonblock }.should.raise(IOError) + -> { @server.accept_nonblock(exception: false) }.should.raise(IOError) end end @@ -78,7 +78,7 @@ describe 'Socket#accept_nonblock' do describe 'without a connected client' do it 'raises IO::WaitReadable' do - -> { @server.accept_nonblock }.should raise_error(IO::WaitReadable) + -> { @server.accept_nonblock }.should.raise(IO::WaitReadable) end end @@ -100,8 +100,8 @@ describe 'Socket#accept_nonblock' do IO.select([@server]) @socket, addrinfo = @server.accept_nonblock - @socket.should be_an_instance_of(Socket) - addrinfo.should be_an_instance_of(Addrinfo) + @socket.should.instance_of?(Socket) + addrinfo.should.instance_of?(Addrinfo) end describe 'the returned Addrinfo' do diff --git a/spec/ruby/library/socket/socket/accept_spec.rb b/spec/ruby/library/socket/socket/accept_spec.rb index 417f996c55..fca727ab08 100644 --- a/spec/ruby/library/socket/socket/accept_spec.rb +++ b/spec/ruby/library/socket/socket/accept_spec.rb @@ -15,7 +15,7 @@ describe 'Socket#accept' do platform_is :linux do # hangs on other platforms describe 'using an unbound socket' do it 'raises Errno::EINVAL' do - -> { @server.accept }.should raise_error(Errno::EINVAL) + -> { @server.accept }.should.raise(Errno::EINVAL) end end @@ -25,7 +25,7 @@ describe 'Socket#accept' do end it 'raises Errno::EINVAL' do - -> { @server.accept }.should raise_error(Errno::EINVAL) + -> { @server.accept }.should.raise(Errno::EINVAL) end end end @@ -34,7 +34,7 @@ describe 'Socket#accept' do it 'raises IOError' do @server.close - -> { @server.accept }.should raise_error(IOError) + -> { @server.accept }.should.raise(IOError) end end @@ -58,7 +58,7 @@ describe 'Socket#accept' do value = thread.value begin - value.should be_an_instance_of(Array) + value.should.instance_of?(Array) ensure client.close value[0].close @@ -82,8 +82,8 @@ describe 'Socket#accept' do it 'returns an Array containing a Socket and an Addrinfo' do @socket, addrinfo = @server.accept - @socket.should be_an_instance_of(Socket) - addrinfo.should be_an_instance_of(Addrinfo) + @socket.should.instance_of?(Socket) + addrinfo.should.instance_of?(Addrinfo) end describe 'the returned Addrinfo' do diff --git a/spec/ruby/library/socket/socket/bind_spec.rb b/spec/ruby/library/socket/socket/bind_spec.rb index e76336eafa..164df92205 100644 --- a/spec/ruby/library/socket/socket/bind_spec.rb +++ b/spec/ruby/library/socket/socket/bind_spec.rb @@ -8,12 +8,12 @@ describe "Socket#bind on SOCK_DGRAM socket" do end after :each do - @sock.closed?.should be_false + @sock.closed?.should == false @sock.close end it "binds to a port" do - -> { @sock.bind(@sockaddr) }.should_not raise_error + -> { @sock.bind(@sockaddr) }.should_not.raise end it "returns 0 if successful" do @@ -23,12 +23,12 @@ describe "Socket#bind on SOCK_DGRAM socket" do it "raises Errno::EINVAL when already bound" do @sock.bind(@sockaddr) - -> { @sock.bind(@sockaddr) }.should raise_error(Errno::EINVAL) + -> { @sock.bind(@sockaddr) }.should.raise(Errno::EINVAL) end it "raises Errno::EADDRNOTAVAIL when the specified sockaddr is not available from the local machine" do sockaddr1 = Socket.pack_sockaddr_in(0, "4.3.2.1") - -> { @sock.bind(sockaddr1) }.should raise_error(Errno::EADDRNOTAVAIL) + -> { @sock.bind(sockaddr1) }.should.raise(Errno::EADDRNOTAVAIL) end platform_is_not :windows, :cygwin do @@ -36,7 +36,7 @@ describe "Socket#bind on SOCK_DGRAM socket" do break if File.read('/proc/sys/net/ipv4/ip_unprivileged_port_start').to_i <= 1 rescue nil it "raises Errno::EACCES when the current user does not have permission to bind" do sockaddr1 = Socket.pack_sockaddr_in(1, "127.0.0.1") - -> { @sock.bind(sockaddr1) }.should raise_error(Errno::EACCES) + -> { @sock.bind(sockaddr1) }.should.raise(Errno::EACCES) end end end @@ -50,12 +50,12 @@ describe "Socket#bind on SOCK_STREAM socket" do end after :each do - @sock.closed?.should be_false + @sock.closed?.should == false @sock.close end it "binds to a port" do - -> { @sock.bind(@sockaddr) }.should_not raise_error + -> { @sock.bind(@sockaddr) }.should_not.raise end it "returns 0 if successful" do @@ -65,12 +65,12 @@ describe "Socket#bind on SOCK_STREAM socket" do it "raises Errno::EINVAL when already bound" do @sock.bind(@sockaddr) - -> { @sock.bind(@sockaddr) }.should raise_error(Errno::EINVAL) + -> { @sock.bind(@sockaddr) }.should.raise(Errno::EINVAL) end it "raises Errno::EADDRNOTAVAIL when the specified sockaddr is not available from the local machine" do sockaddr1 = Socket.pack_sockaddr_in(0, "4.3.2.1") - -> { @sock.bind(sockaddr1) }.should raise_error(Errno::EADDRNOTAVAIL) + -> { @sock.bind(sockaddr1) }.should.raise(Errno::EADDRNOTAVAIL) end platform_is_not :windows, :cygwin do @@ -78,7 +78,7 @@ describe "Socket#bind on SOCK_STREAM socket" do break if File.read('/proc/sys/net/ipv4/ip_unprivileged_port_start').to_i <= 1 rescue nil it "raises Errno::EACCES when the current user does not have permission to bind" do sockaddr1 = Socket.pack_sockaddr_in(1, "127.0.0.1") - -> { @sock.bind(sockaddr1) }.should raise_error(Errno::EACCES) + -> { @sock.bind(sockaddr1) }.should.raise(Errno::EACCES) end end end @@ -103,14 +103,14 @@ describe 'Socket#bind' do it 'raises Errno::EINVAL when binding to an already bound port' do @socket.bind(@sockaddr) - -> { @socket.bind(@sockaddr) }.should raise_error(Errno::EINVAL) + -> { @socket.bind(@sockaddr) }.should.raise(Errno::EINVAL) end it 'raises Errno::EADDRNOTAVAIL when the specified sockaddr is not available' do ip = family == Socket::AF_INET ? '4.3.2.1' : '::2' sockaddr1 = Socket.sockaddr_in(0, ip) - -> { @socket.bind(sockaddr1) }.should raise_error(Errno::EADDRNOTAVAIL) + -> { @socket.bind(sockaddr1) }.should.raise(Errno::EADDRNOTAVAIL) end platform_is_not :windows do @@ -120,7 +120,7 @@ describe 'Socket#bind' do it 'raises Errno::EACCES when the user is not allowed to bind to the port' do sockaddr1 = Socket.pack_sockaddr_in(1, ip_address) - -> { @socket.bind(sockaddr1) }.should raise_error(Errno::EACCES) + -> { @socket.bind(sockaddr1) }.should.raise(Errno::EACCES) end end end @@ -138,7 +138,7 @@ describe 'Socket#bind' do it 'binds to an Addrinfo' do @socket.bind(@addr).should == 0 - @socket.local_address.should be_an_instance_of(Addrinfo) + @socket.local_address.should.instance_of?(Addrinfo) end it 'uses a new Addrinfo for the local address' do diff --git a/spec/ruby/library/socket/socket/connect_nonblock_spec.rb b/spec/ruby/library/socket/socket/connect_nonblock_spec.rb index 359b8719fb..dac24e3e5b 100644 --- a/spec/ruby/library/socket/socket/connect_nonblock_spec.rb +++ b/spec/ruby/library/socket/socket/connect_nonblock_spec.rb @@ -53,13 +53,13 @@ describe "Socket#connect_nonblock" do it "raises Errno::EINPROGRESS when the connect would block" do -> do @socket.connect_nonblock(@addr) - end.should raise_error(Errno::EINPROGRESS) + end.should.raise(Errno::EINPROGRESS) end it "raises Errno::EINPROGRESS with IO::WaitWritable mixed in when the connect would block" do -> do @socket.connect_nonblock(@addr) - end.should raise_error(IO::WaitWritable) + end.should.raise(IO::WaitWritable) end it "returns :wait_writable in exceptionless mode when the connect would block" do @@ -93,7 +93,7 @@ describe 'Socket#connect_nonblock' do end it 'raises TypeError when passed an Integer' do - -> { @client.connect_nonblock(666) }.should raise_error(TypeError) + -> { @client.connect_nonblock(666) }.should.raise(TypeError) end end @@ -122,7 +122,7 @@ describe 'Socket#connect_nonblock' do # as it's too implementation-dependent and checking for connect() # errors is futile anyways because of TOCTOU @client.connect_nonblock(@server.connect_address) - }.should raise_error(Errno::EISCONN) + }.should.raise(Errno::EISCONN) end it 'returns 0 when already connected in exceptionless mode' do @@ -139,7 +139,7 @@ describe 'Socket#connect_nonblock' do -> { @client.connect_nonblock(@server.connect_address) - }.should raise_error(IO::EINPROGRESSWaitWritable) + }.should.raise(IO::EINPROGRESSWaitWritable) end end end diff --git a/spec/ruby/library/socket/socket/connect_spec.rb b/spec/ruby/library/socket/socket/connect_spec.rb index 130379ce2b..c928b66c53 100644 --- a/spec/ruby/library/socket/socket/connect_spec.rb +++ b/spec/ruby/library/socket/socket/connect_spec.rb @@ -40,7 +40,7 @@ describe 'Socket#connect' do # as it's too implementation-dependent and checking for connect() # errors is futile anyways because of TOCTOU @client.connect(@server.getsockname) - }.should raise_error(Errno::EISCONN) + }.should.raise(Errno::EISCONN) end platform_is_not :darwin do @@ -70,7 +70,7 @@ describe 'Socket#connect' do rescue Errno::ENETUNREACH skip "Off line" end - }.should raise_error(IO::TimeoutError) + }.should.raise(IO::TimeoutError) ensure client.close end diff --git a/spec/ruby/library/socket/socket/getaddrinfo_spec.rb b/spec/ruby/library/socket/socket/getaddrinfo_spec.rb index 9f049597d0..7e5bdc9b25 100644 --- a/spec/ruby/library/socket/socket/getaddrinfo_spec.rb +++ b/spec/ruby/library/socket/socket/getaddrinfo_spec.rb @@ -43,7 +43,7 @@ describe "Socket.getaddrinfo" do addrinfo.each do |a| case a.last when Socket::IPPROTO_UDP, Socket::IPPROTO_TCP - expected.should include(a) + expected.should.include?(a) else # don't check this. It's some weird protocol we don't know about # so we can't spec it. @@ -90,7 +90,7 @@ describe "Socket.getaddrinfo" do ["AF_INET6", 9, "::", "::", Socket::AF_INET6, Socket::SOCK_STREAM, Socket::IPPROTO_TCP], ["AF_INET6", 9, "0:0:0:0:0:0:0:0", "0:0:0:0:0:0:0:0", Socket::AF_INET6, Socket::SOCK_STREAM, Socket::IPPROTO_TCP] ] - res.each { |a| expected.should include(a) } + res.each { |a| expected.should.include?(a) } end it "accepts empty addresses for IPv6 non-passive sockets" do @@ -104,7 +104,15 @@ describe "Socket.getaddrinfo" do ["AF_INET6", 9, "::1", "::1", Socket::AF_INET6, Socket::SOCK_STREAM, Socket::IPPROTO_TCP], ["AF_INET6", 9, "0:0:0:0:0:0:0:1", "0:0:0:0:0:0:0:1", Socket::AF_INET6, Socket::SOCK_STREAM, Socket::IPPROTO_TCP] ] - res.each { |a| expected.should include(a) } + res.each { |a| expected.should.include?(a) } + end + + it "raises ResolutionError when fails to resolve address" do + -> { + Socket.getaddrinfo("www.kame.net", 80, "AF_UNIX") + }.should.raise(Socket::ResolutionError) { |e| + [Socket::EAI_FAMILY, Socket::EAI_FAIL].should.include?(e.error_code) + } end end end @@ -112,7 +120,7 @@ end describe 'Socket.getaddrinfo' do describe 'without global reverse lookups' do it 'returns an Array' do - Socket.getaddrinfo(nil, 'ftp').should be_an_instance_of(Array) + Socket.getaddrinfo(nil, 'ftp').should.instance_of?(Array) end it 'accepts an Integer as the address family' do @@ -123,8 +131,8 @@ describe 'Socket.getaddrinfo' do array[2].should == '127.0.0.1' array[3].should == '127.0.0.1' array[4].should == Socket::AF_INET - array[5].should be_kind_of(Integer) - array[6].should be_kind_of(Integer) + array[5].should.is_a?(Integer) + array[6].should.is_a?(Integer) end it 'accepts an Integer as the address family using IPv6' do @@ -135,8 +143,8 @@ describe 'Socket.getaddrinfo' do array[2].should == '::1' array[3].should == '::1' array[4].should == Socket::AF_INET6 - array[5].should be_kind_of(Integer) - array[6].should be_kind_of(Integer) + array[5].should.is_a?(Integer) + array[6].should.is_a?(Integer) end it 'accepts a Symbol as the address family' do @@ -147,8 +155,8 @@ describe 'Socket.getaddrinfo' do array[2].should == '127.0.0.1' array[3].should == '127.0.0.1' array[4].should == Socket::AF_INET - array[5].should be_kind_of(Integer) - array[6].should be_kind_of(Integer) + array[5].should.is_a?(Integer) + array[6].should.is_a?(Integer) end it 'accepts a Symbol as the address family using IPv6' do @@ -159,8 +167,8 @@ describe 'Socket.getaddrinfo' do array[2].should == '::1' array[3].should == '::1' array[4].should == Socket::AF_INET6 - array[5].should be_kind_of(Integer) - array[6].should be_kind_of(Integer) + array[5].should.is_a?(Integer) + array[6].should.is_a?(Integer) end it 'accepts a String as the address family' do @@ -171,8 +179,8 @@ describe 'Socket.getaddrinfo' do array[2].should == '127.0.0.1' array[3].should == '127.0.0.1' array[4].should == Socket::AF_INET - array[5].should be_kind_of(Integer) - array[6].should be_kind_of(Integer) + array[5].should.is_a?(Integer) + array[6].should.is_a?(Integer) end it 'accepts a String as the address family using IPv6' do @@ -183,8 +191,8 @@ describe 'Socket.getaddrinfo' do array[2].should == '::1' array[3].should == '::1' array[4].should == Socket::AF_INET6 - array[5].should be_kind_of(Integer) - array[6].should be_kind_of(Integer) + array[5].should.is_a?(Integer) + array[6].should.is_a?(Integer) end it 'accepts an object responding to #to_str as the host' do @@ -199,8 +207,8 @@ describe 'Socket.getaddrinfo' do array[2].should == '127.0.0.1' array[3].should == '127.0.0.1' array[4].should == Socket::AF_INET - array[5].should be_kind_of(Integer) - array[6].should be_kind_of(Integer) + array[5].should.is_a?(Integer) + array[6].should.is_a?(Integer) end it 'accepts an object responding to #to_str as the address family' do @@ -215,8 +223,8 @@ describe 'Socket.getaddrinfo' do array[2].should == '127.0.0.1' array[3].should == '127.0.0.1' array[4].should == Socket::AF_INET - array[5].should be_kind_of(Integer) - array[6].should be_kind_of(Integer) + array[5].should.is_a?(Integer) + array[6].should.is_a?(Integer) end it 'accepts an Integer as the socket type' do @@ -229,7 +237,7 @@ describe 'Socket.getaddrinfo' do Socket::AF_INET, Socket::SOCK_STREAM, ] - [0, Socket::IPPROTO_TCP].should include(proto) + [0, Socket::IPPROTO_TCP].should.include?(proto) end it 'accepts a Symbol as the socket type' do @@ -242,7 +250,7 @@ describe 'Socket.getaddrinfo' do Socket::AF_INET, Socket::SOCK_STREAM, ] - [0, Socket::IPPROTO_TCP].should include(proto) + [0, Socket::IPPROTO_TCP].should.include?(proto) end it 'accepts a String as the socket type' do @@ -255,7 +263,7 @@ describe 'Socket.getaddrinfo' do Socket::AF_INET, Socket::SOCK_STREAM, ] - [0, Socket::IPPROTO_TCP].should include(proto) + [0, Socket::IPPROTO_TCP].should.include?(proto) end it 'accepts an object responding to #to_str as the socket type' do @@ -272,7 +280,7 @@ describe 'Socket.getaddrinfo' do Socket::AF_INET, Socket::SOCK_STREAM, ] - [0, Socket::IPPROTO_TCP].should include(proto) + [0, Socket::IPPROTO_TCP].should.include?(proto) end platform_is_not :windows do @@ -286,7 +294,7 @@ describe 'Socket.getaddrinfo' do Socket::AF_INET, Socket::SOCK_DGRAM, ] - [0, Socket::IPPROTO_UDP].should include(proto) + [0, Socket::IPPROTO_UDP].should.include?(proto) end end @@ -301,7 +309,7 @@ describe 'Socket.getaddrinfo' do Socket::AF_INET, Socket::SOCK_STREAM, ] - [0, Socket::IPPROTO_TCP].should include(proto) + [0, Socket::IPPROTO_TCP].should.include?(proto) end it 'performs a reverse lookup when the reverse_lookup argument is true' do @@ -311,7 +319,7 @@ describe 'Socket.getaddrinfo' do addr[0].should == 'AF_INET' addr[1].should == 21 - addr[2].should be_an_instance_of(String) + addr[2].should.instance_of?(String) addr[2].should_not == addr[3] addr[3].should == '127.0.0.1' @@ -324,7 +332,7 @@ describe 'Socket.getaddrinfo' do addr[0].should == 'AF_INET' addr[1].should == 21 - addr[2].should be_an_instance_of(String) + addr[2].should.instance_of?(String) addr[2].should_not == addr[3] addr[3].should == '127.0.0.1' @@ -341,7 +349,7 @@ describe 'Socket.getaddrinfo' do Socket::AF_INET, Socket::SOCK_STREAM, ] - [0, Socket::IPPROTO_TCP].should include(proto) + [0, Socket::IPPROTO_TCP].should.include?(proto) end end @@ -364,7 +372,7 @@ describe 'Socket.getaddrinfo' do # We don't have control over this value and there's no way to test this # without relying on Socket.getaddrinfo()'s own behaviour (meaning this # test would faily any way of the method was not implemented correctly). - addr[2].should be_an_instance_of(String) + addr[2].should.instance_of?(String) addr[2].should_not == addr[3] addr[3].should == '127.0.0.1' diff --git a/spec/ruby/library/socket/socket/gethostbyaddr_spec.rb b/spec/ruby/library/socket/socket/gethostbyaddr_spec.rb index 5d936046f5..bf6d63dbe9 100644 --- a/spec/ruby/library/socket/socket/gethostbyaddr_spec.rb +++ b/spec/ruby/library/socket/socket/gethostbyaddr_spec.rb @@ -10,7 +10,7 @@ describe 'Socket.gethostbyaddr' do describe 'without an explicit address family' do it 'returns an Array' do - suppress_warning { Socket.gethostbyaddr(@addr) }.should be_an_instance_of(Array) + suppress_warning { Socket.gethostbyaddr(@addr) }.should.instance_of?(Array) end describe 'the returned Array' do @@ -23,10 +23,10 @@ describe 'Socket.gethostbyaddr' do end it 'includes the aliases as the 2nd value' do - @array[1].should be_an_instance_of(Array) + @array[1].should.instance_of?(Array) @array[1].each do |val| - val.should be_an_instance_of(String) + val.should.instance_of?(String) end end @@ -38,7 +38,7 @@ describe 'Socket.gethostbyaddr' do @array[3].should == @addr @array[4..-1].each do |val| - val.should be_an_instance_of(String) + val.should.instance_of?(String) end end end @@ -46,15 +46,15 @@ describe 'Socket.gethostbyaddr' do describe 'with an explicit address family' do it 'returns an Array when using an Integer as the address family' do - suppress_warning { Socket.gethostbyaddr(@addr, Socket::AF_INET) }.should be_an_instance_of(Array) + suppress_warning { Socket.gethostbyaddr(@addr, Socket::AF_INET) }.should.instance_of?(Array) end it 'returns an Array when using a Symbol as the address family' do - suppress_warning { Socket.gethostbyaddr(@addr, :INET) }.should be_an_instance_of(Array) + suppress_warning { Socket.gethostbyaddr(@addr, :INET) }.should.instance_of?(Array) end it 'raises SocketError when the address is not supported by the family' do - -> { suppress_warning { Socket.gethostbyaddr(@addr, :INET6) } }.should raise_error(SocketError) + -> { suppress_warning { Socket.gethostbyaddr(@addr, :INET6) } }.should.raise(SocketError) end end end @@ -67,7 +67,7 @@ describe 'Socket.gethostbyaddr' do describe 'without an explicit address family' do it 'returns an Array' do - suppress_warning { Socket.gethostbyaddr(@addr) }.should be_an_instance_of(Array) + suppress_warning { Socket.gethostbyaddr(@addr) }.should.instance_of?(Array) end describe 'the returned Array' do @@ -80,10 +80,10 @@ describe 'Socket.gethostbyaddr' do end it 'includes the aliases as the 2nd value' do - @array[1].should be_an_instance_of(Array) + @array[1].should.instance_of?(Array) @array[1].each do |val| - val.should be_an_instance_of(String) + val.should.instance_of?(String) end end @@ -92,10 +92,10 @@ describe 'Socket.gethostbyaddr' do end it 'includes all address strings as the remaining values' do - @array[3].should be_an_instance_of(String) + @array[3].should.instance_of?(String) @array[4..-1].each do |val| - val.should be_an_instance_of(String) + val.should.instance_of?(String) end end end @@ -103,16 +103,16 @@ describe 'Socket.gethostbyaddr' do describe 'with an explicit address family' do it 'returns an Array when using an Integer as the address family' do - suppress_warning { Socket.gethostbyaddr(@addr, Socket::AF_INET6) }.should be_an_instance_of(Array) + suppress_warning { Socket.gethostbyaddr(@addr, Socket::AF_INET6) }.should.instance_of?(Array) end it 'returns an Array when using a Symbol as the address family' do - suppress_warning { Socket.gethostbyaddr(@addr, :INET6) }.should be_an_instance_of(Array) + suppress_warning { Socket.gethostbyaddr(@addr, :INET6) }.should.instance_of?(Array) end platform_is_not :windows, :wsl do it 'raises SocketError when the address is not supported by the family' do - -> { suppress_warning { Socket.gethostbyaddr(@addr, :INET) } }.should raise_error(SocketError) + -> { suppress_warning { Socket.gethostbyaddr(@addr, :INET) } }.should.raise(SocketError) end end end diff --git a/spec/ruby/library/socket/socket/gethostbyname_spec.rb b/spec/ruby/library/socket/socket/gethostbyname_spec.rb index 618ef85387..326fe26094 100644 --- a/spec/ruby/library/socket/socket/gethostbyname_spec.rb +++ b/spec/ruby/library/socket/socket/gethostbyname_spec.rb @@ -16,7 +16,7 @@ end describe 'Socket.gethostbyname' do it 'returns an Array' do - suppress_warning { Socket.gethostbyname('127.0.0.1') }.should be_an_instance_of(Array) + suppress_warning { Socket.gethostbyname('127.0.0.1') }.should.instance_of?(Array) end describe 'the returned Array' do @@ -29,10 +29,10 @@ describe 'Socket.gethostbyname' do end it 'includes the aliases as the 2nd value' do - @array[1].should be_an_instance_of(Array) + @array[1].should.instance_of?(Array) @array[1].each do |val| - val.should be_an_instance_of(String) + val.should.instance_of?(String) end end @@ -43,10 +43,10 @@ describe 'Socket.gethostbyname' do end it 'includes the address strings as the remaining values' do - @array[3].should be_an_instance_of(String) + @array[3].should.instance_of?(String) @array[4..-1].each do |val| - val.should be_an_instance_of(String) + val.should.instance_of?(String) end end end diff --git a/spec/ruby/library/socket/socket/getifaddrs_spec.rb b/spec/ruby/library/socket/socket/getifaddrs_spec.rb index 839854ea27..1b326605c8 100644 --- a/spec/ruby/library/socket/socket/getifaddrs_spec.rb +++ b/spec/ruby/library/socket/socket/getifaddrs_spec.rb @@ -7,17 +7,17 @@ describe 'Socket.getifaddrs' do end it 'returns an Array' do - @ifaddrs.should be_an_instance_of(Array) + @ifaddrs.should.instance_of?(Array) end describe 'the returned Array' do it 'should not be empty' do - @ifaddrs.should_not be_empty + @ifaddrs.should_not.empty? end it 'contains instances of Socket::Ifaddr' do @ifaddrs.each do |ifaddr| - ifaddr.should be_an_instance_of(Socket::Ifaddr) + ifaddr.should.instance_of?(Socket::Ifaddr) end end end @@ -25,19 +25,19 @@ describe 'Socket.getifaddrs' do describe 'each returned Socket::Ifaddr' do it 'has an interface index' do @ifaddrs.each do |ifaddr| - ifaddr.ifindex.should be_kind_of(Integer) + ifaddr.ifindex.should.is_a?(Integer) end end it 'has an interface name' do @ifaddrs.each do |ifaddr| - ifaddr.name.should be_an_instance_of(String) + ifaddr.name.should.instance_of?(String) end end it 'has a set of flags' do @ifaddrs.each do |ifaddr| - ifaddr.flags.should be_kind_of(Integer) + ifaddr.flags.should.is_a?(Integer) end end end @@ -49,17 +49,17 @@ describe 'Socket.getifaddrs' do it 'is an Addrinfo' do @addrs.all? do |addr| - addr.should be_an_instance_of(Addrinfo) + addr.should.instance_of?(Addrinfo) true - end.should be_true + end.should == true end it 'has an address family' do @addrs.all? do |addr| - addr.afamily.should be_kind_of(Integer) + addr.afamily.should.is_a?(Integer) addr.afamily.should_not == Socket::AF_UNSPEC true - end.should be_true + end.should == true end end @@ -71,17 +71,17 @@ describe 'Socket.getifaddrs' do it 'is an Addrinfo' do @addrs.all? do |addr| - addr.should be_an_instance_of(Addrinfo) + addr.should.instance_of?(Addrinfo) true - end.should be_true + end.should == true end it 'has an address family' do @addrs.all? do |addr| - addr.afamily.should be_kind_of(Integer) + addr.afamily.should.is_a?(Integer) addr.afamily.should_not == Socket::AF_UNSPEC true - end.should be_true + end.should == true end end @@ -92,24 +92,24 @@ describe 'Socket.getifaddrs' do it 'is an Addrinfo' do @addrs.all? do |addr| - addr.should be_an_instance_of(Addrinfo) + addr.should.instance_of?(Addrinfo) true - end.should be_true + end.should == true end it 'has an address family' do @addrs.all? do |addr| - addr.afamily.should be_kind_of(Integer) + addr.afamily.should.is_a?(Integer) addr.afamily.should_not == Socket::AF_UNSPEC true - end.should be_true + end.should == true end it 'has an IP address' do @addrs.all? do |addr| - addr.ip_address.should be_an_instance_of(String) + addr.ip_address.should.instance_of?(String) true - end.should be_true + end.should == true end end end diff --git a/spec/ruby/library/socket/socket/getnameinfo_spec.rb b/spec/ruby/library/socket/socket/getnameinfo_spec.rb index 4f13bf484d..d0b77004de 100644 --- a/spec/ruby/library/socket/socket/getnameinfo_spec.rb +++ b/spec/ruby/library/socket/socket/getnameinfo_spec.rb @@ -60,6 +60,14 @@ describe "Socket.getnameinfo" do name_info = Socket.getnameinfo ["AF_INET", 9, 'foo', '127.0.0.1'] name_info[1].should == 'discard' end + + it "raises ResolutionError when fails to resolve address" do + -> { + Socket.getnameinfo(["AF_UNIX", 80, "0.0.0.0"]) + }.should.raise(Socket::ResolutionError) { |e| + [Socket::EAI_FAMILY, Socket::EAI_FAIL].should.include?(e.error_code) + } + end end describe 'Socket.getnameinfo' do @@ -69,7 +77,7 @@ describe 'Socket.getnameinfo' do end it 'raises SocketError or TypeError when using an invalid String' do - -> { Socket.getnameinfo('cats') }.should raise_error(Exception) { |e| + -> { Socket.getnameinfo('cats') }.should.raise(Exception) { |e| (e.is_a?(SocketError) || e.is_a?(TypeError)).should == true } end @@ -102,7 +110,7 @@ describe 'Socket.getnameinfo' do end it 'raises ArgumentError when using an invalid Array' do - -> { Socket.getnameinfo([family_name]) }.should raise_error(ArgumentError) + -> { Socket.getnameinfo([family_name]) }.should.raise(ArgumentError) end platform_is_not :windows do @@ -122,7 +130,7 @@ describe 'Socket.getnameinfo' do describe 'without custom flags' do it 'returns an Array containing the hostname and service name' do array = Socket.getnameinfo(@addr) - array.should be_an_instance_of(Array) + array.should.instance_of?(Array) array[0].should == @hostname array[1].should == 'ftp' end @@ -131,7 +139,7 @@ describe 'Socket.getnameinfo' do addr = [family_name, 21, ip_address, nil] array = Socket.getnameinfo(addr) - array.should be_an_instance_of(Array) + array.should.instance_of?(Array) array[0].should == @hostname array[1].should == 'ftp' end diff --git a/spec/ruby/library/socket/socket/getservbyname_spec.rb b/spec/ruby/library/socket/socket/getservbyname_spec.rb index d361e619f2..4a88444fff 100644 --- a/spec/ruby/library/socket/socket/getservbyname_spec.rb +++ b/spec/ruby/library/socket/socket/getservbyname_spec.rb @@ -27,6 +27,6 @@ describe "Socket#getservbyname" do end it "raises a SocketError when the service or port is invalid" do - -> { Socket.getservbyname('invalid') }.should raise_error(SocketError) + -> { Socket.getservbyname('invalid') }.should.raise(SocketError) end end diff --git a/spec/ruby/library/socket/socket/getservbyport_spec.rb b/spec/ruby/library/socket/socket/getservbyport_spec.rb index 563c592b54..7e4b75fa52 100644 --- a/spec/ruby/library/socket/socket/getservbyport_spec.rb +++ b/spec/ruby/library/socket/socket/getservbyport_spec.rb @@ -18,6 +18,6 @@ describe 'Socket.getservbyport' do end it 'raises SocketError for an unknown port number' do - -> { Socket.getservbyport(0) }.should raise_error(SocketError) + -> { Socket.getservbyport(0) }.should.raise(SocketError) end end diff --git a/spec/ruby/library/socket/socket/initialize_spec.rb b/spec/ruby/library/socket/socket/initialize_spec.rb index f8337bcaa5..a8fb1c61fa 100644 --- a/spec/ruby/library/socket/socket/initialize_spec.rb +++ b/spec/ruby/library/socket/socket/initialize_spec.rb @@ -13,7 +13,7 @@ describe 'Socket#initialize' do it 'returns a Socket' do @socket = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM) - @socket.should be_an_instance_of(Socket) + @socket.should.instance_of?(Socket) end end @@ -21,7 +21,7 @@ describe 'Socket#initialize' do it 'returns a Socket' do @socket = Socket.new(:INET, :STREAM) - @socket.should be_an_instance_of(Socket) + @socket.should.instance_of?(Socket) end end @@ -29,7 +29,7 @@ describe 'Socket#initialize' do it 'returns a Socket' do @socket = Socket.new('INET', 'STREAM') - @socket.should be_an_instance_of(Socket) + @socket.should.instance_of?(Socket) end end @@ -43,7 +43,7 @@ describe 'Socket#initialize' do @socket = Socket.new(family, type) - @socket.should be_an_instance_of(Socket) + @socket.should.instance_of?(Socket) end it 'raises TypeError when the #to_str method does not return a String' do @@ -53,7 +53,7 @@ describe 'Socket#initialize' do family.stub!(:to_str).and_return(Socket::AF_INET) type.stub!(:to_str).and_return(Socket::SOCK_STREAM) - -> { Socket.new(family, type) }.should raise_error(TypeError) + -> { Socket.new(family, type) }.should.raise(TypeError) end end @@ -61,11 +61,11 @@ describe 'Socket#initialize' do it 'returns a Socket when using an Integer' do @socket = Socket.new(:INET, :STREAM, Socket::IPPROTO_TCP) - @socket.should be_an_instance_of(Socket) + @socket.should.instance_of?(Socket) end it 'raises TypeError when using a Symbol' do - -> { Socket.new(:INET, :STREAM, :TCP) }.should raise_error(TypeError) + -> { Socket.new(:INET, :STREAM, :TCP) }.should.raise(TypeError) end end @@ -82,6 +82,6 @@ describe 'Socket#initialize' do it "sets the socket to binary mode" do @socket = Socket.new(:INET, :STREAM) - @socket.binmode?.should be_true + @socket.binmode?.should == true end end diff --git a/spec/ruby/library/socket/socket/ip_address_list_spec.rb b/spec/ruby/library/socket/socket/ip_address_list_spec.rb index f97c2d7f85..2c4e008af1 100644 --- a/spec/ruby/library/socket/socket/ip_address_list_spec.rb +++ b/spec/ruby/library/socket/socket/ip_address_list_spec.rb @@ -2,7 +2,7 @@ require_relative '../spec_helper' describe 'Socket.ip_address_list' do it 'returns an Array' do - Socket.ip_address_list.should be_an_instance_of(Array) + Socket.ip_address_list.should.instance_of?(Array) end describe 'the returned Array' do @@ -11,12 +11,12 @@ describe 'Socket.ip_address_list' do end it 'is not empty' do - @array.should_not be_empty + @array.should_not.empty? end it 'contains Addrinfo objects' do @array.each do |klass| - klass.should be_an_instance_of(Addrinfo) + klass.should.instance_of?(Addrinfo) end end end @@ -28,8 +28,8 @@ describe 'Socket.ip_address_list' do it 'has a non-empty IP address' do @array.each do |addr| - addr.ip_address.should be_an_instance_of(String) - addr.ip_address.should_not be_empty + addr.ip_address.should.instance_of?(String) + addr.ip_address.should_not.empty? end end diff --git a/spec/ruby/library/socket/socket/listen_spec.rb b/spec/ruby/library/socket/socket/listen_spec.rb index 4d2aedab19..7986a0225c 100644 --- a/spec/ruby/library/socket/socket/listen_spec.rb +++ b/spec/ruby/library/socket/socket/listen_spec.rb @@ -7,7 +7,7 @@ describe "Socket#listen" do end after :each do - @socket.closed?.should be_false + @socket.closed?.should == false @socket.close end @@ -35,7 +35,7 @@ describe 'Socket#listen' do end it 'raises Errno::EOPNOTSUPP or Errno::EACCES' do - -> { @server.listen(1) }.should raise_error { |e| + -> { @server.listen(1) }.should.raise { |e| [Errno::EOPNOTSUPP, Errno::EACCES].should.include?(e.class) } end @@ -59,7 +59,7 @@ describe 'Socket#listen' do end it "raises when the given argument can't be coerced to an Integer" do - -> { @server.listen('cats') }.should raise_error(TypeError) + -> { @server.listen('cats') }.should.raise(TypeError) end end end diff --git a/spec/ruby/library/socket/socket/local_address_spec.rb b/spec/ruby/library/socket/socket/local_address_spec.rb index 3687f93a0c..86b053fc3e 100644 --- a/spec/ruby/library/socket/socket/local_address_spec.rb +++ b/spec/ruby/library/socket/socket/local_address_spec.rb @@ -10,7 +10,7 @@ describe 'Socket#local_address' do end it 'returns an Addrinfo' do - @sock.local_address.should be_an_instance_of(Addrinfo) + @sock.local_address.should.instance_of?(Addrinfo) end describe 'the returned Addrinfo' do 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 ef2a2d4ba9..17a737cacd 100644 --- a/spec/ruby/library/socket/socket/pack_sockaddr_in_spec.rb +++ b/spec/ruby/library/socket/socket/pack_sockaddr_in_spec.rb @@ -1,7 +1,7 @@ require_relative '../spec_helper' -require_relative '../fixtures/classes' -require_relative '../shared/pack_sockaddr' describe "Socket.pack_sockaddr_in" do - it_behaves_like :socket_pack_sockaddr_in, :pack_sockaddr_in + it "is an alias of Socket.sockaddr_in" do + Socket.method(:pack_sockaddr_in).should == Socket.method(:sockaddr_in) + end end diff --git a/spec/ruby/library/socket/socket/pack_sockaddr_un_spec.rb b/spec/ruby/library/socket/socket/pack_sockaddr_un_spec.rb index 1ee0bc6157..34d4fc1f51 100644 --- a/spec/ruby/library/socket/socket/pack_sockaddr_un_spec.rb +++ b/spec/ruby/library/socket/socket/pack_sockaddr_un_spec.rb @@ -1,7 +1,7 @@ require_relative '../spec_helper' -require_relative '../fixtures/classes' -require_relative '../shared/pack_sockaddr' -describe "Socket#pack_sockaddr_un" do - it_behaves_like :socket_pack_sockaddr_un, :pack_sockaddr_un +describe "Socket.pack_sockaddr_un" do + it "is an alias of Socket.sockaddr_un" do + Socket.method(:pack_sockaddr_un).should == Socket.method(:sockaddr_un) + end end diff --git a/spec/ruby/library/socket/socket/pair_spec.rb b/spec/ruby/library/socket/socket/pair_spec.rb index 8dd470a95e..91317a8d07 100644 --- a/spec/ruby/library/socket/socket/pair_spec.rb +++ b/spec/ruby/library/socket/socket/pair_spec.rb @@ -1,7 +1,141 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -require_relative '../shared/socketpair' describe "Socket.pair" do - it_behaves_like :socket_socketpair, :pair + platform_is_not :windows do + it "ensures the returned sockets are connected" do + s1, s2 = Socket.pair(Socket::AF_UNIX, 1, 0) + s1.puts("test") + s2.gets.should == "test\n" + s1.close + s2.close + end + + it "returns an array of two sockets" do + begin + s1, s2 = Socket.pair(:UNIX, :STREAM) + + s1.should.instance_of?(Socket) + s2.should.instance_of?(Socket) + ensure + s1.close + s2.close + end + end + + describe 'using an Integer as the 1st and 2nd argument' do + it 'returns two Socket objects' do + s1, s2 = Socket.pair(Socket::AF_UNIX, Socket::SOCK_STREAM) + + s1.should.instance_of?(Socket) + s2.should.instance_of?(Socket) + s1.close + s2.close + end + end + + describe 'using a Symbol as the 1st and 2nd argument' do + it 'returns two Socket objects' do + s1, s2 = Socket.pair(:UNIX, :STREAM) + + s1.should.instance_of?(Socket) + s2.should.instance_of?(Socket) + s1.close + s2.close + end + + it 'raises SocketError for an unknown address family' do + -> { Socket.pair(:CATS, :STREAM) }.should.raise(SocketError) + end + + it 'raises SocketError for an unknown socket type' do + -> { Socket.pair(:UNIX, :CATS) }.should.raise(SocketError) + end + end + + describe 'using a String as the 1st and 2nd argument' do + it 'returns two Socket objects' do + s1, s2 = Socket.pair('UNIX', 'STREAM') + + s1.should.instance_of?(Socket) + s2.should.instance_of?(Socket) + s1.close + s2.close + end + + it 'raises SocketError for an unknown address family' do + -> { Socket.pair('CATS', 'STREAM') }.should.raise(SocketError) + end + + it 'raises SocketError for an unknown socket type' do + -> { Socket.pair('UNIX', 'CATS') }.should.raise(SocketError) + end + end + + describe 'using an object that responds to #to_str as the 1st and 2nd argument' do + it 'returns two Socket objects' do + family = mock(:family) + type = mock(:type) + + family.stub!(:to_str).and_return('UNIX') + type.stub!(:to_str).and_return('STREAM') + + s1, s2 = Socket.pair(family, type) + + s1.should.instance_of?(Socket) + s2.should.instance_of?(Socket) + s1.close + s2.close + end + + it 'raises TypeError when #to_str does not return a String' do + family = mock(:family) + type = mock(:type) + + family.stub!(:to_str).and_return(Socket::AF_UNIX) + type.stub!(:to_str).and_return(Socket::SOCK_STREAM) + + -> { Socket.pair(family, type) }.should.raise(TypeError) + end + + it 'raises SocketError for an unknown address family' do + family = mock(:family) + type = mock(:type) + + family.stub!(:to_str).and_return('CATS') + type.stub!(:to_str).and_return('STREAM') + + -> { Socket.pair(family, type) }.should.raise(SocketError) + end + + it 'raises SocketError for an unknown socket type' do + family = mock(:family) + type = mock(:type) + + family.stub!(:to_str).and_return('UNIX') + type.stub!(:to_str).and_return('CATS') + + -> { Socket.pair(family, type) }.should.raise(SocketError) + end + end + + it 'accepts a custom protocol as an Integer as the 3rd argument' do + s1, s2 = Socket.pair(:UNIX, :STREAM, Socket::IPPROTO_IP) + s1.should.instance_of?(Socket) + s2.should.instance_of?(Socket) + s1.close + s2.close + end + + it 'connects the returned Socket objects' do + s1, s2 = Socket.pair(:UNIX, :STREAM) + begin + s1.write('hello') + s2.recv(5).should == 'hello' + ensure + s1.close + s2.close + end + end + end end diff --git a/spec/ruby/library/socket/socket/recvfrom_nonblock_spec.rb b/spec/ruby/library/socket/socket/recvfrom_nonblock_spec.rb index 01b42bcc52..ab29435a1d 100644 --- a/spec/ruby/library/socket/socket/recvfrom_nonblock_spec.rb +++ b/spec/ruby/library/socket/socket/recvfrom_nonblock_spec.rb @@ -16,7 +16,7 @@ describe 'Socket#recvfrom_nonblock' do platform_is_not :windows do describe 'using an unbound socket' do it 'raises IO::WaitReadable' do - -> { @server.recvfrom_nonblock(1) }.should raise_error(IO::WaitReadable) + -> { @server.recvfrom_nonblock(1) }.should.raise(IO::WaitReadable) end end end @@ -29,7 +29,7 @@ describe 'Socket#recvfrom_nonblock' do describe 'without any data available' do it 'raises IO::WaitReadable' do - -> { @server.recvfrom_nonblock(1) }.should raise_error(IO::WaitReadable) + -> { @server.recvfrom_nonblock(1) }.should.raise(IO::WaitReadable) end it 'returns :wait_readable with exception: false' do @@ -47,7 +47,7 @@ describe 'Socket#recvfrom_nonblock' do IO.select([@server]) ret = @server.recvfrom_nonblock(1) - ret.should be_an_instance_of(Array) + ret.should.instance_of?(Array) ret.length.should == 2 end end @@ -98,7 +98,7 @@ describe 'Socket#recvfrom_nonblock' do end it 'contains an Addrinfo at index 1' do - @array[1].should be_an_instance_of(Addrinfo) + @array[1].should.instance_of?(Addrinfo) end end @@ -158,61 +158,30 @@ describe 'Socket#recvfrom_nonblock' do @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 + it "returns nil on a closed stream socket" do + ready = false - t = Thread.new do - client, _ = @server.accept + 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 + Thread.pass while !ready + begin + client.recvfrom_nonblock(10) + rescue IO::EAGAINWaitReadable + retry 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 == "" + ensure + client.close if client end - end - ruby_version_is "3.3" do - it "returns nil on a closed stream socket" do - ready = false + Thread.pass while t.status and t.status != "sleep" + t.status.should_not == nil - t = Thread.new do - client, _ = @server.accept + @client.connect(@server_addr) + @client.close + ready = true - 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 + t.value.should == nil end end end diff --git a/spec/ruby/library/socket/socket/recvfrom_spec.rb b/spec/ruby/library/socket/socket/recvfrom_spec.rb index 6ba39ffcaf..0f319fc47c 100644 --- a/spec/ruby/library/socket/socket/recvfrom_spec.rb +++ b/spec/ruby/library/socket/socket/recvfrom_spec.rb @@ -39,7 +39,7 @@ describe 'Socket#recvfrom' do it 'returns an Array containing the data and an Addrinfo' do ret = @server.recvfrom(1) - ret.should be_an_instance_of(Array) + ret.should.instance_of?(Array) ret.length.should == 2 end @@ -53,7 +53,7 @@ describe 'Socket#recvfrom' do end it 'contains an Addrinfo at index 1' do - @array[1].should be_an_instance_of(Addrinfo) + @array[1].should.instance_of?(Addrinfo) end end @@ -111,43 +111,21 @@ describe 'Socket#recvfrom' do @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 == "" + 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 - 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 + Thread.pass while t.status and t.status != "sleep" + t.status.should_not == nil - @client.connect(@server_addr) - @client.close + @client.connect(@server_addr) + @client.close - t.value.should be_nil - end + t.value.should == nil end end diff --git a/spec/ruby/library/socket/socket/remote_address_spec.rb b/spec/ruby/library/socket/socket/remote_address_spec.rb index 24d60d7f58..f72ec50ed7 100644 --- a/spec/ruby/library/socket/socket/remote_address_spec.rb +++ b/spec/ruby/library/socket/socket/remote_address_spec.rb @@ -22,7 +22,7 @@ describe 'Socket#remote_address' do end it 'returns an Addrinfo' do - @client.remote_address.should be_an_instance_of(Addrinfo) + @client.remote_address.should.instance_of?(Addrinfo) end describe 'the returned Addrinfo' do diff --git a/spec/ruby/library/socket/socket/sockaddr_in_spec.rb b/spec/ruby/library/socket/socket/sockaddr_in_spec.rb index 8ee956ac26..9d3367cd69 100644 --- a/spec/ruby/library/socket/socket/sockaddr_in_spec.rb +++ b/spec/ruby/library/socket/socket/sockaddr_in_spec.rb @@ -1,7 +1,49 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -require_relative '../shared/pack_sockaddr' -describe "Socket#sockaddr_in" do - it_behaves_like :socket_pack_sockaddr_in, :sockaddr_in +describe "Socket.sockaddr_in" do + it "packs and unpacks" do + sockaddr_in = Socket.sockaddr_in(0, nil) + port, addr = Socket.unpack_sockaddr_in(sockaddr_in) + ["127.0.0.1", "::1"].include?(addr).should == true + port.should == 0 + + sockaddr_in = Socket.sockaddr_in(0, '') + Socket.unpack_sockaddr_in(sockaddr_in).should == [0, '0.0.0.0'] + + sockaddr_in = Socket.sockaddr_in(80, '127.0.0.1') + Socket.unpack_sockaddr_in(sockaddr_in).should == [80, '127.0.0.1'] + + sockaddr_in = Socket.sockaddr_in('80', '127.0.0.1') + Socket.unpack_sockaddr_in(sockaddr_in).should == [80, '127.0.0.1'] + + sockaddr_in = Socket.sockaddr_in(nil, '127.0.0.1') + Socket.unpack_sockaddr_in(sockaddr_in).should == [0, '127.0.0.1'] + + sockaddr_in = Socket.sockaddr_in(80, Socket::INADDR_ANY) + Socket.unpack_sockaddr_in(sockaddr_in).should == [80, '0.0.0.0'] + end + + it 'resolves the service name to a port' do + sockaddr_in = Socket.sockaddr_in('http', '127.0.0.1') + Socket.unpack_sockaddr_in(sockaddr_in).should == [80, '127.0.0.1'] + end + + describe 'using an IPv4 address' do + it 'returns a String of 16 bytes' do + str = Socket.sockaddr_in(80, '127.0.0.1') + + str.should.instance_of?(String) + str.bytesize.should == 16 + end + end + + describe 'using an IPv6 address' do + it 'returns a String of 28 bytes' do + str = Socket.sockaddr_in(80, '::1') + + str.should.instance_of?(String) + str.bytesize.should == 28 + end + end end diff --git a/spec/ruby/library/socket/socket/sockaddr_un_spec.rb b/spec/ruby/library/socket/socket/sockaddr_un_spec.rb index 8922ff4d6d..548dc526ff 100644 --- a/spec/ruby/library/socket/socket/sockaddr_un_spec.rb +++ b/spec/ruby/library/socket/socket/sockaddr_un_spec.rb @@ -1,7 +1,47 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -require_relative '../shared/pack_sockaddr' -describe "Socket#sockaddr_un" do - it_behaves_like :socket_pack_sockaddr_un, :sockaddr_un +describe "Socket.sockaddr_un" do + it 'should be idempotent' do + bytes = Socket.sockaddr_un('/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.sockaddr_un('/tmp/s') + Socket.unpack_sockaddr_un(sockaddr_un).should == '/tmp/s' + end + + it "handles correctly paths with multibyte chars" do + sockaddr_un = Socket.sockaddr_un('/home/вася/sock') + path = Socket.unpack_sockaddr_un(sockaddr_un).encode('UTF-8', 'UTF-8') + path.should == '/home/вася/sock' + end + + platform_is :linux do + it 'returns a String of 110 bytes' do + str = Socket.sockaddr_un('/tmp/test.sock') + + str.should.instance_of?(String) + str.bytesize.should == 110 + end + end + + platform_is :bsd do + it 'returns a String of 106 bytes' do + str = Socket.sockaddr_un('/tmp/test.sock') + + str.should.instance_of?(String) + str.bytesize.should == 106 + end + end + + platform_is_not :aix do + it "raises ArgumentError for paths that are too long" do + # AIX doesn't raise error + long_path = 'a' * 110 + -> { Socket.sockaddr_un(long_path) }.should.raise(ArgumentError) + end + end end diff --git a/spec/ruby/library/socket/socket/socketpair_spec.rb b/spec/ruby/library/socket/socket/socketpair_spec.rb index 551c376d49..191fb358cf 100644 --- a/spec/ruby/library/socket/socket/socketpair_spec.rb +++ b/spec/ruby/library/socket/socket/socketpair_spec.rb @@ -1,7 +1,7 @@ require_relative '../spec_helper' -require_relative '../fixtures/classes' -require_relative '../shared/socketpair' describe "Socket.socketpair" do - it_behaves_like :socket_socketpair, :socketpair + it "is an alias of Socket.pair" do + Socket.method(:socketpair).should == Socket.method(:pair) + end end diff --git a/spec/ruby/library/socket/socket/sysaccept_spec.rb b/spec/ruby/library/socket/socket/sysaccept_spec.rb index 92ac21124e..3e7078f745 100644 --- a/spec/ruby/library/socket/socket/sysaccept_spec.rb +++ b/spec/ruby/library/socket/socket/sysaccept_spec.rb @@ -15,7 +15,7 @@ describe 'Socket#sysaccept' do platform_is :linux do # hangs on other platforms describe 'using an unbound socket' do it 'raises Errno::EINVAL' do - -> { @server.sysaccept }.should raise_error(Errno::EINVAL) + -> { @server.sysaccept }.should.raise(Errno::EINVAL) end end @@ -25,7 +25,7 @@ describe 'Socket#sysaccept' do end it 'raises Errno::EINVAL' do - -> { @server.sysaccept }.should raise_error(Errno::EINVAL) + -> { @server.sysaccept }.should.raise(Errno::EINVAL) end end end @@ -59,7 +59,7 @@ describe 'Socket#sysaccept' do @client.connect(@server_addr) - thread.value.should be_an_instance_of(Array) + thread.value.should.instance_of?(Array) end end @@ -76,8 +76,8 @@ describe 'Socket#sysaccept' do it 'returns an Array containing an Integer and an Addrinfo' do @fd, addrinfo = @server.sysaccept - @fd.should be_kind_of(Integer) - addrinfo.should be_an_instance_of(Addrinfo) + @fd.should.is_a?(Integer) + addrinfo.should.instance_of?(Addrinfo) end it 'returns a new file descriptor' do diff --git a/spec/ruby/library/socket/socket/tcp_server_loop_spec.rb b/spec/ruby/library/socket/socket/tcp_server_loop_spec.rb index a46c6df5c6..4e39d01d72 100644 --- a/spec/ruby/library/socket/socket/tcp_server_loop_spec.rb +++ b/spec/ruby/library/socket/socket/tcp_server_loop_spec.rb @@ -47,8 +47,8 @@ describe 'Socket.tcp_server_loop' do # complete. thread.join - @sock.should be_an_instance_of(Socket) - addr.should be_an_instance_of(Addrinfo) + @sock.should.instance_of?(Socket) + addr.should.instance_of?(Addrinfo) end end end diff --git a/spec/ruby/library/socket/socket/tcp_server_sockets_spec.rb b/spec/ruby/library/socket/socket/tcp_server_sockets_spec.rb index bd496d3015..b6cdb3c583 100644 --- a/spec/ruby/library/socket/socket/tcp_server_sockets_spec.rb +++ b/spec/ruby/library/socket/socket/tcp_server_sockets_spec.rb @@ -13,16 +13,16 @@ describe 'Socket.tcp_server_sockets' do it 'returns an Array of Socket objects' do @sockets = Socket.tcp_server_sockets(0) - @sockets.should be_an_instance_of(Array) - @sockets[0].should be_an_instance_of(Socket) + @sockets.should.instance_of?(Array) + @sockets[0].should.instance_of?(Socket) end end describe 'with a block' do it 'yields the sockets to the supplied block' do Socket.tcp_server_sockets(0) do |sockets| - sockets.should be_an_instance_of(Array) - sockets[0].should be_an_instance_of(Socket) + sockets.should.instance_of?(Array) + sockets[0].should.instance_of?(Socket) end end diff --git a/spec/ruby/library/socket/socket/tcp_spec.rb b/spec/ruby/library/socket/socket/tcp_spec.rb index faf020b1ea..cc3c9381c7 100644 --- a/spec/ruby/library/socket/socket/tcp_spec.rb +++ b/spec/ruby/library/socket/socket/tcp_spec.rb @@ -22,12 +22,12 @@ describe 'Socket.tcp' do it 'returns a Socket when no block is given' do @client = Socket.tcp(@host, @port) - @client.should be_an_instance_of(Socket) + @client.should.instance_of?(Socket) end it 'yields the Socket when a block is given' do Socket.tcp(@host, @port) do |socket| - socket.should be_an_instance_of(Socket) + socket.should.instance_of?(Socket) end end @@ -51,20 +51,38 @@ describe 'Socket.tcp' do it 'raises ArgumentError when 6 arguments are provided' do -> { Socket.tcp(@host, @port, @host, 0, {:connect_timeout => 1}, 10) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) end it 'connects to the server' do @client = Socket.tcp(@host, @port) - @client.write('hello') - connection, _ = @server.accept - begin connection.recv(5).should == 'hello' ensure connection.close end end + + ruby_version_is "4.0" do + it 'connects to the server when passed open_timeout argument' do + @client = Socket.tcp(@host, @port, open_timeout: 60) + @client.write('open_timeout') + connection, _ = @server.accept + begin + connection.recv(12).should == 'open_timeout' + ensure + connection.close + end + end + + it 'raises Errno::ETIMEDOUT with :open_timeout when no server is listening on the given address' do + -> { + Socket.tcp("192.0.2.1", 80, open_timeout: 0) + }.should.raise(Errno::ETIMEDOUT) + rescue Errno::ENETUNREACH + skip "all network interfaces down" + end + end end diff --git a/spec/ruby/library/socket/socket/udp_server_loop_on_spec.rb b/spec/ruby/library/socket/socket/udp_server_loop_on_spec.rb index cb8c5c5587..9197509f1f 100644 --- a/spec/ruby/library/socket/socket/udp_server_loop_on_spec.rb +++ b/spec/ruby/library/socket/socket/udp_server_loop_on_spec.rb @@ -41,7 +41,7 @@ describe 'Socket.udp_server_loop_on' do end msg.should == 'hello' - src.should be_an_instance_of(Socket::UDPSource) + src.should.instance_of?(Socket::UDPSource) end end 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 cd22ea56cf..d44d522c20 100644 --- a/spec/ruby/library/socket/socket/udp_server_loop_spec.rb +++ b/spec/ruby/library/socket/socket/udp_server_loop_spec.rb @@ -53,7 +53,7 @@ describe 'Socket.udp_server_loop' do thread.join msg.should == 'hello' - src.should be_an_instance_of(Socket::UDPSource) + src.should.instance_of?(Socket::UDPSource) end end end diff --git a/spec/ruby/library/socket/socket/udp_server_recv_spec.rb b/spec/ruby/library/socket/socket/udp_server_recv_spec.rb index 47ed74bc03..34e2280558 100644 --- a/spec/ruby/library/socket/socket/udp_server_recv_spec.rb +++ b/spec/ruby/library/socket/socket/udp_server_recv_spec.rb @@ -30,6 +30,6 @@ describe 'Socket.udp_server_recv' do end msg.should == 'hello' - src.should be_an_instance_of(Socket::UDPSource) + src.should.instance_of?(Socket::UDPSource) end end diff --git a/spec/ruby/library/socket/socket/udp_server_sockets_spec.rb b/spec/ruby/library/socket/socket/udp_server_sockets_spec.rb index f8be672612..cb357977d6 100644 --- a/spec/ruby/library/socket/socket/udp_server_sockets_spec.rb +++ b/spec/ruby/library/socket/socket/udp_server_sockets_spec.rb @@ -13,16 +13,16 @@ describe 'Socket.udp_server_sockets' do it 'returns an Array of Socket objects' do @sockets = Socket.udp_server_sockets(0) - @sockets.should be_an_instance_of(Array) - @sockets[0].should be_an_instance_of(Socket) + @sockets.should.instance_of?(Array) + @sockets[0].should.instance_of?(Socket) end end describe 'with a block' do it 'yields the sockets to the supplied block' do Socket.udp_server_sockets(0) do |sockets| - sockets.should be_an_instance_of(Array) - sockets[0].should be_an_instance_of(Socket) + sockets.should.instance_of?(Array) + sockets[0].should.instance_of?(Socket) 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..9d35a995bc 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.instance_of?(Socket) + addr.should.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..da9671bf8c 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.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.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.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..87f4938871 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.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.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..35d46b0fd0 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(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(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..85a941cfc2 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(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(ArgumentError) end end diff --git a/spec/ruby/library/socket/spec_helper.rb b/spec/ruby/library/socket/spec_helper.rb index 1121542dd5..86f3a61086 100644 --- a/spec/ruby/library/socket/spec_helper.rb +++ b/spec/ruby/library/socket/spec_helper.rb @@ -1,13 +1,14 @@ 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) -MSpec.enable_feature :ipv6_pktinfo if Socket.const_defined?(:IPV6_PKTINFO) -MSpec.enable_feature :ip_mtu if Socket.const_defined?(:IP_MTU) -MSpec.enable_feature :ipv6_nexthop if Socket.const_defined?(:IPV6_NEXTHOP) -MSpec.enable_feature :tcp_info if Socket.const_defined?(:TCP_INFO) -MSpec.enable_feature :ancillary_data if Socket.const_defined?(:AncillaryData) +# We force enable all features on Linux because anyway Linux implements all these features, +# and we want a constant number of spec examples across Ruby implementations, even if they don't define these constants. +MSpec.enable_feature :sock_packet if platform_is(:linux) || Socket.const_defined?(:SOCK_PACKET) +MSpec.enable_feature :udp_cork if platform_is(:linux) || Socket.const_defined?(:UDP_CORK) +MSpec.enable_feature :tcp_cork if platform_is(:linux) || Socket.const_defined?(:TCP_CORK) +MSpec.enable_feature :pktinfo if platform_is(:linux) || Socket.const_defined?(:IP_PKTINFO) +MSpec.enable_feature :ipv6_pktinfo if platform_is(:linux) || Socket.const_defined?(:IPV6_PKTINFO) +MSpec.enable_feature :ip_mtu if platform_is(:linux) || Socket.const_defined?(:IP_MTU) +MSpec.enable_feature :ipv6_nexthop if platform_is(:linux) || Socket.const_defined?(:IPV6_NEXTHOP) +MSpec.enable_feature :tcp_info if platform_is(:linux) || Socket.const_defined?(:TCP_INFO) +MSpec.enable_feature :ancillary_data if platform_is(:linux) || Socket.const_defined?(:AncillaryData) diff --git a/spec/ruby/library/socket/tcpserver/accept_nonblock_spec.rb b/spec/ruby/library/socket/tcpserver/accept_nonblock_spec.rb index 91f6a327f0..ac08fe37c6 100644 --- a/spec/ruby/library/socket/tcpserver/accept_nonblock_spec.rb +++ b/spec/ruby/library/socket/tcpserver/accept_nonblock_spec.rb @@ -15,7 +15,7 @@ describe "Socket::TCPServer.accept_nonblock" do @server.listen(5) -> { @server.accept_nonblock - }.should raise_error(IO::WaitReadable) + }.should.raise(IO::WaitReadable) c = TCPSocket.new("127.0.0.1", @port) IO.select([@server]) @@ -25,7 +25,7 @@ describe "Socket::TCPServer.accept_nonblock" do port.should == @port address.should == "127.0.0.1" - s.should be_kind_of(TCPSocket) + s.should.is_a?(TCPSocket) c.close s.close @@ -33,12 +33,12 @@ describe "Socket::TCPServer.accept_nonblock" do it "raises an IOError if the socket is closed" do @server.close - -> { @server.accept }.should raise_error(IOError) + -> { @server.accept }.should.raise(IOError) end describe 'without a connected client' do it 'raises error' do - -> { @server.accept_nonblock }.should raise_error(IO::WaitReadable) + -> { @server.accept_nonblock }.should.raise(IO::WaitReadable) end it 'returns :wait_readable in exceptionless mode' do @@ -59,7 +59,7 @@ describe 'TCPServer#accept_nonblock' do describe 'without a connected client' do it 'raises IO::WaitReadable' do - -> { @server.accept_nonblock }.should raise_error(IO::WaitReadable) + -> { @server.accept_nonblock }.should.raise(IO::WaitReadable) end end @@ -77,7 +77,7 @@ describe 'TCPServer#accept_nonblock' do it 'returns a TCPSocket' do IO.select([@server]) @socket = @server.accept_nonblock - @socket.should be_an_instance_of(TCPSocket) + @socket.should.instance_of?(TCPSocket) end end end diff --git a/spec/ruby/library/socket/tcpserver/accept_spec.rb b/spec/ruby/library/socket/tcpserver/accept_spec.rb index d8892cd5f0..f2aa0bf8e1 100644 --- a/spec/ruby/library/socket/tcpserver/accept_spec.rb +++ b/spec/ruby/library/socket/tcpserver/accept_spec.rb @@ -15,7 +15,7 @@ describe "TCPServer#accept" do data = nil t = Thread.new do client = @server.accept - client.should be_kind_of(TCPSocket) + client.should.is_a?(TCPSocket) data = client.read(5) client << "goodbye" client.close @@ -50,7 +50,7 @@ describe "TCPServer#accept" do t = Thread.new { -> { @server.accept - }.should raise_error(Exception, "interrupted") + }.should.raise(Exception, "interrupted") } Thread.pass while t.status and t.status != "sleep" @@ -80,7 +80,7 @@ describe "TCPServer#accept" do it "raises an IOError if the socket is closed" do @server.close - -> { @server.accept }.should raise_error(IOError) + -> { @server.accept }.should.raise(IOError) end end @@ -112,7 +112,7 @@ describe 'TCPServer#accept' do it 'returns a TCPSocket' do @socket = @server.accept - @socket.should be_an_instance_of(TCPSocket) + @socket.should.instance_of?(TCPSocket) end platform_is_not :windows do diff --git a/spec/ruby/library/socket/tcpserver/gets_spec.rb b/spec/ruby/library/socket/tcpserver/gets_spec.rb index 417976d737..72a72fa2dc 100644 --- a/spec/ruby/library/socket/tcpserver/gets_spec.rb +++ b/spec/ruby/library/socket/tcpserver/gets_spec.rb @@ -11,6 +11,6 @@ describe "TCPServer#gets" do end it "raises Errno::ENOTCONN on gets" do - -> { @server.gets }.should raise_error(Errno::ENOTCONN) + -> { @server.gets }.should.raise(Errno::ENOTCONN) end end diff --git a/spec/ruby/library/socket/tcpserver/initialize_spec.rb b/spec/ruby/library/socket/tcpserver/initialize_spec.rb index 4ddd1f465f..517b014edc 100644 --- a/spec/ruby/library/socket/tcpserver/initialize_spec.rb +++ b/spec/ruby/library/socket/tcpserver/initialize_spec.rb @@ -12,7 +12,7 @@ describe 'TCPServer#initialize' do end it 'sets the port to the given argument' do - @server.local_address.ip_port.should be_kind_of(Integer) + @server.local_address.ip_port.should.is_a?(Integer) @server.local_address.ip_port.should > 0 end @@ -24,7 +24,7 @@ describe 'TCPServer#initialize' do end it "sets the socket to binmode" do - @server.binmode?.should be_true + @server.binmode?.should == true end end @@ -38,7 +38,7 @@ describe 'TCPServer#initialize' do end it 'sets the port to the given argument' do - @server.local_address.ip_port.should be_kind_of(Integer) + @server.local_address.ip_port.should.is_a?(Integer) @server.local_address.ip_port.should > 0 end @@ -52,7 +52,7 @@ describe 'TCPServer#initialize' do describe 'with a single String argument containing a non numeric value' do it 'raises SocketError' do - -> { TCPServer.new('cats') }.should raise_error(SocketError) + -> { TCPServer.new('cats') }.should.raise(SocketError) end end @@ -67,7 +67,7 @@ describe 'TCPServer#initialize' do end it 'sets the port to the given port argument' do - @server.local_address.ip_port.should be_kind_of(Integer) + @server.local_address.ip_port.should.is_a?(Integer) @server.local_address.ip_port.should > 0 end @@ -90,7 +90,7 @@ describe 'TCPServer#initialize' do end it 'sets the port to the given port argument' do - @server.local_address.ip_port.should be_kind_of(Integer) + @server.local_address.ip_port.should.is_a?(Integer) @server.local_address.ip_port.should > 0 end diff --git a/spec/ruby/library/socket/tcpserver/listen_spec.rb b/spec/ruby/library/socket/tcpserver/listen_spec.rb index c877fdced6..5b046ef6f7 100644 --- a/spec/ruby/library/socket/tcpserver/listen_spec.rb +++ b/spec/ruby/library/socket/tcpserver/listen_spec.rb @@ -16,7 +16,7 @@ describe 'TCPServer#listen' do end it "raises when the given argument can't be coerced to an Integer" do - -> { @server.listen('cats') }.should raise_error(TypeError) + -> { @server.listen('cats') }.should.raise(TypeError) end end end diff --git a/spec/ruby/library/socket/tcpserver/new_spec.rb b/spec/ruby/library/socket/tcpserver/new_spec.rb index dd1ba676bd..70b8d4352e 100644 --- a/spec/ruby/library/socket/tcpserver/new_spec.rb +++ b/spec/ruby/library/socket/tcpserver/new_spec.rb @@ -10,7 +10,7 @@ describe "TCPServer.new" do @server = TCPServer.new('127.0.0.1', 0) addr = @server.addr addr[0].should == 'AF_INET' - addr[1].should be_kind_of(Integer) + addr[1].should.is_a?(Integer) # on some platforms (Mac), MRI # returns comma at the end. addr[2].should =~ /^#{SocketSpecs.hostname}\b/ @@ -20,7 +20,7 @@ describe "TCPServer.new" do it "binds to localhost and a port with either IPv4 or IPv6" do @server = TCPServer.new(SocketSpecs.hostname, 0) addr = @server.addr - addr[1].should be_kind_of(Integer) + addr[1].should.is_a?(Integer) if addr[0] == 'AF_INET' addr[2].should =~ /^#{SocketSpecs.hostname}\b/ addr[3].should == '127.0.0.1' @@ -34,7 +34,7 @@ describe "TCPServer.new" do @server = TCPServer.new('', 0) addr = @server.addr addr[0].should == 'AF_INET' - addr[1].should be_kind_of(Integer) + addr[1].should.is_a?(Integer) addr[2].should == '0.0.0.0' addr[3].should == '0.0.0.0' end @@ -43,7 +43,7 @@ describe "TCPServer.new" do @server = TCPServer.new('', '0') addr = @server.addr addr[0].should == 'AF_INET' - addr[1].should be_kind_of(Integer) + addr[1].should.is_a?(Integer) addr[2].should == '0.0.0.0' addr[3].should == '0.0.0.0' end @@ -52,7 +52,7 @@ describe "TCPServer.new" do @server = TCPServer.new('', nil) addr = @server.addr addr[0].should == 'AF_INET' - addr[1].should be_kind_of(Integer) + addr[1].should.is_a?(Integer) addr[2].should == '0.0.0.0' addr[3].should == '0.0.0.0' end @@ -61,20 +61,20 @@ describe "TCPServer.new" do @server = TCPServer.new('', '') addr = @server.addr addr[0].should == 'AF_INET' - addr[1].should be_kind_of(Integer) + addr[1].should.is_a?(Integer) addr[2].should == '0.0.0.0' addr[3].should == '0.0.0.0' end it "coerces port to string, then determines port from that number or service name" do - -> { TCPServer.new(SocketSpecs.hostname, Object.new) }.should raise_error(TypeError) + -> { TCPServer.new(SocketSpecs.hostname, Object.new) }.should.raise(TypeError) port = Object.new port.should_receive(:to_str).and_return("0") @server = TCPServer.new(SocketSpecs.hostname, port) addr = @server.addr - addr[1].should be_kind_of(Integer) + addr[1].should.is_a?(Integer) # TODO: This should also accept strings like 'https', but I don't know how to # pick such a service port that will be able to reliably bind... @@ -83,18 +83,18 @@ describe "TCPServer.new" do it "has a single argument form and treats it as a port number" do @server = TCPServer.new(0) addr = @server.addr - addr[1].should be_kind_of(Integer) + addr[1].should.is_a?(Integer) end it "coerces port to a string when it is the only argument" do - -> { TCPServer.new(Object.new) }.should raise_error(TypeError) + -> { TCPServer.new(Object.new) }.should.raise(TypeError) port = Object.new port.should_receive(:to_str).and_return("0") @server = TCPServer.new(port) addr = @server.addr - addr[1].should be_kind_of(Integer) + addr[1].should.is_a?(Integer) end it "does not use the given block and warns to use TCPServer::open" do @@ -104,7 +104,7 @@ describe "TCPServer.new" do end it "raises Errno::EADDRNOTAVAIL when the address is unknown" do - -> { TCPServer.new("1.2.3.4", 0) }.should raise_error(Errno::EADDRNOTAVAIL) + -> { TCPServer.new("1.2.3.4", 0) }.should.raise(Errno::EADDRNOTAVAIL) end # There is no way to make this fail-proof on all machines, because @@ -114,7 +114,7 @@ describe "TCPServer.new" do it "raises a SocketError when the host is unknown" do -> { TCPServer.new("--notavalidname", 0) - }.should raise_error(SocketError) + }.should.raise(SocketError) end end @@ -122,7 +122,7 @@ describe "TCPServer.new" do @server = TCPServer.new('127.0.0.1', 0) -> { @server = TCPServer.new('127.0.0.1', @server.addr[1]) - }.should raise_error(Errno::EADDRINUSE) + }.should.raise(Errno::EADDRINUSE) end platform_is_not :windows, :aix do diff --git a/spec/ruby/library/socket/tcpserver/sysaccept_spec.rb b/spec/ruby/library/socket/tcpserver/sysaccept_spec.rb index bd7d33faf4..ed23bced23 100644 --- a/spec/ruby/library/socket/tcpserver/sysaccept_spec.rb +++ b/spec/ruby/library/socket/tcpserver/sysaccept_spec.rb @@ -21,7 +21,7 @@ describe "TCPServer#sysaccept" do fd = @server.sysaccept - fd.should be_kind_of(Integer) + fd.should.is_a?(Integer) ensure sock.close if sock && !sock.closed? IO.for_fd(fd).close if fd @@ -58,7 +58,7 @@ describe 'TCPServer#sysaccept' do it 'returns a new file descriptor as an Integer' do @fd = @server.sysaccept - @fd.should be_kind_of(Integer) + @fd.should.is_a?(Integer) @fd.should_not == @client.fileno end end diff --git a/spec/ruby/library/socket/tcpsocket/gethostbyname_spec.rb b/spec/ruby/library/socket/tcpsocket/gethostbyname_spec.rb index 5a2c704f35..c6fe007827 100644 --- a/spec/ruby/library/socket/tcpsocket/gethostbyname_spec.rb +++ b/spec/ruby/library/socket/tcpsocket/gethostbyname_spec.rb @@ -10,7 +10,7 @@ describe "TCPSocket.gethostbyname" do end it "returns an array elements of information on the hostname" do - @host_info.should be_kind_of(Array) + @host_info.should.is_a?(Array) end platform_is_not :windows do @@ -20,12 +20,12 @@ describe "TCPSocket.gethostbyname" do it "returns the address type as the third value" do address_type = @host_info[2] - [Socket::AF_INET, Socket::AF_INET6].include?(address_type).should be_true + [Socket::AF_INET, Socket::AF_INET6].include?(address_type).should == true end it "returns the IP address as the fourth value" do ip = @host_info[3] - ["127.0.0.1", "::1"].include?(ip).should be_true + ["127.0.0.1", "::1"].include?(ip).should == true end end @@ -48,14 +48,14 @@ describe "TCPSocket.gethostbyname" do end it "returns any aliases to the address as second value" do - @host_info[1].should be_kind_of(Array) + @host_info[1].should.is_a?(Array) end end describe 'TCPSocket.gethostbyname' do it 'returns an Array' do suppress_warning do - TCPSocket.gethostbyname('127.0.0.1').should be_an_instance_of(Array) + TCPSocket.gethostbyname('127.0.0.1').should.instance_of?(Array) end end @@ -72,11 +72,11 @@ describe 'TCPSocket.gethostbyname' do end it 'includes an array of alternative hostnames as the 2nd value' do - @array[1].should be_an_instance_of(Array) + @array[1].should.instance_of?(Array) end it 'includes the address family as the 3rd value' do - @array[2].should be_kind_of(Integer) + @array[2].should.is_a?(Integer) end it 'includes the IP addresses as all the remaining values' do diff --git a/spec/ruby/library/socket/tcpsocket/initialize_spec.rb b/spec/ruby/library/socket/tcpsocket/initialize_spec.rb index d7feb9751b..a33d0b16ba 100644 --- a/spec/ruby/library/socket/tcpsocket/initialize_spec.rb +++ b/spec/ruby/library/socket/tcpsocket/initialize_spec.rb @@ -31,7 +31,7 @@ describe 'TCPSocket#initialize' do SocketSpecs.each_ip_protocol do |family, ip_address| describe 'when no server is listening on the given address' do it 'raises Errno::ECONNREFUSED' do - -> { TCPSocket.new(ip_address, 666) }.should raise_error(Errno::ECONNREFUSED) + -> { TCPSocket.new(ip_address, 666) }.should.raise(Errno::ECONNREFUSED) end end @@ -48,21 +48,21 @@ describe 'TCPSocket#initialize' do it 'returns a TCPSocket when using an Integer as the port' do @client = TCPSocket.new(ip_address, @port) - @client.should be_an_instance_of(TCPSocket) + @client.should.instance_of?(TCPSocket) end it 'returns a TCPSocket when using a String as the port' do @client = TCPSocket.new(ip_address, @port.to_s) - @client.should be_an_instance_of(TCPSocket) + @client.should.instance_of?(TCPSocket) end it 'raises SocketError when the port number is a non numeric String' do - -> { TCPSocket.new(ip_address, 'cats') }.should raise_error(SocketError) + -> { TCPSocket.new(ip_address, 'cats') }.should.raise(SocketError) end it 'set the socket to binmode' do @client = TCPSocket.new(ip_address, @port) - @client.binmode?.should be_true + @client.binmode?.should == true end it 'connects to the right address' do diff --git a/spec/ruby/library/socket/tcpsocket/local_address_spec.rb b/spec/ruby/library/socket/tcpsocket/local_address_spec.rb index ce66d5ff8f..5dcf741f29 100644 --- a/spec/ruby/library/socket/tcpsocket/local_address_spec.rb +++ b/spec/ruby/library/socket/tcpsocket/local_address_spec.rb @@ -23,7 +23,7 @@ describe 'TCPSocket#local_address' do end it 'returns an Addrinfo' do - @sock.local_address.should be_an_instance_of(Addrinfo) + @sock.local_address.should.instance_of?(Addrinfo) end describe 'the returned Addrinfo' do diff --git a/spec/ruby/library/socket/tcpsocket/remote_address_spec.rb b/spec/ruby/library/socket/tcpsocket/remote_address_spec.rb index eb9dabc075..085d57b3f9 100644 --- a/spec/ruby/library/socket/tcpsocket/remote_address_spec.rb +++ b/spec/ruby/library/socket/tcpsocket/remote_address_spec.rb @@ -23,7 +23,7 @@ describe 'TCPSocket#remote_address' do end it 'returns an Addrinfo' do - @sock.remote_address.should be_an_instance_of(Addrinfo) + @sock.remote_address.should.instance_of?(Addrinfo) end describe 'the returned Addrinfo' do diff --git a/spec/ruby/library/socket/tcpsocket/shared/new.rb b/spec/ruby/library/socket/tcpsocket/shared/new.rb index 5280eb7900..9c15dced4f 100644 --- a/spec/ruby/library/socket/tcpsocket/shared/new.rb +++ b/spec/ruby/library/socket/tcpsocket/shared/new.rb @@ -3,24 +3,33 @@ require_relative '../../fixtures/classes' describe :tcpsocket_new, shared: true do it "requires a hostname and a port as arguments" do - -> { TCPSocket.send(@method) }.should raise_error(ArgumentError) + -> { TCPSocket.send(@method) }.should.raise(ArgumentError) end it "refuses the connection when there is no server to connect to" do -> do TCPSocket.send(@method, SocketSpecs.hostname, SocketSpecs.reserved_unused_port) - end.should raise_error(SystemCallError) {|e| - [Errno::ECONNREFUSED, Errno::EADDRNOTAVAIL].should include(e.class) + end.should.raise(SystemCallError) {|e| + [Errno::ECONNREFUSED, Errno::EADDRNOTAVAIL].should.include?(e.class) } 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) + }.should.raise(IO::TimeoutError) rescue Errno::ENETUNREACH - # In the case all network interfaces down. - # raise_error cannot deal with multiple expected exceptions + skip "all network interfaces down" + end + + ruby_version_is "4.0" do + it 'raises IO::TimeoutError with :open_timeout when no server is listening on the given address' do + -> { + TCPSocket.send(@method, "192.0.2.1", 80, open_timeout: 0) + }.should.raise(IO::TimeoutError) + rescue Errno::ENETUNREACH + skip "all network interfaces down" + end end describe "with a running server" do @@ -39,34 +48,43 @@ describe :tcpsocket_new, shared: true do it "silently ignores 'nil' as the third parameter" do @socket = TCPSocket.send(@method, @hostname, @server.port, nil) - @socket.should be_an_instance_of(TCPSocket) + @socket.should.instance_of?(TCPSocket) end it "connects to a listening server with host and port" do @socket = TCPSocket.send(@method, @hostname, @server.port) - @socket.should be_an_instance_of(TCPSocket) + @socket.should.instance_of?(TCPSocket) end it "connects to a server when passed local_host argument" do @socket = TCPSocket.send(@method, @hostname, @server.port, @hostname) - @socket.should be_an_instance_of(TCPSocket) + @socket.should.instance_of?(TCPSocket) 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) + @socket.should.instance_of?(TCPSocket) end it "has an address once it has connected to a listening server" do @socket = TCPSocket.send(@method, @hostname, @server.port) - @socket.should be_an_instance_of(TCPSocket) + @socket.should.instance_of?(TCPSocket) # TODO: Figure out how to abstract this. You can get AF_INET # from 'Socket.getaddrinfo(hostname, nil)[0][3]' but socket.addr @@ -81,13 +99,20 @@ describe :tcpsocket_new, shared: true do @socket.addr[3].should == SocketSpecs.addr(:ipv6) end - @socket.addr[1].should be_kind_of(Integer) + @socket.addr[1].should.is_a?(Integer) @socket.addr[2].should =~ /^#{@hostname}/ 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) + @socket.should.instance_of?(TCPSocket) + end + + ruby_version_is "4.0" do + it "connects to a server when passed open_timeout argument" do + @socket = TCPSocket.send(@method, @hostname, @server.port, open_timeout: 1) + @socket.should.instance_of?(TCPSocket) + end end end end diff --git a/spec/ruby/library/socket/udpsocket/bind_spec.rb b/spec/ruby/library/socket/udpsocket/bind_spec.rb index 08b386e941..974e701e71 100644 --- a/spec/ruby/library/socket/udpsocket/bind_spec.rb +++ b/spec/ruby/library/socket/udpsocket/bind_spec.rb @@ -12,7 +12,7 @@ describe "UDPSocket#bind" do it "binds the socket to a port" do @socket.bind(SocketSpecs.hostname, 0) - @socket.addr[1].should be_kind_of(Integer) + @socket.addr[1].should.is_a?(Integer) end it "raises Errno::EINVAL when already bound" do @@ -20,7 +20,7 @@ describe "UDPSocket#bind" do -> { @socket.bind(SocketSpecs.hostname, @socket.addr[1]) - }.should raise_error(Errno::EINVAL) + }.should.raise(Errno::EINVAL) end it "receives a hostname and a port" do diff --git a/spec/ruby/library/socket/udpsocket/initialize_spec.rb b/spec/ruby/library/socket/udpsocket/initialize_spec.rb index ecf0043c10..c040187400 100644 --- a/spec/ruby/library/socket/udpsocket/initialize_spec.rb +++ b/spec/ruby/library/socket/udpsocket/initialize_spec.rb @@ -7,27 +7,27 @@ describe 'UDPSocket#initialize' do it 'initializes a new UDPSocket' do @socket = UDPSocket.new - @socket.should be_an_instance_of(UDPSocket) + @socket.should.instance_of?(UDPSocket) end it 'initializes a new UDPSocket using an Integer' do @socket = UDPSocket.new(Socket::AF_INET) - @socket.should be_an_instance_of(UDPSocket) + @socket.should.instance_of?(UDPSocket) end it 'initializes a new UDPSocket using a Symbol' do @socket = UDPSocket.new(:INET) - @socket.should be_an_instance_of(UDPSocket) + @socket.should.instance_of?(UDPSocket) end it 'initializes a new UDPSocket using a String' do @socket = UDPSocket.new('INET') - @socket.should be_an_instance_of(UDPSocket) + @socket.should.instance_of?(UDPSocket) end it 'sets the socket to binmode' do @socket = UDPSocket.new(:INET) - @socket.binmode?.should be_true + @socket.binmode?.should == true end platform_is_not :windows do @@ -46,8 +46,8 @@ describe 'UDPSocket#initialize' do it 'raises Errno::EAFNOSUPPORT or Errno::EPROTONOSUPPORT when given an invalid address family' do -> { UDPSocket.new(666) - }.should raise_error(SystemCallError) { |e| - [Errno::EAFNOSUPPORT, Errno::EPROTONOSUPPORT].should include(e.class) + }.should.raise(SystemCallError) { |e| + [Errno::EAFNOSUPPORT, Errno::EPROTONOSUPPORT].should.include?(e.class) } end end diff --git a/spec/ruby/library/socket/udpsocket/inspect_spec.rb b/spec/ruby/library/socket/udpsocket/inspect_spec.rb deleted file mode 100644 index e212120b14..0000000000 --- a/spec/ruby/library/socket/udpsocket/inspect_spec.rb +++ /dev/null @@ -1,17 +0,0 @@ -require_relative '../spec_helper' - -describe 'UDPSocket#inspect' do - before do - @socket = UDPSocket.new - @socket.bind('127.0.0.1', 0) - end - - after do - @socket.close - end - - it 'returns a String with the fd, family, address and port' do - port = @socket.addr[1] - @socket.inspect.should == "#<UDPSocket:fd #{@socket.fileno}, AF_INET, 127.0.0.1, #{port}>" - end -end diff --git a/spec/ruby/library/socket/udpsocket/local_address_spec.rb b/spec/ruby/library/socket/udpsocket/local_address_spec.rb index 92e4cc10c7..868d2f537e 100644 --- a/spec/ruby/library/socket/udpsocket/local_address_spec.rb +++ b/spec/ruby/library/socket/udpsocket/local_address_spec.rb @@ -28,7 +28,7 @@ describe 'UDPSocket#local_address' do end it 'returns an Addrinfo' do - @sock.local_address.should be_an_instance_of(Addrinfo) + @sock.local_address.should.instance_of?(Addrinfo) end describe 'the returned Addrinfo' do diff --git a/spec/ruby/library/socket/udpsocket/new_spec.rb b/spec/ruby/library/socket/udpsocket/new_spec.rb index 79bfcb624d..aff111927c 100644 --- a/spec/ruby/library/socket/udpsocket/new_spec.rb +++ b/spec/ruby/library/socket/udpsocket/new_spec.rb @@ -8,22 +8,22 @@ describe 'UDPSocket.new' do it 'without arguments' do @socket = UDPSocket.new - @socket.should be_an_instance_of(UDPSocket) + @socket.should.instance_of?(UDPSocket) end it 'using Integer argument' do @socket = UDPSocket.new(Socket::AF_INET) - @socket.should be_an_instance_of(UDPSocket) + @socket.should.instance_of?(UDPSocket) end it 'using Symbol argument' do @socket = UDPSocket.new(:INET) - @socket.should be_an_instance_of(UDPSocket) + @socket.should.instance_of?(UDPSocket) end it 'using String argument' do @socket = UDPSocket.new('INET') - @socket.should be_an_instance_of(UDPSocket) + @socket.should.instance_of?(UDPSocket) end it "does not use the given block and warns to use UDPSocket::open" do @@ -33,8 +33,8 @@ describe 'UDPSocket.new' do 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) + -> { UDPSocket.new(-1) }.should.raise(SystemCallError) { |e| + [Errno::EAFNOSUPPORT, Errno::EPROTONOSUPPORT].should.include?(e.class) } end end diff --git a/spec/ruby/library/socket/udpsocket/open_spec.rb b/spec/ruby/library/socket/udpsocket/open_spec.rb index e4dbb2ee2a..7c77855372 100644 --- a/spec/ruby/library/socket/udpsocket/open_spec.rb +++ b/spec/ruby/library/socket/udpsocket/open_spec.rb @@ -8,6 +8,6 @@ describe "UDPSocket.open" do it "allows calls to open without arguments" do @socket = UDPSocket.open - @socket.should be_kind_of(UDPSocket) + @socket.should.is_a?(UDPSocket) end end diff --git a/spec/ruby/library/socket/udpsocket/recvfrom_nonblock_spec.rb b/spec/ruby/library/socket/udpsocket/recvfrom_nonblock_spec.rb index b804099589..460cf2c9a2 100644 --- a/spec/ruby/library/socket/udpsocket/recvfrom_nonblock_spec.rb +++ b/spec/ruby/library/socket/udpsocket/recvfrom_nonblock_spec.rb @@ -16,7 +16,7 @@ describe 'UDPSocket#recvfrom_nonblock' do platform_is_not :windows do describe 'using an unbound socket' do it 'raises IO::WaitReadable' do - -> { @server.recvfrom_nonblock(1) }.should raise_error(IO::WaitReadable) + -> { @server.recvfrom_nonblock(1) }.should.raise(IO::WaitReadable) end end end @@ -32,7 +32,7 @@ describe 'UDPSocket#recvfrom_nonblock' do describe 'without any data available' do it 'raises IO::WaitReadable' do - -> { @server.recvfrom_nonblock(1) }.should raise_error(IO::WaitReadable) + -> { @server.recvfrom_nonblock(1) }.should.raise(IO::WaitReadable) end it 'returns :wait_readable with exception: false' do @@ -48,7 +48,7 @@ describe 'UDPSocket#recvfrom_nonblock' do it 'returns an Array containing the data and an Array' do IO.select([@server]) - @server.recvfrom_nonblock(1).should be_an_instance_of(Array) + @server.recvfrom_nonblock(1).should.instance_of?(Array) end it 'writes the data to the buffer when one is present' do @@ -78,7 +78,7 @@ describe 'UDPSocket#recvfrom_nonblock' do end it 'contains an Array at index 1' do - @array[1].should be_an_instance_of(Array) + @array[1].should.instance_of?(Array) end end diff --git a/spec/ruby/library/socket/udpsocket/remote_address_spec.rb b/spec/ruby/library/socket/udpsocket/remote_address_spec.rb index 94889ce560..d1310200fc 100644 --- a/spec/ruby/library/socket/udpsocket/remote_address_spec.rb +++ b/spec/ruby/library/socket/udpsocket/remote_address_spec.rb @@ -28,7 +28,7 @@ describe 'UDPSocket#remote_address' do end it 'returns an Addrinfo' do - @sock.remote_address.should be_an_instance_of(Addrinfo) + @sock.remote_address.should.instance_of?(Addrinfo) end describe 'the returned Addrinfo' do diff --git a/spec/ruby/library/socket/udpsocket/send_spec.rb b/spec/ruby/library/socket/udpsocket/send_spec.rb index 6dd5f67bea..63f5b0dcc6 100644 --- a/spec/ruby/library/socket/udpsocket/send_spec.rb +++ b/spec/ruby/library/socket/udpsocket/send_spec.rb @@ -34,7 +34,7 @@ describe "UDPSocket#send" do @msg[0].should == "ad hoc" @msg[1][0].should == "AF_INET" - @msg[1][1].should be_kind_of(Integer) + @msg[1][1].should.is_a?(Integer) @msg[1][3].should == "127.0.0.1" end @@ -46,7 +46,7 @@ describe "UDPSocket#send" do @msg[0].should == "ad hoc" @msg[1][0].should == "AF_INET" - @msg[1][1].should be_kind_of(Integer) + @msg[1][1].should.is_a?(Integer) @msg[1][3].should == "127.0.0.1" end @@ -59,7 +59,7 @@ describe "UDPSocket#send" do @msg[0].should == "connection-based" @msg[1][0].should == "AF_INET" - @msg[1][1].should be_kind_of(Integer) + @msg[1][1].should.is_a?(Integer) @msg[1][3].should == "127.0.0.1" end @@ -68,7 +68,7 @@ describe "UDPSocket#send" do begin -> do @socket.send('1' * 100_000, 0, SocketSpecs.hostname, @port.to_s) - end.should raise_error(Errno::EMSGSIZE) + end.should.raise(Errno::EMSGSIZE) ensure @socket.send("ad hoc", 0, SocketSpecs.hostname, @port) @socket.close @@ -96,7 +96,7 @@ describe 'UDPSocket#send' do describe 'using a disconnected socket' do describe 'without a destination address' do it "raises #{SocketSpecs.dest_addr_req_error}" do - -> { @client.send('hello', 0) }.should raise_error(SocketSpecs.dest_addr_req_error) + -> { @client.send('hello', 0) }.should.raise(SocketSpecs.dest_addr_req_error) end end @@ -108,7 +108,7 @@ describe 'UDPSocket#send' do it 'does not persist the connection after sending data' do @client.send('hello', 0, @addr.ip_address, @addr.ip_port) - -> { @client.send('hello', 0) }.should raise_error(SocketSpecs.dest_addr_req_error) + -> { @client.send('hello', 0) }.should.raise(SocketSpecs.dest_addr_req_error) end end diff --git a/spec/ruby/library/socket/udpsocket/write_spec.rb b/spec/ruby/library/socket/udpsocket/write_spec.rb index c971f29b62..d41ee078d8 100644 --- a/spec/ruby/library/socket/udpsocket/write_spec.rb +++ b/spec/ruby/library/socket/udpsocket/write_spec.rb @@ -12,7 +12,7 @@ describe "UDPSocket#write" do -> do s2.write('1' * 100_000) - end.should raise_error(Errno::EMSGSIZE) + end.should.raise(Errno::EMSGSIZE) ensure s1.close if s1 && !s1.closed? s2.close if s2 && !s2.closed? diff --git a/spec/ruby/library/socket/unixserver/accept_nonblock_spec.rb b/spec/ruby/library/socket/unixserver/accept_nonblock_spec.rb index dba3de7359..531d851658 100644 --- a/spec/ruby/library/socket/unixserver/accept_nonblock_spec.rb +++ b/spec/ruby/library/socket/unixserver/accept_nonblock_spec.rb @@ -1,87 +1,85 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -with_feature :unix_socket do - describe "UNIXServer#accept_nonblock" do - before :each do - @path = SocketSpecs.socket_path - @server = UNIXServer.open(@path) - @client = UNIXSocket.open(@path) +describe "UNIXServer#accept_nonblock" 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.is_a?(UNIXSocket) + end + + it 'returns :wait_readable in exceptionless mode' do + @server.accept_nonblock(exception: false).should == :wait_readable + end +end - it 'returns :wait_readable in exceptionless mode' do - @server.accept_nonblock(exception: false).should == :wait_readable +describe 'UNIXServer#accept_nonblock' 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 'raises IO::WaitReadable' do + -> { @server.accept_nonblock }.should.raise(IO::WaitReadable) end end - 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.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.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 1305bc6220..8f3ea50966 100644 --- a/spec/ruby/library/socket/unixserver/accept_spec.rb +++ b/spec/ruby/library/socket/unixserver/accept_spec.rb @@ -1,126 +1,124 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -with_feature :unix_socket 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.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(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.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 - @socket.should be_an_instance_of(UNIXSocket) - end + it 'returns a UNIXSocket' do + @socket = @server.accept + @socket.should.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 - @socket.should be_an_instance_of(UNIXSocket) + @socket.recv(5).should == 'hello' end - describe 'the returned UNIXSocket' do - it 'can read the data written' do - @socket = @server.accept - @socket.recv(5).should == 'hello' - end - + platform_is_not :windows do it "is set to nonblocking" do require 'io/nonblock' @socket = @server.accept @socket.should.nonblock? end + end - it "is set to close on exec" do - @socket = @server.accept - @socket.should.close_on_exec? - end + it "is set to close on exec" do + @socket = @server.accept + @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 8cc55ef391..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' -with_feature :unix_socket 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..ca1dd301f0 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.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 == 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(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 a160e3ce5c..7d0c7bf76e 100644 --- a/spec/ruby/library/socket/unixserver/new_spec.rb +++ b/spec/ruby/library/socket/unixserver/new_spec.rb @@ -1,14 +1,12 @@ require_relative '../spec_helper' require_relative 'shared/new' -with_feature :unix_socket do - describe "UNIXServer.new" do - it_behaves_like :unixserver_new, :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 + 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 16453dd3bd..c49df802d0 100644 --- a/spec/ruby/library/socket/unixserver/open_spec.rb +++ b/spec/ruby/library/socket/unixserver/open_spec.rb @@ -2,25 +2,23 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' require_relative 'shared/new' -with_feature :unix_socket do - describe "UNIXServer.open" do - it_behaves_like :unixserver_new, :open +describe "UNIXServer.open" do + it_behaves_like :unixserver_new, :open - 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/sysaccept_spec.rb b/spec/ruby/library/socket/unixserver/sysaccept_spec.rb index e59731878a..5970c01114 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.is_a?(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.is_a?(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 d93e061312..b3ae2af5d8 100644 --- a/spec/ruby/library/socket/unixsocket/addr_spec.rb +++ b/spec/ruby/library/socket/unixsocket/addr_spec.rb @@ -1,35 +1,33 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -with_feature :unix_socket do - describe "UNIXSocket#addr" do - before :each do - @path = SocketSpecs.socket_path - @server = UNIXServer.open(@path) - @client = UNIXSocket.open(@path) - end +describe "UNIXSocket#addr" 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.is_a?(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 bf7896ab0e..ac30b93de0 100644 --- a/spec/ruby/library/socket/unixsocket/initialize_spec.rb +++ b/spec/ruby/library/socket/unixsocket/initialize_spec.rb @@ -1,48 +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) + -> { UNIXSocket.new(SocketSpecs.socket_path) }.should.raise(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(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.instance_of?(UNIXSocket) + end - it 'sets the socket to binmode' do - @socket.binmode?.should be_true - 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 == 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 - + 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 a542ba6db5..77bb521069 100644 --- a/spec/ruby/library/socket/unixsocket/inspect_spec.rb +++ b/spec/ruby/library/socket/unixsocket/inspect_spec.rb @@ -1,17 +1,15 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -with_feature :unix_socket do - describe "UNIXSocket#inspect" 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 +describe "UNIXSocket#inspect" 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 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 734253e7f5..fc504698c3 100644 --- a/spec/ruby/library/socket/unixsocket/local_address_spec.rb +++ b/spec/ruby/library/socket/unixsocket/local_address_spec.rb @@ -1,94 +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.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 - end - describe 'UNIXSocket#local_address with a UNIX socket pair' do - before :each do - @sock, @sock2 = Socket.pair(Socket::AF_UNIX, Socket::SOCK_STREAM) + it 'uses 0 as the protocol' do + @client.local_address.protocol.should == 0 end + end +end - after :each do - @sock.close - @sock2.close - 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 - it 'returns an Addrinfo' do - @sock.local_address.should be_an_instance_of(Addrinfo) - end + after :each do + @sock.close + @sock2.close + 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 'returns an Addrinfo' do + @sock.local_address.should.instance_of?(Addrinfo) + end - it 'uses PF_UNIX as the protocol family' do - @sock.local_address.pfamily.should == Socket::PF_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 SOCK_STREAM as the socket type' do - @sock.local_address.socktype.should == Socket::SOCK_STREAM - end + it 'uses PF_UNIX as the protocol family' do + @sock.local_address.pfamily.should == Socket::PF_UNIX + end - it 'raises SocketError for #ip_address' do - -> { - @sock.local_address.ip_address - }.should raise_error(SocketError, "need IPv4 or IPv6 address") - end + it 'uses SOCK_STREAM as the socket type' do + @sock.local_address.socktype.should == Socket::SOCK_STREAM + 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_address' do + -> { + @sock.local_address.ip_address + }.should.raise(SocketError, "need IPv4 or IPv6 address") + end - it 'uses 0 as the protocol' do - @sock.local_address.protocol.should == 0 - end + it 'raises SocketError for #ip_port' do + -> { + @sock.local_address.ip_port + }.should.raise(SocketError, "need IPv4 or IPv6 address") + 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 6d8ea6dcfe..fea2c1e2b7 100644 --- a/spec/ruby/library/socket/unixsocket/new_spec.rb +++ b/spec/ruby/library/socket/unixsocket/new_spec.rb @@ -1,14 +1,12 @@ require_relative '../spec_helper' require_relative 'shared/new' -with_feature :unix_socket do - describe "UNIXSocket.new" do - it_behaves_like :unixsocket_new, :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 + 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 61def30abb..b5e8c6c23a 100644 --- a/spec/ruby/library/socket/unixsocket/open_spec.rb +++ b/spec/ruby/library/socket/unixsocket/open_spec.rb @@ -2,27 +2,25 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' require_relative 'shared/new' -with_feature :unix_socket do - describe "UNIXSocket.open" do - it_behaves_like :unixsocket_new, :open - end +describe "UNIXSocket.open" do + it_behaves_like :unixsocket_new, :open +end - describe "UNIXSocket.open" do - before :each do - @path = SocketSpecs.socket_path - @server = UNIXServer.open(@path) - end +describe "UNIXSocket.open" do + 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 b0a3b2af99..9f04f568fa 100644 --- a/spec/ruby/library/socket/unixsocket/pair_spec.rb +++ b/spec/ruby/library/socket/unixsocket/pair_spec.rb @@ -1,20 +1,59 @@ 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.pair" do - it_should_behave_like :unixsocket_pair - it_should_behave_like :partially_closable_sockets +describe "UNIXSocket.pair" do + it_should_behave_like :partially_closable_sockets - before :each do - @s1, @s2 = UNIXSocket.pair + before :each do + @s1, @s2 = UNIXSocket.pair + end + + after :each do + @s1.close + @s2.close + end + + it "returns two UNIXSockets" do + @s1.should.instance_of?(UNIXSocket) + @s2.should.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 - after :each do - @s1.close - @s2.close + 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/partially_closable_spec.rb b/spec/ruby/library/socket/unixsocket/partially_closable_spec.rb index ef7d0f0b2a..108a6c3063 100644 --- a/spec/ruby/library/socket/unixsocket/partially_closable_spec.rb +++ b/spec/ruby/library/socket/unixsocket/partially_closable_spec.rb @@ -2,22 +2,20 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' require_relative '../shared/partially_closable_sockets' -with_feature :unix_socket 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 +describe "UNIXSocket partial closability" do + before :each do + @path = SocketSpecs.socket_path + @server = UNIXServer.open(@path) + @s1 = UNIXSocket.new(@path) + @s2 = @server.accept + end - it_should_behave_like :partially_closable_sockets + 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 a608378e4f..ffe7e4bea2 100644 --- a/spec/ruby/library/socket/unixsocket/path_spec.rb +++ b/spec/ruby/library/socket/unixsocket/path_spec.rb @@ -1,26 +1,24 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -with_feature :unix_socket do - describe "UNIXSocket#path" do - before :each do - @path = SocketSpecs.socket_path - @server = UNIXServer.open(@path) - @client = UNIXSocket.open(@path) - end +describe "UNIXSocket#path" 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 the path of the socket if it's a server" do - @server.path.should == @path - 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 + 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 72bc96b1fe..b586b1fcbb 100644 --- a/spec/ruby/library/socket/unixsocket/peeraddr_spec.rb +++ b/spec/ruby/library/socket/unixsocket/peeraddr_spec.rb @@ -1,28 +1,26 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -with_feature :unix_socket do - describe "UNIXSocket#peeraddr" do - before :each do - @path = SocketSpecs.socket_path - @server = UNIXServer.open(@path) - @client = UNIXSocket.open(@path) - end +describe "UNIXSocket#peeraddr" 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 the address family and path of the server end of the connection" do - @client.peeraddr.should == ["AF_UNIX", @path] - 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 + it "raises an error in server sockets" do + -> { + @server.peeraddr + }.should.raise(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 1dbc4538e3..ac9d892375 100644 --- a/spec/ruby/library/socket/unixsocket/recv_io_spec.rb +++ b/spec/ruby/library/socket/unixsocket/recv_io_spec.rb @@ -1,7 +1,7 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -with_feature :unix_socket do +platform_is_not :windows do describe "UNIXSocket#recv_io" do before :each do @path = SocketSpecs.socket_path @@ -37,7 +37,7 @@ with_feature :unix_socket do @socket = @server.accept @io = @socket.recv_io(File) - @io.should be_an_instance_of(File) + @io.should.instance_of?(File) end end @@ -59,7 +59,7 @@ with_feature :unix_socket do @client.send_io(@file) @io = @server.recv_io - @io.should be_an_instance_of(IO) + @io.should.instance_of?(IO) end end @@ -68,7 +68,7 @@ with_feature :unix_socket do @client.send_io(@file) @io = @server.recv_io(File) - @io.should be_an_instance_of(File) + @io.should.instance_of?(File) end end @@ -77,7 +77,7 @@ with_feature :unix_socket do @client.send_io(@file) @io = @server.recv_io(File, File::WRONLY) - @io.should be_an_instance_of(File) + @io.should.instance_of?(File) end end end diff --git a/spec/ruby/library/socket/unixsocket/recvfrom_spec.rb b/spec/ruby/library/socket/unixsocket/recvfrom_spec.rb index d849fdc302..9ae3777961 100644 --- a/spec/ruby/library/socket/unixsocket/recvfrom_spec.rb +++ b/spec/ruby/library/socket/unixsocket/recvfrom_spec.rb @@ -1,59 +1,105 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -with_feature :unix_socket do - describe "UNIXSocket#recvfrom" do - before :each do - @path = SocketSpecs.socket_path - @server = UNIXServer.open(@path) - @client = UNIXSocket.open(@path) +describe "UNIXSocket#recvfrom" 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 "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 - it "allows an output buffer as third argument" do - buffer = +'' + 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 - @client.send("foobar", 0) - sock = @server.accept - message, = sock.recvfrom(6, 0, buffer) - sock.close + it "allows an output buffer as third argument" do + buffer = +'' - message.should.equal?(buffer) - buffer.should == "foobar" - end + @client.send("foobar", 0) + sock = @server.accept + message, = sock.recvfrom(6, 0, buffer) + sock.close - it "preserves the encoding of the given buffer" do - buffer = ''.encode(Encoding::ISO_8859_1) + message.should.equal?(buffer) + buffer.should == "foobar" + end - @client.send("foobar", 0) - sock = @server.accept - sock.recvfrom(6, 0, buffer) - sock.close + it "preserves the encoding of the given buffer" do + buffer = ''.encode(Encoding::ISO_8859_1) - buffer.encoding.should == Encoding::ISO_8859_1 - end + @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 @@ -65,24 +111,34 @@ with_feature :unix_socket do sock.close end end +end - describe 'UNIXSocket#recvfrom' do - describe 'using a socket pair' do - before do - @client, @server = UNIXSocket.socketpair - @client.write('hello') - end +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 + after do + @client.close + @server.close + end + + 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..d2303a6587 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.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 80f3550c6d..0063fc7d3f 100644 --- a/spec/ruby/library/socket/unixsocket/send_io_spec.rb +++ b/spec/ruby/library/socket/unixsocket/send_io_spec.rb @@ -1,7 +1,7 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -with_feature :unix_socket do +platform_is_not :windows do describe "UNIXSocket#send_io" do before :each do @path = SocketSpecs.socket_path @@ -49,7 +49,7 @@ with_feature :unix_socket do @client.send_io(@file) @io = @server.recv_io - @io.should be_an_instance_of(IO) + @io.should.instance_of?(IO) end end end diff --git a/spec/ruby/library/socket/unixsocket/shared/pair.rb b/spec/ruby/library/socket/unixsocket/shared/pair.rb deleted file mode 100644 index ade7fc9852..0000000000 --- a/spec/ruby/library/socket/unixsocket/shared/pair.rb +++ /dev/null @@ -1,29 +0,0 @@ -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 - - 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 diff --git a/spec/ruby/library/socket/unixsocket/socketpair_spec.rb b/spec/ruby/library/socket/unixsocket/socketpair_spec.rb index 5f34008df3..a8bfb412e5 100644 --- a/spec/ruby/library/socket/unixsocket/socketpair_spec.rb +++ b/spec/ruby/library/socket/unixsocket/socketpair_spec.rb @@ -1,20 +1,7 @@ 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 - it_should_behave_like :unixsocket_pair - it_should_behave_like :partially_closable_sockets - - before :each do - @s1, @s2 = UNIXSocket.socketpair - end - - after :each do - @s1.close - @s2.close - end +describe "UNIXSocket.socketpair" do + it "is an alias of UNIXSocket.pair" do + UNIXSocket.method(:socketpair).should == UNIXSocket.method(:pair) end end diff --git a/spec/ruby/library/stringio/append_spec.rb b/spec/ruby/library/stringio/append_spec.rb index cb50d73d1b..c21ba00508 100644 --- a/spec/ruby/library/stringio/append_spec.rb +++ b/spec/ruby/library/stringio/append_spec.rb @@ -7,7 +7,7 @@ describe "StringIO#<< when passed [Object]" do end it "returns self" do - (@io << "just testing").should equal(@io) + (@io << "just testing").should.equal?(@io) end it "writes the passed argument onto self" do @@ -31,7 +31,7 @@ describe "StringIO#<< when passed [Object]" do it "updates self's position" do @io << "test" - @io.pos.should eql(4) + @io.pos.should.eql?(4) end it "tries to convert the passed argument to a String using #to_s" do @@ -45,11 +45,11 @@ end describe "StringIO#<< when self is not writable" do it "raises an IOError" do io = StringIO.new(+"test", "r") - -> { io << "test" }.should raise_error(IOError) + -> { io << "test" }.should.raise(IOError) io = StringIO.new(+"test") io.close_write - -> { io << "test" }.should raise_error(IOError) + -> { io << "test" }.should.raise(IOError) end end @@ -69,6 +69,6 @@ describe "StringIO#<< when in append mode" do it "correctly updates self's position" do @io << ", testing" - @io.pos.should eql(16) + @io.pos.should.eql?(16) end end diff --git a/spec/ruby/library/stringio/binmode_spec.rb b/spec/ruby/library/stringio/binmode_spec.rb index 9e92c63814..bc7ccda0a2 100644 --- a/spec/ruby/library/stringio/binmode_spec.rb +++ b/spec/ruby/library/stringio/binmode_spec.rb @@ -4,7 +4,7 @@ require_relative 'fixtures/classes' describe "StringIO#binmode" do it "returns self" do io = StringIO.new(+"example") - io.binmode.should equal(io) + io.binmode.should.equal?(io) end it "changes external encoding to BINARY" do diff --git a/spec/ruby/library/stringio/close_read_spec.rb b/spec/ruby/library/stringio/close_read_spec.rb index 0f08e1ff2e..dd46a927be 100644 --- a/spec/ruby/library/stringio/close_read_spec.rb +++ b/spec/ruby/library/stringio/close_read_spec.rb @@ -7,12 +7,12 @@ describe "StringIO#close_read" do end it "returns nil" do - @io.close_read.should be_nil + @io.close_read.should == nil end it "prevents further reading" do @io.close_read - -> { @io.read(1) }.should raise_error(IOError) + -> { @io.read(1) }.should.raise(IOError) end it "allows further writing" do @@ -22,7 +22,7 @@ describe "StringIO#close_read" do it "raises an IOError when in write-only mode" do io = StringIO.new(+"example", "w") - -> { io.close_read }.should raise_error(IOError) + -> { io.close_read }.should.raise(IOError) io = StringIO.new("example") io.close_read diff --git a/spec/ruby/library/stringio/close_spec.rb b/spec/ruby/library/stringio/close_spec.rb index 520a8de782..6febd14a26 100644 --- a/spec/ruby/library/stringio/close_spec.rb +++ b/spec/ruby/library/stringio/close_spec.rb @@ -7,17 +7,17 @@ describe "StringIO#close" do end it "returns nil" do - @io.close.should be_nil + @io.close.should == nil end it "prevents further reading and/or writing" do @io.close - -> { @io.read(1) }.should raise_error(IOError) - -> { @io.write('x') }.should raise_error(IOError) + -> { @io.read(1) }.should.raise(IOError) + -> { @io.write('x') }.should.raise(IOError) end it "does not raise anything when self was already closed" do @io.close - -> { @io.close }.should_not raise_error(IOError) + -> { @io.close }.should_not.raise(IOError) end end diff --git a/spec/ruby/library/stringio/close_write_spec.rb b/spec/ruby/library/stringio/close_write_spec.rb index c86c3f9826..b74b996166 100644 --- a/spec/ruby/library/stringio/close_write_spec.rb +++ b/spec/ruby/library/stringio/close_write_spec.rb @@ -7,12 +7,12 @@ describe "StringIO#close_write" do end it "returns nil" do - @io.close_write.should be_nil + @io.close_write.should == nil end it "prevents further writing" do @io.close_write - -> { @io.write('x') }.should raise_error(IOError) + -> { @io.write('x') }.should.raise(IOError) end it "allows further reading" do @@ -22,7 +22,7 @@ describe "StringIO#close_write" do it "raises an IOError when in read-only mode" do io = StringIO.new(+"example", "r") - -> { io.close_write }.should raise_error(IOError) + -> { io.close_write }.should.raise(IOError) io = StringIO.new(+"example") io.close_write diff --git a/spec/ruby/library/stringio/closed_read_spec.rb b/spec/ruby/library/stringio/closed_read_spec.rb index b4dcadc3a4..2e3813b1bc 100644 --- a/spec/ruby/library/stringio/closed_read_spec.rb +++ b/spec/ruby/library/stringio/closed_read_spec.rb @@ -5,8 +5,8 @@ describe "StringIO#closed_read?" do it "returns true if self is not readable" do io = StringIO.new(+"example", "r+") io.close_write - io.closed_read?.should be_false + io.closed_read?.should == false io.close_read - io.closed_read?.should be_true + io.closed_read?.should == true end end diff --git a/spec/ruby/library/stringio/closed_spec.rb b/spec/ruby/library/stringio/closed_spec.rb index bf7ba63184..647fe445da 100644 --- a/spec/ruby/library/stringio/closed_spec.rb +++ b/spec/ruby/library/stringio/closed_spec.rb @@ -5,12 +5,12 @@ describe "StringIO#closed?" do it "returns true if self is completely closed" do io = StringIO.new(+"example", "r+") io.close_read - io.closed?.should be_false + io.closed?.should == false io.close_write - io.closed?.should be_true + io.closed?.should == true io = StringIO.new(+"example", "r+") io.close - io.closed?.should be_true + io.closed?.should == true end end diff --git a/spec/ruby/library/stringio/closed_write_spec.rb b/spec/ruby/library/stringio/closed_write_spec.rb index 2bd3e6fa8b..339691cd82 100644 --- a/spec/ruby/library/stringio/closed_write_spec.rb +++ b/spec/ruby/library/stringio/closed_write_spec.rb @@ -5,8 +5,8 @@ describe "StringIO#closed_write?" do it "returns true if self is not writable" do io = StringIO.new(+"example", "r+") io.close_read - io.closed_write?.should be_false + io.closed_write?.should == false io.close_write - io.closed_write?.should be_true + io.closed_write?.should == true end end diff --git a/spec/ruby/library/stringio/each_byte_spec.rb b/spec/ruby/library/stringio/each_byte_spec.rb index 6f82a32441..1be0081c1e 100644 --- a/spec/ruby/library/stringio/each_byte_spec.rb +++ b/spec/ruby/library/stringio/each_byte_spec.rb @@ -1,11 +1,51 @@ require_relative '../../spec_helper' require 'stringio' -require_relative 'shared/each_byte' describe "StringIO#each_byte" do - it_behaves_like :stringio_each_byte, :each_byte + before :each do + @io = StringIO.new("xyz") + end + + it "yields each character code in turn" do + seen = [] + @io.each_byte { |b| seen << b } + seen.should == [120, 121, 122] + end + + it "updates the position before each yield" do + seen = [] + @io.each_byte { |b| seen << @io.pos } + seen.should == [1, 2, 3] + end + + it "does not yield if the current position is out of bounds" do + @io.pos = 1000 + seen = nil + @io.each_byte { |b| seen = b } + seen.should == nil + end + + it "returns self" do + @io.each_byte {}.should.equal?(@io) + end + + it "returns an Enumerator when passed no block" do + enum = @io.each_byte + enum.instance_of?(Enumerator).should == true + + seen = [] + enum.each { |b| seen << b } + seen.should == [120, 121, 122] + end end describe "StringIO#each_byte when self is not readable" do - it_behaves_like :stringio_each_byte_not_readable, :each_byte + it "raises an IOError" do + io = StringIO.new(+"xyz", "w") + -> { io.each_byte { |b| b } }.should.raise(IOError) + + io = StringIO.new("xyz") + io.close_read + -> { io.each_byte { |b| b } }.should.raise(IOError) + end end diff --git a/spec/ruby/library/stringio/each_char_spec.rb b/spec/ruby/library/stringio/each_char_spec.rb index 14b2f09a17..1db80c7d07 100644 --- a/spec/ruby/library/stringio/each_char_spec.rb +++ b/spec/ruby/library/stringio/each_char_spec.rb @@ -1,11 +1,38 @@ require_relative '../../spec_helper' require 'stringio' -require_relative 'shared/each_char' describe "StringIO#each_char" do - it_behaves_like :stringio_each_char, :each_char + before :each do + @io = StringIO.new("xyz äöü") + end + + it "yields each character code in turn" do + seen = [] + @io.each_char { |c| seen << c } + seen.should == ["x", "y", "z", " ", "ä", "ö", "ü"] + end + + it "returns self" do + @io.each_char {}.should.equal?(@io) + end + + it "returns an Enumerator when passed no block" do + enum = @io.each_char + enum.instance_of?(Enumerator).should == true + + seen = [] + enum.each { |c| seen << c } + seen.should == ["x", "y", "z", " ", "ä", "ö", "ü"] + end end describe "StringIO#each_char when self is not readable" do - it_behaves_like :stringio_each_char_not_readable, :each_char + it "raises an IOError" do + io = StringIO.new(+"xyz", "w") + -> { io.each_char { |b| b } }.should.raise(IOError) + + io = StringIO.new("xyz") + io.close_read + -> { io.each_char { |b| b } }.should.raise(IOError) + end end diff --git a/spec/ruby/library/stringio/each_codepoint_spec.rb b/spec/ruby/library/stringio/each_codepoint_spec.rb index f18de22aad..d4f461db90 100644 --- a/spec/ruby/library/stringio/each_codepoint_spec.rb +++ b/spec/ruby/library/stringio/each_codepoint_spec.rb @@ -1,9 +1,47 @@ -# -*- encoding: utf-8 -*- require_relative '../../spec_helper' -require_relative 'fixtures/classes' -require_relative 'shared/codepoints' +require 'stringio' # See redmine #1667 describe "StringIO#each_codepoint" do - it_behaves_like :stringio_codepoints, :each_codepoint + before :each do + @io = StringIO.new("∂φ/∂x = gaîté") + @enum = @io.each_codepoint + end + + it "returns an Enumerator" do + @enum.should.instance_of?(Enumerator) + end + + it "yields each codepoint code in turn" do + @enum.to_a.should == [8706, 966, 47, 8706, 120, 32, 61, 32, 103, 97, 238, 116, 233] + end + + it "yields each codepoint starting from the current position" do + @io.pos = 15 + @enum.to_a.should == [238, 116, 233] + end + + it "raises an error if reading invalid sequence" do + @io.pos = 1 # inside of a multibyte sequence + -> { @enum.first }.should.raise(ArgumentError) + end + + it "raises an IOError if not readable" do + @io.close_read + -> { @enum.to_a }.should.raise(IOError) + + io = StringIO.new(+"xyz", "w") + -> { io.each_codepoint.to_a }.should.raise(IOError) + end + + + it "calls the given block" do + r = [] + @io.each_codepoint{|c| r << c } + r.should == [8706, 966, 47, 8706, 120, 32, 61, 32, 103, 97, 238, 116, 233] + end + + it "returns self" do + @io.each_codepoint {|l| l }.should.equal?(@io) + end end diff --git a/spec/ruby/library/stringio/each_line_spec.rb b/spec/ruby/library/stringio/each_line_spec.rb index 4ac0db7c45..4abecbf026 100644 --- a/spec/ruby/library/stringio/each_line_spec.rb +++ b/spec/ruby/library/stringio/each_line_spec.rb @@ -1,27 +1,212 @@ require_relative '../../spec_helper' require_relative 'fixtures/classes' -require_relative 'shared/each' describe "StringIO#each_line when passed a separator" do - it_behaves_like :stringio_each_separator, :each_line + before :each do + @io = StringIO.new("a b c d e\n1 2 3 4 5") + end + + it "uses the passed argument as the line separator" do + seen = [] + @io.each_line(" ") {|s| seen << s} + seen.should == ["a ", "b ", "c ", "d ", "e\n1 ", "2 ", "3 ", "4 ", "5"] + end + + it "does not change $_" do + $_ = "test" + @io.each_line(" ") { |s| s} + $_.should == "test" + end + + it "returns self" do + @io.each_line {|l| l }.should.equal?(@io) + end + + it "tries to convert the passed separator to a String using #to_str" do + obj = mock("to_str") + obj.stub!(:to_str).and_return(" ") + + seen = [] + @io.each_line(obj) { |l| seen << l } + seen.should == ["a ", "b ", "c ", "d ", "e\n1 ", "2 ", "3 ", "4 ", "5"] + end + + it "yields self's content starting from the current position when the passed separator is nil" do + seen = [] + io = StringIO.new("1 2 1 2 1 2") + io.pos = 2 + io.each_line(nil) {|s| seen << s} + seen.should == ["2 1 2 1 2"] + 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.each_line("") {|s| seen << s} + seen.should == ["para1\n\n", "para2\n\n\n", "para3"] + end end describe "StringIO#each_line when passed no arguments" do - it_behaves_like :stringio_each_no_arguments, :each_line + before :each do + @io = StringIO.new("a b c d e\n1 2 3 4 5") + end + + it "yields each line to the passed block" do + seen = [] + @io.each_line {|s| seen << s } + seen.should == ["a b c d e\n", "1 2 3 4 5"] + end + + it "yields each line starting from the current position" do + seen = [] + @io.pos = 4 + @io.each_line {|s| seen << s } + seen.should == ["c d e\n", "1 2 3 4 5"] + end + + it "does not change $_" do + $_ = "test" + @io.each_line { |s| s} + $_.should == "test" + end + + it "uses $/ as the default line separator" do + seen = [] + begin + old_rs = $/ + suppress_warning {$/ = " "} + @io.each_line {|s| seen << s } + seen.should.eql?(["a ", "b ", "c ", "d ", "e\n1 ", "2 ", "3 ", "4 ", "5"]) + ensure + suppress_warning {$/ = old_rs} + end + end + + it "returns self" do + @io.each_line {|l| l }.should.equal?(@io) + end + + it "returns an Enumerator when passed no block" do + enum = @io.each_line + enum.instance_of?(Enumerator).should == true + + seen = [] + enum.each { |b| seen << b } + seen.should == ["a b c d e\n", "1 2 3 4 5"] + end end describe "StringIO#each_line when self is not readable" do - it_behaves_like :stringio_each_not_readable, :each_line + it "raises an IOError" do + io = StringIO.new(+"a b c d e", "w") + -> { io.each_line { |b| b } }.should.raise(IOError) + + io = StringIO.new("a b c d e") + io.close_read + -> { io.each_line { |b| b } }.should.raise(IOError) + end +end + +describe "StringIO#each_line when passed chomp" do + it "yields each line with removed newline characters to the passed block" do + seen = [] + io = StringIO.new("a b \rc d e\n1 2 3 4 5\r\nthe end") + io.each_line(chomp: true) {|s| seen << s } + seen.should == ["a b \rc d e", "1 2 3 4 5", "the end"] + end + + it "returns each line with removed newline characters when called without block" do + seen = [] + io = StringIO.new("a b \rc d e\n1 2 3 4 5\r\nthe end") + enum = io.each_line(chomp: true) + enum.each {|s| seen << s } + seen.should == ["a b \rc d e", "1 2 3 4 5", "the end"] + end end describe "StringIO#each_line when passed chomp" do - it_behaves_like :stringio_each_chomp, :each_line + it "yields each line with removed separator to the passed block" do + seen = [] + io = StringIO.new("a b \nc d e|1 2 3 4 5\n|the end") + io.each_line("|", chomp: true) {|s| seen << s } + seen.should == ["a b \nc d e", "1 2 3 4 5\n", "the end"] + end + + it "returns each line with removed separator when called without block" do + seen = [] + io = StringIO.new("a b \nc d e|1 2 3 4 5\n|the end") + enum = io.each_line("|", chomp: true) + enum.each {|s| seen << s } + seen.should == ["a b \nc d e", "1 2 3 4 5\n", "the end"] + end end describe "StringIO#each_line when passed limit" do - it_behaves_like :stringio_each_limit, :each_line + before :each do + @io = StringIO.new("a b c d e\n1 2 3 4 5") + end + + it "returns the data read until the limit is met" do + seen = [] + @io.each_line(4) { |s| seen << s } + seen.should == ["a b ", "c d ", "e\n", "1 2 ", "3 4 ", "5"] + end end describe "StringIO#each when passed separator and limit" do - it_behaves_like :stringio_each_separator_and_limit, :each_line + 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.each_line('>', 8) { |s| break s }.should == "this>" + @io.each_line('>', 2) { |s| break s }.should == "is" + @io.each_line('>', 10) { |s| break s }.should == ">" + @io.each_line('>', 6) { |s| break s }.should == "an>" + @io.each_line('>', 5) { |s| break s }.should == "examp" + end + + it "truncates the multi-character separator at the end to meet the limit" do + @io.each_line("is>an", 7) { |s| break s }.should == "this>is" + end + + it "does not change $_" do + $_ = "test" + @io.each_line('>', 8) { |s| s } + $_.should == "test" + end + + it "updates self's lineno by one" do + @io.each_line('>', 3) { |s| break s } + @io.lineno.should.eql?(1) + + @io.each_line('>', 3) { |s| break s } + @io.lineno.should.eql?(2) + + @io.each_line('>', 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.each_line(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.each_line(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.each_line('>', obj) { |s| seen << s } + seen.should == ["this>", "is>", "an>", "examp", "le"] + end end diff --git a/spec/ruby/library/stringio/each_spec.rb b/spec/ruby/library/stringio/each_spec.rb index 7eb322f3ff..f3785bc18f 100644 --- a/spec/ruby/library/stringio/each_spec.rb +++ b/spec/ruby/library/stringio/each_spec.rb @@ -1,31 +1,8 @@ require_relative '../../spec_helper' -require_relative 'fixtures/classes' -require_relative 'shared/each' +require 'stringio' -describe "StringIO#each when passed a separator" do - it_behaves_like :stringio_each_separator, :each -end - -describe "StringIO#each when passed no arguments" do - it_behaves_like :stringio_each_no_arguments, :each -end - -describe "StringIO#each when self is not readable" do - it_behaves_like :stringio_each_not_readable, :each -end - -describe "StringIO#each when passed chomp" do - it_behaves_like :stringio_each_chomp, :each -end - -describe "StringIO#each when passed chomp" do - it_behaves_like :stringio_each_separator_and_chomp, :each -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 +describe "StringIO#each" do + it "is an alias of StringIO#each_line" do + StringIO.instance_method(:each).should == StringIO.instance_method(:each_line) + end end diff --git a/spec/ruby/library/stringio/eof_spec.rb b/spec/ruby/library/stringio/eof_spec.rb index af0170977c..acc49305f5 100644 --- a/spec/ruby/library/stringio/eof_spec.rb +++ b/spec/ruby/library/stringio/eof_spec.rb @@ -1,11 +1,33 @@ require_relative '../../spec_helper' -require_relative 'fixtures/classes' -require_relative 'shared/eof' +require 'stringio' describe "StringIO#eof?" do - it_behaves_like :stringio_eof, :eof? + before :each do + @io = StringIO.new("eof") + end + + it "returns true when self's position is greater than or equal to self's size" do + @io.pos = 3 + @io.eof?.should == true + + @io.pos = 6 + @io.eof?.should == true + end + + it "returns false when self's position is less than self's size" do + @io.pos = 0 + @io.eof?.should == false + + @io.pos = 1 + @io.eof?.should == false + + @io.pos = 2 + @io.eof?.should == false + end end describe "StringIO#eof" do - it_behaves_like :stringio_eof, :eof + it "is an alias of StringIO#eof?" do + StringIO.instance_method(:eof).should == StringIO.instance_method(:eof?) + end end diff --git a/spec/ruby/library/stringio/fcntl_spec.rb b/spec/ruby/library/stringio/fcntl_spec.rb index a78004d868..6108130db7 100644 --- a/spec/ruby/library/stringio/fcntl_spec.rb +++ b/spec/ruby/library/stringio/fcntl_spec.rb @@ -3,6 +3,6 @@ require_relative 'fixtures/classes' describe "StringIO#fcntl" do it "raises a NotImplementedError" do - -> { StringIO.new("boom").fcntl }.should raise_error(NotImplementedError) + -> { StringIO.new("boom").fcntl }.should.raise(NotImplementedError) end end diff --git a/spec/ruby/library/stringio/fileno_spec.rb b/spec/ruby/library/stringio/fileno_spec.rb index 5a9f440a0f..f5d1e83776 100644 --- a/spec/ruby/library/stringio/fileno_spec.rb +++ b/spec/ruby/library/stringio/fileno_spec.rb @@ -3,6 +3,6 @@ require 'stringio' describe "StringIO#fileno" do it "returns nil" do - StringIO.new("nuffin").fileno.should be_nil + StringIO.new("nuffin").fileno.should == nil end end diff --git a/spec/ruby/library/stringio/flush_spec.rb b/spec/ruby/library/stringio/flush_spec.rb index 4dc58b1d48..48be44773c 100644 --- a/spec/ruby/library/stringio/flush_spec.rb +++ b/spec/ruby/library/stringio/flush_spec.rb @@ -4,6 +4,6 @@ require_relative 'fixtures/classes' describe "StringIO#flush" do it "returns self" do io = StringIO.new(+"flush") - io.flush.should equal(io) + 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 85053cb2e5..30fae15c8e 100644 --- a/spec/ruby/library/stringio/fsync_spec.rb +++ b/spec/ruby/library/stringio/fsync_spec.rb @@ -4,6 +4,6 @@ require_relative 'fixtures/classes' describe "StringIO#fsync" do it "returns zero" do io = StringIO.new(+"fsync") - io.fsync.should eql(0) + 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 ac876f0b4f..5dc572fba5 100644 --- a/spec/ruby/library/stringio/gets_spec.rb +++ b/spec/ruby/library/stringio/gets_spec.rb @@ -10,8 +10,8 @@ describe "StringIO#gets" do @io = StringIO.new("this>is>an>example") @io.pos = 36 - @io.gets(">").should be_nil - @io.gets(">").should be_nil + @io.gets(">").should == nil + @io.gets(">").should == nil end end @@ -22,8 +22,8 @@ describe "StringIO#gets" do @io = StringIO.new("this>is>an>example") @io.pos = 36 - @io.gets(3).should be_nil - @io.gets(3).should be_nil + @io.gets(3).should == nil + @io.gets(3).should == nil end end @@ -34,8 +34,8 @@ describe "StringIO#gets" do @io = StringIO.new("this>is>an>example") @io.pos = 36 - @io.gets(">", 3).should be_nil - @io.gets(">", 3).should be_nil + @io.gets(">", 3).should == nil + @io.gets(">", 3).should == nil end end @@ -46,8 +46,8 @@ describe "StringIO#gets" do @io = StringIO.new("this>is>an>example") @io.pos = 36 - @io.gets.should be_nil - @io.gets.should be_nil + @io.gets.should == nil + @io.gets.should == nil end end diff --git a/spec/ruby/library/stringio/initialize_spec.rb b/spec/ruby/library/stringio/initialize_spec.rb index 6f4d2e456c..413e0aacc0 100644 --- a/spec/ruby/library/stringio/initialize_spec.rb +++ b/spec/ruby/library/stringio/initialize_spec.rb @@ -8,111 +8,111 @@ describe "StringIO#initialize when passed [Object, mode]" do it "uses the passed Object as the StringIO backend" do @io.send(:initialize, str = "example", "r") - @io.string.should equal(str) + @io.string.should.equal?(str) end it "sets the mode based on the passed mode" do io = StringIO.allocate io.send(:initialize, +"example", "r") - io.closed_read?.should be_false - io.closed_write?.should be_true + io.closed_read?.should == false + io.closed_write?.should == true io = StringIO.allocate io.send(:initialize, +"example", "rb") - io.closed_read?.should be_false - io.closed_write?.should be_true + io.closed_read?.should == false + io.closed_write?.should == true io = StringIO.allocate io.send(:initialize, +"example", "r+") - io.closed_read?.should be_false - io.closed_write?.should be_false + io.closed_read?.should == false + io.closed_write?.should == false io = StringIO.allocate io.send(:initialize, +"example", "rb+") - io.closed_read?.should be_false - io.closed_write?.should be_false + io.closed_read?.should == false + io.closed_write?.should == false io = StringIO.allocate io.send(:initialize, +"example", "w") - io.closed_read?.should be_true - io.closed_write?.should be_false + io.closed_read?.should == true + io.closed_write?.should == false io = StringIO.allocate io.send(:initialize, +"example", "wb") - io.closed_read?.should be_true - io.closed_write?.should be_false + io.closed_read?.should == true + io.closed_write?.should == false io = StringIO.allocate io.send(:initialize, +"example", "w+") - io.closed_read?.should be_false - io.closed_write?.should be_false + io.closed_read?.should == false + io.closed_write?.should == false io = StringIO.allocate io.send(:initialize, +"example", "wb+") - io.closed_read?.should be_false - io.closed_write?.should be_false + io.closed_read?.should == false + io.closed_write?.should == false io = StringIO.allocate io.send(:initialize, +"example", "a") - io.closed_read?.should be_true - io.closed_write?.should be_false + io.closed_read?.should == true + io.closed_write?.should == false io = StringIO.allocate io.send(:initialize, +"example", "ab") - io.closed_read?.should be_true - io.closed_write?.should be_false + io.closed_read?.should == true + io.closed_write?.should == false io = StringIO.allocate io.send(:initialize, +"example", "a+") - io.closed_read?.should be_false - io.closed_write?.should be_false + io.closed_read?.should == false + io.closed_write?.should == false io = StringIO.allocate io.send(:initialize, +"example", "ab+") - io.closed_read?.should be_false - io.closed_write?.should be_false + io.closed_read?.should == false + io.closed_write?.should == false end it "allows passing the mode as an Integer" do io = StringIO.allocate io.send(:initialize, +"example", IO::RDONLY) - io.closed_read?.should be_false - io.closed_write?.should be_true + io.closed_read?.should == false + io.closed_write?.should == true io = StringIO.allocate io.send(:initialize, +"example", IO::RDWR) - io.closed_read?.should be_false - io.closed_write?.should be_false + io.closed_read?.should == false + io.closed_write?.should == false io = StringIO.allocate io.send(:initialize, +"example", IO::WRONLY) - io.closed_read?.should be_true - io.closed_write?.should be_false + io.closed_read?.should == true + io.closed_write?.should == false io = StringIO.allocate io.send(:initialize, +"example", IO::WRONLY | IO::TRUNC) - io.closed_read?.should be_true - io.closed_write?.should be_false + io.closed_read?.should == true + io.closed_write?.should == false io = StringIO.allocate io.send(:initialize, +"example", IO::RDWR | IO::TRUNC) - io.closed_read?.should be_false - io.closed_write?.should be_false + io.closed_read?.should == false + io.closed_write?.should == false io = StringIO.allocate io.send(:initialize, +"example", IO::WRONLY | IO::APPEND) - io.closed_read?.should be_true - io.closed_write?.should be_false + io.closed_read?.should == true + io.closed_write?.should == false io = StringIO.allocate io.send(:initialize, +"example", IO::RDWR | IO::APPEND) - io.closed_read?.should be_false - io.closed_write?.should be_false + io.closed_read?.should == false + io.closed_write?.should == false end it "raises a FrozenError when passed a frozen String in truncate mode as StringIO backend" do io = StringIO.allocate - -> { io.send(:initialize, "example".freeze, IO::TRUNC) }.should raise_error(FrozenError) + -> { io.send(:initialize, "example".freeze, IO::TRUNC) }.should.raise(FrozenError) end it "tries to convert the passed mode to a String using #to_str" do @@ -120,15 +120,15 @@ describe "StringIO#initialize when passed [Object, mode]" do obj.should_receive(:to_str).and_return("r") @io.send(:initialize, +"example", obj) - @io.closed_read?.should be_false - @io.closed_write?.should be_true + @io.closed_read?.should == false + @io.closed_write?.should == true end it "raises an Errno::EACCES error when passed a frozen string with a write-mode" do (str = "example").freeze - -> { @io.send(:initialize, str, "r+") }.should raise_error(Errno::EACCES) - -> { @io.send(:initialize, str, "w") }.should raise_error(Errno::EACCES) - -> { @io.send(:initialize, str, "a") }.should raise_error(Errno::EACCES) + -> { @io.send(:initialize, str, "r+") }.should.raise(Errno::EACCES) + -> { @io.send(:initialize, str, "w") }.should.raise(Errno::EACCES) + -> { @io.send(:initialize, str, "a") }.should.raise(Errno::EACCES) end it "truncates all the content if passed w mode" do @@ -159,19 +159,19 @@ describe "StringIO#initialize when passed [Object]" do it "uses the passed Object as the StringIO backend" do @io.send(:initialize, str = "example") - @io.string.should equal(str) + @io.string.should.equal?(str) end 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 + @io.closed_read?.should == false + @io.closed_write?.should == 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 + @io.closed_read?.should == false + @io.closed_write?.should == true end it "tries to convert the passed Object to a String using #to_str" do @@ -184,8 +184,8 @@ describe "StringIO#initialize when passed [Object]" do it "automatically sets the mode to read-only when passed a frozen string" do (str = "example").freeze @io.send(:initialize, str) - @io.closed_read?.should be_false - @io.closed_write?.should be_true + @io.closed_read?.should == false + @io.closed_write?.should == true end end @@ -193,8 +193,8 @@ end describe "StringIO#initialize when passed keyword arguments" do it "sets the mode based on the passed :mode option" do io = StringIO.new("example", mode: "r") - io.closed_read?.should be_false - io.closed_write?.should be_true + io.closed_read?.should == false + io.closed_write?.should == true end it "accepts a mode argument set to nil with a valid :mode option" do @@ -223,54 +223,54 @@ describe "StringIO#initialize when passed keyword arguments and error happens" d it "raises an error if passed encodings two ways" do -> { @io = StringIO.new(+'', 'w:ISO-8859-1', encoding: 'ISO-8859-1') - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) -> { @io = StringIO.new(+'', 'w:ISO-8859-1', external_encoding: 'ISO-8859-1') - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) -> { @io = StringIO.new(+'', 'w:ISO-8859-1:UTF-8', internal_encoding: 'ISO-8859-1') - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) end it "raises an error if passed matching binary/text mode two ways" do -> { @io = StringIO.new(+'', "wb", binmode: true) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) -> { @io = StringIO.new(+'', "wt", textmode: true) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) -> { @io = StringIO.new(+'', "wb", textmode: false) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) -> { @io = StringIO.new(+'', "wt", binmode: false) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) end it "raises an error if passed conflicting binary/text mode two ways" do -> { @io = StringIO.new(+'', "wb", binmode: false) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) -> { @io = StringIO.new(+'', "wt", textmode: false) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) -> { @io = StringIO.new(+'', "wb", textmode: true) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) -> { @io = StringIO.new(+'', "wt", binmode: true) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) end it "raises an error when trying to set both binmode and textmode" do -> { @io = StringIO.new(+'', "w", textmode: true, binmode: true) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) -> { @io = StringIO.new(+'', File::Constants::WRONLY, textmode: true, binmode: true) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) end end @@ -280,13 +280,13 @@ describe "StringIO#initialize when passed no arguments" do end it "is private" do - StringIO.should have_private_instance_method(:initialize) + StringIO.private_instance_methods(false).should.include?(:initialize) end it "sets the mode to read-write" do @io.send(:initialize) - @io.closed_read?.should be_false - @io.closed_write?.should be_false + @io.closed_read?.should == false + @io.closed_write?.should == false end it "uses an empty String as the StringIO backend" do diff --git a/spec/ruby/library/stringio/inspect_spec.rb b/spec/ruby/library/stringio/inspect_spec.rb index 7c02f8d360..962d858e48 100644 --- a/spec/ruby/library/stringio/inspect_spec.rb +++ b/spec/ruby/library/stringio/inspect_spec.rb @@ -9,7 +9,7 @@ describe "StringIO#inspect" do it "does not include the contents" do io = StringIO.new("contents") - io.inspect.should_not include("contents") + io.inspect.should_not.include?("contents") end it "uses the regular Object#inspect without any instance variable" do diff --git a/spec/ruby/library/stringio/isatty_spec.rb b/spec/ruby/library/stringio/isatty_spec.rb index 1ef33978b5..07743acc12 100644 --- a/spec/ruby/library/stringio/isatty_spec.rb +++ b/spec/ruby/library/stringio/isatty_spec.rb @@ -1,7 +1,8 @@ require_relative '../../spec_helper' -require_relative 'fixtures/classes' -require_relative 'shared/isatty' +require 'stringio' describe "StringIO#isatty" do - it_behaves_like :stringio_isatty, :isatty + it "is an alias of StringIO#tty?" do + StringIO.instance_method(:isatty).should == StringIO.instance_method(:tty?) + end end diff --git a/spec/ruby/library/stringio/length_spec.rb b/spec/ruby/library/stringio/length_spec.rb index d3070f50a7..a83be6256a 100644 --- a/spec/ruby/library/stringio/length_spec.rb +++ b/spec/ruby/library/stringio/length_spec.rb @@ -1,7 +1,8 @@ require_relative '../../spec_helper' -require_relative 'fixtures/classes' -require_relative 'shared/length' +require 'stringio' describe "StringIO#length" do - it_behaves_like :stringio_length, :length + it "returns the length of the wrapped string" do + StringIO.new("example").length.should == 7 + end end diff --git a/spec/ruby/library/stringio/lineno_spec.rb b/spec/ruby/library/stringio/lineno_spec.rb index c620a1a686..a96dc05927 100644 --- a/spec/ruby/library/stringio/lineno_spec.rb +++ b/spec/ruby/library/stringio/lineno_spec.rb @@ -10,7 +10,7 @@ describe "StringIO#lineno" do @io.gets @io.gets @io.gets - @io.lineno.should eql(3) + @io.lineno.should.eql?(3) end end @@ -21,10 +21,10 @@ describe "StringIO#lineno=" do it "sets the current line number, but has no impact on the position" do @io.lineno = 3 - @io.pos.should eql(0) + @io.pos.should.eql?(0) @io.gets.should == "this\n" - @io.lineno.should eql(4) - @io.pos.should eql(5) + @io.lineno.should.eql?(4) + @io.pos.should.eql?(5) end end diff --git a/spec/ruby/library/stringio/open_spec.rb b/spec/ruby/library/stringio/open_spec.rb index b7c90661f9..23c7b34e09 100644 --- a/spec/ruby/library/stringio/open_spec.rb +++ b/spec/ruby/library/stringio/open_spec.rb @@ -4,24 +4,24 @@ require 'stringio' describe "StringIO.open when passed [Object, mode]" do it "uses the passed Object as the StringIO backend" do io = StringIO.open(str = "example", "r") - io.string.should equal(str) + io.string.should.equal?(str) end it "returns the blocks return value when yielding" do ret = StringIO.open(+"example", "r") { :test } - ret.should equal(:test) + ret.should.equal?(:test) end it "yields self to the passed block" do io = nil StringIO.open(+"example", "r") { |strio| io = strio } - io.should be_kind_of(StringIO) + io.should.is_a?(StringIO) end it "closes self after yielding" do io = nil StringIO.open(+"example", "r") { |strio| io = strio } - io.closed?.should be_true + io.closed?.should == true end it "even closes self when an exception is raised while yielding" do @@ -33,13 +33,13 @@ describe "StringIO.open when passed [Object, mode]" do end rescue end - io.closed?.should be_true + io.closed?.should == true end it "sets self's string to nil after yielding" do io = nil StringIO.open(+"example", "r") { |strio| io = strio } - io.string.should be_nil + io.string.should == nil end it "even sets self's string to nil when an exception is raised while yielding" do @@ -51,91 +51,91 @@ describe "StringIO.open when passed [Object, mode]" do end rescue end - io.string.should be_nil + io.string.should == nil end it "sets the mode based on the passed mode" do io = StringIO.open(+"example", "r") - io.closed_read?.should be_false - io.closed_write?.should be_true + io.closed_read?.should == false + io.closed_write?.should == true io = StringIO.open(+"example", "rb") - io.closed_read?.should be_false - io.closed_write?.should be_true + io.closed_read?.should == false + io.closed_write?.should == true io = StringIO.open(+"example", "r+") - io.closed_read?.should be_false - io.closed_write?.should be_false + io.closed_read?.should == false + io.closed_write?.should == false io = StringIO.open(+"example", "rb+") - io.closed_read?.should be_false - io.closed_write?.should be_false + io.closed_read?.should == false + io.closed_write?.should == false io = StringIO.open(+"example", "w") - io.closed_read?.should be_true - io.closed_write?.should be_false + io.closed_read?.should == true + io.closed_write?.should == false io = StringIO.open(+"example", "wb") - io.closed_read?.should be_true - io.closed_write?.should be_false + io.closed_read?.should == true + io.closed_write?.should == false io = StringIO.open(+"example", "w+") - io.closed_read?.should be_false - io.closed_write?.should be_false + io.closed_read?.should == false + io.closed_write?.should == false io = StringIO.open(+"example", "wb+") - io.closed_read?.should be_false - io.closed_write?.should be_false + io.closed_read?.should == false + io.closed_write?.should == false io = StringIO.open(+"example", "a") - io.closed_read?.should be_true - io.closed_write?.should be_false + io.closed_read?.should == true + io.closed_write?.should == false io = StringIO.open(+"example", "ab") - io.closed_read?.should be_true - io.closed_write?.should be_false + io.closed_read?.should == true + io.closed_write?.should == false io = StringIO.open(+"example", "a+") - io.closed_read?.should be_false - io.closed_write?.should be_false + io.closed_read?.should == false + io.closed_write?.should == false io = StringIO.open(+"example", "ab+") - io.closed_read?.should be_false - io.closed_write?.should be_false + io.closed_read?.should == false + io.closed_write?.should == false end it "allows passing the mode as an Integer" do io = StringIO.open(+"example", IO::RDONLY) - io.closed_read?.should be_false - io.closed_write?.should be_true + io.closed_read?.should == false + io.closed_write?.should == true io = StringIO.open(+"example", IO::RDWR) - io.closed_read?.should be_false - io.closed_write?.should be_false + io.closed_read?.should == false + io.closed_write?.should == false io = StringIO.open(+"example", IO::WRONLY) - io.closed_read?.should be_true - io.closed_write?.should be_false + io.closed_read?.should == true + io.closed_write?.should == false io = StringIO.open(+"example", IO::WRONLY | IO::TRUNC) - io.closed_read?.should be_true - io.closed_write?.should be_false + io.closed_read?.should == true + io.closed_write?.should == false io = StringIO.open(+"example", IO::RDWR | IO::TRUNC) - io.closed_read?.should be_false - io.closed_write?.should be_false + io.closed_read?.should == false + io.closed_write?.should == false io = StringIO.open(+"example", IO::WRONLY | IO::APPEND) - io.closed_read?.should be_true - io.closed_write?.should be_false + io.closed_read?.should == true + io.closed_write?.should == false io = StringIO.open(+"example", IO::RDWR | IO::APPEND) - io.closed_read?.should be_false - io.closed_write?.should be_false + io.closed_read?.should == false + io.closed_write?.should == false end it "raises a FrozenError when passed a frozen String in truncate mode as StringIO backend" do - -> { StringIO.open("example".freeze, IO::TRUNC) }.should raise_error(FrozenError) + -> { StringIO.open("example".freeze, IO::TRUNC) }.should.raise(FrozenError) end it "tries to convert the passed mode to a String using #to_str" do @@ -143,34 +143,34 @@ describe "StringIO.open when passed [Object, mode]" do obj.should_receive(:to_str).and_return("r") io = StringIO.open(+"example", obj) - io.closed_read?.should be_false - io.closed_write?.should be_true + io.closed_read?.should == false + io.closed_write?.should == true end it "raises an Errno::EACCES error when passed a frozen string with a write-mode" do (str = "example").freeze - -> { StringIO.open(str, "r+") }.should raise_error(Errno::EACCES) - -> { StringIO.open(str, "w") }.should raise_error(Errno::EACCES) - -> { StringIO.open(str, "a") }.should raise_error(Errno::EACCES) + -> { StringIO.open(str, "r+") }.should.raise(Errno::EACCES) + -> { StringIO.open(str, "w") }.should.raise(Errno::EACCES) + -> { StringIO.open(str, "a") }.should.raise(Errno::EACCES) end end describe "StringIO.open when passed [Object]" do it "uses the passed Object as the StringIO backend" do io = StringIO.open(str = "example") - io.string.should equal(str) + io.string.should.equal?(str) end it "yields self to the passed block" do io = nil ret = StringIO.open(+"example") { |strio| io = strio } - io.should equal(ret) + io.should.equal?(ret) end it "sets the mode to read-write (r+)" do io = StringIO.open(+"example") - io.closed_read?.should be_false - io.closed_write?.should be_false + io.closed_read?.should == false + io.closed_write?.should == false io = StringIO.new(+"example") io.printf("%d", 123) @@ -187,8 +187,8 @@ describe "StringIO.open when passed [Object]" do it "automatically sets the mode to read-only when passed a frozen string" do (str = "example").freeze io = StringIO.open(str) - io.closed_read?.should be_false - io.closed_write?.should be_true + io.closed_read?.should == false + io.closed_write?.should == true end end @@ -196,13 +196,13 @@ describe "StringIO.open when passed no arguments" do it "yields self to the passed block" do io = nil ret = StringIO.open { |strio| io = strio } - io.should equal(ret) + io.should.equal?(ret) end it "sets the mode to read-write (r+)" do io = StringIO.open - io.closed_read?.should be_false - io.closed_write?.should be_false + io.closed_read?.should == false + io.closed_write?.should == false io = StringIO.new(+"example") io.printf("%d", 123) diff --git a/spec/ruby/library/stringio/path_spec.rb b/spec/ruby/library/stringio/path_spec.rb index 1184ca523f..dcb77b1df8 100644 --- a/spec/ruby/library/stringio/path_spec.rb +++ b/spec/ruby/library/stringio/path_spec.rb @@ -3,6 +3,6 @@ require_relative 'fixtures/classes' describe "StringIO#path" do it "is not defined" do - -> { StringIO.new("path").path }.should raise_error(NoMethodError) + -> { StringIO.new("path").path }.should.raise(NoMethodError) end end diff --git a/spec/ruby/library/stringio/pid_spec.rb b/spec/ruby/library/stringio/pid_spec.rb index 08f2d7ab1a..7a729fbe41 100644 --- a/spec/ruby/library/stringio/pid_spec.rb +++ b/spec/ruby/library/stringio/pid_spec.rb @@ -3,6 +3,6 @@ require_relative 'fixtures/classes' describe "StringIO#pid" do it "returns nil" do - StringIO.new("pid").pid.should be_nil + StringIO.new("pid").pid.should == nil end end diff --git a/spec/ruby/library/stringio/pos_spec.rb b/spec/ruby/library/stringio/pos_spec.rb index 81be5f01a5..16f068b049 100644 --- a/spec/ruby/library/stringio/pos_spec.rb +++ b/spec/ruby/library/stringio/pos_spec.rb @@ -1,9 +1,17 @@ require_relative '../../spec_helper' require_relative 'fixtures/classes' -require_relative 'shared/tell' describe "StringIO#pos" do - it_behaves_like :stringio_tell, :pos + before :each do + @io = StringIOSpecs.build + end + + it "returns the current byte offset" do + @io.getc + @io.pos.should == 1 + @io.read(7) + @io.pos.should == 8 + end end describe "StringIO#pos=" do @@ -17,7 +25,7 @@ describe "StringIO#pos=" do end it "raises an EINVAL if given a negative argument" do - -> { @io.pos = -10 }.should raise_error(Errno::EINVAL) + -> { @io.pos = -10 }.should.raise(Errno::EINVAL) end it "updates the current byte offset after reaching EOF" do diff --git a/spec/ruby/library/stringio/print_spec.rb b/spec/ruby/library/stringio/print_spec.rb index 00c33367dc..48728e5f14 100644 --- a/spec/ruby/library/stringio/print_spec.rb +++ b/spec/ruby/library/stringio/print_spec.rb @@ -29,7 +29,7 @@ describe "StringIO#print" do end it "returns nil" do - @io.print(1, 2, 3).should be_nil + @io.print(1, 2, 3).should == nil end it "pads self with \\000 when the current position is after the end" do @@ -52,10 +52,10 @@ describe "StringIO#print" do it "updates the current position" do @io.print(1, 2, 3) - @io.pos.should eql(3) + @io.pos.should.eql?(3) @io.print(1, 2, 3) - @io.pos.should eql(6) + @io.pos.should.eql?(6) end it "correctly updates the current position when honoring the output record separator global" do @@ -64,7 +64,7 @@ describe "StringIO#print" do begin @io.print(5, 6, 7, 8) - @io.pos.should eql(5) + @io.pos.should.eql?(5) ensure suppress_warning {$\ = old_rs} end @@ -86,17 +86,17 @@ describe "StringIO#print when in append mode" do it "correctly updates self's position" do @io.print(", testing") - @io.pos.should eql(16) + @io.pos.should.eql?(16) end end describe "StringIO#print when self is not writable" do it "raises an IOError" do io = StringIO.new(+"test", "r") - -> { io.print("test") }.should raise_error(IOError) + -> { io.print("test") }.should.raise(IOError) io = StringIO.new(+"test") io.close_write - -> { io.print("test") }.should raise_error(IOError) + -> { io.print("test") }.should.raise(IOError) end end diff --git a/spec/ruby/library/stringio/printf_spec.rb b/spec/ruby/library/stringio/printf_spec.rb index ca82e84757..ae7e0af729 100644 --- a/spec/ruby/library/stringio/printf_spec.rb +++ b/spec/ruby/library/stringio/printf_spec.rb @@ -8,7 +8,7 @@ describe "StringIO#printf" do end it "returns nil" do - @io.printf("%d %04x", 123, 123).should be_nil + @io.printf("%d %04x", 123, 123).should == nil end it "pads self with \\000 when the current position is after the end" do @@ -24,10 +24,10 @@ describe "StringIO#printf" do it "updates the current position" do @io.printf("%d %04x", 123, 123) - @io.pos.should eql(8) + @io.pos.should.eql?(8) @io.printf("%d %04x", 123, 123) - @io.pos.should eql(16) + @io.pos.should.eql?(16) end describe "formatting" do @@ -56,7 +56,7 @@ describe "StringIO#printf when in read-write mode" do it "correctly updates self's position" do @io.printf("%s", "abc") - @io.pos.should eql(3) + @io.pos.should.eql?(3) end end @@ -75,17 +75,17 @@ describe "StringIO#printf when in append mode" do it "correctly updates self's position" do @io.printf("%d %04x", 123, 123) - @io.pos.should eql(15) + @io.pos.should.eql?(15) end end describe "StringIO#printf when self is not writable" do it "raises an IOError" do io = StringIO.new(+"test", "r") - -> { io.printf("test") }.should raise_error(IOError) + -> { io.printf("test") }.should.raise(IOError) io = StringIO.new(+"test") io.close_write - -> { io.printf("test") }.should raise_error(IOError) + -> { io.printf("test") }.should.raise(IOError) end end diff --git a/spec/ruby/library/stringio/putc_spec.rb b/spec/ruby/library/stringio/putc_spec.rb index 9f1ac8ffb2..742f8623eb 100644 --- a/spec/ruby/library/stringio/putc_spec.rb +++ b/spec/ruby/library/stringio/putc_spec.rb @@ -22,7 +22,7 @@ describe "StringIO#putc when passed [String]" do it "returns the passed String" do str = "test" - @io.putc(str).should equal(str) + @io.putc(str).should.equal?(str) end it "correctly updates the current position" do @@ -79,7 +79,7 @@ describe "StringIO#putc when passed [Object]" do end it "raises a TypeError when the passed argument can't be coerced to Integer" do - -> { @io.putc(Object.new) }.should raise_error(TypeError) + -> { @io.putc(Object.new) }.should.raise(TypeError) end end @@ -94,10 +94,10 @@ end describe "StringIO#putc when self is not writable" do it "raises an IOError" do io = StringIO.new(+"test", "r") - -> { io.putc(?a) }.should raise_error(IOError) + -> { io.putc(?a) }.should.raise(IOError) io = StringIO.new(+"test") io.close_write - -> { io.putc("t") }.should raise_error(IOError) + -> { io.putc("t") }.should.raise(IOError) end end diff --git a/spec/ruby/library/stringio/puts_spec.rb b/spec/ruby/library/stringio/puts_spec.rb index 054ec8227f..ebe74d4a45 100644 --- a/spec/ruby/library/stringio/puts_spec.rb +++ b/spec/ruby/library/stringio/puts_spec.rb @@ -123,7 +123,7 @@ describe "StringIO#puts when passed no arguments" do end it "returns nil" do - @io.puts.should be_nil + @io.puts.should == nil end it "prints a newline" do @@ -158,18 +158,18 @@ describe "StringIO#puts when in append mode" do it "correctly updates self's position" do @io.puts(", testing") - @io.pos.should eql(17) + @io.pos.should.eql?(17) end end describe "StringIO#puts when self is not writable" do it "raises an IOError" do io = StringIO.new(+"test", "r") - -> { io.puts }.should raise_error(IOError) + -> { io.puts }.should.raise(IOError) io = StringIO.new(+"test") io.close_write - -> { io.puts }.should raise_error(IOError) + -> { io.puts }.should.raise(IOError) end end diff --git a/spec/ruby/library/stringio/read_nonblock_spec.rb b/spec/ruby/library/stringio/read_nonblock_spec.rb index 74736f7792..38ae7541ca 100644 --- a/spec/ruby/library/stringio/read_nonblock_spec.rb +++ b/spec/ruby/library/stringio/read_nonblock_spec.rb @@ -45,7 +45,7 @@ describe "StringIO#read_nonblock" do stringio.rewind stringio.read_nonblock(5).should == "hello" - stringio.read_nonblock(5, exception: false).should be_nil + stringio.read_nonblock(5, exception: false).should == nil end end end diff --git a/spec/ruby/library/stringio/read_spec.rb b/spec/ruby/library/stringio/read_spec.rb index e49f262127..9a2086a682 100644 --- a/spec/ruby/library/stringio/read_spec.rb +++ b/spec/ruby/library/stringio/read_spec.rb @@ -39,7 +39,7 @@ describe "StringIO#read when passed [length]" do it "returns nil when self's position is at the end" do @io.pos = 7 - @io.read(10).should be_nil + @io.read(10).should == nil end it "returns an empty String when length is 0" do @@ -57,6 +57,6 @@ describe "StringIO#read when passed length and a buffer" do result = @io.read(10, buf) buf.should == "abcdefghij" - result.should equal(buf) + result.should.equal?(buf) end end diff --git a/spec/ruby/library/stringio/readline_spec.rb b/spec/ruby/library/stringio/readline_spec.rb index 085360707f..3f026080e2 100644 --- a/spec/ruby/library/stringio/readline_spec.rb +++ b/spec/ruby/library/stringio/readline_spec.rb @@ -11,7 +11,7 @@ describe "StringIO#readline" do @io = StringIO.new("this>is>an>example") @io.pos = 36 - -> { @io.readline(">") }.should raise_error(IOError) + -> { @io.readline(">") }.should.raise(IOError) end end @@ -22,7 +22,7 @@ describe "StringIO#readline" do @io = StringIO.new("this>is>an>example") @io.pos = 36 - -> { @io.readline(3) }.should raise_error(IOError) + -> { @io.readline(3) }.should.raise(IOError) end end @@ -33,7 +33,7 @@ describe "StringIO#readline" do @io = StringIO.new("this>is>an>example") @io.pos = 36 - -> { @io.readline(">", 3) }.should raise_error(IOError) + -> { @io.readline(">", 3) }.should.raise(IOError) end end @@ -44,7 +44,7 @@ describe "StringIO#readline" do @io = StringIO.new("this>is>an>example") @io.pos = 36 - -> { @io.readline }.should raise_error(IOError) + -> { @io.readline }.should.raise(IOError) end end diff --git a/spec/ruby/library/stringio/readlines_spec.rb b/spec/ruby/library/stringio/readlines_spec.rb index ed7cc22b3d..821a8169e7 100644 --- a/spec/ruby/library/stringio/readlines_spec.rb +++ b/spec/ruby/library/stringio/readlines_spec.rb @@ -12,12 +12,12 @@ describe "StringIO#readlines when passed [separator]" do it "updates self's position based on the number of read bytes" do @io.readlines(">") - @io.pos.should eql(18) + @io.pos.should.eql?(18) end it "updates self's lineno based on the number of read lines" do @io.readlines(">") - @io.lineno.should eql(4) + @io.lineno.should.eql?(4) end it "does not change $_" do @@ -61,12 +61,12 @@ describe "StringIO#readlines when passed no argument" do it "updates self's position based on the number of read bytes" do @io.readlines - @io.pos.should eql(41) + @io.pos.should.eql?(41) end it "updates self's lineno based on the number of read lines" do @io.readlines - @io.lineno.should eql(3) + @io.lineno.should.eql?(3) end it "does not change $_" do @@ -84,11 +84,11 @@ end describe "StringIO#readlines when in write-only mode" do it "raises an IOError" do io = StringIO.new(+"xyz", "w") - -> { io.readlines }.should raise_error(IOError) + -> { io.readlines }.should.raise(IOError) io = StringIO.new("xyz") io.close_read - -> { io.readlines }.should raise_error(IOError) + -> { io.readlines }.should.raise(IOError) end end @@ -109,7 +109,7 @@ describe "StringIO#readlines when passed [limit]" do end it "raises ArgumentError when limit is 0" do - -> { @io.readlines(0) }.should raise_error(ArgumentError) + -> { @io.readlines(0) }.should.raise(ArgumentError) end it "ignores it when the limit is negative" do diff --git a/spec/ruby/library/stringio/readpartial_spec.rb b/spec/ruby/library/stringio/readpartial_spec.rb index f25cef4014..e05d9bded4 100644 --- a/spec/ruby/library/stringio/readpartial_spec.rb +++ b/spec/ruby/library/stringio/readpartial_spec.rb @@ -10,13 +10,7 @@ describe "StringIO#readpartial" 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 @@ -55,26 +57,46 @@ describe "StringIO#readpartial" do it "raises EOFError on EOF" do @string.readpartial(18).should == 'Stop, look, listen' - -> { @string.readpartial(10) }.should raise_error(EOFError) + -> { @string.readpartial(10) }.should.raise(EOFError) end it "discards the existing buffer content upon error" do buffer = +'hello' @string.readpartial(100) - -> { @string.readpartial(1, buffer) }.should raise_error(EOFError) - buffer.should be_empty + -> { @string.readpartial(1, buffer) }.should.raise(EOFError) + buffer.should.empty? end it "raises IOError if the stream is closed" do @string.close - -> { @string.readpartial(1) }.should raise_error(IOError) + -> { @string.readpartial(1) }.should.raise(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(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(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 7021ff17e5..3d4ae3a698 100644 --- a/spec/ruby/library/stringio/reopen_spec.rb +++ b/spec/ruby/library/stringio/reopen_spec.rb @@ -8,18 +8,18 @@ describe "StringIO#reopen when passed [Object, Integer]" do it "reopens self with the passed Object in the passed mode" do @io.reopen("reopened", IO::RDONLY) - @io.closed_read?.should be_false - @io.closed_write?.should be_true + @io.closed_read?.should == false + @io.closed_write?.should == true @io.string.should == "reopened" @io.reopen(+"reopened, twice", IO::WRONLY) - @io.closed_read?.should be_true - @io.closed_write?.should be_false + @io.closed_read?.should == true + @io.closed_write?.should == false @io.string.should == "reopened, twice" @io.reopen(+"reopened, another time", IO::RDWR) - @io.closed_read?.should be_false - @io.closed_write?.should be_false + @io.closed_read?.should == false + @io.closed_write?.should == false @io.string.should == "reopened, another time" end @@ -31,16 +31,16 @@ describe "StringIO#reopen when passed [Object, Integer]" do end it "raises a TypeError when the passed Object can't be converted to a String" do - -> { @io.reopen(Object.new, IO::RDWR) }.should raise_error(TypeError) + -> { @io.reopen(Object.new, IO::RDWR) }.should.raise(TypeError) end it "raises an Errno::EACCES when trying to reopen self with a frozen String in write-mode" do - -> { @io.reopen("burn".freeze, IO::WRONLY) }.should raise_error(Errno::EACCES) - -> { @io.reopen("burn".freeze, IO::WRONLY | IO::APPEND) }.should raise_error(Errno::EACCES) + -> { @io.reopen("burn".freeze, IO::WRONLY) }.should.raise(Errno::EACCES) + -> { @io.reopen("burn".freeze, IO::WRONLY | IO::APPEND) }.should.raise(Errno::EACCES) end it "raises a FrozenError when trying to reopen self with a frozen String in truncate-mode" do - -> { @io.reopen("burn".freeze, IO::RDONLY | IO::TRUNC) }.should raise_error(FrozenError) + -> { @io.reopen("burn".freeze, IO::RDONLY | IO::TRUNC) }.should.raise(FrozenError) end it "does not raise IOError when passed a frozen String in read-mode" do @@ -56,23 +56,23 @@ describe "StringIO#reopen when passed [Object, Object]" do it "reopens self with the passed Object in the passed mode" do @io.reopen("reopened", "r") - @io.closed_read?.should be_false - @io.closed_write?.should be_true + @io.closed_read?.should == false + @io.closed_write?.should == true @io.string.should == "reopened" @io.reopen(+"reopened, twice", "r+") - @io.closed_read?.should be_false - @io.closed_write?.should be_false + @io.closed_read?.should == false + @io.closed_write?.should == false @io.string.should == "reopened, twice" @io.reopen(+"reopened, another", "w+") - @io.closed_read?.should be_false - @io.closed_write?.should be_false + @io.closed_read?.should == false + @io.closed_write?.should == false @io.string.should == "" @io.reopen(+"reopened, another time", "r+") - @io.closed_read?.should be_false - @io.closed_write?.should be_false + @io.closed_read?.should == false + @io.closed_write?.should == false @io.string.should == "reopened, another time" end @@ -89,35 +89,35 @@ describe "StringIO#reopen when passed [Object, Object]" do end it "raises a TypeError when the passed Object can't be converted to a String using #to_str" do - -> { @io.reopen(Object.new, "r") }.should raise_error(TypeError) + -> { @io.reopen(Object.new, "r") }.should.raise(TypeError) end it "resets self's position to 0" do @io.read(5) @io.reopen(+"reopened") - @io.pos.should eql(0) + @io.pos.should.eql?(0) end it "resets self's line number to 0" do @io.gets @io.reopen(+"reopened") - @io.lineno.should eql(0) + @io.lineno.should.eql?(0) end it "tries to convert the passed mode Object to an Integer using #to_str" do obj = mock("to_str") obj.should_receive(:to_str).and_return("r") @io.reopen("reopened", obj) - @io.closed_read?.should be_false - @io.closed_write?.should be_true + @io.closed_read?.should == false + @io.closed_write?.should == true @io.string.should == "reopened" end it "raises an Errno::EACCES error when trying to reopen self with a frozen String in write-mode" do - -> { @io.reopen("burn".freeze, 'w') }.should raise_error(Errno::EACCES) - -> { @io.reopen("burn".freeze, 'w+') }.should raise_error(Errno::EACCES) - -> { @io.reopen("burn".freeze, 'a') }.should raise_error(Errno::EACCES) - -> { @io.reopen("burn".freeze, "r+") }.should raise_error(Errno::EACCES) + -> { @io.reopen("burn".freeze, 'w') }.should.raise(Errno::EACCES) + -> { @io.reopen("burn".freeze, 'w+') }.should.raise(Errno::EACCES) + -> { @io.reopen("burn".freeze, 'a') }.should.raise(Errno::EACCES) + -> { @io.reopen("burn".freeze, "r+") }.should.raise(Errno::EACCES) end it "does not raise IOError if a frozen string is passed in read mode" do @@ -136,8 +136,8 @@ describe "StringIO#reopen when passed [String]" do @io.reopen(+"reopened") - @io.closed_write?.should be_false - @io.closed_read?.should be_false + @io.closed_write?.should == false + @io.closed_read?.should == false @io.string.should == "reopened" end @@ -145,13 +145,13 @@ describe "StringIO#reopen when passed [String]" do it "resets self's position to 0" do @io.read(5) @io.reopen(+"reopened") - @io.pos.should eql(0) + @io.pos.should.eql?(0) end it "resets self's line number to 0" do @io.gets @io.reopen(+"reopened") - @io.lineno.should eql(0) + @io.lineno.should.eql?(0) end end @@ -161,13 +161,13 @@ describe "StringIO#reopen when passed [Object]" do end it "raises a TypeError when passed an Object that can't be converted to a StringIO" do - -> { @io.reopen(Object.new) }.should raise_error(TypeError) + -> { @io.reopen(Object.new) }.should.raise(TypeError) end it "does not try to convert the passed Object to a String using #to_str" do obj = mock("not to_str") obj.should_not_receive(:to_str) - -> { @io.reopen(obj) }.should raise_error(TypeError) + -> { @io.reopen(obj) }.should.raise(TypeError) end it "tries to convert the passed Object to a StringIO using #to_strio" do @@ -186,20 +186,20 @@ describe "StringIO#reopen when passed no arguments" do it "resets self's mode to read-write" do @io.close @io.reopen - @io.closed_read?.should be_false - @io.closed_write?.should be_false + @io.closed_read?.should == false + @io.closed_write?.should == false end it "resets self's position to 0" do @io.read(5) @io.reopen - @io.pos.should eql(0) + @io.pos.should.eql?(0) end it "resets self's line number to 0" do @io.gets @io.reopen - @io.lineno.should eql(0) + @io.lineno.should.eql?(0) end end diff --git a/spec/ruby/library/stringio/rewind_spec.rb b/spec/ruby/library/stringio/rewind_spec.rb index 5f885ecf81..8c48709d89 100644 --- a/spec/ruby/library/stringio/rewind_spec.rb +++ b/spec/ruby/library/stringio/rewind_spec.rb @@ -9,7 +9,7 @@ describe "StringIO#rewind" do end it "returns 0" do - @io.rewind.should eql(0) + @io.rewind.should.eql?(0) end it "resets the position" do diff --git a/spec/ruby/library/stringio/seek_spec.rb b/spec/ruby/library/stringio/seek_spec.rb index 253b5027a9..9043e0338f 100644 --- a/spec/ruby/library/stringio/seek_spec.rb +++ b/spec/ruby/library/stringio/seek_spec.rb @@ -9,18 +9,18 @@ describe "StringIO#seek" do it "seeks from the current position when whence is IO::SEEK_CUR" do @io.pos = 1 @io.seek(1, IO::SEEK_CUR) - @io.pos.should eql(2) + @io.pos.should.eql?(2) @io.seek(-1, IO::SEEK_CUR) - @io.pos.should eql(1) + @io.pos.should.eql?(1) end it "seeks from the end of self when whence is IO::SEEK_END" do @io.seek(3, IO::SEEK_END) - @io.pos.should eql(11) # Outside of the StringIO's content + @io.pos.should.eql?(11) # Outside of the StringIO's content @io.seek(-2, IO::SEEK_END) - @io.pos.should eql(6) + @io.pos.should.eql?(6) end it "seeks to an absolute position when whence is IO::SEEK_SET" do @@ -33,25 +33,25 @@ describe "StringIO#seek" do end it "raises an Errno::EINVAL error on negative amounts when whence is IO::SEEK_SET" do - -> { @io.seek(-5, IO::SEEK_SET) }.should raise_error(Errno::EINVAL) + -> { @io.seek(-5, IO::SEEK_SET) }.should.raise(Errno::EINVAL) end it "raises an Errno::EINVAL error on incorrect whence argument" do - -> { @io.seek(0, 3) }.should raise_error(Errno::EINVAL) - -> { @io.seek(0, -1) }.should raise_error(Errno::EINVAL) - -> { @io.seek(0, 2**16) }.should raise_error(Errno::EINVAL) - -> { @io.seek(0, -2**16) }.should raise_error(Errno::EINVAL) + -> { @io.seek(0, 3) }.should.raise(Errno::EINVAL) + -> { @io.seek(0, -1) }.should.raise(Errno::EINVAL) + -> { @io.seek(0, 2**16) }.should.raise(Errno::EINVAL) + -> { @io.seek(0, -2**16) }.should.raise(Errno::EINVAL) end it "tries to convert the passed Object to a String using #to_int" do obj = mock("to_int") obj.should_receive(:to_int).and_return(2) @io.seek(obj) - @io.pos.should eql(2) + @io.pos.should.eql?(2) end it "raises a TypeError when the passed Object can't be converted to an Integer" do - -> { @io.seek(Object.new) }.should raise_error(TypeError) + -> { @io.seek(Object.new) }.should.raise(TypeError) end end @@ -62,6 +62,6 @@ describe "StringIO#seek when self is closed" do end it "raises an IOError" do - -> { @io.seek(5) }.should raise_error(IOError) + -> { @io.seek(5) }.should.raise(IOError) end end diff --git a/spec/ruby/library/stringio/set_encoding_by_bom_spec.rb b/spec/ruby/library/stringio/set_encoding_by_bom_spec.rb index 1030aad042..b4583a7ad7 100644 --- a/spec/ruby/library/stringio/set_encoding_by_bom_spec.rb +++ b/spec/ruby/library/stringio/set_encoding_by_bom_spec.rb @@ -6,7 +6,7 @@ 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.set_encoding_by_bom.should == nil io.external_encoding.should == Encoding::ASCII_8BIT end @@ -82,7 +82,7 @@ describe "StringIO#set_encoding_by_bom" do it "returns nil if io is empty" do io = StringIO.new("".b, "rb") - io.set_encoding_by_bom.should be_nil + io.set_encoding_by_bom.should == nil io.external_encoding.should == Encoding::ASCII_8BIT end @@ -227,7 +227,7 @@ describe "StringIO#set_encoding_by_bom" do it "raises FrozenError when io is frozen" do io = StringIO.new() io.freeze - -> { io.set_encoding_by_bom }.should raise_error(FrozenError) + -> { io.set_encoding_by_bom }.should.raise(FrozenError) end it "does not raise FrozenError when initial string is frozen" do diff --git a/spec/ruby/library/stringio/shared/codepoints.rb b/spec/ruby/library/stringio/shared/codepoints.rb deleted file mode 100644 index 25333bb0fd..0000000000 --- a/spec/ruby/library/stringio/shared/codepoints.rb +++ /dev/null @@ -1,45 +0,0 @@ -# -*- encoding: utf-8 -*- -describe :stringio_codepoints, shared: true do - before :each do - @io = StringIO.new("∂φ/∂x = gaîté") - @enum = @io.send(@method) - end - - it "returns an Enumerator" do - @enum.should be_an_instance_of(Enumerator) - end - - it "yields each codepoint code in turn" do - @enum.to_a.should == [8706, 966, 47, 8706, 120, 32, 61, 32, 103, 97, 238, 116, 233] - end - - it "yields each codepoint starting from the current position" do - @io.pos = 15 - @enum.to_a.should == [238, 116, 233] - end - - it "raises an error if reading invalid sequence" do - @io.pos = 1 # inside of a multibyte sequence - -> { @enum.first }.should raise_error(ArgumentError) - end - - it "raises an IOError if not readable" do - @io.close_read - -> { @enum.to_a }.should raise_error(IOError) - - io = StringIO.new(+"xyz", "w") - -> { io.send(@method).to_a }.should raise_error(IOError) - end - - - it "calls the given block" do - r = [] - @io.send(@method){|c| r << c } - r.should == [8706, 966, 47, 8706, 120, 32, 61, 32, 103, 97, 238, 116, 233] - end - - it "returns self" do - @io.send(@method) {|l| l }.should equal(@io) - end - -end diff --git a/spec/ruby/library/stringio/shared/each.rb b/spec/ruby/library/stringio/shared/each.rb deleted file mode 100644 index 626b41a4d3..0000000000 --- a/spec/ruby/library/stringio/shared/each.rb +++ /dev/null @@ -1,209 +0,0 @@ -describe :stringio_each_separator, shared: true do - before :each do - @io = StringIO.new("a b c d e\n1 2 3 4 5") - end - - it "uses the passed argument as the line separator" do - seen = [] - @io.send(@method, " ") {|s| seen << s} - seen.should == ["a ", "b ", "c ", "d ", "e\n1 ", "2 ", "3 ", "4 ", "5"] - end - - it "does not change $_" do - $_ = "test" - @io.send(@method, " ") { |s| s} - $_.should == "test" - end - - it "returns self" do - @io.send(@method) {|l| l }.should equal(@io) - end - - it "tries to convert the passed separator to a String using #to_str" do - obj = mock("to_str") - obj.stub!(:to_str).and_return(" ") - - seen = [] - @io.send(@method, obj) { |l| seen << l } - seen.should == ["a ", "b ", "c ", "d ", "e\n1 ", "2 ", "3 ", "4 ", "5"] - end - - it "yields self's content starting from the current position when the passed separator is nil" do - seen = [] - io = StringIO.new("1 2 1 2 1 2") - io.pos = 2 - io.send(@method, nil) {|s| seen << s} - seen.should == ["2 1 2 1 2"] - 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 - -describe :stringio_each_no_arguments, shared: true do - before :each do - @io = StringIO.new("a b c d e\n1 2 3 4 5") - end - - it "yields each line to the passed block" do - seen = [] - @io.send(@method) {|s| seen << s } - seen.should == ["a b c d e\n", "1 2 3 4 5"] - end - - it "yields each line starting from the current position" do - seen = [] - @io.pos = 4 - @io.send(@method) {|s| seen << s } - seen.should == ["c d e\n", "1 2 3 4 5"] - end - - it "does not change $_" do - $_ = "test" - @io.send(@method) { |s| s} - $_.should == "test" - end - - it "uses $/ as the default line separator" do - seen = [] - begin - old_rs = $/ - suppress_warning {$/ = " "} - @io.send(@method) {|s| seen << s } - seen.should eql(["a ", "b ", "c ", "d ", "e\n1 ", "2 ", "3 ", "4 ", "5"]) - ensure - suppress_warning {$/ = old_rs} - end - end - - it "returns self" do - @io.send(@method) {|l| l }.should equal(@io) - end - - it "returns an Enumerator when passed no block" do - enum = @io.send(@method) - enum.instance_of?(Enumerator).should be_true - - seen = [] - enum.each { |b| seen << b } - seen.should == ["a b c d e\n", "1 2 3 4 5"] - end -end - -describe :stringio_each_not_readable, shared: true do - it "raises an IOError" do - 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") - io.close_read - -> { io.send(@method) { |b| b } }.should raise_error(IOError) - end -end - -describe :stringio_each_chomp, shared: true do - it "yields each line with removed newline characters to the passed block" do - seen = [] - io = StringIO.new("a b \rc d e\n1 2 3 4 5\r\nthe end") - io.send(@method, chomp: true) {|s| seen << s } - seen.should == ["a b \rc d e", "1 2 3 4 5", "the end"] - end - - it "returns each line with removed newline characters when called without block" do - seen = [] - io = StringIO.new("a b \rc d e\n1 2 3 4 5\r\nthe end") - enum = io.send(@method, chomp: true) - enum.each {|s| seen << s } - seen.should == ["a b \rc d e", "1 2 3 4 5", "the end"] - end -end - -describe :stringio_each_separator_and_chomp, shared: true do - it "yields each line with removed separator to the passed block" do - seen = [] - io = StringIO.new("a b \nc d e|1 2 3 4 5\n|the end") - io.send(@method, "|", chomp: true) {|s| seen << s } - seen.should == ["a b \nc d e", "1 2 3 4 5\n", "the end"] - end - - it "returns each line with removed separator when called without block" do - seen = [] - io = StringIO.new("a b \nc d e|1 2 3 4 5\n|the end") - enum = io.send(@method, "|", chomp: true) - enum.each {|s| seen << s } - seen.should == ["a b \nc d e", "1 2 3 4 5\n", "the end"] - end -end - -describe :stringio_each_limit, shared: true do - before :each do - @io = StringIO.new("a b c d e\n1 2 3 4 5") - end - - it "returns the data read until the limit is met" do - seen = [] - @io.send(@method, 4) { |s| seen << s } - 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 deleted file mode 100644 index b51fa38f2f..0000000000 --- a/spec/ruby/library/stringio/shared/each_byte.rb +++ /dev/null @@ -1,48 +0,0 @@ -describe :stringio_each_byte, shared: true do - before :each do - @io = StringIO.new("xyz") - end - - it "yields each character code in turn" do - seen = [] - @io.send(@method) { |b| seen << b } - seen.should == [120, 121, 122] - end - - it "updates the position before each yield" do - seen = [] - @io.send(@method) { |b| seen << @io.pos } - seen.should == [1, 2, 3] - end - - it "does not yield if the current position is out of bounds" do - @io.pos = 1000 - seen = nil - @io.send(@method) { |b| seen = b } - seen.should be_nil - end - - it "returns self" do - @io.send(@method) {}.should equal(@io) - end - - it "returns an Enumerator when passed no block" do - enum = @io.send(@method) - enum.instance_of?(Enumerator).should be_true - - seen = [] - enum.each { |b| seen << b } - seen.should == [120, 121, 122] - end -end - -describe :stringio_each_byte_not_readable, shared: true do - it "raises an IOError" do - io = StringIO.new(+"xyz", "w") - -> { io.send(@method) { |b| b } }.should raise_error(IOError) - - io = StringIO.new("xyz") - io.close_read - -> { io.send(@method) { |b| b } }.should raise_error(IOError) - end -end diff --git a/spec/ruby/library/stringio/shared/each_char.rb b/spec/ruby/library/stringio/shared/each_char.rb deleted file mode 100644 index 197237c1c8..0000000000 --- a/spec/ruby/library/stringio/shared/each_char.rb +++ /dev/null @@ -1,36 +0,0 @@ -# -*- encoding: utf-8 -*- -describe :stringio_each_char, shared: true do - before :each do - @io = StringIO.new("xyz äöü") - end - - it "yields each character code in turn" do - seen = [] - @io.send(@method) { |c| seen << c } - seen.should == ["x", "y", "z", " ", "ä", "ö", "ü"] - end - - it "returns self" do - @io.send(@method) {}.should equal(@io) - end - - it "returns an Enumerator when passed no block" do - enum = @io.send(@method) - enum.instance_of?(Enumerator).should be_true - - seen = [] - enum.each { |c| seen << c } - seen.should == ["x", "y", "z", " ", "ä", "ö", "ü"] - end -end - -describe :stringio_each_char_not_readable, shared: true do - it "raises an IOError" do - io = StringIO.new(+"xyz", "w") - -> { io.send(@method) { |b| b } }.should raise_error(IOError) - - io = StringIO.new("xyz") - io.close_read - -> { io.send(@method) { |b| b } }.should raise_error(IOError) - end -end diff --git a/spec/ruby/library/stringio/shared/eof.rb b/spec/ruby/library/stringio/shared/eof.rb deleted file mode 100644 index e0368a2892..0000000000 --- a/spec/ruby/library/stringio/shared/eof.rb +++ /dev/null @@ -1,24 +0,0 @@ -describe :stringio_eof, shared: true do - before :each do - @io = StringIO.new("eof") - end - - it "returns true when self's position is greater than or equal to self's size" do - @io.pos = 3 - @io.send(@method).should be_true - - @io.pos = 6 - @io.send(@method).should be_true - end - - it "returns false when self's position is less than self's size" do - @io.pos = 0 - @io.send(@method).should be_false - - @io.pos = 1 - @io.send(@method).should be_false - - @io.pos = 2 - @io.send(@method).should be_false - end -end diff --git a/spec/ruby/library/stringio/shared/getc.rb b/spec/ruby/library/stringio/shared/getc.rb index ba65040bce..a146b2d4cf 100644 --- a/spec/ruby/library/stringio/shared/getc.rb +++ b/spec/ruby/library/stringio/shared/getc.rb @@ -5,39 +5,39 @@ describe :stringio_getc, shared: true do it "increases self's position by one" do @io.send(@method) - @io.pos.should eql(1) + @io.pos.should.eql?(1) @io.send(@method) - @io.pos.should eql(2) + @io.pos.should.eql?(2) @io.send(@method) - @io.pos.should eql(3) + @io.pos.should.eql?(3) end it "returns nil when called at the end of self" do @io.pos = 7 - @io.send(@method).should be_nil - @io.send(@method).should be_nil - @io.send(@method).should be_nil + @io.send(@method).should == nil + @io.send(@method).should == nil + @io.send(@method).should == nil end it "does not increase self's position when called at the end of file" do @io.pos = 7 @io.send(@method) - @io.pos.should eql(7) + @io.pos.should.eql?(7) @io.send(@method) - @io.pos.should eql(7) + @io.pos.should.eql?(7) end end describe :stringio_getc_not_readable, shared: true do it "raises an IOError" do io = StringIO.new(+"xyz", "w") - -> { io.send(@method) }.should raise_error(IOError) + -> { io.send(@method) }.should.raise(IOError) io = StringIO.new("xyz") io.close_read - -> { io.send(@method) }.should raise_error(IOError) + -> { io.send(@method) }.should.raise(IOError) end end diff --git a/spec/ruby/library/stringio/shared/gets.rb b/spec/ruby/library/stringio/shared/gets.rb index 8396b161f1..16039b18ef 100644 --- a/spec/ruby/library/stringio/shared/gets.rb +++ b/spec/ruby/library/stringio/shared/gets.rb @@ -33,13 +33,13 @@ describe :stringio_gets_separator, shared: true do it "updates self's lineno by one" do @io.send(@method, ">") - @io.lineno.should eql(1) + @io.lineno.should.eql?(1) @io.send(@method, ">") - @io.lineno.should eql(2) + @io.lineno.should.eql?(2) @io.send(@method, ">") - @io.lineno.should eql(3) + @io.lineno.should.eql?(3) end it "returns the next paragraph when the passed separator is an empty String" do @@ -88,13 +88,13 @@ describe :stringio_gets_limit, shared: true do it "updates self's lineno by one" do @io.send(@method, 3) - @io.lineno.should eql(1) + @io.lineno.should.eql?(1) @io.send(@method, 3) - @io.lineno.should eql(2) + @io.lineno.should.eql?(2) @io.send(@method, 3) - @io.lineno.should eql(3) + @io.lineno.should.eql?(3) end it "tries to convert the passed limit to an Integer using #to_int" do @@ -146,13 +146,13 @@ describe :stringio_gets_separator_and_limit, shared: true do it "updates self's lineno by one" do @io.send(@method, '>', 3) - @io.lineno.should eql(1) + @io.lineno.should.eql?(1) @io.send(@method, '>', 3) - @io.lineno.should eql(2) + @io.lineno.should.eql?(2) @io.send(@method, '>', 3) - @io.lineno.should eql(3) + @io.lineno.should.eql?(3) end it "tries to convert the passed separator to a String using #to_str" do @@ -204,24 +204,24 @@ describe :stringio_gets_no_argument, shared: true do it "updates self's position" do @io.send(@method) - @io.pos.should eql(8) + @io.pos.should.eql?(8) @io.send(@method) - @io.pos.should eql(19) + @io.pos.should.eql?(19) @io.send(@method) - @io.pos.should eql(36) + @io.pos.should.eql?(36) end it "updates self's lineno" do @io.send(@method) - @io.lineno.should eql(1) + @io.lineno.should.eql?(1) @io.send(@method) - @io.lineno.should eql(2) + @io.lineno.should.eql?(2) @io.send(@method) - @io.lineno.should eql(3) + @io.lineno.should.eql?(3) end end end @@ -239,11 +239,11 @@ 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.send(@method) }.should.raise(IOError) io = StringIO.new("xyz") io.close_read - -> { io.send(@method) }.should raise_error(IOError) + -> { io.send(@method) }.should.raise(IOError) end end end diff --git a/spec/ruby/library/stringio/shared/isatty.rb b/spec/ruby/library/stringio/shared/isatty.rb deleted file mode 100644 index c9e7ee7321..0000000000 --- a/spec/ruby/library/stringio/shared/isatty.rb +++ /dev/null @@ -1,5 +0,0 @@ -describe :stringio_isatty, shared: true do - it "returns false" do - StringIO.new("tty").send(@method).should be_false - end -end diff --git a/spec/ruby/library/stringio/shared/length.rb b/spec/ruby/library/stringio/shared/length.rb deleted file mode 100644 index 60a4eb1bdd..0000000000 --- a/spec/ruby/library/stringio/shared/length.rb +++ /dev/null @@ -1,5 +0,0 @@ -describe :stringio_length, shared: true do - it "returns the length of the wrapped string" do - StringIO.new("example").send(@method).should == 7 - end -end diff --git a/spec/ruby/library/stringio/shared/read.rb b/spec/ruby/library/stringio/shared/read.rb index 22f76b0fb0..6e04e75dba 100644 --- a/spec/ruby/library/stringio/shared/read.rb +++ b/spec/ruby/library/stringio/shared/read.rb @@ -5,9 +5,9 @@ describe :stringio_read, shared: true do it "returns the passed buffer String" do # Note: Rubinius bug: - # @io.send(@method, 7, buffer = +"").should equal(buffer) + # @io.send(@method, 7, buffer = +"").should.equal?(buffer) ret = @io.send(@method, 7, buffer = +"") - ret.should equal(buffer) + ret.should.equal?(buffer) end it "reads length bytes and writes them to the buffer String" do @@ -42,11 +42,11 @@ describe :stringio_read, shared: true do end it "raises a TypeError when the passed buffer Object can't be converted to a String" do - -> { @io.send(@method, 7, Object.new) }.should raise_error(TypeError) + -> { @io.send(@method, 7, Object.new) }.should.raise(TypeError) end it "raises a FrozenError error when passed a frozen String as buffer" do - -> { @io.send(@method, 7, "".freeze) }.should raise_error(FrozenError) + -> { @io.send(@method, 7, "".freeze) }.should.raise(FrozenError) end end @@ -66,10 +66,10 @@ describe :stringio_read_length, shared: true do it "correctly updates the position" do @io.send(@method, 3) - @io.pos.should eql(3) + @io.pos.should.eql?(3) @io.send(@method, 999) - @io.pos.should eql(7) + @io.pos.should.eql?(7) end it "tries to convert the passed length to an Integer using #to_int" do @@ -79,11 +79,11 @@ describe :stringio_read_length, shared: true do end it "raises a TypeError when the passed length can't be converted to an Integer" do - -> { @io.send(@method, Object.new) }.should raise_error(TypeError) + -> { @io.send(@method, Object.new) }.should.raise(TypeError) end it "raises a TypeError when the passed length is negative" do - -> { @io.send(@method, -2) }.should raise_error(ArgumentError) + -> { @io.send(@method, -2) }.should.raise(ArgumentError) end it "returns a binary String" do @@ -105,13 +105,13 @@ describe :stringio_read_no_arguments, shared: true do it "correctly updates the current position" do @io.send(@method) - @io.pos.should eql(7) + @io.pos.should.eql?(7) end it "correctly update the current position in bytes when multi-byte characters are used" do @io.print("example\u03A3") # Overwrite the original string with 8 characters containing 9 bytes. @io.send(@method) - @io.pos.should eql(9) + @io.pos.should.eql?(9) end end @@ -129,17 +129,17 @@ describe :stringio_read_nil, shared: true do it "updates the current position" do @io.send(@method, nil) - @io.pos.should eql(7) + @io.pos.should.eql?(7) end end describe :stringio_read_not_readable, shared: true do it "raises an IOError" do io = StringIO.new(+"test", "w") - -> { io.send(@method) }.should raise_error(IOError) + -> { io.send(@method) }.should.raise(IOError) io = StringIO.new("test") io.close_read - -> { io.send(@method) }.should raise_error(IOError) + -> { io.send(@method) }.should.raise(IOError) end end diff --git a/spec/ruby/library/stringio/shared/readchar.rb b/spec/ruby/library/stringio/shared/readchar.rb index 72d7446c36..5ac28e0743 100644 --- a/spec/ruby/library/stringio/shared/readchar.rb +++ b/spec/ruby/library/stringio/shared/readchar.rb @@ -13,17 +13,17 @@ describe :stringio_readchar, shared: true do it "raises an EOFError when self is at the end" do @io.pos = 7 - -> { @io.send(@method) }.should raise_error(EOFError) + -> { @io.send(@method) }.should.raise(EOFError) end end describe :stringio_readchar_not_readable, shared: true do it "raises an IOError" do io = StringIO.new(+"a b c d e", "w") - -> { io.send(@method) }.should raise_error(IOError) + -> { io.send(@method) }.should.raise(IOError) io = StringIO.new("a b c d e") io.close_read - -> { io.send(@method) }.should raise_error(IOError) + -> { io.send(@method) }.should.raise(IOError) end end diff --git a/spec/ruby/library/stringio/shared/sysread.rb b/spec/ruby/library/stringio/shared/sysread.rb index 3e23fbc233..bc448d3379 100644 --- a/spec/ruby/library/stringio/shared/sysread.rb +++ b/spec/ruby/library/stringio/shared/sysread.rb @@ -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.send(@method, 1) }.should raise_error(EOFError) + -> { @io.send(@method, 1) }.should.raise(EOFError) end end diff --git a/spec/ruby/library/stringio/shared/tell.rb b/spec/ruby/library/stringio/shared/tell.rb deleted file mode 100644 index 852c51c192..0000000000 --- a/spec/ruby/library/stringio/shared/tell.rb +++ /dev/null @@ -1,12 +0,0 @@ -describe :stringio_tell, shared: true do - before :each do - @io = StringIOSpecs.build - end - - it "returns the current byte offset" do - @io.getc - @io.send(@method).should == 1 - @io.read(7) - @io.send(@method).should == 8 - end -end diff --git a/spec/ruby/library/stringio/shared/write.rb b/spec/ruby/library/stringio/shared/write.rb index 4661658baf..b6bffe7f12 100644 --- a/spec/ruby/library/stringio/shared/write.rb +++ b/spec/ruby/library/stringio/shared/write.rb @@ -42,7 +42,7 @@ describe :stringio_write_string, shared: true do it "updates self's position" do @io.send(@method, 'test') - @io.pos.should eql(4) + @io.pos.should.eql?(4) end it "handles concurrent writes correctly" do @@ -107,11 +107,11 @@ end describe :stringio_write_not_writable, shared: true do it "raises an IOError" do io = StringIO.new(+"test", "r") - -> { io.send(@method, "test") }.should raise_error(IOError) + -> { io.send(@method, "test") }.should.raise(IOError) io = StringIO.new(+"test") io.close_write - -> { io.send(@method, "test") }.should raise_error(IOError) + -> { io.send(@method, "test") }.should.raise(IOError) end end @@ -130,6 +130,6 @@ describe :stringio_write_append, shared: true do it "correctly updates self's position" do @io.send(@method, ", testing") - @io.pos.should eql(16) + @io.pos.should.eql?(16) end end diff --git a/spec/ruby/library/stringio/size_spec.rb b/spec/ruby/library/stringio/size_spec.rb index f674d22db9..33e574ddae 100644 --- a/spec/ruby/library/stringio/size_spec.rb +++ b/spec/ruby/library/stringio/size_spec.rb @@ -1,7 +1,8 @@ require_relative '../../spec_helper' -require_relative 'fixtures/classes' -require_relative 'shared/length' +require 'stringio' describe "StringIO#size" do - it_behaves_like :stringio_length, :size + it "is an alias of StringIO#length" do + StringIO.instance_method(:size).should == StringIO.instance_method(:length) + end end diff --git a/spec/ruby/library/stringio/string_spec.rb b/spec/ruby/library/stringio/string_spec.rb index 1ed5233ba6..3b27243da9 100644 --- a/spec/ruby/library/stringio/string_spec.rb +++ b/spec/ruby/library/stringio/string_spec.rb @@ -4,7 +4,7 @@ require_relative 'fixtures/classes' describe "StringIO#string" do it "returns the underlying string" do io = StringIO.new(str = "hello") - io.string.should equal(str) + io.string.should.equal?(str) end end @@ -15,25 +15,25 @@ describe "StringIO#string=" do it "returns the passed String" do str = "test" - (@io.string = str).should equal(str) + (@io.string = str).should.equal?(str) end it "changes the underlying string" do str = "hello" @io.string = str - @io.string.should equal(str) + @io.string.should.equal?(str) end it "resets the position" do @io.pos = 1 @io.string = "other" - @io.pos.should eql(0) + @io.pos.should.eql?(0) end it "resets the line number" do @io.lineno = 1 @io.string = "other" - @io.lineno.should eql(0) + @io.lineno.should.eql?(0) end it "tries to convert the passed Object to a String using #to_str" do @@ -45,6 +45,6 @@ describe "StringIO#string=" do end it "raises a TypeError when the passed Object can't be converted to an Integer" do - -> { @io.seek(Object.new) }.should raise_error(TypeError) + -> { @io.seek(Object.new) }.should.raise(TypeError) end end diff --git a/spec/ruby/library/stringio/stringio_spec.rb b/spec/ruby/library/stringio/stringio_spec.rb index 5ef42b3390..dee0364ab0 100644 --- a/spec/ruby/library/stringio/stringio_spec.rb +++ b/spec/ruby/library/stringio/stringio_spec.rb @@ -3,6 +3,6 @@ require "stringio" describe "StringIO" do it "includes the Enumerable module" do - StringIO.should include(Enumerable) + StringIO.should.include?(Enumerable) end end diff --git a/spec/ruby/library/stringio/sync_spec.rb b/spec/ruby/library/stringio/sync_spec.rb index e717a5697b..d7d1209047 100644 --- a/spec/ruby/library/stringio/sync_spec.rb +++ b/spec/ruby/library/stringio/sync_spec.rb @@ -3,7 +3,7 @@ require_relative 'fixtures/classes' describe "StringIO#sync" do it "returns true" do - StringIO.new('').sync.should be_true + StringIO.new('').sync.should == true end end @@ -14,6 +14,6 @@ describe "StringIO#sync=" do it "does not change 'sync' status" do @io.sync = false - @io.sync.should be_true + @io.sync.should == true end end diff --git a/spec/ruby/library/stringio/sysread_spec.rb b/spec/ruby/library/stringio/sysread_spec.rb index fabb06dd9a..1403dab5cb 100644 --- a/spec/ruby/library/stringio/sysread_spec.rb +++ b/spec/ruby/library/stringio/sysread_spec.rb @@ -44,7 +44,7 @@ describe "StringIO#sysread when passed [length]" do it "raises an EOFError when self's position is at the end" do @io.pos = 7 - -> { @io.sysread(10) }.should raise_error(EOFError) + -> { @io.sysread(10) }.should.raise(EOFError) end it "returns an empty String when length is 0" do diff --git a/spec/ruby/library/stringio/tell_spec.rb b/spec/ruby/library/stringio/tell_spec.rb index 8350ee6f4d..80095999e9 100644 --- a/spec/ruby/library/stringio/tell_spec.rb +++ b/spec/ruby/library/stringio/tell_spec.rb @@ -1,7 +1,8 @@ require_relative '../../spec_helper' -require_relative 'fixtures/classes' -require_relative 'shared/tell' +require 'stringio' describe "StringIO#tell" do - it_behaves_like :stringio_tell, :tell + it "is an alias of StringIO#pos" do + StringIO.instance_method(:tell).should == StringIO.instance_method(:pos) + end end diff --git a/spec/ruby/library/stringio/truncate_spec.rb b/spec/ruby/library/stringio/truncate_spec.rb index 592ca5a6e1..7205261141 100644 --- a/spec/ruby/library/stringio/truncate_spec.rb +++ b/spec/ruby/library/stringio/truncate_spec.rb @@ -7,7 +7,7 @@ describe "StringIO#truncate when passed [length]" do end it "returns an Integer" do - @io.truncate(4).should be_kind_of(Integer) + @io.truncate(4).should.is_a?(Integer) end it "truncated the underlying string down to the passed length" do @@ -18,13 +18,13 @@ describe "StringIO#truncate when passed [length]" do it "does not create a copy of the underlying string" do io = StringIO.new(str = +"123456789") io.truncate(4) - io.string.should equal(str) + io.string.should.equal?(str) end it "does not change the position" do @io.pos = 7 @io.truncate(4) - @io.pos.should eql(7) + @io.pos.should.eql?(7) end it "can grow a string to a larger size, padding it with \\000" do @@ -33,8 +33,8 @@ describe "StringIO#truncate when passed [length]" do end it "raises an Errno::EINVAL when the passed length is negative" do - -> { @io.truncate(-1) }.should raise_error(Errno::EINVAL) - -> { @io.truncate(-10) }.should raise_error(Errno::EINVAL) + -> { @io.truncate(-1) }.should.raise(Errno::EINVAL) + -> { @io.truncate(-10) }.should.raise(Errno::EINVAL) end it "tries to convert the passed length to an Integer using #to_int" do @@ -46,17 +46,17 @@ describe "StringIO#truncate when passed [length]" do end it "raises a TypeError when the passed length can't be converted to an Integer" do - -> { @io.truncate(Object.new) }.should raise_error(TypeError) + -> { @io.truncate(Object.new) }.should.raise(TypeError) end end describe "StringIO#truncate when self is not writable" do it "raises an IOError" do io = StringIO.new(+"test", "r") - -> { io.truncate(2) }.should raise_error(IOError) + -> { io.truncate(2) }.should.raise(IOError) io = StringIO.new(+"test") io.close_write - -> { io.truncate(2) }.should raise_error(IOError) + -> { io.truncate(2) }.should.raise(IOError) end end diff --git a/spec/ruby/library/stringio/tty_spec.rb b/spec/ruby/library/stringio/tty_spec.rb index c6293dcbd7..87e22d49a5 100644 --- a/spec/ruby/library/stringio/tty_spec.rb +++ b/spec/ruby/library/stringio/tty_spec.rb @@ -1,7 +1,8 @@ require_relative '../../spec_helper' -require_relative 'fixtures/classes' -require_relative 'shared/isatty' +require 'stringio' describe "StringIO#tty?" do - it_behaves_like :stringio_isatty, :tty? + it "returns false" do + StringIO.new("tty").tty?.should == false + end end diff --git a/spec/ruby/library/stringio/ungetc_spec.rb b/spec/ruby/library/stringio/ungetc_spec.rb index bceafa79ff..8753ac9666 100644 --- a/spec/ruby/library/stringio/ungetc_spec.rb +++ b/spec/ruby/library/stringio/ungetc_spec.rb @@ -14,13 +14,13 @@ describe "StringIO#ungetc when passed [char]" do it "returns nil" do @io.pos = 1 - @io.ungetc(?A).should be_nil + @io.ungetc(?A).should == nil end it "decreases the current position by one" do @io.pos = 2 @io.ungetc(?A) - @io.pos.should eql(1) + @io.pos.should.eql?(1) end it "pads with \\000 when the current position is after the end" do @@ -39,7 +39,7 @@ describe "StringIO#ungetc when passed [char]" do end it "raises a TypeError when the passed length can't be converted to an Integer or String" do - -> { @io.ungetc(Object.new) }.should raise_error(TypeError) + -> { @io.ungetc(Object.new) }.should.raise(TypeError) end end @@ -47,12 +47,12 @@ describe "StringIO#ungetc when self is not readable" do it "raises an IOError" do io = StringIO.new(+"test", "w") io.pos = 1 - -> { io.ungetc(?A) }.should raise_error(IOError) + -> { io.ungetc(?A) }.should.raise(IOError) io = StringIO.new(+"test") io.pos = 1 io.close_read - -> { io.ungetc(?A) }.should raise_error(IOError) + -> { io.ungetc(?A) }.should.raise(IOError) end end @@ -62,11 +62,11 @@ end # it "raises an IOError" do # io = StringIO.new(+"test", "r") # io.pos = 1 -# lambda { io.ungetc(?A) }.should raise_error(IOError) +# lambda { io.ungetc(?A) }.should.raise(IOError) # # io = StringIO.new(+"test") # io.pos = 1 # io.close_write -# lambda { io.ungetc(?A) }.should raise_error(IOError) +# lambda { io.ungetc(?A) }.should.raise(IOError) # end # end diff --git a/spec/ruby/library/stringscanner/append_spec.rb b/spec/ruby/library/stringscanner/append_spec.rb index fef5dcf2bd..68747d52d7 100644 --- a/spec/ruby/library/stringscanner/append_spec.rb +++ b/spec/ruby/library/stringscanner/append_spec.rb @@ -1,11 +1,33 @@ require_relative '../../spec_helper' -require_relative 'shared/concat' require 'strscan' describe "StringScanner#<<" do - it_behaves_like :strscan_concat, :<< + it "concatenates the given argument to self and returns self" do + s = StringScanner.new(+"hello ") + (s. << 'world').should == s + s.string.should == "hello world" + s.eos?.should == false + end + + it "raises a TypeError if the given argument can't be converted to a String" do + -> { StringScanner.new('hello') << :world }.should.raise(TypeError) + -> { StringScanner.new('hello') << mock('x') }.should.raise(TypeError) + end end describe "StringScanner#<< when passed an Integer" do - it_behaves_like :strscan_concat_fixnum, :<< + it "raises a TypeError" do + a = StringScanner.new("hello world") + -> { a << 333 }.should.raise(TypeError) + b = StringScanner.new("") + -> { b << (256 * 3 + 64) }.should.raise(TypeError) + -> { b << -200 }.should.raise(TypeError) + end + + it "doesn't call to_int on the argument" do + x = mock('x') + x.should_not_receive(:to_int) + + -> { StringScanner.new("") << x }.should.raise(TypeError) + end end diff --git a/spec/ruby/library/stringscanner/beginning_of_line_spec.rb b/spec/ruby/library/stringscanner/beginning_of_line_spec.rb index 3f6f0da75f..ae97f52fe0 100644 --- a/spec/ruby/library/stringscanner/beginning_of_line_spec.rb +++ b/spec/ruby/library/stringscanner/beginning_of_line_spec.rb @@ -1,7 +1,28 @@ require_relative '../../spec_helper' -require_relative 'shared/bol' require 'strscan' describe "StringScanner#beginning_of_line?" do - it_behaves_like :strscan_bol, :beginning_of_line? + it "returns true if the scan pointer is at the beginning of the line, false otherwise" do + s = StringScanner.new("This is a test") + s.beginning_of_line?.should == true + s.scan(/This/) + s.beginning_of_line?.should == false + s.terminate + s.beginning_of_line?.should == false + + s = StringScanner.new("hello\nworld") + s.beginning_of_line?.should == true + s.scan(/\w+/) + s.beginning_of_line?.should == false + s.scan(/\n/) + s.beginning_of_line?.should == true + s.unscan + s.beginning_of_line?.should == false + end + + it "returns true if the scan pointer is at the end of the line of an empty string." do + s = StringScanner.new('') + s.terminate + s.beginning_of_line?.should == true + end end diff --git a/spec/ruby/library/stringscanner/bol_spec.rb b/spec/ruby/library/stringscanner/bol_spec.rb index d31766e0e2..1d10c8f7c0 100644 --- a/spec/ruby/library/stringscanner/bol_spec.rb +++ b/spec/ruby/library/stringscanner/bol_spec.rb @@ -1,7 +1,8 @@ require_relative '../../spec_helper' -require_relative 'shared/bol' require 'strscan' describe "StringScanner#bol?" do - it_behaves_like :strscan_bol, :bol? + it "is an alias of StringScanner#beginning_of_line?" do + StringScanner.instance_method(:bol?).should == StringScanner.instance_method(:beginning_of_line?) + end end diff --git a/spec/ruby/library/stringscanner/check_spec.rb b/spec/ruby/library/stringscanner/check_spec.rb index 235f2f22e9..232158b09e 100644 --- a/spec/ruby/library/stringscanner/check_spec.rb +++ b/spec/ruby/library/stringscanner/check_spec.rb @@ -33,33 +33,31 @@ describe "StringScanner#check" do it "returns nil when matching failed" do @s.check(/(?<a>2008)/) @s.should_not.matched? - @s[:a].should be_nil + @s[:a].should == nil end end context "when #check was called with a String pattern" do # https://github.com/ruby/strscan/issues/139 - ruby_version_is ""..."3.5" do # Don't run on 3.5.0dev that already contains not released fixes 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 + @s[:a].should == nil end 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) + -> { @s[:a] }.should.raise(IndexError) end end it "returns nil when matching failed" do @s.check("2008") @s.should_not.matched? - @s[:a].should be_nil + @s[:a].should == nil end it "returns a matching substring when given Integer index" do @@ -68,7 +66,6 @@ describe "StringScanner#check" do end # https://github.com/ruby/strscan/issues/135 - ruby_version_is ""..."3.5" do # Don't run on 3.5.0dev that already contains not released fixes 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)/) @@ -77,10 +74,9 @@ describe "StringScanner#check" do @s.check("This") @s.should.matched? - @s[:a].should be_nil + @s[:a].should == nil end 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)/) @@ -89,7 +85,7 @@ describe "StringScanner#check" do @s.check("This") @s.should.matched? - -> { @s[:a] }.should raise_error(IndexError) + -> { @s[:a] }.should.raise(IndexError) end end end diff --git a/spec/ruby/library/stringscanner/check_until_spec.rb b/spec/ruby/library/stringscanner/check_until_spec.rb index 701a703ebe..b4ef35d9f7 100644 --- a/spec/ruby/library/stringscanner/check_until_spec.rb +++ b/spec/ruby/library/stringscanner/check_until_spec.rb @@ -24,7 +24,7 @@ describe "StringScanner#check_until" do it "raises TypeError if given a String" do -> { @s.check_until('T') - }.should raise_error(TypeError, 'wrong argument type String (expected Regexp)') + }.should.raise(TypeError, 'wrong argument type String (expected Regexp)') end end @@ -35,7 +35,6 @@ describe "StringScanner#check_until" do end # https://github.com/ruby/strscan/issues/131 - ruby_version_is ""..."3.5" do # Don't run on 3.5.0dev that already contains not released fixes 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") @@ -45,7 +44,6 @@ describe "StringScanner#check_until" do @s.post_match.should == " test" end 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 @@ -69,34 +67,32 @@ describe "StringScanner#check_until" do it "returns nil when matching failed" do @s.check_until(/(?<a>2008)/) @s.should_not.matched? - @s[:a].should be_nil + @s[:a].should == 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 - ruby_version_is ""..."3.5" do # Don't run on 3.5.0dev that already contains not released fixes 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 + @s[:a].should == nil end 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) + -> { @s[:a] }.should.raise(IndexError) end end it "returns nil when matching failed" do @s.check_until("2008") @s.should_not.matched? - @s[:a].should be_nil + @s[:a].should == nil end it "returns a matching substring when given Integer index" do @@ -105,7 +101,6 @@ describe "StringScanner#check_until" do end # https://github.com/ruby/strscan/issues/135 - ruby_version_is ""..."3.5" do # Don't run on 3.5.0dev that already contains not released fixes 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)/) @@ -114,10 +109,9 @@ describe "StringScanner#check_until" do @s.check_until("This") @s.should.matched? - @s[:a].should be_nil + @s[:a].should == nil end 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)/) @@ -126,7 +120,7 @@ describe "StringScanner#check_until" do @s.check_until("This") @s.should.matched? - -> { @s[:a] }.should raise_error(IndexError) + -> { @s[:a] }.should.raise(IndexError) 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/concat_spec.rb b/spec/ruby/library/stringscanner/concat_spec.rb index 4f790e2505..716268c956 100644 --- a/spec/ruby/library/stringscanner/concat_spec.rb +++ b/spec/ruby/library/stringscanner/concat_spec.rb @@ -1,11 +1,8 @@ require_relative '../../spec_helper' -require_relative 'shared/concat' require 'strscan' describe "StringScanner#concat" do - it_behaves_like :strscan_concat, :concat -end - -describe "StringScanner#concat when passed an Integer" do - it_behaves_like :strscan_concat_fixnum, :concat + it "is an alias of StringScanner#<<" do + StringScanner.instance_method(:concat).should == StringScanner.instance_method(:<<) + end end diff --git a/spec/ruby/library/stringscanner/dup_spec.rb b/spec/ruby/library/stringscanner/dup_spec.rb index 0fc52a1477..0118964526 100644 --- a/spec/ruby/library/stringscanner/dup_spec.rb +++ b/spec/ruby/library/stringscanner/dup_spec.rb @@ -15,7 +15,7 @@ describe "StringScanner#dup" do it "copies the passed StringScanner's position to self" do @orig_s.pos = 5 s = @orig_s.dup - s.pos.should eql(5) + s.pos.should.eql?(5) end it "copies previous match state" do @@ -34,6 +34,6 @@ describe "StringScanner#dup" do it "copies the passed StringScanner scan pointer to self" do @orig_s.terminate s = @orig_s.dup - s.eos?.should be_true + s.eos?.should == true end end diff --git a/spec/ruby/library/stringscanner/element_reference_spec.rb b/spec/ruby/library/stringscanner/element_reference_spec.rb index 91b6d86dc7..bcd48ede61 100644 --- a/spec/ruby/library/stringscanner/element_reference_spec.rb +++ b/spec/ruby/library/stringscanner/element_reference_spec.rb @@ -7,8 +7,8 @@ describe "StringScanner#[]" do end it "returns nil if there is no current match" do - @s[0].should be_nil - @s[:wday].should be_nil + @s[0].should == nil + @s[:wday].should == nil end it "returns the n-th subgroup in the most recent match" do @@ -35,24 +35,24 @@ describe "StringScanner#[]" do it "raises a TypeError if the given index is nil" do @s.scan(/(\w+) (\w+) (\d+) /) - -> { @s[nil]}.should raise_error(TypeError) + -> { @s[nil]}.should.raise(TypeError) end it "raises a TypeError when a Range is as argument" do @s.scan(/(\w+) (\w+) (\d+) /) - -> { @s[0..2]}.should raise_error(TypeError) + -> { @s[0..2]}.should.raise(TypeError) end 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) + -> { @s["wday"]}.should.raise(IndexError) + -> { @s[:wday]}.should.raise(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) + -> { @s["wday"]}.should.raise(IndexError) + -> { @s[:wday]}.should.raise(IndexError) end it "returns named capture" do 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 3f40c7a5a5..2207622366 100644 --- a/spec/ruby/library/stringscanner/exist_spec.rb +++ b/spec/ruby/library/stringscanner/exist_spec.rb @@ -32,7 +32,7 @@ describe "StringScanner#exist?" do it "raises TypeError if given a String" do -> { @s.exist?('T') - }.should raise_error(TypeError, 'wrong argument type String (expected Regexp)') + }.should.raise(TypeError, 'wrong argument type String (expected Regexp)') end end @@ -57,34 +57,32 @@ describe "StringScanner#exist?" do it "returns nil when matching failed" do @s.exist?(/(?<a>2008)/) @s.should_not.matched? - @s[:a].should be_nil + @s[:a].should == 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 - ruby_version_is ""..."3.5" do # Don't run on 3.5.0dev that already contains not released fixes 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 + @s[:a].should == nil end 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) + -> { @s[:a] }.should.raise(IndexError) end end it "returns nil when matching failed" do @s.exist?("2008") @s.should_not.matched? - @s[:a].should be_nil + @s[:a].should == nil end it "returns a matching substring when given Integer index" do @@ -93,7 +91,6 @@ describe "StringScanner#exist?" do end # https://github.com/ruby/strscan/issues/135 - ruby_version_is ""..."3.5" do # Don't run on 3.5.0dev that already contains not released fixes 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)/) @@ -102,10 +99,9 @@ describe "StringScanner#exist?" do @s.exist?("This") @s.should.matched? - @s[:a].should be_nil + @s[:a].should == nil end 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)/) @@ -114,7 +110,7 @@ describe "StringScanner#exist?" do @s.exist?("This") @s.should.matched? - -> { @s[:a] }.should raise_error(IndexError) + -> { @s[:a] }.should.raise(IndexError) end end end diff --git a/spec/ruby/library/stringscanner/get_byte_spec.rb b/spec/ruby/library/stringscanner/get_byte_spec.rb index 29e2f557de..b989b73883 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 == 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(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 == 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(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 c9c3eb6fd3..cd41b4336a 100644 --- a/spec/ruby/library/stringscanner/getch_spec.rb +++ b/spec/ruby/library/stringscanner/getch_spec.rb @@ -11,6 +11,13 @@ describe "StringScanner#getch" do s.getch.should == "c" end + it "scans newlines too" do + s = StringScanner.new("a\nc") + s.getch.should == "a" + s.getch.should == "\n" + s.getch.should == "c" + end + it "is multi-byte character sensitive" do # Japanese hiragana "A" in EUC-JP src = "\244\242".dup.force_encoding("euc-jp") @@ -33,22 +40,20 @@ describe "StringScanner#getch" do describe "#[] successive call with a capture group name" do # https://github.com/ruby/strscan/issues/139 - ruby_version_is ""..."3.5" do # Don't run on 3.5.0dev that already contains not released fixes 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 + s[:a].should == nil end 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) + -> { s[:a] }.should.raise(IndexError) end end @@ -59,7 +64,6 @@ describe "StringScanner#getch" do end # https://github.com/ruby/strscan/issues/135 - ruby_version_is ""..."3.5" do # Don't run on 3.5.0dev that already contains not released fixes 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") @@ -70,10 +74,9 @@ describe "StringScanner#getch" do s.getch s.should.matched? - s[:a].should be_nil + s[:a].should == nil end 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") @@ -84,7 +87,7 @@ describe "StringScanner#getch" do s.getch s.should.matched? - -> { s[:a] }.should raise_error(IndexError) + -> { s[:a] }.should.raise(IndexError) end end end diff --git a/spec/ruby/library/stringscanner/initialize_spec.rb b/spec/ruby/library/stringscanner/initialize_spec.rb index 77f6084c1b..fdab4d381c 100644 --- a/spec/ruby/library/stringscanner/initialize_spec.rb +++ b/spec/ruby/library/stringscanner/initialize_spec.rb @@ -7,12 +7,12 @@ describe "StringScanner#initialize" do end it "is a private method" do - StringScanner.should have_private_instance_method(:initialize) + StringScanner.private_instance_methods(false).should.include?(:initialize) end it "returns an instance of StringScanner" do - @s.should be_kind_of(StringScanner) - @s.eos?.should be_false + @s.should.is_a?(StringScanner) + @s.eos?.should == false end it "converts the argument into a string using #to_str" do diff --git a/spec/ruby/library/stringscanner/inspect_spec.rb b/spec/ruby/library/stringscanner/inspect_spec.rb index ff6b97eb91..570d0b7b10 100644 --- a/spec/ruby/library/stringscanner/inspect_spec.rb +++ b/spec/ruby/library/stringscanner/inspect_spec.rb @@ -7,7 +7,7 @@ describe "StringScanner#inspect" do end it "returns a String object" do - @s.inspect.should be_kind_of(String) + @s.inspect.should.is_a?(String) end it "returns a string that represents the StringScanner object" do diff --git a/spec/ruby/library/stringscanner/match_spec.rb b/spec/ruby/library/stringscanner/match_spec.rb index a27bb51d72..c2bc49324b 100644 --- a/spec/ruby/library/stringscanner/match_spec.rb +++ b/spec/ruby/library/stringscanner/match_spec.rb @@ -45,7 +45,7 @@ describe "StringScanner#match?" do it "returns nil when matching failed" do @s.match?(/(?<a>2008)/) @s.should_not.matched? - @s[:a].should be_nil + @s[:a].should == nil end end end diff --git a/spec/ruby/library/stringscanner/matched_spec.rb b/spec/ruby/library/stringscanner/matched_spec.rb index c020bd3eae..95b57574c5 100644 --- a/spec/ruby/library/stringscanner/matched_spec.rb +++ b/spec/ruby/library/stringscanner/matched_spec.rb @@ -31,11 +31,11 @@ describe "StringScanner#matched?" do it "returns true if the last match was successful" do @s.match?(/\w+/) - @s.matched?.should be_true + @s.matched?.should == true end it "returns false if there's no match" do @s.match?(/\d+/) - @s.matched?.should be_false + @s.matched?.should == false end end diff --git a/spec/ruby/library/stringscanner/named_captures_spec.rb b/spec/ruby/library/stringscanner/named_captures_spec.rb index a68d66c216..927784a6c4 100644 --- a/spec/ruby/library/stringscanner/named_captures_spec.rb +++ b/spec/ruby/library/stringscanner/named_captures_spec.rb @@ -16,11 +16,9 @@ describe "StringScanner#named_captures" do @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 + # https://github.com/ruby/strscan/issues/132 fixed in strscan v3.0.7 + it "returns {} if there is no any matching done" do + @s.named_captures.should == {} end it "returns nil for an optional named capturing group if it doesn't match" do diff --git a/spec/ruby/library/stringscanner/peek_spec.rb b/spec/ruby/library/stringscanner/peek_spec.rb index cbb5630ff9..5b54c6be0b 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(ArgumentError) + end + + it "raises a RangeError when the passed argument is a Bignum" do + -> { @s.peek(bignum_value) }.should.raise(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.is_a?(cls) + ch.should.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/pointer_spec.rb b/spec/ruby/library/stringscanner/pointer_spec.rb index bc0c0c50b7..5fc6c8cdf3 100644 --- a/spec/ruby/library/stringscanner/pointer_spec.rb +++ b/spec/ruby/library/stringscanner/pointer_spec.rb @@ -1,11 +1,14 @@ require_relative '../../spec_helper' -require_relative 'shared/pos' require 'strscan' describe "StringScanner#pointer" do - it_behaves_like :strscan_pos, :pointer + it "is an alias of StringScanner#pos" do + StringScanner.instance_method(:pointer).should == StringScanner.instance_method(:pos) + end end describe "StringScanner#pointer=" do - it_behaves_like :strscan_pos_set, :pointer= + it "is an alias of StringScanner#pos=" do + StringScanner.instance_method(:pointer=).should == StringScanner.instance_method(:pos=) + end end diff --git a/spec/ruby/library/stringscanner/pos_spec.rb b/spec/ruby/library/stringscanner/pos_spec.rb index 275fecf0f3..bc3003ebdf 100644 --- a/spec/ruby/library/stringscanner/pos_spec.rb +++ b/spec/ruby/library/stringscanner/pos_spec.rb @@ -1,11 +1,62 @@ require_relative '../../spec_helper' -require_relative 'shared/pos' require 'strscan' describe "StringScanner#pos" do - it_behaves_like :strscan_pos, :pos + before :each do + @s = StringScanner.new("This is a test") + end + + it "returns the position of the scan pointer" do + @s.pos.should == 0 + @s.scan_until(/This is/) + @s.pos.should == 7 + @s.get_byte + @s.pos.should == 8 + @s.terminate + @s.pos.should == 14 + end + + it "returns 0 in the reset position" do + @s.reset + @s.pos.should == 0 + end + + it "returns the length of the string in the terminate position" do + @s.terminate + @s.pos.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 "StringScanner#pos=" do - it_behaves_like :strscan_pos_set, :pos= + before :each do + @s = StringScanner.new("This is a test") + end + + it "modify the scan pointer" do + @s.pos = 5 + @s.rest.should == "is a test" + end + + it "positions from the end if the argument is negative" do + @s.pos = -2 + @s.rest.should == "st" + @s.pos.should == 12 + end + + it "raises a RangeError if position too far backward" do + -> { + @s.pos = -20 + }.should.raise(RangeError) + end + + it "raises a RangeError when the passed argument is out of range" do + -> { @s.pos = 20 }.should.raise(RangeError) + end end diff --git a/spec/ruby/library/stringscanner/rest_size_spec.rb b/spec/ruby/library/stringscanner/rest_size_spec.rb index e62e3a8f8c..65d3b50e08 100644 --- a/spec/ruby/library/stringscanner/rest_size_spec.rb +++ b/spec/ruby/library/stringscanner/rest_size_spec.rb @@ -1,7 +1,30 @@ 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.bytesize" do + @s.scan(/This/) + @s.rest_size.should == @s.rest.bytesize + + s = StringScanner.new('été') + s.rest_size.should == 5 + s.scan(/./) + s.rest_size.should == 3 + s.scan(/./) + s.rest_size.should == 2 + s.scan(/./) + s.rest_size.should == 0 + end end diff --git a/spec/ruby/library/stringscanner/rest_spec.rb b/spec/ruby/library/stringscanner/rest_spec.rb index 67072f880d..40f073058c 100644 --- a/spec/ruby/library/stringscanner/rest_spec.rb +++ b/spec/ruby/library/stringscanner/rest_spec.rb @@ -32,14 +32,14 @@ describe "StringScanner#rest?" do end it "returns true if there is more data in the string" do - @s.rest?.should be_true + @s.rest?.should == true @s.scan(/This/) - @s.rest?.should be_true + @s.rest?.should == true end it "returns false if there is no more data in the string" do @s.terminate - @s.rest?.should be_false + @s.rest?.should == false end it "is the opposite of eos?" do 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 index c60e22be4f..8fd77270e4 100644 --- a/spec/ruby/library/stringscanner/scan_byte_spec.rb +++ b/spec/ruby/library/stringscanner/scan_byte_spec.rb @@ -43,22 +43,20 @@ version_is StringScanner::Version, "3.1.1" do # ruby_version_is "3.4" describe "#[] successive call with a capture group name" do # https://github.com/ruby/strscan/issues/139 - ruby_version_is ""..."3.5" do # Don't run on 3.5.0dev that already contains not released fixes 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 + s[:a].should == nil end 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) + -> { s[:a] }.should.raise(IndexError) end end @@ -69,7 +67,6 @@ version_is StringScanner::Version, "3.1.1" do # ruby_version_is "3.4" end # https://github.com/ruby/strscan/issues/135 - ruby_version_is ""..."3.5" do # Don't run on 3.5.0dev that already contains not released fixes 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") @@ -83,7 +80,6 @@ version_is StringScanner::Version, "3.1.1" do # ruby_version_is "3.4" s[:a].should == nil end 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") @@ -94,7 +90,7 @@ version_is StringScanner::Version, "3.1.1" do # ruby_version_is "3.4" s.scan_byte s.should.matched? - -> { s[:a] }.should raise_error(IndexError) + -> { s[:a] }.should.raise(IndexError) end end end diff --git a/spec/ruby/library/stringscanner/scan_full_spec.rb b/spec/ruby/library/stringscanner/scan_full_spec.rb index 967313f5ca..7633c17860 100644 --- a/spec/ruby/library/stringscanner/scan_full_spec.rb +++ b/spec/ruby/library/stringscanner/scan_full_spec.rb @@ -38,7 +38,7 @@ describe "StringScanner#scan_full" do it "returns nil when matching failed" do @s.scan_full(/(?<a>2008)/, false, false) @s.should_not.matched? - @s[:a].should be_nil + @s[:a].should == nil end end end diff --git a/spec/ruby/library/stringscanner/scan_integer_spec.rb b/spec/ruby/library/stringscanner/scan_integer_spec.rb index a0b3685bae..d83149344a 100644 --- a/spec/ruby/library/stringscanner/scan_integer_spec.rb +++ b/spec/ruby/library/stringscanner/scan_integer_spec.rb @@ -25,7 +25,7 @@ version_is StringScanner::Version, "3.1.1" do # ruby_version_is "3.4" end # https://github.com/ruby/strscan/issues/130 - ruby_bug "", "3.4"..."3.5" do # introduced in strscan v3.1.1 + 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 @@ -44,7 +44,7 @@ version_is StringScanner::Version, "3.1.1" do # ruby_version_is "3.4" -> { s.scan_integer - }.should raise_error(Encoding::CompatibilityError, 'ASCII incompatible encoding: UTF-16BE') + }.should.raise(Encoding::CompatibilityError, /ASCII incompatible encoding: UTF-16BE|incompatible encoding regexp match/) end context "given base" do @@ -65,10 +65,9 @@ version_is StringScanner::Version, "3.1.1" do # ruby_version_is "3.4" 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") + }.should.raise(ArgumentError, "Unsupported integer base: 5, expected 10 or 16") end - ruby_version_is ""..."3.5" do # Don't run on 3.5.0dev that already contains not released fixes 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 @@ -76,7 +75,6 @@ version_is StringScanner::Version, "3.1.1" do # ruby_version_is "3.4" StringScanner.new("+0x").scan_integer(base: 16).should == nil end 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 @@ -96,7 +94,6 @@ version_is StringScanner::Version, "3.1.1" do # ruby_version_is "3.4" describe "#[] successive call with a capture group name" do # https://github.com/ruby/strscan/issues/139 - ruby_version_is ""..."3.5" do # Don't run on 3.5.0dev that already contains not released fixes 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") @@ -105,13 +102,12 @@ version_is StringScanner::Version, "3.1.1" do # ruby_version_is "3.4" s[:a].should == nil end 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) + -> { s[:a] }.should.raise(IndexError) end end @@ -119,7 +115,7 @@ version_is StringScanner::Version, "3.1.1" do # ruby_version_is "3.4" s = StringScanner.new("a42") s.scan_integer s.should_not.matched? - s[:a].should be_nil + s[:a].should == nil end version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4" @@ -131,7 +127,6 @@ version_is StringScanner::Version, "3.1.1" do # ruby_version_is "3.4" end # https://github.com/ruby/strscan/issues/135 - ruby_version_is ""..."3.5" do # Don't run on 3.5.0dev that already contains not released fixes 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") @@ -145,7 +140,6 @@ version_is StringScanner::Version, "3.1.1" do # ruby_version_is "3.4" s[:a].should == "42" end 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") @@ -156,7 +150,7 @@ version_is StringScanner::Version, "3.1.1" do # ruby_version_is "3.4" s.scan_integer s.should.matched? - -> { s[:a] }.should raise_error(IndexError) + -> { s[:a] }.should.raise(IndexError) end end end diff --git a/spec/ruby/library/stringscanner/scan_spec.rb b/spec/ruby/library/stringscanner/scan_spec.rb index 088c3419fb..ee8a9eb103 100644 --- a/spec/ruby/library/stringscanner/scan_spec.rb +++ b/spec/ruby/library/stringscanner/scan_spec.rb @@ -15,7 +15,7 @@ describe "StringScanner#scan" do it "treats ^ as matching from the beginning of the current position" do @s.scan(/\w+/).should == "This" - @s.scan(/^\d/).should be_nil + @s.scan(/^\d/).should == nil @s.scan(/^\s/).should == " " end @@ -26,7 +26,7 @@ describe "StringScanner#scan" do it "treats \\A as matching from the beginning of the current position" do @s.scan(/\w+/).should == "This" - @s.scan(/\A\d/).should be_nil + @s.scan(/\A\d/).should == nil @s.scan(/\A\s/).should == " " end @@ -41,24 +41,24 @@ describe "StringScanner#scan" do it "returns nil when there is no more to scan" do @s.scan(/[\w\s]+/).should == "This is a test" - @s.scan(/\w+/).should be_nil + @s.scan(/\w+/).should == nil end it "returns an empty string when the pattern matches empty" do @s.scan(/.*/).should == "This is a test" @s.scan(/.*/).should == "" - @s.scan(/./).should be_nil + @s.scan(/./).should == nil end it "treats String as the pattern itself" do - @s.scan("this").should be_nil + @s.scan("this").should == nil @s.scan("This").should == "This" end it "raises a TypeError if pattern isn't a Regexp nor String" do - -> { @s.scan(5) }.should raise_error(TypeError) - -> { @s.scan(:test) }.should raise_error(TypeError) - -> { @s.scan(mock('x')) }.should raise_error(TypeError) + -> { @s.scan(5) }.should.raise(TypeError) + -> { @s.scan(:test) }.should.raise(TypeError) + -> { @s.scan(mock('x')) }.should.raise(TypeError) end describe "#[] successive call with a capture group name" do @@ -71,7 +71,7 @@ describe "StringScanner#scan" do it "returns nil when matching failed" do @s.scan(/(?<a>2008)/) @s.should_not.matched? - @s[:a].should be_nil + @s[:a].should == nil end end end @@ -91,11 +91,11 @@ describe "StringScanner#scan with fixed_anchor: true" do it "treats ^ as matching from the beginning of line" do @s.scan(/\w+\n/).should == "This\n" @s.scan(/^\w/).should == "i" - @s.scan(/^\w/).should be_nil + @s.scan(/^\w/).should == nil end it "treats \\A as matching from the beginning of string" do @s.scan(/\A\w/).should == "T" - @s.scan(/\A\w/).should be_nil + @s.scan(/\A\w/).should == nil end end diff --git a/spec/ruby/library/stringscanner/scan_until_spec.rb b/spec/ruby/library/stringscanner/scan_until_spec.rb index 737d83a14c..df83f3916a 100644 --- a/spec/ruby/library/stringscanner/scan_until_spec.rb +++ b/spec/ruby/library/stringscanner/scan_until_spec.rb @@ -31,7 +31,7 @@ describe "StringScanner#scan_until" do it "raises TypeError if given a String" do -> { @s.scan_until('T') - }.should raise_error(TypeError, 'wrong argument type String (expected Regexp)') + }.should.raise(TypeError, 'wrong argument type String (expected Regexp)') end end @@ -41,7 +41,6 @@ describe "StringScanner#scan_until" do end # https://github.com/ruby/strscan/issues/131 - ruby_version_is ""..."3.5" do # Don't run on 3.5.0dev that already contains not released fixes 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") @@ -51,7 +50,6 @@ describe "StringScanner#scan_until" do @s.post_match.should == " test" end 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 @@ -75,34 +73,32 @@ describe "StringScanner#scan_until" do it "returns nil when matching failed" do @s.scan_until(/(?<a>2008)/) @s.should_not.matched? - @s[:a].should be_nil + @s[:a].should == 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 - ruby_version_is ""..."3.5" do # Don't run on 3.5.0dev that already contains not released fixes 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 + @s[:a].should == nil end 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) + -> { @s[:a] }.should.raise(IndexError) end end it "returns nil when matching failed" do @s.scan_until("2008") @s.should_not.matched? - @s[:a].should be_nil + @s[:a].should == nil end it "returns a matching substring when given Integer index" do @@ -111,7 +107,6 @@ describe "StringScanner#scan_until" do end # https://github.com/ruby/strscan/issues/135 - ruby_version_is ""..."3.5" do # Don't run on 3.5.0dev that already contains not released fixes 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)/) @@ -120,10 +115,9 @@ describe "StringScanner#scan_until" do @s.scan_until("This") @s.should.matched? - @s[:a].should be_nil + @s[:a].should == nil end 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)/) @@ -132,7 +126,7 @@ describe "StringScanner#scan_until" do @s.scan_until("This") @s.should.matched? - -> { @s[:a] }.should raise_error(IndexError) + -> { @s[:a] }.should.raise(IndexError) end end end diff --git a/spec/ruby/library/stringscanner/search_full_spec.rb b/spec/ruby/library/stringscanner/search_full_spec.rb index a089da2043..656884f46b 100644 --- a/spec/ruby/library/stringscanner/search_full_spec.rb +++ b/spec/ruby/library/stringscanner/search_full_spec.rb @@ -40,7 +40,7 @@ describe "StringScanner#search_full" do it "raises TypeError if given a String" do -> { @s.search_full('T', true, true) - }.should raise_error(TypeError, 'wrong argument type String (expected Regexp)') + }.should.raise(TypeError, 'wrong argument type String (expected Regexp)') end end @@ -50,7 +50,6 @@ describe "StringScanner#search_full" do end # https://github.com/ruby/strscan/issues/131 - ruby_version_is ""..."3.5" do # Don't run on 3.5.0dev that already contains not released fixes 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) @@ -60,7 +59,6 @@ describe "StringScanner#search_full" do @s.post_match.should == " test" end 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 @@ -84,34 +82,32 @@ describe "StringScanner#search_full" do it "returns nil when matching failed" do @s.search_full(/(?<a>2008)/, false, false) @s.should_not.matched? - @s[:a].should be_nil + @s[:a].should == 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 - ruby_version_is ""..."3.5" do # Don't run on 3.5.0dev that already contains not released fixes 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 + @s[:a].should == nil end 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) + -> { @s[:a] }.should.raise(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 + @s[:a].should == nil end it "returns a matching substring when given Integer index" do @@ -128,7 +124,7 @@ describe "StringScanner#search_full" do @s.search_full("This", false, false) @s.should.matched? - -> { @s[:a] }.should raise_error(IndexError) + -> { @s[:a] }.should.raise(IndexError) end end end diff --git a/spec/ruby/library/stringscanner/shared/bol.rb b/spec/ruby/library/stringscanner/shared/bol.rb deleted file mode 100644 index ebcdd7938f..0000000000 --- a/spec/ruby/library/stringscanner/shared/bol.rb +++ /dev/null @@ -1,25 +0,0 @@ -describe :strscan_bol, shared: true do - it "returns true if the scan pointer is at the beginning of the line, false otherwise" do - s = StringScanner.new("This is a test") - s.send(@method).should be_true - s.scan(/This/) - s.send(@method).should be_false - s.terminate - s.send(@method).should be_false - - s = StringScanner.new("hello\nworld") - s.bol?.should be_true - s.scan(/\w+/) - s.bol?.should be_false - s.scan(/\n/) - s.bol?.should be_true - s.unscan - s.bol?.should be_false - end - - it "returns true if the scan pointer is at the end of the line of an empty string." do - s = StringScanner.new('') - s.terminate - s.send(@method).should be_true - end -end diff --git a/spec/ruby/library/stringscanner/shared/concat.rb b/spec/ruby/library/stringscanner/shared/concat.rb deleted file mode 100644 index 1dbae11f7c..0000000000 --- a/spec/ruby/library/stringscanner/shared/concat.rb +++ /dev/null @@ -1,30 +0,0 @@ -describe :strscan_concat, shared: true do - it "concatenates the given argument to self and returns self" do - s = StringScanner.new(+"hello ") - s.send(@method, 'world').should == s - s.string.should == "hello world" - s.eos?.should be_false - end - - it "raises a TypeError if the given argument can't be converted to a String" do - -> { StringScanner.new('hello').send(@method, :world) }.should raise_error(TypeError) - -> { StringScanner.new('hello').send(@method, mock('x')) }.should raise_error(TypeError) - end -end - -describe :strscan_concat_fixnum, shared: true do - it "raises a TypeError" do - a = StringScanner.new("hello world") - -> { a.send(@method, 333) }.should raise_error(TypeError) - b = StringScanner.new("") - -> { b.send(@method, (256 * 3 + 64)) }.should raise_error(TypeError) - -> { b.send(@method, -200) }.should raise_error(TypeError) - end - - it "doesn't call to_int on the argument" do - x = mock('x') - x.should_not_receive(:to_int) - - -> { StringScanner.new("").send(@method, x) }.should raise_error(TypeError) - end -end 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/extract_range.rb b/spec/ruby/library/stringscanner/shared/extract_range.rb index e7404fd0cb..c64cc41fa7 100644 --- a/spec/ruby/library/stringscanner/shared/extract_range.rb +++ b/spec/ruby/library/stringscanner/shared/extract_range.rb @@ -5,7 +5,7 @@ describe :extract_range, shared: true do s = StringScanner.new(sub) ch = s.send(@method) - ch.should_not be_kind_of(cls) - ch.should be_an_instance_of(String) + ch.should_not.is_a?(cls) + ch.should.instance_of?(String) end end diff --git a/spec/ruby/library/stringscanner/shared/extract_range_matched.rb b/spec/ruby/library/stringscanner/shared/extract_range_matched.rb index 070a132812..8a6349bec1 100644 --- a/spec/ruby/library/stringscanner/shared/extract_range_matched.rb +++ b/spec/ruby/library/stringscanner/shared/extract_range_matched.rb @@ -7,7 +7,7 @@ describe :extract_range_matched, shared: true do s.scan(/\w{1}/) ch = s.send(@method) - ch.should_not be_kind_of(cls) - ch.should be_an_instance_of(String) + ch.should_not.is_a?(cls) + ch.should.instance_of?(String) 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 1f7378d5c6..0000000000 --- a/spec/ruby/library/stringscanner/shared/get_byte.rb +++ /dev/null @@ -1,87 +0,0 @@ -# encoding: binary -require 'strscan' - -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 - - describe "#[] successive call with a capture group name" do - # https://github.com/ruby/strscan/issues/139 - ruby_version_is ""..."3.5" do # Don't run on 3.5.0dev that already contains not released fixes - 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.send(@method) - s.should.matched? - s[:a].should be_nil - end - 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.send(@method) - 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.send(@method) - s[0].should == "T" - end - - # https://github.com/ruby/strscan/issues/135 - ruby_version_is ""..."3.5" do # Don't run on 3.5.0dev that already contains not released fixes - 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.send(@method) - s.should.matched? - s[:a].should be_nil - end - 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.send(@method) - s.should.matched? - -> { s[:a] }.should raise_error(IndexError) - end - end - 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 deleted file mode 100644 index eea7ead6b5..0000000000 --- a/spec/ruby/library/stringscanner/shared/pos.rb +++ /dev/null @@ -1,59 +0,0 @@ -describe :strscan_pos, shared: true do - before :each do - @s = StringScanner.new("This is a test") - end - - it "returns the position of the scan pointer" do - @s.send(@method).should == 0 - @s.scan_until(/This is/) - @s.send(@method).should == 7 - @s.get_byte - @s.send(@method).should == 8 - @s.terminate - @s.send(@method).should == 14 - end - - it "returns 0 in the reset position" do - @s.reset - @s.send(@method).should == 0 - end - - it "returns the length of the string in the terminate position" 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 - before :each do - @s = StringScanner.new("This is a test") - end - - it "modify the scan pointer" do - @s.send(@method, 5) - @s.rest.should == "is a test" - end - - it "positions from the end if the argument is negative" do - @s.send(@method, -2) - @s.rest.should == "st" - @s.pos.should == 12 - end - - it "raises a RangeError if position too far backward" do - -> { - @s.send(@method, -20) - }.should raise_error(RangeError) - end - - it "raises a RangeError when the passed argument is out of range" do - -> { @s.send(@method, 20) }.should raise_error(RangeError) - end -end 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 12f5b7781c..2b955b3172 100644 --- a/spec/ruby/library/stringscanner/skip_spec.rb +++ b/spec/ruby/library/stringscanner/skip_spec.rb @@ -26,7 +26,7 @@ describe "StringScanner#skip" do it "returns nil when matching failed" do @s.skip(/(?<a>2008)/) @s.should_not.matched? - @s[:a].should be_nil + @s[:a].should == 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 f5be4b5ceb..508db285ba 100644 --- a/spec/ruby/library/stringscanner/skip_until_spec.rb +++ b/spec/ruby/library/stringscanner/skip_until_spec.rb @@ -27,7 +27,7 @@ describe "StringScanner#skip_until" do it "raises TypeError if given a String" do -> { @s.skip_until('T') - }.should raise_error(TypeError, 'wrong argument type String (expected Regexp)') + }.should.raise(TypeError, 'wrong argument type String (expected Regexp)') end end @@ -38,7 +38,6 @@ describe "StringScanner#skip_until" do end # https://github.com/ruby/strscan/issues/131 - ruby_version_is ""..."3.5" do # Don't run on 3.5.0dev that already contains not released fixes 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") @@ -48,7 +47,6 @@ describe "StringScanner#skip_until" do @s.post_match.should == " test" end 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 @@ -72,34 +70,32 @@ describe "StringScanner#skip_until" do it "returns nil when matching failed" do @s.skip_until(/(?<a>2008)/) @s.should_not.matched? - @s[:a].should be_nil + @s[:a].should == 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 - ruby_version_is ""..."3.5" do # Don't run on 3.5.0dev that already contains not released fixes 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 + @s[:a].should == nil end 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) + -> { @s[:a] }.should.raise(IndexError) end end it "returns nil when matching failed" do @s.skip_until("2008") @s.should_not.matched? - @s[:a].should be_nil + @s[:a].should == nil end it "returns a matching substring when given Integer index" do @@ -108,7 +104,6 @@ describe "StringScanner#skip_until" do end # https://github.com/ruby/strscan/issues/135 - ruby_version_is ""..."3.5" do # Don't run on 3.5.0dev that already contains not released fixes 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)/) @@ -117,10 +112,9 @@ describe "StringScanner#skip_until" do @s.skip_until("This") @s.should.matched? - @s[:a].should be_nil + @s[:a].should == nil end 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)/) @@ -129,7 +123,7 @@ describe "StringScanner#skip_until" do @s.skip_until("This") @s.should.matched? - -> { @s[:a] }.should raise_error(IndexError) + -> { @s[:a] }.should.raise(IndexError) end end end diff --git a/spec/ruby/library/stringscanner/string_spec.rb b/spec/ruby/library/stringscanner/string_spec.rb index cba6bd51dd..6cbbff4822 100644 --- a/spec/ruby/library/stringscanner/string_spec.rb +++ b/spec/ruby/library/stringscanner/string_spec.rb @@ -14,7 +14,7 @@ describe "StringScanner#string" do end it "returns the identical object passed in" do - @s.string.equal?(@string).should be_true + @s.string.equal?(@string).should == true end end diff --git a/spec/ruby/library/stringscanner/terminate_spec.rb b/spec/ruby/library/stringscanner/terminate_spec.rb index 7943efe0f9..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..f738778273 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(StringScanner::Error) + -> { @s.scan(/\d/); @s.unscan }.should.raise(StringScanner::Error) end end diff --git a/spec/ruby/library/stringscanner/values_at_spec.rb b/spec/ruby/library/stringscanner/values_at_spec.rb index 14d4a5f6a7..b00cce0ffa 100644 --- a/spec/ruby/library/stringscanner/values_at_spec.rb +++ b/spec/ruby/library/stringscanner/values_at_spec.rb @@ -35,7 +35,7 @@ describe "StringScanner#captures" do -> { @s.values_at("foo") - }.should raise_error(IndexError, "undefined group name reference: foo") + }.should.raise(IndexError, "undefined group name reference: foo") end end @@ -54,7 +54,7 @@ describe "StringScanner#captures" do -> { @s.values_at([]) - }.should raise_error(TypeError, "no implicit conversion of Array into Integer") + }.should.raise(TypeError, "no implicit conversion of Array into Integer") end it "returns nil if the most recent matching fails" do diff --git a/spec/ruby/library/syslog/close_spec.rb b/spec/ruby/library/syslog/close_spec.rb index 8c3b67c05b..713ef701d2 100644 --- a/spec/ruby/library/syslog/close_spec.rb +++ b/spec/ruby/library/syslog/close_spec.rb @@ -7,29 +7,29 @@ platform_is_not :windows do platform_is_not :windows do before :each do - Syslog.opened?.should be_false + Syslog.opened?.should == false end after :each do - Syslog.opened?.should be_false + Syslog.opened?.should == false end it "closes the log" do - Syslog.opened?.should be_false + Syslog.opened?.should == false Syslog.open - Syslog.opened?.should be_true + Syslog.opened?.should == true Syslog.close - Syslog.opened?.should be_false + Syslog.opened?.should == false end it "raises a RuntimeError if the log's already closed" do - -> { Syslog.close }.should raise_error(RuntimeError) + -> { Syslog.close }.should.raise(RuntimeError) end it "it does not work inside blocks" do -> { Syslog.open { |s| s.close } - }.should raise_error(RuntimeError) + }.should.raise(RuntimeError) Syslog.should_not.opened? end @@ -37,7 +37,7 @@ platform_is_not :windows do Syslog.open("rubyspec") Syslog.ident.should == "rubyspec" Syslog.close - Syslog.ident.should be_nil + Syslog.ident.should == nil end it "sets the options to nil" do diff --git a/spec/ruby/library/syslog/constants_spec.rb b/spec/ruby/library/syslog/constants_spec.rb index fc9db47dd8..a6ac355ddd 100644 --- a/spec/ruby/library/syslog/constants_spec.rb +++ b/spec/ruby/library/syslog/constants_spec.rb @@ -17,7 +17,7 @@ platform_is_not :windows do it "includes the Syslog constants" do @constants.each do |c| - Syslog::Constants.should have_constant(c) + Syslog::Constants.should.const_defined?(c, true) end end end diff --git a/spec/ruby/library/syslog/facility_spec.rb b/spec/ruby/library/syslog/facility_spec.rb index 550ca70b11..79a685c201 100644 --- a/spec/ruby/library/syslog/facility_spec.rb +++ b/spec/ruby/library/syslog/facility_spec.rb @@ -7,11 +7,11 @@ platform_is_not :windows do platform_is_not :windows do before :each do - Syslog.opened?.should be_false + Syslog.opened?.should == false end after :each do - Syslog.opened?.should be_false + Syslog.opened?.should == false end it "returns the logging facility" do @@ -21,7 +21,7 @@ platform_is_not :windows do end it "returns nil if the log is closed" do - Syslog.opened?.should be_false + Syslog.opened?.should == false Syslog.facility.should == nil end diff --git a/spec/ruby/library/syslog/ident_spec.rb b/spec/ruby/library/syslog/ident_spec.rb index 3b08327140..80302a42b8 100644 --- a/spec/ruby/library/syslog/ident_spec.rb +++ b/spec/ruby/library/syslog/ident_spec.rb @@ -7,11 +7,11 @@ platform_is_not :windows do platform_is_not :windows do before :each do - Syslog.opened?.should be_false + Syslog.opened?.should == false end after :each do - Syslog.opened?.should be_false + Syslog.opened?.should == false end it "returns the logging identity" do diff --git a/spec/ruby/library/syslog/inspect_spec.rb b/spec/ruby/library/syslog/inspect_spec.rb index f45231f8e3..6407423fd3 100644 --- a/spec/ruby/library/syslog/inspect_spec.rb +++ b/spec/ruby/library/syslog/inspect_spec.rb @@ -7,11 +7,11 @@ platform_is_not :windows do platform_is_not :windows do before :each do - Syslog.opened?.should be_false + Syslog.opened?.should == false end after :each do - Syslog.opened?.should be_false + Syslog.opened?.should == false end it "returns a string a closed log" do diff --git a/spec/ruby/library/syslog/log_spec.rb b/spec/ruby/library/syslog/log_spec.rb index 0c855b8257..1650283371 100644 --- a/spec/ruby/library/syslog/log_spec.rb +++ b/spec/ruby/library/syslog/log_spec.rb @@ -7,11 +7,11 @@ platform_is_not :windows do platform_is_not :windows, :darwin, :aix, :android do before :each do - Syslog.opened?.should be_false + Syslog.opened?.should == false end after :each do - Syslog.opened?.should be_false + Syslog.opened?.should == false end it "receives a priority as first argument" do @@ -34,14 +34,14 @@ platform_is_not :windows do it "fails with TypeError on nil log messages" do Syslog.open do |s| - -> { s.log(1, nil) }.should raise_error(TypeError) + -> { s.log(1, nil) }.should.raise(TypeError) end end it "fails if the log is closed" do -> { Syslog.log(Syslog::LOG_ALERT, "test") - }.should raise_error(RuntimeError) + }.should.raise(RuntimeError) end it "accepts printf parameters" do diff --git a/spec/ruby/library/syslog/mask_spec.rb b/spec/ruby/library/syslog/mask_spec.rb index b3f1250b24..23cca6fa8d 100644 --- a/spec/ruby/library/syslog/mask_spec.rb +++ b/spec/ruby/library/syslog/mask_spec.rb @@ -7,11 +7,11 @@ platform_is_not :windows do platform_is_not :windows do before :each do - Syslog.opened?.should be_false + Syslog.opened?.should == false end after :each do - Syslog.opened?.should be_false + Syslog.opened?.should == false # make sure we return the mask to the default value Syslog.open { |s| s.mask = 255 } end @@ -74,11 +74,11 @@ platform_is_not :windows do platform_is_not :windows do before :each do - Syslog.opened?.should be_false + Syslog.opened?.should == false end after :each do - Syslog.opened?.should be_false + Syslog.opened?.should == false # make sure we return the mask to the default value Syslog.open { |s| s.mask = 255 } end @@ -91,7 +91,7 @@ platform_is_not :windows do end it "raises an error if the log is closed" do - -> { Syslog.mask = 1337 }.should raise_error(RuntimeError) + -> { Syslog.mask = 1337 }.should.raise(RuntimeError) end it "only accepts numbers" do @@ -103,8 +103,8 @@ platform_is_not :windows do Syslog.mask = 3.1416 Syslog.mask.should == 3 - -> { Syslog.mask = "oh hai" }.should raise_error(TypeError) - -> { Syslog.mask = "43" }.should raise_error(TypeError) + -> { Syslog.mask = "oh hai" }.should.raise(TypeError) + -> { Syslog.mask = "43" }.should.raise(TypeError) end end diff --git a/spec/ruby/library/syslog/open_spec.rb b/spec/ruby/library/syslog/open_spec.rb index 543f5d418b..3aceea007d 100644 --- a/spec/ruby/library/syslog/open_spec.rb +++ b/spec/ruby/library/syslog/open_spec.rb @@ -1,18 +1,17 @@ require_relative '../../spec_helper' platform_is_not :windows do - require_relative 'shared/reopen' require 'syslog' describe "Syslog.open" do platform_is_not :windows do before :each do - Syslog.opened?.should be_false + Syslog.opened?.should == false end after :each do - Syslog.opened?.should be_false + Syslog.opened?.should == false end it "returns the module" do @@ -69,24 +68,59 @@ platform_is_not :windows do it "closes the log if after it receives a block" do Syslog.open{ } - Syslog.opened?.should be_false + Syslog.opened?.should == false end it "raises an error if the log is opened" do Syslog.open -> { Syslog.open - }.should raise_error(RuntimeError, /syslog already open/) + }.should.raise(RuntimeError, /syslog already open/) -> { Syslog.close Syslog.open - }.should_not raise_error + }.should_not.raise Syslog.close end end end describe "Syslog.open!" do - it_behaves_like :syslog_reopen, :open! + before :each do + Syslog.opened?.should == false + end + + after :each do + Syslog.opened?.should == false + end + + it "reopens the log" do + Syslog.open + -> { Syslog.open! }.should_not.raise + Syslog.opened?.should == true + Syslog.close + end + + it "fails with RuntimeError if the log is closed" do + -> { Syslog.open! }.should.raise(RuntimeError) + end + + it "receives the same parameters as Syslog.open" do + Syslog.open + Syslog.open!("rubyspec", 3, 8) do |s| + s.should == Syslog + s.ident.should == "rubyspec" + s.options.should == 3 + s.facility.should == Syslog::LOG_USER + s.opened?.should == true + end + Syslog.opened?.should == false + end + + it "returns the module" do + Syslog.open + Syslog.open!.should == Syslog + Syslog.close + end end end diff --git a/spec/ruby/library/syslog/opened_spec.rb b/spec/ruby/library/syslog/opened_spec.rb index 94432e65a4..ad4311d15a 100644 --- a/spec/ruby/library/syslog/opened_spec.rb +++ b/spec/ruby/library/syslog/opened_spec.rb @@ -7,32 +7,32 @@ platform_is_not :windows do platform_is_not :windows do before :each do - Syslog.opened?.should be_false + Syslog.opened?.should == false end after :each do - Syslog.opened?.should be_false + Syslog.opened?.should == false end it "returns true if the log is opened" do Syslog.open - Syslog.opened?.should be_true + Syslog.opened?.should == true Syslog.close end it "returns false otherwise" do - Syslog.opened?.should be_false + Syslog.opened?.should == false Syslog.open Syslog.close - Syslog.opened?.should be_false + Syslog.opened?.should == false end it "works inside a block" do Syslog.open do |s| - s.opened?.should be_true - Syslog.opened?.should be_true + s.opened?.should == true + Syslog.opened?.should == true end - Syslog.opened?.should be_false + Syslog.opened?.should == false end end end diff --git a/spec/ruby/library/syslog/options_spec.rb b/spec/ruby/library/syslog/options_spec.rb index 83ba43503e..2035272f70 100644 --- a/spec/ruby/library/syslog/options_spec.rb +++ b/spec/ruby/library/syslog/options_spec.rb @@ -7,11 +7,11 @@ platform_is_not :windows do platform_is_not :windows do before :each do - Syslog.opened?.should be_false + Syslog.opened?.should == false end after :each do - Syslog.opened?.should be_false + Syslog.opened?.should == false end it "returns the logging options" do @@ -21,7 +21,7 @@ platform_is_not :windows do end it "returns nil when the log is closed" do - Syslog.opened?.should be_false + Syslog.opened?.should == false Syslog.options.should == nil end diff --git a/spec/ruby/library/syslog/reopen_spec.rb b/spec/ruby/library/syslog/reopen_spec.rb index a78529fa1f..ef32d13a87 100644 --- a/spec/ruby/library/syslog/reopen_spec.rb +++ b/spec/ruby/library/syslog/reopen_spec.rb @@ -1,10 +1,11 @@ require_relative '../../spec_helper' platform_is_not :windows do - require_relative 'shared/reopen' require 'syslog' describe "Syslog.reopen" do - it_behaves_like :syslog_reopen, :reopen + it "is an alias of Syslog.open!" do + Syslog.method(:reopen).should == Syslog.method(:open!) + end end end diff --git a/spec/ruby/library/syslog/shared/log.rb b/spec/ruby/library/syslog/shared/log.rb index 9f9302b214..98ce4f54b2 100644 --- a/spec/ruby/library/syslog/shared/log.rb +++ b/spec/ruby/library/syslog/shared/log.rb @@ -1,11 +1,11 @@ describe :syslog_log, shared: true do platform_is_not :windows, :darwin, :aix, :android do before :each do - Syslog.opened?.should be_false + Syslog.opened?.should == false end after :each do - Syslog.opened?.should be_false + Syslog.opened?.should == false end it "logs a message" do diff --git a/spec/ruby/library/syslog/shared/reopen.rb b/spec/ruby/library/syslog/shared/reopen.rb deleted file mode 100644 index 621437a01d..0000000000 --- a/spec/ruby/library/syslog/shared/reopen.rb +++ /dev/null @@ -1,40 +0,0 @@ -describe :syslog_reopen, shared: true do - platform_is_not :windows do - before :each do - Syslog.opened?.should be_false - end - - after :each do - Syslog.opened?.should be_false - end - - it "reopens the log" do - Syslog.open - -> { Syslog.send(@method)}.should_not raise_error - Syslog.opened?.should be_true - Syslog.close - end - - it "fails with RuntimeError if the log is closed" do - -> { Syslog.send(@method)}.should raise_error(RuntimeError) - end - - it "receives the same parameters as Syslog.open" do - Syslog.open - Syslog.send(@method, "rubyspec", 3, 8) do |s| - s.should == Syslog - s.ident.should == "rubyspec" - s.options.should == 3 - s.facility.should == Syslog::LOG_USER - s.opened?.should be_true - end - Syslog.opened?.should be_false - end - - it "returns the module" do - Syslog.open - Syslog.send(@method).should == Syslog - Syslog.close - end - end -end diff --git a/spec/ruby/library/tempfile/_close_spec.rb b/spec/ruby/library/tempfile/_close_spec.rb index c08f425b6f..344b08dc17 100644 --- a/spec/ruby/library/tempfile/_close_spec.rb +++ b/spec/ruby/library/tempfile/_close_spec.rb @@ -11,11 +11,11 @@ describe "Tempfile#_close" do end it "is protected" do - Tempfile.should have_protected_instance_method(:_close) + Tempfile.protected_instance_methods(false).should.include?(:_close) end it "closes self" do @tempfile.send(:_close) - @tempfile.closed?.should be_true + @tempfile.closed?.should == true end 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/close_spec.rb b/spec/ruby/library/tempfile/close_spec.rb index db0eae3fa5..7e95ae1d7e 100644 --- a/spec/ruby/library/tempfile/close_spec.rb +++ b/spec/ruby/library/tempfile/close_spec.rb @@ -12,7 +12,7 @@ describe "Tempfile#close when passed no argument or [false]" do it "closes self" do @tempfile.close - @tempfile.closed?.should be_true + @tempfile.closed?.should == true end it "does not unlink self" do @@ -29,7 +29,7 @@ describe "Tempfile#close when passed [true]" do it "closes self" do @tempfile.close(true) - @tempfile.closed?.should be_true + @tempfile.closed?.should == true end it "unlinks self" do @@ -46,7 +46,7 @@ describe "Tempfile#close!" do it "closes self" do @tempfile.close! - @tempfile.closed?.should be_true + @tempfile.closed?.should == true end it "unlinks self" do diff --git a/spec/ruby/library/tempfile/create_spec.rb b/spec/ruby/library/tempfile/create_spec.rb new file mode 100644 index 0000000000..be6d21e218 --- /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.instance_of?(File)` would be true either way. + @tempfile.instance_of?(File).should == true + + @tempfile.should_not.closed? + File.file?(@tempfile.path).should == 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 == true + end + + @tempfile.should.closed? + File.exist?(@tempfile.path).should == 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(ArgumentError, "unexpected prefix: :create_spec") + -> { Tempfile.create([:create_spec]) }.should.raise(ArgumentError, "unexpected prefix: :create_spec") + -> { Tempfile.create(["create_spec", :temp]) }.should.raise(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(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(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 == 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 == 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 == 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 == true + end + end +end diff --git a/spec/ruby/library/tempfile/delete_spec.rb b/spec/ruby/library/tempfile/delete_spec.rb index 0332b44dde..b126ceae6a 100644 --- a/spec/ruby/library/tempfile/delete_spec.rb +++ b/spec/ruby/library/tempfile/delete_spec.rb @@ -1,7 +1,15 @@ require_relative '../../spec_helper' -require_relative 'shared/unlink' require 'tempfile' describe "Tempfile#delete" do - it_behaves_like :tempfile_unlink, :delete + before :each do + @tempfile = Tempfile.new("specs") + end + + it "unlinks self" do + @tempfile.close + path = @tempfile.path + @tempfile.delete + File.should_not.exist?(path) + end end diff --git a/spec/ruby/library/tempfile/initialize_spec.rb b/spec/ruby/library/tempfile/initialize_spec.rb index f2e786d7d8..0e882a3f0c 100644 --- a/spec/ruby/library/tempfile/initialize_spec.rb +++ b/spec/ruby/library/tempfile/initialize_spec.rb @@ -24,7 +24,7 @@ describe "Tempfile#initialize" do end path[0, tmpdir.length].should == tmpdir - path.should include("basename") + path.should.include?("basename") end platform_is_not :windows do diff --git a/spec/ruby/library/tempfile/length_spec.rb b/spec/ruby/library/tempfile/length_spec.rb index bc622b9a70..924c12942b 100644 --- a/spec/ruby/library/tempfile/length_spec.rb +++ b/spec/ruby/library/tempfile/length_spec.rb @@ -1,7 +1,8 @@ require_relative '../../spec_helper' -require_relative 'shared/length' require 'tempfile' describe "Tempfile#length" do - it_behaves_like :tempfile_length, :length + it "is an alias of Tempfile#size" do + Tempfile.instance_method(:length).should == Tempfile.instance_method(:size) + end end diff --git a/spec/ruby/library/tempfile/open_spec.rb b/spec/ruby/library/tempfile/open_spec.rb index ef2c95376f..0993a2c5ee 100644 --- a/spec/ruby/library/tempfile/open_spec.rb +++ b/spec/ruby/library/tempfile/open_spec.rb @@ -14,7 +14,7 @@ describe "Tempfile#open" do it "reopens self" do @tempfile.close @tempfile.open - @tempfile.closed?.should be_false + @tempfile.closed?.should == false end it "reopens self in read and write mode and does not truncate" do @@ -33,8 +33,8 @@ describe "Tempfile.open" do it "returns a new, open Tempfile instance" do @tempfile = Tempfile.open("specs") - # Delegation messes up .should be_an_instance_of(Tempfile) - @tempfile.instance_of?(Tempfile).should be_true + # Delegation messes up .should.instance_of?(Tempfile) + @tempfile.instance_of?(Tempfile).should == true end it "is passed an array [base, suffix] as first argument" do @@ -46,14 +46,14 @@ describe "Tempfile.open" do Tempfile.open("specs", Dir.tmpdir, encoding: "IBM037:IBM037", binmode: true) do |tempfile| @tempfile = tempfile tempfile.external_encoding.should == Encoding.find("IBM037") - tempfile.binmode?.should be_true + tempfile.binmode?.should == true end end it "uses a blank string for basename when passed no arguments" do Tempfile.open() do |tempfile| @tempfile = tempfile - tempfile.closed?.should be_false + tempfile.closed?.should == false end @tempfile.should_not == nil end @@ -74,9 +74,9 @@ describe "Tempfile.open when passed a block" do @tempfile = tempfile ScratchPad.record :yielded - # Delegation messes up .should be_an_instance_of(Tempfile) - tempfile.instance_of?(Tempfile).should be_true - tempfile.closed?.should be_false + # Delegation messes up .should.instance_of?(Tempfile) + tempfile.instance_of?(Tempfile).should == true + tempfile.closed?.should == false end ScratchPad.recorded.should == :yielded @@ -92,6 +92,6 @@ describe "Tempfile.open when passed a block" do it "closes the yielded Tempfile after the block" do Tempfile.open("specs") { |tempfile| @tempfile = tempfile } - @tempfile.closed?.should be_true + @tempfile.closed?.should == true end end diff --git a/spec/ruby/library/tempfile/path_spec.rb b/spec/ruby/library/tempfile/path_spec.rb index 07f75b3e10..be56bd87c8 100644 --- a/spec/ruby/library/tempfile/path_spec.rb +++ b/spec/ruby/library/tempfile/path_spec.rb @@ -21,6 +21,6 @@ describe "Tempfile#path" do end path[0, tmpdir.length].should == tmpdir - path.should include("specs") + path.should.include?("specs") end end diff --git a/spec/ruby/library/tempfile/shared/length.rb b/spec/ruby/library/tempfile/shared/length.rb deleted file mode 100644 index 4d18d1f385..0000000000 --- a/spec/ruby/library/tempfile/shared/length.rb +++ /dev/null @@ -1,21 +0,0 @@ -describe :tempfile_length, shared: true do - before :each do - @tempfile = Tempfile.new("specs") - end - - after :each do - @tempfile.close! - end - - it "returns the size of self" do - @tempfile.send(@method).should eql(0) - @tempfile.print("Test!") - @tempfile.send(@method).should eql(5) - end - - it "returns the size of self even if self is closed" do - @tempfile.print("Test!") - @tempfile.close - @tempfile.send(@method).should eql(5) - end -end diff --git a/spec/ruby/library/tempfile/shared/unlink.rb b/spec/ruby/library/tempfile/shared/unlink.rb deleted file mode 100644 index e821228d70..0000000000 --- a/spec/ruby/library/tempfile/shared/unlink.rb +++ /dev/null @@ -1,12 +0,0 @@ -describe :tempfile_unlink, shared: true do - before :each do - @tempfile = Tempfile.new("specs") - end - - it "unlinks self" do - @tempfile.close - path = @tempfile.path - @tempfile.send(@method) - File.should_not.exist?(path) - end -end diff --git a/spec/ruby/library/tempfile/size_spec.rb b/spec/ruby/library/tempfile/size_spec.rb index f4824601c7..5a7edf8e4b 100644 --- a/spec/ruby/library/tempfile/size_spec.rb +++ b/spec/ruby/library/tempfile/size_spec.rb @@ -1,7 +1,24 @@ require_relative '../../spec_helper' -require_relative 'shared/length' require 'tempfile' describe "Tempfile#size" do - it_behaves_like :tempfile_length, :size + before :each do + @tempfile = Tempfile.new("specs") + end + + after :each do + @tempfile.close! + end + + it "returns the size of self" do + @tempfile.size.should.eql?(0) + @tempfile.print("Test!") + @tempfile.size.should.eql?(5) + end + + it "returns the size of self even if self is closed" do + @tempfile.print("Test!") + @tempfile.close + @tempfile.size.should.eql?(5) + end end diff --git a/spec/ruby/library/tempfile/unlink_spec.rb b/spec/ruby/library/tempfile/unlink_spec.rb index eac7df8472..c03fc34a54 100644 --- a/spec/ruby/library/tempfile/unlink_spec.rb +++ b/spec/ruby/library/tempfile/unlink_spec.rb @@ -1,7 +1,8 @@ require_relative '../../spec_helper' -require_relative 'shared/unlink' require 'tempfile' describe "Tempfile#unlink" do - it_behaves_like :tempfile_unlink, :unlink + it "is an alias of Tempfile#delete" do + Tempfile.instance_method(:unlink).should == Tempfile.instance_method(:delete) + end end diff --git a/spec/ruby/library/thread/queue_spec.rb b/spec/ruby/library/thread/queue_spec.rb index c7e2bb1b50..b6c4fef08f 100644 --- a/spec/ruby/library/thread/queue_spec.rb +++ b/spec/ruby/library/thread/queue_spec.rb @@ -2,7 +2,7 @@ require_relative '../../spec_helper' describe "Thread::Queue" do it "is the same class as ::Queue" do - Thread.should have_constant(:Queue) - Thread::Queue.should equal ::Queue + Thread.should.const_defined?(:Queue, false) + Thread::Queue.should.equal? ::Queue end end diff --git a/spec/ruby/library/thread/sizedqueue_spec.rb b/spec/ruby/library/thread/sizedqueue_spec.rb index 6151ff437c..ffa66bcd35 100644 --- a/spec/ruby/library/thread/sizedqueue_spec.rb +++ b/spec/ruby/library/thread/sizedqueue_spec.rb @@ -2,7 +2,7 @@ require_relative '../../spec_helper' describe "Thread::SizedQueue" do it "is the same class as ::SizedQueue" do - Thread.should have_constant(:SizedQueue) - Thread::SizedQueue.should equal ::SizedQueue + Thread.should.const_defined?(:SizedQueue, false) + Thread::SizedQueue.should.equal? ::SizedQueue end end diff --git a/spec/ruby/library/time/iso8601_spec.rb b/spec/ruby/library/time/iso8601_spec.rb index ab35ab25d6..d78de76792 100644 --- a/spec/ruby/library/time/iso8601_spec.rb +++ b/spec/ruby/library/time/iso8601_spec.rb @@ -1,7 +1,8 @@ require_relative '../../spec_helper' -require_relative 'shared/xmlschema' require 'time' describe "Time.iso8601" do - it_behaves_like :time_library_xmlschema, :iso8601 + it "is an alias of Time.xmlschema" do + Time.method(:iso8601).should == Time.method(:xmlschema) + end end diff --git a/spec/ruby/library/time/rfc2822_spec.rb b/spec/ruby/library/time/rfc2822_spec.rb index 7fc5e9a64b..14824e2396 100644 --- a/spec/ruby/library/time/rfc2822_spec.rb +++ b/spec/ruby/library/time/rfc2822_spec.rb @@ -1,7 +1,68 @@ require_relative '../../spec_helper' -require_relative 'shared/rfc2822' require 'time' describe "Time.rfc2822" do - it_behaves_like :time_rfc2822, :rfc2822 + 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") + t1.should == t2 + + t3 = Time.utc(1976, 8, 27, 9, 32) + 7 * 3600 + t4 = Time.rfc2822("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") + 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") + 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") + 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") + 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") + t9.should == t10 + + begin + Time.at(-1) + rescue ArgumentError + # 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") + t11.should == t12 + + t13 = Time.utc(1969, 2, 13, 23, 32, 0) + 3 * 3600 + 30 * 60 + t14 = Time.rfc2822(" Thu, + 13 + Feb + 1969 + 23:32 + -0330 (Newfoundland Time)") + t13.should == t14 + end + + t15 = Time.utc(1997, 11, 21, 9, 55, 6) + t16 = Time.rfc2822("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") + t17.should == t18 + + -> { + # inner comment is not supported. + Time.rfc2822("Fri, 21 Nov 1997 09(comment): 55 : 06 -0600") + }.should.raise(ArgumentError) + end end diff --git a/spec/ruby/library/time/rfc822_spec.rb b/spec/ruby/library/time/rfc822_spec.rb index da77e6ee77..e32e9becae 100644 --- a/spec/ruby/library/time/rfc822_spec.rb +++ b/spec/ruby/library/time/rfc822_spec.rb @@ -1,7 +1,8 @@ require_relative '../../spec_helper' -require_relative 'shared/rfc2822' require 'time' describe "Time.rfc822" do - it_behaves_like :time_rfc2822, :rfc822 + it "is an alias of Time.rfc2822" do + Time.method(:rfc822).should == Time.method(:rfc2822) + end end diff --git a/spec/ruby/library/time/shared/rfc2822.rb b/spec/ruby/library/time/shared/rfc2822.rb deleted file mode 100644 index e460d655a6..0000000000 --- a/spec/ruby/library/time/shared/rfc2822.rb +++ /dev/null @@ -1,65 +0,0 @@ -describe :time_rfc2822, shared: true do - it "parses RFC-822 strings" do - t1 = (Time.utc(1976, 8, 26, 14, 30) + 4 * 3600) - 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.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.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.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.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.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.send(@method, "Mon, 24 Nov 1997 14:22:01 -0800") - t9.should == t10 - - begin - Time.at(-1) - rescue ArgumentError - # ignore - else - t11 = Time.utc(1969, 2, 13, 23, 32, 54) + 3 * 3600 + 30 * 60 - 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.send(@method, " Thu, - 13 - Feb - 1969 - 23:32 - -0330 (Newfoundland Time)") - t13.should == t14 - end - - t15 = Time.utc(1997, 11, 21, 9, 55, 6) - 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.send(@method, "Fri, 21 Nov 1997 09 : 55 : 06 -0600") - t17.should == t18 - - -> { - # inner comment is not supported. - 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 deleted file mode 100644 index 0002886ca5..0000000000 --- a/spec/ruby/library/time/shared/xmlschema.rb +++ /dev/null @@ -1,53 +0,0 @@ -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.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.send(@method, s) - # There is no way to generate time string with arbitrary timezone. - s = "1996-12-20T00:39:57Z" - 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.send(@method, s) - # leap second is representable only if timezone file has it. - s = "1990-12-31T15:59:60-08:00" - t.should == Time.send(@method, s) - - begin - Time.at(-1) - rescue ArgumentError - # ignore - else - t = Time.utc(1937, 1, 1, 11, 40, 27, 870000) - s = "1937-01-01T12:00:27.87+00:20" - t.should == Time.send(@method, s) - end - - # more - - # (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/to_time_spec.rb b/spec/ruby/library/time/to_time_spec.rb index 7e6c75a003..d2b89cb112 100644 --- a/spec/ruby/library/time/to_time_spec.rb +++ b/spec/ruby/library/time/to_time_spec.rb @@ -6,10 +6,10 @@ describe "Time#to_time" do time = Time.new(2012, 2, 21, 10, 11, 12) with_timezone("America/Regina") do - time.to_time.should equal time + time.to_time.should.equal? time end time2 = Time.utc(2012, 2, 21, 10, 11, 12) - time2.to_time.should equal time2 + time2.to_time.should.equal? time2 end end diff --git a/spec/ruby/library/time/xmlschema_spec.rb b/spec/ruby/library/time/xmlschema_spec.rb index ff3c864a02..1f7d63979a 100644 --- a/spec/ruby/library/time/xmlschema_spec.rb +++ b/spec/ruby/library/time/xmlschema_spec.rb @@ -1,7 +1,56 @@ require_relative '../../spec_helper' -require_relative 'shared/xmlschema' require 'time' describe "Time.xmlschema" do - it_behaves_like :time_library_xmlschema, :xmlschema + 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 = Time.utc(1996, 12, 20, 0, 39, 57) + s = "1996-12-19T16:39:57-08:00" + t.should == Time.xmlschema(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 = Time.utc(1990, 12, 31, 23, 59, 60) + s = "1990-12-31T23:59:60Z" + t.should == Time.xmlschema(s) + # leap second is representable only if timezone file has it. + s = "1990-12-31T15:59:60-08:00" + t.should == Time.xmlschema(s) + + begin + Time.at(-1) + rescue ArgumentError + # ignore + 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) + 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") + end end diff --git a/spec/ruby/library/timeout/error_spec.rb b/spec/ruby/library/timeout/error_spec.rb index 6c236e5128..2c28236e29 100644 --- a/spec/ruby/library/timeout/error_spec.rb +++ b/spec/ruby/library/timeout/error_spec.rb @@ -3,6 +3,6 @@ require 'timeout' describe "Timeout::Error" do it "is a subclass of RuntimeError" do - RuntimeError.should be_ancestor_of(Timeout::Error) + Timeout::Error.ancestors.should.include?(RuntimeError) end end diff --git a/spec/ruby/library/timeout/timeout_spec.rb b/spec/ruby/library/timeout/timeout_spec.rb index e16bcaea6a..9ae70bf600 100644 --- a/spec/ruby/library/timeout/timeout_spec.rb +++ b/spec/ruby/library/timeout/timeout_spec.rb @@ -7,7 +7,7 @@ describe "Timeout.timeout" do Timeout.timeout(1) do sleep end - }.should raise_error(Timeout::Error) + }.should.raise(Timeout::Error) end it "raises specified error type when it times out" do @@ -15,7 +15,7 @@ describe "Timeout.timeout" do Timeout.timeout(1, StandardError) do sleep end - end.should raise_error(StandardError) + end.should.raise(StandardError) end it "raises specified error type with specified message when it times out" do @@ -23,7 +23,7 @@ describe "Timeout.timeout" do Timeout.timeout(1, StandardError, "foobar") do sleep end - end.should raise_error(StandardError, "foobar") + end.should.raise(StandardError, "foobar") end it "raises specified error type with a default message when it times out if message is nil" do @@ -31,7 +31,7 @@ describe "Timeout.timeout" do Timeout.timeout(1, StandardError, nil) do sleep end - end.should raise_error(StandardError, "execution expired") + end.should.raise(StandardError, "execution expired") end it "returns back the last value in the block" do @@ -44,7 +44,7 @@ describe "Timeout.timeout" 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") + }.should.raise(ArgumentError, "Timeout sec must be a non-negative number") end end end diff --git a/spec/ruby/library/tmpdir/dir/mktmpdir_spec.rb b/spec/ruby/library/tmpdir/dir/mktmpdir_spec.rb index 8165c2d8a8..edc4795efb 100644 --- a/spec/ruby/library/tmpdir/dir/mktmpdir_spec.rb +++ b/spec/ruby/library/tmpdir/dir/mktmpdir_spec.rb @@ -16,8 +16,8 @@ describe "Dir.mktmpdir when passed no arguments" do it "creates a new writable directory in the path provided by Dir.tmpdir" do Dir.should_receive(:tmpdir).and_return(tmp("")) @tmpdir = Dir.mktmpdir - File.directory?(@tmpdir).should be_true - File.writable?(@tmpdir).should be_true + File.directory?(@tmpdir).should == true + File.writable?(@tmpdir).should == true end end @@ -41,15 +41,15 @@ describe "Dir.mktmpdir when passed a block" do called = true path.should.start_with?(@real_tmp_root) end - called.should be_true + called.should == true end it "creates the tmp-dir before yielding" do Dir.should_receive(:tmpdir).and_return(tmp("")) Dir.mktmpdir do |path| @tmpdir = path - File.directory?(path).should be_true - File.writable?(path).should be_true + File.directory?(path).should == true + File.writable?(path).should == true end end @@ -67,7 +67,7 @@ describe "Dir.mktmpdir when passed a block" do @tmpdir = path :test end - result.should equal(:test) + result.should.equal?(:test) end end @@ -110,8 +110,8 @@ end describe "Dir.mktmpdir when passed [Object]" do it "raises an ArgumentError" do - -> { Dir.mktmpdir(Object.new) }.should raise_error(ArgumentError) - -> { Dir.mktmpdir(:symbol) }.should raise_error(ArgumentError) - -> { Dir.mktmpdir(10) }.should raise_error(ArgumentError) + -> { Dir.mktmpdir(Object.new) }.should.raise(ArgumentError) + -> { Dir.mktmpdir(:symbol) }.should.raise(ArgumentError) + -> { Dir.mktmpdir(10) }.should.raise(ArgumentError) end end diff --git a/spec/ruby/library/tmpdir/dir/tmpdir_spec.rb b/spec/ruby/library/tmpdir/dir/tmpdir_spec.rb index f4ab5e40b8..330f04458f 100644 --- a/spec/ruby/library/tmpdir/dir/tmpdir_spec.rb +++ b/spec/ruby/library/tmpdir/dir/tmpdir_spec.rb @@ -4,7 +4,7 @@ require "tmpdir" describe "Dir.tmpdir" do it "returns the path to a writable and readable directory" do dir = Dir.tmpdir - File.directory?(dir).should be_true - File.writable?(dir).should be_true + File.directory?(dir).should == true + File.writable?(dir).should == true end end diff --git a/spec/ruby/library/uri/join_spec.rb b/spec/ruby/library/uri/join_spec.rb index 796f74134f..1777303360 100644 --- a/spec/ruby/library/uri/join_spec.rb +++ b/spec/ruby/library/uri/join_spec.rb @@ -23,7 +23,7 @@ describe "URI.join" do it "raises an error if given no argument" do -> { URI.join - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) end it "doesn't create redundant '/'s" do diff --git a/spec/ruby/library/uri/mailto/build_spec.rb b/spec/ruby/library/uri/mailto/build_spec.rb index 2c011626ab..081707b1cf 100644 --- a/spec/ruby/library/uri/mailto/build_spec.rb +++ b/spec/ruby/library/uri/mailto/build_spec.rb @@ -84,7 +84,7 @@ describe "URI::Mailto.build" do end bad.each do |x| - -> { URI::MailTo.build(x) }.should raise_error(URI::InvalidComponentError) + -> { URI::MailTo.build(x) }.should.raise(URI::InvalidComponentError) end ok.flatten.join("\0").should == ok_all diff --git a/spec/ruby/library/uri/parse_spec.rb b/spec/ruby/library/uri/parse_spec.rb index e9ec59b490..f0373fbf5e 100644 --- a/spec/ruby/library/uri/parse_spec.rb +++ b/spec/ruby/library/uri/parse_spec.rb @@ -4,7 +4,7 @@ require_relative 'fixtures/classes' describe "URI.parse" do it "returns a URI::HTTP object when parsing an HTTP URI" do - URI.parse("http://www.example.com/").should be_kind_of(URI::HTTP) + URI.parse("http://www.example.com/").should.is_a?(URI::HTTP) end it "populates the components of a parsed URI::HTTP, setting the port to 80 by default" do @@ -47,7 +47,7 @@ describe "URI.parse" do end it "returns a URI::HTTPS object when parsing an HTTPS URI" do - URI.parse("https://important-intern-net.net").should be_kind_of(URI::HTTPS) + URI.parse("https://important-intern-net.net").should.is_a?(URI::HTTPS) end it "sets the port of a parsed https URI to 443 by default" do @@ -57,7 +57,7 @@ describe "URI.parse" do it "populates the components of a parsed URI::FTP object" do # generic, empty password. url = URI.parse("ftp://anonymous@ruby-lang.org/pub/ruby/1.8/ruby-1.8.6.tar.bz2;type=i") - url.should be_kind_of(URI::FTP) + url.should.is_a?(URI::FTP) URISpec.components(url).should == { scheme: "ftp", userinfo: "anonymous", @@ -69,7 +69,7 @@ describe "URI.parse" do # multidomain, no user or password url = URI.parse('ftp://ftp.is.co.za/rfc/rfc1808.txt') - url.should be_kind_of(URI::FTP) + url.should.is_a?(URI::FTP) URISpec.components(url).should == { scheme: "ftp", userinfo: nil, @@ -81,7 +81,7 @@ describe "URI.parse" do # empty user url = URI.parse('ftp://:pass@localhost/') - url.should be_kind_of(URI::FTP) + url.should.is_a?(URI::FTP) URISpec.components(url).should == { scheme: "ftp", userinfo: ":pass", @@ -97,7 +97,7 @@ describe "URI.parse" do #taken from http://www.faqs.org/rfcs/rfc2255.html 'cause I don't really know what an LDAP url looks like ldap_uris = %w{ ldap:///o=University%20of%20Michigan,c=US ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US?postalAddress ldap://host.com:6666/o=University%20of%20Michigan,c=US??sub?(cn=Babs%20Jensen) ldap://ldap.itd.umich.edu/c=GB?objectClass?one ldap://ldap.question.com/o=Question%3f,c=US?mail ldap://ldap.netscape.com/o=Babsco,c=US??(int=%5c00%5c00%5c00%5c04) ldap:///??sub??bindname=cn=Manager%2co=Foo ldap:///??sub??!bindname=cn=Manager%2co=Foo } ldap_uris.each do |ldap_uri| - URI.parse(ldap_uri).should be_kind_of(URI::LDAP) + URI.parse(ldap_uri).should.is_a?(URI::LDAP) end end @@ -115,7 +115,7 @@ describe "URI.parse" do end it "returns a URI::MailTo object when passed a mailto URI" do - URI.parse("mailto:spam@mailinator.com").should be_kind_of(URI::MailTo) + URI.parse("mailto:spam@mailinator.com").should.is_a?(URI::MailTo) end it "populates the components of a parsed URI::MailTo object" do @@ -145,7 +145,7 @@ describe "URI.parse" do # gopher gopher = URI.parse('gopher://spinaltap.micro.umn.edu/00/Weather/California/Los%20Angeles') - gopher.should be_kind_of(URI::Generic) + gopher.should.is_a?(URI::Generic) URISpec.components(gopher).should == { scheme: "gopher", @@ -161,7 +161,7 @@ describe "URI.parse" do # news news = URI.parse('news:comp.infosystems.www.servers.unix') - news.should be_kind_of(URI::Generic) + news.should.is_a?(URI::Generic) URISpec.components(news).should == { scheme: "news", userinfo: nil, @@ -176,7 +176,7 @@ describe "URI.parse" do # telnet telnet = URI.parse('telnet://melvyl.ucop.edu/') - telnet.should be_kind_of(URI::Generic) + telnet.should.is_a?(URI::Generic) URISpec.components(telnet).should == { scheme: "telnet", userinfo: nil, @@ -191,9 +191,9 @@ describe "URI.parse" do # files file_l = URI.parse('file:///foo/bar.txt') - file_l.should be_kind_of(URI::Generic) + file_l.should.is_a?(URI::Generic) file = URI.parse('file:/foo/bar.txt') - file.should be_kind_of(URI::Generic) + file.should.is_a?(URI::Generic) end it "doesn't raise errors on URIs which has underscore in reg_name" do diff --git a/spec/ruby/library/uri/parser/extract_spec.rb b/spec/ruby/library/uri/parser/extract_spec.rb index 20d4565b08..f5ecd6ec8e 100644 --- a/spec/ruby/library/uri/parser/extract_spec.rb +++ b/spec/ruby/library/uri/parser/extract_spec.rb @@ -1,7 +1,90 @@ require_relative '../../../spec_helper' -require_relative '../shared/extract' require 'uri' describe "URI::Parser#extract" do - it_behaves_like :uri_extract, :extract, URI::Parser.new + before :all do + @parser = URI::Parser.new + end + + it "behaves according to its documentation" do + @parser.extract("text here http://foo.example.org/bla and here mailto:test@example.com and here also.").should == ["http://foo.example.org/bla", "mailto:test@example.com"] + end + + it "treats contiguous URIs as a single URI" do + @parser.extract('http://example.jphttp://example.jp').should == ['http://example.jphttp://example.jp'] + end + + it "treats pretty much anything with a colon as a URI" do + @parser.extract('From: XXX [mailto:xxx@xxx.xxx.xxx]').should == ['From:', 'mailto:xxx@xxx.xxx.xxx]'] + end + + it "wraps a URI string in an array" do + @parser.extract("http://github.com/brixen/rubyspec/tree/master").should == ["http://github.com/brixen/rubyspec/tree/master"] + end + + it "pulls a variety of protocol URIs from a string" do + @parser.extract("this is a string, it has http://rubini.us/ in it").should == ["http://rubini.us/"] + @parser.extract("mailto:spambait@example.com").should == ["mailto:spambait@example.com"] + @parser.extract("ftp://ruby-lang.org/").should == ["ftp://ruby-lang.org/"] + @parser.extract("https://mail.google.com").should == ["https://mail.google.com"] + @parser.extract("anything://example.com/").should == ["anything://example.com/"] + end + + it "pulls all URIs within a string in order into an array when a block is not given" do + @parser.extract("1.3. Example URI + + The following examples illustrate URI that are in common use. + + ftp://ftp.is.co.za/rfc/rfc1808.txt + -- ftp scheme for File Transfer Protocol services + + gopher://spinaltap.micro.umn.edu/00/Weather/California/Los%20Angeles + -- gopher scheme for Gopher and Gopher+ Protocol services + + http://www.math.uio.no/faq/compression-faq/part1.html + -- http scheme for Hypertext Transfer Protocol services + + mailto:mduerst@ifi.unizh.ch + -- mailto scheme for electronic mail addresses + + news:comp.infosystems.www.servers.unix + -- news scheme for USENET news groups and articles + + telnet://melvyl.ucop.edu/ + -- telnet scheme for interactive services via the TELNET Protocol + ").should == ["ftp://ftp.is.co.za/rfc/rfc1808.txt","gopher://spinaltap.micro.umn.edu/00/Weather/California/Los%20Angeles","http://www.math.uio.no/faq/compression-faq/part1.html","mailto:mduerst@ifi.unizh.ch","news:comp.infosystems.www.servers.unix","telnet://melvyl.ucop.edu/"] + end + + it "yields each URI in the given string in order to a block, if given, and returns nil" do + results = ["http://foo.example.org/bla", "mailto:test@example.com"] + @parser.extract("text here http://foo.example.org/bla and here mailto:test@example.com and here also.") {|uri| + uri.should == results.shift + }.should == nil + results.should == [] + end + + it "allows the user to specify a list of acceptable protocols of URIs to scan for" do + @parser.extract("1.3. Example URI + + The following examples illustrate URI that are in common use. + + ftp://ftp.is.co.za/rfc/rfc1808.txt + -- ftp scheme for File Transfer Protocol services + + gopher://spinaltap.micro.umn.edu/00/Weather/California/Los%20Angeles + -- gopher scheme for Gopher and Gopher+ Protocol services + + http://www.math.uio.no/faq/compression-faq/part1.html + -- http scheme for Hypertext Transfer Protocol services + + mailto:mduerst@ifi.unizh.ch + -- mailto scheme for electronic mail addresses + + news:comp.infosystems.www.servers.unix + -- news scheme for USENET news groups and articles + + telnet://melvyl.ucop.edu/ + -- telnet scheme for interactive services via the TELNET Protocol + ", ["http","ftp","mailto"]).should == ["ftp://ftp.is.co.za/rfc/rfc1808.txt","http://www.math.uio.no/faq/compression-faq/part1.html","mailto:mduerst@ifi.unizh.ch"] + end end diff --git a/spec/ruby/library/uri/parser/join_spec.rb b/spec/ruby/library/uri/parser/join_spec.rb index 0c9230be76..0fb29cf00a 100644 --- a/spec/ruby/library/uri/parser/join_spec.rb +++ b/spec/ruby/library/uri/parser/join_spec.rb @@ -1,7 +1,62 @@ require_relative '../../../spec_helper' -require_relative '../shared/join' require 'uri' describe "URI::Parser#join" do - it_behaves_like :uri_join, :join, URI::Parser.new + before :all do + @parser = URI::Parser.new + end + + it "returns a URI object of the concatenation of a protocol and domain, and a path" do + @parser.join("http://localhost/","main.rbx").should == URI.parse("http://localhost/main.rbx") + end + + it "accepts URI objects" do + @parser.join(URI("http://localhost/"),"main.rbx").should == URI.parse("http://localhost/main.rbx") + @parser.join("http://localhost/",URI("main.rbx")).should == URI.parse("http://localhost/main.rbx") + @parser.join(URI("http://localhost/"),URI("main.rbx")).should == URI.parse("http://localhost/main.rbx") + end + + it "accepts string-like arguments with to_str" do + str = mock('string-like') + str.should_receive(:to_str).and_return("http://ruby-lang.org") + str2 = mock('string-like also') + str2.should_receive(:to_str).and_return("foo/bar") + @parser.join(str, str2).should == URI.parse("http://ruby-lang.org/foo/bar") + end + + it "raises an error if given no argument" do + -> { + @parser.join + }.should.raise(ArgumentError) + end + + it "doesn't create redundant '/'s" do + @parser.join("http://localhost/", "/main.rbx").should == URI.parse("http://localhost/main.rbx") + end + + it "discards arguments given before an absolute uri" do + @parser.join("http://localhost/a/b/c/d", "http://ruby-lang.com/foo", "bar").should == URI.parse("http://ruby-lang.com/bar") + end + + it "resolves .. in paths" do + @parser.join("http://localhost/a/b/c/d", "../../e/f", "g/h/../i").to_s.should == "http://localhost/a/e/g/i" + end end + +# assert_equal(URI.parse('http://foo/bar'), URI.join('http://foo/bar')) +# assert_equal(URI.parse('http://foo/bar'), URI.join('http://foo', 'bar')) +# assert_equal(URI.parse('http://foo/bar/'), URI.join('http://foo', 'bar/')) +# +# assert_equal(URI.parse('http://foo/baz'), URI.join('http://foo', 'bar', 'baz')) +# assert_equal(URI.parse('http://foo/baz'), URI.join('http://foo', 'bar', '/baz')) +# assert_equal(URI.parse('http://foo/baz/'), URI.join('http://foo', 'bar', '/baz/')) +# assert_equal(URI.parse('http://foo/bar/baz'), URI.join('http://foo', 'bar/', 'baz')) +# assert_equal(URI.parse('http://foo/hoge'), URI.join('http://foo', 'bar', 'baz', 'hoge')) +# +# assert_equal(URI.parse('http://foo/bar/baz'), URI.join('http://foo', 'bar/baz')) +# assert_equal(URI.parse('http://foo/bar/hoge'), URI.join('http://foo', 'bar/baz', 'hoge')) +# assert_equal(URI.parse('http://foo/bar/baz/hoge'), URI.join('http://foo', 'bar/baz/', 'hoge')) +# assert_equal(URI.parse('http://foo/hoge'), URI.join('http://foo', 'bar/baz', '/hoge')) +# assert_equal(URI.parse('http://foo/bar/hoge'), URI.join('http://foo', 'bar/baz', 'hoge')) +# assert_equal(URI.parse('http://foo/bar/baz/hoge'), URI.join('http://foo', 'bar/baz/', 'hoge')) +# assert_equal(URI.parse('http://foo/hoge'), URI.join('http://foo', 'bar/baz', '/hoge')) diff --git a/spec/ruby/library/uri/parser/parse_spec.rb b/spec/ruby/library/uri/parser/parse_spec.rb index df126eab6d..0e6a06ebe5 100644 --- a/spec/ruby/library/uri/parser/parse_spec.rb +++ b/spec/ruby/library/uri/parser/parse_spec.rb @@ -1,7 +1,213 @@ require_relative '../../../spec_helper' require_relative '../fixtures/classes' -require_relative '../shared/parse' describe "URI::Parser#parse" do - it_behaves_like :uri_parse, :parse, URI::Parser.new + before :all do + @parser = URI::Parser.new + end + + it "returns a URI::HTTP object when parsing an HTTP URI" do + @parser.parse("http://www.example.com/").should.is_a?(URI::HTTP) + end + + it "populates the components of a parsed URI::HTTP, setting the port to 80 by default" do + # general case + URISpec.components(@parser.parse("http://user:pass@example.com/path/?query=val&q2=val2#fragment")).should == { + scheme: "http", + userinfo: "user:pass", + host: "example.com", + port: 80, + path: "/path/", + query: "query=val&q2=val2", + fragment: "fragment" + } + + # multiple paths + URISpec.components(@parser.parse("http://a/b/c/d;p?q")).should == { + scheme: "http", + userinfo: nil, + host: "a", + port: 80, + path: "/b/c/d;p", + query: "q", + fragment: nil + } + + # multi-level domain + URISpec.components(@parser.parse('http://www.math.uio.no/faq/compression-faq/part1.html')).should == { + scheme: "http", + userinfo: nil, + host: "www.math.uio.no", + port: 80, + path: "/faq/compression-faq/part1.html", + query: nil, + fragment: nil + } + end + + it "parses out the port number of a URI, when given" do + @parser.parse("http://example.com:8080/").port.should == 8080 + end + + it "returns a URI::HTTPS object when parsing an HTTPS URI" do + @parser.parse("https://important-intern-net.net").should.is_a?(URI::HTTPS) + end + + it "sets the port of a parsed https URI to 443 by default" do + @parser.parse("https://example.com/").port.should == 443 + end + + it "populates the components of a parsed URI::FTP object" do + # generic, empty password. + url = @parser.parse("ftp://anonymous@ruby-lang.org/pub/ruby/1.8/ruby-1.8.6.tar.bz2;type=i") + url.should.is_a?(URI::FTP) + URISpec.components(url).should == { + scheme: "ftp", + userinfo: "anonymous", + host: "ruby-lang.org", + port: 21, + path: "pub/ruby/1.8/ruby-1.8.6.tar.bz2", + typecode: "i" + } + + # multidomain, no user or password + url = @parser.parse('ftp://ftp.is.co.za/rfc/rfc1808.txt') + url.should.is_a?(URI::FTP) + URISpec.components(url).should == { + scheme: "ftp", + userinfo: nil, + host: "ftp.is.co.za", + port: 21, + path: "rfc/rfc1808.txt", + typecode: nil + } + + # empty user + url = @parser.parse('ftp://:pass@localhost/') + url.should.is_a?(URI::FTP) + URISpec.components(url).should == { + scheme: "ftp", + userinfo: ":pass", + host: "localhost", + port: 21, + path: "", + typecode: nil + } + url.password.should == "pass" + end + + it "returns a URI::LDAP object when parsing an LDAP URI" do + #taken from http://www.faqs.org/rfcs/rfc2255.html 'cause I don't really know what an LDAP url looks like + ldap_uris = %w{ ldap:///o=University%20of%20Michigan,c=US ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US?postalAddress ldap://host.com:6666/o=University%20of%20Michigan,c=US??sub?(cn=Babs%20Jensen) ldap://ldap.itd.umich.edu/c=GB?objectClass?one ldap://ldap.question.com/o=Question%3f,c=US?mail ldap://ldap.netscape.com/o=Babsco,c=US??(int=%5c00%5c00%5c00%5c04) ldap:///??sub??bindname=cn=Manager%2co=Foo ldap:///??sub??!bindname=cn=Manager%2co=Foo } + ldap_uris.each do |ldap_uri| + @parser.parse(ldap_uri).should.is_a?(URI::LDAP) + end + end + + it "populates the components of a parsed URI::LDAP object" do + URISpec.components(@parser.parse("ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US?postalAddress?scope?filter?extensions")).should == { + scheme: "ldap", + host: "ldap.itd.umich.edu", + port: 389, + dn: "o=University%20of%20Michigan,c=US", + attributes: "postalAddress", + scope: "scope", + filter: "filter", + extensions: "extensions" + } + end + + it "returns a URI::MailTo object when passed a mailto URI" do + @parser.parse("mailto:spam@mailinator.com").should.is_a?(URI::MailTo) + end + + it "populates the components of a parsed URI::MailTo object" do + URISpec.components(@parser.parse("mailto:spam@mailinator.com?subject=Discounts%20On%20Imported%20methods!!!&body=Exciting%20offer")).should == { + scheme: "mailto", + to: "spam@mailinator.com", + headers: [["subject","Discounts%20On%20Imported%20methods!!!"], + ["body", "Exciting%20offer"]] + } + end + + # TODO + # Test registry + it "does its best to extract components from URI::Generic objects" do + # generic + URISpec.components(URI("scheme://userinfo@host/path?query#fragment")).should == { + scheme: "scheme", + userinfo: "userinfo", + host: "host", + port: nil, + path: "/path", + query: "query", + fragment: "fragment", + registry: nil, + opaque: nil + } + + # gopher + gopher = @parser.parse('gopher://spinaltap.micro.umn.edu/00/Weather/California/Los%20Angeles') + gopher.should.is_a?(URI::Generic) + + URISpec.components(gopher).should == { + scheme: "gopher", + userinfo: nil, + host: "spinaltap.micro.umn.edu", + port: nil, + path: "/00/Weather/California/Los%20Angeles", + query: nil, + fragment: nil, + registry: nil, + opaque: nil + } + + # news + news = @parser.parse('news:comp.infosystems.www.servers.unix') + news.should.is_a?(URI::Generic) + URISpec.components(news).should == { + scheme: "news", + userinfo: nil, + host: nil, + port: nil, + path: nil, + query: nil, + fragment: nil, + registry: nil, + opaque: "comp.infosystems.www.servers.unix" + } + + # telnet + telnet = @parser.parse('telnet://melvyl.ucop.edu/') + telnet.should.is_a?(URI::Generic) + URISpec.components(telnet).should == { + scheme: "telnet", + userinfo: nil, + host: "melvyl.ucop.edu", + port: nil, + path: "/", + query: nil, + fragment: nil, + registry: nil, + opaque: nil + } + + # files + file_l = @parser.parse('file:///foo/bar.txt') + file_l.should.is_a?(URI::Generic) + file = @parser.parse('file:/foo/bar.txt') + file.should.is_a?(URI::Generic) + end + + if URI::DEFAULT_PARSER == URI::RFC2396_Parser + it "raises errors on malformed URIs" do + -> { @parser.parse('http://a_b:80/') }.should.raise(URI::InvalidURIError) + -> { @parser.parse('http://a_b/') }.should.raise(URI::InvalidURIError) + end + elsif URI::DEFAULT_PARSER == URI::RFC3986_Parser + it "does not raise errors on URIs contained underscore" do + -> { @parser.parse('http://a_b:80/') }.should_not.raise(URI::InvalidURIError) + -> { @parser.parse('http://a_b/') }.should_not.raise(URI::InvalidURIError) + end + end end diff --git a/spec/ruby/library/uri/plus_spec.rb b/spec/ruby/library/uri/plus_spec.rb index b84b0767c1..51fb5e3750 100644 --- a/spec/ruby/library/uri/plus_spec.rb +++ b/spec/ruby/library/uri/plus_spec.rb @@ -36,7 +36,7 @@ describe "URI#+" do end it "raises a URI::BadURIError when adding two relative URIs" do - -> {URI.parse('a/b/c') + "d"}.should raise_error(URI::BadURIError) + -> {URI.parse('a/b/c') + "d"}.should.raise(URI::BadURIError) end #Todo: make more BDD? @@ -47,403 +47,403 @@ describe "URI#+" do # http://a/b/c/d;p?q # g:h = g:h url = @base_url.merge('g:h') - url.should be_kind_of(URI::Generic) + url.should.is_a?(URI::Generic) url.to_s.should == 'g:h' url = @base_url.route_to('g:h') - url.should be_kind_of(URI::Generic) + url.should.is_a?(URI::Generic) url.to_s.should == 'g:h' # http://a/b/c/d;p?q # g = http://a/b/c/g url = @base_url.merge('g') - url.should be_kind_of(URI::HTTP) + url.should.is_a?(URI::HTTP) url.to_s.should == 'http://a/b/c/g' url = @base_url.route_to('http://a/b/c/g') - url.should be_kind_of(URI::Generic) + url.should.is_a?(URI::Generic) url.to_s.should == 'g' # http://a/b/c/d;p?q # ./g = http://a/b/c/g url = @base_url.merge('./g') - url.should be_kind_of(URI::HTTP) + url.should.is_a?(URI::HTTP) url.to_s.should == 'http://a/b/c/g' url = @base_url.route_to('http://a/b/c/g') - url.should be_kind_of(URI::Generic) + url.should.is_a?(URI::Generic) url.to_s.should_not == './g' # ok url.to_s.should == 'g' # http://a/b/c/d;p?q # g/ = http://a/b/c/g/ url = @base_url.merge('g/') - url.should be_kind_of(URI::HTTP) + url.should.is_a?(URI::HTTP) url.to_s.should == 'http://a/b/c/g/' url = @base_url.route_to('http://a/b/c/g/') - url.should be_kind_of(URI::Generic) + url.should.is_a?(URI::Generic) url.to_s.should == 'g/' # http://a/b/c/d;p?q # /g = http://a/g url = @base_url.merge('/g') - url.should be_kind_of(URI::HTTP) + url.should.is_a?(URI::HTTP) url.to_s.should == 'http://a/g' url = @base_url.route_to('http://a/g') - url.should be_kind_of(URI::Generic) + url.should.is_a?(URI::Generic) url.to_s.should_not == '/g' # ok url.to_s.should == '../../g' # http://a/b/c/d;p?q # //g = http://g url = @base_url.merge('//g') - url.should be_kind_of(URI::HTTP) + url.should.is_a?(URI::HTTP) url.to_s.should == 'http://g' url = @base_url.route_to('http://g') - url.should be_kind_of(URI::Generic) + url.should.is_a?(URI::Generic) url.to_s.should == '//g' # http://a/b/c/d;p?q # ?y = http://a/b/c/?y url = @base_url.merge('?y') - url.should be_kind_of(URI::HTTP) + url.should.is_a?(URI::HTTP) url.to_s.should == 'http://a/b/c/d;p?y' url = @base_url.route_to('http://a/b/c/?y') - url.should be_kind_of(URI::Generic) + url.should.is_a?(URI::Generic) url.to_s.should == '?y' # http://a/b/c/d;p?q # g?y = http://a/b/c/g?y url = @base_url.merge('g?y') - url.should be_kind_of(URI::HTTP) + url.should.is_a?(URI::HTTP) url.to_s.should == 'http://a/b/c/g?y' url = @base_url.route_to('http://a/b/c/g?y') - url.should be_kind_of(URI::Generic) + url.should.is_a?(URI::Generic) url.to_s.should == 'g?y' # http://a/b/c/d;p?q # #s = (current document)#s url = @base_url.merge('#s') - url.should be_kind_of(URI::HTTP) + url.should.is_a?(URI::HTTP) url.to_s.should == @base_url.to_s + '#s' url = @base_url.route_to(@base_url.to_s + '#s') - url.should be_kind_of(URI::Generic) + url.should.is_a?(URI::Generic) url.to_s.should == '#s' # http://a/b/c/d;p?q # g#s = http://a/b/c/g#s url = @base_url.merge('g#s') - url.should be_kind_of(URI::HTTP) + url.should.is_a?(URI::HTTP) url.to_s.should == 'http://a/b/c/g#s' url = @base_url.route_to('http://a/b/c/g#s') - url.should be_kind_of(URI::Generic) + url.should.is_a?(URI::Generic) url.to_s.should == 'g#s' # http://a/b/c/d;p?q # g?y#s = http://a/b/c/g?y#s url = @base_url.merge('g?y#s') - url.should be_kind_of(URI::HTTP) + url.should.is_a?(URI::HTTP) url.to_s.should == 'http://a/b/c/g?y#s' url = @base_url.route_to('http://a/b/c/g?y#s') - url.should be_kind_of(URI::Generic) + url.should.is_a?(URI::Generic) url.to_s.should == 'g?y#s' # http://a/b/c/d;p?q # ;x = http://a/b/c/;x url = @base_url.merge(';x') - url.should be_kind_of(URI::HTTP) + url.should.is_a?(URI::HTTP) url.to_s.should == 'http://a/b/c/;x' url = @base_url.route_to('http://a/b/c/;x') - url.should be_kind_of(URI::Generic) + url.should.is_a?(URI::Generic) url.to_s.should == ';x' # http://a/b/c/d;p?q # g;x = http://a/b/c/g;x url = @base_url.merge('g;x') - url.should be_kind_of(URI::HTTP) + url.should.is_a?(URI::HTTP) url.to_s.should == 'http://a/b/c/g;x' url = @base_url.route_to('http://a/b/c/g;x') - url.should be_kind_of(URI::Generic) + url.should.is_a?(URI::Generic) url.to_s.should == 'g;x' # http://a/b/c/d;p?q # g;x?y#s = http://a/b/c/g;x?y#s url = @base_url.merge('g;x?y#s') - url.should be_kind_of(URI::HTTP) + url.should.is_a?(URI::HTTP) url.to_s.should == 'http://a/b/c/g;x?y#s' url = @base_url.route_to('http://a/b/c/g;x?y#s') - url.should be_kind_of(URI::Generic) + url.should.is_a?(URI::Generic) url.to_s.should == 'g;x?y#s' # http://a/b/c/d;p?q # . = http://a/b/c/ url = @base_url.merge('.') - url.should be_kind_of(URI::HTTP) + url.should.is_a?(URI::HTTP) url.to_s.should == 'http://a/b/c/' url = @base_url.route_to('http://a/b/c/') - url.should be_kind_of(URI::Generic) + url.should.is_a?(URI::Generic) url.to_s.should_not == '.' # ok url.to_s.should == './' # http://a/b/c/d;p?q # ./ = http://a/b/c/ url = @base_url.merge('./') - url.should be_kind_of(URI::HTTP) + url.should.is_a?(URI::HTTP) url.to_s.should == 'http://a/b/c/' url = @base_url.route_to('http://a/b/c/') - url.should be_kind_of(URI::Generic) + url.should.is_a?(URI::Generic) url.to_s.should == './' # http://a/b/c/d;p?q # .. = http://a/b/ url = @base_url.merge('..') - url.should be_kind_of(URI::HTTP) + url.should.is_a?(URI::HTTP) url.to_s.should == 'http://a/b/' url = @base_url.route_to('http://a/b/') - url.should be_kind_of(URI::Generic) + url.should.is_a?(URI::Generic) url.to_s.should_not == '..' # ok url.to_s.should == '../' # http://a/b/c/d;p?q # ../ = http://a/b/ url = @base_url.merge('../') - url.should be_kind_of(URI::HTTP) + url.should.is_a?(URI::HTTP) url.to_s.should == 'http://a/b/' url = @base_url.route_to('http://a/b/') - url.should be_kind_of(URI::Generic) + url.should.is_a?(URI::Generic) url.to_s.should == '../' # http://a/b/c/d;p?q # ../g = http://a/b/g url = @base_url.merge('../g') - url.should be_kind_of(URI::HTTP) + url.should.is_a?(URI::HTTP) url.to_s.should == 'http://a/b/g' url = @base_url.route_to('http://a/b/g') - url.should be_kind_of(URI::Generic) + url.should.is_a?(URI::Generic) url.to_s.should == '../g' # http://a/b/c/d;p?q # ../.. = http://a/ url = @base_url.merge('../..') - url.should be_kind_of(URI::HTTP) + url.should.is_a?(URI::HTTP) url.to_s.should == 'http://a/' url = @base_url.route_to('http://a/') - url.should be_kind_of(URI::Generic) + url.should.is_a?(URI::Generic) url.to_s.should_not == '../..' # ok url.to_s.should == '../../' # http://a/b/c/d;p?q # ../../ = http://a/ url = @base_url.merge('../../') - url.should be_kind_of(URI::HTTP) + url.should.is_a?(URI::HTTP) url.to_s.should == 'http://a/' url = @base_url.route_to('http://a/') - url.should be_kind_of(URI::Generic) + url.should.is_a?(URI::Generic) url.to_s.should == '../../' # http://a/b/c/d;p?q # ../../g = http://a/g url = @base_url.merge('../../g') - url.should be_kind_of(URI::HTTP) + url.should.is_a?(URI::HTTP) url.to_s.should == 'http://a/g' url = @base_url.route_to('http://a/g') - url.should be_kind_of(URI::Generic) + url.should.is_a?(URI::Generic) url.to_s.should == '../../g' # http://a/b/c/d;p?q # <> = (current document) url = @base_url.merge('') - url.should be_kind_of(URI::HTTP) + url.should.is_a?(URI::HTTP) url.to_s.should == 'http://a/b/c/d;p?q' url = @base_url.route_to('http://a/b/c/d;p?q') - url.should be_kind_of(URI::Generic) + url.should.is_a?(URI::Generic) url.to_s.should == '' # http://a/b/c/d;p?q # /./g = http://a/./g url = @base_url.merge('/./g') - url.should be_kind_of(URI::HTTP) + url.should.is_a?(URI::HTTP) url.to_s.should == 'http://a/g' url = @base_url.route_to('http://a/./g') - url.should be_kind_of(URI::Generic) + url.should.is_a?(URI::Generic) url.to_s.should == '/./g' # http://a/b/c/d;p?q # /../g = http://a/../g url = @base_url.merge('/../g') - url.should be_kind_of(URI::HTTP) + url.should.is_a?(URI::HTTP) url.to_s.should == 'http://a/g' url = @base_url.route_to('http://a/../g') - url.should be_kind_of(URI::Generic) + url.should.is_a?(URI::Generic) url.to_s.should == '/../g' # http://a/b/c/d;p?q # g. = http://a/b/c/g. url = @base_url.merge('g.') - url.should be_kind_of(URI::HTTP) + url.should.is_a?(URI::HTTP) url.to_s.should == 'http://a/b/c/g.' url = @base_url.route_to('http://a/b/c/g.') - url.should be_kind_of(URI::Generic) + url.should.is_a?(URI::Generic) url.to_s.should == 'g.' # http://a/b/c/d;p?q # .g = http://a/b/c/.g url = @base_url.merge('.g') - url.should be_kind_of(URI::HTTP) + url.should.is_a?(URI::HTTP) url.to_s.should == 'http://a/b/c/.g' url = @base_url.route_to('http://a/b/c/.g') - url.should be_kind_of(URI::Generic) + url.should.is_a?(URI::Generic) url.to_s.should == '.g' # http://a/b/c/d;p?q # g.. = http://a/b/c/g.. url = @base_url.merge('g..') - url.should be_kind_of(URI::HTTP) + url.should.is_a?(URI::HTTP) url.to_s.should == 'http://a/b/c/g..' url = @base_url.route_to('http://a/b/c/g..') - url.should be_kind_of(URI::Generic) + url.should.is_a?(URI::Generic) url.to_s.should == 'g..' # http://a/b/c/d;p?q # ..g = http://a/b/c/..g url = @base_url.merge('..g') - url.should be_kind_of(URI::HTTP) + url.should.is_a?(URI::HTTP) url.to_s.should == 'http://a/b/c/..g' url = @base_url.route_to('http://a/b/c/..g') - url.should be_kind_of(URI::Generic) + url.should.is_a?(URI::Generic) url.to_s.should == '..g' # http://a/b/c/d;p?q # ../../../g = http://a/../g url = @base_url.merge('../../../g') - url.should be_kind_of(URI::HTTP) + url.should.is_a?(URI::HTTP) url.to_s.should == 'http://a/g' url = @base_url.route_to('http://a/../g') - url.should be_kind_of(URI::Generic) + url.should.is_a?(URI::Generic) url.to_s.should_not == '../../../g' # ok? yes, it confuses you url.to_s.should == '/../g' # and it is clearly # http://a/b/c/d;p?q # ../../../../g = http://a/../../g url = @base_url.merge('../../../../g') - url.should be_kind_of(URI::HTTP) + url.should.is_a?(URI::HTTP) url.to_s.should == 'http://a/g' url = @base_url.route_to('http://a/../../g') - url.should be_kind_of(URI::Generic) + url.should.is_a?(URI::Generic) url.to_s.should_not == '../../../../g' # ok? yes, it confuses you url.to_s.should == '/../../g' # and it is clearly # http://a/b/c/d;p?q # ./../g = http://a/b/g url = @base_url.merge('./../g') - url.should be_kind_of(URI::HTTP) + url.should.is_a?(URI::HTTP) url.to_s.should == 'http://a/b/g' url = @base_url.route_to('http://a/b/g') - url.should be_kind_of(URI::Generic) + url.should.is_a?(URI::Generic) url.to_s.should_not == './../g' # ok url.to_s.should == '../g' # http://a/b/c/d;p?q # ./g/. = http://a/b/c/g/ url = @base_url.merge('./g/.') - url.should be_kind_of(URI::HTTP) + url.should.is_a?(URI::HTTP) url.to_s.should == 'http://a/b/c/g/' url = @base_url.route_to('http://a/b/c/g/') - url.should be_kind_of(URI::Generic) + url.should.is_a?(URI::Generic) url.to_s.should_not == './g/.' # ok url.to_s.should == 'g/' # http://a/b/c/d;p?q # g/./h = http://a/b/c/g/h url = @base_url.merge('g/./h') - url.should be_kind_of(URI::HTTP) + url.should.is_a?(URI::HTTP) url.to_s.should == 'http://a/b/c/g/h' url = @base_url.route_to('http://a/b/c/g/h') - url.should be_kind_of(URI::Generic) + url.should.is_a?(URI::Generic) url.to_s.should_not == 'g/./h' # ok url.to_s.should == 'g/h' # http://a/b/c/d;p?q # g/../h = http://a/b/c/h url = @base_url.merge('g/../h') - url.should be_kind_of(URI::HTTP) + url.should.is_a?(URI::HTTP) url.to_s.should == 'http://a/b/c/h' url = @base_url.route_to('http://a/b/c/h') - url.should be_kind_of(URI::Generic) + url.should.is_a?(URI::Generic) url.to_s.should_not == 'g/../h' # ok url.to_s.should == 'h' # http://a/b/c/d;p?q # g;x=1/./y = http://a/b/c/g;x=1/y url = @base_url.merge('g;x=1/./y') - url.should be_kind_of(URI::HTTP) + url.should.is_a?(URI::HTTP) url.to_s.should == 'http://a/b/c/g;x=1/y' url = @base_url.route_to('http://a/b/c/g;x=1/y') - url.should be_kind_of(URI::Generic) + url.should.is_a?(URI::Generic) url.to_s.should_not == 'g;x=1/./y' # ok url.to_s.should == 'g;x=1/y' # http://a/b/c/d;p?q # g;x=1/../y = http://a/b/c/y url = @base_url.merge('g;x=1/../y') - url.should be_kind_of(URI::HTTP) + url.should.is_a?(URI::HTTP) url.to_s.should == 'http://a/b/c/y' url = @base_url.route_to('http://a/b/c/y') - url.should be_kind_of(URI::Generic) + url.should.is_a?(URI::Generic) url.to_s.should_not == 'g;x=1/../y' # ok url.to_s.should == 'y' # http://a/b/c/d;p?q # g?y/./x = http://a/b/c/g?y/./x url = @base_url.merge('g?y/./x') - url.should be_kind_of(URI::HTTP) + url.should.is_a?(URI::HTTP) url.to_s.should == 'http://a/b/c/g?y/./x' url = @base_url.route_to('http://a/b/c/g?y/./x') - url.should be_kind_of(URI::Generic) + url.should.is_a?(URI::Generic) url.to_s.should == 'g?y/./x' # http://a/b/c/d;p?q # g?y/../x = http://a/b/c/g?y/../x url = @base_url.merge('g?y/../x') - url.should be_kind_of(URI::HTTP) + url.should.is_a?(URI::HTTP) url.to_s.should == 'http://a/b/c/g?y/../x' url = @base_url.route_to('http://a/b/c/g?y/../x') - url.should be_kind_of(URI::Generic) + url.should.is_a?(URI::Generic) url.to_s.should == 'g?y/../x' # http://a/b/c/d;p?q # g#s/./x = http://a/b/c/g#s/./x url = @base_url.merge('g#s/./x') - url.should be_kind_of(URI::HTTP) + url.should.is_a?(URI::HTTP) url.to_s.should == 'http://a/b/c/g#s/./x' url = @base_url.route_to('http://a/b/c/g#s/./x') - url.should be_kind_of(URI::Generic) + url.should.is_a?(URI::Generic) url.to_s.should == 'g#s/./x' # http://a/b/c/d;p?q # g#s/../x = http://a/b/c/g#s/../x url = @base_url.merge('g#s/../x') - url.should be_kind_of(URI::HTTP) + url.should.is_a?(URI::HTTP) url.to_s.should == 'http://a/b/c/g#s/../x' url = @base_url.route_to('http://a/b/c/g#s/../x') - url.should be_kind_of(URI::Generic) + url.should.is_a?(URI::Generic) url.to_s.should == 'g#s/../x' # http://a/b/c/d;p?q # http:g = http:g ; for validating parsers # | http://a/b/c/g ; for backwards compatibility url = @base_url.merge('http:g') - url.should be_kind_of(URI::HTTP) + url.should.is_a?(URI::HTTP) url.to_s.should == 'http:g' url = @base_url.route_to('http:g') - url.should be_kind_of(URI::Generic) + url.should.is_a?(URI::Generic) url.to_s.should == 'http:g' end end diff --git a/spec/ruby/library/uri/select_spec.rb b/spec/ruby/library/uri/select_spec.rb index 839b68b3a1..27591f69f2 100644 --- a/spec/ruby/library/uri/select_spec.rb +++ b/spec/ruby/library/uri/select_spec.rb @@ -15,13 +15,13 @@ describe "URI#select" do end it "raises an ArgumentError if a component is requested that isn't valid under the given scheme" do - -> { URI("mailto:spam@mailinator.com").select(:path) }.should raise_error(ArgumentError) - -> { URI("http://blog.blag.web").select(:typecode) }.should raise_error(ArgumentError) + -> { URI("mailto:spam@mailinator.com").select(:path) }.should.raise(ArgumentError) + -> { URI("http://blog.blag.web").select(:typecode) }.should.raise(ArgumentError) end it "raises an ArgumentError if given strings rather than symbols" do -> { URI("http://host:8080/path/").select("scheme","host","port",'path') - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) end end diff --git a/spec/ruby/library/uri/set_component_spec.rb b/spec/ruby/library/uri/set_component_spec.rb index 642a5d6fcf..15f1ed1f87 100644 --- a/spec/ruby/library/uri/set_component_spec.rb +++ b/spec/ruby/library/uri/set_component_spec.rb @@ -6,40 +6,42 @@ 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) + -> { uri.password = 'bar' }.should.raise(URI::InvalidURIError) uri.userinfo = 'foo:bar' uri.to_s.should == 'http://foo:bar@example.com' - -> { uri.registry = 'bar' }.should raise_error(URI::InvalidURIError) - -> { uri.opaque = 'bar' }.should raise_error(URI::InvalidURIError) + -> { uri.registry = 'bar' }.should.raise(URI::InvalidURIError) + -> { uri.opaque = 'bar' }.should.raise(URI::InvalidURIError) uri = URI.parse('mailto:foo@example.com') - -> { uri.user = 'bar' }.should raise_error(URI::InvalidURIError) - -> { uri.password = 'bar' }.should raise_error(URI::InvalidURIError) - -> { uri.userinfo = ['bar', 'baz'] }.should raise_error(URI::InvalidURIError) - -> { uri.host = 'bar' }.should raise_error(URI::InvalidURIError) - -> { uri.port = 'bar' }.should raise_error(URI::InvalidURIError) - -> { uri.path = 'bar' }.should raise_error(URI::InvalidURIError) - -> { uri.query = 'bar' }.should raise_error(URI::InvalidURIError) + -> { uri.user = 'bar' }.should.raise(URI::InvalidURIError) + -> { uri.password = 'bar' }.should.raise(URI::InvalidURIError) + -> { uri.userinfo = ['bar', 'baz'] }.should.raise(URI::InvalidURIError) + -> { uri.host = 'bar' }.should.raise(URI::InvalidURIError) + -> { uri.port = 'bar' }.should.raise(URI::InvalidURIError) + -> { uri.path = 'bar' }.should.raise(URI::InvalidURIError) + -> { uri.query = 'bar' }.should.raise(URI::InvalidURIError) end end diff --git a/spec/ruby/library/uri/shared/eql.rb b/spec/ruby/library/uri/shared/eql.rb index 2cc960d39a..978c4aae05 100644 --- a/spec/ruby/library/uri/shared/eql.rb +++ b/spec/ruby/library/uri/shared/eql.rb @@ -3,7 +3,7 @@ describe :uri_eql, shared: true do URISpec::NORMALIZED_FORMS.each do |form| normal_uri = URI(form[:normalized]) form[:different].each do |other| - URI(other).send(@method, normal_uri).should be_false + URI(other).send(@method, normal_uri).should == false end end end @@ -11,7 +11,7 @@ end describe :uri_eql_against_other_types, shared: true do it "returns false for when compared to non-uri objects" do - URI("http://example.com/").send(@method, "http://example.com/").should be_false - URI("http://example.com/").send(@method, nil).should be_false + URI("http://example.com/").send(@method, "http://example.com/").should == false + URI("http://example.com/").send(@method, nil).should == false end end diff --git a/spec/ruby/library/uri/shared/extract.rb b/spec/ruby/library/uri/shared/extract.rb deleted file mode 100644 index efe60ae4b9..0000000000 --- a/spec/ruby/library/uri/shared/extract.rb +++ /dev/null @@ -1,83 +0,0 @@ -describe :uri_extract, shared: true do - it "behaves according to its documentation" do - @object.extract("text here http://foo.example.org/bla and here mailto:test@example.com and here also.").should == ["http://foo.example.org/bla", "mailto:test@example.com"] - end - - it "treats contiguous URIs as a single URI" do - @object.extract('http://example.jphttp://example.jp').should == ['http://example.jphttp://example.jp'] - end - - it "treats pretty much anything with a colon as a URI" do - @object.extract('From: XXX [mailto:xxx@xxx.xxx.xxx]').should == ['From:', 'mailto:xxx@xxx.xxx.xxx]'] - end - - it "wraps a URI string in an array" do - @object.extract("http://github.com/brixen/rubyspec/tree/master").should == ["http://github.com/brixen/rubyspec/tree/master"] - end - - it "pulls a variety of protocol URIs from a string" do - @object.extract("this is a string, it has http://rubini.us/ in it").should == ["http://rubini.us/"] - @object.extract("mailto:spambait@example.com").should == ["mailto:spambait@example.com"] - @object.extract("ftp://ruby-lang.org/").should == ["ftp://ruby-lang.org/"] - @object.extract("https://mail.google.com").should == ["https://mail.google.com"] - @object.extract("anything://example.com/").should == ["anything://example.com/"] - end - - it "pulls all URIs within a string in order into an array when a block is not given" do - @object.extract("1.3. Example URI - - The following examples illustrate URI that are in common use. - - ftp://ftp.is.co.za/rfc/rfc1808.txt - -- ftp scheme for File Transfer Protocol services - - gopher://spinaltap.micro.umn.edu/00/Weather/California/Los%20Angeles - -- gopher scheme for Gopher and Gopher+ Protocol services - - http://www.math.uio.no/faq/compression-faq/part1.html - -- http scheme for Hypertext Transfer Protocol services - - mailto:mduerst@ifi.unizh.ch - -- mailto scheme for electronic mail addresses - - news:comp.infosystems.www.servers.unix - -- news scheme for USENET news groups and articles - - telnet://melvyl.ucop.edu/ - -- telnet scheme for interactive services via the TELNET Protocol - ").should == ["ftp://ftp.is.co.za/rfc/rfc1808.txt","gopher://spinaltap.micro.umn.edu/00/Weather/California/Los%20Angeles","http://www.math.uio.no/faq/compression-faq/part1.html","mailto:mduerst@ifi.unizh.ch","news:comp.infosystems.www.servers.unix","telnet://melvyl.ucop.edu/"] - end - - it "yields each URI in the given string in order to a block, if given, and returns nil" do - results = ["http://foo.example.org/bla", "mailto:test@example.com"] - @object.extract("text here http://foo.example.org/bla and here mailto:test@example.com and here also.") {|uri| - uri.should == results.shift - }.should == nil - results.should == [] - end - - it "allows the user to specify a list of acceptable protocols of URIs to scan for" do - @object.extract("1.3. Example URI - - The following examples illustrate URI that are in common use. - - ftp://ftp.is.co.za/rfc/rfc1808.txt - -- ftp scheme for File Transfer Protocol services - - gopher://spinaltap.micro.umn.edu/00/Weather/California/Los%20Angeles - -- gopher scheme for Gopher and Gopher+ Protocol services - - http://www.math.uio.no/faq/compression-faq/part1.html - -- http scheme for Hypertext Transfer Protocol services - - mailto:mduerst@ifi.unizh.ch - -- mailto scheme for electronic mail addresses - - news:comp.infosystems.www.servers.unix - -- news scheme for USENET news groups and articles - - telnet://melvyl.ucop.edu/ - -- telnet scheme for interactive services via the TELNET Protocol - ", ["http","ftp","mailto"]).should == ["ftp://ftp.is.co.za/rfc/rfc1808.txt","http://www.math.uio.no/faq/compression-faq/part1.html","mailto:mduerst@ifi.unizh.ch"] - end -end diff --git a/spec/ruby/library/uri/shared/join.rb b/spec/ruby/library/uri/shared/join.rb deleted file mode 100644 index 4df0782b37..0000000000 --- a/spec/ruby/library/uri/shared/join.rb +++ /dev/null @@ -1,56 +0,0 @@ -describe :uri_join, shared: true do - it "returns a URI object of the concatenation of a protocol and domain, and a path" do - @object.join("http://localhost/","main.rbx").should == URI.parse("http://localhost/main.rbx") - end - - it "accepts URI objects" do - @object.join(URI("http://localhost/"),"main.rbx").should == URI.parse("http://localhost/main.rbx") - @object.join("http://localhost/",URI("main.rbx")).should == URI.parse("http://localhost/main.rbx") - @object.join(URI("http://localhost/"),URI("main.rbx")).should == URI.parse("http://localhost/main.rbx") - end - - it "accepts string-like arguments with to_str" do - str = mock('string-like') - str.should_receive(:to_str).and_return("http://ruby-lang.org") - str2 = mock('string-like also') - str2.should_receive(:to_str).and_return("foo/bar") - @object.join(str, str2).should == URI.parse("http://ruby-lang.org/foo/bar") - end - - it "raises an error if given no argument" do - -> { - @object.join - }.should raise_error(ArgumentError) - end - - it "doesn't create redundant '/'s" do - @object.join("http://localhost/", "/main.rbx").should == URI.parse("http://localhost/main.rbx") - end - - it "discards arguments given before an absolute uri" do - @object.join("http://localhost/a/b/c/d", "http://ruby-lang.com/foo", "bar").should == URI.parse("http://ruby-lang.com/bar") - end - - it "resolves .. in paths" do - @object.join("http://localhost/a/b/c/d", "../../e/f", "g/h/../i").to_s.should == "http://localhost/a/e/g/i" - end -end - - -# assert_equal(URI.parse('http://foo/bar'), URI.join('http://foo/bar')) -# assert_equal(URI.parse('http://foo/bar'), URI.join('http://foo', 'bar')) -# assert_equal(URI.parse('http://foo/bar/'), URI.join('http://foo', 'bar/')) -# -# assert_equal(URI.parse('http://foo/baz'), URI.join('http://foo', 'bar', 'baz')) -# assert_equal(URI.parse('http://foo/baz'), URI.join('http://foo', 'bar', '/baz')) -# assert_equal(URI.parse('http://foo/baz/'), URI.join('http://foo', 'bar', '/baz/')) -# assert_equal(URI.parse('http://foo/bar/baz'), URI.join('http://foo', 'bar/', 'baz')) -# assert_equal(URI.parse('http://foo/hoge'), URI.join('http://foo', 'bar', 'baz', 'hoge')) -# -# assert_equal(URI.parse('http://foo/bar/baz'), URI.join('http://foo', 'bar/baz')) -# assert_equal(URI.parse('http://foo/bar/hoge'), URI.join('http://foo', 'bar/baz', 'hoge')) -# assert_equal(URI.parse('http://foo/bar/baz/hoge'), URI.join('http://foo', 'bar/baz/', 'hoge')) -# assert_equal(URI.parse('http://foo/hoge'), URI.join('http://foo', 'bar/baz', '/hoge')) -# assert_equal(URI.parse('http://foo/bar/hoge'), URI.join('http://foo', 'bar/baz', 'hoge')) -# assert_equal(URI.parse('http://foo/bar/baz/hoge'), URI.join('http://foo', 'bar/baz/', 'hoge')) -# assert_equal(URI.parse('http://foo/hoge'), URI.join('http://foo', 'bar/baz', '/hoge')) diff --git a/spec/ruby/library/uri/shared/parse.rb b/spec/ruby/library/uri/shared/parse.rb deleted file mode 100644 index c5057b6c4b..0000000000 --- a/spec/ruby/library/uri/shared/parse.rb +++ /dev/null @@ -1,206 +0,0 @@ -describe :uri_parse, shared: true do - it "returns a URI::HTTP object when parsing an HTTP URI" do - @object.parse("http://www.example.com/").should be_kind_of(URI::HTTP) - end - - it "populates the components of a parsed URI::HTTP, setting the port to 80 by default" do - # general case - URISpec.components(@object.parse("http://user:pass@example.com/path/?query=val&q2=val2#fragment")).should == { - scheme: "http", - userinfo: "user:pass", - host: "example.com", - port: 80, - path: "/path/", - query: "query=val&q2=val2", - fragment: "fragment" - } - - # multiple paths - URISpec.components(@object.parse("http://a/b/c/d;p?q")).should == { - scheme: "http", - userinfo: nil, - host: "a", - port: 80, - path: "/b/c/d;p", - query: "q", - fragment: nil - } - - # multi-level domain - URISpec.components(@object.parse('http://www.math.uio.no/faq/compression-faq/part1.html')).should == { - scheme: "http", - userinfo: nil, - host: "www.math.uio.no", - port: 80, - path: "/faq/compression-faq/part1.html", - query: nil, - fragment: nil - } - end - - it "parses out the port number of a URI, when given" do - @object.parse("http://example.com:8080/").port.should == 8080 - end - - it "returns a URI::HTTPS object when parsing an HTTPS URI" do - @object.parse("https://important-intern-net.net").should be_kind_of(URI::HTTPS) - end - - it "sets the port of a parsed https URI to 443 by default" do - @object.parse("https://example.com/").port.should == 443 - end - - it "populates the components of a parsed URI::FTP object" do - # generic, empty password. - url = @object.parse("ftp://anonymous@ruby-lang.org/pub/ruby/1.8/ruby-1.8.6.tar.bz2;type=i") - url.should be_kind_of(URI::FTP) - URISpec.components(url).should == { - scheme: "ftp", - userinfo: "anonymous", - host: "ruby-lang.org", - port: 21, - path: "pub/ruby/1.8/ruby-1.8.6.tar.bz2", - typecode: "i" - } - - # multidomain, no user or password - url = @object.parse('ftp://ftp.is.co.za/rfc/rfc1808.txt') - url.should be_kind_of(URI::FTP) - URISpec.components(url).should == { - scheme: "ftp", - userinfo: nil, - host: "ftp.is.co.za", - port: 21, - path: "rfc/rfc1808.txt", - typecode: nil - } - - # empty user - url = @object.parse('ftp://:pass@localhost/') - url.should be_kind_of(URI::FTP) - URISpec.components(url).should == { - scheme: "ftp", - userinfo: ":pass", - host: "localhost", - port: 21, - path: "", - typecode: nil - } - url.password.should == "pass" - end - - it "returns a URI::LDAP object when parsing an LDAP URI" do - #taken from http://www.faqs.org/rfcs/rfc2255.html 'cause I don't really know what an LDAP url looks like - ldap_uris = %w{ ldap:///o=University%20of%20Michigan,c=US ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US?postalAddress ldap://host.com:6666/o=University%20of%20Michigan,c=US??sub?(cn=Babs%20Jensen) ldap://ldap.itd.umich.edu/c=GB?objectClass?one ldap://ldap.question.com/o=Question%3f,c=US?mail ldap://ldap.netscape.com/o=Babsco,c=US??(int=%5c00%5c00%5c00%5c04) ldap:///??sub??bindname=cn=Manager%2co=Foo ldap:///??sub??!bindname=cn=Manager%2co=Foo } - ldap_uris.each do |ldap_uri| - @object.parse(ldap_uri).should be_kind_of(URI::LDAP) - end - end - - it "populates the components of a parsed URI::LDAP object" do - URISpec.components(@object.parse("ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US?postalAddress?scope?filter?extensions")).should == { - scheme: "ldap", - host: "ldap.itd.umich.edu", - port: 389, - dn: "o=University%20of%20Michigan,c=US", - attributes: "postalAddress", - scope: "scope", - filter: "filter", - extensions: "extensions" - } - end - - it "returns a URI::MailTo object when passed a mailto URI" do - @object.parse("mailto:spam@mailinator.com").should be_kind_of(URI::MailTo) - end - - it "populates the components of a parsed URI::MailTo object" do - URISpec.components(@object.parse("mailto:spam@mailinator.com?subject=Discounts%20On%20Imported%20methods!!!&body=Exciting%20offer")).should == { - scheme: "mailto", - to: "spam@mailinator.com", - headers: [["subject","Discounts%20On%20Imported%20methods!!!"], - ["body", "Exciting%20offer"]] - } - end - - # TODO - # Test registry - it "does its best to extract components from URI::Generic objects" do - # generic - URISpec.components(URI("scheme://userinfo@host/path?query#fragment")).should == { - scheme: "scheme", - userinfo: "userinfo", - host: "host", - port: nil, - path: "/path", - query: "query", - fragment: "fragment", - registry: nil, - opaque: nil - } - - # gopher - gopher = @object.parse('gopher://spinaltap.micro.umn.edu/00/Weather/California/Los%20Angeles') - gopher.should be_kind_of(URI::Generic) - - URISpec.components(gopher).should == { - scheme: "gopher", - userinfo: nil, - host: "spinaltap.micro.umn.edu", - port: nil, - path: "/00/Weather/California/Los%20Angeles", - query: nil, - fragment: nil, - registry: nil, - opaque: nil - } - - # news - news = @object.parse('news:comp.infosystems.www.servers.unix') - news.should be_kind_of(URI::Generic) - URISpec.components(news).should == { - scheme: "news", - userinfo: nil, - host: nil, - port: nil, - path: nil, - query: nil, - fragment: nil, - registry: nil, - opaque: "comp.infosystems.www.servers.unix" - } - - # telnet - telnet = @object.parse('telnet://melvyl.ucop.edu/') - telnet.should be_kind_of(URI::Generic) - URISpec.components(telnet).should == { - scheme: "telnet", - userinfo: nil, - host: "melvyl.ucop.edu", - port: nil, - path: "/", - query: nil, - fragment: nil, - registry: nil, - opaque: nil - } - - # files - file_l = @object.parse('file:///foo/bar.txt') - file_l.should be_kind_of(URI::Generic) - file = @object.parse('file:/foo/bar.txt') - file.should be_kind_of(URI::Generic) - end - - 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/uri/uri_spec.rb b/spec/ruby/library/uri/uri_spec.rb index 45a7502052..eab4e7176c 100644 --- a/spec/ruby/library/uri/uri_spec.rb +++ b/spec/ruby/library/uri/uri_spec.rb @@ -19,11 +19,11 @@ describe "the URI method" do it "returns the argument if it is a URI object" do result = URI.parse("http://ruby-lang.org") - URI(result).should equal(result) + URI(result).should.equal?(result) end #apparently this was a concern? imported from MRI tests it "does not add a URI method to Object instances" do - -> {Object.new.URI("http://ruby-lang.org/")}.should raise_error(NoMethodError) + -> {Object.new.URI("http://ruby-lang.org/")}.should.raise(NoMethodError) end end diff --git a/spec/ruby/library/weakref/__getobj___spec.rb b/spec/ruby/library/weakref/__getobj___spec.rb index 79b06f5c96..fa507384c2 100644 --- a/spec/ruby/library/weakref/__getobj___spec.rb +++ b/spec/ruby/library/weakref/__getobj___spec.rb @@ -5,13 +5,13 @@ describe "WeakRef#__getobj__" do it "returns the object if it is reachable" do obj = Object.new ref = WeakRef.new(obj) - ref.__getobj__.should equal(obj) + ref.__getobj__.should.equal?(obj) end it "raises WeakRef::RefError if the object is no longer reachable" do ref = WeakRefSpec.make_dead_weakref -> { ref.__getobj__ - }.should raise_error(WeakRef::RefError) + }.should.raise(WeakRef::RefError) end end diff --git a/spec/ruby/library/weakref/allocate_spec.rb b/spec/ruby/library/weakref/allocate_spec.rb index e734cfd23d..0438d093c4 100644 --- a/spec/ruby/library/weakref/allocate_spec.rb +++ b/spec/ruby/library/weakref/allocate_spec.rb @@ -3,6 +3,6 @@ require 'weakref' describe "WeakRef#allocate" do it "assigns nil as the reference" do - -> { WeakRef.allocate.__getobj__ }.should raise_error(WeakRef::RefError) + -> { WeakRef.allocate.__getobj__ }.should.raise(WeakRef::RefError) end end diff --git a/spec/ruby/library/weakref/send_spec.rb b/spec/ruby/library/weakref/send_spec.rb index 9591657e01..da8660066f 100644 --- a/spec/ruby/library/weakref/send_spec.rb +++ b/spec/ruby/library/weakref/send_spec.rb @@ -27,11 +27,11 @@ describe "WeakRef#__send__" do it "delegates to protected methods of the weakly-referenced object" do wr = WeakRef.new(WeakRefSpecs) - -> { wr.protected_method }.should raise_error(NameError) + -> { wr.protected_method }.should.raise(NameError) end it "does not delegate to private methods of the weakly-referenced object" do wr = WeakRef.new(WeakRefSpecs) - -> { wr.private_method }.should raise_error(NameError) + -> { wr.private_method }.should.raise(NameError) end end diff --git a/spec/ruby/library/weakref/weakref_alive_spec.rb b/spec/ruby/library/weakref/weakref_alive_spec.rb index 1ebf9c1ee3..1b12ffbbec 100644 --- a/spec/ruby/library/weakref/weakref_alive_spec.rb +++ b/spec/ruby/library/weakref/weakref_alive_spec.rb @@ -5,11 +5,11 @@ describe "WeakRef#weakref_alive?" do it "returns true if the object is reachable" do obj = Object.new ref = WeakRef.new(obj) - ref.weakref_alive?.should be_true + ref.weakref_alive?.should == true end it "returns a falsy value if the object is no longer reachable" do ref = WeakRefSpec.make_dead_weakref - [false, nil].should include(ref.weakref_alive?) + [false, nil].should.include?(ref.weakref_alive?) end end diff --git a/spec/ruby/library/win32ole/win32ole/_invoke_spec.rb b/spec/ruby/library/win32ole/win32ole/_invoke_spec.rb index 994c2e6d36..747121aeba 100644 --- a/spec/ruby/library/win32ole/win32ole/_invoke_spec.rb +++ b/spec/ruby/library/win32ole/win32ole/_invoke_spec.rb @@ -8,9 +8,9 @@ platform_is :windows do end it "raises ArgumentError if insufficient number of arguments are given" do - -> { @shell._invoke() }.should raise_error ArgumentError - -> { @shell._invoke(0) }.should raise_error ArgumentError - -> { @shell._invoke(0, []) }.should raise_error ArgumentError + -> { @shell._invoke() }.should.raise ArgumentError + -> { @shell._invoke(0) }.should.raise ArgumentError + -> { @shell._invoke(0, []) }.should.raise ArgumentError end it "dispatches the method bound to a specific ID" do diff --git a/spec/ruby/library/win32ole/win32ole/connect_spec.rb b/spec/ruby/library/win32ole/win32ole/connect_spec.rb index ac0976ddc1..3a1caf85d3 100644 --- a/spec/ruby/library/win32ole/win32ole/connect_spec.rb +++ b/spec/ruby/library/win32ole/win32ole/connect_spec.rb @@ -5,11 +5,11 @@ platform_is :windows do describe "WIN32OLE.connect" do it "creates WIN32OLE object given valid argument" do obj = WIN32OLE.connect("winmgmts:") - obj.should be_kind_of WIN32OLE + obj.should.is_a? WIN32OLE end it "raises TypeError when given invalid argument" do - -> { WIN32OLE.connect 1 }.should raise_error TypeError + -> { WIN32OLE.connect 1 }.should.raise TypeError end end diff --git a/spec/ruby/library/win32ole/win32ole/const_load_spec.rb b/spec/ruby/library/win32ole/win32ole/const_load_spec.rb index 2099c4aa66..b0ba023536 100644 --- a/spec/ruby/library/win32ole/win32ole/const_load_spec.rb +++ b/spec/ruby/library/win32ole/win32ole/const_load_spec.rb @@ -8,9 +8,9 @@ platform_is :windows do end it "loads constant SsfWINDOWS into WIN32OLE namespace" do - WIN32OLE.const_defined?(:SsfWINDOWS).should be_false + WIN32OLE.const_defined?(:SsfWINDOWS).should == false WIN32OLE.const_load @win32ole - WIN32OLE.const_defined?(:SsfWINDOWS).should be_true + WIN32OLE.const_defined?(:SsfWINDOWS).should == true end end @@ -23,9 +23,9 @@ platform_is :windows do it "loads constants into given namespace" do module WIN32OLE_RUBYSPEC; end - WIN32OLE_RUBYSPEC.const_defined?(:SsfWINDOWS).should be_false + WIN32OLE_RUBYSPEC.const_defined?(:SsfWINDOWS).should == false WIN32OLE.const_load @win32ole, WIN32OLE_RUBYSPEC - WIN32OLE_RUBYSPEC.const_defined?(:SsfWINDOWS).should be_true + WIN32OLE_RUBYSPEC.const_defined?(:SsfWINDOWS).should == true end end diff --git a/spec/ruby/library/win32ole/win32ole/locale_spec.rb b/spec/ruby/library/win32ole/win32ole/locale_spec.rb index 89e84d8038..390c41d1a2 100644 --- a/spec/ruby/library/win32ole/win32ole/locale_spec.rb +++ b/spec/ruby/library/win32ole/win32ole/locale_spec.rb @@ -20,7 +20,7 @@ platform_is :windows do WIN32OLE.locale.should == 1041 WIN32OLE.locale = WIN32OLE::LOCALE_SYSTEM_DEFAULT - -> { WIN32OLE.locale = 111 }.should raise_error WIN32OLE::RuntimeError + -> { WIN32OLE.locale = 111 }.should.raise 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 b2a0a5da18..4f54c724d9 100644 --- a/spec/ruby/library/win32ole/win32ole/new_spec.rb +++ b/spec/ruby/library/win32ole/win32ole/new_spec.rb @@ -5,20 +5,20 @@ platform_is :windows do describe "WIN32OLESpecs.new_ole" do it "creates a WIN32OLE object from OLE server name" do shell = WIN32OLESpecs.new_ole 'Shell.Application' - shell.should be_kind_of WIN32OLE + shell.should.is_a? WIN32OLE end it "creates a WIN32OLE object from valid CLSID" do shell = WIN32OLESpecs.new_ole("{13709620-C279-11CE-A49E-444553540000}") - shell.should be_kind_of WIN32OLE + shell.should.is_a? WIN32OLE end it "raises TypeError if argument cannot be converted to String" do - -> { WIN32OLESpecs.new_ole(42) }.should raise_error( TypeError ) + -> { WIN32OLESpecs.new_ole(42) }.should.raise( TypeError ) end it "raises WIN32OLE::RuntimeError if invalid string is given" do - -> { WIN32OLE.new('foo') }.should raise_error( WIN32OLE::RuntimeError ) + -> { WIN32OLE.new('foo') }.should.raise( 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 b846685518..33e3e23b1b 100644 --- a/spec/ruby/library/win32ole/win32ole/ole_func_methods_spec.rb +++ b/spec/ruby/library/win32ole/win32ole/ole_func_methods_spec.rb @@ -8,15 +8,15 @@ platform_is :windows do end it "raises ArgumentError if argument is given" do - -> { @dict.ole_func_methods(1) }.should raise_error ArgumentError + -> { @dict.ole_func_methods(1) }.should.raise ArgumentError end it "returns an array of WIN32OLE::Methods" do - @dict.ole_func_methods.all? { |m| m.kind_of? WIN32OLE::Method }.should be_true + @dict.ole_func_methods.all? { |m| m.kind_of? WIN32OLE::Method }.should == true end it "contains a 'AddRef' method for Scripting Dictionary" do - @dict.ole_func_methods.map { |m| m.name }.include?('AddRef').should be_true + @dict.ole_func_methods.map { |m| m.name }.include?('AddRef').should == true end end end 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 b6e7f960bb..168a225d58 100644 --- a/spec/ruby/library/win32ole/win32ole/ole_get_methods_spec.rb +++ b/spec/ruby/library/win32ole/win32ole/ole_get_methods_spec.rb @@ -9,7 +9,7 @@ platform_is :windows do end it "returns an array of WIN32OLE::Method objects" do - @win32ole.ole_get_methods.all? {|m| m.kind_of? WIN32OLE::Method}.should be_true + @win32ole.ole_get_methods.all? {|m| m.kind_of? WIN32OLE::Method}.should == 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 92c4363f78..5152deeaf4 100644 --- a/spec/ruby/library/win32ole/win32ole/ole_methods_spec.rb +++ b/spec/ruby/library/win32ole/win32ole/ole_methods_spec.rb @@ -8,15 +8,15 @@ platform_is :windows do end it "raises ArgumentError if argument is given" do - -> { @dict.ole_methods(1) }.should raise_error ArgumentError + -> { @dict.ole_methods(1) }.should.raise ArgumentError end it "returns an array of WIN32OLE::Methods" do - @dict.ole_methods.all? { |m| m.kind_of? WIN32OLE::Method }.should be_true + @dict.ole_methods.all? { |m| m.kind_of? WIN32OLE::Method }.should == true end it "contains a 'AddRef' method for Scripting Dictionary" do - @dict.ole_methods.map { |m| m.name }.include?('AddRef').should be_true + @dict.ole_methods.map { |m| m.name }.include?('AddRef').should == true end end end 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 f298f19dba..1478804b55 100644 --- a/spec/ruby/library/win32ole/win32ole/ole_obj_help_spec.rb +++ b/spec/ruby/library/win32ole/win32ole/ole_obj_help_spec.rb @@ -9,11 +9,11 @@ platform_is :windows do end it "raises ArgumentError if argument is given" do - -> { @dict.ole_obj_help(1) }.should raise_error ArgumentError + -> { @dict.ole_obj_help(1) }.should.raise ArgumentError end it "returns an instance of WIN32OLE::Type" do - @dict.ole_obj_help.kind_of?(WIN32OLE::Type).should be_true + @dict.ole_obj_help.kind_of?(WIN32OLE::Type).should == 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 2b46ae47de..b03a5d4b06 100644 --- a/spec/ruby/library/win32ole/win32ole/ole_put_methods_spec.rb +++ b/spec/ruby/library/win32ole/win32ole/ole_put_methods_spec.rb @@ -8,15 +8,15 @@ platform_is :windows do end it "raises ArgumentError if argument is given" do - -> { @dict.ole_put_methods(1) }.should raise_error ArgumentError + -> { @dict.ole_put_methods(1) }.should.raise ArgumentError end it "returns an array of WIN32OLE::Methods" do - @dict.ole_put_methods.all? { |m| m.kind_of? WIN32OLE::Method }.should be_true + @dict.ole_put_methods.all? { |m| m.kind_of? WIN32OLE::Method }.should == true end it "contains a 'Key' method for Scripting Dictionary" do - @dict.ole_put_methods.map { |m| m.name }.include?('Key').should be_true + @dict.ole_put_methods.map { |m| m.name }.include?('Key').should == true end end end diff --git a/spec/ruby/library/win32ole/win32ole/shared/ole_method.rb b/spec/ruby/library/win32ole/win32ole/shared/ole_method.rb index bae424a604..9e4b7e7c20 100644 --- a/spec/ruby/library/win32ole/win32ole/shared/ole_method.rb +++ b/spec/ruby/library/win32ole/win32ole/shared/ole_method.rb @@ -7,12 +7,12 @@ platform_is :windows do end it "raises ArgumentError if no argument is given" do - -> { @dict.send(@method) }.should raise_error ArgumentError + -> { @dict.send(@method) }.should.raise ArgumentError end 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 == true result.name.should == 'Add' end end diff --git a/spec/ruby/library/win32ole/win32ole/shared/setproperty.rb b/spec/ruby/library/win32ole/win32ole/shared/setproperty.rb index b9267aef71..de3ad7b286 100644 --- a/spec/ruby/library/win32ole/win32ole/shared/setproperty.rb +++ b/spec/ruby/library/win32ole/win32ole/shared/setproperty.rb @@ -7,7 +7,7 @@ platform_is :windows do end it "raises ArgumentError if no argument is given" do - -> { @dict.send(@method) }.should raise_error ArgumentError + -> { @dict.send(@method) }.should.raise ArgumentError end it "sets key to newkey and returns nil" do diff --git a/spec/ruby/library/win32ole/win32ole_event/new_spec.rb b/spec/ruby/library/win32ole/win32ole_event/new_spec.rb index 4efd4c3e0f..d09c38b78d 100644 --- a/spec/ruby/library/win32ole/win32ole_event/new_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_event/new_spec.rb @@ -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 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 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 RuntimeError end it "creates WIN32OLE::Event object" do ev = WIN32OLE::Event.new(@xml_dom) - ev.should be_kind_of WIN32OLE::Event + ev.should.is_a? WIN32OLE::Event end end end diff --git a/spec/ruby/library/win32ole/win32ole_method/dispid_spec.rb b/spec/ruby/library/win32ole/win32ole_method/dispid_spec.rb index e5f55f2d38..43084eb943 100644 --- a/spec/ruby/library/win32ole/win32ole_method/dispid_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_method/dispid_spec.rb @@ -9,7 +9,7 @@ platform_is :windows do end it "raises ArgumentError if argument is given" do - -> { @m.dispid(0) }.should raise_error ArgumentError + -> { @m.dispid(0) }.should.raise ArgumentError end it "returns expected dispatch ID for Shell's 'namespace' method" 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 bea47348ee..1d00fb9696 100644 --- a/spec/ruby/library/win32ole/win32ole_method/event_interface_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_method/event_interface_spec.rb @@ -12,7 +12,7 @@ platform_is :windows do end it "raises ArgumentError if argument is given" do - -> { @on_dbl_click_method.event_interface(1) }.should raise_error ArgumentError + -> { @on_dbl_click_method.event_interface(1) }.should.raise ArgumentError end it "returns expected string for System Monitor Control's 'OnDblClick' method" do @@ -20,7 +20,7 @@ platform_is :windows do end it "returns nil if method has no event interface" do - @namespace_method.event_interface.should be_nil + @namespace_method.event_interface.should == nil end end diff --git a/spec/ruby/library/win32ole/win32ole_method/event_spec.rb b/spec/ruby/library/win32ole/win32ole_method/event_spec.rb index 5a94cf5ce6..fd611519cb 100644 --- a/spec/ruby/library/win32ole/win32ole_method/event_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_method/event_spec.rb @@ -10,11 +10,11 @@ platform_is :windows do end it "raises ArgumentError if argument is given" do - -> { @on_dbl_click_method.event?(1) }.should raise_error ArgumentError + -> { @on_dbl_click_method.event?(1) }.should.raise ArgumentError end it "returns true for System Monitor Control's 'OnDblClick' method" do - @on_dbl_click_method.event?.should be_true + @on_dbl_click_method.event?.should == true end end diff --git a/spec/ruby/library/win32ole/win32ole_method/helpcontext_spec.rb b/spec/ruby/library/win32ole/win32ole_method/helpcontext_spec.rb index 83f34b9c10..88164bcd1f 100644 --- a/spec/ruby/library/win32ole/win32ole_method/helpcontext_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_method/helpcontext_spec.rb @@ -11,7 +11,7 @@ platform_is :windows do end it "raises ArgumentError if argument is given" do - -> { @get_file_version.helpcontext(1) }.should raise_error ArgumentError + -> { @get_file_version.helpcontext(1) }.should.raise ArgumentError end it "returns expected value for FileSystemObject's 'GetFileVersion' method" do diff --git a/spec/ruby/library/win32ole/win32ole_method/helpfile_spec.rb b/spec/ruby/library/win32ole/win32ole_method/helpfile_spec.rb index 9cf9d63d3b..314f58c062 100644 --- a/spec/ruby/library/win32ole/win32ole_method/helpfile_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_method/helpfile_spec.rb @@ -9,7 +9,7 @@ platform_is :windows do end it "raises ArgumentError if argument is given" do - -> { @m_file_name.helpfile(1) }.should raise_error ArgumentError + -> { @m_file_name.helpfile(1) }.should.raise ArgumentError end it "returns expected value for Scripting Runtime's 'File' method" do diff --git a/spec/ruby/library/win32ole/win32ole_method/helpstring_spec.rb b/spec/ruby/library/win32ole/win32ole_method/helpstring_spec.rb index 5ae4a5e090..2a93acdb37 100644 --- a/spec/ruby/library/win32ole/win32ole_method/helpstring_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_method/helpstring_spec.rb @@ -9,7 +9,7 @@ platform_is :windows do end it "raises ArgumentError if argument is given" do - -> { @m_file_name.helpstring(1) }.should raise_error ArgumentError + -> { @m_file_name.helpstring(1) }.should.raise ArgumentError end it "returns expected value for Scripting Runtime's 'File' method" do diff --git a/spec/ruby/library/win32ole/win32ole_method/invkind_spec.rb b/spec/ruby/library/win32ole/win32ole_method/invkind_spec.rb index 06acbb58a5..16e5412a36 100644 --- a/spec/ruby/library/win32ole/win32ole_method/invkind_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_method/invkind_spec.rb @@ -9,7 +9,7 @@ platform_is :windows do end it "raises ArgumentError if argument is given" do - -> { @m_file_name.invkind(1) }.should raise_error ArgumentError + -> { @m_file_name.invkind(1) }.should.raise ArgumentError end it "returns expected value for Scripting Runtime's 'name' method" 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 0e97ec3305..312860a9c5 100644 --- a/spec/ruby/library/win32ole/win32ole_method/invoke_kind_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_method/invoke_kind_spec.rb @@ -9,7 +9,7 @@ platform_is :windows do end it "raises ArgumentError if argument is given" do - -> { @m_file_name.invoke_kind(1) }.should raise_error ArgumentError + -> { @m_file_name.invoke_kind(1) }.should.raise ArgumentError end it "returns expected value for Scripting Runtime's 'name' method" do diff --git a/spec/ruby/library/win32ole/win32ole_method/new_spec.rb b/spec/ruby/library/win32ole/win32ole_method/new_spec.rb index 46186ae566..d805d80128 100644 --- a/spec/ruby/library/win32ole/win32ole_method/new_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_method/new_spec.rb @@ -8,25 +8,25 @@ platform_is :windows do 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 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 ArgumentError + -> { WIN32OLE::Method.new(@ole_type) }.should.raise 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 + WIN32OLE::Method.new(@ole_type, "Open").should.is_a? WIN32OLE::Method + WIN32OLE::Method.new(@ole_type, "open").should.is_a? WIN32OLE::Method end it "raises WIN32OLE::RuntimeError if the method does not exist" do - -> { WIN32OLE::Method.new(@ole_type, "NonexistentMethod") }.should raise_error WIN32OLE::RuntimeError + -> { WIN32OLE::Method.new(@ole_type, "NonexistentMethod") }.should.raise 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 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 3c80cb3c2a..7c7e49ff3a 100644 --- a/spec/ruby/library/win32ole/win32ole_method/offset_vtbl_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_method/offset_vtbl_spec.rb @@ -9,7 +9,7 @@ platform_is :windows do end it "raises ArgumentError if argument is given" do - -> { @m_file_name.offset_vtbl(1) }.should raise_error ArgumentError + -> { @m_file_name.offset_vtbl(1) }.should.raise ArgumentError end it "returns expected value for Scripting Runtime's 'name' method" do diff --git a/spec/ruby/library/win32ole/win32ole_method/params_spec.rb b/spec/ruby/library/win32ole/win32ole_method/params_spec.rb index 0b1b4595a3..40a543fa55 100644 --- a/spec/ruby/library/win32ole/win32ole_method/params_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_method/params_spec.rb @@ -11,16 +11,16 @@ platform_is :windows do end it "raises ArgumentError if argument is given" do - -> { @m_file_name.params(1) }.should raise_error ArgumentError + -> { @m_file_name.params(1) }.should.raise ArgumentError end it "returns empty array for Scripting Runtime's 'name' method" do - @m_file_name.params.should be_kind_of Array - @m_file_name.params.should be_empty + @m_file_name.params.should.is_a? Array + @m_file_name.params.should.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 + @m_browse_for_folder.params.all? { |p| p.kind_of? WIN32OLE::Param }.should == 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 c3725bfef2..6d46c705c6 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 @@ -9,11 +9,11 @@ platform_is :windows do end it "raises ArgumentError if argument is given" do - -> { @m_browse_for_folder.return_type_detail(1) }.should raise_error ArgumentError + -> { @m_browse_for_folder.return_type_detail(1) }.should.raise ArgumentError end it "returns expected value for Shell Control's 'BrowseForFolder' method" do - @m_browse_for_folder.return_type_detail.should be_kind_of Array + @m_browse_for_folder.return_type_detail.should.is_a? Array @m_browse_for_folder.return_type_detail.should == ['PTR', 'USERDEFINED', 'Folder'] end 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 9e5a1eb1df..5afaf202f2 100644 --- a/spec/ruby/library/win32ole/win32ole_method/return_type_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_method/return_type_spec.rb @@ -9,7 +9,7 @@ platform_is :windows do end it "raises ArgumentError if argument is given" do - -> { @m_file_name.return_type(1) }.should raise_error ArgumentError + -> { @m_file_name.return_type(1) }.should.raise ArgumentError end it "returns expected value for Scripting Runtime's 'name' method" 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 34fd135b8c..882b5eaf43 100644 --- a/spec/ruby/library/win32ole/win32ole_method/return_vtype_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_method/return_vtype_spec.rb @@ -9,7 +9,7 @@ platform_is :windows do end it "raises ArgumentError if argument is given" do - -> { @m_browse_for_folder.return_vtype(1) }.should raise_error ArgumentError + -> { @m_browse_for_folder.return_vtype(1) }.should.raise ArgumentError end it "returns expected value for Shell Control's 'BrowseForFolder' method" do diff --git a/spec/ruby/library/win32ole/win32ole_method/shared/name.rb b/spec/ruby/library/win32ole/win32ole_method/shared/name.rb index 7e2197ca5a..ef63999836 100644 --- a/spec/ruby/library/win32ole/win32ole_method/shared/name.rb +++ b/spec/ruby/library/win32ole/win32ole_method/shared/name.rb @@ -8,7 +8,7 @@ platform_is :windows do end it "raises ArgumentError if argument is given" do - -> { @m_file_name.send(@method, 1) }.should raise_error ArgumentError + -> { @m_file_name.send(@method, 1) }.should.raise ArgumentError end it "returns expected value for Scripting Runtime's 'name' method" 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 38cb21ccef..e03a97c6c0 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 @@ -9,7 +9,7 @@ platform_is :windows do end it "raises ArgumentError if argument is given" do - -> { @m_browse_for_folder.size_opt_params(1) }.should raise_error ArgumentError + -> { @m_browse_for_folder.size_opt_params(1) }.should.raise ArgumentError end it "returns expected value for Shell Control's 'BrowseForFolder' method" 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 5d0a35a0ef..f64f77af46 100644 --- a/spec/ruby/library/win32ole/win32ole_method/size_params_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_method/size_params_spec.rb @@ -9,7 +9,7 @@ platform_is :windows do end it "raises ArgumentError if argument is given" do - -> { @m_browse_for_folder.size_params(1) }.should raise_error ArgumentError + -> { @m_browse_for_folder.size_params(1) }.should.raise ArgumentError end it "returns expected value for Shell Control's 'BrowseForFolder' method" do diff --git a/spec/ruby/library/win32ole/win32ole_method/visible_spec.rb b/spec/ruby/library/win32ole/win32ole_method/visible_spec.rb index 2f02c15c8b..a04ac6570b 100644 --- a/spec/ruby/library/win32ole/win32ole_method/visible_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_method/visible_spec.rb @@ -9,11 +9,11 @@ platform_is :windows do end it "raises ArgumentError if argument is given" do - -> { @m_browse_for_folder.visible?(1) }.should raise_error ArgumentError + -> { @m_browse_for_folder.visible?(1) }.should.raise ArgumentError end it "returns true for Shell Control's 'BrowseForFolder' method" do - @m_browse_for_folder.visible?.should be_true + @m_browse_for_folder.visible?.should == true end end diff --git a/spec/ruby/library/win32ole/win32ole_param/default_spec.rb b/spec/ruby/library/win32ole/win32ole_param/default_spec.rb index a37b03866d..dded6833d4 100644 --- a/spec/ruby/library/win32ole/win32ole_param/default_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_param/default_spec.rb @@ -14,12 +14,12 @@ platform_is :windows do end it "raises ArgumentError if argument is given" do - -> { @params[0].default(1) }.should raise_error ArgumentError + -> { @params[0].default(1) }.should.raise ArgumentError end it "returns nil for each of WIN32OLE::Param for Shell's 'BrowseForFolder' method" do @params.each do |p| - p.default.should be_nil + p.default.should == nil end end diff --git a/spec/ruby/library/win32ole/win32ole_param/input_spec.rb b/spec/ruby/library/win32ole/win32ole_param/input_spec.rb index d7e27d7739..46dc305d2b 100644 --- a/spec/ruby/library/win32ole/win32ole_param/input_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_param/input_spec.rb @@ -10,7 +10,7 @@ platform_is :windows do end it "raises ArgumentError if argument is given" do - -> { @param_overwritefiles.input?(1) }.should raise_error ArgumentError + -> { @param_overwritefiles.input?(1) }.should.raise ArgumentError end it "returns true for 3rd parameter of FileSystemObject's 'CopyFile' method" do 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 e3379dbf3e..bd25ec325a 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 @@ -10,7 +10,7 @@ platform_is :windows do end it "raises ArgumentError if argument is given" do - -> { @param_overwritefiles.ole_type_detail(1) }.should raise_error ArgumentError + -> { @param_overwritefiles.ole_type_detail(1) }.should.raise ArgumentError end it "returns ['BOOL'] for 3rd parameter of FileSystemObject's 'CopyFile' method" do 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 a7b6666807..3f0c279316 100644 --- a/spec/ruby/library/win32ole/win32ole_param/ole_type_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_param/ole_type_spec.rb @@ -10,7 +10,7 @@ platform_is :windows do end it "raises ArgumentError if argument is given" do - -> { @param_overwritefiles.ole_type(1) }.should raise_error ArgumentError + -> { @param_overwritefiles.ole_type(1) }.should.raise ArgumentError end it "returns 'BOOL' for 3rd parameter of FileSystemObject's 'CopyFile' method" do diff --git a/spec/ruby/library/win32ole/win32ole_param/optional_spec.rb b/spec/ruby/library/win32ole/win32ole_param/optional_spec.rb index 50e95fc77f..ca676e0950 100644 --- a/spec/ruby/library/win32ole/win32ole_param/optional_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_param/optional_spec.rb @@ -10,11 +10,11 @@ platform_is :windows do end it "raises ArgumentError if argument is given" do - -> { @param_overwritefiles.optional?(1) }.should raise_error ArgumentError + -> { @param_overwritefiles.optional?(1) }.should.raise ArgumentError end it "returns true for 3rd parameter of FileSystemObject's 'CopyFile' method" do - @param_overwritefiles.optional?.should be_true + @param_overwritefiles.optional?.should == true end end diff --git a/spec/ruby/library/win32ole/win32ole_param/retval_spec.rb b/spec/ruby/library/win32ole/win32ole_param/retval_spec.rb index fa4a09ea0c..f25b1e7e14 100644 --- a/spec/ruby/library/win32ole/win32ole_param/retval_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_param/retval_spec.rb @@ -10,11 +10,11 @@ platform_is :windows do end it "raises ArgumentError if argument is given" do - -> { @param_overwritefiles.retval?(1) }.should raise_error ArgumentError + -> { @param_overwritefiles.retval?(1) }.should.raise ArgumentError end it "returns false for 3rd parameter of FileSystemObject's 'CopyFile' method" do - @param_overwritefiles.retval?.should be_false + @param_overwritefiles.retval?.should == false end end diff --git a/spec/ruby/library/win32ole/win32ole_param/shared/name.rb b/spec/ruby/library/win32ole/win32ole_param/shared/name.rb index 56ff24ddc8..1f6cbea7a0 100644 --- a/spec/ruby/library/win32ole/win32ole_param/shared/name.rb +++ b/spec/ruby/library/win32ole/win32ole_param/shared/name.rb @@ -9,7 +9,7 @@ platform_is :windows do end it "raises ArgumentError if argument is given" do - -> { @param_overwritefiles.send(@method, 1) }.should raise_error ArgumentError + -> { @param_overwritefiles.send(@method, 1) }.should.raise ArgumentError end it "returns expected value for Scripting Runtime's 'name' method" do diff --git a/spec/ruby/library/win32ole/win32ole_type/helpcontext_spec.rb b/spec/ruby/library/win32ole/win32ole_type/helpcontext_spec.rb index 35911fec52..7b605a038b 100644 --- a/spec/ruby/library/win32ole/win32ole_type/helpcontext_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_type/helpcontext_spec.rb @@ -12,7 +12,7 @@ platform_is :windows do end it "returns an Integer" do - @ole_type.helpcontext.should be_kind_of Integer + @ole_type.helpcontext.should.is_a? Integer end end diff --git a/spec/ruby/library/win32ole/win32ole_type/helpfile_spec.rb b/spec/ruby/library/win32ole/win32ole_type/helpfile_spec.rb index 7bd61a1c40..43a979882a 100644 --- a/spec/ruby/library/win32ole/win32ole_type/helpfile_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_type/helpfile_spec.rb @@ -12,7 +12,7 @@ platform_is :windows do end it "returns an empty string" do - @ole_type.helpfile.should be_empty + @ole_type.helpfile.should.empty? end end 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 598e5bcef8..66fdbc9ab0 100644 --- a/spec/ruby/library/win32ole/win32ole_type/major_version_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_type/major_version_spec.rb @@ -12,7 +12,7 @@ platform_is :windows do end it "returns an Integer" do - @ole_type.major_version.should be_kind_of Integer + @ole_type.major_version.should.is_a? Integer end end 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 59cfb94012..afb5086565 100644 --- a/spec/ruby/library/win32ole/win32ole_type/minor_version_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_type/minor_version_spec.rb @@ -12,7 +12,7 @@ platform_is :windows do end it "returns an Integer" do - @ole_type.minor_version.should be_kind_of Integer + @ole_type.minor_version.should.is_a? Integer end end diff --git a/spec/ruby/library/win32ole/win32ole_type/new_spec.rb b/spec/ruby/library/win32ole/win32ole_type/new_spec.rb index 185a235940..9d92177a4b 100644 --- a/spec/ruby/library/win32ole/win32ole_type/new_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_type/new_spec.rb @@ -4,37 +4,37 @@ platform_is :windows 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 ArgumentError end it "raises ArgumentError with invalid string" do - -> { WIN32OLE::Type.new("foo") }.should raise_error ArgumentError + -> { WIN32OLE::Type.new("foo") }.should.raise 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 TypeError -> { WIN32OLE::Type.new('Microsoft Shell Controls And Automation',2) - }.should raise_error TypeError + }.should.raise TypeError end it "raise WIN32OLE::RuntimeError if OLE object specified is not found" do -> { WIN32OLE::Type.new('Microsoft Shell Controls And Automation','foo') - }.should raise_error WIN32OLE::RuntimeError + }.should.raise WIN32OLE::RuntimeError -> { WIN32OLE::Type.new('Microsoft Shell Controls And Automation','Application') - }.should raise_error WIN32OLE::RuntimeError + }.should.raise 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 + ole_type.should.is_a? 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 + ole_type2.should.is_a? 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 ed14e37a95..7db08dc900 100644 --- a/spec/ruby/library/win32ole/win32ole_type/ole_classes_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_type/ole_classes_spec.rb @@ -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 == 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 0c031abaa6..bdf668e53b 100644 --- a/spec/ruby/library/win32ole/win32ole_type/ole_methods_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_type/ole_methods_spec.rb @@ -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 == true end end diff --git a/spec/ruby/library/win32ole/win32ole_type/progids_spec.rb b/spec/ruby/library/win32ole/win32ole_type/progids_spec.rb index b1b57960cd..cbb9247da1 100644 --- a/spec/ruby/library/win32ole/win32ole_type/progids_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_type/progids_spec.rb @@ -4,11 +4,11 @@ platform_is :windows 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 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 == 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 efae7aeec1..707149a5bb 100644 --- a/spec/ruby/library/win32ole/win32ole_type/shared/name.rb +++ b/spec/ruby/library/win32ole/win32ole_type/shared/name.rb @@ -7,7 +7,7 @@ platform_is :windows do end it "raises ArgumentError if argument is given" do - -> { @ole_type.send(@method, 1) }.should raise_error ArgumentError + -> { @ole_type.send(@method, 1) }.should.raise ArgumentError end it "returns a String" 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 3c7651cc1f..9f0893b750 100644 --- a/spec/ruby/library/win32ole/win32ole_type/src_type_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_type/src_type_spec.rb @@ -12,7 +12,7 @@ platform_is :windows do end it "returns nil" do - @ole_type.src_type.should be_nil + @ole_type.src_type.should == nil end end diff --git a/spec/ruby/library/win32ole/win32ole_type/typekind_spec.rb b/spec/ruby/library/win32ole/win32ole_type/typekind_spec.rb index 8b62f3e2eb..1051627025 100644 --- a/spec/ruby/library/win32ole/win32ole_type/typekind_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_type/typekind_spec.rb @@ -12,7 +12,7 @@ platform_is :windows do end it "returns an Integer" do - @ole_type.typekind.should be_kind_of Integer + @ole_type.typekind.should.is_a? Integer end end diff --git a/spec/ruby/library/win32ole/win32ole_type/typelibs_spec.rb b/spec/ruby/library/win32ole/win32ole_type/typelibs_spec.rb index 71d7cf00f7..36400d75f2 100644 --- a/spec/ruby/library/win32ole/win32ole_type/typelibs_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_type/typelibs_spec.rb @@ -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 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 == true end end diff --git a/spec/ruby/library/win32ole/win32ole_type/visible_spec.rb b/spec/ruby/library/win32ole/win32ole_type/visible_spec.rb index 05c54c8838..bca9159d53 100644 --- a/spec/ruby/library/win32ole/win32ole_type/visible_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_type/visible_spec.rb @@ -12,7 +12,7 @@ platform_is :windows do end it "returns true" do - @ole_type.visible?.should be_true + @ole_type.visible?.should == true end end 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 89576ceedc..a9232d2b28 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 @@ -11,8 +11,8 @@ platform_is :windows do end it "returns a nonempty Array" do - @var.ole_type_detail.should be_kind_of Array - @var.ole_type_detail.should_not be_empty + @var.ole_type_detail.should.is_a? Array + @var.ole_type_detail.should_not.empty? end 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 441011f1e7..f28cbfd37a 100644 --- a/spec/ruby/library/win32ole/win32ole_variable/ole_type_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_variable/ole_type_spec.rb @@ -11,7 +11,7 @@ platform_is :windows do end it "returns a String" do - @var.ole_type.should be_kind_of String + @var.ole_type.should.is_a? String end end diff --git a/spec/ruby/library/win32ole/win32ole_variable/shared/name.rb b/spec/ruby/library/win32ole/win32ole_variable/shared/name.rb index d02942ce0a..d079066616 100644 --- a/spec/ruby/library/win32ole/win32ole_variable/shared/name.rb +++ b/spec/ruby/library/win32ole/win32ole_variable/shared/name.rb @@ -10,7 +10,7 @@ platform_is :windows do end it "returns a String" do - @var.send(@method).should be_kind_of String + @var.send(@method).should.is_a? String end end diff --git a/spec/ruby/library/win32ole/win32ole_variable/value_spec.rb b/spec/ruby/library/win32ole/win32ole_variable/value_spec.rb index d26273ebed..33066e40ef 100644 --- a/spec/ruby/library/win32ole/win32ole_variable/value_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_variable/value_spec.rb @@ -12,7 +12,7 @@ platform_is :windows do it "returns an Integer" do # according to doc, this could return nil - @var.value.should be_kind_of Integer + @var.value.should.is_a? Integer end 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 17bc47160a..2cf1d7f1f2 100644 --- a/spec/ruby/library/win32ole/win32ole_variable/variable_kind_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_variable/variable_kind_spec.rb @@ -11,7 +11,7 @@ platform_is :windows do end it "returns a String" do - @var.variable_kind.should be_kind_of String + @var.variable_kind.should.is_a? String @var.variable_kind.should == 'CONSTANT' end diff --git a/spec/ruby/library/win32ole/win32ole_variable/varkind_spec.rb b/spec/ruby/library/win32ole/win32ole_variable/varkind_spec.rb index c5f8164509..04ccb8d46f 100644 --- a/spec/ruby/library/win32ole/win32ole_variable/varkind_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_variable/varkind_spec.rb @@ -12,7 +12,7 @@ platform_is :windows do end it "returns an Integer" do - @var.varkind.should be_kind_of Integer + @var.varkind.should.is_a? Integer end end diff --git a/spec/ruby/library/win32ole/win32ole_variable/visible_spec.rb b/spec/ruby/library/win32ole/win32ole_variable/visible_spec.rb index ba53a81de0..939468122c 100644 --- a/spec/ruby/library/win32ole/win32ole_variable/visible_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_variable/visible_spec.rb @@ -11,7 +11,7 @@ platform_is :windows do end it "returns a String" do - @var.visible?.should be_true + @var.visible?.should == true end end diff --git a/spec/ruby/library/yaml/load_stream_spec.rb b/spec/ruby/library/yaml/load_stream_spec.rb index 31bc862f5e..5f5d4c7337 100644 --- a/spec/ruby/library/yaml/load_stream_spec.rb +++ b/spec/ruby/library/yaml/load_stream_spec.rb @@ -1,9 +1,23 @@ require_relative '../../spec_helper' require_relative 'fixtures/strings' -require_relative 'shared/each_document' - require 'yaml' describe "YAML.load_stream" do - it_behaves_like :yaml_each_document, :load_stream + it "calls the block on each successive document" do + documents = [] + YAML.load_stream(YAMLSpecs::MULTIDOCUMENT) do |doc| + documents << doc + end + documents.should == [["Mark McGwire", "Sammy Sosa", "Ken Griffey"], + ["Chicago Cubs", "St Louis Cardinals"]] + end + + it "works on files" do + test_parse_file = fixture __FILE__, "test_yaml.yml" + File.open(test_parse_file, "r") do |file| + YAML.load_stream(file) do |doc| + doc.should == {"project"=>{"name"=>"RubySpec"}} + end + end + end end diff --git a/spec/ruby/library/yaml/parse_file_spec.rb b/spec/ruby/library/yaml/parse_file_spec.rb index 7bffcdc62f..a29377f163 100644 --- a/spec/ruby/library/yaml/parse_file_spec.rb +++ b/spec/ruby/library/yaml/parse_file_spec.rb @@ -5,6 +5,6 @@ require 'yaml' describe "YAML.parse_file" do it "returns a YAML::Syck::Map object after parsing a YAML file" do test_parse_file = fixture __FILE__, "test_yaml.yml" - YAML.parse_file(test_parse_file).should be_kind_of(Psych::Nodes::Document) + YAML.parse_file(test_parse_file).should.is_a?(Psych::Nodes::Document) end end diff --git a/spec/ruby/library/yaml/parse_spec.rb b/spec/ruby/library/yaml/parse_spec.rb index 37e2b7fa0a..832cd99d03 100644 --- a/spec/ruby/library/yaml/parse_spec.rb +++ b/spec/ruby/library/yaml/parse_spec.rb @@ -4,7 +4,7 @@ require 'yaml' describe "YAML.parse with an empty string" do it "returns false" do - YAML.parse('').should be_false + YAML.parse('').should == false end end diff --git a/spec/ruby/library/yaml/shared/each_document.rb b/spec/ruby/library/yaml/shared/each_document.rb deleted file mode 100644 index 6f00aee297..0000000000 --- a/spec/ruby/library/yaml/shared/each_document.rb +++ /dev/null @@ -1,19 +0,0 @@ -describe :yaml_each_document, shared: true do - it "calls the block on each successive document" do - documents = [] - YAML.send(@method, YAMLSpecs::MULTIDOCUMENT) do |doc| - documents << doc - end - documents.should == [["Mark McGwire", "Sammy Sosa", "Ken Griffey"], - ["Chicago Cubs", "St Louis Cardinals"]] - end - - it "works on files" do - 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 - end - end -end diff --git a/spec/ruby/library/yaml/shared/load.rb b/spec/ruby/library/yaml/shared/load.rb index b8bb605b0a..7e5669f2d0 100644 --- a/spec/ruby/library/yaml/shared/load.rb +++ b/spec/ruby/library/yaml/shared/load.rb @@ -60,7 +60,7 @@ describe :yaml_load_safe, shared: true do else error = ArgumentError end - -> { YAML.send(@method, "key1: value\ninvalid_key") }.should raise_error(error) + -> { YAML.send(@method, "key1: value\ninvalid_key") }.should.raise(error) end it "accepts symbols" do @@ -117,7 +117,7 @@ describe :yaml_load_unsafe, shared: true do ].should be_computed_by(:usec) end - it "rounds values smaller than 1 usec to 0 " do + it "rounds values smaller than 1 usec to 0" do YAML.send(@method, "2011-03-22t23:32:11.000000342222+01:00").usec.should == 0 end end @@ -137,6 +137,6 @@ describe :yaml_load_unsafe, shared: true do loaded = YAML.send(@method, "--- !ruby/object:File {}\n") -> { loaded.read(1) - }.should raise_error(IOError) + }.should.raise(IOError) end end diff --git a/spec/ruby/library/yaml/to_yaml_spec.rb b/spec/ruby/library/yaml/to_yaml_spec.rb index 08c5451416..328ab25552 100644 --- a/spec/ruby/library/yaml/to_yaml_spec.rb +++ b/spec/ruby/library/yaml/to_yaml_spec.rb @@ -32,25 +32,25 @@ describe "Object#to_yaml" do it "returns the YAML representation of a FalseClass" do false_klass = false - false_klass.should be_kind_of(FalseClass) + false_klass.should.is_a?(FalseClass) false_klass.to_yaml.should match_yaml("--- false\n") end it "returns the YAML representation of a Float object" do float = 1.2 - float.should be_kind_of(Float) + float.should.is_a?(Float) float.to_yaml.should match_yaml("--- 1.2\n") end it "returns the YAML representation of an Integer object" do int = 20 - int.should be_kind_of(Integer) + int.should.is_a?(Integer) int.to_yaml.should match_yaml("--- 20\n") end it "returns the YAML representation of a NilClass object" do nil_klass = nil - nil_klass.should be_kind_of(NilClass) + nil_klass.should.is_a?(NilClass) nil_klass.to_yaml.should match_yaml("--- \n") end @@ -84,7 +84,7 @@ describe "Object#to_yaml" do it "returns the YAML representation of a TrueClass" do true_klass = true - true_klass.should be_kind_of(TrueClass) + true_klass.should.is_a?(TrueClass) true_klass.to_yaml.should match_yaml("--- true\n") end @@ -94,10 +94,10 @@ describe "Object#to_yaml" do it "returns the YAML representation for Range objects" do yaml = Range.new(1,3).to_yaml - yaml.include?("!ruby/range").should be_true - yaml.include?("begin: 1").should be_true - yaml.include?("end: 3").should be_true - yaml.include?("excl: false").should be_true + yaml.include?("!ruby/range").should == true + yaml.include?("begin: 1").should == true + yaml.include?("end: 3").should == true + yaml.include?("excl: false").should == true end it "returns the YAML representation of numeric constants" do diff --git a/spec/ruby/library/zlib/adler32_spec.rb b/spec/ruby/library/zlib/adler32_spec.rb index 226aa18522..887c22d059 100644 --- a/spec/ruby/library/zlib/adler32_spec.rb +++ b/spec/ruby/library/zlib/adler32_spec.rb @@ -19,7 +19,7 @@ describe "Zlib.adler32" do Zlib.adler32(test_string, 1).should == 66391324 Zlib.adler32(test_string, 2**8).should == 701435419 Zlib.adler32(test_string, 2**16).should == 63966491 - -> { Zlib.adler32(test_string, 2**128) }.should raise_error(RangeError) + -> { Zlib.adler32(test_string, 2**128) }.should.raise(RangeError) end it "calculates the Adler checksum for string and initial Adler value for Integers" do diff --git a/spec/ruby/library/zlib/crc32_spec.rb b/spec/ruby/library/zlib/crc32_spec.rb index d5f5c199cc..b94b5c627c 100644 --- a/spec/ruby/library/zlib/crc32_spec.rb +++ b/spec/ruby/library/zlib/crc32_spec.rb @@ -26,7 +26,7 @@ describe "Zlib.crc32" do Zlib.crc32(test_string, 2**16).should == 1932511220 Zlib.crc32("p", ~305419896).should == 4046865307 Zlib.crc32("p", -305419897).should == 4046865307 - -> { Zlib.crc32(test_string, 2**128) }.should raise_error(RangeError) + -> { Zlib.crc32(test_string, 2**128) }.should.raise(RangeError) end it "calculates the CRC checksum for string and initial CRC value for Integers" do diff --git a/spec/ruby/library/zlib/gzipfile/close_spec.rb b/spec/ruby/library/zlib/gzipfile/close_spec.rb index 964b5ffb4d..07bafac961 100644 --- a/spec/ruby/library/zlib/gzipfile/close_spec.rb +++ b/spec/ruby/library/zlib/gzipfile/close_spec.rb @@ -10,10 +10,8 @@ describe "Zlib::GzipFile#close" do gzio.should.closed? - -> { gzio.orig_name }.should \ - raise_error(Zlib::GzipFile::Error, 'closed gzip stream') - -> { gzio.comment }.should \ - raise_error(Zlib::GzipFile::Error, 'closed gzip stream') + -> { gzio.orig_name }.should.raise(Zlib::GzipFile::Error, 'closed gzip stream') + -> { gzio.comment }.should.raise(Zlib::GzipFile::Error, 'closed gzip stream') end io.string[10..-1].should == ([3] + Array.new(9,0)).pack('C*') diff --git a/spec/ruby/library/zlib/gzipfile/comment_spec.rb b/spec/ruby/library/zlib/gzipfile/comment_spec.rb index 70d97ecaf6..845224df98 100644 --- a/spec/ruby/library/zlib/gzipfile/comment_spec.rb +++ b/spec/ruby/library/zlib/gzipfile/comment_spec.rb @@ -19,8 +19,7 @@ describe "Zlib::GzipFile#comment" do Zlib::GzipWriter.wrap @io do |gzio| gzio.close - -> { gzio.comment }.should \ - raise_error(Zlib::GzipFile::Error, 'closed gzip stream') + -> { gzio.comment }.should.raise(Zlib::GzipFile::Error, 'closed gzip stream') end end end diff --git a/spec/ruby/library/zlib/gzipfile/orig_name_spec.rb b/spec/ruby/library/zlib/gzipfile/orig_name_spec.rb index ebfd3692af..1da375390b 100644 --- a/spec/ruby/library/zlib/gzipfile/orig_name_spec.rb +++ b/spec/ruby/library/zlib/gzipfile/orig_name_spec.rb @@ -19,8 +19,7 @@ describe "Zlib::GzipFile#orig_name" do Zlib::GzipWriter.wrap @io do |gzio| gzio.close - -> { gzio.orig_name }.should \ - raise_error(Zlib::GzipFile::Error, 'closed gzip stream') + -> { gzio.orig_name }.should.raise(Zlib::GzipFile::Error, 'closed gzip stream') end end end diff --git a/spec/ruby/library/zlib/gzipreader/each_line_spec.rb b/spec/ruby/library/zlib/gzipreader/each_line_spec.rb index 6f17365879..97f24d410f 100644 --- a/spec/ruby/library/zlib/gzipreader/each_line_spec.rb +++ b/spec/ruby/library/zlib/gzipreader/each_line_spec.rb @@ -1,6 +1,9 @@ require_relative "../../../spec_helper" -require_relative 'shared/each' +require 'zlib' describe "Zlib::GzipReader#each_line" do - it_behaves_like :gzipreader_each, :each_line + it "is an alias of Zlib::GzipReader#each" do + Zlib::GzipReader.instance_method(:each_line).should == + Zlib::GzipReader.instance_method(:each) + end end diff --git a/spec/ruby/library/zlib/gzipreader/each_spec.rb b/spec/ruby/library/zlib/gzipreader/each_spec.rb index 3b98391a87..75fd7e6bae 100644 --- a/spec/ruby/library/zlib/gzipreader/each_spec.rb +++ b/spec/ruby/library/zlib/gzipreader/each_spec.rb @@ -1,6 +1,49 @@ require_relative "../../../spec_helper" -require_relative 'shared/each' +require 'stringio' +require 'zlib' describe "Zlib::GzipReader#each" do - it_behaves_like :gzipreader_each, :each + before :each do + @data = "firstline\nsecondline\n\nforthline" + @zip = [31, 139, 8, 0, 244, 125, 128, 88, 2, 255, 75, 203, 44, 42, 46, 201, + 201, 204, 75, 229, 42, 78, 77, 206, 207, 75, 1, 51, 185, 210,242, + 139, 74, 50, 64, 76, 0, 180, 54, 61, 111, 31, 0, 0, 0].pack('C*') + + @io = StringIO.new @zip + @gzreader = Zlib::GzipReader.new @io + end + + after :each do + ScratchPad.clear + end + + it "calls the given block for each line in the stream, passing the line as an argument" do + ScratchPad.record [] + @gzreader.each { |b| ScratchPad << b } + + ScratchPad.recorded.should == ["firstline\n", "secondline\n", "\n", "forthline"] + end + + it "returns an enumerator, which yields each byte in the stream, when no block is passed" do + enum = @gzreader.each + + ScratchPad.record [] + while true + begin + ScratchPad << enum.next + rescue StopIteration + break + end + end + + ScratchPad.recorded.should == ["firstline\n", "secondline\n", "\n", "forthline"] + end + + it "increments position before calling the block" do + i = 0 + @gzreader.each do |line| + i += line.length + @gzreader.pos.should == i + end + end end diff --git a/spec/ruby/library/zlib/gzipreader/eof_spec.rb b/spec/ruby/library/zlib/gzipreader/eof_spec.rb index 673220fdfd..434e716b64 100644 --- a/spec/ruby/library/zlib/gzipreader/eof_spec.rb +++ b/spec/ruby/library/zlib/gzipreader/eof_spec.rb @@ -12,31 +12,31 @@ describe "Zlib::GzipReader#eof?" do it "returns true when at EOF" do gz = Zlib::GzipReader.new @io - gz.eof?.should be_false + gz.eof?.should == false gz.read - gz.eof?.should be_true + gz.eof?.should == true end it "returns true when at EOF with the exact length of uncompressed data" do gz = Zlib::GzipReader.new @io - gz.eof?.should be_false + gz.eof?.should == false gz.read(10) - gz.eof?.should be_true + gz.eof?.should == true end it "returns true when at EOF with a length greater than the size of uncompressed data" do gz = Zlib::GzipReader.new @io - gz.eof?.should be_false + gz.eof?.should == false gz.read(11) - gz.eof?.should be_true + gz.eof?.should == true end it "returns false when at EOF when there's data left in the buffer to read" do gz = Zlib::GzipReader.new @io gz.read(9) - gz.eof?.should be_false + gz.eof?.should == false gz.read - gz.eof?.should be_true + gz.eof?.should == true end # This is especially important for JRuby, since eof? there @@ -44,11 +44,18 @@ describe "Zlib::GzipReader#eof?" do it "does not affect the reading data" do gz = Zlib::GzipReader.new @io 0.upto(9) do |i| - gz.eof?.should be_false + gz.eof?.should == false gz.read(1).should == @data[i, 1] end - gz.eof?.should be_true + gz.eof?.should == true gz.read.should == "" - gz.eof?.should be_true + gz.eof?.should == true + end +end + +describe "Zlib::GzipReader#eof" do + it "is an alias of Zlib::GzipReader#eof?" do + Zlib::GzipReader.instance_method(:eof).should == + Zlib::GzipReader.instance_method(:eof?) end end diff --git a/spec/ruby/library/zlib/gzipreader/getc_spec.rb b/spec/ruby/library/zlib/gzipreader/getc_spec.rb index e567231940..be13592189 100644 --- a/spec/ruby/library/zlib/gzipreader/getc_spec.rb +++ b/spec/ruby/library/zlib/gzipreader/getc_spec.rb @@ -33,7 +33,7 @@ describe "Zlib::GzipReader#getc" do gz = Zlib::GzipReader.new @io gz.read pos = gz.pos - gz.getc.should be_nil + gz.getc.should == nil gz.pos.should == pos end end diff --git a/spec/ruby/library/zlib/gzipreader/gets_spec.rb b/spec/ruby/library/zlib/gzipreader/gets_spec.rb index d3a2e7d263..5d0809f833 100644 --- a/spec/ruby/library/zlib/gzipreader/gets_spec.rb +++ b/spec/ruby/library/zlib/gzipreader/gets_spec.rb @@ -16,7 +16,7 @@ describe 'Zlib::GzipReader#gets' do gz.gets('').should == "123\n45\n\n" gz.gets('').should == "abc\nde\n\n" - gz.eof?.should be_true + gz.eof?.should == true end end end diff --git a/spec/ruby/library/zlib/gzipreader/read_spec.rb b/spec/ruby/library/zlib/gzipreader/read_spec.rb index b81954b5ce..b07d433bdd 100644 --- a/spec/ruby/library/zlib/gzipreader/read_spec.rb +++ b/spec/ruby/library/zlib/gzipreader/read_spec.rb @@ -30,7 +30,7 @@ describe "Zlib::GzipReader#read" do gz = Zlib::GzipReader.new @io -> { gz.read(-1) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) end it "returns an empty string if a 0 length is given" do @@ -59,8 +59,8 @@ describe "Zlib::GzipReader#read" do it "returns nil if length parameter is positive" do gz = Zlib::GzipReader.new @io gz.read # read till the end - gz.read(1).should be_nil - gz.read(2**16).should be_nil + gz.read(1).should == nil + gz.read(2**16).should == nil end end end diff --git a/spec/ruby/library/zlib/gzipreader/shared/each.rb b/spec/ruby/library/zlib/gzipreader/shared/each.rb deleted file mode 100644 index 71608e04ab..0000000000 --- a/spec/ruby/library/zlib/gzipreader/shared/each.rb +++ /dev/null @@ -1,49 +0,0 @@ -require_relative '../../../../spec_helper' -require 'stringio' -require 'zlib' - -describe :gzipreader_each, shared: true do - before :each do - @data = "firstline\nsecondline\n\nforthline" - @zip = [31, 139, 8, 0, 244, 125, 128, 88, 2, 255, 75, 203, 44, 42, 46, 201, - 201, 204, 75, 229, 42, 78, 77, 206, 207, 75, 1, 51, 185, 210,242, - 139, 74, 50, 64, 76, 0, 180, 54, 61, 111, 31, 0, 0, 0].pack('C*') - - @io = StringIO.new @zip - @gzreader = Zlib::GzipReader.new @io - end - - after :each do - ScratchPad.clear - end - - it "calls the given block for each line in the stream, passing the line as an argument" do - ScratchPad.record [] - @gzreader.send(@method) { |b| ScratchPad << b } - - ScratchPad.recorded.should == ["firstline\n", "secondline\n", "\n", "forthline"] - end - - it "returns an enumerator, which yields each byte in the stream, when no block is passed" do - enum = @gzreader.send(@method) - - ScratchPad.record [] - while true - begin - ScratchPad << enum.next - rescue StopIteration - break - end - end - - ScratchPad.recorded.should == ["firstline\n", "secondline\n", "\n", "forthline"] - end - - it "increments position before calling the block" do - i = 0 - @gzreader.send(@method) do |line| - i += line.length - @gzreader.pos.should == i - end - end -end diff --git a/spec/ruby/library/zlib/gzipreader/tell_spec.rb b/spec/ruby/library/zlib/gzipreader/tell_spec.rb new file mode 100644 index 0000000000..cc103e57b4 --- /dev/null +++ b/spec/ruby/library/zlib/gzipreader/tell_spec.rb @@ -0,0 +1,9 @@ +require_relative "../../../spec_helper" +require 'zlib' + +describe "Zlib::GzipReader#tell" do + it "is an alias of Zlib::GzipReader#pos" do + Zlib::GzipReader.instance_method(:tell).should == + Zlib::GzipReader.instance_method(:pos) + end +end diff --git a/spec/ruby/library/zlib/gzipreader/ungetbyte_spec.rb b/spec/ruby/library/zlib/gzipreader/ungetbyte_spec.rb index 7fa0608f9f..53870b9177 100644 --- a/spec/ruby/library/zlib/gzipreader/ungetbyte_spec.rb +++ b/spec/ruby/library/zlib/gzipreader/ungetbyte_spec.rb @@ -94,7 +94,7 @@ describe "Zlib::GzipReader#ungetbyte" do it 'makes eof? false' do @gz.ungetbyte 0x21 - @gz.eof?.should be_false + @gz.eof?.should == false end end @@ -112,7 +112,7 @@ describe "Zlib::GzipReader#ungetbyte" do it 'does not make eof? false' do @gz.ungetbyte nil - @gz.eof?.should be_true + @gz.eof?.should == true end end end diff --git a/spec/ruby/library/zlib/gzipreader/ungetc_spec.rb b/spec/ruby/library/zlib/gzipreader/ungetc_spec.rb index 34f2a1a2ca..46dcfde989 100644 --- a/spec/ruby/library/zlib/gzipreader/ungetc_spec.rb +++ b/spec/ruby/library/zlib/gzipreader/ungetc_spec.rb @@ -190,7 +190,7 @@ describe "Zlib::GzipReader#ungetc" do it 'makes eof? false' do @gz.ungetc 'x' - @gz.eof?.should be_false + @gz.eof?.should == false end end @@ -207,7 +207,7 @@ describe "Zlib::GzipReader#ungetc" do it 'makes eof? false' do @gz.ungetc 'ŷ' - @gz.eof?.should be_false + @gz.eof?.should == false end end @@ -224,7 +224,7 @@ describe "Zlib::GzipReader#ungetc" do it 'makes eof? false' do @gz.ungetc 'xŷž' - @gz.eof?.should be_false + @gz.eof?.should == false end end @@ -241,7 +241,7 @@ describe "Zlib::GzipReader#ungetc" do it 'makes eof? false' do @gz.ungetc 0x21 - @gz.eof?.should be_false + @gz.eof?.should == false end end @@ -258,7 +258,7 @@ describe "Zlib::GzipReader#ungetc" do it 'does not make eof? false' do @gz.ungetc '' - @gz.eof?.should be_true + @gz.eof?.should == true end end @@ -276,7 +276,7 @@ describe "Zlib::GzipReader#ungetc" do it 'does not make eof? false' do @gz.ungetc nil - @gz.eof?.should be_true + @gz.eof?.should == true end end end diff --git a/spec/ruby/library/zlib/gzipwriter/append_spec.rb b/spec/ruby/library/zlib/gzipwriter/append_spec.rb index 6aa2824180..ef9e3d3a6b 100644 --- a/spec/ruby/library/zlib/gzipwriter/append_spec.rb +++ b/spec/ruby/library/zlib/gzipwriter/append_spec.rb @@ -9,7 +9,7 @@ describe "Zlib::GzipWriter#<<" do it "returns self" do Zlib::GzipWriter.wrap @io do |gzio| - (gzio << "test").should equal(gzio) + (gzio << "test").should.equal?(gzio) end end end diff --git a/spec/ruby/library/zlib/gzipwriter/mtime_spec.rb b/spec/ruby/library/zlib/gzipwriter/mtime_spec.rb index 621b602dc7..a70fa68069 100644 --- a/spec/ruby/library/zlib/gzipwriter/mtime_spec.rb +++ b/spec/ruby/library/zlib/gzipwriter/mtime_spec.rb @@ -31,8 +31,7 @@ describe "Zlib::GzipWriter#mtime=" do Zlib::GzipWriter.wrap @io do |gzio| gzio.write '' - -> { gzio.mtime = nil }.should \ - raise_error(Zlib::GzipFile::Error, 'header is already written') + -> { gzio.mtime = nil }.should.raise(Zlib::GzipFile::Error, 'header is already written') end end end diff --git a/spec/ruby/library/zlib/inflate/append_spec.rb b/spec/ruby/library/zlib/inflate/append_spec.rb index f121e66566..a4c791e31e 100644 --- a/spec/ruby/library/zlib/inflate/append_spec.rb +++ b/spec/ruby/library/zlib/inflate/append_spec.rb @@ -41,7 +41,7 @@ describe "Zlib::Inflate#<<" do it "properly handles incomplete data" do # add bytes, one by one @foo_deflated[0, 5].each_byte { |d| @z << d.chr} - -> { @z.finish }.should raise_error(Zlib::BufError) + -> { @z.finish }.should.raise(Zlib::BufError) end it "properly handles excessive data, byte-by-byte" do diff --git a/spec/ruby/library/zlib/inflate/finish_spec.rb b/spec/ruby/library/zlib/inflate/finish_spec.rb index 3e0663e265..b7494e419c 100644 --- a/spec/ruby/library/zlib/inflate/finish_spec.rb +++ b/spec/ruby/library/zlib/inflate/finish_spec.rb @@ -23,7 +23,7 @@ describe "Zlib::Inflate#finish" do end it "each chunk should have the same prefix" do - @chunks.all? { |chunk| chunk =~ /\A0+\z/ }.should be_true + @chunks.all? { |chunk| chunk =~ /\A0+\z/ }.should == true end end diff --git a/spec/ruby/library/zlib/inflate/inflate_spec.rb b/spec/ruby/library/zlib/inflate/inflate_spec.rb index b308a4ba67..92e52363db 100644 --- a/spec/ruby/library/zlib/inflate/inflate_spec.rb +++ b/spec/ruby/library/zlib/inflate/inflate_spec.rb @@ -84,7 +84,7 @@ describe "Zlib::Inflate.inflate" do # add bytes, one by one, but not all result = +"" data.each_byte { |d| result << z.inflate(d.chr)} - -> { result << z.finish }.should raise_error(Zlib::BufError) + -> { result << z.finish }.should.raise(Zlib::BufError) end it "properly handles excessive data, byte-by-byte" do @@ -138,7 +138,7 @@ describe "Zlib::Inflate#inflate" do end it "properly handles chunked data" do - @chunks.all? { |chunk| chunk =~ /\A0+\z/ }.should be_true + @chunks.all? { |chunk| chunk =~ /\A0+\z/ }.should == true end end diff --git a/spec/ruby/library/zlib/zlib_version_spec.rb b/spec/ruby/library/zlib/zlib_version_spec.rb index f83dfae66d..7edc76cdd5 100644 --- a/spec/ruby/library/zlib/zlib_version_spec.rb +++ b/spec/ruby/library/zlib/zlib_version_spec.rb @@ -3,6 +3,6 @@ require 'zlib' describe "Zlib.zlib_version" do it "returns the version of the libz library" do - Zlib.zlib_version.should be_an_instance_of(String) + Zlib.zlib_version.should.instance_of?(String) end end |
