Sha256: a16a2f0cdb49df59ba92765bbd51d9d8e87f799efc62d36004a740aa95eae912

Contents?: true

Size: 1.82 KB

Versions: 4

Compression:

Stored size: 1.82 KB

Contents

require 'greenmat'

module Greenmat
  RSpec.describe Markdown do
    subject(:markdown) { Markdown.new(renderer, options) }
    let(:renderer) { Render::HTML.new }
    let(:options) { {} }
    let(:rendered_html) { markdown.render(text) }

    context 'with no_mention_emphasis option' do
      let(:options) { { no_mention_emphasis: true } }

      [
        ['@_username_',         false],
        ['@__username__',       false],
        ['@___username___',     false],
        ['@user__name__',       false],
        ['@some__user__name__', false],
        [' @_username_',        false],
        ['あ@_username_',       false],
        ['A@_username_',        true],
        ['@*username*',         true],
        ['_foo_',               true],
        ['_',                   false],
        ['_foo @username_',     false],
        ['__foo @username__',   false],
        ['___foo @username___', false]
      ].each do |text, emphasize|
        context "with text #{text.inspect}" do
          let(:text) { text }

          if emphasize
            it 'emphasizes the text' do
              expect(rendered_html).to include('<em>').or include('<strong>')
            end
          else
            it 'does not emphasize the text' do
              expect(rendered_html.chomp).to eq("<p>#{text.strip}</p>")
            end
          end
        end
      end
    end

    context 'without no_mention_emphasis option' do
      let(:options) { {} }

      context 'with text "@_username_"' do
        let(:text) { '@_username_' }

        it 'emphasizes the text' do
          expect(rendered_html).to include('<em>')
        end
      end

      context 'with text "_foo @username_"' do
        let(:text) { '_foo @username_' }

        it 'emphasizes the text' do
          expect(rendered_html).to include('<em>')
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
greenmat-3.2.2.2 spec/greenmat/markdown_spec.rb
greenmat-3.2.2.1 spec/greenmat/markdown_spec.rb
greenmat-3.2.2.0 spec/greenmat/markdown_spec.rb
greenmat-3.2.0.2 spec/greenmat/markdown_spec.rb