A gem that tests the operation of applications with RSpec and Ruby on Rails and Ruby.
As the purpose of use, check mistakes such as large-scale services are likely to occur, so code it. You can also save yourself the trouble of testing from scratch each time you update your application.
group :development, :test do
gem "rspec-rails"
end
% rails g rspec:install
Run this from your terminal to generate the required directories. Make sure you have a ** spec ** directory in your directory.
--format documentation
By writing this in .rspec, you can see the result of the test code from the terminal.
This time, I will make a simple sample and explain it. First, create a sample directory under the spec directory generated by rails g rspec: install, and create a sample_spec.rb file in it. I will describe it there.
sample_spec.rb
RSpec.describe 'What test code?' do
contenxt 'Situation explanation' do
it "The result that this should be" do
Describe the processing content here
end
end
end
After describe, describe the test contents in a large group. For example, *** New registration test *** and *** Login function test ***.
In the second line of describe, the test code declared in the first line is broken down a little more. For example, *** when new registration is possible *** or *** when login is not possible ***.
Here, the specific processing content is described. For example, *** You can register newly if your name is entered *** or *** You cannot log in if your password is incorrect ***.
sample_spec.rb
RSpec.describe 'Test total score' do
contenxt 'Total points when math is 100 points and national language is 50 points' do
it "If you add the math and national language scores, you get a total of 150 points." do
expect(100 + 50).to eq 150
end
end
end
Here is the test code for the total score of the test. In context, we explain the situation of how many points each score is. And in it, I explain specifically what should be like this and describe the processing contents in it.
The flow is to verbalize the confirmation content and execute the process. Next time, I would like to introduce what I learned about the processing contents.
Recommended Posts