我有工厂
FactoryBot.define do
factory :activity_fit_file do
association :user, factory: :user
activity_type {:cycling}
after(:build) do |activity|
activity.original_activity_log_file.attach(
io: File.open("#{Rails.root}/spec/files/example_fit_file.fit"),
filename: 'example_fit_file.fit',
content_type: 'application/vnd.ant.fit'
)
end
end
end
在我的规范中我有
require 'rails_helper'
RSpec.describe "Activity upload fixer" do
it 'converts fit files to gpx' do
activity = FactoryBot.create(:activity_fit_file)
end
end
运行规范给出错误
NameError:
uninitialized constant ActivityFitFile
不太确定哪里出了问题,因为它看起来和其他工作工厂一样。
您可以自定义工厂名称,但您必须指定实际的类。
factory :activity_fit_file, class: 'Activity' do
···
end
我是一名优秀的程序员,十分优秀!