Skip to content

Commit 1275e93

Browse files
andrewn617rafaelfranca
authored andcommitted
Update application_system_test_case.rb from DevcontainerGenerator
Instead of relying on the template to be dev container aware and generate the correct configuration, let's just update the configuration in place when running the DevcontainerGenerator. This will allow the devcontainer command to update this file with the configuration needed for devcontainers without overwriting the entire file.
1 parent f31b6f0 commit 1275e93

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed
Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
11
require "test_helper"
22

33
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
4-
<% if skip_devcontainer? -%>
54
driven_by :selenium, using: :headless_chrome, screen_size: [ 1400, 1400 ]
6-
<% else -%>
7-
if ENV["CAPYBARA_SERVER_PORT"]
8-
served_by host: "rails-app", port: ENV["CAPYBARA_SERVER_PORT"]
9-
10-
driven_by :selenium, using: :headless_chrome, screen_size: [ 1400, 1400 ], options: {
11-
browser: :remote,
12-
url: "http://#{ENV["SELENIUM_HOST"]}:4444"
13-
}
14-
else
15-
driven_by :selenium, using: :headless_chrome, screen_size: [ 1400, 1400 ]
16-
end
17-
<% end -%>
185
end

railties/lib/rails/generators/rails/devcontainer/devcontainer_generator.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ def create_devcontainer
3434
template ".devcontainer/compose.yaml"
3535
end
3636

37+
def update_application_system_test_case
38+
return unless options[:system_test]
39+
return unless File.exist?("test/application_system_test_case.rb")
40+
41+
gsub_file("test/application_system_test_case.rb", /^(\s*driven_by\b.*)/, system_test_configuration)
42+
end
43+
3744
private
3845
def dependencies
3946
return @dependencies if @dependencies
@@ -122,6 +129,21 @@ def local_rails_mount
122129
target: Rails::Generators::RAILS_DEV_PATH
123130
}
124131
end
132+
133+
def system_test_configuration
134+
<<~RUBY
135+
if ENV["CAPYBARA_SERVER_PORT"]
136+
served_by host: "rails-app", port: ENV["CAPYBARA_SERVER_PORT"]
137+
138+
driven_by :selenium, using: :headless_chrome, screen_size: [ 1400, 1400 ], options: {
139+
browser: :remote,
140+
url: "http://#{ENV["SELENIUM_HOST"]}:4444"
141+
}
142+
else
143+
driven_by :selenium, using: :headless_chrome, screen_size: [ 1400, 1400 ]
144+
end
145+
RUBY
146+
end
125147
end
126148
end
127149
end

railties/test/generators/app_generator_test.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,6 +1285,9 @@ def test_devcontainer
12851285
assert_file(".devcontainer/Dockerfile") do |content|
12861286
assert_match(/ARG RUBY_VERSION=#{RUBY_VERSION}/, content)
12871287
end
1288+
assert_file("test/application_system_test_case.rb") do |content|
1289+
assert_match(/served_by host: "rails-app", port: ENV\["CAPYBARA_SERVER_PORT"\]/, content)
1290+
end
12881291
assert_compose_file do |compose_config|
12891292
assert_equal "my_app", compose_config["name"]
12901293

0 commit comments

Comments
 (0)