Class: MockProxy
Instance Attribute Summary collapse
-
#raising ⇒ Object
readonly
Returns the value of attribute raising.
-
#yielding ⇒ Object
readonly
Returns the value of attribute yielding.
Instance Method Summary collapse
- #and_raise(exception) ⇒ Object
- #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
- #raising? ⇒ Boolean
- #returning ⇒ Object
- #stub? ⇒ Boolean
- #times ⇒ Object
- #twice ⇒ Object
- #with(*args) ⇒ Object
- #yielding? ⇒ Boolean
Constructor Details
#initialize(type = nil) ⇒ MockProxy
Returns a new instance of MockProxy.
29 30 31 32 33 34 35 36 |
# 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 |
Instance Attribute Details
#raising ⇒ Object (readonly)
Returns the value of attribute raising.
27 28 29 |
# File 'lib/mspec/mocks/proxy.rb', line 27 def raising @raising end |
#yielding ⇒ Object (readonly)
Returns the value of attribute yielding.
27 28 29 |
# File 'lib/mspec/mocks/proxy.rb', line 27 def yielding @yielding end |
Instance Method Details
#and_raise(exception) ⇒ Object
128 129 130 131 132 133 134 |
# 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) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 |
# 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) ⇒ Object
140 141 142 143 |
# File 'lib/mspec/mocks/proxy.rb', line 140 def and_yield(*args) @yielding << args self end |
#any_number_of_times ⇒ Object
100 101 102 103 |
# File 'lib/mspec/mocks/proxy.rb', line 100 def any_number_of_times @count = [:any_number_of_times, 0] self end |
#arguments ⇒ Object
50 51 52 |
# File 'lib/mspec/mocks/proxy.rb', line 50 def arguments @arguments end |
#at_least(n) ⇒ Object
82 83 84 85 |
# File 'lib/mspec/mocks/proxy.rb', line 82 def at_least(n) @count = [:at_least, n_times(n)] self end |
#at_most(n) ⇒ Object
87 88 89 90 |
# File 'lib/mspec/mocks/proxy.rb', line 87 def at_most(n) @count = [:at_most, n_times(n)] self end |
#called ⇒ Object
73 74 75 |
# File 'lib/mspec/mocks/proxy.rb', line 73 def called @calls = calls + 1 end |
#calls ⇒ Object
69 70 71 |
# File 'lib/mspec/mocks/proxy.rb', line 69 def calls @calls ||= 0 end |
#count ⇒ Object
46 47 48 |
# File 'lib/mspec/mocks/proxy.rb', line 46 def count @count ||= mock? ? [:exactly, 1] : [:any_number_of_times, 0] end |
#exactly(n) ⇒ Object
77 78 79 80 |
# File 'lib/mspec/mocks/proxy.rb', line 77 def exactly(n) @count = [:exactly, n_times(n)] self end |
#mock? ⇒ Boolean
38 39 40 |
# File 'lib/mspec/mocks/proxy.rb', line 38 def mock? @type == :mock end |
#once ⇒ Object
92 93 94 |
# File 'lib/mspec/mocks/proxy.rb', line 92 def once exactly 1 end |
#raising? ⇒ Boolean
136 137 138 |
# File 'lib/mspec/mocks/proxy.rb', line 136 def raising? @raising != nil end |
#returning ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# 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? ⇒ Boolean
42 43 44 |
# File 'lib/mspec/mocks/proxy.rb', line 42 def stub? @type == :stub end |
#times ⇒ Object
65 66 67 |
# File 'lib/mspec/mocks/proxy.rb', line 65 def times self end |
#twice ⇒ Object
96 97 98 |
# File 'lib/mspec/mocks/proxy.rb', line 96 def twice exactly 2 end |
#with(*args) ⇒ Object
105 106 107 108 109 110 111 112 |
# 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? ⇒ Boolean
145 146 147 |
# File 'lib/mspec/mocks/proxy.rb', line 145 def yielding? !@yielding.empty? end |