Method: PuppetDockerTools::Runner#spec

Defined in:
lib/puppet_docker_tools/runner.rb

#spec(image: nil) ⇒ Object

Run spec tests



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/puppet_docker_tools/runner.rb', line 183

def spec(image: nil)
  if image
    fail 'Oh no! You have PUPPET_TEST_DOCKER_IMAGE set! Please unset!' if ENV['PUPPET_TEST_DOCKER_IMAGE']
    ENV['PUPPET_TEST_DOCKER_IMAGE'] = image
  end

  tests = Dir.glob(File.join(directory,'spec','*_spec.rb'))
  test_files = tests.map { |test| File.basename(test, '.rb') }

  puts "Running RSpec tests from #{File.expand_path(File.join(directory,'spec'))} (#{test_files.join ","}), this may take some time"
  success = true
  tests.each do |test|
    Open3.popen2e('rspec', 'spec', test) do |stdin, output_stream, wait_thread|
      output_stream.each_line do |line|
        puts line
      end
      exit_status = wait_thread.value.exitstatus
      success = success && (exit_status == 0)
    end
  end

  if image
    ENV['PUPPET_TEST_DOCKER_IMAGE'] = nil
  end

  fail "Running RSpec tests for #{directory} failed!" unless success
end