Sha256: b5c337d32b1001f7a8125650cfca1543f70ab24c98eea83aa159309d691b94ad

Contents?: true

Size: 1.82 KB

Versions: 3

Compression:

Stored size: 1.82 KB

Contents

require 'spec_helper'

describe Rake::Builder::LocalConfig do
  let(:local_config_file) { 'local_config' }
  let(:include_paths) { ['/foo/bar'] }
  let(:compilation_options) { ['foo', 'bar'] }
  let(: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_data[:rake_builder][:config_file][:version] = '0.1'
    config_data
  end

  before { YAML.stub(:load_file).and_return(config_data) }

  subject { Rake::Builder::LocalConfig.new(local_config_file) }

  context '#load' do
    it 'loads the file' do
      YAML.should_receive(:load_file).and_return(config_data)

      subject.load
    end

    it 'fails if the version is not recognized' do
      YAML.should_receive(:load_file).and_return(bad_config_data)

      expect {
        subject.load
      }.to raise_error(Rake::Builder::Error, /version incorrect/)
    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) { stub('File') }

    before do
      File.stub(:open).with(local_config_file, 'w') do |&block|
        block.call file
      end
    end

    it 'write to the file' do
      File.should_receive(:open).with(local_config_file, 'w') {}

      subject.save
    end

    it 'saves the data' do
      expected = {
        :rake_builder        => {:config_file => {:version => '1.1'}},
        :include_paths       => [],
        :compilation_options => []
      }.to_yaml
      file.should_receive(:write).with(expected)

      subject.save
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rake-builder-0.9.2 spec/unit/rake/builder/local_config_spec.rb
rake-builder-0.9.1 spec/unit/rake/builder/local_config_spec.rb
rake-builder-0.9.0 spec/unit/rake/builder/local_config_spec.rb