Class: BarkingIguana::Compound::Test
- Inherits:
-
Object
- Object
- BarkingIguana::Compound::Test
- Extended by:
- Forwardable
- Includes:
- Benchmark, Logging::Helper
- Defined in:
- lib/barking_iguana/compound/test.rb
Instance Attribute Summary collapse
-
#directory ⇒ Object
readonly
Returns the value of attribute directory.
-
#suite ⇒ Object
readonly
Returns the value of attribute suite.
Instance Method Summary collapse
- #custom_teardown? ⇒ Boolean
- #custom_teardown_file ⇒ Object
- #driver_options ⇒ Object
- #environment ⇒ Object
- #environment_file ⇒ Object
- #host_manager ⇒ Object
-
#initialize(suite, directory) ⇒ Test
constructor
A new instance of Test.
- #name ⇒ Object
- #run ⇒ Object
- #stages ⇒ Object
- #teardown ⇒ Object
- #test_file_with_fallback(file_name) ⇒ Object
- #vagrant_file_template_path ⇒ Object
Constructor Details
#initialize(suite, directory) ⇒ Test
15 16 17 18 |
# File 'lib/barking_iguana/compound/test.rb', line 15 def initialize suite, directory self.suite = suite self.directory = directory end |
Instance Attribute Details
#directory ⇒ Object
Returns the value of attribute directory.
9 10 11 |
# File 'lib/barking_iguana/compound/test.rb', line 9 def directory @directory end |
#suite ⇒ Object
Returns the value of attribute suite.
6 7 8 |
# File 'lib/barking_iguana/compound/test.rb', line 6 def suite @suite end |
Instance Method Details
#custom_teardown? ⇒ Boolean
52 53 54 |
# File 'lib/barking_iguana/compound/test.rb', line 52 def custom_teardown? File.exists? custom_teardown_file end |
#custom_teardown_file ⇒ Object
56 57 58 |
# File 'lib/barking_iguana/compound/test.rb', line 56 def custom_teardown_file File. "teardown.sh", directory end |
#driver_options ⇒ Object
80 81 82 83 84 85 86 87 |
# File 'lib/barking_iguana/compound/test.rb', line 80 def = {} logger.debug { "Does #{vagrant_file_template_path} exist? -> #{File.exists? vagrant_file_template_path}" } [:vagrant_file_template_path] = vagrant_file_template_path if File.exists? vagrant_file_template_path [:root] = directory [:environment] = suite.environment.merge environment end |
#environment ⇒ Object
93 94 95 |
# File 'lib/barking_iguana/compound/test.rb', line 93 def environment @environment ||= Environment.new(environment_file) end |
#environment_file ⇒ Object
89 90 91 |
# File 'lib/barking_iguana/compound/test.rb', line 89 def environment_file File.join directory, 'env' end |
#host_manager ⇒ Object
60 61 62 63 64 65 |
# File 'lib/barking_iguana/compound/test.rb', line 60 def host_manager @host_manger ||= begin hosts = stages.map(&:hosts).flatten.uniq.sort HostManager.new(hosts, ) end end |
#name ⇒ Object
20 21 22 |
# File 'lib/barking_iguana/compound/test.rb', line 20 def name directory.sub(suite.directory + '/', '').tr('/', ':') end |
#run ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/barking_iguana/compound/test.rb', line 28 def run benchmark "test #{name}" do begin logger.debug { "#{name}: found #{stages.size} stages: #{stages.map(&:name).map(&:inspect).join(', ')}" } stages.each &:run ensure teardown end end end |
#stages ⇒ Object
24 25 26 |
# File 'lib/barking_iguana/compound/test.rb', line 24 def stages Dir[directory + '/*'].select { |d| File.directory? d }.map { |s| TestStage.new self, File.basename(s) } end |
#teardown ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/barking_iguana/compound/test.rb', line 39 def teardown benchmark "#{name}: destroying all hosts" do host_manager.destroy_all end return unless custom_teardown? command_line = "bash -ex #{custom_teardown_file}" c = Mixlib::ShellOut.new command_line, cwd: directory, live_stream: logger benchmark "#{name}: running custom teardown" do c.run_command end c.error! end |
#test_file_with_fallback(file_name) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/barking_iguana/compound/test.rb', line 67 def test_file_with_fallback file_name logger.debug { "Searching for #{file_name.inspect}" } test_file = File. file_name, directory logger.debug { "Checking #{test_file.inspect}" } if File.exists? test_file logger.debug { "Found #{file_name.inspect} at #{test_file.inspect}" } return test_file end suite_file = File. file_name, suite.directory logger.debug { "Assuming it'll be at #{suite_file.inspect}" } suite_file end |
#vagrant_file_template_path ⇒ Object
97 98 99 |
# File 'lib/barking_iguana/compound/test.rb', line 97 def vagrant_file_template_path test_file_with_fallback 'Vagrantfile.erb' end |