Intermediate TDD in Rails : Eliminating Duplication in Feature Tests
Learn how to reuse methods for feature tests.
Create spec/support/features folder. Create
session_helpers.rb in this folder.
module Features module SessionHelpers def sign_up(email, password) click_link 'Register' fill_in 'Email', with: email fill_in 'Password', with: password click_button 'Sign up' end end end
Create spec/support/features.rb file.
RSpec.configure do |config| config.include Features::SessionHelpers, type: :feature end
Replace the following lines:
click_link 'Register' fill_in 'Email', with: 'email@example.com' fill_in 'Password', with: '12345678' click_button 'Sign up'
Run the test:
Create a subscribe helper in subscription_spec.rb that can subscribe a user to a given plan. Change the subscription_spec.rb to use the helper.
In this lesson you learned how to create, configure and use helpers for feature tests.
Ace the Technical Interview
- Easily find the gaps in your knowledge
- Get customized lessons based on where you are
- Take consistent action everyday
- Builtin accountability to keep you on track
- You will solve bigger problems over time
- Get the job of your dreams
Take the 30 Day Coding Skills Challenge
Gain confidence to attend the interview