Module: Autobuild::SelfTest
- Defined in:
- lib/autobuild/test.rb
Overview
This module is the common setup for all tests
It should be included in the toplevel describe blocks
Instance Attribute Summary collapse
-
#tempdir ⇒ Object
readonly
Returns the value of attribute tempdir.
Instance Method Summary collapse
- #build_config(bind, template) ⇒ Object
- #data_dir ⇒ Object
- #make_tmpdir ⇒ Object
- #prepare_and_build_package(package) ⇒ Object
- #setup ⇒ Object
- #teardown ⇒ Object
- #untar(file) ⇒ Object
Instance Attribute Details
#tempdir ⇒ Object (readonly)
Returns the value of attribute tempdir.
76 77 78 |
# File 'lib/autobuild/test.rb', line 76 def tempdir @tempdir end |
Instance Method Details
#build_config(bind, template) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/autobuild/test.rb', line 78 def build_config(bind, template) bind.local_variable_set(:basedir, tempdir.to_s) ryml = File.open(File.join(data_dir, "#{template}.ryml"), &:readlines) .join('') result = ERB.new(ryml).result(bind) yml = File.join(tempdir, "#{template}.yml") File.open(yml, 'w+') { |f| f.write(result) } yml end |
#data_dir ⇒ Object
72 73 74 |
# File 'lib/autobuild/test.rb', line 72 def data_dir File.join(File.dirname(__FILE__), '..', '..', 'test', 'data') end |
#make_tmpdir ⇒ Object
67 68 69 70 |
# File 'lib/autobuild/test.rb', line 67 def make_tmpdir @temp_dirs << (dir = Dir.mktmpdir) dir end |
#prepare_and_build_package(package) ⇒ Object
100 101 102 103 |
# File 'lib/autobuild/test.rb', line 100 def prepare_and_build_package(package) package.prepare Rake::Task["#{package.name}-build"].invoke end |
#setup ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/autobuild/test.rb', line 43 def setup @temp_dirs = Array.new @tempdir = make_tmpdir FileUtils.mkdir_p(@tempdir, mode: 0o700) Autobuild.logdir = "#{tempdir}/log" FileUtils.mkdir_p Autobuild.logdir Autobuild.silent = true # Setup code for all the tests end |
#teardown ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/autobuild/test.rb', line 54 def teardown Autobuild.silent = false super Autobuild::Package.clear Rake::Task.clear Autobuild.reset_gnumake_detection @temp_dirs.each do |dir| FileUtils.rm_rf dir end end |
#untar(file) ⇒ Object
90 91 92 93 94 95 96 97 98 |
# File 'lib/autobuild/test.rb', line 90 def untar(file) file = File.(file, data_dir) dir = tempdir Dir.chdir(dir) do system("tar xf #{file}") end dir end |