summaryrefslogtreecommitdiff
path: root/spec/ruby/core/string/setbyte_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/string/setbyte_spec.rb')
-rw-r--r--spec/ruby/core/string/setbyte_spec.rb17
1 files changed, 12 insertions, 5 deletions
diff --git a/spec/ruby/core/string/setbyte_spec.rb b/spec/ruby/core/string/setbyte_spec.rb
index 3f2e03f8a8..85403ca62c 100644
--- a/spec/ruby/core/string/setbyte_spec.rb
+++ b/spec/ruby/core/string/setbyte_spec.rb
@@ -1,4 +1,5 @@
# -*- encoding: utf-8 -*-
+# frozen_string_literal: false
require_relative '../../spec_helper'
describe "String#setbyte" do
@@ -36,6 +37,12 @@ describe "String#setbyte" do
str.valid_encoding?.should be_true
str.setbyte(2,253)
str.valid_encoding?.should be_false
+
+ str = "ABC"
+ str.setbyte(0, 0x20) # ' '
+ str.should.valid_encoding?
+ str.setbyte(0, 0xE3)
+ str.should_not.valid_encoding?
end
it "regards a negative index as counting from the end of the String" do
@@ -51,11 +58,11 @@ describe "String#setbyte" do
end
it "raises an IndexError if the index is greater than the String bytesize" do
- lambda { "?".setbyte(1, 97) }.should raise_error(IndexError)
+ -> { "?".setbyte(1, 97) }.should raise_error(IndexError)
end
it "raises an IndexError if the negative index is greater magnitude than the String bytesize" do
- lambda { "???".setbyte(-5, 97) }.should raise_error(IndexError)
+ -> { "???".setbyte(-5, 97) }.should raise_error(IndexError)
end
it "sets a byte at an index greater than String size" do
@@ -75,14 +82,14 @@ describe "String#setbyte" do
str1.should_not == "ledgehog"
end
- it "raises a #{frozen_error_class} if self is frozen" do
+ it "raises a FrozenError if self is frozen" do
str = "cold".freeze
str.frozen?.should be_true
- lambda { str.setbyte(3,96) }.should raise_error(frozen_error_class)
+ -> { str.setbyte(3,96) }.should raise_error(FrozenError)
end
it "raises a TypeError unless the second argument is an Integer" do
- lambda { "a".setbyte(0,'a') }.should raise_error(TypeError)
+ -> { "a".setbyte(0,'a') }.should raise_error(TypeError)
end
it "calls #to_int to convert the index" do