From 0d397db5dd803fab2b7ddda9ae0dd5c26f4880a6 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Fri, 10 May 2024 08:36:09 -0400 Subject: [PATCH] Consolidate system specs into single directory, use rspec tags for configuration (#30206) --- .github/workflows/test-ruby.yml | 4 ++- .rubocop_todo.yml | 2 +- lib/tasks/spec.rake | 13 ------- spec/rails_helper.rb | 36 ++++++++----------- spec/requests/content_security_policy_spec.rb | 2 +- spec/support/capybara.rb | 4 +++ spec/support/javascript_errors.rb | 2 +- spec/support/streaming_server_manager.rb | 4 +-- .../admin/accounts_spec.rb | 0 .../admin/custom_emojis_spec.rb | 0 .../admin/domain_blocks_spec.rb | 0 .../admin/email_domain_blocks_spec.rb | 0 .../admin/ip_blocks_spec.rb | 0 .../admin/software_updates_spec.rb | 0 .../admin/statuses_spec.rb | 0 .../links/preview_card_providers_spec.rb | 0 .../admin/trends/links_spec.rb | 0 .../admin/trends/statuses_spec.rb | 0 .../admin/trends/tags_spec.rb | 0 spec/{features => system}/captcha_spec.rb | 0 spec/{features => system}/log_in_spec.rb | 0 spec/system/new_statuses_spec.rb | 2 +- spec/system/oauth_spec.rb | 2 +- spec/system/ocr_spec.rb | 2 +- spec/{features => system}/profile_spec.rb | 0 .../{features => system}/redirections_spec.rb | 0 spec/system/report_interface_spec.rb | 2 +- .../severed_relationships_spec.rb | 0 spec/system/share_entrypoint_spec.rb | 2 +- spec/system/unlogged_spec.rb | 2 +- 30 files changed, 32 insertions(+), 47 deletions(-) delete mode 100644 lib/tasks/spec.rake rename spec/{features => system}/admin/accounts_spec.rb (100%) rename spec/{features => system}/admin/custom_emojis_spec.rb (100%) rename spec/{features => system}/admin/domain_blocks_spec.rb (100%) rename spec/{features => system}/admin/email_domain_blocks_spec.rb (100%) rename spec/{features => system}/admin/ip_blocks_spec.rb (100%) rename spec/{features => system}/admin/software_updates_spec.rb (100%) rename spec/{features => system}/admin/statuses_spec.rb (100%) rename spec/{features => system}/admin/trends/links/preview_card_providers_spec.rb (100%) rename spec/{features => system}/admin/trends/links_spec.rb (100%) rename spec/{features => system}/admin/trends/statuses_spec.rb (100%) rename spec/{features => system}/admin/trends/tags_spec.rb (100%) rename spec/{features => system}/captcha_spec.rb (100%) rename spec/{features => system}/log_in_spec.rb (100%) rename spec/{features => system}/profile_spec.rb (100%) rename spec/{features => system}/redirections_spec.rb (100%) rename spec/{features => system}/severed_relationships_spec.rb (100%) diff --git a/.github/workflows/test-ruby.yml b/.github/workflows/test-ruby.yml index 84b9075708..45dc8a0deb 100644 --- a/.github/workflows/test-ruby.yml +++ b/.github/workflows/test-ruby.yml @@ -186,6 +186,8 @@ jobs: DISABLE_SIMPLECOV: true RAILS_ENV: test BUNDLE_WITH: test + LOCAL_DOMAIN: localhost:3000 + LOCAL_HTTPS: false strategy: fail-fast: false @@ -215,7 +217,7 @@ jobs: - name: Load database schema run: './bin/rails db:create db:schema:load db:seed' - - run: bundle exec rake spec:system + - run: bin/rspec spec/system --tag streaming --tag js - name: Archive logs uses: actions/upload-artifact@v4 diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 4d20330e0e..91e666d7f4 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -70,7 +70,7 @@ Style/FetchEnvVar: - 'config/initializers/vapid.rb' - 'lib/mastodon/redis_config.rb' - 'lib/tasks/repo.rake' - - 'spec/features/profile_spec.rb' + - 'spec/system/profile_spec.rb' # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle, MaxUnannotatedPlaceholdersAllowed, AllowedMethods, AllowedPatterns. diff --git a/lib/tasks/spec.rake b/lib/tasks/spec.rake deleted file mode 100644 index d505a47195..0000000000 --- a/lib/tasks/spec.rake +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -if Rake::Task.task_defined?('spec:system') - namespace :spec do - task :enable_system_specs do # rubocop:disable Rails/RakeEnvironment - ENV['LOCAL_DOMAIN'] = 'localhost:3000' - ENV['LOCAL_HTTPS'] = 'false' - ENV['RUN_SYSTEM_SPECS'] = 'true' - end - end - - Rake::Task['spec:system'].enhance ['spec:enable_system_specs'] -end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 89fc25bcbd..d8eb561d42 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -3,12 +3,8 @@ ENV['RAILS_ENV'] ||= 'test' # This needs to be defined before Rails is initialized -RUN_SYSTEM_SPECS = ENV.fetch('RUN_SYSTEM_SPECS', false) - -if RUN_SYSTEM_SPECS - STREAMING_PORT = ENV.fetch('TEST_STREAMING_PORT', '4020') - ENV['STREAMING_API_BASE_URL'] = "http://localhost:#{STREAMING_PORT}" -end +STREAMING_PORT = ENV.fetch('TEST_STREAMING_PORT', '4020') +ENV['STREAMING_API_BASE_URL'] = "http://localhost:#{STREAMING_PORT}" require File.expand_path('../config/environment', __dir__) @@ -26,10 +22,12 @@ require 'test_prof/recipes/rspec/before_all' Dir[Rails.root.join('spec', 'support', '**', '*.rb')].each { |f| require f } ActiveRecord::Migration.maintain_test_schema! -WebMock.disable_net_connect!(allow: Chewy.settings[:host], allow_localhost: RUN_SYSTEM_SPECS) +WebMock.disable_net_connect!( + allow_localhost: true, + allow: Chewy.settings[:host] +) Sidekiq.logger = nil -# System tests config DatabaseCleaner.strategy = [:deletion] Devise::Test::ControllerHelpers.module_eval do @@ -49,16 +47,14 @@ Devise::Test::ControllerHelpers.module_eval do end RSpec.configure do |config| - # This is set before running spec:system, see lib/tasks/tests.rake - config.filter_run_excluding type: lambda { |type| - case type - when :system - !RUN_SYSTEM_SPECS - end - } + # By default, skip specs that need full JS browser + config.filter_run_excluding :js - # By default, skip the elastic search integration specs - config.filter_run_excluding search: true + # By default, skip specs that need elastic search server + config.filter_run_excluding :search + + # By default, skip specs that need the streaming server + config.filter_run_excluding :streaming config.fixture_paths = [ Rails.root.join('spec', 'fixtures'), @@ -81,7 +77,7 @@ RSpec.configure do |config| config.include Devise::Test::ControllerHelpers, type: :controller config.include Devise::Test::ControllerHelpers, type: :helper config.include Devise::Test::ControllerHelpers, type: :view - config.include Devise::Test::IntegrationHelpers, type: :feature + config.include Devise::Test::IntegrationHelpers, type: :system config.include Devise::Test::IntegrationHelpers, type: :request config.include ActionMailer::TestHelper config.include Paperclip::Shoulda::Matchers @@ -111,10 +107,6 @@ RSpec.configure do |config| stub_reset_connection_pools end - config.before :each, type: :feature do - Capybara.current_driver = :rack_test - end - config.before do |example| allow(Resolv::DNS).to receive(:open).and_raise('Real DNS queries are disabled, stub Resolv::DNS as needed') unless example.metadata[:type] == :system end diff --git a/spec/requests/content_security_policy_spec.rb b/spec/requests/content_security_policy_spec.rb index d4447dca4b..ba6fe47741 100644 --- a/spec/requests/content_security_policy_spec.rb +++ b/spec/requests/content_security_policy_spec.rb @@ -23,7 +23,7 @@ describe 'Content-Security-Policy' do <<~CSP.split("\n").map(&:strip) base-uri 'none' child-src 'self' blob: https://cb6e6126.ngrok.io - connect-src 'self' data: blob: https://cb6e6126.ngrok.io ws://cb6e6126.ngrok.io:4000 + connect-src 'self' data: blob: https://cb6e6126.ngrok.io #{Rails.configuration.x.streaming_api_base_url} default-src 'none' font-src 'self' https://cb6e6126.ngrok.io form-action 'self' diff --git a/spec/support/capybara.rb b/spec/support/capybara.rb index d4f27e209e..be1378ffac 100644 --- a/spec/support/capybara.rb +++ b/spec/support/capybara.rb @@ -26,6 +26,10 @@ Capybara.javascript_driver = :headless_chrome RSpec.configure do |config| config.before(:each, type: :system) do + driven_by :rack_test + end + + config.before(:each, :js, type: :system) do driven_by Capybara.javascript_driver end end diff --git a/spec/support/javascript_errors.rb b/spec/support/javascript_errors.rb index a36bf6017e..28a43b3b8a 100644 --- a/spec/support/javascript_errors.rb +++ b/spec/support/javascript_errors.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true RSpec.configure do |config| - config.after(:each, type: :system) do + config.after(:each, :js, type: :system) do errors = page.driver.browser.logs.get(:browser) if errors.present? aggregate_failures 'javascript errrors' do diff --git a/spec/support/streaming_server_manager.rb b/spec/support/streaming_server_manager.rb index b702fc77ce..3facf16b8e 100644 --- a/spec/support/streaming_server_manager.rb +++ b/spec/support/streaming_server_manager.rb @@ -95,7 +95,7 @@ RSpec.configure do |config| end end - config.around :each, type: :system do |example| + config.around :each, :streaming, type: :system do |example| # Streaming server needs DB access but `use_transactional_tests` rolls back # every transaction. Disable this feature for streaming tests, and use # DatabaseCleaner to clean the database tables between each test. @@ -125,6 +125,6 @@ RSpec.configure do |config| end def streaming_examples_present? - RUN_SYSTEM_SPECS + RSpec.world.filtered_examples.values.flatten.any? { |example| example.metadata[:streaming] == true } end end diff --git a/spec/features/admin/accounts_spec.rb b/spec/system/admin/accounts_spec.rb similarity index 100% rename from spec/features/admin/accounts_spec.rb rename to spec/system/admin/accounts_spec.rb diff --git a/spec/features/admin/custom_emojis_spec.rb b/spec/system/admin/custom_emojis_spec.rb similarity index 100% rename from spec/features/admin/custom_emojis_spec.rb rename to spec/system/admin/custom_emojis_spec.rb diff --git a/spec/features/admin/domain_blocks_spec.rb b/spec/system/admin/domain_blocks_spec.rb similarity index 100% rename from spec/features/admin/domain_blocks_spec.rb rename to spec/system/admin/domain_blocks_spec.rb diff --git a/spec/features/admin/email_domain_blocks_spec.rb b/spec/system/admin/email_domain_blocks_spec.rb similarity index 100% rename from spec/features/admin/email_domain_blocks_spec.rb rename to spec/system/admin/email_domain_blocks_spec.rb diff --git a/spec/features/admin/ip_blocks_spec.rb b/spec/system/admin/ip_blocks_spec.rb similarity index 100% rename from spec/features/admin/ip_blocks_spec.rb rename to spec/system/admin/ip_blocks_spec.rb diff --git a/spec/features/admin/software_updates_spec.rb b/spec/system/admin/software_updates_spec.rb similarity index 100% rename from spec/features/admin/software_updates_spec.rb rename to spec/system/admin/software_updates_spec.rb diff --git a/spec/features/admin/statuses_spec.rb b/spec/system/admin/statuses_spec.rb similarity index 100% rename from spec/features/admin/statuses_spec.rb rename to spec/system/admin/statuses_spec.rb diff --git a/spec/features/admin/trends/links/preview_card_providers_spec.rb b/spec/system/admin/trends/links/preview_card_providers_spec.rb similarity index 100% rename from spec/features/admin/trends/links/preview_card_providers_spec.rb rename to spec/system/admin/trends/links/preview_card_providers_spec.rb diff --git a/spec/features/admin/trends/links_spec.rb b/spec/system/admin/trends/links_spec.rb similarity index 100% rename from spec/features/admin/trends/links_spec.rb rename to spec/system/admin/trends/links_spec.rb diff --git a/spec/features/admin/trends/statuses_spec.rb b/spec/system/admin/trends/statuses_spec.rb similarity index 100% rename from spec/features/admin/trends/statuses_spec.rb rename to spec/system/admin/trends/statuses_spec.rb diff --git a/spec/features/admin/trends/tags_spec.rb b/spec/system/admin/trends/tags_spec.rb similarity index 100% rename from spec/features/admin/trends/tags_spec.rb rename to spec/system/admin/trends/tags_spec.rb diff --git a/spec/features/captcha_spec.rb b/spec/system/captcha_spec.rb similarity index 100% rename from spec/features/captcha_spec.rb rename to spec/system/captcha_spec.rb diff --git a/spec/features/log_in_spec.rb b/spec/system/log_in_spec.rb similarity index 100% rename from spec/features/log_in_spec.rb rename to spec/system/log_in_spec.rb diff --git a/spec/system/new_statuses_spec.rb b/spec/system/new_statuses_spec.rb index 5a3f1b406b..725ea8fe52 100644 --- a/spec/system/new_statuses_spec.rb +++ b/spec/system/new_statuses_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -describe 'NewStatuses', :sidekiq_inline do +describe 'NewStatuses', :js, :sidekiq_inline, :streaming do include ProfileStories subject { page } diff --git a/spec/system/oauth_spec.rb b/spec/system/oauth_spec.rb index 3b98ad352b..1c9aca3114 100644 --- a/spec/system/oauth_spec.rb +++ b/spec/system/oauth_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -describe 'Using OAuth from an external app' do +describe 'Using OAuth from an external app', :js, :streaming do let(:client_app) { Doorkeeper::Application.create!(name: 'test', redirect_uri: about_url(host: Rails.application.config.x.local_domain), scopes: 'read') } context 'when the user is already logged in' do diff --git a/spec/system/ocr_spec.rb b/spec/system/ocr_spec.rb index 254efa7137..4f4941adca 100644 --- a/spec/system/ocr_spec.rb +++ b/spec/system/ocr_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -describe 'OCR', :paperclip_processing, :sidekiq_inline do +describe 'OCR', :js, :paperclip_processing, :sidekiq_inline, :streaming do include ProfileStories let(:email) { 'test@example.com' } diff --git a/spec/features/profile_spec.rb b/spec/system/profile_spec.rb similarity index 100% rename from spec/features/profile_spec.rb rename to spec/system/profile_spec.rb diff --git a/spec/features/redirections_spec.rb b/spec/system/redirections_spec.rb similarity index 100% rename from spec/features/redirections_spec.rb rename to spec/system/redirections_spec.rb diff --git a/spec/system/report_interface_spec.rb b/spec/system/report_interface_spec.rb index 6eba552559..f82604aae8 100644 --- a/spec/system/report_interface_spec.rb +++ b/spec/system/report_interface_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -describe 'report interface', :paperclip_processing do +describe 'report interface', :js, :paperclip_processing, :streaming do include ProfileStories let(:email) { 'admin@example.com' } diff --git a/spec/features/severed_relationships_spec.rb b/spec/system/severed_relationships_spec.rb similarity index 100% rename from spec/features/severed_relationships_spec.rb rename to spec/system/severed_relationships_spec.rb diff --git a/spec/system/share_entrypoint_spec.rb b/spec/system/share_entrypoint_spec.rb index 126a816bcc..5fdbeacefa 100644 --- a/spec/system/share_entrypoint_spec.rb +++ b/spec/system/share_entrypoint_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -describe 'ShareEntrypoint' do +describe 'ShareEntrypoint', :js, :streaming do include ProfileStories subject { page } diff --git a/spec/system/unlogged_spec.rb b/spec/system/unlogged_spec.rb index c3ebf51d7f..417ccdaeb6 100644 --- a/spec/system/unlogged_spec.rb +++ b/spec/system/unlogged_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -describe 'UnloggedBrowsing' do +describe 'UnloggedBrowsing', :js, :streaming do subject { page } before do