vendor/gems/flexmock-0.8.5/lib/flexmock/mock_container.rb
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.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
# Automatically add mocks for some common methods in ActiveRecord
# models.
Automatically add mocks for some common methods in ActiveRecord
models.
Automatically add mocks for some common methods in ActiveRecord models .
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.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
      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
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 . 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 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
Automatically add mocks for some common methods in ActiveRecord
models.
Automatically add mocks for some common methods in ActiveRecord models .
# HACK: Ruby 1.9 needs the following lambda so that model_class # is correctly bound below.
mock
model_class
id