<commit_before>require File.dirname(__FILE__) + '/../../spec_helper'
require "stringio"

describe "StringIO#gets when passed [Object]" do
  before(:each) do
    @io = StringIO.new("this>is>an>example")
  end
  
  it "tries to convert the passed Object to a String using #to_str" do
    obj = mock('to_str')
    obj.should_receive(:to_str).and_return(">")
    @io.gets(obj).should == "this>"
  end
  
  it "returns the next paragrah when passed an empty String" do
    io = StringIO.new("this is\n\nan example")
    io.gets("").should == "this is\n"
    io.gets("").should == "an example"
  end
  
  it "returns the entire content when passed nil" do
    io = StringIO.new("this is\n\nan example")
    io.gets(nil).should == "this is\n\nan example"
  end

  ruby_version_is "" ... "1.8.7" do
    it "checks whether the passed argument responds to #to_str" do
      obj = mock('method_missing to_str')
      obj.should_receive(:respond_to?).with(:to_str).and_return(true)
      obj.should_receive(:method_missing).with(:to_str).and_return(">")
      @io.gets(obj).should == "this>"
    end
  end

  ruby_version_is "1.8.7" do
    it "checks whether the passed argument responds to #to_str (including private methods)" do
      obj = mock('method_missing to_str')
      obj.should_receive(:respond_to?).with(:to_str, true).and_return(true)
      obj.should_receive(:method_missing).with(:to_str).and_return(">")
      @io.gets(obj).should == "this>"
    end
  end
end

describe "StringIO#gets" do
  before(:each) do
    @io = StringIO.new("this is\nan example\nfor StringIO#gets")
  end
  
  it "updates self's position" do
    @io.gets
    @io.pos.should eql(8)
    
    @io.gets
    @io.pos.should eql(19)

    @io.gets
    @io.pos.should eql(36)
  end
  
  it "returns the data read till the next occurence of $/ or till eof" do
    @io.gets.should == "this is\n"
    
    begin
      old_sep, $/ = $/, " "
      @io.gets.should == "an "
      @io.gets.should == "example\nfor "
      @io.gets.should == "StringIO#gets"
    ensure<commit_msg>Updated the StringIO#gets specs.<commit_after>require File.dirname(__FILE__) + '/../../spec_helper'
require "stringio"

describe "StringIO#gets when passed [Object]" do
  before(:each) do
    @io = StringIO.new("this>is>an>example")
  end

  it "returns the data read till the next occurence of the passed seperator" do
    @io.gets(">").should == "this>"
    @io.gets(">").should == "is>"
    @io.gets(">").should == "an>"
    @io.gets(">").should == "example"
  end

  it "updates self's lineno based on the passed seperator" do
    @io.gets(">")
    @io.lineno.should eql(1)
    
    @io.gets(">")
    @io.lineno.should eql(2)
    
    @io.gets(">")
    @io.lineno.should eql(3)
  end

  it "tries to convert the passed Object to a String using #to_str" do
    obj = mock('to_str')
    obj.should_receive(:to_str).and_return(">")
    @io.gets(obj).should == "this>"
  end
  
  it "returns the next paragraph when passed an empty String" do
    io = StringIO.new("this is\n\nan example")
    io.gets("").should == "this is\n"
    io.gets("").should == "an example"
  end
  
  it "returns the entire content when passed nil" do
    io = StringIO.new("this is\n\nan example")
    io.gets(nil).should == "this is\n\nan example"
  end

  ruby_version_is "" ... "1.8.7" do
    it "checks whether the passed argument responds to #to_str" do
      obj = mock('method_missing to_str')
      obj.should_receive(:respond_to?).with(:to_str).and_return(true)
      obj.should_receive(:method_missing).with(:to_str).and_return(">")
      @io.gets(obj).should == "this>"
    end
  end

  ruby_version_is "1.8.7" do
    it "checks whether the passed argument responds to #to_str (including private methods)" do
      obj = mock('method_missing to_str')
      obj.should_receive(:respond_to?).with(:to_str, true).and_return(true)
      obj.should_receive(:method_missing).with(:to_str).and_return(">")
      @io.gets(obj).should == "this>"
    end
  end
end

describe "StringIO#gets" do
  before(:each) do
    @io = StringIO.new("this is\nan example\nfor StringIO#gets")
  end
  
  it "updates self's position" do
    @io.gets
    @io.pos.should eql(8)
    
    @io.gets
    @io.pos.should eql(19)

    @io.gets
    @io.pos.should eql(36)
  end
  
  it "updates self's lineno" do
    @io.gets
    @io.lineno.should eql(1)
    
    @io.gets
    @io.lineno.should eql(2)
    
    @io.gets
    @io.lineno.should eql(3)
  end
  
  it "returns the data read till the next occurence of $/ or till eof" do
    @io.gets.should == "this is\n"
    
    begin
      old_sep, $/ = $/, " "
      @io.gets.should == "an "
      @io.gets.should == "example\nfor "
      @io.gets.should == "StringIO#gets"
    ensure
{'fraction_non_alphanumeric': 0.15313028764805414, 'fraction_numerical': 0.005922165820642978, 'mean_word_length': 2.9212271973466004, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, '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': '951108', 'n_tokens_mistral': 1735, 'n_tokens_neox': 1691, 'n_words': 412}