diff --git a/middleman-core/spec/spec_helper.rb b/middleman-core/spec/spec_helper.rb index 4e363fc6..c7b3d141 100644 --- a/middleman-core/spec/spec_helper.rb +++ b/middleman-core/spec/spec_helper.rb @@ -12,6 +12,8 @@ RSpec.configure do |config| config.include Aruba::Api end +require_relative 'support/given' + # encoding: utf-8 RSpec.configure do |config| config.filter_run :focus diff --git a/middleman-core/spec/support/given.rb b/middleman-core/spec/support/given.rb new file mode 100644 index 00000000..499fcb78 --- /dev/null +++ b/middleman-core/spec/support/given.rb @@ -0,0 +1,42 @@ +module Given + ROOT = File.expand_path( '../..', File.dirname( File.realpath(__FILE__) ) ) + TMP = File.join( ROOT, 'tmp' ) + + class << self + + def fixture name + cleanup! + + `rsync -av #{File.join( ROOT, 'fixtures', name )}/ #{TMP}/` + Dir.chdir TMP + ENV['MM_ROOT'] = TMP + end + + def no_file name + FileUtils.rm name, force: true + end + + def symlink source, destination + no_file destination + FileUtils.symlink File.expand_path(source), + File.expand_path(destination), + force: true + end + + def file name, content + file_path = File.join( TMP, name ) + FileUtils.mkdir_p( File.dirname(file_path) ) + File.open( file_path, 'w' ) do |file| + file.write content + end + end + + def cleanup! + Dir.chdir ROOT + if File.exist? TMP + `rm -rf #{TMP}` + end + end + + end +end