-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdependencies_spec.rb
More file actions
78 lines (63 loc) · 2.29 KB
/
dependencies_spec.rb
File metadata and controls
78 lines (63 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# frozen_string_literal: true
require 'mindee'
describe Mindee::Dependencies do
before(:each) do
if Mindee::Dependencies.instance_variable_defined?(:@all_deps_available)
Mindee::Dependencies.remove_instance_variable(:@all_deps_available)
end
end
describe '.all_deps_available?' do
context 'when evaluating the full mindee gem' do
before do
allow(Mindee::Dependencies).to receive(:require).and_return(true)
Mindee::Dependencies.instance_variable_set(:@all_deps_available, Mindee::Dependencies.check_all_dependencies)
end
it 'returns true' do
expect(Mindee::Dependencies.all_deps_available?).to be true
end
end
context 'when evaluating the mindee-lite gem' do
before do
allow(Mindee::Dependencies).to receive(:require).and_raise(LoadError)
Mindee::Dependencies.instance_variable_set(:@all_deps_available, Mindee::Dependencies.check_all_dependencies)
end
it 'returns false' do
expect(Mindee::Dependencies.all_deps_available?).to be false
end
end
end
end
describe 'Mindee PDF Module Loading' do
let(:pdf_tools_module_path) { File.expand_path('../lib/mindee/pdf/pdf_tools.rb', __dir__) }
context 'when initialized in a mindee-lite environment' do
before do
allow(Mindee::Dependencies).to receive(:all_deps_available?).and_return(false)
end
it 'raises a LoadError with the lite exception message' do
expect do
load pdf_tools_module_path
end.to raise_error(LoadError, Mindee::Dependencies::MINDEE_DEPENDENCIES_LOAD_ERROR)
end
end
context 'when initialized in a full mindee environment' do
around do |example|
original_require = Kernel.instance_method(:require)
Kernel.define_method(:require) do |name|
['origami', 'mini_magick', 'pdf-reader'].include?(name) || original_require.bind_call(self, name)
end
begin
example.run
ensure
Kernel.define_method(:require, original_require) # Restore original require
end
end
before do
allow(Mindee::Dependencies).to receive(:all_deps_available?).and_return(true)
end
it 'loads the module successfully without raising errors' do
expect do
load pdf_tools_module_path
end.not_to raise_error
end
end
end