Sha256: 3a969b714b41917b3688a78356092aa4eb30f3babb5be2186b7c67dde2f5e4f4

Contents?: true

Size: 1.45 KB

Versions: 1

Compression:

Stored size: 1.45 KB

Contents

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

require 'tempfile'

describe File do
  subject { File }

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

  describe "each_line" do
    let(:lines) { %w[one two three] }
    let(:path)  { Tempfile.new('ronin-support-File#each_line') }

    before do
      File.open(path,'w') { |file| file.puts(*lines) }
    end

    it "should enumerate over each line in the file" do
      expect(File.each_line(path).to_a).to eq(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) }
    let(:path)      { Tempfile.new('ronin-support-File#each_row') }

    before do
      File.open(path,'w') { |file| file.puts(*lines) }
    end

    it "should enumerate over each row from each line" do
      expect(File.each_row(path,separator).to_a).to eq(rows)
    end
  end

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

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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ronin-support-0.5.2 spec/extensions/file_spec.rb