Skip to content

Commit 26182e7

Browse files
authored
Merge pull request #2841 from s01ipsist/served_by
Add support for ActionDispatch::SystemTestCase.served_by
2 parents 94c4be4 + 48bd424 commit 26182e7

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

lib/rspec/rails/example/system_example_group.rb

+6
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,12 @@ def driven_by(driver, **driver_options, &blk)
153153
@driver = ::ActionDispatch::SystemTestCase.driven_by(driver, **driver_options, &blk).tap(&:use)
154154
end
155155

156+
if ::Rails::VERSION::STRING.to_f >= 7.2
157+
def served_by(**options)
158+
::ActionDispatch::SystemTestCase.served_by(**options)
159+
end
160+
end
161+
156162
before do
157163
@routes = ::Rails.application.routes
158164
end

spec/rspec/rails/example/system_example_group_spec.rb

+15
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,21 @@ module RSpec::Rails
7878

7979
expect(example).to have_received(:driven_by).once
8080
end
81+
82+
it 'calls :served_by method only once', if: ::Rails::VERSION::STRING.to_f >= 7.2 do
83+
group = RSpec::Core::ExampleGroup.describe do
84+
include SystemExampleGroup
85+
86+
before do
87+
served_by(host: 'rails', port: 8080)
88+
end
89+
end
90+
example = group.new
91+
allow(example).to receive(:served_by).and_call_original
92+
group.hooks.run(:before, :example, example)
93+
94+
expect(example).to have_received(:served_by).once
95+
end
8196
end
8297

8398
describe '#after' do

0 commit comments

Comments
 (0)