What to do if you don't see the test code error message in the terminal console

Trigger

items_controllers.rb


it "Cannot register if the zip code is empty" do
        @user_item.postal_code = nil
        binding.pry
        @user_item.valid?
        expect(@user_item.errors.full_messages).to include("Postal code can't be blank")
      end

When I tried to get the error message in the terminal with the above description in the controller, the following result was obtained.

console


[1] pry(#<RSpec::ExampleGroups::UserItem::Nested::Nested_2>)> @user_item.errors.full_messages
=> []

why? ?? I thought that there was a validation problem if there was no error message, but the cause was not there.

Conclusion

The location of binding.pry was incorrect. or I made a mistake in the order from applying binding.pry to arriving at the error message.

When binding.pry is applied, the movement of the PC stops at that point, but when moving from there on the console, the order was important. Give me an error message unnecessarily! Even so, the computer doesn't work. First of all, if you apply binding.pry to the above location,

console


@item.valid?

I had to write on the console. And for the first time if the return value is false

console


@item.errors.full_messages

By describing, an error message will be returned.

Summary

When binding.pry is applied, the console will fulfill your wishes if you proceed while checking the order in the same way as with a normal controller, instead of asking for the Paramus value or error message unnecessarily.

Recommended Posts

What to do if you don't see the test code error message in the terminal console
What to do if you get a "302" error in your controller unit test code in Rails
What to do if you get an error in Basic authentication during Rails test code
What to do if you don't like the code generated by swagger-codegen-cli
What to do if you get the error message unrecognized selector send to instance "***"
How to translate the error message into Japanese (What to do if you cannot log in for some reason)
What to do if you get a DISPLAY error in gym.render ()
What to do if you forget the root password in CentOS7
[Rails] What to do if you can't get an error message with the errors method
What to do if Operation not permitted is displayed when you execute a command in the terminal
What to do if you get a wrong number of arguments error in binding.pry
What to do if you can't get the text of an element in Selenium
What to do if you get the error Couldn't find Item without an ID
What to do if you can't use the rails command
What to do if you get an Argument Error: wrong number of arguments (given 2, expected 0) in your RSpec test
[Rails] What to do if you accidentally install bundle in the production environment in your local environment
What to do if the Rails page doesn't appear in Rails tutorial 1.3.2
What to do if Cloud9 is full in the Rails tutorial
What to do if you cannot roll back the migration (UnknownMigrationVersionError)
What to do if you install Ubuntu
What to do if you get a "Mysql2 :: Error: Operand should contain 1 column (s)" error in Rails
What to do if you get a JNI shared library error when trying to build in Eclipse
What to do if you get an [An HTTP request took too long to complete.] Error in Docker.
What to do if you get a groovy warning in Thymeleaf Layout
What to do if you get an error during rails db: reset
What to do if the prefix c is not bound in JSP
What to do if you get an uninitialized constant Likes Controller error
What to do if you can't install the plugin from the Eclipse marketplace
What to do if you get an error when you hit Heroku logs
What to do if you get an error with bundle install by entering gem'bcrypt' in your Gemfile
What to do if the image posted by refile disappears after setting a 404 error page in Rails
What to do if you can't bundle update and bundle install after installing Ruby 3.0.0 in the Rails tutorial
What to do if you get the error Too long with no output (exceeded 10m0s) on CircleCI
What to do if the server tomcat dies
What to do if you push incorrect information
What to do if you get a SQLite3 :: BusyException: database is locked error
If you want to satisfy the test coverage of private methods in JUnit
What to do if the changes are not reflected in the jar manifest file
What to do if you get an error on heroku rake db: migrate
What to do if you get angry if you don't have nokogiri while installing wp2txt
What to do if you get To install the missing version, run `gem install bundler: 2.1.4`
What to do if you get an "A server is already running." Error when you try to start the rails server
What to do if you get a javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake in the IBM JDK
What to do if you have enabled Use the WSL2 based engine in Docker Desktop with insufficient WSL2 installation
What to do if the debug gem installation fails
What to do if the Rails server can't start
What to do if you accidentally create a model
What to do if an ActionController :: UnknownFormat error occurs
If you want to recreate the instance in cloud9
What to do if password authentication fails in Docker/Postgres
What to do if Failure / Error: require File.expand_path ('../ config / environment', __dir__) appears in RSpec
What to do if you get a port error when docker-compose up on Mac
What to do if you cannot execute with the command "Java package name / class name"
[Java] What to do if you get an error in Eclipse saying "Not allowed at source level below 1.X"
What to do if you get the warning "Uniqueness validator will no longer enforce case sensitive comparison in Rails 6.1." in Rails 6.0
What to do if you can't find the JDK you put in SDKMAN after migrating from bash to zsh on macOS
What to do if you change the Listen Address from the settings screen with Mattermost docker
What to do if you installed Ruby with rbenv but the version does not change
# What to do if you accidentally do rails db: migrate: drop
[Rails Tutorial Chapter 2] What to do when you make a mistake in the column name
[Maven] What to do if you are asked to incorporate a jar that is not in the remote repository into the war