System notice: In light of the Debian OpenSSL security issue we've regenerated the server keys. See this thread for instructions and the new key fingerprints.

Commit b299ac775e92c788c06a36381fdcb1277149b761

enhanced stub_model rdoc

Commit diff

rspec_on_rails/lib/spec/rails/example/rails_example_group.rb

 
5454
5555 # :call-seq:
5656 # stub_model(Model)
57 # stub_model(Model).as_new_record
5758 # stub_model(Model, hash_of_stubs)
5859 #
5960 # Creates an instance of +Model+ that is prohibited from accessing the
6061 # database. For each key in +hash_of_stubs+, if the model has a
6162 # matching attribute (determined by asking it, which it answers based
6263 # on schema.rb) are simply assigned the submitted values. If the model
63 # does not have a matching attribute, the key/value pair is assigned as
64 # a stub return value using RSpec's mocking/stubbing framework.
64 # does not have a matching attribute, the key/value pair is assigned
65 # as a stub return value using RSpec's mocking/stubbing framework.
6566 #
6667 # new_record? is overridden to return the result of id.nil? This means
67 # that by default new_record? will return false. If you explicitly set
68 # :id => nil, the object will behave as you would expect, and return
69 # true for new_record?
68 # that by default new_record? will return false. If you want the
69 # object to behave as a new record, sending it +as_new_record+ will
70 # set the id to nil. You can also explicitly set :id => nil, in which
71 # case new_record? will return true, but using +as_new_record+ makes
72 # the example a bit more descriptive.
73 #
74 # While you can use stub_model in any example (model, view,
75 # controller, helper), it is especially useful in view examples,
76 # which are inherently more state-based than interaction-based.
7077 #
7178 # == Examples
7279 #
7380 # stub_model(Person)
81 # stub_model(Person).as_new_record
7482 # stub_model(Person, :id => 37)
7583 # stub_model(Person) do |person|
7684 # model.first_name = "David"
toggle raw diff