Skip to content

Commit

Permalink
feature: add unit testsTestCoverage module
Browse files Browse the repository at this point in the history
  • Loading branch information
askonev committed Nov 16, 2023
1 parent 6ddaa3a commit 52b26bf
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions assets/unit/simple_incorrect_script
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Pattern(some parameters)
3 changes: 3 additions & 0 deletions unit/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# frozen_string_literal: true

require 'rspec'
42 changes: 42 additions & 0 deletions unit/test_coverage/test_coverage_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 52b26bf

Please sign in to comment.