Sha256: 4d2b7f2418c96faac34e01a3295f3fb808e1f5c0f68a63250641a9a69dc85a14

Contents?: true

Size: 933 Bytes

Versions: 9

Compression:

Stored size: 933 Bytes

Contents

require_relative "fulfills_stubbing/finds_satisfaction"
require_relative "fulfills_stubbing/describes_unsatisfied_stubbing"

module Mocktail
  class FulfillsStubbing
    def initialize
      @finds_satisfaction = FindsSatisfaction.new
      @describes_unsatisfied_stubbing = DescribesUnsatisfiedStubbing.new
    end

    def fulfill(dry_call)
      if (stubbing = satisfaction(dry_call))
        stubbing.satisfied!
        stubbing.effect&.call(dry_call)
      else
        store_unsatisfying_call!(dry_call)
        nil
      end
    end

    def satisfaction(dry_call)
      return if Mocktail.cabinet.demonstration_in_progress?

      @finds_satisfaction.find(dry_call)
    end

    private

    def store_unsatisfying_call!(dry_call)
      return if Mocktail.cabinet.demonstration_in_progress?

      Mocktail.cabinet.store_unsatisfying_call(
        @describes_unsatisfied_stubbing.describe(dry_call)
      )
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
mocktail-1.2.3 lib/mocktail/handles_dry_call/fulfills_stubbing.rb
mocktail-1.2.2 lib/mocktail/handles_dry_call/fulfills_stubbing.rb
mocktail-1.2.1 lib/mocktail/handles_dry_call/fulfills_stubbing.rb
mocktail-1.2.0 lib/mocktail/handles_dry_call/fulfills_stubbing.rb
mocktail-1.1.3 lib/mocktail/handles_dry_call/fulfills_stubbing.rb
mocktail-1.1.2 lib/mocktail/handles_dry_call/fulfills_stubbing.rb
mocktail-1.1.1 lib/mocktail/handles_dry_call/fulfills_stubbing.rb
mocktail-1.1.0 lib/mocktail/handles_dry_call/fulfills_stubbing.rb
mocktail-1.0.0 lib/mocktail/handles_dry_call/fulfills_stubbing.rb