How to test ActionText using RSpec?
In spec/rails_helper.rb
:
Require the helper file and include the module in the system specs:
require "action_text/system_test_helper"
RSpec.configure do |config|
config.include ActionText::SystemTestHelper, type: :system
end
You can now use the fill_in_rich_text_area
helper in your system specs:
fill_in_rich_text_area "page_content", with: "Some content."
…where "page_content"
is the id of the trix-editor.
The rich text area can also be found by the value of placeholder attribute, value of the aria-label attribute, the text from its label or by the name of its input.
The first argument can be omitted if you only have one editor on the page, like this:
fill_in_rich_text_area with: "Some content."
Here’s the script I’m using (just include it as a helper):
def fill_in_trix_editor(id, with:)
find(:css, "##{id}").click.set(with)
end
ActionText creates an underscored id of the model + attribute. You can also inspect to see.