can mocks be created with default attribute values? I am not certain what this question really mean. Two possibilities:
-
if an object
t=Movie.find(10), and then if I saym=mock(t), does m automatically inherit all the attribute values of t? -
is there a way to create a mock object with default attributes such that we can clone it everytime when we use it without going thru series stubs to
"initialize"those attributes?
Thanks for your help.
When it comes to 1) It does not have a sense. If inside the test you have an access to the real object through
Movie.find(10)you don’t have to use mocks. Assuming that you’re usingrspec_mocksand you’re going to write an assertion that particular method was called, you could simply write:Also check this out: https://www.relishapp.com/rspec/rspec-rails/v/2-11/docs/mocks/mock-model
and this https://www.relishapp.com/rspec/rspec-rails/v/2-11/docs/mocks/stub-model
Very useful helpers for mocking AR/Mongoid and other models in specs.
Along with
factory_girlyou could set an attributes on this mocks, for examplemovie = mock_model(Movie, FactoryGirl.attributes_for(:move))