machinist icon indicating copy to clipboard operation
machinist copied to clipboard

rspec issue: no master blueprint defined

Open wulftone opened this issue 13 years ago • 3 comments

I keep getting this intermittent error:

 Machinist::NoBlueprintError:
   No master blueprint defined for class User

When I have clearly defined the blueprints and spork has loaded them. It pops up on capybara specs more than any others, though I have had it pop up on some non-integration specs. I can't seem to find a consistent way to replicate it. Sometimes I'll run a spec in isolation and it will work fine, but when I run the suite, it will break. Sometimes an individual spec will break it. It's quite strange.

Can I get some help tracking this issue down? Pointers?

Thanks!

wulftone avatar Jan 26 '12 23:01 wulftone

If it only happens when many examples are run together, and you're using spork, it's almost certainly a code reloading issue.

I'd guess the issue is that the already-defined blueprints don't match against the newly reloaded User class, which is a new object with no relation to the old one.

If you can find a smallish set of examples that consistently produce the error, try running them without spork.

benhoskings avatar Jan 26 '12 23:01 benhoskings

That makes sense, and I took a stroll through the source code to see if they had a reload command like FactoryGirl.reload to put in my Spork.each_run block, and there is something close: clear_blueprints!, although I haven't been able to get it working very well.

I wanted an automatic way to see what classes have blueprints enabled and then iterate through them, doing a clear_blueprints! on each one, then reloading the blueprints file. Here's what I came up with:

module BlueprintHelpers
  class Class
    def extend?(klass)
      not superclass.nil? and ( superclass == klass or superclass.extend? klass )
    end
  end

  def models
    Module.constants.select do |constant_name|
      constant = Object.const_get(constant_name)
      not constant.nil? and constant.is_a? Class and constant.extend? ActiveRecord::Base
    end
  end

  def clear_blueprints!
    models.each do |klass|
      constant = Object.const_get(klass)
      constant.clear_blueprints! if constant.respond_to? :make
    end
  end
end

Which appears to work in the console, but I can't get it running in Spork.each_run. Stumped again.

wulftone avatar Jan 27 '12 01:01 wulftone

I am trying to find a solution for this as well, if anyone comes up with a nice way to reload them just as FactoryGirl.reload does it, please let us know :)

flov avatar Jul 10 '12 01:07 flov