swt2-intro-exercise / rails-exercise-20-Georgy5

rails-exercise-20-Georgy5 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 #4

Open swt2public opened 11 months ago

swt2public commented 11 months 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 (at /authors/new) is empty. Before adding input fields, create a test that checks for their presence.

In the spec file (spec/features/author/new_author_spec.rb), 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 present or valid. For example have_field checks if the HTML of the page contains 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 what your test could look like. 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 Rails 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. 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 generates the required HTML. The primary form builder for Rails is provided by a helper method called form_with. See the Rails Guide.

Don't worry if submitting the form causes an error at this point, that functionality will follow.

Error

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

2 exercise tests have passed. There are 44 in total. You will solve multiple at once towards the end.

swt2public commented 11 months ago

Sorry, it's not working for me yet:

Scenario

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

Error

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

If you have problems solving this task, please don't hesitate to contact the teaching team!