2

This is my spec code that isn't working:

require 'spec_helper'

describe User do
  describe "blah" do
    it "should save itself" do
      user = User.make!
      u = User.find user.id
      user = User.make!
      u = User.find user.id
    end
  end
end

The spec fails on the 2nd User.find even though that user object has an id.

If I remove the 'describe "blah" do' block then the code seems to work fine. I'm using machinist 2.0.0.beta2.

If I disable machinist caching in my test.rb config file it also works:

Machinist.configure do |config|
  config.cache_objects = false
end

Anyone know what I'm doing wrong here? Is it a bad practice to nest multiple describes in a spec?

Thanks

nimblegorilla
  • 1,183
  • 2
  • 9
  • 19

1 Answers1

1

This should also work:

u = User.make
u.save

I run into this bug all the time using Machinist. I don't think it's exclusive to nesting describes, it seems pops up in other situations as well. Really wish they would fix this. It causes seemingly-random errors that are hard to track down.

Sky
  • 4,327
  • 4
  • 26
  • 40