Skip to content

Commit 8c7e460

Browse files
committed
Fix tests for spring changes
1 parent 54aa1f6 commit 8c7e460

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

lib/dotenv/rails.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
Dotenv.instrumenter = ActiveSupport::Notifications
1111

1212
# Watch all loaded env files with Spring
13-
if defined?(Spring)
14-
ActiveSupport::Notifications.subscribe("load.dotenv") do |*args|
13+
ActiveSupport::Notifications.subscribe("load.dotenv") do |*args|
14+
if defined?(Spring)
1515
event = ActiveSupport::Notifications::Event.new(*args)
1616
Spring.watch event.payload[:env].filename if Rails.application
1717
end

spec/dotenv/rails_spec.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
Rails.env = "test"
3535
Rails.application = nil
3636
Rails.logger = nil
37-
Spring.watcher = Set.new # Responds to #add
3837

3938
begin
4039
# Remove the singleton instance if it exists
@@ -76,6 +75,7 @@
7675
end
7776

7877
it "watches other loaded files with Spring" do
78+
stub_spring
7979
application.initialize!
8080
path = fixture_path("plain.env")
8181
Dotenv.load(path)
@@ -93,6 +93,7 @@
9393
subject { application.initialize! }
9494

9595
it "watches .env with Spring" do
96+
stub_spring
9697
subject
9798
expect(Spring.watcher).to include(fixture_path(".env").to_s)
9899
end
@@ -204,4 +205,14 @@
204205
expect(Dotenv::Rails.logger).to be(logger)
205206
end
206207
end
208+
209+
def stub_spring
210+
spring = Struct.new("Spring", :watcher) do
211+
def watch(path)
212+
watcher.add path
213+
end
214+
end
215+
216+
stub_const "Spring", spring.new(Set.new)
217+
end
207218
end

0 commit comments

Comments
 (0)