About app testing RSpec (unit test)

RSpec A test-specific language created based on Ruby

Test code basics

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

describe 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).

Recommended Posts

About app testing RSpec (unit test)
[Rails] About Rspec response test
[Rails] From test preparation to model unit testing [RSpec]
I tried unit testing Rails app using RSpec and FactoryBot
[Rails5] Rspec -Unit test when nesting-
[RSpec] Unit test (using gem: factory_bot)
Let's unit test with [rails] Rspec!
Introduce RSpec and write unit test code
About designing Spring Boot and unit test environment
RSpec test code execution
RSpec unit test code creation procedure (login user creation Ver.)
[Ralis] About unit tests
[Rails] Test with RSpec
Test Nokogiri with Rspec.
Unit test with Junit.
About Android App Components
[IntelliJ IDEA] Perform Unit Test
Test Active Strage with RSpec
Introduction to Micronaut 2 ~ Unit test ~
Test GraphQL resolver with rspec