Skip to content

Commit

Permalink
Add specs for #get_local_files
Browse files Browse the repository at this point in the history
  • Loading branch information
obrie committed Aug 28, 2024
1 parent 26c45ed commit 923417f
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions spec/unit/storage_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require File.dirname(__FILE__) + '/../spec_helper'
require 'fileutils'

describe AssetSync::Storage do
include_context "mock Rails without_yml"
Expand Down Expand Up @@ -450,4 +451,52 @@ def check_file(file)
end
end
end

describe '#get_local_files' do
around(:each) do |example|
Dir.mktmpdir do |public_path|
@public_path = public_path
example.call
end
end

before(:each) do
@config = AssetSync::Config.new
@config.public_path = @public_path
@config.prefix = 'assets'
@storage = AssetSync::Storage.new(@config)

Dir.mkdir("#{@public_path}/assets")
end

context 'with empty directory' do
it 'has no files' do
expect(@storage.get_local_files).to eq([])
end
end

context 'with non-empty directory' do
before(:each) do
FileUtils.touch("#{@public_path}/assets/application.js")
end

it 'lists available files' do
expect(@storage.get_local_files).to eq([
'assets/application.js'
])
end

context 'with trailing slash on asset prefix' do
before(:each) do
@config.prefix = 'assets/'
end

it 'lists available files with single slashes' do
expect(@storage.get_local_files).to eq([
'assets/application.js'
])
end
end
end
end
end

0 comments on commit 923417f

Please sign in to comment.