spec/spec_helper.rb in mina-1.2.4 vs spec/spec_helper.rb in mina-1.2.5

- old
+ new

@@ -1,34 +1,53 @@ +# frozen_string_literal: true + require 'simplecov' -SimpleCov.start +SimpleCov.start do + add_filter '/spec/' -$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) -$LOAD_PATH.unshift(File.dirname(__FILE__)) + enable_coverage :branch + primary_coverage :branch +end require 'mina' require 'rspec' require 'pry' +require 'set' -Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f } +Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each { |f| require f } Rake.application = Mina::Application.new -Dir["./tasks/mina/**/*.rb"].each { |f| require f } +Dir['./tasks/mina/**/*.rb'].sort.each { |f| require f } RSpec.configure do |config| config.include RakeExampleGroup, type: :rake config.raise_errors_for_deprecations! config.order = 'random' - config.before(:all, type: :rake) do - Mina::Configuration.instance.set :simulate, true - Mina::Configuration.instance.set :domain, 'localhost' - Mina::Configuration.instance.set :deploy_to, "#{Dir.pwd}/deploy" - Mina::Configuration.instance.set :repository, "#{Mina.root_path}" - Mina::Configuration.instance.set :shared_paths, ['config/database.yml', 'log'] - Mina::Configuration.instance.set :keep_releases, 2 + initial_task_names = Rake.application.tasks.to_set(&:name) + initial_variables = Mina::Configuration.instance.variables + + config.before do + Mina::Configuration.instance.instance_variable_set(:@variables, initial_variables.clone) end - config.after(:all, type: :rake) do - Mina::Configuration.instance.remove :simulate + config.after do + Rake.application.tasks.each(&:reenable) + Rake.application.instance_variable_get(:@tasks).keep_if { |task_name, _| initial_task_names.include?(task_name) } + end + + config.around(:each, :suppressed_output) do |example| + original_stdout, $stdout = $stdout, File.open(File::NULL, 'w') + original_stderr, $stderr = $stderr, File.open(File::NULL, 'w') + + example.run + + $stdout, $stderr = original_stdout, original_stderr + end + + config.around do |example| + example.run + rescue SystemExit + raise "Unhandled system exit (you're probably missing a raise_error(SystemExit) matcher somewhere)" end end