Class: MockProxy
Instance Method Summary collapse
- #and_return(*args) ⇒ Object
- #and_yield(*args) ⇒ Object
- #any_number_of_times ⇒ Object
- #arguments ⇒ Object
- #at_least(n) ⇒ Object
- #at_most(n) ⇒ Object
- #called ⇒ Object
- #calls ⇒ Object
- #count ⇒ Object
- #exactly(n) ⇒ Object
-
#initialize(type = nil) ⇒ MockProxy
constructor
A new instance of MockProxy.
- #mock? ⇒ Boolean
- #once ⇒ Object
- #returning ⇒ Object
- #stub? ⇒ Boolean
- #times ⇒ Object
- #twice ⇒ Object
- #with(*args) ⇒ Object
- #yielding ⇒ Object
- #yielding? ⇒ Boolean
Constructor Details
#initialize(type = nil) ⇒ MockProxy
Returns a new instance of MockProxy.
13 14 15 16 17 18 19 |
# File 'lib/mspec/mocks/proxy.rb', line 13 def initialize(type=nil) @multiple_returns = nil @returning = nil @yielding = [] @arguments = :any_args @type = type || :mock end |
Instance Method Details
#and_return(*args) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/mspec/mocks/proxy.rb', line 97 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) ⇒ Object
111 112 113 114 |
# File 'lib/mspec/mocks/proxy.rb', line 111 def and_yield(*args) @yielding << args self end |
#any_number_of_times ⇒ Object
83 84 85 86 |
# File 'lib/mspec/mocks/proxy.rb', line 83 def any_number_of_times @count = [:any_number_of_times, 0] self end |
#arguments ⇒ Object
33 34 35 |
# File 'lib/mspec/mocks/proxy.rb', line 33 def arguments @arguments end |
#at_least(n) ⇒ Object
65 66 67 68 |
# File 'lib/mspec/mocks/proxy.rb', line 65 def at_least(n) @count = [:at_least, n_times(n)] self end |
#at_most(n) ⇒ Object
70 71 72 73 |
# File 'lib/mspec/mocks/proxy.rb', line 70 def at_most(n) @count = [:at_most, n_times(n)] self end |
#called ⇒ Object
56 57 58 |
# File 'lib/mspec/mocks/proxy.rb', line 56 def called @calls = calls + 1 end |
#calls ⇒ Object
52 53 54 |
# File 'lib/mspec/mocks/proxy.rb', line 52 def calls @calls ||= 0 end |
#count ⇒ Object
29 30 31 |
# File 'lib/mspec/mocks/proxy.rb', line 29 def count @count ||= mock? ? [:exactly, 1] : [:any_number_of_times, 0] end |
#exactly(n) ⇒ Object
60 61 62 63 |
# File 'lib/mspec/mocks/proxy.rb', line 60 def exactly(n) @count = [:exactly, n_times(n)] self end |
#mock? ⇒ Boolean
21 22 23 |
# File 'lib/mspec/mocks/proxy.rb', line 21 def mock? @type == :mock end |
#once ⇒ Object
75 76 77 |
# File 'lib/mspec/mocks/proxy.rb', line 75 def once exactly 1 end |
#returning ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/mspec/mocks/proxy.rb', line 37 def returning if @multiple_returns if @returning.size == 1 @multiple_returns = false return @returning = @returning.shift end return @returning.shift end @returning end |
#stub? ⇒ Boolean
25 26 27 |
# File 'lib/mspec/mocks/proxy.rb', line 25 def stub? @type == :stub end |
#times ⇒ Object
48 49 50 |
# File 'lib/mspec/mocks/proxy.rb', line 48 def times self end |
#twice ⇒ Object
79 80 81 |
# File 'lib/mspec/mocks/proxy.rb', line 79 def twice exactly 2 end |
#with(*args) ⇒ Object
88 89 90 91 92 93 94 95 |
# File 'lib/mspec/mocks/proxy.rb', line 88 def with(*args) raise ArgumentError, "you must specify the expected arguments" if args.empty? @arguments = *args if RUBY_VERSION >= '1.9' @arguments = @arguments.first if @arguments.length <= 1 end self end |
#yielding ⇒ Object
116 117 118 |
# File 'lib/mspec/mocks/proxy.rb', line 116 def yielding @yielding end |
#yielding? ⇒ Boolean
120 121 122 |
# File 'lib/mspec/mocks/proxy.rb', line 120 def yielding? !@yielding.empty? end |