这是我用于创建新帖子的功能规格测试
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
尝试上传图像,而不是使用真实的图像文件。这应该适合骗子吗? 最佳答案
该错误告诉您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/