Sha256: fe0adac0124d4123f26df364cb641991694ba71c87e71df30e4ef602a8a12082

Contents?: true

Size: 880 Bytes

Versions: 3

Compression:

Stored size: 880 Bytes

Contents

module DevelopWithPassion
  module Fakes
    class MethodStub
      def initialize(arg_sets = [])
        @arg_sets = arg_sets
      end

      def with(*args)
        return add_new_set(ArgSet.new(*args))
      end

      def add_new_set(set)
        @arg_sets << set
        return set
      end

      def ignore_arg
        return add_new_set(IgnoreSet.new)
      end

      def and_return(item)
        ignore_arg.and_return(item)
      end


      def invoke(*args)
        set = @arg_sets.find{|item| item.matches?(*args)} || ignore_arg
        set.capture_args(*args)
        return set.return_value
      end

      def called_with(*args)
        return @arg_sets.find{|item| item.was_called_with?(*args)}
      end

      def times?(value)
        total = @arg_sets.inject(0){|sum,item|sum += item.times_called}
        return total == value
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
developwithpassion_fakes-0.0.3 lib/developwithpassion_fakes/method_stub.rb
developwithpassion_fakes-0.0.2 lib/developwithpassion_fakes/method_stub.rb
developwithpassion_fakes-0.0.1 lib/developwithpassion_fakes/method_stub.rb