Sha256: eda90565a437f6aab4d8caf0933cdf502ae4ae94b24afb898013db17bd1b4f07

Contents?: true

Size: 821 Bytes

Versions: 8

Compression:

Stored size: 821 Bytes

Contents

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

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
bogus-0.1.7 lib/bogus/stubbing/ensures_all_interactions_satisfied.rb
bogus-0.1.6 lib/bogus/stubbing/ensures_all_interactions_satisfied.rb
bogus-0.1.5 lib/bogus/stubbing/ensures_all_interactions_satisfied.rb
bogus-0.1.4 lib/bogus/stubbing/ensures_all_interactions_satisfied.rb
bogus-0.1.3 lib/bogus/ensures_all_interactions_satisfied.rb
bogus-0.1.2 lib/bogus/ensures_all_interactions_satisfied.rb
bogus-0.1.1 lib/bogus/ensures_all_interactions_satisfied.rb
bogus-0.1.0 lib/bogus/ensures_all_interactions_satisfied.rb