File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed
Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change 44module NetboxClientRuby
55 module Entities
66 include NetboxClientRuby ::Communication
7+ include Enumerable
78
89 def self . included ( other_klass )
910 other_klass . extend ClassMethods
@@ -120,8 +121,8 @@ def [](index)
120121 as_entity raw_data_array [ index ]
121122 end
122123
123- def to_a
124- raw_data_array . map { |raw_entity | as_entity raw_entity }
124+ def each
125+ raw_data_array . each { |raw_entity | yield as_entity ( raw_entity ) }
125126 end
126127
127128 ##
Original file line number Diff line number Diff line change @@ -115,6 +115,25 @@ class TestEntities3
115115 end
116116 end
117117
118+ describe '#each' do
119+ it 'yields all items once' do
120+ count = 0
121+ subject . each do |_entity |
122+ count += 1
123+ end
124+
125+ expect ( count ) . to eq ( 3 )
126+ end
127+
128+ it 'yields a single entity of the expected type' do
129+ subject . each do |entity |
130+ expect ( entity ) . to be_a OpenStruct
131+ expect ( entity ) . to respond_to :data
132+ expect ( entity . data ) . to be_a Hash
133+ end
134+ end
135+ end
136+
118137 describe '#[]' do
119138 it 'returns the requested item as correct type' do
120139 expect ( subject [ 0 ] ) . to be_a OpenStruct
You can’t perform that action at this time.
0 commit comments