# frozen_string_literal: true require 'spec_helper' describe Coveralls do before do allow(SimpleCov).to receive(:start) stub_api_post described_class.testing = true end describe '#will_run?' do it 'checks CI environemnt variables' do expect(described_class).to be_will_run end context 'with CI disabled' do before do allow(ENV).to receive(:[]) allow(ENV).to receive(:[]).with('COVERALLS_RUN_LOCALLY').and_return(nil) allow(ENV).to receive(:[]).with('CI').and_return(nil) described_class.testing = false end it 'indicates no run' do expect(described_class).not_to be_will_run end end end describe '#should_run?' do it 'outputs to stdout when running locally' do described_class.testing = false described_class.run_locally = true silence do described_class.should_run? end end end describe '#wear!' do it 'receives block' do silence do subject.wear! do add_filter 's' end end expect(::SimpleCov).to have_received(:start) end it 'uses string' do silence do subject.wear! 'test_frameworks' end expect(::SimpleCov).to have_received(:start).with 'test_frameworks' end it 'uses default' do silence do subject.wear! end expect(::SimpleCov).to have_received(:start).with no_args expect(::SimpleCov.filters.map(&:filter_argument)).to include 'vendor' end end describe '#wear_merged!' do it 'sets formatter to NilFormatter' do silence do subject.wear_merged! 'rails' do add_filter '/spec/' end end expect(::SimpleCov.formatter).to be Coveralls::NilFormatter end end describe '#push!' do it 'sends existing test results' do result = false silence do result = subject.push! end expect(result).to be_truthy end end describe '#setup!' do it 'sets SimpleCov adapter' do SimpleCovTmp = SimpleCov Object.send :remove_const, :SimpleCov silence { subject.setup! } SimpleCov = SimpleCovTmp end end end