Class | Spec::Rails::Example::RailsExampleGroup |
In: |
vendor/plugins/rspec_on_rails/lib/spec/rails/example/rails_example_group.rb
|
Parent: | Test::Unit::TestCase |
Creates a mock object instance for a model_class with common methods stubbed out. Additional methods may be easily stubbed (via add_stubs) if stubs is passed.
# File vendor/plugins/rspec_on_rails/lib/spec/rails/example/rails_example_group.rb, line 23 23: def mock_model(model_class, options_and_stubs = {}) 24: # null = options_and_stubs.delete(:null_object) 25: # stubs = options_and_stubs 26: id = @@model_id 27: @@model_id += 1 28: options_and_stubs = { 29: :id => id, 30: :to_param => id.to_s, 31: :new_record? => false, 32: :errors => stub("errors", :count => 0) 33: }.merge(options_and_stubs) 34: m = mock("#{model_class.name}_#{id}", options_and_stubs) 35: m.send(:__mock_proxy).instance_eval "def @target.is_a?(other)\n\#{model_class}.ancestors.include?(other)\nend\ndef @target.kind_of?(other)\n\#{model_class}.ancestors.include?(other)\nend\ndef @target.instance_of?(other)\nother == \#{model_class}\nend\ndef @target.class\n\#{model_class}\nend\n" 36: yield m if block_given? 37: m 38: end