File: ensures_all_interactions_satisfied.rb

package info (click to toggle)
ruby-bogus 0.1.6-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 860 kB
  • sloc: ruby: 4,219; makefile: 8; sh: 2
file content (34 lines) | stat: -rw-r--r-- 821 bytes parent folder | download | duplicates (3)
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
module Bogus
  class EnsuresAllInteractionsSatisfied
    def ensure_satisfied!(objects)
      unsatisfied = unsatisfied_interactions(objects)
      return if unsatisfied.empty?

      calls = all_calls(objects)
      raise NotAllExpectationsSatisfied.create(unsatisfied, calls)
    end

    private

    def unsatisfied_interactions(objects)
      mapcat_shadows(objects) do |object, shadow|
        shadow.unsatisfied_interactions.map{|c| [object, c]}
      end
    end

    def all_calls(objects)
      mapcat_shadows(objects) do |object, shadow|
        shadow.calls.map{|c| [object, c]}
      end
    end

    def mapcat_shadows(objects, &block)
      mapped = objects.map do |object|
        shadow = object.__shadow__
        block.call(object, shadow)
      end

      mapped.reduce([], :concat)
    end
  end
end