Sha256: a7b5c66411060491dc625152cda3170309df0d1044bf6c2128c9fc0375028b96

Contents?: true

Size: 1.89 KB

Versions: 3

Compression:

Stored size: 1.89 KB

Contents

require File.expand_path(File.join(File.dirname(__FILE__), "../spec_helper"))
describe WebResourceBundler::FileManager do

  def create_stub_file(name)
    File.open(File.join(@settings[:resource_dir], name), "w") do |file|
      file.print "hi there"
    end
  end

  before(:each) do
    @settings = settings
    temp_dir = File.join(@settings[:resource_dir], 'temp')
    Dir.mkdir(temp_dir) unless File.exist?(temp_dir)
    @bundle_url = 'temp/bundle.dat'
    @bundle_path = File.join(@settings[:resource_dir], @bundle_url)
    create_stub_file(@bundle_url)
    @manager = FileManager.new(@settings)
  end

  after(:each) do
    FileUtils.rm_rf(File.join(@settings[:resource_dir], 'temp'))
  end

  describe "#create_cache_dir" do
    it "creates cache dir if it doesn't exists" do
      dir_path = File.join(@settings[:resource_dir], @settings[:cache_dir])
      FileUtils.rm_rf(dir_path)
      @manager.create_cache_dir
      File.exist?(dir_path).should == true
    end
  end

  describe "#set_settings" do
    it "should set new settings in file manager" do
      @manager.resource_dir.should == @settings[:resource_dir]
      @manager.cache_dir.should == @settings[:cache_dir]
      @manager.set_settings({:resource_dir => 'A', :cache_dir => 'B'})
      @manager.resource_dir.should == 'A'
      @manager.cache_dir.should == 'B' 
    end
  end

  describe "#get_content" do
    it "reads file and returns its content" do
      @manager.get_content(@bundle_url).should == 'hi there'
    end
  end

  describe "#full_path" do

    it "returns full path using file url" do
      @manager.full_path(@bundle_url).should == @bundle_path 
    end

  end

  describe "#exist?" do

    it "returns false when no such file in resource dir" do
      @manager.exist?("non_existent_file.data").should == false
    end

    it "return true when file exists in resource dir" do
      @manager.exist?(@bundle_url).should == true
    end
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
web_resource_bundler-0.0.23 spec/web_resource_bundler/file_manager_spec.rb
web_resource_bundler-0.0.22 spec/web_resource_bundler/file_manager_spec.rb
web_resource_bundler-0.0.21 spec/web_resource_bundler/file_manager_spec.rb