By: Mayur Shende Category: Ruby on Rails,Web Development Technologies: Ruby on Rails
Rspec:-
Rspec setup for testing application:-
rails new Demo -T
You can utilize any application name you need, the — T flag is used to tell Rails not to utilize MiniTest. By default, Rails will use a test system called ‘MiniTest’ on the off chance that we didn’t indicate — T flag, we need to use Rspec as the test framework rather than MiniTest.
RSpec-rails is the RSpec testing framework, in addition to a few takes on Rail’s magic. For example, when you run rails to produce model User to make user, it will also consequently create a model test record for that client: user_spec.rb.
# Gemfile
# …
group :development, :test do
gem ‘rspec-rails’
end
require ‘spec_helper’
require ‘web drivers’
Now create a file named “static_spec.rb” , and place it in “spec/static_spec.rb”
# spec/static_spec.rb
require ‘rails_helper’
RSpec.describe ‘Static content’, type: :system do
it ‘shows the static text’ do
visit static_index_path
expect(page).to have_content(‘Hello world’)
end
end
You should see your default Browser open and it will load the page briefly and close, and a succeeded test :
Congratulation! You have written your first Rspec test!!!