File: hash_counter_spec.rb

package info (click to toggle)
ruby-webmock 3.25.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,172 kB
  • sloc: ruby: 12,829; makefile: 6
file content (39 lines) | stat: -rw-r--r-- 1,065 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
require 'spec_helper'

describe WebMock::Util::HashCounter do

  it "should return 0 for non existing key" do
    expect(WebMock::Util::HashCounter.new.get(:abc)).to eq(0)
  end

  it "should increase the returned value on every put with the same key" do
    counter = WebMock::Util::HashCounter.new
    counter.put(:abc)
    expect(counter.get(:abc)).to eq(1)
    counter.put(:abc)
    expect(counter.get(:abc)).to eq(2)
  end

  it "should only increase value for given key provided to put" do
    counter = WebMock::Util::HashCounter.new
    counter.put(:abc)
    expect(counter.get(:abc)).to eq(1)
    expect(counter.get(:def)).to eq(0)
  end

  describe "each" do
    it "should provide elements in order of the last modified" do
      counter = WebMock::Util::HashCounter.new
      counter.put(:a)
      counter.put(:b)
      counter.put(:c)
      counter.put(:b)
      counter.put(:a)
      counter.put(:d)

      elements = []
      counter.each {|k,v| elements << [k,v]}
      expect(elements).to eq([[:c, 1], [:b, 2], [:a, 2], [:d, 1]])
    end
  end
end