|
19 | 19 | it "returns a copy when Encoding.default_internal is nil" do
|
20 | 20 | Encoding.default_internal = nil
|
21 | 21 | str = "あ"
|
22 |
| - str.encode.should_not equal(str) |
| 22 | + encoded = str.encode |
| 23 | + encoded.should_not equal(str) |
| 24 | + encoded.should eql(str) |
23 | 25 | end
|
24 | 26 |
|
25 | 27 | it "returns a copy for a ASCII-only String when Encoding.default_internal is nil" do
|
26 | 28 | Encoding.default_internal = nil
|
27 | 29 | str = "abc"
|
28 |
| - str.encode.should_not equal(str) |
| 30 | + encoded = str.encode |
| 31 | + encoded.should_not equal(str) |
| 32 | + encoded.should eql(str) |
29 | 33 | end
|
30 | 34 |
|
31 | 35 | it "encodes an ascii substring of a binary string to UTF-8" do
|
|
39 | 43 | describe "when passed to encoding" do
|
40 | 44 | it "returns a copy when passed the same encoding as the String" do
|
41 | 45 | str = "あ"
|
42 |
| - str.encode(Encoding::UTF_8).should_not equal(str) |
| 46 | + encoded = str.encode(Encoding::UTF_8) |
| 47 | + encoded.should_not equal(str) |
| 48 | + encoded.should eql(str) |
43 | 49 | end
|
44 | 50 |
|
45 | 51 | it "round trips a String" do
|
|
75 | 81 | encoded = str.encode("utf-8", "utf-8")
|
76 | 82 |
|
77 | 83 | encoded.should_not equal(str)
|
| 84 | + encoded.should eql(str.force_encoding("utf-8")) |
78 | 85 | encoded.encoding.should == Encoding::UTF_8
|
79 | 86 | end
|
80 | 87 |
|
|
87 | 94 | describe "when passed to, options" do
|
88 | 95 | it "returns a copy when the destination encoding is the same as the String encoding" do
|
89 | 96 | str = "あ"
|
90 |
| - str.encode(Encoding::UTF_8, undef: :replace).should_not equal(str) |
| 97 | + encoded = str.encode(Encoding::UTF_8, undef: :replace) |
| 98 | + encoded.should_not equal(str) |
| 99 | + encoded.should eql(str) |
91 | 100 | end
|
92 | 101 | end
|
93 | 102 |
|
94 | 103 | describe "when passed to, from, options" do
|
95 | 104 | it "returns a copy when both encodings are the same" do
|
96 | 105 | str = "あ"
|
97 |
| - str.encode("utf-8", "utf-8", invalid: :replace).should_not equal(str) |
| 106 | + encoded = str.encode("utf-8", "utf-8", invalid: :replace) |
| 107 | + encoded.should_not equal(str) |
| 108 | + encoded.should eql(str) |
| 109 | + end |
| 110 | + |
| 111 | + it "returns a copy in the destination encoding when both encodings are the same" do |
| 112 | + str = "あ" |
| 113 | + str.force_encoding("binary") |
| 114 | + encoded = str.encode("utf-8", "utf-8", invalid: :replace) |
| 115 | + |
| 116 | + encoded.should_not equal(str) |
| 117 | + encoded.should eql(str.force_encoding("utf-8")) |
| 118 | + encoded.encoding.should == Encoding::UTF_8 |
98 | 119 | end
|
99 | 120 | end
|
100 | 121 | end
|
|
0 commit comments