RSpec Display Elements Flashcards
How to add a base structure for testing routing?
require ‘rails_helper’
RSpec.describe ‘Route’, type: :routing do
it ‘tests routes’ do
end
end
How to check the root route?
expect(get: ‘/’).to route_to(controller: ‘projects’, action: ‘index’)
How to test an ordinary get route ‘/name’?
expect(get: ‘/name’).to route_to(controller: ‘projects’, action: ‘name’)
How to check the route with params?
expect(get: ‘/name/1’).to route_to(controller: ‘projects’, action: ‘name’, id: ‘1’)
How to test the route with another request?( delete)
expect(delete: ‘/name/1’).to route_to(controller: ‘projects’, action: ‘destroy’, id: ‘1’)
How to check that route doesn’t define?
expect(delete: ‘/something’).not_to be_routable
How to create a base helper structure?
require ‘rails_helper’
RSpec.describe ProjectsHelper, type: :helper do
it ‘test helper’ do
end
end
How to use the helper inside the test?
# use keyword 'helper' and helper method my itself expect(helper.plus_one(1)).to eq(2)
How to create base structure for the request spec?
require ‘rails_helper’
RSpec.describe ‘GET /name’, type: :request do
it ‘request test’ do
end
end
How to check the response status for the request spec?
get ‘/name’
expect(response).to have_http_status(200)
How to create a base mailer spec structure?
require “rails_helper”
RSpec.describe UserMailer, type: :mailer do
it ‘is a base mailer spec’ do
end
end
How to send that letter was sent?
before { UserMailer.with(params: ‘Something’).welcome_email.deliver_now }
it ‘is a base mailer spec’ do
expect(ActionMailer::Base.deliveries.count).to eq(1)
end
How to test email subject?
email = ActionMailer::Base.deliveries.first
expect(email.subject).to eq(‘Email Subject’)
How to check the receiver email address?
email = ActionMailer::Base.deliveries.first
expect(email.to).to eq([‘sample@gmail.com’])