Introduction to Rspec (Testing)

bhartee_sahare

Bhartee Rameshwar Sahare

Posted on February 25, 2023

Introduction to Rspec (Testing)

What is the testing framework:

A testing framework automates the test code that executes and verifies bug checks (= operation checks). In other words, a testing framework is a framework that makes it easy to implement tests.

A software framework that provides functions such as creating automatic execution programs for software tests, intuitive judgement, and automatic aggregation of test results.

Testing framework in Ruby:
There are mainly three testing frameworks in Ruby, and the order of usage is as follows

  1. RSpec
  2. Minitest
  3. test-unit .

What is the Rspec:

RSpec is one of Ruby’s testing frameworks and the most used language among Ruby developers.

RSpec’s R stands for Ruby and Spec stands for test code.

As a feature, RSpec is created based on the Ruby language, so it has the advantage that anyone who understands Ruby to some extent can easily implement it.

How to install:

Add the code below to the Gemfile and after that, run the command “bundle install”

group :development, :test do
  # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
  gem "debug", platforms: %i[ mri mingw x64_mingw ]
  # this is for the test case for rspec
  gem 'rspec-rails'
end
Enter fullscreen mode Exit fullscreen mode

Next are the RSpec settings:

rails g rspec:install # this command type in our project folder terminal and it is create the below files
# this above command generate the four files 
create  .rspec # file genrated
create  spec # file generated
create  spec/spec_helper.rb # file generated
create  spec/rails_helper.rb # file generated

rspec --format d # type this commnd in bash terminal

No examples found.

Finished in 0.00024 seconds (files took 0.05174 seconds to load)
0 examples, 0 failures


Note: --format d => is an option to make the test output results easier to read.

Enter fullscreen mode Exit fullscreen mode

Regarding the above, I will upload the next post soon…

💖 💪 🙅 🚩
bhartee_sahare
Bhartee Rameshwar Sahare

Posted on February 25, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related