Permalink
Browse files

Add specs for String#chomp! without argument

ported from String#chomp specs
  • Loading branch information...
1 parent f14ff08 commit 9a0b44568f6f8ff27add8cd4d02f8e2a516846ae @kachick committed Dec 7, 2012
Showing with 41 additions and 0 deletions.
  1. +41 −0 spec/ruby/core/string/chomp_spec.rb
@@ -159,6 +159,47 @@
"hello".chomp!(nil).should == nil
end
+ describe "with a different $/ separator" do
+ before :each do
+ @old_rec_sep = $/
+ @expectation = lambda do |sep|
+ $/ = sep
+ [ ["", "".chomp!(sep)],
+ ["x", "x".chomp!(sep)],
+ ["x\n", "x\n".chomp!(sep)],
+ ["x\r", "x\r".chomp!(sep)],
+ ["x\r\n", "x\r\n".chomp!(sep)],
+ ["x\n\r\r\n", "x\n\r\r\n".chomp!(sep)],
+ ["hello", "hello".chomp!(sep)]
+ ].should be_computed_by(:'chomp!')
+ end
+ end
+
+ after :each do
+ $/ = @old_rec_sep
+ end
+
+ it "uses separator #{"".inspect} for $/ as the separator when none is given" do
+ @expectation.call("")
+ end
+
+ it "uses separator #{"llo".inspect} for $/ as the separator when none is given" do
+ @expectation.call("llo")
+ end
+
+ it "uses separator #{"\n".inspect} for $/ as the separator when none is given" do
+ @expectation.call("\n")
+ end
+
+ it "uses separator #{"\r".inspect} for $/ as the separator when none is given" do
+ @expectation.call("\r")
+ end
+
+ it "uses separator #{nil.inspect} for $/ as the separator when none is given" do
+ @expectation.call(nil)
+ end
+ end
+
ruby_version_is ""..."1.9" do
it "raises a TypeError when self is frozen" do
a = "string\n"

0 comments on commit 9a0b445

Please sign in to comment.