我正在尝试编写一个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