features/support/env.rb in berkshelf-2.0.18 vs features/support/env.rb in berkshelf-3.0.0.beta1

- old
+ new

@@ -1,78 +1,73 @@ -require 'rubygems' -require 'bundler' require 'spork' Spork.prefork do - require 'rspec' - require 'pp' require 'aruba/cucumber' + require 'aruba/in_process' + require 'aruba/spawn_process' + require 'cucumber/rspec/doubles' + require 'berkshelf/api/rspec' + require 'berkshelf/api/cucumber' - APP_ROOT = File.expand_path('../../../', __FILE__) + Dir['spec/support/**/*.rb'].each { |f| require File.expand_path(f) } - ENV['RUBY_ENV'] = 'test' - ENV['BERKSHELF_PATH'] = File.join(APP_ROOT, 'tmp', 'berkshelf') - ENV['BERKSHELF_CHEF_CONFIG'] = File.join(APP_ROOT, 'spec', 'config', 'knife.rb') + World(Berkshelf::RSpec::PathHelpers) + World(Berkshelf::RSpec::Kitchen) - # Workaround for RSA Fingerprint prompt in Travis CI - git_ssh_path = '/tmp/git_ssh.sh' - unless File.exist? git_ssh_path - git_ssh = File.new(git_ssh_path, 'w+') - git_ssh.puts 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $1 $2' - git_ssh.chmod 0775 - git_ssh.flush - git_ssh.close + CHEF_SERVER_PORT = 26310 + BERKS_API_PORT = 26210 + + at_exit do + Berkshelf::RSpec::ChefServer.stop + Berkshelf::API::RSpec::Server.stop end - ENV['GIT_SSH'] = git_ssh_path - - Dir[File.join(APP_ROOT, 'spec/support/**/*.rb')].each {|f| require f} - - World(Berkshelf::TestGenerators) - Before do - set_env 'RUBY_ENV', 'test' - clean_cookbook_store - generate_berks_config(File.join(ENV['BERKSHELF_PATH'], 'config.json')) - @aruba_io_wait_seconds = 5 - @aruba_timeout_seconds = 30 - end + # Legacy ENV variables until we can move over to all InProcess + ENV['BERKSHELF_PATH'] = berkshelf_path.to_s + ENV['BERKSHELF_CONFIG'] = Berkshelf.config.path.to_s + ENV['BERKSHELF_CHEF_CONFIG'] = chef_config_path.to_s - Before('@slow_process') do - @aruba_timeout_seconds = 60 - @aruba_io_wait_seconds = 30 - end + Aruba::InProcess.main_class = Berkshelf::Cli::Runner + Aruba.process = Aruba::InProcess - # Chef Zero - require 'chef_zero/server' - @server = ChefZero::Server.new(port: 4000, generate_real_keys: false) - @server.start_background + stub_kitchen! + clean_tmp_path + Berkshelf.initialize_filesystem + Berkshelf::CookbookStore.instance.initialize_filesystem + reload_configs - at_exit do - @server.stop if @server && @server.running? - end + endpoints = [ + { + type: "chef_server", + options: { + url: "http://localhost:#{CHEF_SERVER_PORT}", + client_name: "reset", + client_key: fixtures_path.join("reset.pem") + } + } + ] - def cookbook_store - Pathname.new(File.join(ENV['BERKSHELF_PATH'], 'cookbooks')) - end + Berkshelf::RSpec::ChefServer.start(port: CHEF_SERVER_PORT) + Berkshelf::API::RSpec::Server.start(port: BERKS_API_PORT, endpoints: endpoints) - def clean_cookbook_store - FileUtils.rm_rf(cookbook_store) - FileUtils.mkdir_p(cookbook_store) + @aruba_io_wait_seconds = Cucumber::JRUBY ? 7 : 5 + @aruba_timeout_seconds = Cucumber::JRUBY ? 35 : 15 end - def app_root_path - Pathname.new(APP_ROOT) - end + Before('@spawn') do + Aruba.process = Aruba::SpawnProcess - def tmp_path - app_root_path.join('spec/tmp') + set_env('BERKSHELF_PATH', berkshelf_path.to_s) + set_env('BERKSHELF_CONFIG', Berkshelf.config.path.to_s) + set_env('BERKSHELF_CHEF_CONFIG', chef_config_path.to_s) end - def fixtures_path - app_root_path.join('spec/fixtures') + Before('@slow_process') do + @aruba_io_wait_seconds = Cucumber::JRUBY ? 70 : 30 + @aruba_timeout_seconds = Cucumber::JRUBY ? 140 : 60 end end Spork.each_run do - require 'berkshelf' + require 'berkshelf/cli' end