Skip to content

Commit

Permalink
Use 'let' in code, and fix spec description
Browse files Browse the repository at this point in the history
Avoid hard coding reused value.
  • Loading branch information
Rajarshi Das authored and BanzaiMan committed Aug 19, 2013
1 parent 4932a84 commit 54b4bc5
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions spec/java_integration/addons/io_spec.rb
Expand Up @@ -2,13 +2,14 @@
require 'tempfile'

describe "Ruby IO" do
it "should be able to get an IO from a java.io.InputStream" do
io = java.io.ByteArrayInputStream.new("1234567890".to_java_bytes).to_io
let(:input_number){"1234567890"}
it "gets an IO from a java.io.InputStream" do
io = java.io.ByteArrayInputStream.new(input_number.to_java_bytes).to_io
io.class.should == IO
io.read(5).should == "12345"
end

it "should be able to get an IO from a java.io.OutputStream" do
it "gets an IO from a java.io.OutputStream" do
output = java.io.ByteArrayOutputStream.new
io = output.to_io
io.class.should == IO
Expand All @@ -17,7 +18,7 @@
String.from_java_bytes(output.to_byte_array).should == "12345"
end

it "should be coercible to java.io.InputStream with IO#to_inputstream" do
it "coercible to java.io.InputStream with IO#to_inputstream" do
file = File.open(__FILE__)
first_ten = file.read(10)
file.seek(0)
Expand All @@ -29,21 +30,21 @@
String.from_java_bytes(bytes).should == first_ten
end

it "should be coercible to java.io.OutputStream with IO#to_outputstream" do
it "coercible to java.io.OutputStream with IO#to_outputstream" do
file = Tempfile.new("io_spec")
stream = file.to_outputstream
java.io.OutputStream.should === stream

bytes = "1234567890".to_java_bytes
bytes = input_number.to_java_bytes
stream.write(bytes)
stream.flush
file.seek(0)
str = file.read(10)
str.should == String.from_java_bytes(bytes)
end

it "should be able to get an IO from a java.nio.channels.Channel" do
input = java.io.ByteArrayInputStream.new("1234567890".to_java_bytes)
it "gets an IO from a java.nio.channels.Channel" do
input = java.io.ByteArrayInputStream.new(input_number.to_java_bytes)
channel = java.nio.channels.Channels.newChannel(input)
io = channel.to_io
io.class.should == IO
Expand All @@ -58,12 +59,12 @@
String.from_java_bytes(output.to_byte_array).should == "12345"
end

it "should be coercible to java.nio.channels.Channel with IO#to_channel" do
it "coercible to java.nio.channels.Channel with IO#to_channel" do
file = Tempfile.new("io_spec")
channel = file.to_channel
java.nio.channels.Channel.should === channel

bytes = java.nio.ByteBuffer.wrap("1234567890".to_java_bytes)
bytes = java.nio.ByteBuffer.wrap(input_number.to_java_bytes)
channel.write(bytes)
file.seek(0)
str = file.read(10)
Expand Down

0 comments on commit 54b4bc5

Please sign in to comment.