Sha256: 35342896da76e25ab8fe56dba71a42d06c208832957cd882191ebad9563ca24c

Contents?: true

Size: 1.84 KB

Versions: 4

Compression:

Stored size: 1.84 KB

Contents

require "#{File.dirname(__FILE__)}/spec_setup"
require 'rack/cache/config'

class MockConfig
  include Rack::Cache::Config
  def configured!
    @configured = true
  end
  def configured?
    @configured
  end
end

describe 'Rack::Cache::Config' do
  before :each do
    @config = MockConfig.new
    @tempdir = create_temp_directory
    $:.unshift @tempdir
  end
  after :each do
    @config = nil
    $:.shift if $:.first == @tempdir
    remove_entry_secure @tempdir
  end

  def make_temp_file(filename, data='configured!')
    create_temp_file @tempdir, filename, data
  end

  it 'loads config files from the load path when file is relative' do
    make_temp_file 'foo/bar.rb'
    @config.import 'foo/bar.rb'
    @config.should.be.configured
  end
  it 'assumes a .rb file extension when no file extension exists' do
    make_temp_file 'foo/bar.rb'
    @config.import 'foo/bar'
    @config.should.be.configured
  end
  it 'does not assume a .rb file extension when other file extension exists' do
    make_temp_file 'foo/bar.conf'
    @config.import 'foo/bar.conf'
    @config.should.be.configured
  end
  it 'should locate files with absolute path names' do
    make_temp_file 'foo/bar.rb'
    @config.import File.join(@tempdir, 'foo/bar.rb')
    @config.should.be.configured
  end
  it 'raises a LoadError when the file cannot be found' do
    assert_raises(LoadError) {
      @config.import('this/file/is/very-likely/not/to/exist.rb')
    }
  end
  it 'executes within the context of the object instance' do
    make_temp_file 'foo/bar.rb',
      'self.should.be.kind_of Rack::Cache::Config ; configured!'
    @config.import 'foo/bar'
    @config.should.be.configured
  end
  it 'does not import files more than once' do
    make_temp_file 'foo/bar.rb', "import 'foo/bar'"
    @config.import('foo/bar').should.be true
    @config.import('foo/bar').should.be false
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
rtomayko-rack-cache-0.2.0 test/config_test.rb
rtomayko-rack-cache-0.3.0 test/config_test.rb
rack-cache-0.3.0 test/config_test.rb
rack-cache-0.2.0 test/config_test.rb