diff options
| author | fatkodima <fatkodima123@gmail.com> | 2019-10-30 18:17:56 +0200 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2024-04-19 05:18:20 +0000 |
| commit | 09cbbe0e3d2006bd191e33785154775fcfff9532 (patch) | |
| tree | c706252ec802dc5537c5863dfc9650a0097a0ae3 /spec | |
| parent | 1984db2db8ee54c33aabf6994718b972c56e2283 (diff) | |
[rubygems/rubygems] Add plugin hooks for Bundler.require
https://github.com/rubygems/rubygems/commit/b373b7ed0d
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/bundler/plugins/hook_spec.rb | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/spec/bundler/plugins/hook_spec.rb b/spec/bundler/plugins/hook_spec.rb index 72feb14d84..d20321b126 100644 --- a/spec/bundler/plugins/hook_spec.rb +++ b/spec/bundler/plugins/hook_spec.rb @@ -106,4 +106,103 @@ RSpec.describe "hook plugins" do expect(out).to include "installed gem rack : installed" end end + + context "before-require-all hook" do + before do + build_repo2 do + build_plugin "before-require-all-plugin" do |s| + s.write "plugins.rb", <<-RUBY + Bundler::Plugin::API.hook Bundler::Plugin::Events::GEM_BEFORE_REQUIRE_ALL do |deps| + puts "gems to be required \#{deps.map(&:name).join(", ")}" + end + RUBY + end + end + + bundle "plugin install before-require-all-plugin --source #{file_uri_for(gem_repo2)}" + end + + it "runs before all rubygems are required" do + install_gemfile_and_bundler_require + expect(out).to include "gems to be required rake, rack" + end + end + + context "before-require hook" do + before do + build_repo2 do + build_plugin "before-require-plugin" do |s| + s.write "plugins.rb", <<-RUBY + Bundler::Plugin::API.hook Bundler::Plugin::Events::GEM_BEFORE_REQUIRE do |dep| + puts "requiring gem \#{dep.name}" + end + RUBY + end + end + + bundle "plugin install before-require-plugin --source #{file_uri_for(gem_repo2)}" + end + + it "runs before each rubygem is required" do + install_gemfile_and_bundler_require + expect(out).to include "requiring gem rake" + expect(out).to include "requiring gem rack" + end + end + + context "after-require-all hook" do + before do + build_repo2 do + build_plugin "after-require-all-plugin" do |s| + s.write "plugins.rb", <<-RUBY + Bundler::Plugin::API.hook Bundler::Plugin::Events::GEM_AFTER_REQUIRE_ALL do |deps| + puts "required gems \#{deps.map(&:name).join(", ")}" + end + RUBY + end + end + + bundle "plugin install after-require-all-plugin --source #{file_uri_for(gem_repo2)}" + end + + it "runs after all rubygems are required" do + install_gemfile_and_bundler_require + expect(out).to include "required gems rake, rack" + end + end + + context "after-require hook" do + before do + build_repo2 do + build_plugin "after-require-plugin" do |s| + s.write "plugins.rb", <<-RUBY + Bundler::Plugin::API.hook Bundler::Plugin::Events::GEM_AFTER_REQUIRE do |dep| + puts "required gem \#{dep.name}" + end + RUBY + end + end + + bundle "plugin install after-require-plugin --source #{file_uri_for(gem_repo2)}" + end + + it "runs after each rubygem is required" do + install_gemfile_and_bundler_require + expect(out).to include "required gem rake" + expect(out).to include "required gem rack" + end + end + + def install_gemfile_and_bundler_require + install_gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem "rake" + gem "rack" + G + + ruby! <<-RUBY + require "#{lib}/bundler" + Bundler.require + RUBY + end end |
