Sha256: a6545af0c84d4926a77440c31134f24fd3e5dce896f66b9b0f16c68c764fafdc

Contents?: true

Size: 1.45 KB

Versions: 52

Compression:

Stored size: 1.45 KB

Contents

require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes.rb', __FILE__)

describe "String#*" do
  it "returns a new string containing count copies of self" do
    ("cool" * 0).should == ""
    ("cool" * 1).should == "cool"
    ("cool" * 3).should == "coolcoolcool"
  end

  it "tries to convert the given argument to an integer using to_int" do
    ("cool" * 3.1).should == "coolcoolcool"
    ("a" * 3.999).should == "aaa"

    a = mock('4')
    a.should_receive(:to_int).and_return(4)

    ("a" * a).should == "aaaa"
  end

  it "raises an ArgumentError when given integer is negative" do
    lambda { "cool" * -3    }.should raise_error(ArgumentError)
    lambda { "cool" * -3.14 }.should raise_error(ArgumentError)
  end

  it "raises a RangeError when given integer is a Bignum" do
    lambda { "cool" * 999999999999999999999 }.should raise_error(RangeError)
  end

  it "returns subclass instances" do
    (StringSpecs::MyString.new("cool") * 0).should be_kind_of(StringSpecs::MyString)
    (StringSpecs::MyString.new("cool") * 1).should be_kind_of(StringSpecs::MyString)
    (StringSpecs::MyString.new("cool") * 2).should be_kind_of(StringSpecs::MyString)
  end

  it "always taints the result when self is tainted" do
    ["", "OK", StringSpecs::MyString.new(""), StringSpecs::MyString.new("OK")].each do |str|
      str.taint

      [0, 1, 2].each do |arg|
        (str * arg).tainted?.should == true
      end
    end
  end
end

Version data entries

52 entries across 52 versions & 2 rubygems

Version Path
rhodes-7.6.0 spec/framework_spec/app/spec/core/string/multiply_spec.rb
rhodes-7.5.1 spec/framework_spec/app/spec/core/string/multiply_spec.rb
rhodes-7.4.1 spec/framework_spec/app/spec/core/string/multiply_spec.rb
rhodes-7.1.17 spec/framework_spec/app/spec/core/string/multiply_spec.rb
rhodes-6.2.0 spec/framework_spec/app/spec/core/string/multiply_spec.rb
rhodes-6.0.11 spec/framework_spec/app/spec/core/string/multiply_spec.rb
rhodes-5.5.18 spec/framework_spec/app/spec/core/string/multiply_spec.rb
rhodes-5.5.17 spec/framework_spec/app/spec/core/string/multiply_spec.rb
rhodes-5.5.15 spec/framework_spec/app/spec/core/string/multiply_spec.rb
rhodes-5.5.0.22 spec/framework_spec/app/spec/core/string/multiply_spec.rb
rhodes-5.5.2 spec/framework_spec/app/spec/core/string/multiply_spec.rb
rhodes-5.5.0.7 spec/framework_spec/app/spec/core/string/multiply_spec.rb
rhodes-5.5.0.3 spec/framework_spec/app/spec/core/string/multiply_spec.rb
rhodes-5.5.0 spec/framework_spec/app/spec/core/string/multiply_spec.rb
tauplatform-1.0.3 spec/framework_spec/app/spec/core/string/multiply_spec.rb
tauplatform-1.0.2 spec/framework_spec/app/spec/core/string/multiply_spec.rb
tauplatform-1.0.1 spec/framework_spec/app/spec/core/string/multiply_spec.rb
rhodes-3.5.1.12 spec/framework_spec/app/spec/core/string/multiply_spec.rb
rhodes-3.3.5 spec/framework_spec/app/spec/core/string/multiply_spec.rb
rhodes-3.4.2 spec/framework_spec/app/spec/core/string/multiply_spec.rb