# Rails Test Basics

DevFeed: [Rails Test Basics](<https://devfeed.tech/articles/rails-test-basics-28258.md>)

Original publisher: [Read original article](<http://fuzzyblog.io/blog/rails/2020/01/27/rails-test-basics.html>)

Author: Fuzzygroup

Published: 2020-01-27T00:00:00Z

Content type: tutorial

Language: en

Sources: [Scott Johnson](<https://devfeed.tech/sources/scott-johnson.md>)

Topics: [Ruby on Rails](<https://devfeed.tech/topics/ruby-on-rails.md>), [Software Testing](<https://devfeed.tech/topics/software-testing.md>), [Test automation](<https://devfeed.tech/topics/test-automation.md>), [RSpec](<https://devfeed.tech/topics/rspec.md>), [Tutorial](<https://devfeed.tech/topics/tutorial.md>), [software-development](<https://devfeed.tech/topics/software-development.md>)

Tags: [basics](<https://devfeed.tech/tags/basics.md>), [rails](<https://devfeed.tech/tags/rails.md>), [rspec](<https://devfeed.tech/tags/rspec.md>), [test](<https://devfeed.tech/tags/test.md>), [testing](<https://devfeed.tech/tags/testing.md>), [tests](<https://devfeed.tech/tags/tests.md>)

## AI overview

The excerpt recaps standard Rails testing in a Jumpstart project: add `byebug` to the Gemfile's development and test groups and require it at the top of `test_helper.rb` to use breakpoints; skip a test with `skip`; and run model tests, a file, the full suite, verbose tests, fail-fast tests, or a line-specific test with the shown `rails test` commands. It notes that a stale line number can yield zero runs and assertions, unlike the author's experience with RSpec. For FactoryBot, it lists adding the test dependency, installing it, creating `test/factories`, including `FactoryBot::Syntax::Methods` in `test_helper.rb`, restarting Spring, and writing a factory-based test. Examples use `assert_equal` and `assert_redirected_to`; other listed assertions include `assert_response`, `assert_difference`, and `assert_match`.

## Source excerpt

More than a decade using RSpec has left me flummoxed in terms of "classical" Rails testing. I'm on a new project built using the Jumpstart application template and all the tests are standard Rails tests so here's a quick recap that I wrote, well, to force myself to step back in time and go "old school". And if you don't like my version then you should really read this. And if you are using Devise for authentication then you really must read this. Making Tests Debuggable The ability to use byebug in a testing context for breakpoints and stepping through code is utterly invaluable. Here's what you need to do for that: Add byebug into a development, test group in Gemfile. Add the line require 'byebug' to the very top of test_helper.rb How Do You Skip a Test? You put the keyword 'skip' at the top of the test that you need to skip. This is equivalent to xit in RSpec. Running Tests The very basic of testing is nothing more than test execution so to run all model tests: rails test test/models/ and to run one file rails test test/models/user_test.rb and to run everything: rails test and to run with verbose mode: rails test -v test/models and to run verbosely and fail on the first test failure: rails test -v -f test/helpers/application_helper.rb and to run just one specific test: rails test test/controllers/labels_controller_test.rb:9 Note: RSpec is very good at running the next test if the line number shifts a bit (example you put in :8 but you added a line so its actually :9). With standard rails test, you get this madness: ❯ rails test test/controllers/projects_controller_test.rb:17 Running via Spring preloader in process 95090 Run options: --seed 52687 # Running: Finished in 0.010622s, 0.0000 runs/s, 0.0000 assertions/s. 0 runs, 0 assertions, 0 failures, 0 errors, 0 skips The 0 runs, 0 assertions, 0 failures, 0 errors, 0 skips can best be interpreted as: Yo! Hoser! I don't know what to do here so I'm going to confuse you deliberately. Ha Haw! Death to Fixtures; Viva La F