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.
53 54 55 56 57 58 59 60 |
# File 'lib/extensions/mspec/mspec/mocks/proxy.rb', line 53 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.
51 52 53 |
# File 'lib/extensions/mspec/mspec/mocks/proxy.rb', line 51 def raising @raising end |
#yielding ⇒ Object (readonly)
Returns the value of attribute yielding.
51 52 53 |
# File 'lib/extensions/mspec/mspec/mocks/proxy.rb', line 51 def yielding @yielding end |
Instance Method Details
#and_raise(exception) ⇒ Object
153 154 155 156 157 158 159 |
# File 'lib/extensions/mspec/mspec/mocks/proxy.rb', line 153 def and_raise(exception) if exception.kind_of? String @raising = RuntimeError.new exception else @raising = exception end end |
#and_return(*args) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/extensions/mspec/mspec/mocks/proxy.rb', line 139 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
165 166 167 168 |
# File 'lib/extensions/mspec/mspec/mocks/proxy.rb', line 165 def and_yield(*args) @yielding << args self end |
#any_number_of_times ⇒ Object
124 125 126 127 |
# File 'lib/extensions/mspec/mspec/mocks/proxy.rb', line 124 def any_number_of_times @count = [:any_number_of_times, 0] self end |
#arguments ⇒ Object
74 75 76 |
# File 'lib/extensions/mspec/mspec/mocks/proxy.rb', line 74 def arguments @arguments end |
#at_least(n) ⇒ Object
106 107 108 109 |
# File 'lib/extensions/mspec/mspec/mocks/proxy.rb', line 106 def at_least(n) @count = [:at_least, n_times(n)] self end |
#at_most(n) ⇒ Object
111 112 113 114 |
# File 'lib/extensions/mspec/mspec/mocks/proxy.rb', line 111 def at_most(n) @count = [:at_most, n_times(n)] self end |
#called ⇒ Object
97 98 99 |
# File 'lib/extensions/mspec/mspec/mocks/proxy.rb', line 97 def called @calls = calls + 1 end |
#calls ⇒ Object
93 94 95 |
# File 'lib/extensions/mspec/mspec/mocks/proxy.rb', line 93 def calls @calls ||= 0 end |
#count ⇒ Object
70 71 72 |
# File 'lib/extensions/mspec/mspec/mocks/proxy.rb', line 70 def count @count ||= mock? ? [:exactly, 1] : [:any_number_of_times, 0] end |
#exactly(n) ⇒ Object
101 102 103 104 |
# File 'lib/extensions/mspec/mspec/mocks/proxy.rb', line 101 def exactly(n) @count = [:exactly, n_times(n)] self end |
#mock? ⇒ Boolean
62 63 64 |
# File 'lib/extensions/mspec/mspec/mocks/proxy.rb', line 62 def mock? @type == :mock end |
#once ⇒ Object
116 117 118 |
# File 'lib/extensions/mspec/mspec/mocks/proxy.rb', line 116 def once exactly 1 end |
#raising? ⇒ Boolean
161 162 163 |
# File 'lib/extensions/mspec/mspec/mocks/proxy.rb', line 161 def raising? @raising != nil end |
#returning ⇒ Object
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/extensions/mspec/mspec/mocks/proxy.rb', line 78 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
66 67 68 |
# File 'lib/extensions/mspec/mspec/mocks/proxy.rb', line 66 def stub? @type == :stub end |
#times ⇒ Object
89 90 91 |
# File 'lib/extensions/mspec/mspec/mocks/proxy.rb', line 89 def times self end |
#twice ⇒ Object
120 121 122 |
# File 'lib/extensions/mspec/mspec/mocks/proxy.rb', line 120 def twice exactly 2 end |
#with(*args) ⇒ Object
129 130 131 132 133 134 135 136 137 |
# File 'lib/extensions/mspec/mspec/mocks/proxy.rb', line 129 def with(*args) raise ArgumentError, "you must specify the expected arguments" if args.empty? @arguments = *args behaves_like_ruby_1_9 = *[] if (behaves_like_ruby_1_9) @arguments = @arguments.first if @arguments.length <= 1 end self end |
#yielding? ⇒ Boolean
170 171 172 |
# File 'lib/extensions/mspec/mspec/mocks/proxy.rb', line 170 def yielding? !@yielding.empty? end |