require 'acceptance_spec_helper' require 'support/heredoc_helper' RSpec.describe Pluginscan::Scanner do before do # these are slow, so don't run them if we don't have to stub_cloc stub_sloccount stub_vuln_check end describe '.scan' do let(:output) { StringIO.new } describe "CLOC Report", type: [:file, :process] do subject(:scanner) { Pluginscan::Scanner.new(sloccount: false, output: output) } before(:all) { setup_tempdir 'tmp' } it "reports on sloc by language" do LanguageCount = Struct.new :language, :sloc, :file_count cloc_output = <<-EOS.heredoc_unindent files,language,blank,comment,code,"github.com/AlDanial/cloc v 1.70 T=0.29 s (284.9 files/s, 65539.8 lines/s)" 20,PHP,4584,0,6628 EOS stub_cloc(result: cloc_output) php = coloured_cyan('PHP') count = coloured_red('6628') scanner.scan 'tmp' expect(output.string).to match(/#{php}\s*#{count} lines across 20 files/) end it "displays a message when there was no code" do stub_cloc(result: "") scanner.scan 'tmp' expect(output.string).to match(/CLOC didn't find any code/) end it "displays a message when cloc was unavailable (doesn't error out)" do stub_cloc(which_result: which_failure) scanner.scan 'tmp' expect(output.string).to match(/The 'cloc' command is unavailable/) end it "displays a message when cloc threw an error (doesn't error out)" do stub_cloc(result: "Some nonsense", process_status: failed_process_status) scanner.scan 'tmp' expect(output.string).to match(/Some nonsense/) end end end end