From 69b290b0d45a8822961fc88e204bd6552facea08 Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Sat, 2 Apr 2016 11:23:33 -0500 Subject: [PATCH] Add Running A Single MiniTest Example as a ruby til --- README.md | 1 + ruby/running-a-single-minitest-example.md | 36 +++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 ruby/running-a-single-minitest-example.md diff --git a/README.md b/README.md index 9c67c18..91ec990 100644 --- a/README.md +++ b/README.md @@ -296,6 +296,7 @@ _381 TILs and counting..._ - [Replace The Current Process With An External Command](ruby/replace-the-current-process-with-an-external-command.md) - [Rendering ERB](ruby/rendering-erb.md) - [Returning With Sequel](ruby/returning-with-sequel.md) +- [Running A Single MiniTest Example](ruby/running-a-single-minitest-example.md) - [Safe Navigation Operator](ruby/safe-navigation-operator.md) - [Set RVM Default Ruby](ruby/set-rvm-default-ruby.md) - [Show Public Methods With Pry](ruby/show-public-methods-with-pry.md) diff --git a/ruby/running-a-single-minitest-example.md b/ruby/running-a-single-minitest-example.md new file mode 100644 index 0000000..ce2360d --- /dev/null +++ b/ruby/running-a-single-minitest-example.md @@ -0,0 +1,36 @@ +# Running A Single MiniTest Example + +Consider the following +[MiniTest](http://ruby-doc.org/stdlib-2.0.0/libdoc/minitest/rdoc/MiniTest.html) +file: + +```ruby +# test_stuff.rb +require 'minitest/autorun' + +class TestStuff < MiniTest::Unit::TestCase + def test_first_thing + assert_equal 4, (2 * 2) + end + + def test_second_thing + assert_equal 9, (3 * 3) + end +end +``` + +If we want to run all the tests in this file, we can do so with: + +```bash +$ ruby test_stuff.rb +``` + +But what if we want to run a specific test? We can target a single MiniTest +example with the `--name` flag and the name of that example. We can do +something like the following: + +```bash +$ ruby test_stuff.rb --name test_second_thing +``` + +[source](http://stackoverflow.com/a/5292885/535590)