Sha256: 7757babd1555f6642a6bf204626bdf50b4ad8a17fcdbf8bccad122669db4eabd

Contents?: true

Size: 1.13 KB

Versions: 8

Compression:

Stored size: 1.13 KB

Contents

############################################################
# This file is imported from a different project.
# DO NOT make modifications in this repo.
# File a patch instead and assign it to Ryan Davis
############################################################

class MockExpectationError < StandardError; end

module MiniTest
  class Mock
    def initialize
      @expected_calls = {}
      @actual_calls = Hash.new {|h,k| h[k] = [] }
    end

    def expect(name, retval, args=[])
      n, r, a = name, retval, args # for the closure below
      @expected_calls[name] = { :retval => retval, :args => args }
      self.class.__send__(:define_method, name) { |*x|
        raise ArgumentError unless @expected_calls[n][:args].size == x.size
        @actual_calls[n] << { :retval => r, :args => x }
        retval
      }
      self
    end

    def verify
      @expected_calls.each_key do |name|
        expected = @expected_calls[name]
        msg = "expected #{name}, #{expected.inspect}"
        raise MockExpectationError, msg unless
          @actual_calls.has_key? name and @actual_calls[name].include?(expected)
      end
      true
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
shoesgem-0.1514.0 shoes/ruby/lib/minitest/mock.rb
shoesgem-0.1480.0 shoes/ruby/lib/minitest/mock.rb
shoesgem-0.1469.0 shoes/ruby/lib/minitest/mock.rb
shoesgem-0.1430.0 shoes/ruby/lib/minitest/mock.rb
shoesgem-0.1429.0 shoes/ruby/lib/minitest/mock.rb
shoesgem-0.1428.0 shoes/ruby/lib/minitest/mock.rb
shoesgem-0.1426.0 shoes/ruby/lib/minitest/mock.rb
shoesgem-0.1424.0 shoes/ruby/lib/minitest/mock.rb