Parent

Files

Class/Module Index [+]

Quicksearch

MockProxy

Attributes

raising[R]
yielding[R]

Public Class Methods

new(type=nil) click to toggle source
# File lib/mspec/mocks/proxy.rb, line 29
def initialize(type=nil)
  @multiple_returns = nil
  @returning = nil
  @raising   = nil
  @yielding  = []
  @arguments = :any_args
  @type      = type || :mock
end

Public Instance Methods

and_raise(exception) click to toggle source
# File lib/mspec/mocks/proxy.rb, line 128
def and_raise(exception)
  if exception.kind_of? String
    @raising = RuntimeError.new exception
  else
    @raising = exception
  end
end
and_return(*args) click to toggle source
# File lib/mspec/mocks/proxy.rb, line 114
def and_return(*args)
  case args.size
  when 0
    @returning = nil
  when 1
    @returning = args[0]
  else
    @multiple_returns = true
    @returning = args
    count[1] = args.size if count[1] < args.size
  end
  self
end
and_yield(*args) click to toggle source
# File lib/mspec/mocks/proxy.rb, line 140
def and_yield(*args)
  @yielding << args
  self
end
any_number_of_times() click to toggle source
# File lib/mspec/mocks/proxy.rb, line 100
def any_number_of_times
  @count = [:any_number_of_times, 0]
  self
end
arguments() click to toggle source
# File lib/mspec/mocks/proxy.rb, line 50
def arguments
  @arguments
end
at_least(n) click to toggle source
# File lib/mspec/mocks/proxy.rb, line 82
def at_least(n)
  @count = [:at_least, n_times(n)]
  self
end
at_most(n) click to toggle source
# File lib/mspec/mocks/proxy.rb, line 87
def at_most(n)
  @count = [:at_most, n_times(n)]
  self
end
called() click to toggle source
# File lib/mspec/mocks/proxy.rb, line 73
def called
  @calls = calls + 1
end
calls() click to toggle source
# File lib/mspec/mocks/proxy.rb, line 69
def calls
  @calls ||= 0
end
count() click to toggle source
# File lib/mspec/mocks/proxy.rb, line 46
def count
  @count ||= mock? ? [:exactly, 1] : [:any_number_of_times, 0]
end
exactly(n) click to toggle source
# File lib/mspec/mocks/proxy.rb, line 77
def exactly(n)
  @count = [:exactly, n_times(n)]
  self
end
mock?() click to toggle source
# File lib/mspec/mocks/proxy.rb, line 38
def mock?
  @type == :mock
end
once() click to toggle source
# File lib/mspec/mocks/proxy.rb, line 92
def once
  exactly 1
end
raising?() click to toggle source
# File lib/mspec/mocks/proxy.rb, line 136
def raising?
  @raising != nil
end
returning() click to toggle source
# File lib/mspec/mocks/proxy.rb, line 54
def returning
  if @multiple_returns
    if @returning.size == 1
      @multiple_returns = false
      return @returning = @returning.shift
    end
    return @returning.shift
  end
  @returning
end
stub?() click to toggle source
# File lib/mspec/mocks/proxy.rb, line 42
def stub?
  @type == :stub
end
times() click to toggle source
# File lib/mspec/mocks/proxy.rb, line 65
def times
  self
end
twice() click to toggle source
# File lib/mspec/mocks/proxy.rb, line 96
def twice
  exactly 2
end
with(*args) click to toggle source
# File lib/mspec/mocks/proxy.rb, line 105
def with(*args)
  raise ArgumentError, "you must specify the expected arguments" if args.empty?
  @arguments = *args
  if (behaves_like_ruby_1_9 = *[])
    @arguments = @arguments.first if @arguments.length <= 1
  end
  self
end
yielding?() click to toggle source
# File lib/mspec/mocks/proxy.rb, line 145
def yielding?
  !@yielding.empty?
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.