/
feature_loader_spec.rb
97 lines (79 loc) · 2.38 KB
/
feature_loader_spec.rb
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# frozen_string_literal: true
RSpec.describe RuboCop::FeatureLoader do
describe '.load' do
subject(:load) do
described_class.load(config_directory_path: config_directory_path, feature: feature)
end
let(:config_directory_path) do
'path-to-config'
end
let(:feature) do
'feature'
end
context 'with normally lodable feature' do
before do
allow(Kernel).to receive(:require)
end
it 'loads it normally' do
expect(Kernel).to receive(:require).with('feature')
load
end
end
context 'with dot-prefixed lodable feature' do
before do
allow(Kernel).to receive(:require)
end
let(:feature) do
'./path/to/feature'
end
it 'loads it as relative path' do
expect(Kernel).to receive(:require).with('path-to-config/./path/to/feature')
load
end
end
context 'with namespaced feature' do
before do
allow(Kernel).to receive(:require).with('feature-foo').and_call_original
allow(Kernel).to receive(:require).with('feature/foo')
end
let(:feature) do
'feature-foo'
end
it 'loads it as namespaced feature' do
expect(Kernel).to receive(:require).with('feature/foo')
load
end
end
context 'with dot-prefixed namespaced feature' do
before do
allow(Kernel).to receive(:require).with('path-to-config/./feature-foo').and_call_original
allow(Kernel).to receive(:require).with('path-to-config/./feature/foo')
end
let(:feature) do
'./feature-foo'
end
it 'loads it as namespaced feature' do
expect(Kernel).to receive(:require).with('path-to-config/./feature/foo')
load
end
end
context 'with unexpected LoadError from require' do
before do
allow(Kernel).to receive(:require).and_raise(LoadError)
end
it 'raises LoadError' do
expect { load }.to raise_error(LoadError)
end
end
context 'with unloadable namespaced feature' do
let(:feature) do
'feature-foo'
end
# In normal Ruby, the message starts with "cannot load such file",
# but in JRuby it seems to start with "no such file to load".
it 'raises LoadError with preferred message' do
expect { load }.to raise_error(LoadError, /feature-foo/)
end
end
end
end