Minitest Cheat Sheet

Minitest cheatsheet Rake cheatsheet Rspec-rails cheatsheet Top cheatsheets. Elixir cheatsheet ES2015+ cheatsheet React.js cheatsheet Vimdiff cheatsheet Vim cheatsheet. Ruby MiniTest Cheat Sheet, Unit and Spec reference Ruby’s standard testing suite, MiniTest, is in dire need of a quick-and-handy reference for its syntax. I’ve put one together comparing the unit syntax (assert/refute) and the spec syntax (must/wont). For more help with writing tests with Minitest, I highly recommend The Minitest Cheat Sheet by Chris Kottom. It includes both assert-style and spec-style method references with descriptions.

As more developers have started to use Minitest, the number of resources available for learning about the framework has gradually been growing. We’ve never been short on cheat sheets or references, but as the community has grown, we’ve seen more and more articles focused on specific aspects of the framework being published. That’s good for everyone involved.

One area where there’s still very little information available, though, is Minitest benchmarks. If you’ve looked into the framework at all, you’re probably aware that it allows developers to make assertions about the performance of the code they write. Still, most developers never or rarely use this feature or understand what it does or how to get started. In this first post of a three-part series, I want to explain what Minitest::Benchmark is and how it works in a clear, easy to understand way.

What’s a benchmark good for?

The word benchmark is seriously overloaded within the IT domain, so developers make all kinds of assumptions about what Minitest::Benchmark is and does. Well, at least I did. Before I started digging into it, I’d always assumed that benchmarks were a tool for demonstrating that a given piece of code could be executed within a certain time limit. But think about that for a moment. Pass or fail, what would the absolute performance of a given amount of work within a testing environment tell me about the performance of my application in production? Practically nothing of value. While my definition wasn’t exactly wrong, it wasn’t complete either.

Here’s what I found: a Benchmark in Minitest is a specialized test (actually a subclass of Minitest::Test) that executes the same block of code repeatedly with varied inputs to show the relative performance of the algorithm against increasing demands. It does not assert, for example, that a method or chunk of code will execute within a given duration; rather, it makes predictions about how execution time will change with different inputs and workloads.


In order to clarify what a Benchmark does, we’ll want to understand it as a process with four steps:

  1. Define a range of inputs.
  2. Assert the performance of your algorithm.
  3. Execute the benchmark.
  4. Check the validity of your assertion.

Let’s break this down further so that we can understand each of these individually.

Step 1: Define a range of inputs.

Each Benchmark needs a range of values that will be fed to the code under test during execution, and this is defined by the bench_range class method. Because it’s the result of a class method, the same range is use for all benchmark tests within the same class. The values in the returned Array must be numeric and should, in most cases, translate into an increasing workload.

The Minitest::Benchmark base class has a default implementation of bench_range that returns an exponential progression of powers of 10 from 1 through 10,000 as shown here:

You can also override this implementation for each Benchmark subclass, and Minitest provides helper functions for defining both linear and exponential numeric progressions.

Step 2: Assert the performance of your algorithm.

Discord markdown cheat sheet cheat. At the core of any Benchmark test is an assertion about the performance of your code given an arbitrary amount of work to do. There are five different assertions supported out of the box:

  • assert_performance_constant - Execution time should remain constant regardless of inputs.
  • assert_performance_linear - Execution time should increase in proportion to workload.
  • assert_performance_logarithmic - Execution time approaches a maximum limit.
  • assert_performance_exponential - Execution time increases exponentially with workload.
  • assert_performance_power - Execution time increases with workload according to a power function relation.

Like any other kind of test, the assertion is essentially a prediction about the way your code should behave (or in this case, perform) given certain inputs. These predictions can be expressed as mathematical formulas which in turn be expressed graphically.

Don’t be intimidated by the math here. It’s actually quite intuitive what each of these things mean:

  • x is the numeric input provided to the code under test which represents a certain amount of work to be performed by the code under test.
  • y is the predicted execution time resulting from a given input.
  • a and b are implementation-specific constants that affect the shape of the curve.

In each case, the assertion method takes two arguments: a threshold value representing how closely the observed execution times match the predictions and a block representing the code under test. We’ll circle back to these shortly.

Step 3: Execute the benchmark.

Minitest runs the benchmark by executing the block once for each input value returned by bench_range. With each execution, it measures the running time and stores it for later comparison.

While your benchmark runs, Minitest will print out the times for each execution of the code under test. The output below is an example from a sample benchmark.

Step 4: Check the validity of your assertion.

Let’s consider what we have by the time we reach the final step of the process:

  • An assumption about the general pattern of performance for the algorithm (determined by the assertion type)
  • A threshold number describing how closely we expect observed values to match predictions
  • The range of inputs used to conduct the benchmark
  • Observed execution times for the code under test for each input value in the range

Using all of this and the awesome power of MATH, Minitest can determine the optimal values for the coefficients (recall: a and b from the formulas mentioned above). By “optimal” in this case, we mean the values of a and b such that an equation of the form indicated by the assertion type provides the best representation and prediction of the observed values. That might sound complicated, but essentially, it’s answering the question: what’s the best formula for predicting execution time?

As soon as these values are known, Minitest is also able to quantify how closely our predictions match the real, observed values by computing the coefficient of determination - commonly known as the R-squared value. Without going into the gory technical details, R-squared is just a number between 0.0 and 1.0 that measures how closely the computed function matches the real observed data with a larger value indicating a closer match.

And that brings us back to our test code. Recall that we provided a numeric threshold value when we wrote the original assertion? Well, if the R-squared value is greater than the threshold value we passed to the assertion, it means that the performance fits with the expected model, and our assertion succeeds; if R-squared is less than the threshold though, the assertion fails. So in this way, we haven’t demonstrated that our code is fast or slow, but rather that it performs according to one of these models.

Hopefully that explains a little better about Minitest::Benchmark and what it might be used for. In the next installment, we’ll take a look at how we might be able to apply this knowledge within a realistic use case, and try to understand the value it can provide us.

Additional Resources:

  • Ruby Benchmarking & Complexity - one of the only detailed technical articles I found on Minitest::Benchmark

Helpy is a modern help desk platform written in Ruby on Rails and released under the MIT license. The goal of Helpy is to power your support email and ticketing, integrate seamlessly with your app, and run an amazing customer helpcenter.

Helpy is licensed under the MIT license, and is an open-core project. This means that the core functionality is 100% open source and fully hackable or even re-sellable under the MIT license. See the features comparison below to understand what is included.

Helpy is a large system and cannot exist purely as a hobby project. If you use it in a money generating capacity, it makes good sense to support the project financially or by becoming an official sponsor or supporter.

Helpy is an integrated support solution- combining and leveraging synergies between support ticketing, Knowledgebase and a public community. Each feature is optional however, and can be easily disabled.

  • Multichannel ticketing: Integrated with inbound email via Sendgrid, Mandrill, Mailgun, etc.
  • Knowledgebase: Full text searchable and SEO optimized to help users answer questions before they contact you.
  • Mobile-friendly: Support requests come at all times, and Helpy works on all devices out of the box so you can delight customers with prompt answers, from anywhere and at anytime!
  • Community Support Forums: Customers and Agents can both answer questions in a publicly accessible forum, and vote both threads and replies up or down accordingly.
  • Embed Widget: Helpy Includes a lightweight javascript widget that allows your users to contact you from just about anywhere.
  • Multi-lingual: Helpy is fully multi-lingual and can provide support in multiple languages at the same time. Currently the app includes translations for 19 languages and is easy to translate.
  • Themeable: Customize the look and functionality of your Helpy without disturbing the underlying system that makes it all work. Helpy comes with two additional themes, and we hope to add more and get more from the community as time goes on.
  • Sends HTML email: Responses to customers can include html, emojis and attachments.
  • Customizable: Set colors to match your brand both on the helpcenter, and in the ticketing UI.
  • GDPR Compliant: Comply with GDPR right to be forgotten requests by deleting users and their history, or by anonymizing them.

We also offer a pro version with additional features designed to make your helpcenter even more awesome. This is available as either a turn-key SaaS or AWS/Azure marketplace product. Both spin up in seconds. Proceeds go directly towards supporting the continued development of the project. Some of the things found in the pro version:

  • Triggers: Insert events at any point in the ticket lifecycle. This includes an outbound JSON API.
  • Notifications: Browser notifications when new tickets are received, you are assigned to a ticket, etc.
  • Real time UI: When tickets arrive, they are automatically added to the UI
  • Custom Views: Add additional Ticketing queues to highlight just the tickets you need to see
  • Advanced reporting: A suite of additional reports on the performance of your ticketing and helpcenter knowledgebase
  • Advanced search: Easily filter and find tickets or customers when you have thousands
  • Customizable Request Forms: Easily Add questions to the ticket creation forms
  • AI Support Chatbot: Create a chatbot for your website to answer up 90% of tier one questions autonomously

Helpy Pro - 30 Second one-click install via AWS

You can take a 14 day free trial of the Pro version of Helpy on AWS. This is a 'one click' marketplace image and spins up a dedicated VM within 30 seconds, running Ubuntu. Launch AWS Marketplace Image

Install Helpy via Docker

Docker is the recommended way to quickly test or run Helpy in production.

  1. Install Docker and docker-compose
  2. Create config file from template cp docker/.env.sample docker/.env and edit docker/.env to match your needs
  3. Edit docker/Caddyfile to include your URL or turn on SSL
  4. Build Helpy from local git checkout docker-compose build
  5. Run docker-compose up -d to start all of the services

Install Helpy on your Local System

Although not required, installing locally is highly recommended and will make it easier for you to customize things like settings, colors and logos to match your site identity. To begin, clone Helpy from the official repo to your local system:

git clone

Configure Basic Settings

There is a settings option in the admin panel to set up things like i18n, system names, colors, the embeddable widget, etc. There is a full guide to getting set up at: Configuring Your Helpy Settings

Support Multiple Languages (optional)

Helpy includes support for Multilingual help sites, and multi-language knowledgebase articles. This page explains how to enable Helpy's international capabilities and provides an overview of what functionality this adds to Helpy: How To Set Up A Multilingual Helpy Support Knowledgebase

Minitest Cheat Sheet Template

Set up your Helpy to send and receive email (optional)

Helpy has the ability to receive email at your support email addresses and import the messages as tickets in the web interface. Whenever you or the user replies to the email thread, Helpy captures the discussion and sends out messages accordingly. Follow the tutorial on Setting Up Your Helpy Installation To Send And Receive Email to set this up.

Configure oAuth (optional)

Helpy supports Omniauth login capabilities. This means you can allow your support users to sign in with a single click via any Omniauth provider- ie. Facebook, Twitter, Gmail, or many others. Read Setting Up Oauth For Your Helpy to see how.

There is also a live demo with fake data available at http://demo.helpy.ioAdmin User: [email protected] and password: 12345678

Helpy was designed to run on modern cloud providers, although it should work onany linux based system. There is a full guide to installing Helpy in the wiki:

Requirements are:

  • Ruby 2.4+
  • Rails 4.2.x
  • Postgres
  • A server like Unicorn, Puma or Passenger

Helpy leverages two external services to help out:

Minitest Cheat Sheet Excel

  • an email provider like Sendgrid
  • Google Analytics for stats (optional)

Welcome, and thanks for contributing to Helpy. Together we are building the best customer support platform in the world. Here are some of the ways you can contribute:

  • Report or fix Bugs
  • Refactoring
  • Improve test coverage- As with any large and growing codebase, test coverage is not always as good as it could be. Help improving test coverage is always welcome and will help you learn how Helpy works. We use Minitest exclusively.
  • Translate the project- The community has already translated Helpy into 18 languages, but there are many more waiting. We need help getting Helpy translated into as many locales as possible! Please see the guide to translation for more details.
  • Build new features. There is a backlog of new features that we’d like to see built. Check out our roadmap for more insight on this, and if you would like to take one on, please get in touch with us to make sure someone is not already working on it.

Minitest Cheat Sheet Pdf

General Guidelines:

Minitest Cheat Sheet

  • Join us on Slack. Let me know you wish to contribute.
  • Make your PRs granular. They should only include one piece of functionality per PR.
  • Check the roadmap: Trello If you want to build a feature, contact us to make sure no one else is already working on it
  • You must provide passing test coverage. We use minitest, see
  • You also must expose functionality to the API. We use Grape. API methods should be tested as well.
  • If your feature/bug fix/enhancement adds or changes text in the project, please create i18n strings in en.yml and any other locales you can.
  • We are hugely concerned with user experience, and a nice UI. Oftentimes that means we may take what you have contributed and “dress it up” or ask you to do the same.

If you have found a vulnerability or other security problem in Helpy, please do not open an issue on GitHub. Instead, contact [[email protected]](mailto: [email protected]) directly by email. See the SECURITY guide to learn more and see a hall of fame of security reporters.

Copyright 2016-2020,, LLC, Scott Miller and Contributors. Helpy Core is released under the MIT open source license. Please contribute back any enhancements you make. Also, I would appreciate if you kept the 'powered by Helpy' blurb in the footer. This helps me keep track of how many are using Helpy.