Rails Testing and Debugging Flashcards

1
Q

spec directory

A

rails file structure to store tests

typically has a separate models and features sub-directory

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

Why separate spec/features and spec/models?

A

Allows you to take advantage of RSpec’s built in assumptions (all tests in features are feature test, etc.)

Without this, you need to declare a type for each test: “RSpec.describe ‘this is a feature test’, type: :feature do”

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

Capybara method that allows us to use CSS Selectors to select elements and then write expectations just for that area of the page

A

within

e.g.,
within(‘#artist-13’) do
expect(page).to have_content(‘content about this artist’)
end

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

Spec File naming convention

A

test files MUST end with _spec.rb

convention is to name spec files in model folder after the model its testing.

no convention for feature testing

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

Spec File naming convention

A

test files MUST end with _spec.rb

convention is to name spec files in model folder after the model its testing.

no convention for feature testing. You could match your views, or match the headline of each user story

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

Spec File naming convention

A

test files MUST end with _spec.rb

convention is to name spec files in model folder after the model its testing.

no convention for feature testing. You could match your views, or match the headline of each user story

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

before :each

A

block that will run before every test (every it block), used to create setup for many test and DRY up test files (similar to setup method in Minitest)

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

method to check that some content appears anywhere on a page

A

have_content

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

method to check if there is a button with a particular label

A

have_button

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

method to check if there is a specific link

A

have_link

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

method to check if there is a particular css selector (often used to verify images)

A

have_ccs

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

method to check if there is a particular css selector (often used to verify images)

A

have_ccs

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

method to check if there is a link or button with a matching label

A

click_on(‘label’)

or
click_button
click_link

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

Capybara method to return a single element that matches a css selector, a

A

find

song_14 = page.find(‘#song-14’)
expect(song_14).to have_content(‘Raspberry Beret’)

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

Capybara method to return an array of all elements that match a css selector

A

all

all_songs = page.all(‘.song’)
expect(all_songs[2]).to have_content(‘Purple Rain’)

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

How to test for sorted elements

A

Use all method, ccs selectors, and array methods to verify a specific order.

within ‘#best-users’ do
expect(page.all(‘.user’)[0]).to have_content(“megan”)
expect(page.all(‘.user’)[1]).to have_content(“brian”)
expect(page.all(‘.user’)[2]).to have_content(“sal”)
end