[RUBY] 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.

Expectation

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.

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
I tried unit testing Rails app using RSpec and FactoryBot
About method matchers used in model unit test code (RSpec)
[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 RSpec (Rails)
About designing Spring Boot and unit test environment
RSpec test code execution
Introduction to RSpec 1. Test, RSpec
[Ralis] About unit tests
Testing model with RSpec
Java Unit Test Library-Artery-Sample
[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
[Rails] Test code using Rspec
Test GraphQL resolver with rspec
Implementation of unit test code