Skip to content

Commit 11fcf0d

Browse files
committed
Add spec for before/after fetch hooks
1 parent 034cc23 commit 11fcf0d

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

bundler/spec/plugins/hook_spec.rb

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,79 @@
11
# frozen_string_literal: true
22

33
RSpec.describe "hook plugins" do
4+
5+
context "before-and-after-fetch hooks" do
6+
before do
7+
build_repo2 do
8+
build_plugin "fetch-timing-timing-plugin" do |s|
9+
s.write "plugins.rb", <<-RUBY
10+
@timing_start = nil
11+
Bundler::Plugin::API.hook Bundler::Plugin::Events::GEM_BEFORE_FETCH do |spec_install|
12+
@timing_start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
13+
puts "gem \#{spec_install.name} started fetch at \#{@timing_start}"
14+
end
15+
Bundler::Plugin::API.hook Bundler::Plugin::Events::GEM_AFTER_FETCH do |spec_install|
16+
timing_end = Process.clock_gettime(Process::CLOCK_MONOTONIC)
17+
puts "gem \#{spec_install.name} took \#{timing_end - @timing_start} to fetch"
18+
@timing_start = nil
19+
end
20+
RUBY
21+
end
22+
end
23+
24+
bundle "plugin install fetch-timing-timing-plugin --source https://gem.repo2"
25+
end
26+
27+
it "runs before and after each rubygem is installed" do
28+
install_gemfile <<-G
29+
source "https://gem.repo1"
30+
gem "rake"
31+
gem "myrack"
32+
G
33+
34+
expect(out).to include "gem rake started fetch at"
35+
expect(out).to match /gem rake took \d+\.\d+ to fetch/
36+
expect(out).to include "gem myrack started fetch at"
37+
expect(out).to match /gem myrack took \d+\.\d+ to fetch/
38+
end
39+
end
40+
41+
context "before-and-after-git hooks" do
42+
before do
43+
build_repo2 do
44+
build_plugin "fetch-timing-timing-plugin" do |s|
45+
s.write "plugins.rb", <<-RUBY
46+
@timing_start = nil
47+
Bundler::Plugin::API.hook Bundler::Plugin::Events::GIT_BEFORE_FETCH do |spec_install|
48+
@timing_start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
49+
puts "gem \#{spec_install.name} started git fetch/checkout at \#{@timing_start}"
50+
end
51+
Bundler::Plugin::API.hook Bundler::Plugin::Events::GIT_AFTER_FETCH do |spec_install|
52+
timing_end = Process.clock_gettime(Process::CLOCK_MONOTONIC)
53+
puts "gem \#{spec_install.name} took \#{timing_end - @timing_start} to fetch"
54+
@timing_start = nil
55+
end
56+
RUBY
57+
end
58+
end
59+
60+
bundle "plugin install fetch-timing-timing-plugin --source https://gem.repo2"
61+
end
62+
63+
it "runs before and after each git source rubygem is installed" do
64+
build_git "foo", "1.0", path: lib_path("foo")
65+
66+
relative_path = lib_path("foo").relative_path_from(bundled_app)
67+
install_gemfile <<-G, verbose: true
68+
source "https://gem.repo1"
69+
gem "foo", :git => "#{relative_path}"
70+
G
71+
72+
expect(out).to include "gem foo started git fetch/checkout at"
73+
expect(out).to match /gem foo took \d+\.\d+ to fetch/
74+
end
75+
end
76+
477
context "before-install-all hook" do
578
before do
679
build_repo2 do

0 commit comments

Comments
 (0)