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) looks rather empty, but before adding input fields you should create a test that checks their presence.
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 missing form fields required by the test. It should look something like this.
To create a form within the views/authors/new.html.erb view, you will use a form builder.
The primary form builder for Rails is provided by a helper method called form_with.
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
) looks rather empty, but before adding input fields you should create a test that checks their presence.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 aninput
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.
After committing the test, add the missing form fields required by the test. It should look something like this. To create a form within the
views/authors/new.html.erb
view, you will use a form builder. The primary form builder for Rails is provided by a helper method calledform_with
.For help, see the Rails tutorial.
Don't worry if sending the form causes an error at this point. We'll handle that later.
Error
Estimated progress: 5% complete