File: io_spec.rb

package info (click to toggle)
jruby 9.4.14.0%2Bds-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 89,708 kB
  • sloc: ruby: 553,384; java: 277,371; yacc: 25,867; ansic: 6,322; xml: 6,111; sh: 2,121; sed: 94; makefile: 76; jsp: 48; tcl: 40; exp: 12
file content (39 lines) | stat: -rw-r--r-- 1,177 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
require File.dirname(__FILE__) + "/../spec_helper"
require 'jruby'
require 'stringio'
require 'tmpdir'

describe "The JRuby module" do
  it "should give access to a Java reference with the reference method" do
    str_ref = JRuby.reference("foo")
    expect(str_ref.class).to eq(org.jruby.RubyString)
    
    str = str_ref.toString
    expect(str.class).to eq(String)
  end
  
  it "should unwrap Java-wrapped Ruby objects with the dereference method" do
    io_ref = org.jruby.RubyIO.new(JRuby.runtime, java.lang.System.in)
    expect(io_ref.class).to eq(org.jruby.RubyIO)
    
    io = JRuby.dereference(io_ref)
    expect(io.class).to eq(IO)
  end
end

describe "IOOutputStream" do
  # https://github.com/jruby/jruby/issues/8686
  it "allows source and destination encoding to be the same" do
    filename = File.join(Dir.tmpdir, "iooutputstream_write")
    io = File.open(filename, "w+:UTF-8")
    ioos = org.jruby.util.IOOutputStream.new(io, org.jcodings.specific.UTF8Encoding::INSTANCE)
    bytes = "…".to_java_bytes
    ioos.write(bytes, 0, bytes.length)
    ioos.flush
    io.flush

    File.read(filename).should == "…"
  ensure
    io.close rescue nil
  end
end