################################################################# Helper methods for mock containers. MockContainer is a module that is designed to be mixed into other classes, particularly testing framework test cases. Since we don‘t want to pollute the method namespace of the class that mixes in MockContainer, a number of MockContainer methods were moved into ContainerHelper to to isoloate the names.

Methods
Included Modules
Constants
METHOD_NAME_RE = /^([A-Za-z_][A-Za-z0-9_]*[=!?]?|\[\]=?||\*\*|<<|>>|<=>|[<>=]=|=~|===|[-+]@|[-+\*\/%&^|<>~`])$/
Public Instance methods
add_model_methods(mock, model_class, id)

Automatically add mocks for some common methods in ActiveRecord models.

     # File lib/flexmock/mock_container.rb, line 212
212:     def add_model_methods(mock, model_class, id)
213:       container = mock.flexmock_container
214: 
215:       mock_errors = container.flexmock("errors")
216:       mock_errors.should_receive(:count).and_return(0).by_default
217:       mock_errors.should_receive(:full_messages).and_return([]).by_default
218: 
219:       mock.should_receive(:id).and_return(id).by_default
220:       mock.should_receive(:to_params).and_return(id.to_s).by_default
221:       mock.should_receive(:new_record?).and_return(false).by_default
222:       mock.should_receive(:class).and_return(model_class).by_default
223:       mock.should_receive(:errors).and_return(mock_errors).by_default
224: 
225:       # HACK: Ruby 1.9 needs the following lambda so that model_class
226:       # is correctly bound below.
227:       lambda { }
228:       mock.should_receive(:is_a?).with(any).and_return { |other|
229:         other == model_class
230:       }.by_default
231:       mock.should_receive(:instance_of?).with(any).and_return { |other|
232:         other == model_class
233:       }.by_default
234:       mock.should_receive(:kind_of?).with(any).and_return { |other|
235:         model_class.ancestors.include?(other)
236:       }.by_default
237:     end
make_partial_proxy(container, obj, name, safe_mode)

Create a PartialMockProxy for the given object. Use name as the name of the mock object.

     # File lib/flexmock/mock_container.rb, line 241
241:     def make_partial_proxy(container, obj, name, safe_mode)
242:       name ||= "flexmock(#{obj.class.to_s})"
243:       if !obj.instance_variable_defined?("@flexmock_proxy") || obj.instance_variable_get("@flexmock_proxy").nil?
244:         mock = FlexMock.new(name, container)
245:         proxy = PartialMockProxy.new(obj, mock, safe_mode)
246:         obj.instance_variable_set("@flexmock_proxy", proxy)
247:       end
248:       obj.instance_variable_get("@flexmock_proxy")
249:     end
next_id()

Return the next id for mocked models.

     # File lib/flexmock/mock_container.rb, line 181
181:     def next_id
182:       @id_counter ||= 10000
183:       @id_counter += 1
184:     end