Junior Track Roadmap

Minitest: model & assertions

This course covers Minitest, the default testing framework built into Rails, in an app whose own tests are written in RSpec. It reads ActiveSupport::TestCase and its parent class Minitest::Test from the installed gem source. It runs assert_equal, assert_predicate and assert_difference against a disposable ActiveRecord model on Postgres and shows their failure messages. It explains why ActiveRecord::TestFixtures is installed but never wired in. It also translates two RSpec examples into Minitest and closes with a small challenge in pure Ruby.

What you'll learn

  • ✓How ActiveSupport::TestCase subclasses Minitest::Test and inherits Minitest::Assertions
  • ✓How the declarative test helper turns a string into a test_ method with define_method
  • ✓Using assert_equal and assert_predicate on ActiveRecord models and reading their failure output
  • ✓How assert_difference and its related assertions check what a block changes
  • ✓Why ActiveRecord::TestFixtures depends on rails/test_help.rb and a test/test_helper.rb
  • ✓How RSpec expectations map to Minitest assertions, and where they do not
Free preview · Lesson 1 2 min read

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

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.

Read the full lesson free →

Curriculum

7 lessons
Type to start searching...