File: attribute_map_test.rb

package info (click to toggle)
ruby-enumerize 2.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 432 kB
  • sloc: ruby: 3,712; makefile: 6
file content (70 lines) | stat: -rw-r--r-- 1,512 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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# frozen_string_literal: true

require 'test_helper'

module Enumerize
  class AttributeMapTest < Minitest::Spec
    subject { AttributeMap.new }

    def make_attr(name)
      Attribute.new(nil, name, :in => %[a b])
    end

    it 'empty when no attrs' do
      expect(subject).must_be_empty
    end

    it 'not empty when attr added' do
      subject << make_attr(:a)
      expect(subject).wont_be_empty
    end

    it 'iterates over added attrs' do
      attr_1 = make_attr(:a)
      attr_2 = make_attr(:b)

      subject << attr_1
      subject << attr_2

      count  = 0
      actual = []

      subject.each do |element|
        count += 1
        actual << element
      end

      expect(count).must_equal 2
      expect(actual).must_equal [attr_1, attr_2]
    end

    it 'reads attribute by name' do
      attr = make_attr(:a)
      subject << attr
      expect(subject[:a]).must_equal attr
    end

    it 'reads attribute by name using string' do
      attr = make_attr(:a)
      subject << attr
      expect(subject['a']).must_equal attr
    end

    it 'updates dependants' do
      attr = make_attr(:a)
      dependant = Minitest::Mock.new
      dependant.expect(:<<, nil, [attr])
      subject.add_dependant dependant
      subject << attr
      dependant.verify
    end

    it 'adds attrs to dependant' do
      attr = make_attr(:a)
      subject << attr
      dependant = AttributeMap.new
      subject.add_dependant dependant
      expect(dependant[:a]).must_equal attr
    end
  end
end