Sha256: 5fb17eeb16acc65d352d3107c809f83bcfd848e763ecfdbd43f18c23b4a20f4e

Contents?: true

Size: 1.88 KB

Versions: 4

Compression:

Stored size: 1.88 KB

Contents

require 'spec_helper'
require 'smilodon/fakes'

describe Smilodon::Populator, 'DIRECTORY' do
  it 'should be set to the default directory' do
    Smilodon::Populator::DIRECTORY.should == 'files'
  end
end

describe FakePopulator, '.directory' do
  context 'when no directory is configured' do
    it 'should return the default directory' do
      FakePopulator.directory.should == Smilodon::Populator::DIRECTORY
    end
  end

  context 'when the directory is configured' do
    it 'should return the configured directory' do
      FakePopulatorWithOverriddenDirectory.directory.should == 'db/populate/files'
    end
  end
end

describe FakePopulator, '.file' do
  it 'should return the configured file name' do
    FakePopulator.files.should == ['TestFile']
  end
end

describe FakePopulator, '.type' do
  context 'when no file type is configured' do
    it 'should return the default file type' do
      FakePopulator.type.should == 'csv'
    end
  end

  context 'when the file type is configured' do
    it 'should return the configured file type' do
      FakePopulatorWithOverriddenType.type.should == 'excel'
    end
  end
end

describe FakePopulator, '.process(row)' do
  it 'should raise an exception with a message to define the method in the extended populator class' do
    lambda {
      FakePopulator.process
    }.should raise_exception(MethodNotOverridden)
  end
end

describe FakePopulator, '.files' do
  it 'should return the configured file names' do
    FakePopulatorWithMultipleFiles.files.should == ['TestFile1', 'TestFile2', 'TestFile3']
  end

  it 'should handle an options hash' do
    FakePopulatorWithMultipleFiles.directory.should == 'db/populate/files'
  end

  it 'calls read for each file passed to populate' do
    FakePopulatorWithMultipleFiles.files.each { |f| FakePopulatorWithMultipleFiles.should_receive(:read).with(f).and_return('') }
    FakePopulatorWithMultipleFiles.run
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
smilodon-0.2.6 spec/lib/smilodon_spec.rb
smilodon-0.2.5 spec/lib/smilodon_spec.rb
smilodon-0.2.4 spec/lib/smilodon_spec.rb
smilodon-0.2.3 spec/lib/smilodon_spec.rb