I've run into a snag while trying to test a Rails 4 engine using miniskirt.
I have a model test set up in test/models/job_manager/job_test.rb:
require 'test_helper'
module JobManager
describe Job do
before do
@job = Factory.build(:job)
end
it "is a valid object" do
@job.valid?.must_equal true
end
end
end
My miniskirt factory is currently defined as:
module JobManager
Factory.define :job do |j|
j.title 'Job Title %d'
j.description 'Lorem ipusum dolor sit amet consecateur ad piscin'
end
end
And the error I get is:
uninitialized constant Job
Exception `NameError' at:
… which traces back to line 6 in the model test (@job = Factory.build(:job)). Replacing it with @job = Job.new works fine, but then I'm not using miniskirt factories any more. I get this error whether the factory is defined in the JobManager module or not.
As per Stephen Celis,
Factory.definedoesn't use the current scope to resolve constants. This solved the problem:See https://github.com/stephencelis/miniskirt/issues/19.