Sha256: d637841d8bde32c09e1b8b89c14fe8f864a0a04a88569369e86c12441bae2f07

Contents?: true

Size: 1.58 KB

Versions: 4

Compression:

Stored size: 1.58 KB

Contents

require "spec_helper"

describe Storage::Strategies::FileSystem do
  before do
    @source = RESOURCES.join("file.txt")
    @destiny = TMP.join("lorem.txt")

    Storage.setup do |c|
      c.strategy = :file
      c.path = TMP
    end
  end

  it "should save a file using file handler" do
    handler = File.open(@source)
    Storage.store(handler, :name => "lorem.txt")

    expect(File).to be_file(@destiny)
    expect(File.read(@destiny)).to eq(File.read(@source))
  end

  it "should save a file using a path" do
    Storage.store(@source, :name => "lorem.txt")

    expect(File).to be_file(@destiny)
    expect(File.read(@destiny)).to eq(File.read(@source))
  end

  it "should remove an existing file" do
    Storage.store(@source, :name => "lorem.txt")
    expect(Storage.remove("lorem.txt")).to be_truthy
    expect(File).not_to be_file(@destiny)
  end

  it "should raise when trying to removing an unexesting file" do
    expect {
      Storage.remove("invalid")
    }.to raise_error(Storage::MissingFileError)
  end

  it "should retrieve an existing file" do
    Storage.store(@source, :name => "lorem.txt")
    expect(Storage.get("lorem.txt")).to eq(File.expand_path(TMP.join("lorem.txt")))
  end

  it "should raise when trying to retrieve an unexesting file" do
    expect {
      Storage.get("invalid")
    }.to raise_error(Storage::MissingFileError)
  end

  it "should raise when saving a file that already exists" do
    Storage.store(@source, :name => "lorem.txt")

    expect {
      Storage.store(@source, :name => "lorem.txt")
    }.to raise_error(Storage::FileAlreadyExistsError)
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
storage-0.3.2 spec/storage/strategies/file_system_spec.rb
storage-0.3.1 spec/storage/strategies/file_system_spec.rb
storage-0.3.0 spec/storage/strategies/file_system_spec.rb
storage-0.2.0 spec/storage/strategies/file_system_spec.rb