diff --git a/assets/unit/simple_incorrect_script b/assets/unit/simple_incorrect_script new file mode 100644 index 000000000..d84b9c5c3 --- /dev/null +++ b/assets/unit/simple_incorrect_script @@ -0,0 +1 @@ +Pattern(some parameters) diff --git a/unit/spec_helper.rb b/unit/spec_helper.rb new file mode 100644 index 000000000..2dc2982de --- /dev/null +++ b/unit/spec_helper.rb @@ -0,0 +1,3 @@ +# frozen_string_literal: true + +require 'rspec' diff --git a/unit/test_coverage/test_coverage_spec.rb b/unit/test_coverage/test_coverage_spec.rb new file mode 100644 index 000000000..50447c4d8 --- /dev/null +++ b/unit/test_coverage/test_coverage_spec.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +require 'spec_helper' +require_relative '../../lib/coverage/test_coverage' + +describe TestCoverage do + let(:json) { described_class.get_api } + let(:redactors) { described_class.redactors } + let(:result_json) { described_class.run(json) } + + it 'json that should have expected fields' do + hash = JSON.parse(json) + expect(hash).to be_an(Hash) + expect(hash.length).to eq(4) + hash.each do |key, _value| + expect(redactors.key(key)).to be_truthy + end + end + + it 'run result should be json [String] with expected fields' do + hash = JSON.parse(result_json) + expect(hash).to be_an(Hash) + expect(hash.length).to eq(4) + hash.each do |key, _value| + expect(redactors.key(key)).to be_truthy + end + end + + describe described_class::Matcher do + let(:path) { File.join(Dir.pwd, 'assets', 'unit') } + + it 'true when found' do + matcher = described_class.new('Pattern', path) + expect(matcher).to be_pattern_found + end + + it 'false when not found' do + matcher = described_class.new('abracadabra', path) + expect(matcher).not_to be_pattern_found + end + end +end