Sha256: 015604b521b62e18bd7fc98a1a3e89a3e3471b073f11a30884a0ab9b1d27f40c

Contents?: true

Size: 1.38 KB

Versions: 9

Compression:

Stored size: 1.38 KB

Contents

require 'spec_helper'
require 'ronin/extensions/file'

require 'tempfile'

describe File do
  subject { File }

  it "should provide File.escape_path" do
    subject.should respond_to(:escape_path)
  end

  describe "each_line" do
    let(:lines) { %w[one two three] }

    before(:all) do
      @file = Tempfile.new('ronin-support')
      @file.puts(*lines)
      @file.close
    end

    it "should enumerate over each line in the file" do
      File.each_line(@file.path).to_a.should == lines
    end
  end

  describe "each_row" do
    let(:rows) do
      [
        %w[one two three],
        %w[four five six]
      ]
    end

    let(:separator) { '|' }
    let(:newline)   { "\r\n" }
    let(:lines)     { rows.map { |row| row.join(separator) }.join(newline) }

    before(:all) do
      @file = Tempfile.new('ronin-support')
      @file.write(lines)
      @file.close
    end

    it "should enumerate over each row from each line" do
      File.each_row(@file.path,separator).to_a.should == rows
    end
  end

  describe "escape_path" do
    it "should remove null-bytes" do
      File.escape_path("hello\0world\0").should == "helloworld"
    end

    it "should escape home-dir expansions" do
      File.escape_path("hello/~world").should == "hello/\\~world"
    end

    it "should remove '.' and '..' directories" do
      File.escape_path("hello/./../world").should == "world"
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
ronin-support-0.5.1 spec/extensions/file_spec.rb
ronin-support-0.5.0 spec/extensions/file_spec.rb
ronin-support-0.5.0.rc2 spec/extensions/file_spec.rb
ronin-support-0.5.0.rc1 spec/extensions/file_spec.rb
ronin-support-0.4.1 spec/extensions/file_spec.rb
ronin-support-0.4.0 spec/extensions/file_spec.rb
ronin-support-0.4.0.rc2 spec/extensions/file_spec.rb
ronin-support-0.4.0.rc1 spec/extensions/file_spec.rb
ronin-support-0.3.0 spec/extensions/file_spec.rb