feat(testing): add a fixture/file helper for rspec tests
This commit is contained in:
parent
37d96a9b14
commit
f16fc2229e
|
@ -12,6 +12,8 @@ RSpec.configure do |config|
|
||||||
config.include Aruba::Api
|
config.include Aruba::Api
|
||||||
end
|
end
|
||||||
|
|
||||||
|
require_relative 'support/given'
|
||||||
|
|
||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
config.filter_run :focus
|
config.filter_run :focus
|
||||||
|
|
42
middleman-core/spec/support/given.rb
Normal file
42
middleman-core/spec/support/given.rb
Normal file
|
@ -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
|
Loading…
Reference in a new issue