[Ruby] About app testing RSpec (unit test)

less than 1 minute read

A test-specific language created based on Ruby

Test code basics

スクリーンショット 2020-06-30 22.09.20.png

The describe on the first line creates a group of tests from do to end immediately after. In the “” that follows the describe, write a description of the group.

it and example

The second line, it, represents a set of working test code called an example. Write a description of the example in the “” that follows it.


It is the formula that is actually evaluated. Write between it do ~ end. In the above equation, the part of expect (1 + 1) .to eq 2 is the expectation.

expect(X).to eq Y
Expectation grammar. If the value of the expression in the x part is equal to the value in the Y part, the test succeeds. The part of eq is called matcha.


Shows the conditions under which the test will succeed in the expectation. For example, eq means “if equal”. Other
There are multiple matchers such as include (if included) and valid (if validated).