Cucumber Flashcards

1
Q

When testing that you should be redirected to a page, what can you include in your step definition to make your life a little easier. Given you have the following cucumber step: Then I should be redirected to the “Landing” page

A

Step definition file:

Then(“I should be redirected to the {string} page”) do |page_name|
expect(page.current_path).to eq page_path_from(page_name)
end

def page_path_from(page_name)
  case page_name.downcase
    when 'landing' then root_path
    when 'login' then '/users/sign_in'
end
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you make a table with at least one row representing an instance into a hash in a step definition?

A

table.hashes.each do |user|
User.create(user)
end

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

How to test for a page to a button and a link, as a step definition?

A

expect(page).to have_button button

expect(page).to have_link link

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

Write out the difference between testing fora redirect and visiting a page.

A

expect(page.current_path).to eq page_path_from(page_name)

visit root_path

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