summaryrefslogtreecommitdiff
path: root/spec/ruby/core/string/squeeze_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/string/squeeze_spec.rb')
-rw-r--r--spec/ruby/core/string/squeeze_spec.rb46
1 files changed, 22 insertions, 24 deletions
diff --git a/spec/ruby/core/string/squeeze_spec.rb b/spec/ruby/core/string/squeeze_spec.rb
index d6b3fb6de6..52b6e1eed4 100644
--- a/spec/ruby/core/string/squeeze_spec.rb
+++ b/spec/ruby/core/string/squeeze_spec.rb
@@ -1,6 +1,7 @@
-# -*- encoding: binary -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
+# encoding: binary
+# frozen_string_literal: false
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
# TODO: rewrite all these specs
@@ -50,16 +51,8 @@ describe "String#squeeze" do
it "raises an ArgumentError when the parameter is out of sequence" do
s = "--subbookkeeper--"
- lambda { s.squeeze("e-b") }.should raise_error(ArgumentError)
- lambda { s.squeeze("^e-b") }.should raise_error(ArgumentError)
- end
-
- it "taints the result when self is tainted" do
- "hello".taint.squeeze("e").tainted?.should == true
- "hello".taint.squeeze("a-z").tainted?.should == true
-
- "hello".squeeze("e".taint).tainted?.should == false
- "hello".squeeze("l".taint).tainted?.should == false
+ -> { s.squeeze("e-b") }.should.raise(ArgumentError)
+ -> { s.squeeze("^e-b") }.should.raise(ArgumentError)
end
it "tries to convert each set arg to a string using to_str" do
@@ -72,21 +65,26 @@ describe "String#squeeze" do
"hello room".squeeze(other_string, other_string2).should == "hello rom"
end
+ it "returns a String in the same encoding as self" do
+ "yellow moon".encode("US-ASCII").squeeze.encoding.should == Encoding::US_ASCII
+ "yellow moon".encode("US-ASCII").squeeze("a").encoding.should == Encoding::US_ASCII
+ end
+
it "raises a TypeError when one set arg can't be converted to a string" do
- lambda { "hello world".squeeze([]) }.should raise_error(TypeError)
- lambda { "hello world".squeeze(Object.new)}.should raise_error(TypeError)
- lambda { "hello world".squeeze(mock('x')) }.should raise_error(TypeError)
+ -> { "hello world".squeeze([]) }.should.raise(TypeError)
+ -> { "hello world".squeeze(Object.new)}.should.raise(TypeError)
+ -> { "hello world".squeeze(mock('x')) }.should.raise(TypeError)
end
- it "returns subclass instances when called on a subclass" do
- StringSpecs::MyString.new("oh no!!!").squeeze("!").should be_an_instance_of(StringSpecs::MyString)
+ it "returns String instances when called on a subclass" do
+ StringSpecs::MyString.new("oh no!!!").squeeze("!").should.instance_of?(String)
end
end
describe "String#squeeze!" do
it "modifies self in place and returns self" do
a = "yellow moon"
- a.squeeze!.should equal(a)
+ a.squeeze!.should.equal?(a)
a.should == "yelow mon"
end
@@ -99,15 +97,15 @@ describe "String#squeeze!" do
it "raises an ArgumentError when the parameter is out of sequence" do
s = "--subbookkeeper--"
- lambda { s.squeeze!("e-b") }.should raise_error(ArgumentError)
- lambda { s.squeeze!("^e-b") }.should raise_error(ArgumentError)
+ -> { s.squeeze!("e-b") }.should.raise(ArgumentError)
+ -> { s.squeeze!("^e-b") }.should.raise(ArgumentError)
end
- it "raises a RuntimeError when self is frozen" do
+ it "raises a FrozenError when self is frozen" do
a = "yellow moon"
a.freeze
- lambda { a.squeeze!("") }.should raise_error(RuntimeError)
- lambda { a.squeeze! }.should raise_error(RuntimeError)
+ -> { a.squeeze!("") }.should.raise(FrozenError)
+ -> { a.squeeze! }.should.raise(FrozenError)
end
end