这是我用于创建新帖子
的功能规格测试require 'rails_helper'
require 'ffaker'
RSpec.feature 'Creating posts', :type => :feature do
scenario 'can create a new post' do
visit root_path
click_link 'New Post'
attach_file('Image', FFaker::File.file_name('spec/files', 'foo', 'jpg'))
fill_in 'Caption', with: 'Hello World! This is the first post!'
click_button 'Create Post'
expect(page).to have_content('Post was successfully created')
end
end
运行rspec
命令运行测试时,我会收到以下错误
Failure/Error: attach_file('Image', FFaker::File.file_name('spec/files', 'foo', 'jpg'))
NameError:
uninitialized constant FFaker::File
我该如何解决?
基本上,我使用ffaker
尝试上传图像而不是使用真实的图像文件。这应该与FFAKER一起使用吗?
错误告诉您,导轨找不到FFaker::File
模块。FFAKER GEM参考告诉我,FFAKER中实际上没有FFaker::File
模块。
,但是Faker中有一个(Faker::File
)。而且,由于FFAKER只是重构的Faker,我相信您可以将Faker用于您的需要。