-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathcoverage_spec.rb
More file actions
68 lines (52 loc) · 1.73 KB
/
coverage_spec.rb
File metadata and controls
68 lines (52 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# frozen_string_literal: true
RSpec.describe OpenapiFirst::Test::Coverage do
let(:filepath) { './spec/data/dice.yaml' }
let(:definition) { OpenapiFirst.load(filepath) }
before(:each) do
described_class.install
OpenapiFirst::Test.register(filepath)
described_class.start
end
after(:each) do
described_class.uninstall
described_class.reset
end
let(:valid_request) { Rack::Request.new(Rack::MockRequest.env_for('/roll', method: 'POST')) }
let(:valid_response) do
Rack::Response[200, { 'content-type' => 'application/json' }, ['1']]
end
let(:result) { described_class.result }
describe '.install' do
it 'installs global hooks' do
described_class.install
hooks = OpenapiFirst.configuration.hooks
expect(hooks[:after_request_validation]).not_to be_empty
expect(hooks[:after_response_validation]).not_to be_empty
end
it 'does not install hooks multiple times' do
2.times { described_class.install }
hooks = OpenapiFirst.configuration.hooks
expect(hooks[:after_request_validation].count).to eq(1)
expect(hooks[:after_response_validation].count).to eq(1)
end
end
describe '.result' do
let(:result) { described_class.result }
context 'without any requests' do
specify { expect(result.coverage).to eq(0) }
end
context 'with full coverage' do
before do
definition.validate_request(valid_request)
definition.validate_response(valid_request, valid_response)
end
specify { expect(result.coverage).to eq(100) }
end
context 'with partly coverage' do
before do
definition.validate_request(valid_request)
end
specify { expect(result.coverage).to eq(50) }
end
end
end