File: equality_map_spec.rb

package info (click to toggle)
ruby-tool 0.2.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 148 kB
  • ctags: 37
  • sloc: ruby: 283; makefile: 3
file content (24 lines) | stat: -rw-r--r-- 630 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
require 'tool/equality_map'

describe Tool::EqualityMap do
  before { GC.disable }
  after { GC.enable }

  describe :fetch do
    subject { Tool::EqualityMap.new }
    specify 'with existing entry' do
      next if subject.is_a? Hash
      subject.fetch("foo") { "foo" }
      result = subject.fetch("foo") { "bar" }
      expect(result).to be == "foo"
    end

    specify 'with GC-removed entry' do
      next if subject.is_a? Hash
      subject.fetch("foo") { "foo" }
      expect(subject.map).to receive(:[]).and_return(nil)
      result = subject.fetch("foo") { "bar" }
      expect(result).to be == "bar"
    end
  end
end