Hello,
Right now I’m implementing a capybara test-suite for a rails app as the sole tester (and a novice at that) and looking to improve my structure.
A single form has testing like this…
feature 'The quick-add-patient form' do
scenario 'requires first_name, last_name, and dob', js: true do
login_facility
within quick_add_form do
click_on 'Submit'
expect(page).to quick_display_error 'First Name must be filled.'
expect(page).to quick_display_error 'Last Name must be filled.'
expect(page).to quick_display_error 'Date of Birth must be filled.'
choose 'inlineRadio1'
fill_in 'medical_record_number', with: '123123'
click_on 'Submit'
expect(page).to quick_display_error 'First Name must be filled.'
expect(page).to quick_display_error 'Last Name must be filled.'
expect(page).to quick_display_error 'Date of Birth must be filled.'
fill_each 'first_name' => 'Bob', 'last_name' => 'Boberson'
fill_in_dob
click_on 'Submit'
end
expect(page).to_not quick_display_error 'First Name must be filled.'
expect(page).to_not quick_display_error 'Last Name must be filled.'
expect(page).to_not quick_display_error 'Date of Birth must be filled.'
expect(page).to display_success 'The patient record for Bob Boberson saved successfully.'
end
scenario 'displays to patients#show after save', js: true do
login_facility
within quick_add_form do
fill out form and submit...
end
expect(page).to display_success 'The patient record for Bob Boberson saved successfully.'
expect_page_to_have_p_texts 'First Name: Bob', 'Last Name: Boberson', 'Gender: Male', 'MRN: 123123'
end
scenario 'creates an audit log', js: true do
login_facility
within quick_add_form do
fill and submit form...
end
expect(page).to display_success 'The patient record for Bob Boberson saved successfully.'
expect(bobs_last_audit_log.performed_by).to eq(User.first.id)
expect(bobs_last_audit_log.performed_at).to_not be_nil
expect(bobs_last_audit_log.action).to eq(1)
end
end
When you have multiple values to keep track of after a form submission, how do you break these down into fewer expectations?
I tried breaking the logic into separate categories where the first tests our javascript, the 2nd checks saving to the db, and the 3rd for creating our audit logs, but even within these I’ve had to make helpers like expect_page_to_have_p_texts that iterate over a collection of strings to check if they are on the page.
Thanks,