Skip to content

Instantly share code, notes, and snippets.

Created May 9, 2013
What would you like to do?
A guide for implementing Maruku as the markdown engine instead of Redcarpet in Reinteractive's InstallFest blog guides.

In your Gemfile install the Maruku gem by putting:

gem 'maruku'

at the bottom. Make sure you delete the redcarpet and rouge gems since you won't be using those. Run bundle install to install the gem.

Open spec/services/markdown_service_spec.rb and set the content to be:

require 'spec_helper'

describe MarkdownService do
  it { should be_a MarkdownService }

  describe '#render' do
    # the markdown engine is just a test double we can monitor in our test
    let(:markdown_engine) { double('Markdown') }

    before do
      Maruku.stub(:new) { markdown_engine }

    it 'should delegate to the markdown engine' do
      # Set up the expectation of what our code should accomplish

You can run this spec which will fail with rspec spec/services/markdown_service_spec.rb.

Open: app/services/markdown_service.rb which will look like:

class MarkdownService
  def render(text)

This might be a small class but wrapping the Maruku class like this means we can easily switch between different markdown engines without changing any other areas in our application.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment