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
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?
OK, found the problem and it’s not rspec - my bad…
Turns out that my spork config using guard etc. does not reload model files
as it should - looking into that next
Reloading spork (or killing it and running native) and all tests work as
expected.
Sorry for time waste
H
I’ve seen this same problem with a very similar setup. I believe it’s
got to do with the way devise loads up the user model when routes are
loaded, so basically it’s a problem between spork and devise. (I use
guard as well, but I don’t think it is related.)
Have a look at the very latest spork (0.9.0.rc4) on github - I can’t
recall
where I saw it mentioned yesterday but the combo of that devise fix you
linked to and upgrading spork seems to be working for me now…
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.