<commit_before>require File.dirname(__FILE__) + '/../spec_helper'
require 'mspec/helpers/io'
require 'mspec/helpers/fs'
require 'mspec/helpers/tmp'

describe IOStub do
  before :each do
    @out = IOStub.new
    @sep = $\
  end

  after :each do
    $\ = @sep
  end

  it "provides a write method" do
    @out.write "this"
    @out.should == "this"
  end

  it "concatenates the arguments sent to write" do
    @out.write "flim ", "flam"
    @out.should == "flim flam"
  end

  it "provides a print method that appends the default separator" do
    $\ = " [newline] "
    @out.print "hello"
    @out.print "world"
    @out.should == "hello [newline] world [newline] "
  end

  it "provides a puts method that appends the default separator" do
    @out.puts "hello", 1, 2, 3
    @out.should == "hello\n1\n2\n3\n"
  end

  it "provides a printf method" do
    @out.printf "%-10s, %03d, %2.1f", "test", 42, 4.2
    @out.should == "test      , 042, 4.2"
  end

  it "provides a flush method that does nothing and returns self" do
    @out.flush.should == @out
  end
end

describe Object, "#new_fd" do
  before :each do
    @name = tmp("io_specs")
  end

  after :each do
    @io.close unless @io.closed?
    rm_r @name
  end

  it "returns a Fixnum that can be used to create an IO instance" do
    fd = new_fd @name
    fd.should be_an_instance_of(Fixnum)

    @io = IO.new fd
    @io.sync = true
    @io.print "io data"

    IO.read(@name).should == "io data"
  end
end

describe Object, "#new_io" do
  before :each do<commit_msg>Don't assume write is default open mode on Windows.<commit_after>require File.dirname(__FILE__) + '/../spec_helper'
require 'mspec/helpers/io'
require 'mspec/helpers/fs'
require 'mspec/helpers/tmp'

describe IOStub do
  before :each do
    @out = IOStub.new
    @sep = $\
  end

  after :each do
    $\ = @sep
  end

  it "provides a write method" do
    @out.write "this"
    @out.should == "this"
  end

  it "concatenates the arguments sent to write" do
    @out.write "flim ", "flam"
    @out.should == "flim flam"
  end

  it "provides a print method that appends the default separator" do
    $\ = " [newline] "
    @out.print "hello"
    @out.print "world"
    @out.should == "hello [newline] world [newline] "
  end

  it "provides a puts method that appends the default separator" do
    @out.puts "hello", 1, 2, 3
    @out.should == "hello\n1\n2\n3\n"
  end

  it "provides a printf method" do
    @out.printf "%-10s, %03d, %2.1f", "test", 42, 4.2
    @out.should == "test      , 042, 4.2"
  end

  it "provides a flush method that does nothing and returns self" do
    @out.flush.should == @out
  end
end

describe Object, "#new_fd" do
  before :each do
    @name = tmp("io_specs")
  end

  after :each do
    @io.close unless @io.closed?
    rm_r @name
  end

  it "returns a Fixnum that can be used to create an IO instance" do
    fd = new_fd @name
    fd.should be_an_instance_of(Fixnum)

    @io = IO.new fd, "w"
    @io.sync = true
    @io.print "io data"

    IO.read(@name).should == "io data"
  end
end

describe Object, "#new_io" do
  before :each do
{'fraction_non_alphanumeric': 0.12810584059373992, 'fraction_numerical': 0.013552758954501452, 'mean_word_length': 2.686087990487515, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5489360', 'n_tokens_mistral': 1185, 'n_tokens_neox': 1139, 'n_words': 374}