RSpec Display Elements Flashcards

1
Q

How to add a base structure for testing routing?

A

require ‘rails_helper’

RSpec.describe ‘Route’, type: :routing do
it ‘tests routes’ do

end
end

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How to check the root route?

A

expect(get: ‘/’).to route_to(controller: ‘projects’, action: ‘index’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How to test an ordinary get route ‘/name’?

A

expect(get: ‘/name’).to route_to(controller: ‘projects’, action: ‘name’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How to check the route with params?

A

expect(get: ‘/name/1’).to route_to(controller: ‘projects’, action: ‘name’, id: ‘1’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How to test the route with another request?( delete)

A

expect(delete: ‘/name/1’).to route_to(controller: ‘projects’, action: ‘destroy’, id: ‘1’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How to check that route doesn’t define?

A

expect(delete: ‘/something’).not_to be_routable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How to create a base helper structure?

A

require ‘rails_helper’

RSpec.describe ProjectsHelper, type: :helper do
it ‘test helper’ do

end
end

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How to use the helper inside the test?

A
# use keyword 'helper' and helper method my itself
expect(helper.plus_one(1)).to eq(2)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How to create base structure for the request spec?

A

require ‘rails_helper’

RSpec.describe ‘GET /name’, type: :request do
it ‘request test’ do

end
end

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How to check the response status for the request spec?

A

get ‘/name’

expect(response).to have_http_status(200)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How to create a base mailer spec structure?

A

require “rails_helper”

RSpec.describe UserMailer, type: :mailer do
it ‘is a base mailer spec’ do

end
end

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How to send that letter was sent?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How to test email subject?

A

email = ActionMailer::Base.deliveries.first

expect(email.subject).to eq(‘Email Subject’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How to check the receiver email address?

A

email = ActionMailer::Base.deliveries.first

expect(email.to).to eq([‘sample@gmail.com’])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly