Object
################################################################# 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.
Automatically add mocks for some common methods in ActiveRecord models.
# File lib/flexmock/mock_container.rb, line 222 def add_model_methods(mock, model_class, id) container = mock.flexmock_container mock_errors = container.flexmock("errors") mock_errors.should_receive(:count).and_return(0).by_default mock_errors.should_receive(:full_messages).and_return([]).by_default mock.should_receive(:id).and_return(id).by_default mock.should_receive(:to_params).and_return(id.to_s).by_default mock.should_receive(:new_record?).and_return(false).by_default mock.should_receive(:class).and_return(model_class).by_default mock.should_receive(:errors).and_return(mock_errors).by_default # HACK: Ruby 1.9 needs the following lambda so that model_class # is correctly bound below. lambda { } mock.should_receive(:is_a?).with(any).and_return { |other| other == model_class }.by_default mock.should_receive(:instance_of?).with(any).and_return { |other| other == model_class }.by_default mock.should_receive(:kind_of?).with(any).and_return { |other| model_class.ancestors.include?(other) }.by_default end
Create a PartialMockProxy for the given object. Use name as the name of the mock object.
# File lib/flexmock/mock_container.rb, line 251 def make_partial_proxy(container, obj, name, safe_mode) name ||= "flexmock(#{obj.class.to_s})" if !obj.instance_variable_defined?("@flexmock_proxy") || obj.instance_variable_get("@flexmock_proxy").nil? mock = FlexMock.new(name, container) proxy = PartialMockProxy.new(obj, mock, safe_mode) obj.instance_variable_set("@flexmock_proxy", proxy) end obj.instance_variable_get("@flexmock_proxy") end
Generated with the Darkfish Rdoc Generator 2.