|
45 | 45 | end |
46 | 46 | end |
47 | 47 |
|
| 48 | + describe "#clear_cache" do |
| 49 | + it "invalidates memoized indexes so subsequent reads rebuild them" do |
| 50 | + source = described_class.new |
| 51 | + |
| 52 | + first_specs = source.specs |
| 53 | + first_installed = source.send(:installed_specs) |
| 54 | + first_default = source.send(:default_specs) |
| 55 | + first_cached = source.send(:cached_specs) |
| 56 | + |
| 57 | + expect(source.specs).to equal(first_specs) |
| 58 | + expect(source.send(:installed_specs)).to equal(first_installed) |
| 59 | + expect(source.send(:default_specs)).to equal(first_default) |
| 60 | + expect(source.send(:cached_specs)).to equal(first_cached) |
| 61 | + |
| 62 | + source.clear_cache |
| 63 | + |
| 64 | + expect(source.specs).not_to equal(first_specs) |
| 65 | + expect(source.send(:installed_specs)).not_to equal(first_installed) |
| 66 | + expect(source.send(:default_specs)).not_to equal(first_default) |
| 67 | + expect(source.send(:cached_specs)).not_to equal(first_cached) |
| 68 | + end |
| 69 | + |
| 70 | + it "reflects newly-discovered installed gems after clear_cache" do |
| 71 | + source = described_class.new |
| 72 | + foo = Gem::Specification.new("foo", "1.0.0") |
| 73 | + bar = Gem::Specification.new("bar", "1.0.0") |
| 74 | + |
| 75 | + allow(Bundler.rubygems).to receive(:installed_specs).and_return([foo]) |
| 76 | + expect(source.send(:installed_specs).search("bar")).to be_empty |
| 77 | + |
| 78 | + allow(Bundler.rubygems).to receive(:installed_specs).and_return([foo, bar]) |
| 79 | + expect(source.send(:installed_specs).search("bar")).to be_empty |
| 80 | + |
| 81 | + source.clear_cache |
| 82 | + |
| 83 | + expect(source.send(:installed_specs).search("bar")).not_to be_empty |
| 84 | + end |
| 85 | + end |
| 86 | + |
48 | 87 | describe "log debug information" do |
49 | 88 | it "log the time spent downloading and installing a gem" do |
50 | 89 | build_repo2 do |
|
0 commit comments