Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion bundler/spec/bundler/plugin/events_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,17 @@

RSpec.describe Bundler::Plugin::Events do
context "plugin events" do
before { Bundler::Plugin::Events.send :reset }
before do
@old_constants = Bundler::Plugin::Events.constants.map {|name| [name, Bundler::Plugin::Events.const_get(name)] }
Bundler::Plugin::Events.send :reset
end

after do
Bundler::Plugin::Events.send(:reset)
Hash[@old_constants].each do |name, value|
Bundler::Plugin::Events.send(:define, name, value)
end
end

describe "#define" do
it "raises when redefining a constant" do
Expand Down
8 changes: 8 additions & 0 deletions bundler/spec/bundler/plugin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@
s.write "plugins.rb", code
end

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

after do
Bundler::Plugin::Events.send(:reset)
Hash[@old_constants].each do |name, value|
Bundler::Plugin::Events.send(:define, name, value)
end
end

let(:code) { <<-RUBY }
Bundler::Plugin::API.hook("event-1") { puts "hook for event 1" }
RUBY
Expand Down