[rspec-users] Mock "Consent_6335" received unexpected message :marked_for_destruction? with (no args)

David Chelimsky dchelimsky at gmail.com
Thu Mar 25 07:39:12 EDT 2010


On Wed, Mar 24, 2010 at 1:49 PM, thoen <thoen at edgevaleinteractive.com> wrote:
> On Mar 24, 2:39 pm, thoen <th... at edgevaleinteractive.com> wrote:
>> I have a mock object (Person) that is associated with another object
>> (my_object) through a belongs_to association. When I check whether
>> my_object is valid (my_object.should be_valid), I am getting an error
>> like the following:
>>
>> Mock "Person_6338" received unexpected
>> message :marked_for_destruction? with (no args)
>>
>> Checking the list of methods on the mock, "marked_for_destruction?" is
>> not listed. Is this this something that i should expect to always
>> stub?
>>
>> As a check, I added
>>
>>           def  @target.marked_for_destruction?
>>             false
>>           end
>>
>> to the mock_model definition and the test passed.
>>
>> Rails 2.3.5
>> rspec (1.3.0, 1.2.6, 1.1.3)
>> rspec-rails (1.3.2, 1.2.6)

> Instead of
>
> def  @target.marked_for_destruction?
>    false
> end
>
> i added marked_for_destruction in the list of stubs included in
> mock_model
>
>        options_and_stubs = options_and_stubs.reverse_merge({
>          :id => id,
>          :to_param => id.to_s,
>          :new_record? => false,
>          :destroyed? => false,
>          :marked_for_destruction? => false,
>          :errors => stub("errors", :count => 0)
>        })
>
> This seemed like a better place.

http://github.com/dchelimsky/rspec-rails/commit/ad76867f28cb0ca05925e74eacb4cf81b934ce27

It'll be part of rspec-rails-1.3.3


More information about the rspec-users mailing list