Search⌘ K
AI Features

Assertions and Code Structure

Explore how to write and structure tests in Ruby on Rails by using various assertions like assert, assert_equal, and assert_redirected_to. Understand how these checks validate application behavior and how test methods are organized for effective testing.

We'll cover the following...

Assertions

An assertion is simply a line of code that checks and evaluates an expression or object for an expected result. You can use assertions to check things like:

  • Does value1= value2?
  • Does object = nil?
  • Is expression true?
  • Is the user redirected to the intended page after performing a certain action such as submitting a form?

Some of the common assertions used in MiniTestMiniTest are provided in the table.

Assertion Use
assert(test) Checks if test is true
assert_not(test) Checks if test is false
assert_equal(expectedValue, actualValue)
...