|  | 
| 106 | 106 |       expect(out).to include "installed gem rack : installed" | 
| 107 | 107 |     end | 
| 108 | 108 |   end | 
|  | 109 | + | 
|  | 110 | +  context "before-require-all hook" do | 
|  | 111 | +    before do | 
|  | 112 | +      build_repo2 do | 
|  | 113 | +        build_plugin "before-require-all-plugin" do |s| | 
|  | 114 | +          s.write "plugins.rb", <<-RUBY | 
|  | 115 | +            Bundler::Plugin::API.hook Bundler::Plugin::Events::GEM_BEFORE_REQUIRE_ALL do |deps| | 
|  | 116 | +              puts "gems to be required \#{deps.map(&:name).join(", ")}" | 
|  | 117 | +            end | 
|  | 118 | +          RUBY | 
|  | 119 | +        end | 
|  | 120 | +      end | 
|  | 121 | + | 
|  | 122 | +      bundle "plugin install before-require-all-plugin --source #{file_uri_for(gem_repo2)}" | 
|  | 123 | +    end | 
|  | 124 | + | 
|  | 125 | +    it "runs before all rubygems are required" do | 
|  | 126 | +      install_gemfile_and_bundler_require | 
|  | 127 | +      expect(out).to include "gems to be required rake, rack" | 
|  | 128 | +    end | 
|  | 129 | +  end | 
|  | 130 | + | 
|  | 131 | +  context "before-require hook" do | 
|  | 132 | +    before do | 
|  | 133 | +      build_repo2 do | 
|  | 134 | +        build_plugin "before-require-plugin" do |s| | 
|  | 135 | +          s.write "plugins.rb", <<-RUBY | 
|  | 136 | +            Bundler::Plugin::API.hook Bundler::Plugin::Events::GEM_BEFORE_REQUIRE do |dep| | 
|  | 137 | +              puts "requiring gem \#{dep.name}" | 
|  | 138 | +            end | 
|  | 139 | +          RUBY | 
|  | 140 | +        end | 
|  | 141 | +      end | 
|  | 142 | + | 
|  | 143 | +      bundle "plugin install before-require-plugin --source #{file_uri_for(gem_repo2)}" | 
|  | 144 | +    end | 
|  | 145 | + | 
|  | 146 | +    it "runs before each rubygem is required" do | 
|  | 147 | +      install_gemfile_and_bundler_require | 
|  | 148 | +      expect(out).to include "requiring gem rake" | 
|  | 149 | +      expect(out).to include "requiring gem rack" | 
|  | 150 | +    end | 
|  | 151 | +  end | 
|  | 152 | + | 
|  | 153 | +  context "after-require-all hook" do | 
|  | 154 | +    before do | 
|  | 155 | +      build_repo2 do | 
|  | 156 | +        build_plugin "after-require-all-plugin" do |s| | 
|  | 157 | +          s.write "plugins.rb", <<-RUBY | 
|  | 158 | +            Bundler::Plugin::API.hook Bundler::Plugin::Events::GEM_AFTER_REQUIRE_ALL do |deps| | 
|  | 159 | +              puts "required gems \#{deps.map(&:name).join(", ")}" | 
|  | 160 | +            end | 
|  | 161 | +          RUBY | 
|  | 162 | +        end | 
|  | 163 | +      end | 
|  | 164 | + | 
|  | 165 | +      bundle "plugin install after-require-all-plugin --source #{file_uri_for(gem_repo2)}" | 
|  | 166 | +    end | 
|  | 167 | + | 
|  | 168 | +    it "runs after all rubygems are required" do | 
|  | 169 | +      install_gemfile_and_bundler_require | 
|  | 170 | +      expect(out).to include "required gems rake, rack" | 
|  | 171 | +    end | 
|  | 172 | +  end | 
|  | 173 | + | 
|  | 174 | +  context "after-require hook" do | 
|  | 175 | +    before do | 
|  | 176 | +      build_repo2 do | 
|  | 177 | +        build_plugin "after-require-plugin" do |s| | 
|  | 178 | +          s.write "plugins.rb", <<-RUBY | 
|  | 179 | +            Bundler::Plugin::API.hook Bundler::Plugin::Events::GEM_AFTER_REQUIRE do |dep| | 
|  | 180 | +              puts "required gem \#{dep.name}" | 
|  | 181 | +            end | 
|  | 182 | +          RUBY | 
|  | 183 | +        end | 
|  | 184 | +      end | 
|  | 185 | + | 
|  | 186 | +      bundle "plugin install after-require-plugin --source #{file_uri_for(gem_repo2)}" | 
|  | 187 | +    end | 
|  | 188 | + | 
|  | 189 | +    it "runs after each rubygem is required" do | 
|  | 190 | +      install_gemfile_and_bundler_require | 
|  | 191 | +      expect(out).to include "required gem rake" | 
|  | 192 | +      expect(out).to include "required gem rack" | 
|  | 193 | +    end | 
|  | 194 | +  end | 
|  | 195 | + | 
|  | 196 | +  def install_gemfile_and_bundler_require | 
|  | 197 | +    install_gemfile <<-G | 
|  | 198 | +      source "#{file_uri_for(gem_repo1)}" | 
|  | 199 | +      gem "rake" | 
|  | 200 | +      gem "rack" | 
|  | 201 | +    G | 
|  | 202 | + | 
|  | 203 | +    ruby <<-RUBY | 
|  | 204 | +      require "bundler" | 
|  | 205 | +      Bundler.require | 
|  | 206 | +    RUBY | 
|  | 207 | +  end | 
| 109 | 208 | end | 
0 commit comments