| |   |
| 54 | 54 | |
| 55 | 55 | # :call-seq: |
| 56 | 56 | # stub_model(Model) |
| 57 | # stub_model(Model).as_new_record |
| 57 | 58 | # stub_model(Model, hash_of_stubs) |
| 58 | 59 | # |
| 59 | 60 | # Creates an instance of +Model+ that is prohibited from accessing the |
| 60 | 61 | # database. For each key in +hash_of_stubs+, if the model has a |
| 61 | 62 | # matching attribute (determined by asking it, which it answers based |
| 62 | 63 | # 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. |
| 65 | 66 | # |
| 66 | 67 | # 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. |
| 70 | 77 | # |
| 71 | 78 | # == Examples |
| 72 | 79 | # |
| 73 | 80 | # stub_model(Person) |
| 81 | # stub_model(Person).as_new_record |
| 74 | 82 | # stub_model(Person, :id => 37) |
| 75 | 83 | # stub_model(Person) do |person| |
| 76 | 84 | # model.first_name = "David" |
| toggle raw diff |
--- a/rspec_on_rails/lib/spec/rails/example/rails_example_group.rb
+++ b/rspec_on_rails/lib/spec/rails/example/rails_example_group.rb
@@ -54,23 +54,31 @@ module Spec
# :call-seq:
# stub_model(Model)
+ # stub_model(Model).as_new_record
# stub_model(Model, hash_of_stubs)
#
# Creates an instance of +Model+ that is prohibited from accessing the
# database. For each key in +hash_of_stubs+, if the model has a
# matching attribute (determined by asking it, which it answers based
# on schema.rb) are simply assigned the submitted values. If the model
- # does not have a matching attribute, the key/value pair is assigned as
- # a stub return value using RSpec's mocking/stubbing framework.
+ # does not have a matching attribute, the key/value pair is assigned
+ # as a stub return value using RSpec's mocking/stubbing framework.
#
# new_record? is overridden to return the result of id.nil? This means
- # that by default new_record? will return false. If you explicitly set
- # :id => nil, the object will behave as you would expect, and return
- # true for new_record?
+ # that by default new_record? will return false. If you want the
+ # object to behave as a new record, sending it +as_new_record+ will
+ # set the id to nil. You can also explicitly set :id => nil, in which
+ # case new_record? will return true, but using +as_new_record+ makes
+ # the example a bit more descriptive.
+ #
+ # While you can use stub_model in any example (model, view,
+ # controller, helper), it is especially useful in view examples,
+ # which are inherently more state-based than interaction-based.
#
# == Examples
#
# stub_model(Person)
+ # stub_model(Person).as_new_record
# stub_model(Person, :id => 37)
# stub_model(Person) do |person|
# model.first_name = "David" |