In a Rails app, I'm writing Minitest unit tests for a helper class which generates and returns some HTML (to be used as the body content of an outgoing email message). I'm using assert_select
to verify that a particular element is present in the generated HTML.
When the test is run, the line with the assert_select
throws this error:
Minitest::UnexpectedError: NotImplementedError: Implementing document_root_element makes assert_select work without needing to specify an element to select from.
Here's my (minimal/simplified) test class code:
class MyEmailBodyGeneratorTest < ActiveSupport::TestCase
include Rails::Dom::Testing::Assertions
def test_generate_email_body
generator = MyEmailBodyGenerator.new
generator.generate_email_body
assert_select 'p.salutation', count: 1
end
end
What does that error about implementing document_root_element
mean? I don't have a method with that name in my code.