Sha256: 715bb9c5ae91c0e6184acb8d206e42aed7fbde594a3b4d695d4578685183ae65

Contents?: true

Size: 1.72 KB

Versions: 1

Compression:

Stored size: 1.72 KB

Contents

require 'spec_helper'
require 'file_classify'

BINARY_FILE = 'spec/resources/binary.jpg'
ASCII_FILE = 'spec/resources/ascii.txt'

describe FileClassify do
  let :binary_contents_subject do
    FileClassify.new(contents: File.read(BINARY_FILE))
  end

  let :binary_path_subject do
    FileClassify.new(path: BINARY_FILE)
  end

  let :ascii_contents_subject do
    FileClassify.new(contents: File.read(ASCII_FILE))
  end

  let :ascii_path_subject do
    FileClassify.new(path: ASCII_FILE)
  end

  context '#initialize' do
    it 'path' do
      fc = FileClassify.new(path: BINARY_FILE)
      fc.path.should == BINARY_FILE
    end

    it 'contents' do
      fc = FileClassify.new(contents: File.read(BINARY_FILE))
      fc.contents.should == File.read(BINARY_FILE)
    end

    it 'no args' do
      expect { FileClassify.new }.to raise_error(ArgumentError)
    end
  end

  context '#classify' do
    it 'binary' do
      binary_contents_subject.classify.should == 'binary'
      binary_path_subject.classify.should == 'binary'
    end

    it 'ascii' do
      ascii_contents_subject.classify.should == 'ascii'
      ascii_path_subject.classify.should == 'ascii'
    end
  end

  context '#binary?' do
    it 'binary' do
      binary_contents_subject.binary?.should be_true
      binary_path_subject.binary?.should be_true
    end

    it 'ascii' do
      ascii_contents_subject.binary?.should be_false
      ascii_path_subject.binary?.should be_false
    end
  end

  context '#ascii?' do
    it 'ascii' do
      ascii_contents_subject.ascii?.should be_true
      ascii_path_subject.ascii?.should be_true
    end

    it 'binary' do
      binary_contents_subject.ascii?.should be_false
      binary_path_subject.ascii?.should be_false
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
file_classify-0.0.1 spec/lib/file_classify_spec.rb