diff --git a/lib/hotwire/spark/engine.rb b/lib/hotwire/spark/engine.rb index 677c3a9e..405b8bf9 100644 --- a/lib/hotwire/spark/engine.rb +++ b/lib/hotwire/spark/engine.rb @@ -7,7 +7,7 @@ class Engine < ::Rails::Engine config.hotwire = ActiveSupport::OrderedOptions.new unless config.respond_to?(:hotwire) config.hotwire.spark = ActiveSupport::OrderedOptions.new config.hotwire.spark.merge! \ - enabled: Rails.env.development?, + enabled: Rails.env.development? && !defined?(Rails::Server).nil?, css_paths: File.directory?("app/assets/builds") ? %w[ app/assets/builds ] : %w[ app/assets/stylesheets ], html_paths: %w[ app/controllers app/helpers app/models app/views ], stimulus_paths: %w[ app/javascript/controllers ] diff --git a/test/enabled_test.rb b/test/enabled_test.rb new file mode 100644 index 00000000..25e74d3a --- /dev/null +++ b/test/enabled_test.rb @@ -0,0 +1,11 @@ +require "test_helper" + +class EnabledTest < ActiveSupport::TestCase + test "that Hotwire-Spark is only enabled when starting the Rails server" do + script = <<~RUBY.strip + Hotwire::Spark.enabled? ? exit(1) : exit(0) + RUBY + + assert system({ "RAILS_ENV" => "development" }, "rails", "runner", script, chdir: Rails.application.root) + end +end