require 'fileutils' describe Rscons do before(:all) do FileUtils.rm_rf('build_tests_run') @owd = Dir.pwd end after(:each) do Dir.chdir(@owd) FileUtils.rm_rf('build_tests_run') end def build_testdir if File.exists?("build.rb") system("ruby -I #{@owd}/lib -r rscons build.rb > build.out") end end def test_dir(build_test_directory) FileUtils.cp_r("build_tests/#{build_test_directory}", 'build_tests_run') Dir.chdir("build_tests_run") build_testdir end def file_sub(fname) contents = File.read(fname) replaced = '' contents.each_line do |line| replaced += yield(line) end File.open(fname, 'w') do |fh| fh.write(replaced) end end ########################################################################### # Tests ########################################################################### it 'builds a C program with one source file' do test_dir('simple') File.exists?('simple.o').should be_true `./simple`.should == "This is a simple C program\n" end it 'prints commands as they are executed' do test_dir('simple') File.read('build.out').should == <