Minitest exists here: this app's tests are RSpec, and that's the starting point

Free preview 2 min to read

What this app's tests run

ls -d spec test
ls: cannot access 'test': No such file or directory
spec

This app's tests live in spec/ and run with bundle exec rspec spec/. Gemfile line 60 says gem "rspec-rails". There is no test/ directory, which is where a Minitest suite would live. If a course ever tells you this app "has no tests", that course checked the wrong convention.

So why a course on Minitest

Minitest is Rails' default, built-in testing framework. It's a gem (minitest, version 6.0.2) that activesupport and rails-dom-testing depend on, so it's already installed here. ActiveSupport::TestCase, the class every Rails model test inherits from, is in this app's Rails install too. Require active_support/test_case in bin/rails runner and ActiveSupport::TestCase.ancestors includes Minitest::Test. This app chose RSpec over it, the way a Rails app might choose PostgreSQL over MySQL, or Tailwind over Bootstrap. Both tools are valid; this app picked one.

What this course teaches, and how it was checked

Seven lessons on Minitest's model-testing mechanics, read from the installed activesupport and minitest gem source. Lesson 2 covers ActiveSupport::TestCase's class hierarchy. Lesson 3 runs assert_equal and assert_predicate against a disposable ActiveRecord model inside this app's Rails environment. Lesson 4 runs assert_difference, Rails' addition to plain Minitest, the same way. Lesson 5 covers the file-naming convention and checks whether this app wires in an installed mechanism, ActiveRecord::TestFixtures. Lesson 6 translates two of this app's RSpec examples into Minitest, side by side.

The plan for the rest of this course

The claims in the next six lessons were run as well as read. Lesson 3's assertions, for instance, went into a Ruby file, pointed at a disposable ActiveRecord model on this app's Postgres connection, and ran with ruby, producing a pass/fail count. Lesson 7's challenge reference solution was checked the same way before it shipped. The next course, RSpec: describe/context/it, picks up where lesson 6 leaves off: this app's chosen framework, covered on its own terms.

Lesson 1 of 7 · free

Keep going with lesson 2

ActiveSupport::TestCase: the class every Minitest model test builds on

Reads how ActiveSupport::TestCase subclasses Minitest::Test and how the declarative test helper defines ordinary test methods.

A free account also gives you the quizzes, your progress and notes, and the discussion.

Type to start searching...