Sha256: e0f5e4e9c6b164b23e2712288909e09e42f37e085a56154bdbaf33268977aff7

Contents?: true

Size: 1.88 KB

Versions: 1

Compression:

Stored size: 1.88 KB

Contents

require 'spec_helper'
require 'bukin'
require 'fakefs/safe'
require 'yaml'

describe Bukin::Lockfile do

  before(:each) {File.delete(PATH) if File.exist?(PATH)}
  after(:all) {FakeFS.deactivate!}
  before(:all) do
    FakeFS.activate!
    PATH = File.join(Dir.pwd, Bukin::Lockfile::FILE_NAME)
  end

  it 'assignes a default path if none is provided' do
    lockfile = Bukin::Lockfile.new
    lockfile.path.should == PATH
  end

  it 'assignes the path provided in the constructor' do
    lockfile = Bukin::Lockfile.new('/test/path')
    lockfile.path.should == '/test/path'
  end

  it 'loads no resources for an empty or missing file' do
    lockfile = Bukin::Lockfile.new('/non/existant/path')
    lockfile.resources.should == {}
  end

  it 'loads resources from an already existing lockfile' do
    resources = { 'resources' => 'value' }

    File.open(PATH, 'w') {|file| file.write resources.to_yaml}

    lockfile = Bukin::Lockfile.new
    lockfile.resources.should == 'value'
  end

  it 'saves resources to a lockfile' do
    lockfile = Bukin::Lockfile.new
    lockfile.add({
      :name => 'resource_name',
      :version => '1.0.0',
      :files => ['file']
    })
    lockfile.save

    path = File.join
    data = YAML::load_file(PATH)
    data.should == {
      'resources' => {
        'resource_name' => {
          'version' => '1.0.0',
          'files' => ['file']
        }
      }
    }

    File.delete(PATH)
    lockfile = Bukin::Lockfile.new
    lockfile.resources.should == {}
  end

  it 'adds resources to the lockfile' do
    lockfile = Bukin::Lockfile.new
    lockfile.resources.count.should == 0
    lockfile.add({
      :name => 'resource_name',
      :version => '1.0.0',
      :files => ['file1', 'file2']
    })
    lockfile.resources.count.should == 1
    lockfile.resources['resource_name'].should == {
      'version' => '1.0.0', 
      'files' => ['file1', 'file2']
    }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bukin-0.6.0 spec/lockfile_spec.rb