|
46 | 46 | end |
47 | 47 |
|
48 | 48 | describe "#clear_cache" do |
49 | | - it "clears the installed_specs cache" do |
| 49 | + it "invalidates memoized indexes so subsequent reads rebuild them" do |
50 | 50 | source = described_class.new |
51 | 51 |
|
52 | | - # Access installed_specs to populate the cache |
53 | | - source.send(:installed_specs) |
54 | | - expect(source.instance_variable_get(:@installed_specs)).not_to be_nil |
| 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) |
55 | 56 |
|
56 | | - # Expire the cache |
57 | | - source.clear_cache |
58 | | - |
59 | | - # Cache should be cleared |
60 | | - expect(source.instance_variable_get(:@installed_specs)).to be_nil |
61 | | - end |
| 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) |
62 | 61 |
|
63 | | - it "clears the default_specs cache" do |
64 | | - source = described_class.new |
65 | | - |
66 | | - # Access default_specs to populate the cache |
67 | | - source.send(:default_specs) |
68 | | - expect(source.instance_variable_get(:@default_specs)).not_to be_nil |
69 | | - |
70 | | - # Expire the cache |
71 | 62 | source.clear_cache |
72 | 63 |
|
73 | | - # Cache should be cleared |
74 | | - expect(source.instance_variable_get(:@default_specs)).to be_nil |
| 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) |
75 | 68 | end |
76 | 69 |
|
77 | | - it "clears the merged specs cache" do |
| 70 | + it "reflects newly-discovered installed gems after clear_cache" do |
78 | 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 |
79 | 77 |
|
80 | | - source.instance_variable_set(:@specs, Bundler::Index.new) |
81 | | - source.instance_variable_set(:@cached_specs, Bundler::Index.new) |
| 78 | + allow(Bundler.rubygems).to receive(:installed_specs).and_return([foo, bar]) |
| 79 | + expect(source.send(:installed_specs).search("bar")).to be_empty |
82 | 80 |
|
83 | 81 | source.clear_cache |
84 | 82 |
|
85 | | - expect(source.instance_variable_get(:@specs)).to be_nil |
86 | | - expect(source.instance_variable_get(:@cached_specs)).to be_nil |
| 83 | + expect(source.send(:installed_specs).search("bar")).not_to be_empty |
87 | 84 | end |
88 | 85 | end |
89 | 86 |
|
|
0 commit comments