Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 48 lines (39 sloc) 1.85 kb
957c2c9 @brixen Standardize require lines.
brixen authored
1 require File.expand_path('../../../spec_helper', __FILE__)
ae91f25 @jfirebaugh Spec encoding behavior for String#{<<,concat,+}
jfirebaugh authored
2 require File.expand_path('../fixtures/classes', __FILE__)
3 require File.expand_path('../shared/concat', __FILE__)
6c1c34a @brixen Ask not what RubySpec can do for you, but what you can do for RubySpec.
brixen authored
4
5 describe "String#+" do
6 it "returns a new string containing the given string concatenated to self" do
7 ("" + "").should == ""
8 ("" + "Hello").should == "Hello"
9 ("Hello" + "").should == "Hello"
10 ("Ruby !" + "= Rubinius").should == "Ruby != Rubinius"
11 end
12
13 it "converts any non-String argument with #to_str" do
14 c = mock 'str'
15 c.should_receive(:to_str).any_number_of_times.and_return(' + 1 = 2')
16
17 ("1" + c).should == '1 + 1 = 2'
18 end
19
20 it "raises a TypeError when given any object that fails #to_str" do
21 lambda { "" + Object.new }.should raise_error(TypeError)
22 lambda { "" + 65 }.should raise_error(TypeError)
23 end
24
25 it "doesn't return subclass instances" do
3ccbfd1 @BanzaiMan Avoid result.class.should == Class
BanzaiMan authored
26 (StringSpecs::MyString.new("hello") + "").should be_kind_of(String)
27 (StringSpecs::MyString.new("hello") + "foo").should be_kind_of(String)
28 (StringSpecs::MyString.new("hello") + StringSpecs::MyString.new("foo")).should be_kind_of(String)
29 (StringSpecs::MyString.new("hello") + StringSpecs::MyString.new("")).should be_kind_of(String)
30 (StringSpecs::MyString.new("") + StringSpecs::MyString.new("")).should be_kind_of(String)
31 ("hello" + StringSpecs::MyString.new("foo")).should be_kind_of(String)
32 ("hello" + StringSpecs::MyString.new("")).should be_kind_of(String)
6c1c34a @brixen Ask not what RubySpec can do for you, but what you can do for RubySpec.
brixen authored
33 end
34
35 it "taints the result when self or other is tainted" do
36 strs = ["", "OK", StringSpecs::MyString.new(""), StringSpecs::MyString.new("OK")]
37 strs += strs.map { |s| s.dup.taint }
38
39 strs.each do |str|
40 strs.each do |other|
41 (str + other).tainted?.should == (str.tainted? | other.tainted?)
42 end
43 end
44 end
ae91f25 @jfirebaugh Spec encoding behavior for String#{<<,concat,+}
jfirebaugh authored
45
46 it_behaves_like :string_concat_encoding, :+
6c1c34a @brixen Ask not what RubySpec can do for you, but what you can do for RubySpec.
brixen authored
47 end
Something went wrong with that request. Please try again.