# Back to Rails Test - Putting Rspec in the Rear View - Test Examples

DevFeed: [Back to Rails Test - Putting Rspec in the Rear View - Test Examples](<https://devfeed.tech/articles/back-to-rails-test-putting-rspec-in-the-rear-view-test-examples-28279.md>)

Original publisher: [Read original article](<http://fuzzyblog.io/blog/rails/2022/06/05/back-to-rails-test-putting-rspec-in-the-rear-view-test-examples.html>)

Author: Fuzzygroup

Published: 2022-06-05T12:54:00Z

Content type: tutorial

Language: en

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

Topics: [Rails](<https://devfeed.tech/topics/rails.md>), [test](<https://devfeed.tech/topics/test.md>), [Testing](<https://devfeed.tech/topics/testing.md>), [RSpec](<https://devfeed.tech/topics/rspec.md>), [Development](<https://devfeed.tech/topics/development.md>)

Tags: [building](<https://devfeed.tech/tags/building.md>), [debugger](<https://devfeed.tech/tags/debugger.md>), [development](<https://devfeed.tech/tags/development.md>), [examples](<https://devfeed.tech/tags/examples.md>), [model](<https://devfeed.tech/tags/model.md>), [models](<https://devfeed.tech/tags/models.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>)

## AI overview

This work-in-progress blog post compares Rails' native testing framework with RSpec and presents practical Rails test examples. It covers running individual or complete test suites, inspecting rendered page content, checking form and table elements, validating lists and headings, and asserting database changes.

## Source excerpt

I find myself building a new application, Cartazzi, and since the "template app" I'm building from uses Rails Test not rspec, I'm back to the past using the native rails testing framework - something I probably last touched by in 2009. This blog post summarizes different Rails testing examples and is a work in progress as I come up with new examples. Thinks I Like About Rails Test It is fast Have I mentioned it is fast It is so, so fast It tells you when you write duplicate tests if the test "" block is the same Things I Dislike About Rails Test Lack of output formatting like rspec's nested documentation The inability to nest tests; yes thoughtbot's matchers may provide this but they are 2+ years out of date and unclear if they are still maintained Examples Running a Single Test rails test test/models/my_model.rb:22 Running All Tests rails test test/models/my_model.rb Examining the body of a page at runtime debugger response.body[0..250] debugger response.body.scan(/FOO/) Asserting a form exists with different elements Asserting a row exists within a table assert_select 'table' do assert_select 'tr td', 'user1@example.com' end Asserting a select tag exists within a form # this would find a select with an id of project_type assert_select 'select#project_type' Asserting a text area exists within a form This assumes that the form do block illustrated above is used. # this would find a textarea with an id of component_body-input assert_select 'textarea#component_body-input' Asserting text exists on an H1 element assert_selector "h1", text: "Foobar" Checking a list has 4 elements assert_select "ol" do |elements| elements.each do |element| assert_select element, "li", 4 end end Asserting a difference on a database creation operation assert_difference('LinkType.count') do result = LinkType.find_or_create(OpenStruct.new(context: "execution_url", name: "development")) assert_equal result.class, LinkType end Asserting there should be no difference in database results test "Pr