Sha256: 7128106093b151db5ad2f320e8e01ec2ecf9f6bf2eb75fcdda49cbce94996e82

Contents?: true

Size: 1.6 KB

Versions: 1

Compression:

Stored size: 1.6 KB

Contents

require 'spec_helper'

describe Rake::Builder::LocalConfig do
  let(:local_config_file) { 'local_config' }
  let(:include_paths) { [] }
  let(:compilation_options) { [] }
  let(:good_config_data) do
    {
      :rake_builder => {
        :config_file => {:version => '1.1'},
      },
      :include_paths => include_paths,
      :compilation_options => compilation_options,
    }
  end
  let(:bad_config_data) do
    config = good_config_data.clone
    config[:rake_builder][:config_file][:version] = '0.1'
    config
  end
  let(:config_data) { good_config_data }

  before { allow(YAML).to receive(:load_file) { config_data } }

  subject { described_class.new(local_config_file) }

  context '#load' do
    let(:include_paths) { ['/foo/bar'] }
    let(:compilation_options) { ['foo', 'bar'] }

    context 'if the version is not recognized' do
      let(:config_data) { bad_config_data }

      it 'fails' do
        expect {
          subject.load
        }.to raise_error(Rake::Builder::Error, /version incorrect/)
      end
    end

    it 'sets the include_paths' do
      subject.load

      expect(subject.include_paths).to eq(include_paths)
    end

    it 'sets compilation_options' do
      subject.load

      expect(subject.compilation_options).to eq(compilation_options)
    end
  end

  context '#save' do
    let(:file) { double(File, write: nil) }
    let(:data) { config_data.to_yaml }

    before do
      allow(File).to receive(:open).with(local_config_file, 'w').and_yield(file)
    end

    it 'writes to the file' do
      subject.save

      expect(file).to have_received(:write).with(data)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rake-builder-0.10.1 spec/unit/rake/builder/local_config_spec.rb