spec: Fix some rubocop violations (#2011)

This commit is contained in:
jcrew99
2022-01-23 22:49:44 +10:00
committed by GitHub
parent 01c3413687
commit 29e025bbfc
7 changed files with 36 additions and 54 deletions

View File

@@ -1,12 +1,10 @@
require 'core/loader.rb'
# Notes
# We need to load vairables that 'beef' usually does for us
## config
# @note We need to load variables that 'beef' usually does for us
# @todo review this config (this isn't used or is shadowed by the monkey patching, needs a further look to fix properly)
config = BeEF::Core::Configuration.new('config.yaml')
## home_dir
$home_dir = Dir.pwd
## root_dir
$root_dir = Dir.pwd
require 'core/bootstrap.rb'
@@ -31,9 +29,7 @@ ARGV = []
# Monkey patch to avoid reset sessions
class Capybara::Selenium::Driver < Capybara::Driver::Base
def reset!
if @browser
@browser.navigate.to('about:blank')
end
@browser.navigate.to('about:blank') if @browser
end
end
@@ -47,17 +43,16 @@ CONFIG['key'] = ENV['BROWSERSTACK_ACCESS_KEY'] || ''
## DB config
ActiveRecord::Base.logger = nil
OTR::ActiveRecord.migrations_paths = [File.join('core', 'main', 'ar-migrations')]
OTR::ActiveRecord.configure_from_hash!(adapter:'sqlite3', database:':memory:')
# otr-activerecord require you to manually establish the connection with the following line
#Also a check to confirm that the correct Gem version is installed to require it, likely easier for old systems.
OTR::ActiveRecord.configure_from_hash!(adapter: 'sqlite3', database: ':memory:')
# otr-activerecord requires manually establishing the connection with the following line
# Also a check to confirm that the correct Gem version is installed to require it, likely easier for old systems.
if Gem.loaded_specs['otr-activerecord'].version > Gem::Version.create('1.4.2')
OTR::ActiveRecord.establish_connection!
end
ActiveRecord::Schema.verbose = false
context = ActiveRecord::Migration.new.migration_context
if context.needs_migration?
ActiveRecord::Migrator.new(:up, context.migrations, context.schema_migration).migrate
end
ActiveRecord::Migrator.new(:up, context.migrations, context.schema_migration).migrate if context.needs_migration?
RSpec.configure do |config|
config.disable_monkey_patching!
@@ -76,18 +71,16 @@ RSpec.configure do |config|
end
def server_teardown(webdriver, server_pid, server_pids)
begin
webdriver.quit
rescue => exception
print_info "Exception: #{exception}"
print_info "Exception Class: #{exception.class}"
print_info "Exception Message: #{exception.message}"
print_info "Exception Stack Trace: #{exception.backtrace}"
exit 0
ensure
print_info "Shutting down server"
Process.kill("KILL", server_pid)
Process.kill("KILL", server_pids)
end
webdriver.quit
rescue StandardError => e
print_info "Exception: #{e}"
print_info "Exception Class: #{e.class}"
print_info "Exception Message: #{e.message}"
print_info "Exception Stack Trace: #{e.backtrace}"
exit 0
ensure
print_info 'Shutting down server'
Process.kill('KILL', server_pid)
Process.kill('KILL', server_pids)
end
end