Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rspec issue: no master blueprint defined #108

Open
wulftone opened this issue Jan 26, 2012 · 3 comments
Open

rspec issue: no master blueprint defined #108

wulftone opened this issue Jan 26, 2012 · 3 comments

Comments

@wulftone
Copy link

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!

@benhoskings
Copy link
Collaborator

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.

@wulftone
Copy link
Author

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.

@flov
Copy link

flov commented Jul 10, 2012

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants