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

FactoryGirl DSL clashing with Rake DSL? #427

Closed
wilg opened this issue Aug 23, 2012 · 3 comments
Closed

FactoryGirl DSL clashing with Rake DSL? #427

wilg opened this issue Aug 23, 2012 · 3 comments

Comments

@wilg
Copy link

wilg commented Aug 23, 2012

Given the following factory:

FactoryGirl.define do
    factory :release do 
        file { File.new File.join(Rails.root, 'spec', 'fixtures', 'file.txt') }
    end
end

Running rspec generates the following warnings:

WARNING: Global access to Rake DSL methods is deprecated.  Please include
    ...  Rake::DSL into classes and modules which use the Rake DSL methods.
WARNING: DSL method #<FactoryGirl::Declaration::Implicit:0x007fe0488292b0>
#file called at [...]/spec/factories/releases_factory.rb:5:in `block (2 levels) in <top (required)>'

And using the factory fails with:

Trait not registered: class

I'm using this with Rails, and I have a Paperclip attachment called file.

I think this is Rake's DSL conflicting with FactoryGirl's. Clearly Rake's is deprecated, but I don't want to use an old version of rake just to get this to work. Is there a workaround? Or am I missing something?

Someone's reported a similar situation at rubyist/guard-rake#17

@joshuaclayton
Copy link
Contributor

Yeah, it sounds like you're dealing with Rake here, which is a shame. We try to remove as many methods as possible so there are no clashes, but some of the Rake code sneaks in. In instances like this, you'll have to use add_attribute directly:

factory :release do
  add_attribute(:file) do
    File.new #...
  end
end

Let me know how it goes!

@wilg
Copy link
Author

wilg commented Aug 24, 2012

Aha, I was looking all over for add_attribute. I had ended up using an after(:build). Thanks!

Also, it sounds like you're saying there's no solution on FactoryGirl's end? I guess there's no way to show Rake the door in this case?

@joshuaclayton
Copy link
Contributor

There's not, sadly; it adds methods to Object; we try as best we can to remove them, but some still slip through. Hooray for monkey-patching core libraries!

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

2 participants