Sha256: c0b82f6644d8e50bb71d8c6bca2b5e3444a15d5ed0f9f72cca91d79fd886db0c

Contents?: true

Size: 2 KB

Versions: 14

Compression:

Stored size: 2 KB

Contents

#          Copyright (c) 2009 Michael Fellinger m.fellinger@gmail.com
# All files in this distribution are subject to the terms of the Ruby license.

require File.expand_path('../../../../lib/ramaze/spec/helper/snippets', __FILE__)
require 'fileutils'


# Mock require to only record attempts
$required = []

module Ramaze
  def self.require(name)
    $required << name
  end
end

describe 'Ramaze::acquire' do
  before do
    dir = 'tmp_dir_for_acquire'
    FileUtils.mkdir_p(dir + '/sub')

    %w[ foo.rb bar.rb baz.so baz.yml sub/baz.rb ].
      each do |path|
      FileUtils.touch("#{dir}/#{path}")
    end

    $required = []
  end

  it 'should not load a single file' do
    Ramaze::acquire 'tmp_dir_for_acquire/foo'
    $required.should == []
  end

  it 'should load dir' do
    Ramaze::acquire 'tmp_dir_for_acquire/sub/*'
    $required.should == %w[
      tmp_dir_for_acquire/sub/baz.rb]
  end

  it 'should be aliased to acquire' do
    Ramaze::acquire 'tmp_dir_for_acquire/sub/*'
    $required.should.not.be.empty
  end

  it 'should load {so,rb}, not others' do
    Ramaze::acquire 'tmp_dir_for_acquire/*'
    $required.sort.should == %w[
      tmp_dir_for_acquire/bar.rb
      tmp_dir_for_acquire/baz.so
      tmp_dir_for_acquire/foo.rb]
  end

  it 'should use globbing' do
    Ramaze::acquire 'tmp_dir_for_acquire/ba*'
    $required.sort.should == %w[
      tmp_dir_for_acquire/bar.rb
      tmp_dir_for_acquire/baz.so]
  end

  it 'should use recursive globbing' do
    Ramaze::acquire 'tmp_dir_for_acquire/**/*'
    $required.sort.should == %w[
      tmp_dir_for_acquire/bar.rb
      tmp_dir_for_acquire/baz.so
      tmp_dir_for_acquire/foo.rb
      tmp_dir_for_acquire/sub/baz.rb]
  end

  it 'should accept multiple arguments' do
    Ramaze::acquire 'tmp_dir_for_acquire/*', 'tmp_dir_for_acquire/sub/*'
    $required.sort.should == %w[
      tmp_dir_for_acquire/bar.rb
      tmp_dir_for_acquire/baz.so
      tmp_dir_for_acquire/foo.rb
      tmp_dir_for_acquire/sub/baz.rb]
  end

  FileUtils.rm_rf('tmp_dir_for_acquire')
end

Version data entries

14 entries across 14 versions & 3 rubygems

Version Path
Pistos-ramaze-2009.06.12 spec/snippets/ramaze/acquire.rb
manveru-ramaze-2009.07 spec/snippets/ramaze/acquire.rb
ramaze-2011.12.28 spec/snippets/ramaze/acquire.rb
ramaze-2011.10.23 spec/snippets/ramaze/acquire.rb
ramaze-2011.07.25 spec/snippets/ramaze/acquire.rb
ramaze-2011.01.30 spec/snippets/ramaze/acquire.rb
ramaze-2011.01 spec/snippets/ramaze/acquire.rb
ramaze-2010.06.18 spec/snippets/ramaze/acquire.rb
ramaze-2010.04.04 spec/snippets/ramaze/acquire.rb
ramaze-2010.04 spec/snippets/ramaze/acquire.rb
ramaze-2010.03 spec/snippets/ramaze/acquire.rb
ramaze-2010.01 spec/snippets/ramaze/acquire.rb
ramaze-2009.10 spec/snippets/ramaze/acquire.rb
ramaze-2009.07 spec/snippets/ramaze/acquire.rb