|
159 | 159 | # calling this more than once will load tasks again and 'invoke' or 'execute' calls |
160 | 160 | # will call rake tasks multiple times |
161 | 161 | Application.load_tasks |
| 162 | + |
| 163 | + # Set up Fog mock buckets once at suite start instead of every test |
| 164 | + if Fog.mock? |
| 165 | + CloudController::DependencyLocator.instance.droplet_blobstore.ensure_bucket_exists |
| 166 | + CloudController::DependencyLocator.instance.package_blobstore.ensure_bucket_exists |
| 167 | + CloudController::DependencyLocator.instance.global_app_bits_cache.ensure_bucket_exists |
| 168 | + CloudController::DependencyLocator.instance.buildpack_blobstore.ensure_bucket_exists |
| 169 | + end |
162 | 170 | end |
163 | 171 |
|
164 | 172 | rspec_config.before do |
|
169 | 177 | TestConfig.context = example.metadata[:job_context] || :api |
170 | 178 | TestConfig.reset |
171 | 179 |
|
172 | | - Fog::Mock.reset |
| 180 | + VCAP::CloudController::SecurityContext.clear |
| 181 | + VCAP::Request.current_id = nil |
| 182 | + allow_any_instance_of(VCAP::CloudController::UaaTokenDecoder).to receive(:uaa_issuer).and_return(UAAIssuer::ISSUER) |
173 | 183 |
|
| 184 | + mock_redis = MockRedis.new |
| 185 | + allow(Redis).to receive(:new).and_return(mock_redis) |
| 186 | + end |
| 187 | + |
| 188 | + # Only reset Fog mocks for tests that use blobstores (tagged with :fog_reset) |
| 189 | + # This avoids the overhead of clearing and recreating buckets for every test |
| 190 | + rspec_config.before(:each, :fog_reset) do |
| 191 | + Fog::Mock.reset |
174 | 192 | if Fog.mock? |
175 | 193 | CloudController::DependencyLocator.instance.droplet_blobstore.ensure_bucket_exists |
176 | 194 | CloudController::DependencyLocator.instance.package_blobstore.ensure_bucket_exists |
177 | 195 | CloudController::DependencyLocator.instance.global_app_bits_cache.ensure_bucket_exists |
178 | 196 | CloudController::DependencyLocator.instance.buildpack_blobstore.ensure_bucket_exists |
179 | 197 | end |
180 | | - |
181 | | - VCAP::CloudController::SecurityContext.clear |
182 | | - VCAP::Request.current_id = nil |
183 | | - allow_any_instance_of(VCAP::CloudController::UaaTokenDecoder).to receive(:uaa_issuer).and_return(UAAIssuer::ISSUER) |
184 | | - |
185 | | - mock_redis = MockRedis.new |
186 | | - allow(Redis).to receive(:new).and_return(mock_redis) |
187 | 198 | end |
188 | 199 |
|
189 | 200 | rspec_config.around do |example| |
|
0 commit comments