Class: Spy::Collection

Inherits:
Object
  • Object
show all
Defined in:
lib/spy/collection.rb,
lib/spy/collection/entry.rb,
lib/spy/collection/store.rb

Overview

Responsible for error handling and mapping to Entry

Defined Under Namespace

Classes: Entry, Store

Instance Method Summary collapse

Instance Method Details

#include?(spied, method) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
# File 'lib/spy/collection.rb', line 31

def include?(spied, method)
  entry = Entry.new(spied, method)
  store.include? entry
end

#insert(spied, method, spy) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/spy/collection.rb', line 8

def insert(spied, method, spy)
  entry = Entry.new(spied, method, spy)
  if store.include? entry
    raise Errors::AlreadySpiedError
  end
  store.insert(entry)
end

#remove(spied, method) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/spy/collection.rb', line 16

def remove(spied, method)
  entry = Entry.new(spied, method, nil)
  if !store.include? entry
    raise Errors::MethodNotSpiedError
  end
  store.remove(entry).spy
end

#remove_allObject



24
25
26
27
28
29
# File 'lib/spy/collection.rb', line 24

def remove_all
  store.map {|e| yield remove(e.spied, e.method)}
  if !store.empty?
    raise Errors::UnableToEmptySpyCollectionError
  end
end