Skip to content

Commit f3f779f

Browse files
committed
Temporary just to get code coverage
1 parent 7d71f5e commit f3f779f

5 files changed

Lines changed: 21 additions & 10 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: CI
22

33
on:
44
push:
5-
branches: [master, develop]
5+
branches: [main, develop]
66
pull_request:
7-
branches: [master, develop]
7+
branches: [main, develop]
88

99
permissions:
1010
actions: write

lib/sudo/proxy.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@ def proxy(object, method=:itself, *args, &blk)
1717
end
1818

1919
def loaded_specs
20-
# Something's weird with this method when called outside
21-
Gem.loaded_specs.to_a.to_h
20+
# Return only the keys (gem names) to avoid marshaling StubSpecification objects
21+
# which can fail in newer Bundler versions
22+
Gem.loaded_specs.keys
23+
rescue => e
24+
warn "Warning: Could not get loaded gem specs (#{e.class}: #{e.message}). Returning empty list."
25+
[]
2226
end
2327

2428
def load_path

lib/sudo/wrapper.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def run(ruby_opts: '', load_gems: true) # :yields: sudo
3131
rescue Exception => e # Bubble all exceptions...
3232
raise e
3333
ensure # and ensure sudo stops
34-
sudo.stop!
34+
sudo&.stop!
3535
end
3636

3737
# Do the actual resources clean-up.
@@ -130,7 +130,12 @@ def load_gems?
130130
end
131131

132132
def prospective_gems
133-
(Gem.loaded_specs.keys - @proxy.loaded_specs.keys)
133+
proxy_loaded_specs = @proxy.loaded_specs
134+
local_loaded_specs = Gem.loaded_specs.keys
135+
(local_loaded_specs - proxy_loaded_specs)
136+
rescue => e
137+
warn "Warning: Could not compare loaded gems (#{e.class}: #{e.message}). Skipping gem loading."
138+
[]
134139
end
135140

136141
# Load needed libraries in the DRb server. Usually you don't need

spec/lib/sudo/proxy_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88

99
context '#loaded_specs' do
1010

11-
it 'returns a hash' do
12-
expect(subject.loaded_specs).to be_a(Hash)
11+
it 'returns an array of gem names' do
12+
expect(subject.loaded_specs).to be_a(Array)
13+
expect(subject.loaded_specs).to_not be_empty
14+
expect(subject.loaded_specs).to all(be_a(String))
1315
end
1416

1517
end

spec/lib/sudo/system_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
end
1414

1515
it 'raises exception if unable to delete file' do
16-
allow_any_instance_of(Kernel).to receive(:system).and_return(false)
17-
allow(File).to receive(:exists?).and_return(true)
16+
allow(File).to receive(:exist?).and_return(true)
17+
allow(described_class).to receive(:system).and_return(false)
1818
expect{described_class.unlink('/tmp/bar')}.to raise_exception(Sudo::System::FileStillExists)
1919
end
2020

0 commit comments

Comments
 (0)