require 'support/process_helpers' # helper methods and constants which are only relevant to acceptance specs module AcceptanceHelpers def stub_sloccount(system_sloccount = fake_system_sloccount) allow(SLOCCountScanner::SystemSLOCCount).to receive(:instance) .and_return system_sloccount end def fake_system_sloccount instance_double('SystemSLOCCount').tap do |fake| allow(fake).to receive(:available?) .and_return true allow(fake).to receive(:call) .and_return [double('result'), failed_process_status] end end def stub_cloc(result: "", which_result: which_success('cloc'), process_status: successful_process_status) fake_system_cloc = instance_double( SystemCloc, call: [result, process_status], which: which_result ) fake_system_cloc_klass = class_double(SystemCloc, new: fake_system_cloc) stub_const('SystemCloc', fake_system_cloc_klass) end def stub_vuln_check stub_request(:get, Regexp.new('https://wpvulndb.com/api/v2/plugins/')) .with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Ruby' }) .to_return(status: 404, body: "The page you were looking for doesn't exist (404).", headers: {}) end def coloured_red(string) coloured(RED_START, string) end def coloured_green(string) coloured(GREEN_START, string) end def coloured_yellow(string) coloured(YELLOW_START, string) end def coloured_cyan(string) coloured(CYAN_START, string) end def coloured(colour, string) "#{colour_regexp(colour)}#{string}#{colour_regexp(COLOUR_END)}" end # Colour codes show up when running specs from the command line, # but not when capturing to a file - e.g when running from vim # so these need to be optional - hence the '?' def colour_regexp(colour_code) "(#{Regexp.escape colour_code})?" end # ANSI colour codes: RED_START = "\e[31m".freeze GREEN_START = "\e[32m".freeze YELLOW_START = "\e[33m".freeze CYAN_START = "\e[36m".freeze COLOUR_END = "\e[0m".freeze end