Skip to content

Commit d970a77

Browse files
committed
Allow observing multiple apps in one Test.setup block
1 parent 74536b1 commit d970a77

3 files changed

Lines changed: 20 additions & 2 deletions

File tree

lib/openapi_first/test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def self.setup
4040
yield configuration
4141

4242
configuration.registry.each { |name, oad| register(oad, as: name) }
43-
configuration.apps.each { |name, app| observe(app, api: name) }
43+
configuration.apps.each { |name, apps| apps.each { |app| observe(app, api: name) } }
4444
Coverage.start(skip_response: configuration.skip_response_coverage, skip_route: configuration.skip_coverage)
4545

4646
if definitions.empty?

lib/openapi_first/test/configuration.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def register(oad, as: :default)
2727

2828
# Observe a rack app
2929
def observe(app, api: :default)
30-
@apps[api] = app
30+
(@apps[api] ||= []) << app
3131
end
3232

3333
attr_accessor :coverage_formatter_options, :coverage_formatter, :response_raise_error,

spec/test_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,24 @@ def call(_env)
125125
app.new.call({})
126126
end
127127

128+
it 'observes multiple apps' do
129+
other_app = Class.new do
130+
def call(_env)
131+
Rack::Response.new.finish
132+
end
133+
end
134+
135+
described_class.setup do |test|
136+
test.register(definition, as: :some)
137+
test.observe(app, api: :some)
138+
test.observe(other_app, api: :some)
139+
end
140+
141+
expect(definition).to receive(:validate_request).twice
142+
app.new.call({})
143+
other_app.new.call({})
144+
end
145+
128146
it 'sets up minimum_coverage' do
129147
described_class.setup do |test|
130148
test.register('./examples/openapi.yaml')

0 commit comments

Comments
 (0)