RSpec hooks

Before and After hooks are of great use to execute common set of code before and after a test suite, test case.


Examples:

Ex 1 -

before {@user = User.new(name: ‘John’, email: ‘john@john.com’)}

Ex 2 -

before(:each) do

@user = User.new

end

Ex 3 -

before(:all) do

puts ‘check user’

end

Like what you read? Give Build to explore a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.