|
45 | 45 | end |
46 | 46 | end |
47 | 47 |
|
| 48 | + RSpec.shared_examples 'a cached workspace' do |
| 49 | + it 'should cache the information' do |
| 50 | + expect(subject).to receive(:file_exist?).at_least(:once) |
| 51 | + result = PuppetLanguageServer::DocumentStore.store_root_path |
| 52 | + # Subsequent calls should be cached |
| 53 | + expect(subject).to receive(:file_exist?).exactly(0).times |
| 54 | + result = PuppetLanguageServer::DocumentStore.store_root_path |
| 55 | + result = PuppetLanguageServer::DocumentStore.store_root_path |
| 56 | + result = PuppetLanguageServer::DocumentStore.store_root_path |
| 57 | + end |
| 58 | + |
| 59 | + it 'should recache the information when the cache expires' do |
| 60 | + result = PuppetLanguageServer::DocumentStore.store_root_path |
| 61 | + # Expire the cache |
| 62 | + PuppetLanguageServer::DocumentStore.expire_store_information |
| 63 | + expect(subject).to receive(:file_exist?).at_least(:once) |
| 64 | + result = PuppetLanguageServer::DocumentStore.store_root_path |
| 65 | + # Subsequent calls should be cached |
| 66 | + expect(subject).to receive(:file_exist?).exactly(0).times |
| 67 | + result = PuppetLanguageServer::DocumentStore.store_root_path |
| 68 | + result = PuppetLanguageServer::DocumentStore.store_root_path |
| 69 | + result = PuppetLanguageServer::DocumentStore.store_root_path |
| 70 | + end |
| 71 | + end |
| 72 | + |
48 | 73 | # Empty or missing workspace |
49 | 74 | context 'given a workspace option which is nil' do |
50 | 75 | let(:server_options) { {} } |
|
54 | 79 | end |
55 | 80 |
|
56 | 81 | it_should_behave_like 'an empty workspace', nil |
| 82 | + |
| 83 | + it 'should cache the information' do |
| 84 | + expect(subject).to receive(:file_exist?).exactly(0).times |
| 85 | + result = PuppetLanguageServer::DocumentStore.store_root_path |
| 86 | + result = PuppetLanguageServer::DocumentStore.store_root_path |
| 87 | + result = PuppetLanguageServer::DocumentStore.store_root_path |
| 88 | + result = PuppetLanguageServer::DocumentStore.store_root_path |
| 89 | + end |
| 90 | + |
| 91 | + it 'should not recache the information when the cache expires' do |
| 92 | + expect(subject).to receive(:file_exist?).exactly(0).times |
| 93 | + result = PuppetLanguageServer::DocumentStore.store_root_path |
| 94 | + PuppetLanguageServer::DocumentStore.expire_store_information |
| 95 | + result = PuppetLanguageServer::DocumentStore.store_root_path |
| 96 | + result = PuppetLanguageServer::DocumentStore.store_root_path |
| 97 | + result = PuppetLanguageServer::DocumentStore.store_root_path |
| 98 | + result = PuppetLanguageServer::DocumentStore.store_root_path |
| 99 | + end |
57 | 100 | end |
58 | 101 |
|
59 | 102 | context 'given a workspace option with a missing directory' do |
|
77 | 120 | end |
78 | 121 |
|
79 | 122 | it_should_behave_like 'a puppetfile workspace', expected_root |
| 123 | + it_should_behave_like 'a cached workspace' |
80 | 124 | end |
81 | 125 |
|
82 | 126 | context 'given a workspace option which has a parent directory with a puppetfile' do |
|
90 | 134 | end |
91 | 135 |
|
92 | 136 | it_should_behave_like 'a puppetfile workspace', expected_root |
| 137 | + it_should_behave_like 'a cached workspace' |
93 | 138 | end |
94 | 139 |
|
95 | 140 | # Module metadata style workspaces |
|
103 | 148 | end |
104 | 149 |
|
105 | 150 | it_should_behave_like 'a metadata.json workspace', expected_root |
| 151 | + it_should_behave_like 'a cached workspace' |
106 | 152 | end |
107 | 153 |
|
108 | 154 | context 'given a workspace option which has a parent directory with metadata.json' do |
|
116 | 162 | end |
117 | 163 |
|
118 | 164 | it_should_behave_like 'a metadata.json workspace', expected_root |
| 165 | + it_should_behave_like 'a cached workspace' |
119 | 166 | end |
120 | 167 | end |
0 commit comments