Skip to content

Commit 94dc1b1

Browse files
committed
Merge pull request #9212 from Shopify/ec-leaky-test
Fix leaky tests (cherry picked from commit 8bb602f)
1 parent 07029c3 commit 94dc1b1

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

bundler/spec/bundler/plugin/events_spec.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,17 @@
22

33
RSpec.describe Bundler::Plugin::Events do
44
context "plugin events" do
5-
before { Bundler::Plugin::Events.send :reset }
5+
before do
6+
@old_constants = Bundler::Plugin::Events.constants.map {|name| [name, Bundler::Plugin::Events.const_get(name)] }
7+
Bundler::Plugin::Events.send :reset
8+
end
9+
10+
after do
11+
Bundler::Plugin::Events.send(:reset)
12+
Hash[@old_constants].each do |name, value|
13+
Bundler::Plugin::Events.send(:define, name, value)
14+
end
15+
end
616

717
describe "#define" do
818
it "raises when redefining a constant" do

bundler/spec/bundler/plugin_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@
279279
s.write "plugins.rb", code
280280
end
281281

282+
@old_constants = Bundler::Plugin::Events.constants.map {|name| [name, Bundler::Plugin::Events.const_get(name)] }
282283
Bundler::Plugin::Events.send(:reset)
283284
Bundler::Plugin::Events.send(:define, :EVENT1, "event-1")
284285
Bundler::Plugin::Events.send(:define, :EVENT2, "event-2")
@@ -291,6 +292,13 @@
291292
allow(index).to receive(:load_paths).with("foo-plugin").and_return([])
292293
end
293294

295+
after do
296+
Bundler::Plugin::Events.send(:reset)
297+
Hash[@old_constants].each do |name, value|
298+
Bundler::Plugin::Events.send(:define, name, value)
299+
end
300+
end
301+
294302
let(:code) { <<-RUBY }
295303
Bundler::Plugin::API.hook("event-1") { puts "hook for event 1" }
296304
RUBY

0 commit comments

Comments
 (0)