|
| 1 | +require_relative "../helper" |
| 2 | +require "spring/configuration" |
| 3 | + |
| 4 | +class ConfigurationTest < ActiveSupport::TestCase |
| 5 | + test "after_environment_load_callbacks is empty by default" do |
| 6 | + assert_equal [], Spring.after_environment_load_callbacks |
| 7 | + end |
| 8 | + |
| 9 | + test "after_environment_load registers a callback" do |
| 10 | + callbacks = [] |
| 11 | + Spring.stub(:after_environment_load_callbacks, callbacks) do |
| 12 | + Spring.after_environment_load { true } |
| 13 | + end |
| 14 | + assert_equal 1, callbacks.size |
| 15 | + end |
| 16 | + |
| 17 | + test "after_environment_load accumulates multiple callbacks in order" do |
| 18 | + callbacks = [] |
| 19 | + Spring.stub(:after_environment_load_callbacks, callbacks) do |
| 20 | + Spring.after_environment_load { :first } |
| 21 | + Spring.after_environment_load { :second } |
| 22 | + end |
| 23 | + assert_equal [:first, :second], callbacks.map(&:call) |
| 24 | + end |
| 25 | + |
| 26 | + test "after_environment_load callbacks are independent from after_fork callbacks" do |
| 27 | + env_callbacks = [] |
| 28 | + fork_callbacks = [] |
| 29 | + Spring.stub(:after_environment_load_callbacks, env_callbacks) do |
| 30 | + Spring.stub(:after_fork_callbacks, fork_callbacks) do |
| 31 | + Spring.after_environment_load { true } |
| 32 | + end |
| 33 | + end |
| 34 | + assert_equal 1, env_callbacks.size |
| 35 | + assert_equal 0, fork_callbacks.size |
| 36 | + end |
| 37 | + |
| 38 | + test "after_fork_callbacks is empty by default" do |
| 39 | + assert_equal [], Spring.after_fork_callbacks |
| 40 | + end |
| 41 | + |
| 42 | + test "after_fork registers a callback" do |
| 43 | + callbacks = [] |
| 44 | + Spring.stub(:after_fork_callbacks, callbacks) do |
| 45 | + Spring.after_fork { true } |
| 46 | + end |
| 47 | + assert_equal 1, callbacks.size |
| 48 | + end |
| 49 | + |
| 50 | + test "after_fork accumulates multiple callbacks in order" do |
| 51 | + callbacks = [] |
| 52 | + Spring.stub(:after_fork_callbacks, callbacks) do |
| 53 | + Spring.after_fork { :first } |
| 54 | + Spring.after_fork { :second } |
| 55 | + end |
| 56 | + assert_equal [:first, :second], callbacks.map(&:call) |
| 57 | + end |
| 58 | +end |
0 commit comments