[rspec-users] calbacks on models

David Chelimsky dchelimsky at gmail.com
Thu Mar 3 09:11:28 EST 2011


On Mar 2, 2011, at 11:49 AM, Andrea Reginato wrote:

> Hi, I'm having some strange behavior on callbacks when testing with
> RSpec2. On my test, when I create a resource using the #create method
> the callbacks related to #before_create are not called. If I go to the
> console and I try to type the command Resource.create(client_uri:
> "http://example.com") all works fine.
> 
> There are no mocks around, and I can't understand if this is a normal
> behavior using RSpec, if its due to Mongoid or something else.
> 
>  # resource.rb (model)
>  class Resource
>    include Mongoid::Document
>    before_create :random_code, :create_expiration
> 
>  # resource_rspec.rb (testing suite)
>    let(:resource)  { Resource.create(client_uri: "http://example.com")
> 
> Thanks a lot

There's nothing in RSpec that implicitly interrupts the normal life cycle of any model objects. You can do so with stubs, but you have to do it explicitly.

Is anybody else on this list having a similar experience?


More information about the rspec-users mailing list