summaryrefslogtreecommitdiff
path: root/spec/rubyspec/shared/io/putc.rb
diff options
context:
space:
mode:
authoreregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-07 12:04:49 +0000
committereregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-07 12:04:49 +0000
commit95e8c48dd3348503a8c7db5d0498894a1b676395 (patch)
tree9eef7f720314ebaff56845a74e203770e62284e4 /spec/rubyspec/shared/io/putc.rb
parented7d803500de38186c74bce94d233e85ef51e503 (diff)
Add in-tree mspec and ruby/spec
* For easier modifications of ruby/spec by MRI developers. * .gitignore: track changes under spec. * spec/mspec, spec/rubyspec: add in-tree mspec and ruby/spec. These files can therefore be updated like any other file in MRI. Instructions are provided in spec/README. [Feature #13156] [ruby-core:79246] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58595 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/rubyspec/shared/io/putc.rb')
-rw-r--r--spec/rubyspec/shared/io/putc.rb57
1 files changed, 57 insertions, 0 deletions
diff --git a/spec/rubyspec/shared/io/putc.rb b/spec/rubyspec/shared/io/putc.rb
new file mode 100644
index 0000000000..5f620f183f
--- /dev/null
+++ b/spec/rubyspec/shared/io/putc.rb
@@ -0,0 +1,57 @@
+# -*- encoding: ascii-8bit -*-
+describe :io_putc, shared: true do
+ after :each do
+ @io.close if @io && [email protected]?
+ @io_object = nil
+ rm_r @name
+ end
+
+ describe "with a Fixnum argument" do
+ it "writes one character as a String" do
+ @io.should_receive(:write).with("A")
+ @io_object.send(@method, 65).should == 65
+ end
+
+ it "writes the low byte as a String" do
+ @io.should_receive(:write).with("A")
+ @io_object.send(@method, 0x2441).should == 0x2441
+ end
+ end
+
+ describe "with a String argument" do
+ it "writes one character" do
+ @io.should_receive(:write).with("B")
+ @io_object.send(@method, "B").should == "B"
+ end
+
+ it "writes the first character" do
+ @io.should_receive(:write).with("R")
+ @io_object.send(@method, "Ruby").should == "Ruby"
+ end
+ end
+
+ it "calls #to_int to convert an object to an Integer" do
+ obj = mock("kernel putc")
+ obj.should_receive(:to_int).and_return(65)
+
+ @io.should_receive(:write).with("A")
+ @io_object.send(@method, obj).should == obj
+ end
+
+ it "raises IOError on a closed stream" do
+ @io.close
+ lambda { @io_object.send(@method, "a") }.should raise_error(IOError)
+ end
+
+ it "raises a TypeError when passed nil" do
+ lambda { @io_object.send(@method, nil) }.should raise_error(TypeError)
+ end
+
+ it "raises a TypeError when passed false" do
+ lambda { @io_object.send(@method, false) }.should raise_error(TypeError)
+ end
+
+ it "raises a TypeError when passed true" do
+ lambda { @io_object.send(@method, true) }.should raise_error(TypeError)
+ end
+end