I posted about how to install RSpec and how to write test code before, but I did not explain the actual test method, so I will look at how to execute the test I wrote this time.
[Previous post] After introducing RSpec, until you start writing unit test code for the model
I will not hesitate anymore! RSpec introduction flow
After confirming that the current directory is the application being created, in the terminal
bundle exec rspec spec/models/file name
The file name is the file that actually describes the test code.
If the test goes well, there will be no errors and all exampl items (the part that describes what you want to check in Japanese) will turn green.
% @user.valid?
#=>false
% @user.errors.full_messages
For user model unit test code
Test if the result of @ user.errors.full_messages
is included in the error message.
Recommended Posts