我正在尝试编写一个RSpec系统测试,其中包括在页面上填写一个ActionText / Trix字段。
似乎可以使用定义为ActionText::SystemTestHelper的这里来帮助完成这项任务,但到目前为止,我还没有成功地实现它。
我的RSpec测试如下所示:
# spec/system/add_job_posting_spec.rb
require 'rails_helper'
RSpec.describe 'adding a job posting', type: :system do
let(:user) { FactoryBot.create :user }
before do
login_as(user)
visit new_job_posting_path
end
context 'with valid information' do
let(:valid_job_posting) { FactoryBot.create :job_posting }
scenario 'creates a job posting', js: true do
fill_in 'Title', with: valid_job_posting.title
fill_in_rich_text_area 'Description', with: 'Job Info'
click_button 'Submit'
expect(page).to have_content 'Job was successfully created.'
end
end
end我还尝试创建这样一个RSpec支持文件
# spec/support/action_text.rb
RSpec.configure do |config|
config.include ActionText::SystemTestHelper, type: :system
end当我运行这个程序时
bundle exec rspec spec/system/add_job_posting_spec.rb我得到以下错误:未初始化的常量ActionText::SystemTestHelper
当我试图删除位于spec/support/action_text.rb的文件时,我会得到以下错误:
未定义方法`fill_in_rich_text_area'
我也尝试过使用常规的fill_in RSpec方法来完全避免这种情况,但随后得到了如下结果:
无法找到未禁用的字段“描述”
尽管测试标记为js: true,而且我还有另一个RSpec支持文件来处理设置,如下所示:
# spec/support/system/driver.rb
RSpec.configure do |config|
config.before(:each, type: :system) do
driven_by :rack_test
end
config.before(:each, type: :system, js: true) do
ActiveRecord::Base.establish_connection
driven_by :selenium_chrome_headless
end
end发布于 2020-12-12 20:27:33
在spec/rails_helper.rb中
需要帮助文件并将模块包括在系统规范中:
require "action_text/system_test_helper"
RSpec.configure do |config|
config.include ActionText::SystemTestHelper, type: :system
end现在可以在系统规范中使用fill_in_rich_text_area助手:
fill_in_rich_text_area "page_content", with: "Some content."…其中"page_content"是trix编辑器的id。
还可以通过占位符属性值、aria-label属性的值、其标签中的文本或其输入的名称来找到富文本区域。
如果页面上只有一个编辑器,则可以省略第一个参数,如下所示:
fill_in_rich_text_area with: "Some content."发布于 2019-10-11 13:39:51
我不是百分之百确定,但看起来ActionText::SystemTestHelper可能还没有发布到一个“稳定”版本的Rails。它可能会伴随下一个版本(或者您正在运行的是一个还没有包含它的旧版本)。
有几件事你可以尝试:
master Rails版本(不推荐)https://stackoverflow.com/questions/57319708
复制相似问题