Posted 9 days ago. Visible to the public.

When defining methods in specs, you can super into previous definitions

When you def methods in RSpec tests, you can use super to call a method definition that was created in a surrounding describe/context block.

Example:

Copy
describe User do def build_user(attributes = {}) User.new(attributes) end describe '#my_method' do it 'does something' do # ... end context 'when the user has an e-mail address' do def build_user(attributes = {}) super({ email: 'user@example.com' }.merge(attributes)) end it 'does something special' do # ... end end end end

By refactoring problematic code and creating automated tests, makandra can vastly improve the maintainability of your Rails application.

Owner of this card:

Avatar
Arne Hartherz
Last edit:
9 days ago
by Arne Hartherz
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Arne Hartherz to makandra dev
This website uses cookies to improve usability and analyze traffic.
Accept or learn more