swt2-intro-exercise / rails-exercise-20-sirkrypt0

rails-exercise-20-sirkrypt0 created by GitHub Classroom
MIT License
0 stars 0 forks source link

New author page should have text input for first name, last name, and homepage #2

Closed swt2public closed 4 years ago

swt2public commented 4 years ago

Scenario

When a user visits the new author page Then it should have a text input field with the name 'author[first_name]'

Hints

The new-author page (it should be at /authors/new) looks rather empty, but before adding input fields, create a test that checks their presence.

In the spec file (spec/features/author/new_author_spec.r), create a new it block with a descriptive name. Inside the block, after visiting the new-author page, the test should check for input fields.

RSpec uses matchers to check if a given object is valid. For example, the have_field matcher Checks if the HTML of the page has an input form field with the given label, name or id. For more matchers, see this Cheat Sheet or the documentation.

The following code snippet shows how your final test should look. You can copy&paste this code, but understand what every instruction does before moving on.

it "should have text inputs for an author's first name, last name, and homepage" do
  visit new_author_path

  # these are the standard names given to inputs by the form builder
  expect(page).to have_field('author[first_name]')
  expect(page).to have_field('author[last_name]')
  expect(page).to have_field('author[homepage]')
end

After committing the test, add the form fields (for first_name, last_name and homepage) required by the test. It should look something like this. To create a form within the views/authors/new.html.erb view, you can use a form builder, which allows easily generating the required HTML. The primary form builder for Rails is provided by a helper method called form_with. See the Rails tutorial.

Don't worry if submitting the form causes an Unknown Action error at this point.

Error

Expected to find field "author[first_name]" that is not disabled but there were no matches

2/44 exercise tests have passed