【发布时间】:2019-12-10 16:21:59
【问题描述】:
我正在尝试编写一个涉及在页面上填写 ActionText / Trix 字段的 RSpec 系统测试。
似乎ActionText::SystemTestHelper 定义为here 可以帮助完成这项任务,但到目前为止我还没有成功实施它。
我的 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
【问题讨论】:
标签: ruby-on-rails rspec ruby-on-rails-6 trix actiontext