RSpec.describe Redcarpet::TrustedRenderer do let(:view_context) { ActionController::Base.new.view_context } subject(:renderer) { Redcarpet::Markdown.new(described_class.new(view_context), autolink: true) } context 'when rendering links' do it 'renders internal links without target and rel attributes' do markdown = "[Click here](/internal)" expect(renderer.render(markdown)).to include('Click here') end it 'renders external links with target="_blank" and rel="noopener noreferrer"' do markdown = "[Visit](http://example.com)" expect(renderer.render(markdown)).to include('Visit') end end context 'when rendering images' do it 'renders an image tag with lazy loading' do markdown = "![A cute cat](http://example.com/cat.jpg)" expect(renderer.render(markdown)).to include('A cute cat') end end context 'when autolinking' do it 'autolinks URLs' do markdown = "Visit http://example.com" expect(renderer.render(markdown)).to include('Visit http://example.com') end it 'autolinks email addresses with mailto' do markdown = "Email user@example.com" expect(renderer.render(markdown)).to include('user@example.com') end end end