这是我创建新帖子的功能规范测试
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,对吗?
最佳答案
该错误告诉您 Rails 找不到 FFaker::File
模块。 FFaker gem reference告诉我 FFaker 中实际上没有 FFaker::File
模块。
但是Faker里面有一个(Faker::File
)。由于 FFaker 只是重构了 Faker,我相信您可以使用 Faker 来满足您的需求。
关于ruby-on-rails - 功能测试错误 - 未初始化常量 FFaker::File,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42331783/