Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7671965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:10:40+00:00 2026-05-31T16:10:40+00:00

I have a markdown helper that looks like this in application_helper.rb . How would

  • 0

I have a markdown helper that looks like this in application_helper.rb.

How would you go about writing a test for something like this? Also, is this the best way to generate simple HTML from markdown?

Thanks!

def markdown(text)
  Redcarpet::Markdown.new(Redcarpet::Render::HTML, :autolink => true, :space_after_headers => true).render(text).html_safe
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T16:10:41+00:00Added an answer on May 31, 2026 at 4:10 pm

    Two options come to mind:

    1. Stub out Redcarpet::Markdown and create an expectation of what it should receive:

      expect(Redcarpet::Markdown).to receive(:new).with(...) # `with` args omitted for brevity
      markdown(text)
      

      The problem here is that the coupling between the method and the test is very high. It’s very difficult to refactor the method without breaking the test, even though the method actually functions the same.

    2. Assert the correctness of the output text directly:

      expect(markdown(text)).to eq 'This is markdownified'
      

      This allows you to refactor better, but it seems more like an integration test, not a unit test, and is almost testing Redcarpet more than your own method. Unit tests should usually assume that the external methods they call work correctly.

    This is one of those cases where testing feels redundant to me since the method is just a thin wrapper around another, and I would not be against not unit testing it, and rather ensuring that you have an integration test—if this is by having your spec be an integration test, then that’s probably okay.

    It’s ultimately all up to you and your TDD workflow and overall testing principles though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assume that I have some HTML code, like this (generated from Markdown or Textile
If I have markdown like this: # A Header ``` javascript $(document).ready(function() {}) ```
I would like to have a higher number in my linespace setting for markdown
I've just recently begun to use markdown and have noticed that any markdown within
If any of you have ever used wmd markdown editor (which is like the
I'm working on a commenting system that uses Markdown and I want to have
I want to have independent .markdown files that I then include in my haml
I have a little script that compiles a markdown file into html, and inserts
I have a small vim script that queries Google to insert links in markdown-formatted
If I have some Markdown like ## My Title A paragraph of content here.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.