summaryrefslogtreecommitdiff
path: root/spec/ruby/library/stringscanner/append_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/library/stringscanner/append_spec.rb')
-rw-r--r--spec/ruby/library/stringscanner/append_spec.rb30
1 files changed, 26 insertions, 4 deletions
diff --git a/spec/ruby/library/stringscanner/append_spec.rb b/spec/ruby/library/stringscanner/append_spec.rb
index 378c62e2b1..68747d52d7 100644
--- a/spec/ruby/library/stringscanner/append_spec.rb
+++ b/spec/ruby/library/stringscanner/append_spec.rb
@@ -1,11 +1,33 @@
require_relative '../../spec_helper'
-require_relative 'shared/concat'
require 'strscan'
describe "StringScanner#<<" do
- it_behaves_like :strscan_concat, :<<
+ it "concatenates the given argument to self and returns self" do
+ s = StringScanner.new(+"hello ")
+ (s. << 'world').should == s
+ s.string.should == "hello world"
+ s.eos?.should == false
+ end
+
+ it "raises a TypeError if the given argument can't be converted to a String" do
+ -> { StringScanner.new('hello') << :world }.should.raise(TypeError)
+ -> { StringScanner.new('hello') << mock('x') }.should.raise(TypeError)
+ end
end
-describe "StringScanner#<< when passed a Fixnum" do
- it_behaves_like :strscan_concat_fixnum, :<<
+describe "StringScanner#<< when passed an Integer" do
+ it "raises a TypeError" do
+ a = StringScanner.new("hello world")
+ -> { a << 333 }.should.raise(TypeError)
+ b = StringScanner.new("")
+ -> { b << (256 * 3 + 64) }.should.raise(TypeError)
+ -> { b << -200 }.should.raise(TypeError)
+ end
+
+ it "doesn't call to_int on the argument" do
+ x = mock('x')
+ x.should_not_receive(:to_int)
+
+ -> { StringScanner.new("") << x }.should.raise(TypeError)
+ end
end