Skip to content

Commit

Permalink
Make turbo_test.rb with Rails' generated test_helper.rb
Browse files Browse the repository at this point in the history
> Something in the test suite configuration is preventing the database
> from being wiped between test runs. This results in state leaking
> between tests. As a result, our Continuous Integration tests are flaky.
>
> - [#248][]

As a follow-up to the [short-term solution][] shipped in
[#248][], this commit attempts to make the
`test/turbo_test.rb` file's setup consistent with the test harness setup
generated by Rails' [engine generator][] code.

To that end, this commit:

* renames the `test/turbo_test.rb` file to `test/test_helper.rb`
* omits one-off `require` calls for particular dependencies
* re-orders the require calls so that the
  `../test/dummy/config/environment` file is required ahead of the
  `rails/test_help` file

[engine generator]: https://github.com/rails/rails/blob/3c48b4030adbded21bebaa0d78254216cca48a6e/railties/lib/rails/generators/rails/plugin/templates/test/test_helper.rb.tt
[#248]: #248
[short-term solution]: c2dc5b1
  • Loading branch information
seanpdoyle committed Aug 1, 2022
1 parent 5040246 commit d18702b
Show file tree
Hide file tree
Showing 12 changed files with 13 additions and 20 deletions.
2 changes: 1 addition & 1 deletion test/application_system_test_case.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "turbo_test"
require "test_helper"

class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
driven_by :selenium, using: :headless_chrome, screen_size: [1400, 1400]
Expand Down
2 changes: 1 addition & 1 deletion test/drive/drive_helper_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "turbo_test"
require "test_helper"

class Turbo::DriveHelperTest < ActionDispatch::IntegrationTest
test "opting out of the default cache" do
Expand Down
2 changes: 1 addition & 1 deletion test/frames/frame_request_controller_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "turbo_test"
require "test_helper"

class Turbo::FrameRequestControllerTest < ActionDispatch::IntegrationTest
test "frame requests are rendered without a layout" do
Expand Down
4 changes: 1 addition & 3 deletions test/frames/frames_helper_test.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
require "turbo_test"
require "test_helper"

class Turbo::FramesHelperTest < ActionView::TestCase
setup { Message.delete_all }

test "frame with src" do
assert_dom_equal %(<turbo-frame src="/trays/1" id="tray"></turbo-frame>), turbo_frame_tag("tray", src: "/trays/1")
end
Expand Down
2 changes: 1 addition & 1 deletion test/initializers/helpers_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "turbo_test"
require "test_helper"

class Turbo::HelpersInInitializersTest < ActionDispatch::IntegrationTest
test "AC::Base has the helpers in place when initializers run" do
Expand Down
2 changes: 1 addition & 1 deletion test/native/navigation_controller_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "turbo_test"
require "test_helper"

class Turbo::Native::NavigationControllerTest < ActionDispatch::IntegrationTest
test "recede, resume, or refresh when native or redirect when not" do
Expand Down
2 changes: 1 addition & 1 deletion test/streams/broadcastable_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "turbo_test"
require "test_helper"
require "action_cable"

class Turbo::BroadcastableTest < ActionCable::Channel::TestCase
Expand Down
2 changes: 1 addition & 1 deletion test/streams/streams_channel_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "turbo_test"
require "test_helper"
require "action_cable"

class Turbo::StreamsChannelTest < ActionCable::Channel::TestCase
Expand Down
2 changes: 1 addition & 1 deletion test/streams/streams_controller_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "turbo_test"
require "test_helper"

class Turbo::StreamsControllerTest < ActionDispatch::IntegrationTest
test "create with respond to" do
Expand Down
2 changes: 1 addition & 1 deletion test/streams/streams_helper_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "turbo_test"
require "test_helper"

class TestChannel < ApplicationCable::Channel; end

Expand Down
2 changes: 0 additions & 2 deletions test/system/broadcasts_test.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
require "application_system_test_case"

class BroadcastsTest < ApplicationSystemTestCase
setup { Message.delete_all }

include ActionCable::TestHelper

test "Message broadcasts Turbo Streams" do
Expand Down
9 changes: 3 additions & 6 deletions test/turbo_test.rb → test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
# Configure Rails Environment
ENV["RAILS_ENV"] = "test"

require "minitest/autorun"
require "rails"
require_relative "../test/dummy/config/environment"
ActiveRecord::Migrator.migrations_paths = [File.expand_path("../test/dummy/db/migrate", __dir__)]
require "rails/test_help"
require "byebug"

require_relative "dummy/config/environment"

ActiveRecord::Migrator.migrations_paths = [File.expand_path("../test/dummy/db/migrate", __dir__)]
ActionCable.server.config.logger = Logger.new(STDOUT) if ENV["VERBOSE"]

module ActionViewTestCaseExtensions
Expand Down

0 comments on commit d18702b

Please sign in to comment.